Go to the documentation of this file.00001
00002
00003
00004
00005
00009
00010 #ifndef lgrCommand_H_
00011 #define lgrCommand_H_
00012
00013 #include "lgrCore.h"
00014
00015 #include <runtimeValue.h>
00016 #include <lgrExceptions.h>
00017 #include <vlutil/vlString.h>
00018 #include <vlutil/vlSmartPointers.h>
00019 #include <map>
00020
00021 namespace MAKLogger
00022 {
00023
00024 typedef unsigned char DtLgrDomainId;
00025 typedef unsigned char DtLgrProtocolId;
00026 typedef short DtLgrCommandId;
00027
00030 class DT_DLL_LGRCORE DtLgrCommandType
00031 {
00032 public:
00033
00035
00036 static const DtLgrDomainId Domain_Invalid = 0;
00037 static const DtLgrDomainId Domain_System = 1;
00038 static const DtLgrDomainId Domain_Player = 2;
00039 static const DtLgrDomainId Domain_Recorder = 3;
00040 static const DtLgrDomainId Domain_Editor = 4;
00041 static const DtLgrDomainId Domain_Simulation = 5;
00042 static const DtLgrDomainId Domain_Shared = 6;
00043 static const DtLgrDomainId Domain_UserStart = 20;
00045
00046 static const int theLgrDomainStringsCount;
00047 static const char * const theLgrDomainStrings[];
00048
00049 static DtLgrDomainId lookupDomain(const DtString& name);
00050
00052
00053 static const DtLgrProtocolId Protocol_Invalid = 0;
00054 static const DtLgrProtocolId Protocol_None = 1;
00055 static const DtLgrProtocolId Protocol_DIS = 2;
00056 static const DtLgrProtocolId Protocol_HLA_13 = 3;
00057 static const DtLgrProtocolId Protocol_HLA_1516 = 4;
00058 static const DtLgrProtocolId Protocol_HLA_1516E = 5;
00059 static const DtLgrProtocolId Protocol_TENA = 6;
00060 static const DtLgrProtocolId Protocol_Undefined = 7;
00061
00062
00063
00064 static const int theLgrProtocolsStringsCount;
00065 static const DtString theLgrProtocolsStrings[];
00066
00067 static DtLgrProtocolId lookupProtocol(const DtString& name);
00068
00069 static const DtString& lookupProtocolName(DtLgrProtocolId protocolId);
00070
00071 DtLgrCommandType();
00072
00073 DtLgrCommandType(DtLgrDomainId aDomain,DtLgrProtocolId aProtocol);
00074
00075 DtLgrCommandType(const DtLgrCommandType& type);
00076
00077 DtLgrDomainId domain();
00078 DtLgrProtocolId protocol();
00079
00080 bool operator==(const DtLgrCommandType& secondType) const;
00081
00082 bool operator!=(const DtLgrCommandType& secondType) const;
00083
00084 bool operator<(const DtLgrCommandType& secondType) const;
00085
00086 bool operator>(const DtLgrCommandType& secondType) const;
00087
00088 DtString toString();
00089
00090 public:
00091 static const char* domainToString(int domainValue);
00092 static const char* protocolToString(int protocolValue);
00093
00094 protected:
00095 DtLgrDomainId myDomain;
00096 DtLgrProtocolId myProtocol;
00097 };
00098
00100 template<>
00101 DT_DLL_LGRCORE int DtValue<DtLgrCommandType>::theTypeId();
00102
00103
00104 typedef DtBoost::shared_ptr<DtAnyValue> DtAnyValueSP;
00105 typedef std::map<DtString,DtAnyValueSP> DtCommandParams;
00106 typedef DtBoost::shared_ptr<DtCommandParams> DtCommandParamsSP;
00107
00110 class DT_DLL_LGRCORE DtCommand
00111 {
00112 public:
00113
00115 DtCommand(DtLgrDomainId domain,DtLgrProtocolId protocol,DtLgrCommandId command,
00116 const char* parametersBuffer=0);
00117
00119 DtCommand(DtLgrDomainId domain,DtLgrProtocolId protocol,const DtString& commandName);
00120
00122 DtCommand(const DtLgrCommandType& type,DtLgrCommandId command);
00123
00125 DtCommand(const DtCommand& type);
00126
00128 ~DtCommand();
00129
00131 DtLgrCommandType type() const;
00132
00134 DtLgrCommandId id() const;
00135
00137 void setId(DtLgrCommandId id);
00138
00140 const DtString* name() const;
00141
00143 void setParameter(const DtString& name,DtAnyValue*);
00144
00146 const DtAnyValue* parameter(const DtString& name) const;
00147
00149 void serializeParameters(DtString& parameterBuffer) const;
00150
00152 void deserializeParameters(const char* parameterBuffer);
00153
00155 static const DtLgrCommandId theUnknownCommand = 0;
00156
00160 bool operator==(const DtCommand&) const;
00161 bool operator!=(const DtCommand&) const;
00162 bool operator<(const DtCommand&) const;
00163 bool operator>(const DtCommand&) const;
00164
00165 protected:
00166 DtLgrCommandType myType;
00167 DtLgrCommandId myCommand;
00168 DtCommandParamsSP myParameters;
00169 DtString* myUnknownCommandName;
00170 };
00171
00173 typedef DtBoost::shared_ptr<DtCommand> DtCommandSP;
00174
00175 typedef DtBoost::shared_ptr<const DtCommand> DtResponse;
00176
00178 #define DT_FACTORY_COMMAND(commandName,createParams,decodeParams)\
00179 static DtCommandDefinition define##commandName##Command();\
00180 static DtCommand create##commandName##Command createParams;\
00181 static void decode##commandName##Command decodeParams;
00182
00184 #define DT_FACTORY_COMMAND_EXT(commandId,commandName,createParams,decodeParams)\
00185 static const DtLgrCommandId Command_##commandName = commandId;\
00186 static DtCommandDefinition define##commandName##Command();\
00187 static DtCommand create##commandName##Command createParams;\
00188 static void decode##commandName##Command decodeParams;
00189
00190
00192 #define DT_FACTORY_RESPONSE(responseName,createParams,decodeParams)\
00193 static DtResponse create##responseName##Response createParams;\
00194 static void decode##responseName##Response decodeParams;
00195
00196
00197
00199 #define DT_FACTORY_RESPONSE_EXT(responseId,responseName,createParams,decodeParams)\
00200 static const DtLgrCommandId Response_##responseName = responseId;\
00201 static DtResponse create##responseName##Response createParams;\
00202 static void decode##responseName##Response decodeParams;
00203
00204
00206 template <typename ValueType>
00207 void DtGetCommandParameter(const DtCommand& command,const DtString& name,ValueType& value);
00208
00210 template <typename ValueType>
00211 void DtGetResponseParameter(const DtResponse response,const DtString& name,ValueType& value);
00212
00213 #define lgrCommand_INC_
00214 #include "lgrCommand.inl"
00215 #undef lgrCommand_INC_
00216 }
00217
00218 #endif