#pragma once #include #include #include #include "IOSocket.h" #include #include "../common/comm.h" template class FNRedirector { public: typedef void (T::* FN)(int8_t*, int16_t Size); bool Process(T* lhs, int32_t cmd, int8_t*, int16_t); void Insert(int32_t, FN fn); private: std::unordered_map m_fnmap; }; template bool FNRedirector::Process(T* lhs, int32_t cmd, int8_t* Data, int16_t Size) { auto it = m_fnmap.find(cmd); if (it != m_fnmap.end()) { (lhs->*it->second)(Data, Size); return true; } return false; } template void FNRedirector::Insert(int32_t cmd, FN fn) { m_fnmap.insert(std::make_pair(cmd, fn)); } class CUserSocket :public CIOSocket { public: CUserSocket(HANDLE hCom, SOCKET s); virtual void OnCreate() override; virtual void OnRead() override; void Process(int32_t cmd, int8_t*, int32_t Size); static void InitFnDirector(); virtual void OnClose() override; static FNRedirector Redirector; int32_t uid(); RemoNet::UserState state(); CarType car(); int32_t type(); std::string name(); RemoNet::VideoDesc ReqVideo(int32_t peer,int32_t index); void RepVideo(int32_t peer, int32_t index, RemoNet::VideoDesc desc); void LeaveVideo(int32_t peer,EgoType type); void CloseVideo(int32_t peer, int32_t index, EgoType type); void KickOff(); ULONGLONG GetTimeTick(); void NotifyOffer(int32_t peer, int32_t index, const char* type, const char* sdp); void NotifyAnswer(int32_t peer, int32_t index, const char* type, const char* sdp); void NotifyCandidate(int32_t peer, int32_t index, const char* type, const char* candidate, int32_t sdp_mline_index, const char* sdp_mid); void NotifyMoveBegin(int32_t peer, WorkArea area, int32_t no); void NotifyMoveEnd(int32_t peer, WorkArea area, int32_t no); void OnTimeout(); private: void OnReqVideo(int8_t* Data, int16_t Size); void OnRepVideo(int8_t* Data, int16_t Size); //void OnCancelReq(int8_t* Data, int16_t Size); void OnOffer(int8_t* Data, int16_t Size); void OnAnswer(int8_t* Data, int16_t Size); void OnCadidate(int8_t* Data, int16_t Size); void OnSigin(int8_t* Data, int16_t Size); void OnAdd(int8_t* Data, int16_t Size); void OnRobot(int8_t* Data, int16_t Size); void OnLeave(int8_t* Data, int16_t Size); //void OnCloseVideo(int8_t* Data,int16_t Size); void OnKeepAlive(int8_t* Data, int16_t Size); void OnMoveBegin(int8_t* Data, int16_t Size); void OnMoveEnd(int8_t* Data, int16_t Size); void OnChangeState(int8_t* Data, int16_t Size); void OnSwitchDriver(int8_t* Data, int16_t Size); void OnMoveRet(int8_t* Data, int16_t Size); private: bool _loginsucc; RemoNet::UserState _state; int32_t _uid; EgoType _egoType=EgoType::None; int32_t _userpeer; CarType _car = CarType::ZJ; std::string _name; ULONGLONG TimeTick; };