1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586 |
- #pragma once
- #include <unordered_map>
- #include "../common/comm.h"
- #include "remote_def.h"
- class CIOBuffer;
- template<typename T>
- 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<int32_t, FN> m_fnmap;
- };
- template<typename T>
- bool FNRedirector<T>::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<typename T>
- void FNRedirector<T>::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<CUserHandler> Redirector;
- bool _loginsucc=false;
- std::string _name;
- EgoType _egoType;
- UserState _state;
- int32_t _peer;
-
- };
|