MBDyn-1.7.3
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups
socketstream_out_elem.cc
Go to the documentation of this file.
1 /* $Header: /var/cvs/mbdyn/mbdyn/mbdyn-1.0/mbdyn/base/socketstream_out_elem.cc,v 1.68 2017/10/15 15:41:34 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 /*
33  * Michele Attolico <attolico@aero.polimi.it>
34  */
35 
36 #include "mbconfig.h" /* This goes first in every *.c,*.cc file */
37 
38 #include <cstring>
39 
40 #ifdef USE_SOCKET
41 #include <sys/types.h>
42 #include <sys/socket.h>
43 #include <netinet/in.h>
44 #include <netdb.h>
45 #include <stdio.h>
46 #include <stdlib.h>
47 #include <errno.h>
48 #include <sys/socket.h>
49 #include <netinet/in.h>
50 #include <sys/un.h>
51 #include <arpa/inet.h>
52 #endif // USE_SOCKET
53 
54 #include "dataman.h"
55 #include "socketstream_out_elem.h"
56 #include "socketstreammotionelem.h"
57 #include "sock.h"
58 
59 #ifdef USE_RTAI
60 #include "rtai_out_elem.h"
61 #endif // USE_RTAI
62 
63 #include "geomdata.h"
64 
65 #ifdef USE_SOCKET
66 
67 /* SocketStreamElem - begin */
68 
69 SocketStreamElem::SocketStreamElem(unsigned int uL,
70  const std::string& name,
71  unsigned int oe,
72  UseSocket *pUS,
73  StreamContent *pSC,
74  int flags, bool bSendFirst, bool bAbortIfBroken,
75  StreamOutEcho *pSOE)
76 : Elem(uL, flag(0)),
77 StreamOutElem(uL, name, oe),
78 pUS(pUS), pSC(pSC), send_flags(flags),
79 bSendFirst(bSendFirst), bAbortIfBroken(bAbortIfBroken),
80 pSOE(pSOE)
81 {
82  if (pSOE) {
83  pSOE->Init("SocketStreamElem", uLabel, pSC->GetNumChannels());
84  }
85 }
86 
87 SocketStreamElem::~SocketStreamElem(void)
88 {
89  if (pUS != 0) {
90  SAFEDELETE(pUS);
91  }
92 
93  if (pSC != 0) {
94  SAFEDELETE(pSC);
95  }
96 
97  if (pSOE != 0) {
98  delete pSOE;
99  }
100 }
101 
102 std::ostream&
103 SocketStreamElem::Restart(std::ostream& out) const
104 {
105  return out << "# SocketStreamElem(" << GetLabel() << "): "
106  "not implemented yet" << std::endl;
107 }
108 
109 void
110 SocketStreamElem::SetValue(DataManager *pDM,
113 {
114  if (bSendFirst) {
115  // output imposed values (before "derivatives")
116  OutputCounter = OutputEvery - 1;
117 
118  AfterConvergence(X, XP);
119  }
120 
121  // do not send "derivatives"
122  OutputCounter = -1;
123 }
124 
125 void
126 SocketStreamElem::AfterConvergence(const VectorHandler& X,
127  const VectorHandler& XP)
128 {
129  /* by now, an abandoned element does not write any more;
130  * should we retry or what? */
131  if (pUS->Abandoned()) {
132  return;
133  }
134 
135  ASSERT(pUS->Connected());
136 
137  /* output only every OutputEvery steps */
138  OutputCounter++;
139  if (OutputCounter != OutputEvery) {
140  return;
141  }
142  OutputCounter = 0;
143 
144  // prepare the output buffer
145  pSC->Prepare();
146 
147  // check whether echo is needed
148  if (pSOE) {
149  pSOE->Echo((doublereal *)pSC->GetBuf(), pSC->GetNumChannels());
150  }
151 
152  // int rc = send(pUS->GetSock(), pSC->GetOutBuf(), pSC->GetOutSize(), send_flags);
153  ssize_t rc = pUS->send(pSC->GetOutBuf(), pSC->GetOutSize(), send_flags);
154  if (rc == -1 || rc != pSC->GetOutSize()) {
155  int save_errno = errno;
156 
157  if (save_errno == EAGAIN && (send_flags & MSG_DONTWAIT)) {
158  // would block; continue (and discard...)
159  return;
160  }
161 
162  char *msg = strerror(save_errno);
163  silent_cerr("SocketStreamElem(" << name << "): send() failed "
164  "(" << save_errno << ": " << msg << ")"
165  << std::endl);
166 
167  if (bAbortIfBroken) {
168  throw NoErr(MBDYN_EXCEPT_ARGS);
169  }
170 
171  pUS->Abandon();
172  }
173 }
174 
175 void
176 SocketStreamElem::AfterConvergence(const VectorHandler& X,
177  const VectorHandler& XP, const VectorHandler& XPP)
178 {
179  AfterConvergence(X, XP);
180 }
181 
182 #endif // USE_SOCKET
183 
184 /*----------------------------------------------------------------------------
185 management of 'content type' for stream output element ('values','motion', etc)
186 ------------------------------------------------------------------------------
187 
188 Rearranged by Luca Conti (May 2017) on the basis of previous existing code
189 (fully working, just rearranged).
190 
191 Edited in order to apply the same mechanism with 'readers' and 'maps' (std::map)
192  already in use for constitutive laws and drives
193 */
194 
195 /*temporary data that allows to store all necessary information for creation
196  of socket stream output element (used by functions in struct
197 SocketStreamElemRead)*/
199  bool bIsRTAI;
202  #if defined(HAVE_GETADDRINFO)
203  struct addrinfo hints,*res;
204  int rc;
205  #elif defined(HAVE_GETHOSTBYNAME)
206  struct hostent *he;
207  #elif defined(HAVE_INET_ATON)
208  struct in_addr addr;
209  #endif // ! HAVE_GETADDRINFO && ! HAVE_GETHOSTBYNAME && ! HAVE_INET_ATON
210  std::string name;
211  std::string path;
212  std::string host;
213  bool bCreate;
215  bool bNoSignal;
218  unsigned short int port;
220  int flags;
221  unsigned int OutputEvery;
222 };
223 
224 #ifdef USE_SOCKET
225 static const int sock_stream = SOCK_STREAM;
226 static const int sock_dgram = SOCK_DGRAM;
227 #else // ! USE_SOCKET
228 static const int sock_stream = 1;
229 static const int sock_dgram = 2;
230 #endif // ! USE_SOCKET
231 
232 
233 /*these functions are called by ReadSocketStreamElem in order to get and elaborate all data necessary to create the element*/
235  virtual void getSocketStreamOutParam(DataManager *pDM, MBDynParser& HP, unsigned int uLabel, StreamContent::Type type, SocketStreamOutputDataTmp& socketStreamOutputDataTmp);
236  virtual Elem* createSocketStreamOutElem(DataManager *pDM, MBDynParser& HP, unsigned int uLabel, StreamContent::Type type, SocketStreamOutputDataTmp& socketStreamOutputDataTmp);
237 };
238 
239 Elem *
241 {
242  SocketStreamOutputDataTmp socketStreamOutputDataTmp;
243  SocketStreamOutputElemCreator socketStreamOutputElemCreator;
244  socketStreamOutputElemCreator.getSocketStreamOutParam(pDM, HP, uLabel, type, socketStreamOutputDataTmp);
245  socketStreamOutputDataTmp.pSOE = ReadStreamOutEcho(HP);
246  socketStreamOutputDataTmp.pSC = ReadStreamContent(pDM, HP, type);
247  Elem* pEl = socketStreamOutputElemCreator.createSocketStreamOutElem(pDM, HP, uLabel, type, socketStreamOutputDataTmp);
248  return pEl;
249 }
250 
252  socketStreamOutputDataTmp.bIsRTAI = false;//bool bIsRTAI(false);
253 #ifdef USE_RTAI
254  if (::rtmbdyn_rtai_task != 0) {
255  socketStreamOutputDataTmp.bIsRTAI = true;
256  }
257 #endif // USE_RTAI
258 #ifndef USE_SOCKET
259  if (!socketStreamOutputDataTmp.bIsRTAI) {
260  silent_cerr("SocketStreamElem(" << uLabel << "): "
261  "not allowed because apparently the current "
262  "architecture does not support sockets "
263  "at line " << HP.GetLineData() << std::endl);
265  }
266 #endif // ! USE_SOCKET
267 
268  socketStreamOutputDataTmp.port = (unsigned short int)(-1);
269  socketStreamOutputDataTmp.bCreate = false;
270  bool bGotCreate(false);
271 
272  if (HP.IsKeyWord("name") || HP.IsKeyWord("stream" "name")) {
273  const char *m = HP.GetStringWithDelims();
274  if (m == 0) {
275  silent_cerr("SocketStreamElem(" << uLabel << "): "
276  "unable to read stream name "
277  "at line " << HP.GetLineData() << std::endl);
279 
280  } else if (socketStreamOutputDataTmp.bIsRTAI && strlen(m) != 6) {
281  silent_cerr("SocketStreamElem(" << uLabel << "): "
282  "illegal stream name \"" << m << "\" "
283  "(must be exactly 6 chars) "
284  "at line " << HP.GetLineData() << std::endl);
286  }
287 
288  socketStreamOutputDataTmp.name = m;
289 
290  } else {
291  silent_cerr("SocketStreamElem(" << uLabel << "): "
292  "missing stream name "
293  "at line " << HP.GetLineData() << std::endl);
294  if (socketStreamOutputDataTmp.bIsRTAI) {
296  }
297  }
298 
299  if (HP.IsKeyWord("create")) {
300  bGotCreate = true;
301  if (!HP.GetYesNo(socketStreamOutputDataTmp.bCreate)) {
302  silent_cerr("SocketStreamElem(" << uLabel << "):"
303  "\"create\" must be either "
304  "\"yes\" or \"no\" "
305  "at line " << HP.GetLineData()
306  << std::endl);
308  }
309  }
310 
311  if (HP.IsKeyWord("local") || HP.IsKeyWord("path")) {
312  const char *m = HP.GetFileName();
313 
314  if (m == 0) {
315  silent_cerr("SocketStreamElem(" << uLabel << "): "
316  "unable to read local path "
317  "at line " << HP.GetLineData() << std::endl);
319  }
320 
321  socketStreamOutputDataTmp.path = m;
322  }
323 
324  if (HP.IsKeyWord("port")) {
325  if (!socketStreamOutputDataTmp.path.empty()) {
326  silent_cerr("SocketStreamElem(" << uLabel << "): "
327  "cannot specify a port for a local socket "
328  "at line " << HP.GetLineData() << std::endl);
330  }
331 
332  int p = HP.GetInt();
333 
334  if (p <= 0) {
335  silent_cerr("SocketStreamElem(" << uLabel << "): "
336  "illegal port " << p << " "
337  "at line " << HP.GetLineData() << std::endl);
339  }
340 
341  socketStreamOutputDataTmp.port = p;
342  }
343 
344  if (HP.IsKeyWord("host")) {
345  if (!socketStreamOutputDataTmp.path.empty()) {
346  silent_cerr("SocketStreamElem(" << uLabel << "): "
347  "cannot specify an allowed host "
348  "for a local socket "
349  "at line " << HP.GetLineData() << std::endl);
351  }
352 
353  const char *h;
354 
355  h = HP.GetStringWithDelims();
356  if (h == 0) {
357  silent_cerr("SocketStreamElem(" << uLabel << "): "
358  "unable to read host "
359  "at line " << HP.GetLineData() << std::endl);
361  }
362 
363  socketStreamOutputDataTmp.host = h;
364 
365  } else if (socketStreamOutputDataTmp.path.empty() && !socketStreamOutputDataTmp.bCreate) {
366  /* INET sockets (!path) must be created if host is missing */
367  silent_cerr("SocketStreamElem(" << uLabel << "): "
368  "host undefined "
369  "at line " << HP.GetLineData() << std::endl);
370  socketStreamOutputDataTmp.host = DEFAULT_HOST;
371  silent_cerr("SocketStreamElem(" << uLabel << "): "
372  "using default host: "
373  << socketStreamOutputDataTmp.host << ":"
374  << (socketStreamOutputDataTmp.port == (unsigned short int)(-1) ? DEFAULT_PORT : socketStreamOutputDataTmp.port)
375  << std::endl);
376  }
377 
378  socketStreamOutputDataTmp.socket_type = sock_stream;
379  if (HP.IsKeyWord("socket" "type")) {
380  if (HP.IsKeyWord("udp")) {
381  socketStreamOutputDataTmp.socket_type = sock_dgram;
382 
383  if (!bGotCreate) {
384  socketStreamOutputDataTmp.bCreate = true;
385  }
386 
387  } else if (!HP.IsKeyWord("tcp")) {
388  silent_cerr("SocketStreamElem(" << uLabel << "): "
389  "invalid socket type "
390  "at line " << HP.GetLineData() << std::endl);
392  }
393  }
394 
395  if (socketStreamOutputDataTmp.socket_type == sock_dgram && socketStreamOutputDataTmp.bCreate) {
396  silent_cerr("SocketStreamElem(" << uLabel << "): "
397  "socket type=udp incompatible with create=yes "
398  "at line " << HP.GetLineData() << std::endl);
400  }
401 
402  socketStreamOutputDataTmp.bNonBlocking = false;
403  socketStreamOutputDataTmp.bNoSignal = false;
404  socketStreamOutputDataTmp.bSendFirst = true;
405  socketStreamOutputDataTmp.bAbortIfBroken = false;
406  while (HP.IsArg()) {
407  if (HP.IsKeyWord("no" "signal")) {
408  socketStreamOutputDataTmp.bNoSignal = true;
409 
410  } else if (HP.IsKeyWord("signal")) {
411  socketStreamOutputDataTmp.bNoSignal = false;
412 
413  } else if (HP.IsKeyWord("blocking")) {
414  socketStreamOutputDataTmp.bNonBlocking = false;
415 
416  } else if (HP.IsKeyWord("non" "blocking")) {
417  socketStreamOutputDataTmp.bNonBlocking = true;
418 
419  } else if (HP.IsKeyWord("no" "send" "first")) {
420  socketStreamOutputDataTmp.bSendFirst = false;
421 
422  } else if (HP.IsKeyWord("send" "first")) {
423  socketStreamOutputDataTmp.bSendFirst = true;
424 
425  } else if (HP.IsKeyWord("abort" "if" "broken")) {
426  socketStreamOutputDataTmp.bAbortIfBroken = true;
427 
428  } else if (HP.IsKeyWord("do" "not" "abort" "if" "broken")) {
429  socketStreamOutputDataTmp.bAbortIfBroken = false;
430 
431  } else {
432  break;
433  }
434  }
435 
436  socketStreamOutputDataTmp.OutputEvery = 1;
437  if (HP.IsKeyWord("output" "every")) {
438  int i = HP.GetInt();
439  if (i <= 0) {
440  silent_cerr("SocketStreamElem(" << uLabel << "): "
441  "invalid output every value " << i << " "
442  "at line " << HP.GetLineData() << std::endl);
444  }
445  socketStreamOutputDataTmp.OutputEvery = (unsigned int)i;
446  }
447 
448 }
449 
451  /* Se non c'e' il punto e virgola finale */
452  if (HP.IsArg()) {
453  silent_cerr("SocketStreamElem(" << uLabel << "): "
454  "semicolon expected "
455  "at line " << HP.GetLineData() << std::endl);
457  }
458 
459  Elem *pEl = 0;
460 
461  // .log file output
462  std::ostream& out = pDM->GetLogFile();
463  out
464  << "outputelement: " << uLabel
465  << " stream";
466 
467  if (socketStreamOutputDataTmp.bIsRTAI) {
468 #ifdef USE_RTAI
469  if (socketStreamOutputDataTmp.pSOE != 0) {
470  silent_cerr("SocketStreamElem(" << uLabel << "): "
471  "echo ignored in RTAI mode"
472  << std::endl);
473  }
474 
475  unsigned long node = (unsigned long)-1;
476 #if defined(HAVE_GETADDRINFO)
477  socketStreamOutputDataTmp.hints = {0};
478  socketStreamOutputDataTmp.res = null;
479 
480  socketStreamOutputDataTmp.hints.ai_family = AF_INET;
481  socketStreamOutputDataTmp.hints.ai_socktype = SOCK_STREAM; // FIXME: what about SOCK_DGRAM?
482  socketStreamOutputDataTmp.rc = getaddrinfo(socketStreamOutputDataTmp.host.c_str(), NULL, &(socketStreamOutputDataTmp.hints), &(socketStreamOutputDataTmp.res));
483  if (socketStreamOutputDataTmp.rc == 0) {
484  node = ((struct sockaddr_in *)(socketStreamOutputDataTmp.res)->ai_addr)->sin_addr.s_addr;
485  freeaddrinfo(socketStreamOutputDataTmp.res);
486  }
487 #elif defined(HAVE_GETHOSTBYNAME)
488  socketStreamOutputDataTmp.he = gethostbyname(socketStreamOutputDataTmp.host.c_str());
489  if (socketStreamOutputDataTmp.he != NULL) {
490  node = ((unsigned long *)(socketStreamOutputDataTmp.he)->h_addr_list[0])[0];
491  }
492 #elif defined(HAVE_INET_ATON)
493  if (inet_aton(socketStreamOutputDataTmp.host.c_str(), &(socketStreamOutputDataTmp.addr))) {
494  node = socketStreamOutputDataTmp.addr.s_addr;
495  }
496 #else // ! HAVE_GETADDRINFO && ! HAVE_GETHOSTBYNAME && ! HAVE_INET_ATON
497  silent_cerr("SocketStreamElem(" << uLabel << "): "
498  "host (RTAI RPC) not supported "
499  "at line " << HP.GetLineData() << std::endl);
501 #endif // ! HAVE_GETADDRINFO && ! HAVE_GETHOSTBYNAME && ! HAVE_INET_ATON
502 
503  if (node == (unsigned long)-1) {
504  silent_cerr("RTMBDynInDrive(" << uLabel << "): "
505  "unable to convert host \"" << host << "\" to node" << std::endl);
506  throw ErrGeneric(MBDYN_EXCEPT_ARGS);
507  }
508 
509  silent_cerr("starting RTMBDynOutputElement(" << uLabel << ")..."
510  << std::endl);
512  RTMBDynOutElem(uLabel,
513  socketStreamOutputDataTmp.name, socketStreamOutputDataTmp.host, node,
514  socketStreamOutputDataTmp.bCreate, socketStreamOutputDataTmp.pSC, socketStreamOutputDataTmp.bNonBlocking));
515 
516  out
517  << " " << "RTAI"
518  << " " << name
519  << " " << host
520  << " " << node
521  << " " << bCreate;
522 
523  WriteStreamContentLogOutput(pSC, out);
524 
525 #endif // USE_RTAI
526 
527  } else {
528  socketStreamOutputDataTmp.flags = 0;
529 
530 #ifdef USE_SOCKET
531  /* node creation */
532  UseSocket *pUS = 0;
533  if (socketStreamOutputDataTmp.path.empty()) {
534  if (socketStreamOutputDataTmp.port == (unsigned short int)(-1)) {
535  socketStreamOutputDataTmp.port = DEFAULT_PORT;
536  silent_cerr("SocketStreamElem(" << uLabel << "): "
537  "port undefined; using default port "
538  << socketStreamOutputDataTmp.port << " at line "
539  << HP.GetLineData() << std::endl);
540  }
541 
542  SAFENEWWITHCONSTRUCTOR(pUS, UseInetSocket, UseInetSocket(socketStreamOutputDataTmp.host.c_str(),
543  socketStreamOutputDataTmp.port, socketStreamOutputDataTmp.socket_type, socketStreamOutputDataTmp.bCreate));
544 
545  // .log file output
546  out
547  << " " << "INET"
548  << " " << socketStreamOutputDataTmp.name
549  << " " << socketStreamOutputDataTmp.host
550  << " " << socketStreamOutputDataTmp.port;
551  if (socketStreamOutputDataTmp.socket_type == sock_dgram) {
552  out << " udp";
553  } else {
554  out << " tcp";
555  }
556  out << " " << socketStreamOutputDataTmp.bCreate;
557 
558 
559  } else {
560  SAFENEWWITHCONSTRUCTOR(pUS, UseLocalSocket, UseLocalSocket(socketStreamOutputDataTmp.path.c_str(),
561  socketStreamOutputDataTmp.socket_type, socketStreamOutputDataTmp.bCreate));
562 
563  // .log file output
564  out
565  << " " << "UNIX"
566  << " " << socketStreamOutputDataTmp.name
567  << " " << socketStreamOutputDataTmp.path;
568  if (socketStreamOutputDataTmp.socket_type == sock_dgram) {
569  out << " udp";
570  } else {
571  out << " tcp";
572  }
573  out << " " << socketStreamOutputDataTmp.bCreate;
574  }
575 
576  if (socketStreamOutputDataTmp.bCreate) {
577  pDM->RegisterSocketUser(pUS);
578 
579  } else {
580  pUS->Connect();
581  }
582 
583 #ifdef MSG_NOSIGNAL
584  if (socketStreamOutputDataTmp.bNoSignal) {
585  // NOTE: we assume MSG_NOSIGNAL is a macro...
586  socketStreamOutputDataTmp.flags |= MSG_NOSIGNAL;
587 
588  } else {
589  socketStreamOutputDataTmp.flags &= ~MSG_NOSIGNAL;
590  }
591 #else // !MSG_NOSIGNAL
592  silent_cerr("SocketStreamElem(" << uLabel << "): "
593  "MSG_NOSIGNAL undefined; "
594  "your mileage may vary" << std::endl);
595 #endif // !MSG_NOSIGNAL
596 
597 #ifdef MSG_DONTWAIT
598  // NOTE: we assume MSG_DONTWAIT is a macro...
599  if (socketStreamOutputDataTmp.bNonBlocking) {
600  socketStreamOutputDataTmp.flags |= MSG_DONTWAIT;
601 
602  } else {
603  socketStreamOutputDataTmp.flags &= ~MSG_DONTWAIT;
604  }
605 #else // !MSG_DONTWAIT
606  silent_cerr("SocketStreamElem(" << uLabel << "): "
607  "MSG_DONTWAIT undefined; "
608  "your mileage may vary" << std::endl);
609 #endif // !MSG_DONTWAIT
610 
611  silent_cerr("starting SocketStreamElem(" << uLabel << ")..."
612  << std::endl);
613  SAFENEWWITHCONSTRUCTOR(pEl, SocketStreamElem,
614  SocketStreamElem(uLabel, socketStreamOutputDataTmp.name, socketStreamOutputDataTmp.OutputEvery,
615  pUS, socketStreamOutputDataTmp.pSC, socketStreamOutputDataTmp.flags,
616  socketStreamOutputDataTmp.bSendFirst, socketStreamOutputDataTmp.bAbortIfBroken,
617  socketStreamOutputDataTmp.pSOE));
618 
619  out
620  << " " << (!socketStreamOutputDataTmp.bNoSignal)
621  << " " << (!socketStreamOutputDataTmp.bNonBlocking)
622  << " " << socketStreamOutputDataTmp.bSendFirst
623  << " " << socketStreamOutputDataTmp.bAbortIfBroken
624  << " " << socketStreamOutputDataTmp.OutputEvery;
625 
626  WriteStreamContentLogOutput(socketStreamOutputDataTmp.pSC, out);
627 
628 #endif // USE_SOCKET
629  }
630 
631  return pEl;
632 }
633 
634 void
636  std::ostream& out)
637 {
638  const StreamContentMotion* pSCM = NULL;
639  pSCM = dynamic_cast<const StreamContentMotion*>(pSC);
640 
641  if (pSCM == NULL)
642  {
643  // pSC is of type StreamContent::VALUES
644  out
645  << " values"
646  << " " << pSC->GetNumChannels()
647  << std::endl;
648  } else {
649  // pSC is of type StreamContent::MOTION
650  const unsigned uFlags = pSCM->uGetFlags();
651  out
652  << " motion"
653  << " " << bool(uFlags & GeometryData::X)
654  << " " << bool(uFlags & GeometryData::R)
655  << " " << bool(uFlags & GeometryData::RT)
656  << " " << bool(uFlags & GeometryData::V)
657  << " " << bool(uFlags & GeometryData::W);
658 
659  for (std::vector<const StructNode*>::const_iterator i = pSCM->nodes_begin();
660  i != pSCM->nodes_end(); ++i)
661  {
662  out << " " << (*i)->GetLabel();
663  }
664 
665  out << std::endl;
666  }
667 }
void WriteStreamContentLogOutput(const StreamContent *pSC, std::ostream &out)
const unsigned uGetFlags(void) const
long int flag
Definition: mbdyn.h:43
#define MBDYN_EXCEPT_ARGS
Definition: except.h:63
virtual integer GetInt(integer iDefval=0)
Definition: parser.cc:1050
void Echo(const doublereal *pbuf, unsigned nChannels)
int bool
Definition: mbdyn.h:74
void * GetBuf(void) const
virtual const char * GetFileName(enum Delims Del=DEFAULTDELIM)
Definition: parsinc.cc:673
virtual Elem * createSocketStreamOutElem(DataManager *pDM, MBDynParser &HP, unsigned int uLabel, StreamContent::Type type, SocketStreamOutputDataTmp &socketStreamOutputDataTmp)
std::vector< Hint * > Hints
Definition: simentity.h:89
static const int sock_dgram
std::vector< const StructNode * >::const_iterator nodes_begin(void) const
virtual unsigned GetNumChannels(void) const =0
bool Init(const std::string &msg, unsigned uLabel, unsigned nChannels)
StreamContent * ReadStreamContent(DataManager *pDM, MBDynParser &HP, StreamContent::Type type)
StreamOutEcho * ReadStreamOutEcho(MBDynParser &HP)
virtual bool IsKeyWord(const char *sKeyWord)
Definition: parser.cc:910
Elem * ReadSocketStreamElem(DataManager *pDM, MBDynParser &HP, unsigned int uLabel, StreamContent::Type type)
virtual void Prepare(void)=0
const char * host
Definition: autopilot.c:142
virtual void getSocketStreamOutParam(DataManager *pDM, MBDynParser &HP, unsigned int uLabel, StreamContent::Type type, SocketStreamOutputDataTmp &socketStreamOutputDataTmp)
virtual const char * GetStringWithDelims(enum Delims Del=DEFAULTDELIM, bool escape=true)
Definition: parser.cc:1228
#define DEFAULT_PORT
Definition: streamoutelem.h:40
#define ASSERT(expression)
Definition: colamd.c:977
#define SAFENEWWITHCONSTRUCTOR(pnt, item, constructor)
Definition: mynewmem.h:698
std::vector< const StructNode * >::const_iterator nodes_end(void) const
#define MSG_NOSIGNAL
Definition: sock.h:69
const void * GetOutBuf(void) const
Definition: except.h:79
virtual bool GetYesNo(bool &bRet)
Definition: parser.cc:1022
virtual bool IsArg(void)
Definition: parser.cc:807
Definition: elem.h:75
struct mbrtai_msg_t msg
std::ostream & GetLogFile(void) const
Definition: dataman.h:326
#define DEFAULT_HOST
Definition: streamoutelem.h:41
double doublereal
Definition: colamd.c:52
virtual HighParser::ErrOut GetLineData(void) const
Definition: parsinc.cc:697
static const int sock_stream
int GetOutSize(void) const
#define SAFEDELETE(pnt)
Definition: mynewmem.h:710