MBDyn-1.7.3
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups
rtai_in_drive.h File Reference
#include "streamdrive.h"
Include dependency graph for rtai_in_drive.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

class  RTMBDynInDrive
 

Functions

DriveReadRTMBDynInDrive (const DataManager *pDM, MBDynParser &HP, unsigned int uLabel)
 

Function Documentation

Drive* ReadRTMBDynInDrive ( const DataManager pDM,
MBDynParser HP,
unsigned int  uLabel 
)

Definition at line 122 of file rtai_in_drive.cc.

References HighParser::GetInt(), IncludeParser::GetLineData(), HighParser::GetReal(), HighParser::GetStringWithDelims(), HighParser::GetYesNo(), host, HighParser::IsArg(), HighParser::IsKeyWord(), MBDYN_EXCEPT_ARGS, DataManager::pGetDrvHdl(), ReadStreamDriveModifier(), SAFENEWWITHCONSTRUCTOR, and v0.

Referenced by StreamDR::Read().

123 {
124  unsigned long node = (unsigned long)-1;
125  std::string host;
126  std::string name;
127  bool create = false;
128 
129  if (HP.IsKeyWord("stream" "drive" "name")) {
130  const char *m = HP.GetStringWithDelims();
131  if (m == NULL) {
132  silent_cerr("RTMBDynInDrive(" << uLabel << "): "
133  "unable to read mailbox name "
134  "at line " << HP.GetLineData() << std::endl);
136 
137  } else if (strlen(m) != 6) {
138  silent_cerr("RTMBDynInDrive(" << uLabel << "): "
139  "illegal mailbox name \"" << m << "\" "
140  "(must be exactly 6 chars) "
141  "at line " << HP.GetLineData() << std::endl);
143  }
144 
145  name = m;
146 
147  } else {
148  silent_cerr("RTMBDynInDrive(" << uLabel << "): "
149  "missing mailbox name "
150  "at line " << HP.GetLineData() << std::endl);
152  }
153 
154  if (HP.IsKeyWord("create")) {
155  if (!HP.GetYesNo(create)) {
156  silent_cerr("RTMBDynInDrive(" << uLabel << "): "
157  "\"create\" must be \"yes\" or \"no\" "
158  "at line " << HP.GetLineData() << std::endl);
160  }
161  }
162 
163  if (HP.IsKeyWord("non" "blocking")) {
164  silent_cout("RTMBDynInDrive(" << uLabel << "): "
165  "RTMBDyn mailboxes are always non-blocking"
166  << std::endl);
167  }
168 
169  if (HP.IsKeyWord("local") || HP.IsKeyWord("path")) {
170  const char *m = HP.GetStringWithDelims();
171 
172  silent_cout("RTMBDynInDrive(" << uLabel << "): "
173  "local path \"" << m << "\" silently ignored"
174  << std::endl);
175  }
176 
177  if (HP.IsKeyWord("port")){
178  int p = HP.GetInt();
179 
180  silent_cout("RTMBDynInDrive(" << uLabel << "): "
181  "port " << p << " silently ignored" << std::endl);
182  }
183 
184  if (HP.IsKeyWord("host")) {
185  const char *h;
186 
187  h = HP.GetStringWithDelims();
188  if (h == NULL) {
189  silent_cerr("RTMBDynInDrive(" << uLabel << "): "
190  "unable to read host "
191  "at line " << HP.GetLineData() << std::endl);
193  }
194 
195  if (create) {
196  silent_cout("RTMBDynInDrive(" << uLabel << "): "
197  "host name \"" << h << "\" silently ignored"
198  << std::endl);
199  } else {
200  host = h;
201 
202  // resolve host
203  // TODO: add support for getnameinfo()
204 #if defined(HAVE_GETADDRINFO)
205  struct addrinfo hints = { 0 }, *res = NULL;
206  int rc;
207 
208  hints.ai_family = AF_INET;
209  hints.ai_socktype = SOCK_STREAM; // FIXME: SOCK_DGRAM?
210  rc = getaddrinfo(host.c_str(), NULL, &hints, &res);
211  if (rc == 0) {
212  node = ((struct sockaddr_in *)res->ai_addr)->sin_addr.s_addr;
213  freeaddrinfo(res);
214  }
215 #elif defined(HAVE_GETHOSTBYNAME)
216  // FIXME: non-reentrant
217  struct hostent *he = gethostbyname(host.c_str());
218  if (he != NULL)
219  {
220  node = ((unsigned long *)he->h_addr_list[0])[0];
221  }
222 #elif defined(HAVE_INET_ATON)
223  struct in_addr addr;
224  if (inet_aton(host.c_str(), &addr)) {
225  node = addr.s_addr;
226  }
227 #else // ! HAVE_GETADDRINFO && ! HAVE_GETHOSTBYNAME && ! HAVE_INET_ATON
228  silent_cerr("RTMBDynInDrive(" << uLabel << "): "
229  "host (RTAI RPC) not supported "
230  "at line " << HP.GetLineData() << std::endl);
232 #endif // ! HAVE_GETADDRINFO && ! HAVE_GETHOSTBYNAME && ! HAVE_INET_ATON
233 
234  if (node == (unsigned long)-1) {
235  silent_cerr("RTMBDynInDrive(" << uLabel << "): "
236  "unable to convert host \"" << host << "\" to node" << std::endl);
238  }
239  }
240  }
241 
242  bool bNonBlocking(true);
243  while (HP.IsArg()) {
244  if (HP.IsKeyWord("signal")) {
245  // ignore
246 
247  } else if (HP.IsKeyWord("no" "signal")) {
248  // ignore
249 
250  } else if (HP.IsKeyWord("blocking")) {
251  bNonBlocking = false;
252 
253  } else if (HP.IsKeyWord("non" "blocking")) {
254  bNonBlocking = true;
255 
256  } else {
257  break;
258  }
259  }
260 
261  int idrives = HP.GetInt();
262  if (idrives <= 0) {
263  silent_cerr("RTMBDynInDrive(" << uLabel << "): "
264  "illegal number of channels "
265  "at line " << HP.GetLineData() << std::endl);
267  }
268 
269  std::vector<doublereal> v0;
270  if (HP.IsKeyWord("initial" "values")) {
271  v0.resize(idrives);
272  for (int i = 0; i < idrives; i++) {
273  v0[i] = HP.GetReal();
274  }
275  }
276 
277  StreamDrive::Modifier *pMod(0);
278  if (HP.IsKeyWord("modifier")) {
279  pMod = ReadStreamDriveModifier(HP, idrives);
280  }
281 
282  Drive* pDr = NULL;
284  RTMBDynInDrive(uLabel,
285  pDM->pGetDrvHdl(),
286  name, host, idrives, v0, pMod,
287  create, node, bNonBlocking));
288 
289  return pDr;
290 }
#define MBDYN_EXCEPT_ARGS
Definition: except.h:63
virtual integer GetInt(integer iDefval=0)
Definition: parser.cc:1050
Definition: drive.h:89
StreamDrive::Modifier * ReadStreamDriveModifier(MBDynParser &HP, integer nDrives)
Definition: streamdrive.cc:169
const DriveHandler * pGetDrvHdl(void) const
Definition: dataman.h:340
virtual bool IsKeyWord(const char *sKeyWord)
Definition: parser.cc:910
const char * host
Definition: autopilot.c:142
virtual const char * GetStringWithDelims(enum Delims Del=DEFAULTDELIM, bool escape=true)
Definition: parser.cc:1228
#define SAFENEWWITHCONSTRUCTOR(pnt, item, constructor)
Definition: mynewmem.h:698
virtual bool GetYesNo(bool &bRet)
Definition: parser.cc:1022
virtual bool IsArg(void)
Definition: parser.cc:807
static const std::vector< doublereal > v0
Definition: fixedstep.cc:45
virtual HighParser::ErrOut GetLineData(void) const
Definition: parsinc.cc:697
virtual doublereal GetReal(const doublereal &dDefval=0.0)
Definition: parser.cc:1056

Here is the call graph for this function: