MAK RTIspy API Documentation for HLA 1.3
simpleDDMFederate.h
Go to the documentation of this file.
00001 /******************************************************************************
00002 ** Copyright (c) 2006 MaK Technologies, Inc.
00003 ** All rights reserved.
00004 ******************************************************************************/
00005 /******************************************************************************
00006 ** $RCSfile: simpleDDMFederate.h,v $ $Revision: 1.17 $ $State: Exp $
00007 ******************************************************************************/
00008 
00009 #ifndef REGIONEXAMPLE_H_
00010 #define REGIONEXAMPLE_H_
00011 
00012 // Base class for wrappers around the RTI Ambassador calls.
00013 
00014 #include <sstream>
00015 #include <string>
00016 #include <iostream>
00017 #include <iomanip>
00018 #include <vector>
00019 
00020 
00021 #include "simpleDDMStringUtil.h"
00022 
00023 
00024 
00025 class simpleDDMFederate
00026 {
00027 public:
00029 // Default Constructor
00031    simpleDDMFederate();
00032 
00034 // Constructor
00036    simpleDDMFederate(simpleDDMFederate& data);
00037 
00039 // Destructor
00041    virtual ~simpleDDMFederate();
00042 
00043 // RTI Wrappers
00044 
00046 // Initialize the RTI
00048    virtual void initializeRTI() = 0;
00049 
00051 // Create a federation execution
00053    virtual bool createFedEx() = 0;
00054 
00056 // Join a federation execution
00058    virtual bool joinFedEx() = 0;
00059 
00061 // Resign from the federation execution and destroy it
00063    virtual void resignAndDestroy() = 0;
00064 
00066 // Create the Region and initialize its bounds
00068    virtual bool createAndInitializeRegions() = 0;
00069 
00071 // Publish and subscribe the object class attributes.
00072 // Register an object instance of the class.
00074    virtual bool publishSubscribeAndRegisterObject() = 0;
00075 
00077 // Publish and Subscribe to an interaction class
00079    virtual bool publishAndSubscribeInteraction() = 0;
00080 
00082 // Send the default update with Region.  A less simple federate would have to
00083 // specify which attributes need be updated.  This on merely passes in the
00084 // position which is sent with Region as the object update.
00086    virtual void sendUpdate(int currentPosition ) = 0;
00087 
00089 // Send Interactions with Region.  The following two interactions are meant to
00090 // emulate a cuckoo clock with both an hourly chime, and a quarterly chime.
00092 
00094 // Send the hourly interaction with Region. This is an interaction that in this
00095 // example occurs for each hour that is passed on the clock that is not
00096 // {12,3,6,9}.
00098    virtual void sendInteraction_hourly() = 0;
00099 
00101 // Send the quarterly interaction with Region.  This is an interaction that in
00102 // this example occurs for each hour that is passed on the clock that is in the
00103 // following set {12,3,6,9}
00105    virtual void sendInteraction_quarterly() = 0;
00106 
00108 // changeBounds sets the subscription of publication bounds of this federate.
00110    virtual void changeBounds(int lower, int upper, int UTCZone) = 0;
00111 
00113 // Set the RTI's enable advisory switch
00115    virtual void setEnableScopeAdvisories(bool yesNo) = 0;
00116 
00118 // Get scope advisory setting
00120    bool enableScopeAdvisories() const ;
00121 
00123 // Perform the tick or evokeCallback method.
00125    virtual void tick(double atMost=0.0f) = 0;
00126 
00128 // Perform the tick or evokeCallback method.
00130    virtual void tick(double atLeast, double atMost) = 0;
00131 
00132    // Simulation Methods
00133 
00135 // Set federate as publisher (true) or subscriber (false)
00137    virtual void setIsPublisher(bool yesNo) = 0;
00138 
00140 // Return true if this federate is publishing
00142    bool isPublisher() const ;
00143 
00145 // Set the position (number of seconds)
00147    virtual void setPosition(int data) = 0;
00148 
00150 // Get the position (number of seconds)
00152    virtual int position() = 0;
00153 
00155 // Set the number of seconds to increment each cycle
00157    void setSizeToInc(int data);
00158 
00160 // Get the number of seconds to increment each cycle
00162    int sizeToInc() const ;
00163 
00165 // Get the zone used to send or listen
00167    int zone() const ;
00168 
00169    // Region Range Bound Methods
00170 
00172 // Set the update range (number of seconds ahead of current position)
00173 // This value should be at least large enough to have the next update fall
00174 // within the range.
00176    void setSendRangeSize(int data);
00177 
00179 // Get the update range (number of seconds ahead of current position)
00181    int sendRangeSize() const ;
00182 
00184 // Get this listen upper bound
00186    int listenUpperBound() const ;
00187 
00189 // Get this listen lower bound
00191    int listenLowerBound() const ;
00192 
00194 // Get the send upper bound
00196    int sendUpperBound() const ;
00197 
00199 // Get the send lower bound
00201    int sendLowerBound() const;
00202 
00203 
00205 // Set the Fed File Name
00207 virtual void setFedFileName(const wchar_t* newFedName) = 0;
00208 
00210 // Set the Fed File Name with a std::string.
00212 virtual void setFedFileName(const char* newFedName) = 0;
00213 
00215 // Get the Fed File Name
00217 virtual char* getFedFileName() const = 0;
00218 
00219    // Constants used in calculations
00220    static const unsigned int NUMSECONDSPERMINUTE;
00221    static const unsigned int NUMMINUTESPERHOUR;
00222    static const unsigned int NUMSECONDSPERHOUR;
00223 
00224    // 0 seconds is the minimum.
00225    static const unsigned int LOWESTSecondsInRegion;
00226    //60 seconds * 60 minutes * 360 degrees.
00227    static const unsigned int GREATESTSecondsInRegion;
00228    // 0 is the default UTC
00229    static const unsigned int LOWESTUTCInRegion;
00230    // For this example, the World has only 24 distinct Time Zones. (GREATESTUTCInRegion = 23)
00231    static const unsigned int GREATESTUTCInRegion;
00232 
00233    enum simpleAttributeHandleIndex
00234    {
00235       simplePositionIndex = 0,
00236       simpleMaxIndex
00237    };
00238 
00239 protected:
00240 
00241    // Our upper bound is the number of seconds in a circle.
00242    // This is our default upper bound of interest extent in our region.
00243    int myListenUpperBound;
00244 
00245    // This is our default lower bound of interest extent in our region.
00246    int myListenLowerBound;
00247 
00248    // Is this instance the publisher.  The Simple DDM example has one federate
00249    // publishing and the other federate publishing no information,
00250    // simply subscribing.
00251    bool myIsPublisher;
00252 
00253    //******************************************//
00254    // The following are publisher specific data
00255    //******************************************//
00256    // This is our default upper area of interest extent in our region.
00257    int mySendUpperBound;
00258    // This is our default lower area of interest extent in our region.
00259    int mySendLowerBound;
00260    // This is the default time increment between ticks (seconds)
00261    int mySizeToInc;
00262    // This is the calculated range of the sender
00263    float mySendRangeSize;
00264    // This represents the current position of the executing federate.
00265    //  The valid range for this int is between
00266    //                     [positionLowerBound, positionUpperBound)
00267    int myCurrentposition;
00268 
00269    // The number of updates sent
00270    int myUpdateCount;
00271 
00272    int myUTCZone;
00273 
00274    //******************************************//
00275    // The following is subscriber specific data
00276    //******************************************//
00277    // This boolean enables the scope Advisory callback from the rti1516.
00278    // The scoping callback is issued when an object that is subscribed with
00279    // region changes visibility to the federate.  i.e. When the subscribed and
00280    // published region start to instersect and cease to intersect.
00281    bool myEnableScopeAdvisories;
00282 
00283    //initialized represents whether or not the QT process has Initialized,
00284    // After main launches a QT thread,
00285    //  main waits for QT to set initialized before proceeding
00286    bool myInitialized;
00287    // closed is a global representing whether the main loop has exited for any
00288    // reason including the user closing the dialog.
00289    // The main loop sets it prior to exiting and the QT thread
00290    // exits when it detects the main loop has closed.
00291    bool myClosed;
00292 
00293    bool myRegionValid;
00294    bool myMapsInitialized;
00295 
00296 private:
00297    // Assignment Operator not implemented: Copy not allowed
00298    simpleDDMFederate &operator=(const simpleDDMFederate&);
00299 };
00300 
00301 
00302 inline void simpleDDMFederate::setSizeToInc(int data)
00303 {
00304    mySizeToInc = data;
00305 }
00306 inline void simpleDDMFederate::setSendRangeSize(int data)
00307 {
00308    if ( data < (int)(GREATESTSecondsInRegion - LOWESTSecondsInRegion) )
00309    {
00310       mySendRangeSize = (float)data;
00311    }
00312    else
00313    {
00314       mySendRangeSize = (float)(GREATESTSecondsInRegion - LOWESTSecondsInRegion);
00315    }
00316 }
00317 
00318 inline int simpleDDMFederate::listenUpperBound() const
00319 {
00320    return myListenUpperBound;
00321 }
00322 
00323 inline int simpleDDMFederate::listenLowerBound() const
00324 {
00325    return myListenLowerBound;
00326 }
00327 
00328 inline bool simpleDDMFederate::isPublisher() const
00329 {
00330    return myIsPublisher;
00331 }
00332 
00333 inline int simpleDDMFederate::sendUpperBound() const
00334 {
00335    return mySendUpperBound;
00336 }
00337 
00338 inline int simpleDDMFederate::sendLowerBound() const
00339 {
00340    return mySendLowerBound;
00341 }
00342 
00343 inline int simpleDDMFederate::sizeToInc() const
00344 {
00345    return mySizeToInc;
00346 }
00347 
00348 inline int simpleDDMFederate::sendRangeSize() const
00349 {
00350    return (int)mySendRangeSize;
00351 }
00352 
00353 inline bool simpleDDMFederate::enableScopeAdvisories() const
00354 {
00355    return myEnableScopeAdvisories;
00356 }
00357 
00358 inline int simpleDDMFederate::zone() const
00359 {
00360    return myUTCZone;
00361 }
00362 
00363 #endif

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)