MCommand.h
00001 #ifndef MCOMMAND_H 00002 #define MCOMMAND_H 00003 00004 #include "MUID.h" 00005 00006 #include <vector> 00007 #include <list> 00008 using namespace std; 00009 00010 #include "MCommandParameter.h" 00011 00012 class MCommandManager; 00013 00014 // Command Description Flag 00015 #define MCDT_NOTINITIALIZED 0 00016 #define MCDT_MACHINE2MACHINE 1 00017 #define MCDT_LOCAL 2 00018 #define MCDT_TICKSYNC 4 00019 #define MCDT_TICKASYNC 8 00020 #define MCDT_USER 16 00021 #define MCDT_ADMIN 32 00022 #define MCDT_PEER2PEER 64 00023 00026 class MCommandDesc{ 00027 protected: 00028 int m_nID; 00029 char m_szName[256]; 00030 char m_szDescription[256]; 00031 int m_nFlag; 00032 00033 vector<MCommandParameterDesc*> m_ParamDescs; 00034 public: 00039 MCommandDesc(int nID, const char* szName, const char* szDescription, int nFlag); 00040 virtual ~MCommandDesc(void); 00041 00043 void AddParamDesc(MCommandParameterDesc* pParamDesc); 00044 00046 bool IsFlag(int nFlag) const; 00048 int GetID(void) const { return m_nID; } 00050 const char* GetName(void) const { return m_szName; } 00052 const char* GetDescription(void) const { return m_szDescription; } 00054 MCommandParameterDesc* GetParameterDesc(int i) const { 00055 if(i<0 || i>=(int)m_ParamDescs.size()) return NULL; 00056 return m_ParamDescs[i]; 00057 } 00059 int GetParameterDescCount(void) const { 00060 return (int)m_ParamDescs.size(); 00061 } 00063 MCommandDesc* Clone(); 00064 }; 00065 00066 00067 00069 class MCommand{ 00070 public: 00071 MUID m_Sender; 00072 MUID m_Receiver; 00073 00074 const MCommandDesc* m_pCommandDesc; 00075 vector<MCommandParameter*> m_Params; 00076 00077 protected: 00079 void Reset(void); 00081 void ClearParam(void); 00082 00083 public: 00084 MCommand(void); 00085 MCommand(const MCommandDesc* pCommandDesc, MUID Receiver, MUID Sender); 00086 MCommand::MCommand(int nID, MUID Sender, MUID Receiver, MCommandManager* pCommandManager); 00087 virtual ~MCommand(void); 00088 00090 void SetID(const MCommandDesc* pCommandDesc); 00092 void MCommand::SetID(int nID, MCommandManager* pCommandManager); 00094 int GetID(void) const { return m_pCommandDesc->GetID(); } 00096 const char* GetDescription(void){ return m_pCommandDesc->GetDescription(); } 00097 00099 bool AddParameter(MCommandParameter* pParam); 00101 int GetParameterCount(void) const; 00103 MCommandParameter* GetParameter(int i) const; 00104 00110 bool GetParameter(void* pValue, int i, MCommandParameterType t) const; 00111 00112 MUID GetSenderUID(void){ return m_Sender; } 00113 void SetSenderUID(MUID &uid) { m_Sender = uid; } 00114 MUID GetReceiverUID(void){ return m_Receiver; } 00115 00116 bool IsLocalCommand(void){ return (m_Sender==m_Receiver); } 00117 00119 MCommand* Clone(void) const; 00120 00122 bool CheckRule(void); 00123 00128 int GetData(char* pData, int nSize); 00133 bool SetData(char* pData, MCommandManager* pCM); 00134 }; 00135 00136 // 라인수 줄이기 위한 매크로 00137 #define NEWCMD(_ID) (new MCommand(_ID)) 00138 #define AP(_P) AddParameter(new _P) 00139 #define MKCMD(_C, _ID) { _C = NEWCMD(_ID); } 00140 #define MKCMD1(_C, _ID, _P0) { _C = NEWCMD(_ID); _C->AP(_P0); } 00141 #define MKCMD2(_C, _ID, _P0, _P1) { _C = NEWCMD(_ID); _C->AP(_P0); _C->AP(_P1); } 00142 #define MKCMD3(_C, _ID, _P0, _P1, _P2) { _C = NEWCMD(_ID); _C->AP(_P0); _C->AP(_P1); _C->AP(_P2); } 00143 #define MKCMD4(_C, _ID, _P0, _P1, _P2, _P3) { _C = NEWCMD(_ID); _C->AP(_P0); _C->AP(_P1); _C->AP(_P2); _C->AP(_P3); } 00144 #define MKCMD5(_C, _ID, _P0, _P1, _P2, _P3, _P4) { _C = NEWCMD(_ID); _C->AP(_P0); _C->AP(_P1); _C->AP(_P2); _C->AP(_P3); _C->AP(_P4); } 00145 #define MKCMD6(_C, _ID, _P0, _P1, _P2, _P3, _P4, _P5) { _C = NEWCMD(_ID); _C->AP(_P0); _C->AP(_P1); _C->AP(_P2); _C->AP(_P3); _C->AP(_P4); _C->AP(_P5); } 00146 00147 00148 // Short Name 00149 typedef MCommand MCmd; 00150 typedef MCommandDesc MCmdDesc; 00151 00152 #endif
MAIET entertainment