Message.hh

Go to the documentation of this file.
00001 // ----------------------------------------------------------------------------
00002 // CERTI - HLA RunTime Infrastructure
00003 // Copyright (C) 2002-2005  ONERA
00004 //
00005 // This program is free software ; you can redistribute it and/or
00006 // modify it under the terms of the GNU Lesser General Public License
00007 // as published by the Free Software Foundation ; either version 2 of
00008 // the License, or (at your option) any later version.
00009 //
00010 // This program is distributed in the hope that it will be useful, but
00011 // WITHOUT ANY WARRANTY ; without even the implied warranty of
00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
00013 // Lesser General Public License for more details.
00014 //
00015 // You should have received a copy of the GNU Lesser General Public
00016 // License along with this program ; if not, write to the Free Software
00017 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
00018 // ----------------------------------------------------------------------------
00019 
00020 #ifndef CERTI_MESSAGE_HH
00021 #define CERTI_MESSAGE_HH
00022 
00023 
00024 
00025 #include "Exception.hh"
00026 #include "SocketUN.hh"
00027 #include "BasicMessage.hh"
00028 #include "GAV.hh"
00029 #include "FedTimeD.hh"
00030 
00031 #include <vector>
00032 #include <string>
00033 
00034 namespace certi {
00035 
00041 class CERTI_EXPORT Message : public BasicMessage
00042 {
00043 public:
00044     struct MessageTimeStruct {
00045         FederationTime date ; // Date, Logical Time, Lookahead, etc.
00046         bool mode ; // IsRegulator or IsConstrained
00047     };
00048 
00049     struct MessageT_O_Struct {
00050         ObjectClassHandle handle ;
00051         UShort size ;
00052         TransportType transport ;
00053         OrderType order ;
00054     };
00055 
00056     struct MessageJ_R_Struct {
00057         FederateHandle federate ; // Join
00058         RTI::ResignAction action ; // Resign
00059     };
00060 
00061     struct MessageO_I_Struct {
00062         ObjectClassHandle handle ;
00063         UShort size ;
00064         FederationTime date ;
00065     };
00066 
00067     struct Message_DDM {
00068         SpaceHandle space ;
00069         DimensionHandle dimension ;
00070         RegionHandle region ;
00071     };
00072 
00073     // MessageHeaderUnion  deprecated
00074     //union MessageHeaderUnion {
00075     //    MessageTimeStruct time ;
00076     //    MessageT_O_Struct T_O ;
00077     //    MessageJ_R_Struct J_R ;
00078     //    MessageO_I_Struct O_I ;
00079     //    Message_DDM ddm ;
00080     //};
00081 
00082     enum Type {
00083         NOT_USED = 0,
00084         CLOSE_CONNEXION,
00085 
00086         // gestion federation
00087         CREATE_FEDERATION_EXECUTION,
00088         DESTROY_FEDERATION_EXECUTION,
00089         JOIN_FEDERATION_EXECUTION,
00090         RESIGN_FEDERATION_EXECUTION,
00091         REGISTER_FEDERATION_SYNCHRONIZATION_POINT,
00092         SYNCHRONIZATION_POINT_REGISTRATION_FAILED,
00093         SYNCHRONIZATION_POINT_REGISTRATION_SUCCEEDED,
00094         ANNOUNCE_SYNCHRONIZATION_POINT,
00095         SYNCHRONIZATION_POINT_ACHIEVED,
00096         FEDERATION_SYNCHRONIZED,
00097         REQUEST_FEDERATION_SAVE,
00098         INITIATE_FEDERATE_SAVE,
00099         FEDERATE_SAVE_BEGUN,
00100         FEDERATE_SAVE_COMPLETE,
00101         FEDERATE_SAVE_NOT_COMPLETE,
00102         FEDERATION_SAVED,
00103         FEDERATION_NOT_SAVED,
00104         REQUEST_FEDERATION_RESTORE,
00105         REQUEST_FEDERATION_RESTORE_FAILED,
00106         REQUEST_FEDERATION_RESTORE_SUCCEEDED,
00107         INITIATE_FEDERATE_RESTORE,
00108         FEDERATE_RESTORE_COMPLETE,
00109         FEDERATE_RESTORE_NOT_COMPLETE,
00110         FEDERATION_RESTORED,
00111         FEDERATION_NOT_RESTORED,
00112         FEDERATION_RESTORE_BEGUN,
00113 
00114         // Declaration
00115         PUBLISH_OBJECT_CLASS,
00116         UNPUBLISH_OBJECT_CLASS,
00117         PUBLISH_INTERACTION_CLASS,
00118         UNPUBLISH_INTERACTION_CLASS,
00119         SUBSCRIBE_OBJECT_CLASS_ATTRIBUTES,
00120         UNSUBSCRIBE_OBJECT_CLASS,
00121         SUBSCRIBE_INTERACTION_CLASS,
00122         UNSUBSCRIBE_INTERACTION_CLASS,
00123         START_REGISTRATION_FOR_OBJECT_CLASS,
00124         STOP_REGISTRATION_FOR_OBJECT_CLASS,
00125         TURN_INTERACTIONS_ON,
00126         TURN_INTERACTIONS_OFF,
00127 
00128         // Object
00129         REGISTER_OBJECT_INSTANCE,
00130         UPDATE_ATTRIBUTE_VALUES,
00131         DISCOVER_OBJECT_INSTANCE,
00132         REFLECT_ATTRIBUTE_VALUES,
00133         SEND_INTERACTION,
00134         RECEIVE_INTERACTION,
00135         DELETE_OBJECT_INSTANCE,
00136         LOCAL_DELETE_OBJECT_INSTANCE,
00137         REMOVE_OBJECT_INSTANCE,
00138         CHANGE_ATTRIBUTE_TRANSPORTATION_TYPE,
00139         CHANGE_INTERACTION_TRANSPORTATION_TYPE,
00140         REQUEST_OBJECT_ATTRIBUTE_VALUE_UPDATE,
00141         REQUEST_CLASS_ATTRIBUTE_VALUE_UPDATE,
00142         PROVIDE_ATTRIBUTE_VALUE_UPDATE,
00143         ATTRIBUTES_IN_SCOPE,
00144         ATTRIBUTES_OUT_OF_SCOPE,
00145         TURN_UPDATES_ON_FOR_OBJECT_INSTANCE,
00146         TURN_UPDATES_OFF_FOR_OBJECT_INSTANCE,
00147 
00148         // Ownership
00149         REQUEST_ATTRIBUTE_OWNERSHIP_DIVESTITURE,
00150         REQUEST_ATTRIBUTE_OWNERSHIP_ASSUMPTION,
00151         NEGOTIATED_ATTRIBUTE_OWNERSHIP_DIVESTITURE,
00152         ATTRIBUTE_OWNERSHIP_DIVESTITURE_NOTIFICATION,
00153         ATTRIBUTE_OWNERSHIP_ACQUISITION_NOTIFICATION,
00154         REQUEST_ATTRIBUTE_OWNERSHIP_ACQUISITION,
00155         REQUEST_ATTRIBUTE_OWNERSHIP_RELEASE,
00156         QUERY_ATTRIBUTE_OWNERSHIP,
00157         INFORM_ATTRIBUTE_OWNERSHIP,
00158         IS_ATTRIBUTE_OWNED_BY_FEDERATE,
00159         ATTRIBUTE_IS_NOT_OWNED,
00160         ATTRIBUTE_OWNED_BY_RTI,
00161         ATTRIBUTE_OWNERSHIP_ACQUISITION_IF_AVAILABLE,
00162         ATTRIBUTE_OWNERSHIP_UNAVAILABLE,
00163         UNCONDITIONAL_ATTRIBUTE_OWNERSHIP_DIVESTITURE,
00164         ATTRIBUTE_OWNERSHIP_ACQUISITION,
00165         CANCEL_NEGOTIATED_ATTRIBUTE_OWNERSHIP_DIVESTITURE,
00166         ATTRIBUTE_OWNERSHIP_RELEASE_RESPONSE,
00167         CANCEL_ATTRIBUTE_OWNERSHIP_ACQUISITION,
00168         CONFIRM_ATTRIBUTE_OWNERSHIP_ACQUISITION_CANCELLATION,
00169 
00170         // Time
00171         CHANGE_ATTRIBUTE_ORDER_TYPE,
00172         CHANGE_INTERACTION_ORDER_TYPE,
00173         ENABLE_TIME_REGULATION,
00174         DISABLE_TIME_REGULATION,
00175         ENABLE_TIME_CONSTRAINED,
00176         DISABLE_TIME_CONSTRAINED,
00177         QUERY_LBTS,
00178         QUERY_FEDERATE_TIME,
00179         QUERY_MIN_NEXT_EVENT_TIME,
00180         MODIFY_LOOKAHEAD,
00181         QUERY_LOOKAHEAD,
00182         RETRACT,
00183         REQUEST_RETRACTION,
00184         TIME_ADVANCE_REQUEST,
00185         TIME_ADVANCE_REQUEST_AVAILABLE,
00186         NEXT_EVENT_REQUEST,
00187         NEXT_EVENT_REQUEST_AVAILABLE,
00188         FLUSH_QUEUE_REQUEST,
00189         TIME_ADVANCE_GRANT,
00190         ENABLE_ASYNCHRONOUS_DELIVERY,
00191         DISABLE_ASYNCHRONOUS_DELIVERY,
00192         TIME_REGULATION_ENABLED,
00193         TIME_CONSTRAINED_ENABLED,
00194 
00195         // Data Distribution Management
00196         DDM_CREATE_REGION,
00197         DDM_MODIFY_REGION,
00198         DDM_DELETE_REGION,
00199         DDM_REGISTER_OBJECT,
00200         DDM_ASSOCIATE_REGION,
00201         DDM_UNASSOCIATE_REGION,
00202         DDM_SUBSCRIBE_ATTRIBUTES,
00203         DDM_UNSUBSCRIBE_ATTRIBUTES,
00204         DDM_SUBSCRIBE_INTERACTION,
00205         DDM_UNSUBSCRIBE_INTERACTION,
00206         DDM_REQUEST_UPDATE,
00207 
00208         // Support Services
00209         GET_OBJECT_CLASS_HANDLE,
00210         GET_OBJECT_CLASS_NAME,
00211         GET_ATTRIBUTE_HANDLE,
00212         GET_ATTRIBUTE_NAME,
00213         GET_INTERACTION_CLASS_HANDLE,
00214         GET_INTERACTION_CLASS_NAME,
00215         GET_PARAMETER_HANDLE,
00216         GET_PARAMETER_NAME,
00217         GET_OBJECT_INSTANCE_HANDLE,
00218         GET_OBJECT_INSTANCE_NAME,
00219         GET_SPACE_HANDLE,
00220         GET_SPACE_NAME,
00221         GET_DIMENSION_HANDLE,
00222         GET_DIMENSION_NAME,
00223         GET_ATTRIBUTE_SPACE_HANDLE,
00224         GET_OBJECT_CLASS,
00225         GET_INTERACTION_SPACE_HANDLE,
00226         GET_TRANSPORTATION_HANDLE,
00227         GET_TRANSPORTATION_NAME,
00228         GET_ORDERING_HANDLE,
00229         GET_ORDERING_NAME,
00230         ENABLE_CLASS_RELEVANCE_ADVISORY_SWITCH,
00231         DISABLE_CLASS_RELEVANCE_ADVISORY_SWITCH,
00232         ENABLE_ATTRIBUTE_RELEVANCE_ADVISORY_SWITCH,
00233         DISABLE_ATTRIBUTE_RELEVANCE_ADVISORY_SWITCH,
00234         ENABLE_ATTRIBUTE_SCOPE_ADVISORY_SWITCH,
00235         DISABLE_ATTRIBUTE_SCOPE_ADVISORY_SWITCH,
00236         ENABLE_INTERACTION_RELEVANCE_ADVISORY_SWITCH,
00237         DISABLE_INTERACTION_RELEVANCE_ADVISORY_SWITCH,
00238         TICK_REQUEST,
00239         TICK_REQUEST_NEXT,
00240         TICK_REQUEST_STOP,
00241 
00242     LAST // should be the "last" (not used)
00243     };
00244 
00245     // -- Structure de l'entete --
00246     struct MessageHeader {
00247         Type type ;
00248         TypeException exception ;
00249         UShort bodySize ;
00250         FederationTime date ;
00251         //MessageHeaderUnion VP ; // Variable Part deprecated
00252     };
00253 
00254 public:
00255     Message();
00256 
00260     virtual void serialize(MessageBuffer& msgBuffer);
00264     virtual void deserialize(MessageBuffer& msgBuffer);
00265 
00266     void send(SocketUN* socket, MessageBuffer& msgBuffer) throw (NetworkError, NetworkSignal);
00267     void receive(SocketUN* socket, MessageBuffer& msgBuffer) throw (NetworkError, NetworkSignal);
00268 
00269      void trace(const char* context);
00270 
00271     // Return a newly allocated ValueArray, exactly of size HandleArraySize.
00272     // containing the actual Attrib/Param values.
00273     std::vector <AttributeValue_t> getValueArray();
00274 
00275     std::string getLabel() const { return label ; };
00276     void setLabel(std::string new_label);
00277 
00278     //const char *getName() const { return name ; };
00279     const std::string getName() const {return name;}
00280     void setName(const char *new_name);
00281 
00282     DimensionHandle getDimension() const { return dimension ; };
00283     void setDimension(DimensionHandle);
00284 
00285     std::string getFederationName() const { return federationName ; };
00286     void setFederationName(std::string federation_name);
00287 
00288     std::string getFederateName() const { return federateName ; };
00289     void setFederateName(std::string federate_name);
00290 
00291     std::string getTag() const { return tag ; };
00292     void setTag(std::string new_tag);
00293 
00294     SpaceHandle getSpace() const { return space ; };
00295     void setSpace(SpaceHandle);
00296 
00297     Type getType() const { return type ; };
00298     void setType(Type);
00299 
00300     unsigned long getNumber() const { return number ; };
00301     void setNumber(unsigned long);
00302 
00303     long getRegion() const { return region ; };
00304     void setRegion(long);
00305 
00306     RTI::TickTime getMinTickTime() const { return minTickTime ; };
00307     void setMinTickTime(RTI::TickTime);
00308 
00309     RTI::TickTime getMaxTickTime() const { return maxTickTime ; };
00310     void setMaxTickTime(RTI::TickTime);
00311 
00312     void setFederationTimeDelta(FederationTimeDelta);
00313     FederationTimeDelta getFederationTimeDelta() const
00314     { return lookahead ; };
00315 
00316     void setAttribute(AttributeHandle);
00317     AttributeHandle getAttribute() const { return attribute ; };
00318 
00319     void setInteractionClass(InteractionClassHandle);
00320     InteractionClassHandle getInteractionClass() const {
00321         return interactionClass ;
00322     };
00323 
00324     void setObjectClass(ObjectClassHandle);
00325     ObjectClassHandle getObjectClass() const { return objectClass ; };
00326 
00327     void setResignAction(RTI::ResignAction);
00328     RTI::ResignAction getResignAction() const { return resignAction ; };
00329 
00330     void setFedTime(const double);
00331     double getFedTime() const { return fed_time.getTime(); };
00332 
00333     void setLookahead(const double);
00334 
00335     void setFederationTime(FederationTime);
00336     FederationTime getFederationTime() const { return fed_time.getTime(); };
00337 
00338     void setBoolean(bool);
00339     bool getBoolean() const { return boolean ; };
00340 
00341     void setObject(ObjectHandle);
00342     ObjectHandle getObject() const { return object ; };
00343 
00344     void setTransportation(TransportType);
00345     TransportType getTransportation() const
00346     { return transport; }
00347 
00348     void setOrdering(OrderType);
00349     OrderType getOrdering() const
00350     { return order; }
00351 
00352     void setEventRetraction(EventRetractionHandle);
00353     EventRetractionHandle getEventRetraction() const
00354     { return eventRetraction ; };
00355 
00356     void setParameter(ParameterHandle);
00357     ParameterHandle getParameter() const { return parameter ; };
00358 
00359     void setFederate(FederateHandle);
00360     FederateHandle getFederate() const { return federate ; };
00361 
00362     const std::vector<AttributeHandle>& getAHS() const ;
00363     void setAHS(const std::vector<AttributeHandle> &);
00364     void setAHS(const AttributeHandle *, int);
00365 
00366     std::vector<std::pair<AttributeHandle, AttributeValue_t> > getAHVPS() const ;
00367     void setAHVPS(const std::vector<std::pair<AttributeHandle, AttributeValue_t> > &);
00368 
00369     std::vector<std::pair<ParameterHandle, ParameterValue_t> > getPHVPS() const ;
00370     void setPHVPS(const std::vector<std::pair<ParameterHandle, ParameterValue_t> > &);
00371 
00372     void setAttributes(std::vector <AttributeHandle> &, ushort);
00373     void setAttributes(std::vector <AttributeHandle> &, std::vector <AttributeValue_t> &, ushort);
00374     void setParameters(std::vector <ParameterHandle> &, std::vector <ParameterValue_t> &, ushort);
00375 
00376     void setException(TypeException, const std::string& the_reason = "");
00377     TypeException getExceptionType() const { return exception ; };
00378     const char *getExceptionReason() const { return exceptionReason.c_str() ; };
00379 
00380     std::string getFEDid() const { return FEDid ; };
00381     void setFEDid(std::string FEDid);
00382 
00383         void displayvalueArray(char *);
00384 
00385     // Public attributes
00386     Type type ;
00387 
00388 protected:
00389     TypeException exception ;
00390     std::string exceptionReason;
00391 
00392     FedTime fed_time;
00393     bool boolean ;
00394     FederationTimeDelta lookahead ;
00395     FederateHandle federate ;
00396     RTI::ResignAction resignAction ;
00397     UShort idCount ;
00398     ObjectHandle firstId ;
00399     ObjectHandle lastId ;
00400     ObjectClassHandle objectClass ;
00401     InteractionClassHandle interactionClass ;
00402     AttributeHandle attribute ;
00403     ParameterHandle parameter ;
00404     ObjectHandle object ;
00405     TransportType transport ;
00406     OrderType order ;
00407     EventRetractionHandle eventRetraction ;
00408     SpaceHandle space ;
00409     DimensionHandle dimension ;
00410     // TransportationHandle transportation ;
00411     // OrderingHandle ordering ;
00412     unsigned long number ;
00413     long region ;
00414     RTI::TickTime minTickTime;
00415     RTI::TickTime maxTickTime;
00416 
00417 public:
00418 
00419     // used for both Attributes and Parameters arrays.
00420     UShort handleArraySize ;
00421     std::vector <AttributeHandle> handleArray ;
00422     std::vector <AttributeValue_t> valueArray ;
00423 
00424     Message &operator=(const Message &);
00425 
00426     void display(char *);
00427 
00428 private:
00429 
00430     // Read a Message Body from a Socket. Should be called after
00431     // ReadHeader.
00432     void readBody(MessageBuffer &msgBuffer);
00433 
00434     // Read a Header (buffer beginning)
00435     void readHeader(MessageBuffer &msgBuffer);
00436 
00437     // The message is written onto the socket by WriteHeader if no
00438     // body is required, or by WriteBody is a body has been required
00439     // by WriteHeader.
00440 
00441     // Prepare and write a Body to a socket. Should be called after
00442     // WriteHeader.
00443     void writeBody(MessageBuffer &msgBuffer);
00444 
00445     // Write a Header (buffer beginning)
00446     void writeHeader(MessageBuffer &msgBuffer);
00447 
00448     // -- Other Private Read Methods --
00449     void readHandleArray(MessageBuffer &msgBuffer);
00450     void readLabel(MessageBuffer &msgBuffer);
00451     void readName(MessageBuffer &msgBuffer);
00452     void readFederationName(MessageBuffer &msgBuffer);
00453     void readFederateName(MessageBuffer &msgBuffer);
00454     void readResignAction(MessageBuffer &msgBuffer);
00455     void readTag(MessageBuffer &msgBuffer);
00456     void readValueArray(MessageBuffer &msgBuffer);
00457     void readFEDid(MessageBuffer &msgBuffer);
00458 
00459     // -- Other Private Write Methods --
00460     void writeHandleArray(MessageBuffer &msgBuffer);
00461     void writeResignAction(MessageBuffer &msgBuffer);
00462     void writeValueArray(MessageBuffer &msgBuffer);
00463     void writeFEDid(MessageBuffer &msgBuffer);
00464     void writeFederationName(MessageBuffer &msgBuffer);
00465 
00466     MessageHeader header ;
00467     std::string label ;
00468     std::string name ;
00469     std::string  federateName ;
00470     std::string federationName ;
00471 
00472     std::string tag ;
00473     std::string FEDid ;
00474 };
00475 
00476 } // namespace certi
00477 
00478 #endif // CERTI_MESSAGE_HH

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