MBDyn-1.7.3
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups
rtai_out_elem.cc
Go to the documentation of this file.
1 /* $Header: /var/cvs/mbdyn/mbdyn/mbdyn-1.0/mbdyn/base/rtai_out_elem.cc,v 1.50 2017/01/12 14:46:10 masarati Exp $ */
2 /*
3  * MBDyn (C) is a multibody analysis code.
4  * http://www.mbdyn.org
5  *
6  * Copyright (C) 1996-2017
7  *
8  * Pierangelo Masarati <masarati@aero.polimi.it>
9  * Paolo Mantegazza <mantegazza@aero.polimi.it>
10  *
11  * Dipartimento di Ingegneria Aerospaziale - Politecnico di Milano
12  * via La Masa, 34 - 20156 Milano, Italy
13  * http://www.aero.polimi.it
14  *
15  * Changing this copyright notice is forbidden.
16  *
17  * This program is free software; you can redistribute it and/or modify
18  * it under the terms of the GNU General Public License as published by
19  * the Free Software Foundation (version 2 of the License).
20  *
21  *
22  * This program is distributed in the hope that it will be useful,
23  * but WITHOUT ANY WARRANTY; without even the implied warranty of
24  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25  * GNU General Public License for more details.
26  *
27  * You should have received a copy of the GNU General Public License
28  * along with this program; if not, write to the Free Software
29  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
30  */
31 
32 /* socket driver */
33 
34 #include "mbconfig.h" /* This goes first in every *.c,*.cc file */
35 
36 /* include del programma */
37 
38 #include <sys/socket.h>
39 #include <netinet/in.h>
40 #include <arpa/inet.h>
41 #include <netdb.h>
42 
43 #include "rtai_out_elem.h"
44 #include "mbrtai_utils.h"
45 #include "dataman.h"
46 
47 /* RTMBDynOutElem - begin */
48 
49 RTMBDynOutElem::RTMBDynOutElem(unsigned int uL, const std::string& host,
50  const std::string& m, unsigned long n, bool c, StreamContent *pSC,
51  bool bNonBlocking)
52 : Elem(uL, flag(0)),
53 StreamOutElem(uL, m, 1),
54 host(host), node(n), create(c), port(-1),
55 bNonBlocking(bNonBlocking),
56 pSC(pSC),
57 mbx(0),
58 f_send(0)
59 {
60  /* RATIONALE:
61  *
62  * if host/node is present, the mailbox is "remote";
63  * if it not, we may need to create it
64  */
65 
66  if (create) {
67  ASSERT(node == 0);
68 
69  if (rtmbdyn_rt_mbx_init(name.c_str(), pSC->GetOutSize(), &mbx)) {
70  silent_cerr("RTMBDyn mailbox(" << name << ") "
71  "init failed" << std::endl);
73  }
74 
75  } else {
76  if (node) {
77  /* get port ... */
78  port = rtmbdyn_rt_request_port(node);
79  /* FIXME: what in case of failure? */
80  }
81 
82  if (rtmbdyn_RT_get_adr(node, port, name.c_str(), &mbx)) {
83  silent_cerr("RTMBDyn mailbox(" << name << ") "
84  "get_adr failed" << std::endl);
86  }
87  }
88 
89  if (bNonBlocking) {
90  f_send = rtmbdyn_RT_mbx_send_if;
91 
92  } else {
93  f_send = rtmbdyn_RT_mbx_send;
94  }
95 }
96 
98 {
99  if (mbx) {
100  rtmbdyn_rt_mbx_delete(&mbx);
101  }
102 
103  if (pSC) {
104  SAFEDELETE(pSC);
105  }
106 }
107 
108 std::ostream&
109 RTMBDynOutElem::Restart(std::ostream& out) const
110 {
111  return out << "# RTMBDynOutElem(" << GetLabel() << ") "
112  "not implemented yet" << std::endl;
113 }
114 
115 void
117  const VectorHandler& XP)
118 {
119  pSC->Prepare();
120 
121  int rc = f_send(node, -port, mbx, (void *)pSC->GetOutBuf(), pSC->GetOutSize());
122  if (rc != pSC->GetOutSize()) {
123  /* FIXME: error */
124  }
125 }
126 
127 void
129  const VectorHandler& XP, const VectorHandler& XPP)
130 {
131  AfterConvergence(X, XP);
132 }
133 
RTMBDynOutElem(unsigned int uL, const std::string &m, const std::string &host, unsigned long n, bool c, StreamContent *pSC, bool bNonBlocking)
long int flag
Definition: mbdyn.h:43
#define MBDYN_EXCEPT_ARGS
Definition: except.h:63
virtual ~RTMBDynOutElem(void)
int(* f_send)(unsigned long node, int port, void *v_mbx, void *msg, int msg_size)
Definition: rtai_out_elem.h:55
std::string name
Definition: streamoutelem.h:56
virtual void AfterConvergence(const VectorHandler &X, const VectorHandler &XP)
virtual void Prepare(void)=0
const char * host
Definition: autopilot.c:142
#define ASSERT(expression)
Definition: colamd.c:977
const void * GetOutBuf(void) const
virtual std::ostream & Restart(std::ostream &out) const
static std::stack< cleanup * > c
Definition: cleanup.cc:59
Definition: elem.h:75
StreamContent * pSC
Definition: rtai_out_elem.h:52
unsigned short int port
Definition: autopilot.c:143
unsigned long node
Definition: rtai_out_elem.h:47
unsigned int GetLabel(void) const
Definition: withlab.cc:62
int GetOutSize(void) const
#define SAFEDELETE(pnt)
Definition: mynewmem.h:710