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

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)