message_queue.h 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. #pragma once
  2. #include<mutex>
  3. #include<memory>
  4. #include<string>
  5. #include<condition_variable>
  6. #include <vector>
  7. #include "protocol.pb.h"
  8. #include "../common/socket_client.h"
  9. #include "../common/update_thread.h"
  10. class SocketClient;
  11. class PeerConnectionWrapper;
  12. class VideoRenderer;
  13. /*
  14. enum MessageType:int32_t
  15. {
  16. ReqVideo,
  17. RepVideo,
  18. Connected,
  19. Leave,
  20. AsyncMessage
  21. };
  22. */
  23. struct Message
  24. {
  25. int32_t cmd;
  26. int64_t param_l;
  27. int64_t param_r;
  28. };
  29. class CIOBuffer;
  30. class CMessageQueue
  31. {
  32. public:
  33. CMessageQueue();
  34. virtual ~CMessageQueue();
  35. virtual void Start();
  36. void EnQueue(CIOBuffer* pBuffer);
  37. virtual void Stop();
  38. virtual void Process(CIOBuffer * pBuffer) = 0;
  39. protected:
  40. virtual void OnIdle() = 0;
  41. std::chrono::time_point<std::chrono::high_resolution_clock> oldTime;
  42. private:
  43. void Run();
  44. private:
  45. std::mutex _lock;
  46. std::condition_variable _cv;
  47. CIOBuffer* _head;
  48. CIOBuffer* _tail;
  49. std::thread _thread;
  50. bool _run;
  51. protected:
  52. bool _ping;
  53. };