mod_assistantchannel.h 5.5 KB

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