MAK RTIspy API Documentation for HLA 1.3
rtiUtil.h
Go to the documentation of this file.
00001 /*********************************************************************
00002 ** Copyright (c) 2003 MaK Technologies, Inc.
00003 ** All rights reserved.
00004 *********************************************************************/
00005 /*********************************************************************
00006 ** $RCSfile: rtiUtil.h,v $ $Revision: 1.23 $ $State: Exp $
00007 *********************************************************************/
00008 
00011 
00012 #ifndef DtRtiUtil_H_
00013 #define DtRtiUtil_H_
00014 
00015 #include "rtiMsConfig.h"
00016 
00017 #include <set>
00018 #include <map>
00019 #include <algorithm>
00020 #include <utility>
00021 #include <vector>
00022 
00023 #include <vlutil/vlPrint.h>
00024 #include <vlutil/vlFilename.h>
00025 #include <vlutil/vlUtil.h>
00026 #include <vlutil/vlPrint.h>
00027 #include <vlutil/vlExceptions.h>
00028 #include <vlutil/vlString.h>
00029 #include <vlutil/vlInetAddr.h>
00030 
00031 #ifndef _WIN32
00032 #ifndef __sgi__
00033 #ifndef __solaris__
00034 #include <netinet/if_ether.h>
00035 #include <net/if.h>
00036 #endif
00037 #endif
00038 #endif
00039 
00040 
00041 const unsigned int DtGreatestValidPortNumber = 65535;
00042 
00044 DT_DLL_RTIUTIL void DtRtiAttachNotificationPrinter( MAKRti::DtNotifyLevelType level, MAKRti::DtPrinter* printer );
00045 
00047 DT_DLL_RTIUTIL void DtRtiDetachNotificationPrinter( MAKRti::DtNotifyLevelType level, MAKRti::DtPrinter* printer );
00048 
00051 DT_DLL_RTIUTIL MAKRti::DtFilename DtRtiSearchPathList( const MAKRti::DtFilename& libName, 
00052                                                        const MAKRti::DtString& searchPath = "" );
00053 
00056 DT_DLL_RTIUTIL MAKRti::DtFilename DtRtiLibPath(const MAKRti::DtString& searchPath = "");
00057 
00058 
00071 DT_DLL_RTIUTIL bool DtLocateConfigFile(MAKRti::DtFilename const& fileName, MAKRti::DtFilename& locatedFileName);
00072 
00079 DT_DLL_RTIUTIL bool DtNonBlockingPollInputLine(MAKRti::DtString& buffer);
00080 
00081 
00084 DT_DLL_RTIUTIL int DtGetKey();
00085 
00088 DT_DLL_RTIUTIL int DtKBHit();
00089 
00090 DT_DLL_RTIUTIL void DtSetNotifyLevel(unsigned int notifyLevel);
00091 
00093 DT_DLL_RTIUTIL bool DtReadFile( FILE* fileHandle,
00094                              char** fileBuffer, unsigned int* fileSize);
00095 
00098 int DtBitsRequiredToRepresent(unsigned long x);
00099 
00100 
00102 DT_DLL_RTIUTIL const MAKRti::DtString& DtGetLocalHostName();
00103 
00108 DT_DLL_RTIUTIL MAKRti::DtString DtPerformDNSLookup(MAKRti::DtInetAddr addr);
00109 
00111 DT_DLL_RTIUTIL MAKRti::DtException const& DtInitialException(MAKRti::DtException const& ex);
00112 
00115 DT_DLL_RTIUTIL MAKRti::DtOutputStream& DtRtiOutputStream( MAKRti::DtNotifyLevelType level );
00116 
00117 typedef std::pair< MAKRti::DtInetAddr, int > DtInetAddrAndPort;
00118 
00119 #ifdef _WIN32
00120 DT_DLL_RTIUTIL void getRegKey( MAKRti::DtString& val, HKEY rootKey, 
00121                               const MAKRti::DtString& keyPath, const MAKRti::DtString& keyName );
00122 DT_DLL_RTIUTIL void setRegKey( const MAKRti::DtString& keyVal, HKEY rootKey, 
00123                               const MAKRti::DtString& keyPath, const MAKRti::DtString& keyName, 
00124                               bool expand );
00125 DT_DLL_RTIUTIL void removeRegKey( HKEY rootKey, const MAKRti::DtString& keyPath, 
00126                                  const MAKRti::DtString& keyName );
00127 
00128 DT_DLL_RTIUTIL void setEnvVar( const MAKRti::DtString &val, const MAKRti::DtString& name,  
00129                        bool isSystem, bool expand ) ;
00130 DT_DLL_RTIUTIL void getEnvVar( MAKRti::DtString& val, const MAKRti::DtString& name, bool isSystem );
00131 DT_DLL_RTIUTIL void removeEnvVar( const MAKRti::DtString& name, bool isSystem );
00132 
00133 DT_DLL_RTIUTIL void expandEnvVar(MAKRti::DtString& outVar );
00134 DT_DLL_RTIUTIL bool canWriteSystemPath();
00135 DT_DLL_RTIUTIL bool canWriteUserPath();
00136 
00137 
00138 
00139 DT_DLL_RTIUTIL MAKRti::DtString getAssistantRegistryString();
00140 DT_DLL_RTIUTIL void getSystemRunLocation(HKEY& rootKey, MAKRti::DtString& regPath);
00141 DT_DLL_RTIUTIL void getUserRunLocation(HKEY& rootKey, MAKRti::DtString& regPath);
00142 #endif
00143 
00144 DT_DLL_RTIUTIL void shutdownAssistant(bool force
00145 #ifdef _WIN32 
00146                                       , std::pair< void*, void* > & resultInfo );
00147 #else
00148                                       );
00149 #endif
00150 DT_DLL_RTIUTIL void startupAssistant();
00151 
00152 enum DtRtiAssistantCommandEnum
00153 {
00154    DtAssistantCommandList,
00155    DtAssistantCommandListRtiExec,
00156    DtAssistantCommandListForwarder,
00157    DtAssistantCommandKill,
00158    DtAssistantCommandDeleteFederate
00159 };
00160 
00161 struct DtRtiAssistantCommand
00162 {
00163    DtRtiAssistantCommandEnum commType;
00164    int assistantHandle;
00165    int targetFedexHandle;
00166    int targetFederateHandle;
00167 };
00168 
00169 enum DtRtiAssistantStartupRequest 
00170 { 
00171    DtAssistantStartupNoChange, 
00172    DtAssistantStartupInstallUser,
00173    DtAssistantStartupInstallSys,
00174    DtAssistantStartupUninstall 
00175 };
00176 
00177 DT_DLL_RTIUTIL bool changeAssistantStartup(DtRtiAssistantStartupRequest desiredState);
00178 DT_DLL_RTIUTIL bool removeAssistantStartup();
00179 DT_DLL_RTIUTIL void queryAssistantStartup( bool& isStartupItem, bool& isUserStartupItem );
00180 
00181 
00184 #define DtRtiFatal DtRtiOutputStream( MAKRti::DtNlFatal )
00185 #define DtRtiWarn DtRtiOutputStream( MAKRti::DtNlWarn )
00186 #define DtRtiInfo DtRtiOutputStream( MAKRti::DtNlInfo )
00187 #define DtRtiVerbose DtRtiOutputStream( MAKRti::DtNlVerbose )
00188 #define DtRtiDebug DtRtiOutputStream( MAKRti::DtNlDebug )
00189 
00191 #define DtIsMember(container, element) (container.find(element) != container.end())
00192 
00194 template<class T> void DtDeleteVectorOfPointers(T& pointerVector)
00195 {
00198    typename T::iterator iter = pointerVector.begin();
00199    while (iter != pointerVector.end())
00200    {
00201       delete *iter;
00202       iter = pointerVector.erase(iter);
00203    }
00204 }
00205 
00209 template<class T> class DtDeepCopyPointerIntoVector
00210 {
00211 private:
00212    std::vector<T*>& myVector;
00213 public:
00215    DtDeepCopyPointerIntoVector(std::vector<T*>& targetVector) : myVector(targetVector)
00216    {
00218       DtDeleteVectorOfPointers(myVector);
00219    }
00220 
00222    void operator() (T* element)
00223    {
00224       if (!element)
00225       {
00226          myVector.push_back(element);
00227       }
00228       else
00229       {
00230          myVector.push_back(new T(*element));
00231       }
00232    }
00233 };
00234 
00235 
00237 template<class T> void DtDeleteSetOfPointers(T& pointerSet)
00238 {
00241    typename T::iterator iter = pointerSet.begin();
00242    while (iter != pointerSet.end())
00243    {
00244       delete *iter;
00245       pointerSet.erase(iter);
00246       iter = pointerSet.begin();      
00247    }
00248 }
00249 
00250 
00251 
00255 template<class T> class DtDeepCopyPointerIntoSet
00256 {
00257 private:
00258    std::set<T*>& mySet;
00259 public:
00261    DtDeepCopyPointerIntoSet(std::set<T*>& targetSet) : mySet(targetSet)
00262    {
00264       DtDeleteSetOfPointers(mySet);
00265    }
00266 
00268    void operator() (T* element)
00269    {
00270       if (!element)
00271       {
00272          mySet.insert(element);
00273       }
00274       else
00275       {
00276          mySet.insert(new T(*element));
00277       }
00278    }
00279 };
00280 
00281 
00287 template<class T, class Y> class DtDeepCopyPointerIntoMap
00288 {
00289 private:
00290    std::map<T*, Y>& myMap;
00291 public:
00293    DtDeepCopyPointerIntoMap(std::map<T*, Y>& targetMap) : myMap(targetMap)
00294    {
00296       typename std::map<T*, Y>::iterator iter = myMap.begin();
00297       typename std::map<T*, Y>::iterator theEnd = myMap.end();
00298       for ( ; iter != theEnd; ++iter )
00299       {
00300          delete iter->first;
00301       }
00302       myMap.clear();
00303    }
00304 
00306    void operator() (const std::pair<T* const, Y> element)
00307    {
00308       if (!element.first)
00309       {
00310          myMap.insert(element);
00311       }
00312       else
00313       {
00314          myMap.insert(std::make_pair(new T(*element.first), element.second));
00315       }
00316    }
00317 };
00318 
00319 
00323 template< typename T, typename TContainer >
00324 bool DtUNIQUE_INSERT( const T& value, TContainer& container )
00325 {
00326    typename TContainer::iterator pos = std::find( container.begin(), container.end(), value );
00327    if ( pos != container.end() )
00328    {
00330       return false;
00331    }
00332    else
00333    {
00334       container.insert( pos, value );
00335       return true;
00336    }
00337 };
00338 
00340 #ifdef DtTHROW_PROPAGATE
00341 #undef DtTHROW_PROPAGATE
00342 #endif
00343 #define DtTHROW_PROPAGATE(exceptionClass,errorMsg, exPtr) \
00344    throw exceptionClass(MAKRti::DtString(#exceptionClass": ") + errorMsg, __DtFUNC__, MAKRti::DtFilename::stripPath(__FILE__), __LINE__, exPtr)
00345 
00346 enum DtRtiExceptionDesignator
00347 {
00348    DtRtiExceptionDesignatorDefault,
00349    DtRtiExceptionDesignatorPopup
00350 };
00351 
00352 typedef MAKRti::DtTemplatedException<DtRtiExceptionDesignatorDefault> DtRtiException;
00353 typedef MAKRti::DtTemplatedException<DtRtiExceptionDesignatorPopup>   DtRtiExceptionPopup;
00354 
00355 
00357 DT_DLL_RTIUTIL MAKRti::DtInetAddr DtDefaultInterfaceAddr();
00358 
00362 #ifndef __solaris__
00363 #ifndef __sgi__
00364 DT_DLL_RTIUTIL int DtEnumerateInterfaces(std::vector<MAKRti::DtInetAddr>& addresses,
00365                                          bool ignoreLoopback);
00368 DT_DLL_RTIUTIL bool DtIsIpOfLocalInterface(const MAKRti::DtInetAddr& addrInQuestion, bool refresh = false);
00369 #endif // sgi
00370 #endif // solaris
00371 
00372 DT_DLL_RTIUTIL unsigned long long DtFirstHostMACAddr();
00373 
00374 
00375 
00376 
00377 #endif //! DtRtiUtil_H_

Document ID: Generated on Thu Jun 14 14:15:04 EDT 2012 from SVN revision 116116
Copyright © 2005-2012 VT MÄK Inc. All Rights Reserved (www.mak.com)