UserManager.h 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. #pragma once
  2. #include <unordered_map>
  3. #include <memory>
  4. #include <shared_mutex>
  5. #include <mutex>
  6. #include "../Protocol/win/Protocol.pb.h"
  7. #include "../common/comm.h"
  8. class CUserSocket;
  9. class CIOBuffer;
  10. struct Robot
  11. {
  12. int32_t uid;
  13. int32_t cid;
  14. int32_t type;
  15. std::string name;
  16. RemoNet::Robot::RobotState state;
  17. };
  18. class CUserManager
  19. {
  20. public:
  21. void Add(CUserSocket* ptr);
  22. void Check(int32_t uid);
  23. void Remove(CUserSocket* lhs);
  24. void Write(int32_t id, CIOBuffer* pBuffer);
  25. RemoNet::Robot::RobotState GetState(int32_t uid);
  26. static CUserManager& GetInstance();
  27. RemoNet::VideoDesc ConnectPeerVideo(int32_t peer, int32_t uid, int32_t index);
  28. void NotifyOffer(int32_t peer, int32_t uid, int32_t video, const char* type, const char* sdp);
  29. void NotifyAnswer(int32_t peer, int32_t uid, int32_t video, const char* type, const char* sdp);
  30. void NotifyCandidate(int32_t peer, int32_t uid, int32_t video, const char* type, const char* candidate, int32_t sdp_mline_index, const char* sdp_mid);
  31. void ReplyPeerVideo(int32_t peer, int32_t uid, RemoNet::VideoDesc ret, int32_t index);
  32. void LeavePeerVideo(int32_t peer, int32_t uid, EgoType type);
  33. void ClosePeerVideo(int32_t peer, int32_t uid, EgoType type,int32_t index);
  34. void GetRobot(int32_t cid, std::vector<Robot>& ret);
  35. void BroadCast(CIOBuffer* pBuffer, int32_t cid);
  36. void Start();
  37. void Run();
  38. private:
  39. std::vector<CUserSocket*> SocketList;
  40. std::mutex _lock;
  41. std::thread _thread;
  42. bool _run;
  43. };