mod_assistantchannel.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. #ifndef RVC_MOD_ASSISTANTCHANNEL_H__
  2. #define RVC_MOD_ASSISTANTCHANNEL_H__
  3. #include "SpBase.h"
  4. #include "VideoDesc.h"
  5. #include "AssistantChannel_server_g.h"
  6. #include "AssistantChannel_def_g.h"
  7. #include "ListEntry.h"
  8. #include "mod_counterconnector/CallType.h"
  9. #include "bizchan.h"
  10. #include "rvc_media_common.h"
  11. #include "chan_protocol.h"
  12. #include "EventCode.h"
  13. #include "../mod_counterconnector/CallType.h"
  14. using namespace AssistantChannel;
  15. class CBizChannelEntity : public CEntityBase
  16. {
  17. public:
  18. CBizChannelEntity() : m_id_seq(0) {}
  19. virtual ~CBizChannelEntity() {}
  20. virtual const char* GetEntityName() const { return "AssistantChannel"; }
  21. virtual bool IsService()const { return true; }
  22. virtual void OnPreStart(CAutoArray<CSimpleStringA> strArgs,CSmartPointer<ITransactionContext> pTransactionContext);
  23. virtual void OnPreClose(EntityCloseCauseEnum eCloseCause,CSmartPointer<ITransactionContext> pTransactionContext);
  24. ErrorCodeEnum __OnStart(ErrorCodeEnum preOperationError);
  25. virtual void OnStarted();
  26. DeviceTypeEnum RvcGetDeviceType();
  27. ErrorCodeEnum __OnClose(ErrorCodeEnum preOperationError);
  28. virtual CServerSessionBase *OnNewSession(const char* pszRemoteEntityName, const char * pszClass);
  29. ErrorCodeEnum Connect(const char *ip, int port);
  30. ErrorCodeEnum Close();
  31. int GetState() { return m_eState; }
  32. ErrorCodeEnum RegisterState(int id, SpSubscribeContext<ChannelService_BeginState_Sub, ChannelService_State_Info>::Pointer ctx);
  33. ErrorCodeEnum RegisterRxPkt(int id, SpSubscribeContext<ChannelService_BeginRecv_Sub, ChannelService_Packet_Info>::Pointer ctx);
  34. void UnregisterState(int id);
  35. void UnregisterRxpkt(int id);
  36. ErrorCodeEnum Send(int type, bool compress, bool encrypt, int sub_type, int id, CBlob &data);
  37. //void on_recv_pkt(int type, int sub_type, const char *pkt, int pkt_size)
  38. void on_recv_pkt(int type, int sub_type, int id, CBlob &data);
  39. void on_connect(int error, const char *remote_ip, int remote_video_rtp, int remote_video_desc);
  40. void on_close();
  41. void _on_recv_pkt(int type, int sub_type, int id, const char *pkt, int pkt_size);
  42. void _on_connect(int error, const char *remote_ip, int remote_video_rtp, int remote_video_desc);
  43. void _on_close();
  44. private:
  45. struct NotifyOnClose : public ITaskSp
  46. {
  47. CBizChannelEntity *m_pEntity;
  48. virtual void Process()
  49. {
  50. m_pEntity->on_close();
  51. }
  52. };
  53. struct NotifyOnRecvPkt : public ITaskSp
  54. {
  55. CBizChannelEntity *m_pEntity;
  56. int type;
  57. int sub_type;
  58. int id;
  59. CBlob data;
  60. virtual void Process()
  61. {
  62. m_pEntity->on_recv_pkt(type, sub_type, id, data);
  63. }
  64. };
  65. struct NotifyOnConnect : public ITaskSp
  66. {
  67. CBizChannelEntity *m_pEntity;
  68. int error;
  69. CSimpleStringA remote_rtp_ip;
  70. int remote_video_port;
  71. int remote_video_desc;
  72. virtual void Process()
  73. {
  74. m_pEntity->on_connect(error, (LPCSTR)remote_rtp_ip, remote_video_port, remote_video_desc);
  75. }
  76. };
  77. void ChangeState(int new_state, const char *param = NULL);
  78. private:
  79. DeviceTypeEnum m_eDeviceType;
  80. int m_eState;
  81. bizchan_t *m_pChan;
  82. int m_id_seq;
  83. struct state_entry
  84. {
  85. LIST_ENTRY entry;
  86. int id;
  87. SpSubscribeContext<ChannelService_BeginState_Sub, ChannelService_State_Info>::Pointer ctx;
  88. };
  89. LIST_ENTRY m_stateList;
  90. struct rxpkt_entry
  91. {
  92. LIST_ENTRY entry;
  93. int id;
  94. SpSubscribeContext<ChannelService_BeginRecv_Sub, ChannelService_Packet_Info>::Pointer ctx;
  95. };
  96. LIST_ENTRY m_rxpktList;
  97. };
  98. class ChannelServiceSession : public ChannelService_ServerSessionBase
  99. {
  100. public:
  101. ChannelServiceSession(CBizChannelEntity *pEntity, int id) : m_pEntity(pEntity), m_id(id) {}
  102. virtual void Handle_Connect(SpReqAnsContext<ChannelService_Connect_Req, ChannelService_Connect_Ans>::Pointer ctx);
  103. virtual void Handle_Close(SpReqAnsContext<ChannelService_Close_Req, ChannelService_Close_Ans>::Pointer ctx);
  104. virtual void Handle_GetState(SpReqAnsContext<ChannelService_GetState_Req, ChannelService_GetState_Ans>::Pointer ctx);
  105. virtual void Handle_BeginState(SpSubscribeContext<ChannelService_BeginState_Sub, ChannelService_State_Info>::Pointer ctx);
  106. virtual void Handle_EndState(SpOnewayCallContext<ChannelService_EndState_Info>::Pointer ctx);
  107. virtual void Handle_Send(SpOnewayCallContext<ChannelService_Send_Info>::Pointer ctx);
  108. virtual void Handle_BeginRecv(SpSubscribeContext<ChannelService_BeginRecv_Sub, ChannelService_Packet_Info>::Pointer ctx);
  109. virtual void Handle_EndRecv(SpOnewayCallContext<ChannelService_EndRecv_Info>::Pointer ctx);
  110. virtual void OnClose(ErrorCodeEnum eErrorCode);
  111. private:
  112. int m_id;
  113. CBizChannelEntity *m_pEntity;
  114. };
  115. #endif /*RVC_MOD_ASSISTANTCHANNEL_H__*/