MAK RTIspy API Documentation for HLA 1.3
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
rtiUtil.h
Go to the documentation of this file.
1 /*********************************************************************
2 ** Copyright (c) 2003 MaK Technologies, Inc.
3 ** All rights reserved.
4 *********************************************************************/
5 /*********************************************************************
6 ** $RCSfile: rtiUtil.h,v $ $Revision: 1.23 $ $State: Exp $
7 *********************************************************************/
8 
11 
12 #ifndef DtRtiUtil_H_
13 #define DtRtiUtil_H_
14 
15 #include "rtiMsConfig.h"
16 
17 #include <set>
18 #include <map>
19 #include <algorithm>
20 #include <utility>
21 #include <vector>
22 
23 #include <vlutil/vlPrint.h>
24 #include <vlutil/vlFilename.h>
25 #include <vlutil/vlUtil.h>
26 #include <vlutil/vlPrint.h>
27 #include <vlutil/vlExceptions.h>
28 #include <vlutil/vlString.h>
29 #include <vlutil/vlInetAddr.h>
30 
31 #ifndef _WIN32
32 #ifndef __sgi__
33 #ifndef __solaris__
34 #include <netinet/if_ether.h>
35 #include <net/if.h>
36 #endif
37 #endif
38 #endif
39 
40 #define MAKRTI_MT
41 namespace MAKRti
42 {
43  class DtClock;
44 }
45 
46 #ifdef MAKRTI_MT
47 #define MAK_STATIC
48 #else
49 #define MAK_STATIC static
50 #endif
51 
52 const unsigned int DtGreatestValidPortNumber = 65535;
53 
55 DT_DLL_RTIUTIL void DtRtiAttachNotificationPrinter( MAKRti::DtNotifyLevelType level, MAKRti::DtPrinter* printer );
56 
58 DT_DLL_RTIUTIL void DtRtiDetachNotificationPrinter( MAKRti::DtNotifyLevelType level, MAKRti::DtPrinter* printer );
59 
62 DT_DLL_RTIUTIL MAKRti::DtFilename DtRtiSearchPathList( const MAKRti::DtFilename& libName,
63  const MAKRti::DtString& searchPath = "" );
64 
67 DT_DLL_RTIUTIL MAKRti::DtFilename DtRtiLibPath(const MAKRti::DtString& searchPath = "");
68 
71 DT_DLL_RTIUTIL MAKRti::DtString& DtMakeFileNameUnique(MAKRti::DtString& fileName);
72 
75 DT_DLL_RTIUTIL MAKRti::DtFilename& DtResolveAbsoluteFileLocation(const MAKRti::DtString& path,
76  const MAKRti::DtString& fileName, MAKRti::DtFilename& resolvedFilePath);
77 
80 DT_DLL_RTIUTIL MAKRti::DtFilename& DtMakeLogFilePath(const MAKRti::DtString& baseFilePath,
81  const MAKRti::DtString& fileName, bool makeUnique, MAKRti::DtFilename& resolvedFilePath);
82 
84 DT_DLL_RTIUTIL MAKRti::DtString DtGetProcessName();
85 
98 DT_DLL_RTIUTIL bool DtLocateConfigFile(MAKRti::DtFilename const& fileName, MAKRti::DtFilename& locatedFileName);
99 
106 DT_DLL_RTIUTIL bool DtNonBlockingPollInputLine(MAKRti::DtString& buffer);
107 
108 
112 
115 DT_DLL_RTIUTIL int DtKBHit();
116 
117 DT_DLL_RTIUTIL void DtSetNotifyLevel(unsigned int notifyLevel);
118 
120 DT_DLL_RTIUTIL bool DtReadFile( FILE* fileHandle,
121  char** fileBuffer, unsigned int* fileSize);
122 
125 DT_DLL_RTIUTIL int DtBitsRequiredToRepresent(unsigned long x);
126 
127 
129 DT_DLL_RTIUTIL const MAKRti::DtString& DtGetLocalHostName();
130 
132 DT_DLL_RTIUTIL void DtGetLocalHostName(MAKRti::DtString& hostName);
133 
138 DT_DLL_RTIUTIL MAKRti::DtString DtPerformDNSLookup(MAKRti::DtInetAddr addr);
139 
141 DT_DLL_RTIUTIL MAKRti::DtException const& DtInitialException(MAKRti::DtException const& ex);
142 
145 DT_DLL_RTIUTIL MAKRti::DtOutputStream& DtRtiOutputStream( MAKRti::DtNotifyLevelType level );
146 
147 typedef std::pair< MAKRti::DtInetAddr, int > DtInetAddrAndPort;
148 
149 DT_DLL_RTIUTIL MAKRti::DtString addrAndPortToString(const DtInetAddrAndPort& addrPort);
150 
151 #ifdef _WIN32
152 DT_DLL_RTIUTIL void getRegKey( MAKRti::DtString& val, HKEY rootKey,
153  const MAKRti::DtString& keyPath, const MAKRti::DtString& keyName );
154 DT_DLL_RTIUTIL void setRegKey( const MAKRti::DtString& keyVal, HKEY rootKey,
155  const MAKRti::DtString& keyPath, const MAKRti::DtString& keyName,
156  bool expand );
157 DT_DLL_RTIUTIL void removeRegKey( HKEY rootKey, const MAKRti::DtString& keyPath,
158  const MAKRti::DtString& keyName );
159 
160 DT_DLL_RTIUTIL void setEnvVar( const MAKRti::DtString &val, const MAKRti::DtString& name,
161  bool isSystem, bool expand ) ;
162 DT_DLL_RTIUTIL void getEnvVar( MAKRti::DtString& val, const MAKRti::DtString& name, bool isSystem );
163 DT_DLL_RTIUTIL void removeEnvVar( const MAKRti::DtString& name, bool isSystem );
164 
165 DT_DLL_RTIUTIL void expandEnvVar(MAKRti::DtString& outVar );
166 DT_DLL_RTIUTIL bool canWriteSystemPath();
167 DT_DLL_RTIUTIL bool canWriteUserPath();
168 
169 
170 
171 DT_DLL_RTIUTIL MAKRti::DtString getAssistantRegistryString();
172 DT_DLL_RTIUTIL void getSystemRunLocation(HKEY& rootKey, MAKRti::DtString& regPath);
173 DT_DLL_RTIUTIL void getUserRunLocation(HKEY& rootKey, MAKRti::DtString& regPath);
174 #endif
175 
176 DT_DLL_RTIUTIL void shutdownAssistant(bool force
177 #ifdef _WIN32
178  , std::pair< void*, void* > & resultInfo );
179 #else
180  );
181 #endif
183 
185 {
191 };
192 
194 {
199 };
200 
202 {
207 };
208 
211 DT_DLL_RTIUTIL void queryAssistantStartup( bool& isStartupItem, bool& isUserStartupItem );
212 
213 
216 #define DtRtiFatal DtRtiOutputStream( MAKRti::DtNlFatal )
217 #define DtRtiWarn DtRtiOutputStream( MAKRti::DtNlWarn )
218 #define DtRtiInfo DtRtiOutputStream( MAKRti::DtNlInfo )
219 #define DtRtiVerbose DtRtiOutputStream( MAKRti::DtNlVerbose )
220 #define DtRtiDebug DtRtiOutputStream( MAKRti::DtNlDebug )
221 
223 #define DtIsMember(container, element) (container.find(element) != container.end())
224 
226 template<class T> void DtDeleteVectorOfPointers(T& pointerVector)
227 {
230  typename T::iterator iter = pointerVector.begin();
231  while (iter != pointerVector.end())
232  {
233  delete *iter;
234  iter = pointerVector.erase(iter);
235  }
236 }
237 
241 template<class T> class DtDeepCopyPointerIntoVector
242 {
243 private:
244  std::vector<T*>& myVector;
245 public:
247  DtDeepCopyPointerIntoVector(std::vector<T*>& targetVector) : myVector(targetVector)
248  {
251  }
252 
254  void operator() (T* element)
255  {
256  if (!element)
257  {
258  myVector.push_back(element);
259  }
260  else
261  {
262  myVector.push_back(new T(*element));
263  }
264  }
265 };
266 
267 
269 template<class T> void DtDeleteSetOfPointers(T& pointerSet)
270 {
273  typename T::iterator iter = pointerSet.begin();
274  while (iter != pointerSet.end())
275  {
276  delete *iter;
277  pointerSet.erase(iter);
278  iter = pointerSet.begin();
279  }
280 }
281 
282 
283 
287 template<class T> class DtDeepCopyPointerIntoSet
288 {
289 private:
290  std::set<T*>& mySet;
291 public:
293  DtDeepCopyPointerIntoSet(std::set<T*>& targetSet) : mySet(targetSet)
294  {
297  }
298 
300  void operator() (T* element)
301  {
302  if (!element)
303  {
304  mySet.insert(element);
305  }
306  else
307  {
308  mySet.insert(new T(*element));
309  }
310  }
311 };
312 
313 
319 template<class T, class Y> class DtDeepCopyPointerIntoMap
320 {
321 private:
322  std::map<T*, Y>& myMap;
323 public:
325  DtDeepCopyPointerIntoMap(std::map<T*, Y>& targetMap) : myMap(targetMap)
326  {
328  typename std::map<T*, Y>::iterator iter = myMap.begin();
329  typename std::map<T*, Y>::iterator theEnd = myMap.end();
330  for ( ; iter != theEnd; ++iter )
331  {
332  delete iter->first;
333  }
334  myMap.clear();
335  }
336 
338  void operator() (const std::pair<T* const, Y> element)
339  {
340  if (!element.first)
341  {
342  myMap.insert(element);
343  }
344  else
345  {
346  myMap.insert(std::make_pair(new T(*element.first), element.second));
347  }
348  }
349 };
350 
351 
355 template< typename T, typename TContainer >
356 bool DtUNIQUE_INSERT( const T& value, TContainer& container )
357 {
358  typename TContainer::iterator pos = std::find( container.begin(), container.end(), value );
359  if ( pos != container.end() )
360  {
362  return false;
363  }
364  else
365  {
366  container.insert( pos, value );
367  return true;
368  }
369 };
370 
372 #ifdef DtTHROW_PROPAGATE
373 #undef DtTHROW_PROPAGATE
374 #endif
375 #define DtTHROW_PROPAGATE(exceptionClass,errorMsg, exPtr) \
376  throw exceptionClass(MAKRti::DtString(#exceptionClass": ") + errorMsg, __DtFUNC__, MAKRti::DtFilename::stripPath(__FILE__), __LINE__, exPtr)
377 
379 {
383 };
384 
385 typedef MAKRti::DtTemplatedException<DtRtiExceptionDesignatorDefault> DtRtiException;
386 typedef MAKRti::DtTemplatedException<DtRtiExceptionDesignatorPopup> DtRtiExceptionPopup;
387 typedef MAKRti::DtTemplatedException<DtRtiExceptionDesignatorInvalidRidExpression> DtRtiExceptionInvalidRidExpression;
388 
389 DT_DLL_RTIUTIL typedef std::set<MAKRti::DtInetAddr> DtInetAddrSet;
390 
392 DT_DLL_RTIUTIL MAKRti::DtInetAddr DtDefaultInterfaceAddr();
393 
397 #ifndef __solaris__
398 #ifndef __sgi__
399 DT_DLL_RTIUTIL int DtEnumerateInterfaces(std::vector<MAKRti::DtInetAddr>& addresses,
400  bool ignoreLoopback);
403 DT_DLL_RTIUTIL bool DtIsIpOfLocalInterface(const MAKRti::DtInetAddr& addrInQuestion, bool refresh = false);
404 #endif // sgi
405 #endif // solaris
406 
407 DT_DLL_RTIUTIL unsigned long long DtFirstHostMACAddr();
408 
411 DT_DLL_RTIUTIL MAKRti::DtString timeString(const MAKRti::DtClock& clock);
412 
414 DT_DLL_RTIUTIL MAKRti::DtString timeString();
415 
417 DT_DLL_RTIUTIL void writeMessageToStdErrPipe(const MAKRti::DtString& msg);
418 
419 
420 #endif
Definition: rtiUtil.h:380
void operator()(T *element)
Function operator.
Definition: rtiUtil.h:254
DT_DLL_RTIUTIL MAKRti::DtInetAddr DtDefaultInterfaceAddr()
Get&#39;s the address of the default network interface on this machine.
std::pair< MAKRti::DtInetAddr, int > DtInetAddrAndPort
Definition: rtiUtil.h:147
DT_DLL_RTIUTIL void DtSetNotifyLevel(unsigned int notifyLevel)
DT_DLL_RTIUTIL MAKRti::DtFilename & DtResolveAbsoluteFileLocation(const MAKRti::DtString &path, const MAKRti::DtString &fileName, MAKRti::DtFilename &resolvedFilePath)
Returns the absolute file location Returns the constructed file name in the file name given as a para...
void operator()(const std::pair< T *const, Y > element)
Function operator.
Definition: rtiUtil.h:338
DT_DLL_RTIUTIL int DtGetKey()
Returns a single character of input from stdin.
Definition: rtiUtil.h:204
DT_DLL_RTIUTIL void DtRtiAttachNotificationPrinter(MAKRti::DtNotifyLevelType level, MAKRti::DtPrinter *printer)
Windows only: Attach a MAKRti::DtPrinter to the RTI .dll&#39;s internal notification stream, since they are not exported.
Definition: rtiUtil.h:189
std::map< T *, Y > & myMap
Definition: rtiUtil.h:322
DT_DLL_RTIUTIL void shutdownAssistant(bool force)
DT_DLL_RTIUTIL bool DtNonBlockingPollInputLine(MAKRti::DtString &buffer)
Polls line-buffered standard input without blocking execution.
DT_DLL_RTIUTIL MAKRti::DtString DtGetProcessName()
Return the process name of the current process.
DT_DLL_RTIUTIL void startupAssistant()
bool DtUNIQUE_INSERT(const T &value, TContainer &container)
Insert a copy of a value into a container IF that value is not already in the container If the value ...
Definition: rtiUtil.h:356
Definition: rtiUtil.h:190
DT_DLL_RTIUTIL MAKRti::DtString DtPerformDNSLookup(MAKRti::DtInetAddr addr)
Could be costly operation.
DT_DLL_RTIUTIL int DtBitsRequiredToRepresent(unsigned long x)
Return the number of bits required to represent the given value as an unsigned integer.
DT_DLL_RTIUTIL void writeMessageToStdErrPipe(const MAKRti::DtString &msg)
Write the given message to a stdErr pipe.
DtDeepCopyPointerIntoMap(std::map< T *, Y > &targetMap)
Constructor.
Definition: rtiUtil.h:325
Definition: rtiUtil.h:193
std::set< T * > & mySet
Definition: rtiUtil.h:290
DT_DLL_RTIUTIL MAKRti::DtString timeString(const MAKRti::DtClock &clock)
Return a string representing elapsed time and absolute time in seconds from clock wall clock time fro...
void DtDeleteVectorOfPointers(T &pointerVector)
Delete elements of a vector of pointers.
Definition: rtiUtil.h:226
Deep copy a vector pointer entry into the provided target vector This helper functor is used in for_e...
Definition: rtiUtil.h:241
const unsigned int DtGreatestValidPortNumber
Definition: rtiUtil.h:52
void operator()(T *element)
Function operator.
Definition: rtiUtil.h:300
int targetFedexHandle
Definition: rtiUtil.h:197
DtRtiAssistantCommandEnum
Definition: rtiUtil.h:184
DT_DLL_RTIUTIL bool DtReadFile(FILE *fileHandle, char **fileBuffer, unsigned int *fileSize)
Read an opened file into a new buffer of returned size.
Definition: rtiUtil.h:188
DT_DLL_RTIUTIL int DtKBHit()
Detect if there has been a button press on stdin.
DT_DLL_RTIUTIL MAKRti::DtException const & DtInitialException(MAKRti::DtException const &ex)
Return the initial exception if exceptions were chained or this one if not.
DT_DLL_RTIUTIL MAKRti::DtFilename DtRtiLibPath(const MAKRti::DtString &searchPath="")
Search the system path for the RTI library and return the path to it If searchPath isn&#39;t specified...
MAKRti::DtTemplatedException< DtRtiExceptionDesignatorDefault > DtRtiException
Definition: rtiUtil.h:385
DtRtiExceptionDesignator
Definition: rtiUtil.h:378
DT_DLL_RTIUTIL MAKRti::DtString addrAndPortToString(const DtInetAddrAndPort &addrPort)
DT_DLL_RTIUTIL typedef std::set< MAKRti::DtInetAddr > DtInetAddrSet
Definition: rtiUtil.h:389
Definition: rtiUtil.h:381
DT_DLL_RTIUTIL int DtEnumerateInterfaces(std::vector< MAKRti::DtInetAddr > &addresses, bool ignoreLoopback)
Populate addresses with the IPs of local NICs.
std::vector< T * > & myVector
Definition: rtiUtil.h:244
DtRtiAssistantStartupRequest
Definition: rtiUtil.h:201
DT_DLL_RTIUTIL bool changeAssistantStartup(DtRtiAssistantStartupRequest desiredState)
DT_DLL_RTIUTIL MAKRti::DtString & DtMakeFileNameUnique(MAKRti::DtString &fileName)
Given the filepath, append unique characters to base file name to make it unique Returns the submitte...
Deep copy a map pointer entry into the provided target map This helper functor is used in for_each to...
Definition: rtiUtil.h:319
DT_DLL_RTIUTIL const MAKRti::DtString & DtGetLocalHostName()
Returns the local hostname. Not threadsafe.
DT_DLL_RTIUTIL MAKRti::DtFilename & DtMakeLogFilePath(const MAKRti::DtString &baseFilePath, const MAKRti::DtString &fileName, bool makeUnique, MAKRti::DtFilename &resolvedFilePath)
Makes a log file name from the given path and file name.
DtDeepCopyPointerIntoVector(std::vector< T * > &targetVector)
Constructor.
Definition: rtiUtil.h:247
Definition: rtiUtil.h:205
DT_DLL_RTIUTIL bool DtLocateConfigFile(MAKRti::DtFilename const &fileName, MAKRti::DtFilename &locatedFileName)
Locate a configuration file in the following order.
DT_DLL_RTIUTIL void queryAssistantStartup(bool &isStartupItem, bool &isUserStartupItem)
DtDeepCopyPointerIntoSet(std::set< T * > &targetSet)
Constructor.
Definition: rtiUtil.h:293
Definition: rtiUtil.h:187
DT_DLL_RTIUTIL unsigned long long DtFirstHostMACAddr()
Definition: rtiUtil.h:203
int assistantHandle
Definition: rtiUtil.h:196
DT_DLL_RTIUTIL MAKRti::DtFilename DtRtiSearchPathList(const MAKRti::DtFilename &libName, const MAKRti::DtString &searchPath="")
Search the system path for the specified library by name, and return the path to it If searchPath isn...
MAKRti::DtTemplatedException< DtRtiExceptionDesignatorPopup > DtRtiExceptionPopup
Definition: rtiUtil.h:386
DT_DLL_RTIUTIL bool removeAssistantStartup()
MAKRti::DtTemplatedException< DtRtiExceptionDesignatorInvalidRidExpression > DtRtiExceptionInvalidRidExpression
Definition: rtiUtil.h:387
#define DT_DLL_RTIUTIL
Definition: rtiMsConfig.h:127
DT_DLL_RTIUTIL bool DtIsIpOfLocalInterface(const MAKRti::DtInetAddr &addrInQuestion, bool refresh=false)
returns true for isAnyAddr, and if DtInetaddr matches ip of a local interface.
DT_DLL_RTIUTIL void DtRtiDetachNotificationPrinter(MAKRti::DtNotifyLevelType level, MAKRti::DtPrinter *printer)
Windows only: Detach a MAKRti::DtPrinter from the RTI .dll&#39;s internal notification stream...
void DtDeleteSetOfPointers(T &pointerSet)
Delete elements of a set of pointers.
Definition: rtiUtil.h:269
Definition: rtiUtil.h:186
int targetFederateHandle
Definition: rtiUtil.h:198
DT_DLL_RTIUTIL MAKRti::DtOutputStream & DtRtiOutputStream(MAKRti::DtNotifyLevelType level)
Return a reference to the RTI&#39;s MAKRti::DtOutputStream objects so plugins and applications can log to...
Deep copy a set pointer entry into the provided target set This helper functor is used in for_each to...
Definition: rtiUtil.h:287
Definition: rtiUtil.h:206
DtRtiAssistantCommandEnum commType
Definition: rtiUtil.h:195

Document ID: Generated on Mon Sep 7 15:40:32 EDT 2020 from SVN revision 217499
Copyright © 2005-2020 MAK Technologies Inc. All Rights Reserved (www.mak.com)