1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495 |
- #ifndef __CWSCODEC_H
- #define __CWSCODEC_H
- #include "CStructureInterpreter.h"
- #include "CMessage.h"
- #include "cJSON.h"
- #include "baseEx.h"
- // message type
- // Info = 0, //info message, no response
- // BeginSession = 1, //start entity session
- // EndSession = 2, //end entity session
- // Request = 3, //call request
- // RequestAck = 4, //request acknowledge
- // SessionAck = 5, //start session acknowledge
- // Register = 6, //register entity event
- // Unregister = 7, //unregister entity event
- // Event = 8, //event message
- // LogEvent = 9, //log event
- // LogWarn = 10, //log warn
- // SetVarReq = 11, //set sysvar request
- // SetVarAck = 12, //set sysvar response
- // GetVarReq = 13, //get sysvar request
- // GetVarAck = 14 //get sysvar response
- namespace Chromium{
- typedef struct entity_def_struct{
- char entity_name[64];
- char class_name[64];
- int methodID;
- }entity_def_struct;
- class CWSCodec{
- public:
- CWSCodec();
- ~CWSCodec();
- static CWSCodec* getInstance();
- void init(const char* xmlPath);
- void setEntityHandler(CSmartPointer<IEntityFunction> p);
- std::pair<int, CMessage*> JsonToBuffer(std::string strJson);
- std::string BufferToJson(CMessage& msg, int replaceTransId = 0);
- std::string GetEntityName(std::string strJson);
- std::string GetClassName(std::string strJson);
- private:
- void DeserializeRequestAck(CMessage& msg, std::map<int, entity_def_struct>::iterator& it, int& rpos, cJSON *ret);
- void DeserializeEvent(CMessage& msg, std::vector<CMedthodInterface>* list, int& rpos, cJSON *ret);
- void DeserializeBase(CMessage& msg, CTransStruct& ts, int& rpos, cJSON *ret);
- char* getJsonStr(cJSON *pJson);
- void SerializeInfo(cJSON* js, char* data, int* wpos, int* capacity, CMedthodInterface* pI, char* errmsg);
- void SerializeBeginSession(cJSON* js, char* data, int* wpos, int* capacity, CMedthodInterface* pI, char* errmsg);
- void SerializeEndSession(cJSON* js, char* data, int* wpos, int* capacity, CMedthodInterface* pI, char* errmsg);
- void SerializeRequest(cJSON* js, char* data, int* wpos, int* capacity, CMedthodInterface* pI, char* errmsg);
- void SerializeRegister(cJSON* js, char* data, int* wpos, int* capacity, CMedthodInterface* pI, char* errmsg);
- void SerializeUnregister(cJSON* js, char* data, int* wpos, int* capacity, CMedthodInterface* pI, char* errmsg);
- /* void SerializeEvent(cJSON* js, char* data, int* wpos, int* capacity, unsigned int* len);*/
- void SerializeLogEvent(cJSON* js, char* data, int* wpos, int* capacity, CMedthodInterface* pI, char* errmsg);
- void SerializeLogWarn(cJSON* js, char* data, int* wpos, int* capacity, CMedthodInterface* pI, char* errmsg);
- void SerializeSetVarReq(cJSON* js, char* data, int* wpos, int* capacity, CMedthodInterface* pI, char* errmsg);
- void SerializeGetVarReq(cJSON* js, char* data, int* wpos, int* capacity, CMedthodInterface* pI, char* errmsg);
- void GeneralSerialize(cJSON* js, char* data, int* wpos, int* capacity, CMedthodInterface* pI, char* errmsg);
- bool GetCJsonObjectValue(cJSON *root, const char* strKey, char* dstValue, char* errmsg);
- bool GetCJsonObjectValue(cJSON *root, const char* strKey, int& dstValue, char* errmsg);
- bool GetCJsonObjectValue(cJSON *root, const char* strKey, short& dstValue, char* errmsg);
- bool GetCJsonObjectValue(cJSON *root, const char* strKey, unsigned short& dstValue, char* errmsg);
- bool GetCJsonObjectValue(cJSON *root, const char* strKey, unsigned int& dstValue, char* errmsg);
- bool GetCJsonObjectValue(cJSON *root, const char* strKey, double& dstValue, char* errmsg);
- bool GetCJsonObjectValue(cJSON *root, const char* strKey, bool& dstValue, char* errmsg);
- bool GetCJsonObjectValue(cJSON *root, const char* strKey, CSimpleStringA& dstValue, char* errmsg);
- bool GetCJsonObjectValue(cJSON *root, const char* strKey, CSimpleStringW& dstValue, char* errmsg);
- bool GetCJsonArraySize(cJSON *root, const char* strKey, int& dstValue, char* errmsg);
- bool GetCJsonObjectValue(cJSON *obj, int& dstValue, char* errmsg);
- bool GetCJsonObjectValue(cJSON *obj, CSimpleStringA& dstValue, char* errmsg);
- bool GetCJsonObjectValue(cJSON *obj, CSimpleStringW& dstValue, char* errmsg);
- bool GetCJsonObjectValue(cJSON *obj, unsigned int& dstValue, char* errmsg);
- int UTF8ToUnicode(char* input, CSimpleStringW& output);
- void hexdump(const char *buf, const int num);
- private:
- CStructureInterpreter* mInterpreter;
- std::map<int,entity_def_struct> *m_AckCallbackList;
- std::map<int, std::vector<CMedthodInterface>*> *m_EventCallbackList;
- CMessage m_DeserializeCache;
- CMessage m_SerializeCache; //´æÔÚÔàÊý¾Ý¿ÉÄÜ
- CSmartPointer<IEntityFunction> m_pFunc;
- };
- }
- #endif
|