message_queue.h 955 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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. private:
  42. void Run();
  43. private:
  44. std::mutex _lock;
  45. std::condition_variable _cv;
  46. CIOBuffer* _head;
  47. CIOBuffer* _tail;
  48. std::thread _thread;
  49. bool _run;
  50. protected:
  51. bool _ping;
  52. };