CSCommon: MCommandBuilder.h 소스 파일

MAIET

MCommandBuilder.h

00001 #ifndef MCOMMANDBUILDER_H
00002 #define MCOMMANDBUILDER_H
00003 
00004 #include <windowsx.h>
00005 #include "MCommandManager.h"
00006 #include "Msg.h"
00007 #include "MDebug.h"
00008 #include "MCRC32.h"
00009 
00011 class MCommandBuilder { 
00012 protected:
00013     MUID                    m_uidSender;    // client
00014     MUID                    m_uidReceiver;  // server
00015     MCommandManager*        m_pCommandManager;
00016 
00017     #define COMMAND_BUFFER_LEN  16384
00018 
00019     char                    m_Buffer[COMMAND_BUFFER_LEN];
00020     int                     m_nBufferNext;
00021 
00022     MCommandList            m_CommandList;
00023     list<MPacketHeader*>    m_NetCmdList;
00024 
00025 protected:
00026     bool CheckBufferEmpty();
00027     bool EstimateBufferToCmd();
00028     void AddBuffer(char* pBuffer, int nLen);
00029     bool MoveBufferToFront(int nStart, int nLen);
00030     int MakeCommand(char* pBuffer, int nBufferLen);
00031     void Clear();
00032 public:
00033     MCommandBuilder(MUID uidSender, MUID uidReceiver, MCommandManager*  pCmdMgr);
00034     virtual ~MCommandBuilder() {
00035         Clear();
00036     }
00037     void SetUID(MUID uidReceiver, MUID uidSender)   {
00038         m_uidReceiver = uidReceiver;
00039         m_uidSender = uidSender;
00040     }
00041 
00042     bool Read(char* pBuffer, int nBufferLen);
00043     MCommand* GetCommand();
00044     MPacketHeader* GetNetCommand();
00045 };
00046 
00047 
00048 #ifdef _DEBUG
00049 // Network Buffer Emulation for Debug
00050 class MCmdBufTestor {
00051 public:
00052     char    m_szBuffer[16000];
00053     int     m_nBufferNext;
00054 
00055 public:
00056     MCmdBufTestor() { m_nBufferNext = 0; }
00057     int PostCmd(MCommand* pCommand) {
00058         const BUF_SIZE = 1024;
00059         char SendBuf[BUF_SIZE];
00060         int nSize = pCommand->GetData(SendBuf, BUF_SIZE);
00061         
00062         int nBlockSize = nSize+sizeof(MCommandMsg);
00063         MCommandMsg* pMsg = (MCommandMsg*)(m_szBuffer+m_nBufferNext);
00064         pMsg->nMsg = MSGID_COMMAND;
00065         pMsg->nSize = nBlockSize;
00066         CopyMemory(pMsg->Buffer, SendBuf, nSize);
00067 
00068         m_nBufferNext += nBlockSize;
00069         return nBlockSize;
00070     }
00071 };
00072 #endif
00073 // DEBUG SAMPLE //////////////////////////////////////////////////
00074 //  MCOMMUNICATORINFO Info;
00075 //  Info.uid = MUID(0,100);
00076 //  MCommandBuilder CmdBuilder(&Info, this);
00077 //
00078 //  MCommand* pCmd1 = CreateCommand(MC_AGENT_CONNECT, MUID(0,0));
00079 //  pCmd1->AddParameter(new MCmdParamStr("192.168.0.30"));
00080 //  pCmd1->AddParameter(new MCmdParamInt(5555));
00081 //
00082 //  MCommand* pCmd2 = CreateCommand(MC_AGENT_CONNECT, MUID(0,0));
00083 //  pCmd2->AddParameter(new MCmdParamStr("192.168.0.31"));
00084 //  pCmd2->AddParameter(new MCmdParamInt(6666));
00085 //
00086 //  MCmdBufTestor CmdTestor;
00087 //  int nSize1 = CmdTestor.PostCmd(pCmd1);
00088 //  int nSize2 = CmdTestor.PostCmd(pCmd2);
00089 //  int nSizeTotal = nSize1+nSize2;
00090 //
00091 //  //CmdBuilder.Read(CmdTestor.m_szBuffer, 4);
00092 //  //CmdBuilder.Read(CmdTestor.m_szBuffer+4, 45);
00093 //  //CmdBuilder.Read(CmdTestor.m_szBuffer+4+45, nSizeTotal-4-45);
00095 
00096 
00097 #endif


MAIET entertainment