123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176 |
- #ifndef RVC_MOD_ASSISTANTCHANNEL_H__
- #define RVC_MOD_ASSISTANTCHANNEL_H__
- #include "SpBase.h"
- #include "SpTest.h"
- #include "modVer.h"
- #include "Common/ListEntry.h"
- #include "mod_counterconnector/CallType.h"
- #include "bizchan.h"
- #include "EventCode.h"
- #include "AssistantChannel_server_g.h"
- using namespace AssistantChannel;
- class CBizChannelEntity : public CEntityBase
- {
- public:
- CBizChannelEntity() : m_id_seq(0) {}
- virtual ~CBizChannelEntity() {}
- virtual const char* GetEntityName() const { return "AssistantChannel"; }
- const char* GetEntityVersion() const { return MODULE_VERSION_FULL; }
- virtual bool IsService()const { return true; }
- ON_ENTITYT_TEST()
- virtual void OnPreStart(CAutoArray<CSimpleStringA> strArgs, CSmartPointer<ITransactionContext> pTransactionContext)
- {
- ErrorCodeEnum Error = __OnStart(Error_Succeed);
- pTransactionContext->SendAnswer(Error);
- }
- virtual void OnPreClose(EntityCloseCauseEnum eCloseCause, CSmartPointer<ITransactionContext> pTransactionContext)
- {
- ErrorCodeEnum Error = __OnClose(Error_Succeed);
- pTransactionContext->SendAnswer(Error);
- }
- ErrorCodeEnum __OnStart(ErrorCodeEnum preOperationError);
- ErrorCodeEnum __OnClose(ErrorCodeEnum preOperationError);
- virtual CServerSessionBase* OnNewSession(const char* pszRemoteEntityName, const char* pszClass);
- ErrorCodeEnum Connect(const char* ip, int port, const char* callno, CallingTypeEnum eType);
- ErrorCodeEnum Close();
- int GetState() { return m_eState; }
- ErrorCodeEnum RegisterState(int id, SpSubscribeContext<ChannelService_BeginState_Sub, ChannelService_State_Info>::Pointer ctx);
- ErrorCodeEnum RegisterRxPkt(int id, SpSubscribeContext<ChannelService_BeginRecv_Sub, ChannelService_Packet_Info>::Pointer ctx);
- void UnregisterState(int id);
- void UnregisterRxpkt(int id);
- ErrorCodeEnum Send(int type, bool compress, bool encrypt, int sub_type, int id, CBlob& data);
- private:
- struct NotifyOnClose : public ITaskSp
- {
- CBizChannelEntity* m_pEntity;
- virtual void Process()
- {
- m_pEntity->on_close();
- }
- };
- struct NotifyOnRecvPkt : public ITaskSp
- {
- CBizChannelEntity* m_pEntity;
- int type;
- int sub_type;
- int id;
- CBlob data;
- virtual void Process()
- {
- m_pEntity->on_recv_pkt(type, sub_type, id, data);
- }
- };
- struct NotifyOnConnect : public ITaskSp
- {
- CBizChannelEntity* m_pEntity;
- int error;
- CSimpleStringA remote_rtp_ip;
- int remote_video_port;
- int remote_video_desc;
- virtual void Process()
- {
- m_pEntity->on_connect(error, (LPCSTR)remote_rtp_ip, remote_video_port, remote_video_desc);
- }
- };
- void ChangeState(int new_state, const char* param = NULL);
- void on_recv_pkt(int type, int sub_type, int id, CBlob& data);
- void on_connect(int error, const char* remote_ip, int remote_video_rtp, int remote_video_desc);
- void on_close();
- void _on_recv_pkt(int type, int sub_type, int id, const char* pkt, int pkt_size);
- void _on_connect(int error, const char* remote_ip, int remote_video_rtp, int remote_video_desc);
- void _on_close();
- static void __on_recv_pkt(bizchan_t* chan, int type, int sub_type, int id, const char* pkt, int pkt_size, void* user_data)
- {
- CBizChannelEntity* pThis = static_cast<CBizChannelEntity*>(user_data);
- pThis->_on_recv_pkt(type, sub_type, id, pkt, pkt_size);
- }
- 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)
- {
- CBizChannelEntity* pThis = static_cast<CBizChannelEntity*>(user_data);
- pThis->_on_connect(error, remote_ip, remote_video_rtp, remote_video_desc);
- }
- static void __on_close(bizchan_t* chan, void* user_data)
- {
- CBizChannelEntity* pThis = static_cast<CBizChannelEntity*>(user_data);
- pThis->_on_close();
- }
- static void __on_destroy(bizchan_t* chan, void* user_data)
- {
- }
- static void __dbg(bizchan_t* chan, int level, char *msg, void* user_data)
- {
- CBizChannelEntity* pThis = static_cast<CBizChannelEntity*>(user_data);
- Dbg(msg);
- }
- private:
- DeviceTypeEnum m_eDeviceType;
- int m_eState;
- bizchan_t* m_pChan;
- int m_id_seq;
- struct state_entry
- {
- LIST_ENTRY entry;
- int id;
- SpSubscribeContext<ChannelService_BeginState_Sub, ChannelService_State_Info>::Pointer ctx;
- };
- LIST_ENTRY m_stateList;
- struct rxpkt_entry
- {
- LIST_ENTRY entry;
- int id;
- SpSubscribeContext<ChannelService_BeginRecv_Sub, ChannelService_Packet_Info>::Pointer ctx;
- };
- LIST_ENTRY m_rxpktList;
- };
- class ChannelServiceSession : public ChannelService_ServerSessionBase
- {
- public:
- ChannelServiceSession(CBizChannelEntity* pEntity, int id) : m_pEntity(pEntity), m_id(id) {}
- virtual void Handle_Connect(SpReqAnsContext<ChannelService_Connect_Req, ChannelService_Connect_Ans>::Pointer ctx);
- virtual void Handle_Close(SpReqAnsContext<ChannelService_Close_Req, ChannelService_Close_Ans>::Pointer ctx);
- virtual void Handle_GetState(SpReqAnsContext<ChannelService_GetState_Req, ChannelService_GetState_Ans>::Pointer ctx);
- virtual void Handle_BeginState(SpSubscribeContext<ChannelService_BeginState_Sub, ChannelService_State_Info>::Pointer ctx);
- virtual void Handle_EndState(SpOnewayCallContext<ChannelService_EndState_Info>::Pointer ctx);
- virtual void Handle_Send(SpOnewayCallContext<ChannelService_Send_Info>::Pointer ctx);
- virtual void Handle_BeginRecv(SpSubscribeContext<ChannelService_BeginRecv_Sub, ChannelService_Packet_Info>::Pointer ctx);
- virtual void Handle_EndRecv(SpOnewayCallContext<ChannelService_EndRecv_Info>::Pointer ctx);
- virtual void OnClose(ErrorCodeEnum eErrorCode);
- private:
- int m_id;
- CBizChannelEntity* m_pEntity;
- };
- #endif /*RVC_MOD_ASSISTANTCHANNEL_H__*/
|