# NetworkMessage.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
    00018 // USA
    00019 //
    00020 // $Id: NetworkMessage.hh,v 3.46 2009/04/08 10:47:19 approx Exp $
    00021 // ----------------------------------------------------------------------------
    00022
    00023 #ifndef CERTI_NETWORK_MESSAGE_HH
    00024 #define CERTI_NETWORK_MESSAGE_HH
    00025
    00026 #include "FedTimeD.hh"
    00027 #include "Exception.hh"
    00028 #include "Socket.hh"
    00029 #include "RTIRegion.hh"
    00030 #include "BasicMessage.hh"
    00031
    00032 #include <vector>
    00033 #include <string>
    00034
    00035 #ifdef FEDERATION_USES_MULTICAST
    00036 #define MC_PORT 60123
    00037 #define ADRESSE_MULTICAST "224.0.0.251"
    00038 #endif // FEDERATION_USES_MULTICAST
    00039
    00040 #define PORT_TCP_RTIG "60400"
    00041 #define PORT_UDP_RTIG "60500"
    00042
    00043 namespace certi {
    00044
    00052 class CERTI_EXPORT NetworkMessage : public BasicMessage
    00053 {
    00054 public:
    00055
    00056     typedef enum Type {
    00057         NOT_USED = 0, // Not used.
    00058         CLOSE_CONNEXION,
    00059         MESSAGE_NULL,
    00060         CREATE_FEDERATION_EXECUTION,
    00061         DESTROY_FEDERATION_EXECUTION,
    00062         JOIN_FEDERATION_EXECUTION,
    00063         RESIGN_FEDERATION_EXECUTION,
    00064         SET_TIME_REGULATING,
    00065         SET_TIME_CONSTRAINED,
    00066         TIME_REGULATION_ENABLED, // RTIG to RTIA
    00067         TIME_CONSTRAINED_ENABLED, // RTIG to RTIA
    00068         REGISTER_FEDERATION_SYNCHRONIZATION_POINT,
    00069         SYNCHRONIZATION_POINT_REGISTRATION_SUCCEEDED, // RTIG to RTIA
    00070         ANNOUNCE_SYNCHRONIZATION_POINT, // RTIG to RTIA
    00071         SYNCHRONIZATION_POINT_ACHIEVED,
    00072         FEDERATION_SYNCHRONIZED, // RTIG to RTIA
    00073         REQUEST_FEDERATION_SAVE,
    00074         FEDERATE_SAVE_BEGUN,
    00075         FEDERATE_SAVE_COMPLETE,
    00076         FEDERATE_SAVE_NOT_COMPLETE,
    00077         INITIATE_FEDERATE_SAVE, // RTIG to RTIA
    00078         FEDERATION_SAVED, // RTIG to RTIA
    00079         FEDERATION_NOT_SAVED, // RTIG to RTIA
    00080         REQUEST_FEDERATION_RESTORE,
    00081         FEDERATE_RESTORE_COMPLETE,
    00082         FEDERATE_RESTORE_NOT_COMPLETE,
    00083         REQUEST_FEDERATION_RESTORE_SUCCEEDED, // RTIG to RTIA
    00084         REQUEST_FEDERATION_RESTORE_FAILED, // RTIG to RTIA
    00085         FEDERATION_RESTORE_BEGUN, // RTIG to RTIA
    00086         INITIATE_FEDERATE_RESTORE, // RTIG to RTIA
    00087         FEDERATION_RESTORED, // RTIG to RTIA
    00088         FEDERATION_NOT_RESTORED, // RTIG to RTIA
    00089         PUBLISH_OBJECT_CLASS,
    00090         UNPUBLISH_OBJECT_CLASS,
    00091         PUBLISH_INTERACTION_CLASS,
    00092         UNPUBLISH_INTERACTION_CLASS,
    00093         SUBSCRIBE_OBJECT_CLASS,
    00094         UNSUBSCRIBE_OBJECT_CLASS,
    00095         SUBSCRIBE_INTERACTION_CLASS,
    00096         UNSUBSCRIBE_INTERACTION_CLASS,
    00097         TURN_INTERACTIONS_ON, // only RTIG->RTIA
    00098         TURN_INTERACTIONS_OFF, // only RTIG->RTIA
    00099         REGISTER_OBJECT,
    00100         DISCOVER_OBJECT, // only RTIG->RTIA
    00101         UPDATE_ATTRIBUTE_VALUES,
    00102         REFLECT_ATTRIBUTE_VALUES, // only RTIG->RTIA
    00103         SEND_INTERACTION,
    00104         RECEIVE_INTERACTION, // only RTIG->RTIA
    00105         DELETE_OBJECT,
    00106         REMOVE_OBJECT, // only RTIG->RTIA
    00107         CHANGE_ATTRIBUTE_TRANSPORT_TYPE,
    00108         CHANGE_ATTRIBUTE_ORDER_TYPE,
    00109         CHANGE_INTERACTION_TRANSPORT_TYPE,
    00110         CHANGE_INTERACTION_ORDER_TYPE,
    00111         REQUEST_CLASS_ATTRIBUTE_VALUE_UPDATE,
    00112         REQUEST_OBJECT_ATTRIBUTE_VALUE_UPDATE,
    00113         IS_ATTRIBUTE_OWNED_BY_FEDERATE,
    00114         QUERY_ATTRIBUTE_OWNERSHIP,
    00115         ATTRIBUTE_IS_NOT_OWNED,
    00116         INFORM_ATTRIBUTE_OWNERSHIP,
    00117         NEGOTIATED_ATTRIBUTE_OWNERSHIP_DIVESTITURE,
    00118         ATTRIBUTE_OWNERSHIP_ACQUISITION_NOTIFICATION,
    00119         ATTRIBUTE_OWNERSHIP_DIVESTITURE_NOTIFICATION,
    00120         REQUEST_ATTRIBUTE_OWNERSHIP_ASSUMPTION,
    00121         ATTRIBUTE_OWNERSHIP_UNAVAILABLE,
    00122         ATTRIBUTE_OWNERSHIP_ACQUISITION_IF_AVAILABLE,
    00123         UNCONDITIONAL_ATTRIBUTE_OWNERSHIP_DIVESTITURE,
    00124         ATTRIBUTE_OWNERSHIP_ACQUISITION,
    00125         REQUEST_ATTRIBUTE_OWNERSHIP_RELEASE,
    00126         CANCEL_NEGOTIATED_ATTRIBUTE_OWNERSHIP_DIVESTITURE,
    00127         ATTRIBUTE_OWNERSHIP_RELEASE_RESPONSE,
    00128         CANCEL_ATTRIBUTE_OWNERSHIP_ACQUISITION,
    00129         CONFIRM_ATTRIBUTE_OWNERSHIP_ACQUISITION_CANCELLATION,
    00130         DDM_CREATE_REGION,
    00131         DDM_MODIFY_REGION,
    00132         DDM_DELETE_REGION,
    00133         DDM_ASSOCIATE_REGION,
    00134         DDM_REGISTER_OBJECT,
    00135         DDM_UNASSOCIATE_REGION,
    00136         DDM_SUBSCRIBE_ATTRIBUTES,
    00137         DDM_UNSUBSCRIBE_ATTRIBUTES,
    00138         DDM_SUBSCRIBE_INTERACTION,
    00139         DDM_UNSUBSCRIBE_INTERACTION,
    00140         PROVIDE_ATTRIBUTE_VALUE_UPDATE,
    00141         GET_FED_FILE,
    00142         SET_CLASS_RELEVANCE_ADVISORY_SWITCH,
    00143         SET_INTERACTION_RELEVANCE_ADVISORY_SWITCH,
    00144         SET_ATTRIBUTE_RELEVANCE_ADVISORY_SWITCH,
    00145         SET_ATTRIBUTE_SCOPE_ADVISORY_SWITCH,
    00146         START_REGISTRATION_FOR_OBJECT_CLASS,
    00147         STOP_REGISTRATION_FOR_OBJECT_CLASS,
    00148         LAST
    00149     } Message_T;
    00150
    00151     NetworkMessage();
    00152     virtual ~NetworkMessage();
    00153
    00154     const NetworkMessage::Message_T getType() const {return type;};
    00155     const TypeException getException() const {return exception;};
    00156
    00160     virtual void serialize(MessageBuffer& msgBuffer);
    00164     virtual void deserialize(MessageBuffer& msgBuffer);
    00165
    00166     void send(Socket* socket, MessageBuffer& msgBuffer) throw (NetworkError, NetworkSignal);
    00167     void receive(Socket* socket, MessageBuffer& msgBuffer) throw (NetworkError, NetworkSignal);
    00168
    00169     // Parameter and Attribute Management
    00170     // Remove the Parameter of rank 'Rank' in the ParamArray and its value in
    00171     // ValueArray. If there are other parameter in the list, they are shifted
    00172     // one rank back.
    00173     // Ex: ParamArraySize = 3,
    00174     // ParamArray =[1, 2, 3], ValueArray =["Val1", "Val2", "Val3"]
    00175     //->removeParameter(1)
    00176     // ParamArraySize = 2,
    00177     // ParamArray =[1, 3], ValueArray =["Val1", "Val3"]
    00178     void removeParameter(UShort Rank);
    00179
    00180     // See RemoveParameter for explanations.
    00181     void removeAttribute(UShort Rank);
    00182
    00183     // Value Array Management
    00184
    00185     // Return a newly allocated ValueArray, exactly of size AttribArraySize.
    00186     // containing the actual Attribute values. You must FREE this structure.
    00187     std::vector <AttributeValue_t> getAttribValueArray();
    00188
    00189     // Return a newly allocated ValueArray, exactly of size ParamArraySize,
    00190     // containing the actual Parameter values. You must FREE this structure.
    00191     std::vector <ParameterValue_t> getParamValueArray();
    00192
    00193     void setAHS(const std::vector <AttributeHandle> &, int);
    00194
    00195         void displayValueArray(char *);
    00196
    00197     UShort number ;
    00198
    00199     std::string federationName ;
    00200     std::string federateName;
    00201     std::string FEDid ;
    00202
    00203     int bestEffortPeer ;
    00204     unsigned long bestEffortAddress ;
    00205
    00206     int numberOfRegulators ;
    00207
    00208     /* NM_DDM_Base class fields */
    00209     SpaceHandle            space;
    00210     int32_t                nbExtents;
    00211     int32_t                region;
    00212     ObjectHandle           object;
    00213     ObjectClassHandle      objectClass;
    00214     InteractionClassHandle interactionClass;
    00215
    00219     bool isDated() {return _isDated;};
    00224     void setDate(FederationTime new_date) {_isDated=true; date = new_date;};
    00225     const FederationTime getDate() const {return this->date;};
    00226
    00227     unsigned long multicastAddress ;
    00228
    00232     bool isLabelled() {return _isLabelled;};
    00233     void setLabel(const std::string new_label) {_isLabelled = true; label = new_label;};
    00234     void setLabel(const char *new_label) {_isLabelled = true; label = std::string(new_label); }
    00235     const std::string getLabel() const {return this->label;};
    00236
    00240     bool isTagged() {return _isTagged;};
    00241     void setTag(const std::string new_tag) {_isTagged = true; tag = new_tag;};
    00242     void setTag(const char *new_tag) {_isTagged = true; tag = std::string(new_tag); }
    00243     const std::string getTag() const {return this->tag;};
    00244
    00245         void sizeValueArray(int size) ;
    00246
    00247     ObjectHandlecount idCount ;
    00248     ObjectHandle firstId ;
    00249     ObjectHandle lastId ;
    00250
    00251     EventRetractionHandle eventRetraction ;
    00252
    00253     /* NM_WithHandleArray class specific fields */
    00254     UShort handleArraySize ;
    00255     std::vector <AttributeHandle> handleArray ;
    00256         std::vector <AttributeValue_t> valueArray ;
    00257
    00258     TransportType transport ;
    00259     OrderType order ;
    00260
    00262     const std::string getName() const {return name;}
    00263
    00268     TypeException exception ;
    00273     Handle federation ;
    00278     FederateHandle federate ;
    00279
    00283     std::string exceptionReason;
    00284
    00285     /* used by some sub-classes */
    00286     int32_t attribute;
    00287
    00288 protected:
    00294     std::string name;
    00295
    00302     Message_T type;
    00303
    00304 private:
    00310     FederationTime date;
    00316     bool _isDated;
    00317
    00323     std::string label;
    00329     bool _isLabelled;
    00330
    00336     std::string tag;
    00342     bool _isTagged;
    00343 };
    00344
    00345 // BUG: FIXME this is used by SocketMC and should
    00346 //      be thrown away as soon as possible.
    00347 #define TAILLE_MSG_RESEAU sizeof(NetworkMessage)
    00348
    00349 } // namespace certi
    00350
    00351 #endif // CERTI_NETWORK_MESSAGE_HH
    00352
    00353 // $Id: NetworkMessage.hh,v 3.46 2009/04/08 10:47:19 approx Exp $