![]() |
MAK RTIspy API Documentation for HLA Evolved
|
00001 /****************************************************************************** 00002 ** Copyright (c) 2006 MaK Technologies, Inc. 00003 ** All rights reserved. 00004 ******************************************************************************/ 00005 /****************************************************************************** 00006 ** $RCSfile: simpleDDMSimple13.h,v $ $Revision: 1.2 $ $State: Exp $ 00007 ******************************************************************************/ 00008 00009 #ifndef REGIONEXAMPLE13_H_ 00010 #define REGIONEXAMPLE13_H_ 00011 00012 // A wrapper around the RTI Ambassador calls that incorporates 00013 // Data Distribution Management (DDM). 00014 // The typical calls are supported such as create/destroy, join/resign, 00015 // publish/subscribe, register/delete object, update object, and send interaction. 00016 // The DDM calls to create and maintain regions are also supported and regions 00017 // are used with the other services where appropriate. 00018 00019 #include "simpleDDMFederate.h" 00020 #include <string.h> 00021 #include "RTI.hh" 00022 #include "simpleDDMFedAmb13.h" 00023 00024 // Map between strings and attribute handles 00025 typedef std::map<std::string, RTI::AttributeHandle> DtAttrNameHandleMap; 00026 // Map between strings and parameter handles 00027 typedef std::map<std::string, RTI::ParameterHandle> DtParamNameHandleMap; 00028 00029 00030 class simpleDDMFederate13 : public simpleDDMFederate 00031 { 00032 public: 00033 00035 // Default Constructor 00037 simpleDDMFederate13(); 00038 00040 // Constructor 00042 simpleDDMFederate13(simpleDDMFederate13& data); 00043 00045 // Destructor 00047 ~simpleDDMFederate13(); 00048 00049 // RTI Wrappers 00050 00052 // Initialize the RTI 00054 void initializeRTI(); 00055 00057 // Create a federation execution 00059 bool createFedEx(); 00060 00062 // Join a federation execution 00064 bool joinFedEx(); 00065 00067 // Resign from the federation execution and destroy it 00069 void resignAndDestroy(); 00070 00072 // Create the Region and initialize its bounds 00074 bool createAndInitializeRegions(); 00075 00077 // Publish and subscribe the object class attributes. 00078 // Register an object instance of the class. 00080 bool publishSubscribeAndRegisterObject(); 00081 00083 // Publish and Subscribe to an interaction class 00085 bool publishAndSubscribeInteraction(); 00086 00088 // Send the default update with Region. A less simple federate would have to 00089 // specify which attributes need be updated. This on merely passes in the 00090 // position which is sent with Region as the object update. 00092 void sendUpdate(int currentPosition ); 00093 00095 // Send Interactions with Region. The following two interactions are meant to 00096 // emulate a cuckoo clock with both an hourly chime, and a quarterly chime. 00098 00100 // Send the hourly interaction with Region. This is an interaction that in this 00101 // example occurs for each hour that is passed on the clock that is not 00102 // {12,3,6,9}. 00104 void sendInteraction_hourly(); 00105 00107 // Send the quarterly interaction with Region. This is an interaction that in 00108 // this example occurs for each hour that is passed on the clock that is in the 00109 // following set {12,3,6,9} 00111 void sendInteraction_quarterly(); 00112 00114 // Perform the tick or evokeCallback method. 00116 void tick(double atMost=0.0f); 00117 00119 // Perform the tick or evokeCallback method. 00121 void tick(double atLeast, double atMost); 00122 00124 // changeBounds sets the subscription of publication bounds of this federate. 00126 void changeBounds(int lower, int upper, int UTCZone) ; 00127 00129 // Set the RTI's enable advisory switch 00131 void setEnableScopeAdvisories(bool yesNo); 00132 00133 // Simulation Methods 00134 00136 // Set federate as publisher (true) or subscriber (false) 00138 void setIsPublisher(bool yesNo); 00139 00141 // Get the position (number of seconds) 00143 int position(); 00144 00146 // Set the position (number of seconds) 00148 void setPosition(int data); 00149 00151 // Set the Fed File Name 00153 void setFedFileName(const char* newFedName); 00154 00156 // Set the Fed File Name 00158 void setFedFileName(const wchar_t* newFedName); 00159 00161 // Get the Fed File Name 00163 char* getFedFileName() const; 00164 00165 00166 protected: 00167 00168 // Map between strings and attribute handles 00169 DtAttrNameHandleMap myAttrNameHandleMap; 00170 00171 // Map between strings and parameter handles 00172 DtParamNameHandleMap myParamNameHandleMap; 00173 00174 static const unsigned int myNumAttributes; 00175 static const unsigned long myNumExtents; 00176 00177 // Array of attributeHandles. 00178 RTI::AttributeHandle* myAttrHandlesArray; 00179 00180 RTI::AttributeHandleSet* myAttrHandlesSet; 00181 00182 RTI::AttributeHandleValuePairSet *myAttrValues; 00183 00184 // Data shared between federate and federate ambassador 00185 DtTalkAmbData myAmbData; 00186 00187 private: 00188 // Federate and Federation info 00189 std::string myFederationName; 00190 std::string myFederationFile; 00191 std::string myFederateType; 00192 00193 // An interaction published at {1, 2, 4, 5, 7, 8, 10 , 11} 00194 std::string myHourlyInteraction; 00195 00196 // An interaction published at {3,6,9,12} 00197 std::string myQuarterlyInteraction; 00198 00199 // The interaction class name 00200 std::string myInterClassName; 00201 00202 // The object class name 00203 std::string myClassName; 00204 00205 // The attribute name 00206 std::string myAttrName; 00207 00208 // The number of dimensions 00209 unsigned int myNumberOfDimensions; 00210 00211 // The RTI Ambassador 00212 RTI::RTIambassador* myRTIamb; 00213 00214 // The Federate Ambassador 00215 MyFederateAmbassador* myFedAmb; 00216 00217 // the Handle for the hourlyInteraction, (to be retrieved from RTI). 00218 RTI::ParameterHandle myHourlyHandle; 00219 00220 // the Handle for the quarterlyInteraction, (to be retrieved from RTI). 00221 RTI::ParameterHandle myQuarterlyHandle; 00222 00223 00224 // Construct a parameter handle value pair set with the 00225 // values containing the parameter names 00226 RTI::ParameterHandleValuePairSet* myParamValues; 00227 00228 // The name of the dimension is specified in your FED file. 00229 std::string mySecondsDimensionName; 00230 00231 // The time zone dimension name 00232 std::string myUTCDimensionName; 00233 00234 // The routing space name 00235 std::string mySpaceName; 00236 00237 // The object class handle (to be retrieved from RTI). 00238 RTI::ObjectClassHandle myClassHandle; 00239 00240 //The object instance handle ( to be retrieved from the rti). 00241 RTI::ObjectHandle myObjectHandle; 00242 00243 // The interaction class handle (to be retrieved from RTI). 00244 RTI::InteractionClassHandle myInterClassHandle; 00245 00246 // The Seconds dimension handle (to be retrieved from the RTI). 00247 RTI::DimensionHandle mySecondsDimHandle; 00248 00249 // The UTC dimension handle (to be retrieved from the RTI). 00250 RTI::DimensionHandle myUTCDimHandle; 00251 00252 // The listen region 00253 RTI::Region* myListenRegion; 00254 00255 // The publish region 00256 RTI::Region* mySendRegion; 00257 00258 00259 }; 00260 00261 inline void simpleDDMFederate13::setIsPublisher(bool yesNo) 00262 { 00263 myIsPublisher = yesNo; 00264 myAmbData.isPublisher = yesNo; 00265 } 00266 00267 inline void simpleDDMFederate13::setEnableScopeAdvisories(bool yesNo) 00268 { 00269 myEnableScopeAdvisories = yesNo; 00270 myAmbData.enableScopeAdvisories = yesNo; 00271 } 00272 00273 inline int simpleDDMFederate13::position() 00274 { 00275 if (!isPublisher()) 00276 myCurrentposition = myAmbData.position; 00277 return myCurrentposition; 00278 } 00279 00280 inline void simpleDDMFederate13::setFedFileName(const char* newFedName) 00281 { 00282 myFederationFile = std::string(newFedName); 00283 } 00284 00285 inline void simpleDDMFederate13::setFedFileName(const wchar_t* newFedName) 00286 { 00287 myFederationFile = DtToString(std::wstring(newFedName)); 00288 } 00289 00290 inline char* simpleDDMFederate13::getFedFileName() const 00291 { 00292 return strdup(myFederationFile.c_str()); 00293 } 00294 00295 00296 00297 #endif