CSCommon: MCommandCommunicator.h 소스 파일

MAIET

MCommandCommunicator.h

00001 #ifndef MCOMMANDCOMMUNICATOR_H
00002 #define MCOMMANDCOMMUNICATOR_H
00003 
00004 #include "MCommandManager.h"
00005 #include "MUID.h"
00006 #include "MTCPSocket.h"
00007 
00008 
00009 class MCommandCommunicator;
00010 class MCommandBuilder;
00011 
00012 /*
00014 struct MCOMMUNICATORINFO{
00015     MUID    uid;        ///< 타겟 Communicator의 UID
00016 
00017     MCommandCommunicator*   pDirectConnection;  // 포인터 커넥션 Direction Connection
00018 
00019     // 커넥션을 위한 Low-Level Properties
00020     //...
00021     char            szIP[128];
00022     int             nPort;
00023     void*           pUserContext;
00024 
00025     MCOMMUNICATORINFO(void){
00026         uid.SetInvalid();
00027         pDirectConnection = NULL;
00028         szIP[0] = NULL;
00029         nPort = 0;
00030         pUserContext = NULL;
00031     }
00032 };
00033 */
00034 
00036 class MCommObject {
00037 protected:
00038     MUID                    m_uid;
00039 
00040     MCommandBuilder*        m_pCommandBuilder;
00041 
00042     MCommandCommunicator*   m_pDirectConnection;    // 포인터 커넥션 Direction Connection
00043     DWORD                   m_dwUserContext;
00044 
00045     char                    m_szIP[128];
00046     int                     m_nPort;
00047     bool                    m_bAllowed;
00048 public:
00049     MCommObject(MCommandCommunicator* pCommunicator);
00050     virtual ~MCommObject();
00051 
00052     MUID GetUID()           { return m_uid; }
00053     void SetUID(MUID uid)   { m_uid = uid; }
00054 
00055     MCommandBuilder* GetCommandBuilder()                { return m_pCommandBuilder; }
00056 
00057     MCommandCommunicator* GetDirectConnection()         { return m_pDirectConnection; }
00058     void SetDirectConnection(MCommandCommunicator* pDC) { m_pDirectConnection = pDC; }
00059     DWORD GetUserContext()                              { return m_dwUserContext; }
00060     void SetUserContext(DWORD dwContext)                { m_dwUserContext = dwContext; }
00061 
00062     char* GetIP()           { return m_szIP; }
00063     int GetPort()           { return m_nPort; }
00064     void SetAddress(const char* pszIP, int nPort) {
00065         strcpy(m_szIP, pszIP);
00066         m_nPort = nPort;
00067     }
00068     void SetAllowed(bool bAllowed) { m_bAllowed = bAllowed; }
00069     bool IsAllowed() { return m_bAllowed; }
00070 };
00071 
00072 
00073 class MPacketInfo {
00074 public:
00075     MCommObject*        m_pCommObj;
00076     MPacketHeader*      m_pPacket;
00077 
00078     MPacketInfo(MCommObject* pCommObj, MPacketHeader* pPacket) { m_pCommObj = pCommObj, m_pPacket = pPacket; }
00079 };
00080 typedef list<MPacketInfo*>          MPacketInfoList;
00081 typedef MPacketInfoList::iterator   MPacketInfoListItor;
00082 
00083 
00085 class MCommandCommunicator{
00086 protected:
00087     MCommandManager m_CommandManager;       
00088 
00089     MUID            m_This;                 
00090     MUID            m_DefaultReceiver;      
00091 
00092 protected:
00094     virtual void SendCommand(MCommand* pCommand)=0;
00096     virtual void ReceiveCommand(MCommand* pCommand);
00097 
00099     virtual void OnRegisterCommand(MCommandManager* pCommandManager);
00101     virtual bool OnCommand(MCommand* pCommand);
00103     virtual void OnPrepareRun(void);
00105     virtual void OnPrepareCommand(MCommand* pCommand);
00107     virtual void OnRun(void);
00108 
00110     void SetDefaultReceiver(MUID Receiver);
00111 public:
00112     MCommandCommunicator(void);
00113     virtual ~MCommandCommunicator(void);
00114 
00116     bool Create(void);
00118     void Destroy(void);
00119 
00123     virtual int Connect(MCommObject* pCommObj)=0;
00125     virtual int OnConnected(MUID* pTargetUID, MUID* pAllocUID, MCommObject* pCommObj);
00127     virtual void Disconnect(MUID uid)=0;
00128 
00130     virtual bool Post(MCommand* pCommand);
00132     virtual bool Post(char* szErrMsg, int nErrMsgCount, const char* szCommand);
00133 
00134     virtual MCommand* GetCommandSafe();
00135 
00137     void Run(void);
00138 
00140     MCommandManager* GetCommandManager(void){
00141         return &m_CommandManager;
00142     }
00143     MCommand* CreateCommand(int nCmdID, const MUID& TargetUID);
00144 
00145     enum _LogLevel  { LOG_DEBUG = 1, LOG_FILE = 2, LOG_PROG = 4, LOG_ALL = 7,  };
00147     virtual void Log(unsigned int nLogLevel, const char* szLog){}
00148     void LOG(unsigned int nLogLevel, const char *pFormat,...);
00149 
00151     MUID GetUID(void){ return m_This; }
00152 };
00153 
00154 #endif


MAIET entertainment