mod_assistantchannel.h 4.6 KB

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