#pragma once #include #include "../common/comm.h" #include "remote_def.h" class CIOBuffer; 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 CUserHandler { public: CUserHandler(int32_t fd); static void InitFnDirector(); long long GetTimeTick(); void OnTimeout(); int32_t uid(); int32_t Read(); int32_t Fd(); std::string& name(); UserState state(); void OnClose(); void Write(CIOBuffer * pBuffer); EgoType type(); 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 RepVideo(int32_t peer, int32_t index,remote::VideoDesc desc); remote::VideoDesc ReqVideo(int32_t peer, int32_t index); void LeaveVideo(int32_t peer,EgoType type); private: void Process(int32_t cmd, int8_t*, int32_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 OnKeepAlive(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 OnReqVideo(int8_t* Data, int16_t Size); void OnRepVideo(int8_t* Data, int16_t Size); private: int32_t _fd; CIOBuffer* _readBuffer; long long _tick; int32_t _uid; static FNRedirector Redirector; bool _loginsucc=false; std::string _name; EgoType _egoType; UserState _state; int32_t _peer; };