![]() |
MAK RTIspy API Documentation for HLA 1.3
|
00001 /****************************************************************************** 00002 ** Copyright (c) 2006 MaK Technologies, Inc. 00003 ** All rights reserved. 00004 ******************************************************************************/ 00005 /****************************************************************************** 00006 ** $RCSfile: simpleDDMSimple1516.h,v $ $Revision: 1.2 $ $State: Exp $ 00007 ******************************************************************************/ 00008 00009 #ifndef REGIONEXAMPLE1516_H_ 00010 #define REGIONEXAMPLE1516_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 <wchar.h> 00020 #include "simpleDDMFederate.h" 00021 #include <string.h> 00022 00023 #include <RTI/RTI1516.h> 00024 #include <RTI/RTIambassadorFactory.h> 00025 #include "simpleDDMFedAmb1516.h" 00026 00027 // Map between strings and attribute handles 00028 typedef std::map<std::wstring, rti1516::AttributeHandle> DtAttrNameHandleMap; 00029 // Map between strings and parameter handles 00030 typedef std::map<std::wstring, rti1516::ParameterHandle> DtParamNameHandleMap; 00031 00032 00033 class simpleDDMFederate1516 : public simpleDDMFederate 00034 { 00035 public: 00036 00038 // Default Constructor 00040 simpleDDMFederate1516(); 00041 00043 // Constructor 00045 simpleDDMFederate1516(simpleDDMFederate1516& data); 00046 00048 // Destructor 00050 virtual ~simpleDDMFederate1516(); 00051 00052 // RTI Wrappers 00053 00055 // Initialize the RTI 00057 void initializeRTI(); 00058 00060 // Create a federation execution 00062 bool createFedEx(); 00063 00065 // Join a federation execution 00067 bool joinFedEx(); 00068 00070 // Resign from the federation execution and destroy it 00072 void resignAndDestroy(); 00073 00075 // Create the Region and initialize its bounds 00077 bool createAndInitializeRegions(); 00078 00080 // Publish and subscribe the object class attributes. 00081 // Register an object instance of the class. 00083 bool publishSubscribeAndRegisterObject(); 00084 00086 // Publish and Subscribe to an interaction class 00088 bool publishAndSubscribeInteraction(); 00089 00091 // Send the default update with Region. A less simple federate would have to 00092 // specify which attributes need be updated. This on merely passes in the 00093 // position which is sent with Region as the object update. 00095 void sendUpdate(int currentPosition); 00096 00098 // Send Interactions with Region. The following two interactions are meant to 00099 // emulate a cuckoo clock with both an hourly chime, and a quarterly chime. 00101 00103 // Send the hourly interaction with Region. This is an interaction that in this 00104 // example occurs for each hour that is passed on the clock that is not 00105 // {12,3,6,9}. 00107 void sendInteraction_hourly(); 00108 00110 // Send the quarterly interaction with Region. This is an interaction that in 00111 // this example occurs for each hour that is passed on the clock that is in the 00112 // following set {12,3,6,9} 00114 void sendInteraction_quarterly(); 00115 00117 // Perform the tick or evokeCallback method. 00119 void tick(double atMost=0.0f); 00120 00122 // Perform the tick or evokeCallback method. 00124 void tick(double atLeast, double atMost); 00125 00127 // changeBounds sets the subscription of publication bounds of this federate. 00129 void changeBounds(int lower, int upper, int UTCZone) ; 00130 00132 // Set the RTI's enable advisory switch 00134 void setEnableScopeAdvisories(bool yesNo); 00135 00136 // Simulation Methods 00137 00139 // Set federate as publisher (true) or subscriber (false) 00141 void setIsPublisher(bool yesNo); 00142 00144 // Get the position (number of seconds) 00146 int position(); 00147 00149 // Set the position (number of seconds) 00151 void setPosition(int data); 00152 00153 00155 // Set the Fed File Name 00157 void setFedFileName(const wchar_t* newFedName); 00158 00160 // Set the Fed File Name with a std::string. 00162 void setFedFileName(const char* newFedName); 00163 00164 00166 // Get the Fed File Name 00168 char* getFedFileName() const; 00169 00170 00171 protected: 00172 00174 // Map between strings and attribute handles 00176 DtAttrNameHandleMap myAttrNameHandleMap; 00177 00179 // Map between strings and parameter handles 00181 DtParamNameHandleMap myParamNameHandleMap; 00182 00184 // Construct an attribute handle value pair set with the 00185 // values containing the attribute names 00187 rti1516::AttributeHandleValueMap myAttrValues; 00188 00190 // Data shared between federate and federate ambassador 00192 DtTalkAmbData theAmbData; 00193 00194 private: 00195 // Federate and Federation info 00196 std::wstring myFederationName; 00197 std::wstring myFederationFile; 00198 std::wstring myFederateType; 00199 00200 // An interaction published at {1, 2, 4, 5, 7, 8, 10 , 11} 00201 std::wstring myHourlyInteraction; 00202 00203 // An interaction published at {3,6,9,12} 00204 std::wstring myQuarterlyInteraction; 00205 00206 // The interaction class name 00207 std::wstring myInterClassName; 00208 00209 // The object class name 00210 std::wstring myClassName; 00211 00212 // The attribute name 00213 std::wstring myAttrName; 00214 00215 // The RTI Ambassador 00216 rti1516::RTIambassador* myRTIamb; 00217 00218 // The Federate Ambassador 00219 MyFederateAmbassador* myFedAmb; 00220 00221 // the Handle for the hourlyInteraction, (to be retrieved from rti1516). 00222 rti1516::ParameterHandle myHourlyHandle; 00223 00224 // the Handle for the quarterlyInteraction, (to be retrieved from rti1516). 00225 rti1516::ParameterHandle myQuarterlyHandle; 00226 00227 // The dimension handle Set. 00228 rti1516::DimensionHandleSet myDimHandleSet; 00229 00230 // Construct a parameter handle value pair set with the 00231 // values containing the parameter names 00232 rti1516::ParameterHandleValueMap myParamValues; 00233 00234 // The name of the seconds dimension as specified in your FED file. 00235 std::wstring mySecondsDimensionName; 00236 // seconds dimension handle 00237 rti1516::DimensionHandle mySecondsDim; 00238 00239 // The name of the UTC dimension as specified in your FED file. 00240 std::wstring myUTCDimensionName; 00241 // UTC dimension handle 00242 rti1516::DimensionHandle myUTCDim; 00243 00244 // The object class handle (to be retrieved from rti1516). 00245 rti1516::ObjectClassHandle myClassHandle; 00246 00247 //The object instance handle ( to be retrieved from the rti). 00248 rti1516::ObjectInstanceHandle myObjectInstanceHandle; 00249 00250 // The interaction class handle (to be retrieved from rti1516). 00251 rti1516::InteractionClassHandle myInterClassHandle; 00252 00253 rti1516::AttributeHandleSetRegionHandleSetPairVector myRegionHandleSet; 00254 00255 // Array of attributeHandles. 00256 rti1516::AttributeHandleSet myAttrHandles; 00257 00258 // Region handle list 00259 rti1516::RegionHandleSet myRegions; 00260 00261 // The listen region 00262 rti1516::RegionHandle myListenRegion; 00263 00264 // The send region 00265 rti1516::RegionHandle mySendRegion; 00266 }; 00267 00268 00269 inline void simpleDDMFederate1516::setIsPublisher(bool yesNo) 00270 { 00271 myIsPublisher = yesNo; 00272 theAmbData.isPublisher = yesNo; 00273 } 00274 00275 inline void simpleDDMFederate1516::setEnableScopeAdvisories(bool yesNo) 00276 { 00277 myEnableScopeAdvisories = yesNo; 00278 theAmbData.enableScopeAdvisories = yesNo; 00279 } 00280 00281 inline int simpleDDMFederate1516::position() 00282 { 00283 if (!isPublisher()) 00284 myCurrentposition = theAmbData.position; 00285 return myCurrentposition; 00286 } 00287 00288 inline void simpleDDMFederate1516::setFedFileName(const wchar_t* newFedName) 00289 { 00290 myFederationFile = std::wstring(newFedName); 00291 } 00292 00293 inline void simpleDDMFederate1516::setFedFileName(const char* newFedName) 00294 { 00295 myFederationFile = DtToWString(newFedName); 00296 } 00297 00298 inline char* simpleDDMFederate1516::getFedFileName() const 00299 { 00300 return strdup(DtToString(myFederationFile).c_str()); 00301 } 00302 00303 #endif