Federation.hh

Go to the documentation of this file.
00001 // ----------------------------------------------------------------------------
00002 // CERTI - HLA RunTime Infrastructure
00003 // Copyright (C) 2002-2005  ONERA
00004 //
00005 // This file is part of CERTI
00006 //
00007 // CERTI is free software ; you can redistribute it and/or modify
00008 // it under the terms of the GNU General Public License as published by
00009 // the Free Software Foundation ; either version 2 of the License, or
00010 // (at your option) any later version.
00011 //
00012 // CERTI is distributed in the hope that it will be useful,
00013 // but WITHOUT ANY WARRANTY ; without even the implied warranty of
00014 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00015 // GNU General Public License for more details.
00016 //
00017 // You should have received a copy of the GNU General Public License
00018 // along with this program ; if not, write to the Free Software
00019 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
00020 //
00021 // $Id: Federation.hh,v 3.57 2008/12/16 07:08:29 approx Exp $
00022 // ----------------------------------------------------------------------------
00023 
00024 #ifndef _CERTI_RTIG_FEDERATION_HH
00025 #define _CERTI_RTIG_FEDERATION_HH
00026 
00027 #include "Federate.hh"
00028 #include "RootObject.hh"
00029 #include "LBTS.hh"
00030 #include "GAV.hh"
00031 #include "SecurityServer.hh"
00032 #include "HandleManager.hh"
00033 #include "certi.hh"
00034 
00035 #ifndef WIN32
00036 #include <unistd.h>
00037 #include <stdlib.h>
00038 #endif
00039 
00040 #ifdef FEDERATION_USES_MULTICAST
00041 #include "SocketMC.hh"
00042 #endif
00043 
00044 // Libraries
00045 #ifdef HAVE_XML
00046 #include <libxml/xmlmemory.h> // FIXME: should be in the .cc
00047 #include <libxml/parser.h>
00048 #include <libxml/tree.h>
00049 #endif // HAVE_XML
00050 
00051 namespace certi {
00052 namespace rtig {
00053 
00054 class Federation
00055 {
00056     // ATTRIBUTES --------------------------------------------------------------
00057 private:
00058     Handle handle ;
00059     std::string name ;
00060     std::string FEDid ;
00061 
00063     std::map<const char *, const char *> synchronizationLabels ;
00064 
00065     HandleManager<FederateHandle> federateHandles ;
00066     HandleManager<ObjectHandle> objectHandles ;
00067 
00068     // This object is initialized when the Federation is created, with
00069     // the reference of the RTIG managed Socket Server. The reference of
00070     // this object is passed down the Classes Tree with the help of RootObj.
00071     SecurityServer *server ;
00072     RootObject *root ;
00073 
00074     LBTS regulators ;
00075 
00076 #ifdef FEDERATION_USES_MULTICAST
00077     SocketMC *MCLink ;
00078 #endif
00079 
00080     bool saveXmlData();
00081     bool restoreXmlData();
00082 
00083     // METHODS -----------------------------------------------------------------
00084 public:
00085 #ifdef FEDERATION_USES_MULTICAST
00086 
00096     Federation(const char *,
00097                FederationHandle,
00098                SocketServer &,
00099                AuditFile &,
00100                SocketMC*,
00101                int theVerboseLevel)
00102 #else
00103 
00113         Federation(const char *, Handle, SocketServer &, AuditFile &, const char *, int theVerboseLevel)
00114 #endif
00115         throw (CouldNotOpenFED, ErrorReadingFED, MemoryExhausted, SecurityError,
00116                RTIinternalError);
00117 
00118     ~Federation();
00119 
00120     int getNbFederates() const ;
00121     int getNbRegulators() const ;
00122     bool isSynchronizing() const ;
00123     Handle getHandle() const ;
00124     const char *getName() const ;
00125     const char *getFEDid() const ;
00126 
00127     // -------------------------
00128     // -- Federate Management --
00129     // -------------------------
00130     FederateHandle add(const char *theName, SocketTCP *theTCPLink)
00131         throw (FederateAlreadyExecutionMember,
00132                MemoryExhausted,
00133                RTIinternalError);
00134 
00135     bool empty() const
00136         throw (FederatesCurrentlyJoined);
00137 
00138     bool check(FederateHandle theHandle) const
00139         throw (FederateNotExecutionMember);
00140 
00141     void kill(FederateHandle theFederate) throw ();
00142 
00143     void remove(FederateHandle theHandle)
00144         throw (FederateOwnsAttributes,
00145                FederateNotExecutionMember);
00146 
00147     // ---------------------
00148     // -- Time Management --
00149     // ---------------------
00150     void addRegulator(FederateHandle theHandle, FederationTime theTime)
00151         throw (FederateNotExecutionMember,
00152                SaveInProgress,
00153                RestoreInProgress,
00154                RTIinternalError); // includes Time Regulation already enabled.
00155 
00156     void updateRegulator(FederateHandle theHandle, FederationTime theTime)
00157         throw (FederateNotExecutionMember,
00158                RTIinternalError);
00159 
00160     void removeRegulator(FederateHandle theHandle)
00161         throw (FederateNotExecutionMember,
00162                SaveInProgress,
00163                RestoreInProgress,
00164                RTIinternalError); // includes Time Regulation already disabled.
00165 
00166     void addConstrained(FederateHandle theHandle)
00167         throw (FederateNotExecutionMember,
00168                SaveInProgress,
00169                RestoreInProgress,
00170                RTIinternalError); // includes Time constrained already enabled.
00171 
00172     void removeConstrained(FederateHandle theHandle)
00173         throw (FederateNotExecutionMember,
00174                SaveInProgress,
00175                RestoreInProgress,
00176                RTIinternalError); // includes Time constrained already disabled.
00177 
00178     // Synchronization Management.
00179     void registerSynchronization(FederateHandle the_federate,
00180                                  const char *the_label,
00181                                  const char *the_tag)
00182         throw (FederateNotExecutionMember,
00183                FederationAlreadyPaused,
00184                SaveInProgress,
00185                RestoreInProgress,
00186                RTIinternalError);
00187 
00188     void registerSynchronization(FederateHandle the_federate,
00189                                  const char *the_label,
00190                                  const char *the_tag,
00191                                  unsigned short federate_setSize,
00192                                  std::vector <FederateHandle> &federate_set)
00193         throw (FederateNotExecutionMember,
00194                FederationAlreadyPaused,
00195                SaveInProgress,
00196                RestoreInProgress,
00197                RTIinternalError);
00198 
00199     void unregisterSynchronization(FederateHandle theFederate,
00200                                    const char *theLabel)
00201         throw (FederateNotExecutionMember,
00202                FederationNotPaused,
00203                SaveInProgress,
00204                RestoreInProgress,
00205                RTIinternalError);
00206 
00207     void broadcastSynchronization(FederateHandle federate,
00208                                   const char *label,
00209                                   const char *tag)
00210         throw (RTIinternalError);
00211 
00212     void broadcastSynchronization(FederateHandle federate,
00213                                   const char *label,
00214                                   const char *tag,
00215                                   unsigned short federate_setSize,
00216                                   std::vector <FederateHandle> &federate_set)
00217         throw (RTIinternalError);
00218 
00219 
00220     // Save Management.
00221     void requestFederationSave(FederateHandle, const char *, FederationTime)
00222         throw (FederateNotExecutionMember, SaveInProgress);
00223     void requestFederationSave(FederateHandle, const char *)
00224         throw (FederateNotExecutionMember, SaveInProgress);
00225 
00226 
00227     void federateSaveBegun(FederateHandle)
00228         throw (FederateNotExecutionMember);
00229 
00230     void federateSaveStatus(FederateHandle, bool)
00231         throw (FederateNotExecutionMember);
00232 
00233     void requestFederationRestore(FederateHandle the_federate,
00234                                   const char *the_label)
00235         throw (FederateNotExecutionMember);
00236 
00237     void federateRestoreStatus(FederateHandle the_federate,
00238                                bool the_status)
00239         throw (FederateNotExecutionMember);
00240 
00241     // -----------------------
00242     // -- Object Management --
00243     // -----------------------
00244 
00245     void deleteObject(FederateHandle theFederateHandle,
00246                       ObjectHandle theObjectHandle,
00247               FederationTime theTime,
00248                       const char *theUserTag)
00249         throw (FederateNotExecutionMember,
00250                DeletePrivilegeNotHeld,
00251                ObjectNotKnown,
00252                SaveInProgress,
00253                RestoreInProgress,
00254            InvalidFederationTime,
00255                RTIinternalError);
00256 
00257     void deleteObject(FederateHandle theFederateHandle,
00258                       ObjectHandle theObjectHandle,
00259                       const char *theUserTag)
00260         throw (FederateNotExecutionMember,
00261                DeletePrivilegeNotHeld,
00262                ObjectNotKnown,
00263                SaveInProgress,
00264                RestoreInProgress,
00265                RTIinternalError);
00266 
00267     void publishObject(FederateHandle theFederateHandle,
00268                        ObjectClassHandle theObjectHandle,
00269                        std::vector <AttributeHandle> &theAttributeList,
00270                        UShort theListSize,
00271                        bool PubOrUnpub)
00272         throw (ObjectClassNotDefined,
00273                AttributeNotDefined,
00274                FederateNotExecutionMember,
00275                SaveInProgress,
00276                SecurityError,
00277                RestoreInProgress,
00278                RTIinternalError);
00279 
00280     ObjectHandle registerObject(FederateHandle theFederateHandle,
00281                                 ObjectClassHandle theClass,
00282                                 const char *theName)
00283         throw (FederateNotExecutionMember,
00284                FederateNotPublishing,
00285                ObjectAlreadyRegistered,
00286                ObjectClassNotDefined,
00287                ObjectClassNotPublished,
00288                SaveInProgress,
00289                RestoreInProgress,
00290                RTIinternalError);
00291 
00292     FederateHandle requestObjectOwner(FederateHandle theFederateHandle,
00293                                 ObjectHandle theObject,
00294                                 std::vector <AttributeHandle> &theAttributeList,
00295                                 UShort theListSize)
00296         throw (ObjectNotKnown);
00297 
00307     void subscribeObject(FederateHandle theFederateHandle,
00308                          ObjectClassHandle theObjectHandle,
00309                          std::vector <AttributeHandle> &theAttributeList,
00310                          UShort theListSize)
00311         throw (ObjectClassNotDefined,
00312                AttributeNotDefined,
00313                FederateNotExecutionMember,
00314                SaveInProgress,
00315                SecurityError,
00316                RestoreInProgress,
00317                RTIinternalError);
00318 
00319     void updateAttributeValues(FederateHandle theFederateHandle,
00320                                ObjectHandle theObjectHandle,
00321                                std::vector <AttributeHandle> &theAttributeList,
00322                                std::vector <AttributeValue_t> &theValueList,
00323                                UShort theListSize,
00324                                FederationTime theTime,
00325                                const char *theTag)
00326         throw (FederateNotExecutionMember,
00327                ObjectNotKnown,
00328                AttributeNotDefined,
00329                AttributeNotOwned,
00330                SaveInProgress,
00331                RestoreInProgress,
00332                RTIinternalError);
00333 
00334     void updateAttributeValues(FederateHandle theFederateHandle,
00335                                ObjectHandle theObjectHandle,
00336                                std::vector <AttributeHandle> &theAttributeList,
00337                                std::vector <AttributeValue_t> &theValueList,
00338                                UShort theListSize,
00339                                const char *theTag)
00340         throw (FederateNotExecutionMember,
00341                ObjectNotKnown,
00342                AttributeNotDefined,
00343                AttributeNotOwned,
00344                SaveInProgress,
00345                RestoreInProgress,
00346                RTIinternalError);
00347 
00348     // ----------------------------
00349     // -- Interaction Management --
00350     // ----------------------------
00351 
00352     void broadcastInteraction(FederateHandle theFederateHandle,
00353                               InteractionClassHandle theInteractionHandle,
00354                               std::vector <ParameterHandle> &theParameterList,
00355                               std::vector <ParameterValue_t> &theValueList,
00356                               UShort theListSize,
00357                               FederationTime theTime,
00358                   RegionHandle,
00359                               const char *theTag)
00360         throw (FederateNotExecutionMember,
00361                FederateNotPublishing,
00362                InteractionClassNotDefined,
00363                InteractionParameterNotDefined,
00364                SaveInProgress,
00365                RestoreInProgress,
00366                RTIinternalError);
00367 
00368    void broadcastInteraction(FederateHandle theFederateHandle,
00369                               InteractionClassHandle theInteractionHandle,
00370                               std::vector <ParameterHandle> &theParameterList,
00371                               std::vector <ParameterValue_t> &theValueList,
00372                               UShort theListSize,
00373                   RegionHandle,
00374                               const char *theTag)
00375         throw (FederateNotExecutionMember,
00376                FederateNotPublishing,
00377                InteractionClassNotDefined,
00378                InteractionParameterNotDefined,
00379                SaveInProgress,
00380                RestoreInProgress,
00381                RTIinternalError);
00382 
00383     void publishInteraction(FederateHandle theFederateHandle,
00384                             InteractionClassHandle theInteractionHandle,
00385                             bool PubOrUnpub)
00386         throw (InteractionClassNotDefined,
00387                FederateNotExecutionMember,
00388                SaveInProgress,
00389                SecurityError,
00390                RestoreInProgress,
00391                RTIinternalError);
00392 
00393     void subscribeInteraction(FederateHandle theFederateHandle,
00394                               InteractionClassHandle theInteractionHandle,
00395                               bool SubOrUnsub)
00396         throw (InteractionClassNotDefined,
00397                FederateNotExecutionMember,
00398                SaveInProgress,
00399                SecurityError,
00400                RestoreInProgress,
00401                RTIinternalError);
00402 
00403 
00404     // --------------------------
00405     // -- Ownership Management --
00406     // --------------------------
00407 
00408     bool isOwner(FederateHandle theFederateHandle,
00409                  ObjectHandle theObjectHandle,
00410                  AttributeHandle theAttribute)
00411         throw (FederateNotExecutionMember,
00412                ObjectNotKnown,
00413                AttributeNotDefined,
00414                SaveInProgress,
00415                RestoreInProgress,
00416                RTIinternalError);
00417 
00418     void queryAttributeOwnership(FederateHandle theFederateHandle,
00419                                  ObjectHandle theObjectHandle,
00420                                  AttributeHandle theAttribute)
00421         throw (FederateNotExecutionMember,
00422                ObjectNotKnown,
00423                AttributeNotDefined,
00424                SaveInProgress,
00425                RestoreInProgress,
00426                RTIinternalError);
00427 
00428     void negotiateDivestiture(FederateHandle theFederateHandle,
00429                               ObjectHandle theObjectHandle,
00430                               std::vector <AttributeHandle> &theAttributeList,
00431                               UShort theListSize,
00432                               const char *theTag)
00433         throw (FederateNotExecutionMember,
00434                ObjectNotKnown,
00435                AttributeNotDefined,
00436                AttributeNotOwned,
00437                AttributeAlreadyBeingDivested,
00438                SaveInProgress,
00439                RestoreInProgress,
00440                RTIinternalError);
00441 
00442     void acquireIfAvailable(FederateHandle theFederateHandle,
00443                             ObjectHandle theObjectHandle,
00444                             std::vector <AttributeHandle> &theAttributeList,
00445                             UShort theListSize)
00446         throw (ObjectNotKnown,
00447                ObjectClassNotPublished,
00448                AttributeNotDefined,
00449                AttributeNotPublished,
00450                FederateOwnsAttributes,
00451                AttributeAlreadyBeingAcquired,
00452                FederateNotExecutionMember,
00453                SaveInProgress,
00454                RestoreInProgress,
00455                RTIinternalError);
00456 
00457     void divest(FederateHandle theFederateHandle,
00458                 ObjectHandle theObjectHandle,
00459                 std::vector <AttributeHandle> &theAttributeList,
00460                 UShort theListSize)
00461         throw (ObjectNotKnown,
00462                AttributeNotDefined,
00463                AttributeNotOwned,
00464                FederateNotExecutionMember,
00465                SaveInProgress,
00466                RestoreInProgress,
00467                RTIinternalError);
00468 
00469     void acquire(FederateHandle theFederateHandle,
00470                  ObjectHandle theObjectHandle,
00471                  std::vector <AttributeHandle> &theAttributeList,
00472                  UShort theListSize,
00473                  const char *theTag)
00474         throw (ObjectNotKnown,
00475                ObjectClassNotPublished,
00476                AttributeNotDefined,
00477                AttributeNotPublished,
00478                FederateOwnsAttributes,
00479                FederateNotExecutionMember,
00480                SaveInProgress,
00481                RestoreInProgress,
00482                RTIinternalError);
00483 
00484     void cancelDivestiture(FederateHandle theFederateHandle,
00485                            ObjectHandle theObjectHandle,
00486                            std::vector <AttributeHandle> &theAttributeList,
00487                            UShort theListSize)
00488         throw (ObjectNotKnown,
00489                AttributeNotDefined,
00490                AttributeNotOwned,
00491                AttributeDivestitureWasNotRequested,
00492                FederateNotExecutionMember,
00493                SaveInProgress,
00494                RestoreInProgress,
00495                RTIinternalError);
00496 
00497     AttributeHandleSet* respondRelease(FederateHandle theFederateHandle,
00498                                        ObjectHandle theObjectHandle,
00499                                        std::vector <AttributeHandle> &theAttributeList,
00500                                        UShort theListSize)
00501         throw (ObjectNotKnown,
00502                AttributeNotDefined,
00503                AttributeNotOwned,
00504                FederateWasNotAskedToReleaseAttribute,
00505                FederateNotExecutionMember,
00506                SaveInProgress,
00507                RestoreInProgress,
00508                RTIinternalError);
00509 
00510     void cancelAcquisition(FederateHandle theFederateHandle,
00511                            ObjectHandle theObjectHandle,
00512                            std::vector <AttributeHandle> &theAttributeList,
00513                            UShort theListSize)
00514         throw (ObjectNotKnown,
00515                AttributeNotDefined,
00516                AttributeAlreadyOwned,
00517                AttributeAcquisitionWasNotRequested,
00518                FederateNotExecutionMember,
00519                SaveInProgress,
00520                RestoreInProgress,
00521                RTIinternalError);
00522 
00523     // Data Distribution Management
00524 
00525     long createRegion(FederateHandle, SpaceHandle, long)
00526         throw (SpaceNotDefined,
00527            InvalidExtents,
00528            SaveInProgress,
00529                RestoreInProgress,
00530            RTIinternalError);
00531 
00532     void modifyRegion(FederateHandle, RegionHandle, const std::vector<Extent> &)
00533     throw (RegionNotKnown,
00534            InvalidExtents,
00535            SaveInProgress,
00536            RestoreInProgress,
00537            RTIinternalError);
00538 
00539     void deleteRegion(FederateHandle, long)
00540         throw (RegionNotKnown,
00541            RegionInUse,
00542            SaveInProgress,
00543            RestoreInProgress,
00544                RTIinternalError);
00545 
00546     void associateRegion(FederateHandle, ObjectHandle, RegionHandle,
00547              unsigned short, std::vector <AttributeHandle> &)
00548     throw (RegionNotKnown,
00549            SaveInProgress,
00550            RestoreInProgress,
00551            RTIinternalError);
00552 
00553     void unassociateRegion(FederateHandle, ObjectHandle, RegionHandle)
00554     throw (RegionNotKnown,
00555            SaveInProgress,
00556            RestoreInProgress,
00557            RTIinternalError);
00558 
00559     void subscribeAttributesWR(FederateHandle, ObjectClassHandle, RegionHandle,
00560                 unsigned short, std::vector <AttributeHandle> &)
00561     throw (RegionNotKnown,
00562            SaveInProgress,
00563            RestoreInProgress,
00564            RTIinternalError);
00565 
00566     void unsubscribeAttributesWR(FederateHandle, ObjectClassHandle,
00567                  RegionHandle)
00568     throw (RegionNotKnown,
00569            SaveInProgress,
00570            RestoreInProgress,
00571            RTIinternalError);
00572 
00573     void subscribeInteractionWR(FederateHandle, InteractionClassHandle,
00574                 RegionHandle)
00575     throw (RegionNotKnown,
00576            SaveInProgress,
00577            RestoreInProgress,
00578            RTIinternalError);
00579 
00580     void unsubscribeInteractionWR(FederateHandle, InteractionClassHandle,
00581                   RegionHandle)
00582     throw (RegionNotKnown,
00583            SaveInProgress,
00584            RestoreInProgress,
00585            RTIinternalError);
00586 
00587     ObjectHandle registerObjectWithRegion(FederateHandle,ObjectClassHandle,
00588                       const char *, RegionHandle, int,
00589                       std::vector <AttributeHandle> &)
00590     throw (ObjectClassNotDefined, ObjectClassNotPublished,
00591            AttributeNotDefined, AttributeNotPublished, RegionNotKnown,
00592            InvalidRegionContext, ObjectAlreadyRegistered,
00593            SaveInProgress, RestoreInProgress,
00594            RTIinternalError);
00595 
00596     // switches
00597     void setClassRelevanceAdvisorySwitch(FederateHandle theHandle)
00598         throw (FederateNotExecutionMember,
00599                SaveInProgress,
00600                RestoreInProgress,
00601                RTIinternalError); 
00602 
00603     void unsetClassRelevanceAdvisorySwitch(FederateHandle theHandle)
00604         throw (FederateNotExecutionMember,
00605                SaveInProgress,
00606                RestoreInProgress,
00607                RTIinternalError); 
00608 
00609     void setInteractionRelevanceAdvisorySwitch(FederateHandle theHandle)
00610         throw (FederateNotExecutionMember,
00611                SaveInProgress,
00612                RestoreInProgress,
00613                RTIinternalError); 
00614 
00615     void unsetInteractionRelevanceAdvisorySwitch(FederateHandle theHandle)
00616         throw (FederateNotExecutionMember,
00617                SaveInProgress,
00618                RestoreInProgress,
00619                RTIinternalError); 
00620 
00621     void setAttributeRelevanceAdvisorySwitch(FederateHandle theHandle)
00622         throw (FederateNotExecutionMember,
00623                SaveInProgress,
00624                RestoreInProgress,
00625                RTIinternalError); 
00626 
00627     void unsetAttributeRelevanceAdvisorySwitch(FederateHandle theHandle)
00628         throw (FederateNotExecutionMember,
00629                SaveInProgress,
00630                RestoreInProgress,
00631                RTIinternalError); 
00632 
00633     void setAttributeScopeAdvisorySwitch(FederateHandle theHandle)
00634         throw (FederateNotExecutionMember,
00635                SaveInProgress,
00636                RestoreInProgress,
00637                RTIinternalError); 
00638 
00639     void unsetAttributeScopeAdvisorySwitch(FederateHandle theHandle)
00640         throw (FederateNotExecutionMember,
00641                SaveInProgress,
00642                RestoreInProgress,
00643                RTIinternalError); 
00644 
00645 private:
00646     // Private methods
00647     void broadcastAnyMessage(NetworkMessage *msg, FederateHandle Except);
00648 
00649     void broadcastSomeMessage(NetworkMessage *msg, FederateHandle Except,
00650                        std::vector <FederateHandle> &fede_array, int nbfed);
00651 
00652     Federate &getFederate(const char *theName)
00653         throw (FederateNotExecutionMember);
00654 
00655     Federate &getFederate(FederateHandle theHandle)
00656         throw (FederateNotExecutionMember);
00657 
00658     // Private attributes
00659     typedef std::vector<Federate> FederateList ;
00660 
00661     FederateList federates ;
00662     bool saveInProgress ;
00663     bool restoreInProgress ;
00664     bool saveStatus ; 
00665     bool restoreStatus ; 
00666     int  verboseLevel ;
00667     std::string saveLabel ; 
00668 
00669 #ifdef HAVE_XML
00670     xmlDocPtr doc ; // FIXME: should not be an attribute
00671 #endif // HAVE_XML
00672     /* The message buffer used to send Network messages */
00673     MessageBuffer NM_msgBufSend;
00674 };
00675 
00676 }} // namespace certi/rtig
00677 
00678 #endif // _CERTI_RTIG_FEDERATION_HH
00679 
00680 // $Id: Federation.hh,v 3.57 2008/12/16 07:08:29 approx Exp $

Generated on Thu Apr 30 15:53:48 2009 for CERTIDeveloperDocumentation by doxygen 1.5.5