#ifndef __ENTITY_SESSION_MANAGER_H #define __ENTITY_SESSION_MANAGER_H #include #include #include #include "CMessage.h" // #include "CSocketClient.h" #include "CWSCodec.h" namespace Chromium { enum RequestProcessType { PROCESS_NOTHING, PROCESS_SEND, PROCESS_STARTSESSION, PROCESS_FINDSESSION, PROCESS_RECORDMSG }; enum AckProcessType { ACKPROCESS_NOTHING, ACKPROCESS_SEND }; typedef struct WSClientReqInfoStruct { int transID; unsigned int hdlID; struct WSClientReqInfoStruct* next; }WSClientReqInfo; class EntitySessionManager { public: // EntitySessionManager(CSocketClient* pSocket, CWSCodec* serializer); EntitySessionManager(); ~EntitySessionManager(); std::pair GetStartSessionRequest(std::string entityname, std::string className); //返回分配的transId和生成的beginSession串 std::pair GetAllSessionRequest(int transId, bool isInitCfg); std::pair Get_getconfig_ack(std::string terminalno); RequestProcessType RequestProcess(CMessage* msg, std::string entityName, unsigned int hdlID, const ws_msgInfo &msgInfo); AckProcessType AckProcess(CMessage* msg, unsigned int& hdlID); AckProcessType AskProcessEvent(CMessage* msg, std::vector>& transIdandHdlIDArr); std::pair AskProcessSession(CMessage* msg, unsigned int& hdlID); std::string GetStartSessionAck(CMessage* msg, std::string entityname); std::pair DoSessionRemove(unsigned int session); EntitySessionManager& DoSessionUpdate(std::string entityname, int session); int MakeNewTransID(CMessage* msg, unsigned int hdlID); std::pair getSrcTransID(int newTransID); WSClientReqInfo* ReduceOriginTransID(CMessage* msg); void updateBeginSessionTime(std::string entityName, bool doCleanSessionTime = false); bool checkBeginSession(std::string entityName); void StoreSessionReq(int transid, std::string entityname); std::vector queryUnLinkSession(); static std::map queryAllSessionInfo(); void doWithErrorCode(int errorCode, int transId); static std::pair FromSessionIdToEntityName(int sessionId); private: static std::map m_session_map; // entity name -> session id std::map m_trans_map; // real trans id -> client trans id & client ws connection handler std::map m_session_ack_map; // trans id -> entity name std::map m_broadcast_map; // broadcast list std::map t_BeginSessionTime; // CSocketClient* m_socket; // CWSCodec* m_serializer; private: std::pair GetSessionIDByEntityName(std::string entityname); void RemoveAckListNode(int transid); std::string UpdateSessionMap(int transid, int sessionId); //更新session表并返回更新的实体名 // process with requests RequestProcessType ProcessWithInfo(CMessage* msg, std::string entityName, unsigned int hdlID, const ws_msgInfo& msgInfo); RequestProcessType ProcessWithBeginSession(CMessage* msg, std::string entityName, unsigned int hdlID, const ws_msgInfo& msgInfo); RequestProcessType ProcessWithEndSession(CMessage* msg, std::string entityName, unsigned int hdlID); RequestProcessType ProcessWithRequest(CMessage* msg, std::string entityName, unsigned int hdlID, const ws_msgInfo& msgInfo); RequestProcessType ProcessWithRegister(CMessage* msg, std::string entityName, unsigned int hdlID, const ws_msgInfo& msgInfo); RequestProcessType ProcessWithUnregister(CMessage* msg, std::string entityName, unsigned int hdlID); RequestProcessType ProcessWithSetVarReq(CMessage* msg, std::string entityName, unsigned int hdlID, const ws_msgInfo& msgInfo); RequestProcessType ProcessWithGetVarReq(CMessage* msg, std::string entityName, unsigned int hdlID, const ws_msgInfo& msgInfo); AckProcessType ProcessWithAck(CMessage* msg, unsigned int& hdlID); AckProcessType ProcessWithRecvEvent(CMessage* msg, unsigned int& hdlID); }; } #endif