socket_remote.h 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. #pragma once
  2. #ifdef WIN32
  3. #ifndef WIN32_LEAN_AND_MEAN
  4. #define WIN32_LEAN_AND_MEAN
  5. #endif
  6. #endif
  7. #include <WS2tcpip.h>
  8. #include <WinSock2.h>
  9. #include <thread>
  10. #include <unordered_map>
  11. #include <functional>
  12. #include "../common/comm.h"
  13. #include "remote_notify.h"
  14. #include "../common/remote_def.h"
  15. class CIOBuffer;
  16. class SocketRemote
  17. {
  18. public:
  19. typedef void (SocketRemote::* FN)(int8_t* Data, int16_t Size);
  20. SocketRemote(IRemoteNotify* n);
  21. bool Start(const char* ip);
  22. void Run();
  23. void Stop();
  24. void Write(CIOBuffer* pBuffer);
  25. void WriteAddRobot(std::string& serial, std::string& name, std::string url, int32_t type, int32_t car);
  26. void WriteOffer(int32_t peer, int32_t index, const char* type, const char* sdp);
  27. void WriteAnswer(int32_t peer, int32_t index, const char* type, const char* sdp);
  28. void WriteCandidate(int32_t peer, int32_t index, const char* candidate, int32_t sdp_mline_index, const char* sdp_mid);
  29. void WriteVideoReq(int32_t peer, int32_t index);
  30. void WriteVideoRep(int32_t peer, remote::VideoDesc desc, int32_t index);
  31. void WriteKeepAlive();
  32. private:
  33. void NetProcess(int16_t cmd, int8_t* Data, int16_t Size);
  34. void OnNotifyRep(int8_t* Data, int16_t Size);
  35. void OnNotifyAdd(int8_t* Data, int16_t Size);
  36. void OnNotifyDel(int8_t* Data, int16_t Size);
  37. void OnAdd(int8_t* Data, int16_t Size);
  38. void OnNotifyLeave(int8_t* Data, int16_t Size);
  39. void OnNotifyOffer(int8_t* Data, int16_t Size);
  40. void OnNotifyAnswer(int8_t* Data, int16_t Size);
  41. void OnNotifyCandidate(int8_t* Data, int16_t Size);
  42. void OnNotifyState(int8_t* Data, int16_t Size);
  43. void OnNotifyReq(int8_t* Data, int16_t Size);
  44. void OnRobotRep(int8_t* Data, int16_t Size);
  45. private:
  46. std::unordered_map<int16_t, FN> FnMap;
  47. IRemoteNotify* _notify;
  48. SOCKET sockfd;
  49. std::thread _thread;
  50. bool _run;
  51. bool _connected;
  52. int32_t _uid;
  53. std::string _ip;
  54. };