UserManager.h 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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 type;
  14. std::string name;
  15. RemoNet::UserState state;
  16. CarType car;
  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::UserState 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 NotifyMoveBegin(int32_t peer, int32_t uid, WorkArea area, int32_t no);
  35. void NotifyMoveEnd(int32_t peer,int32_t uid, WorkArea, int32_t no);
  36. void GetRobot(std::vector<Robot>& ret);
  37. void BroadCast(CIOBuffer* pBuffer);
  38. void NotifyState(int32_t uid,EgoType type, RemoNet::UserState state );
  39. void NotifySwitchDriver(int32_t peer, int32_t uid);
  40. void NotifyMoveRet(int32_t peer, int32_t uid, RemoNet::MoveDesc desc);
  41. void Start();
  42. void Run();
  43. private:
  44. std::vector<CUserSocket*> SocketList;
  45. std::mutex _lock;
  46. std::thread _thread;
  47. bool _run;
  48. };