mod_assistantchannel.cpp 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602
  1. #include "stdafx.h"
  2. #include "SpBase.h"
  3. #include "ListEntry.h"
  4. #include "VideoDesc.h"
  5. #include "AssistantChannel_server_g.h"
  6. #include "..\..\Other\libbizchan\bizchan.h"
  7. #include "rec_common.h"
  8. #include "chan_protocol.h"
  9. #include "..\include\EventCode.h"
  10. #include "..\mod_counterconnector\CallType.h"
  11. using namespace AssistantChannel;
  12. class CBizChannelEntity;
  13. static const char *__states[] = {
  14. "Idle", "Connecting", "Connected", "Closing"
  15. };
  16. inline const char *state2str(int state)
  17. {
  18. return __states[state];
  19. }
  20. static __inline unsigned int hash32_buf(const void *bf, size_t len, unsigned int hash)
  21. {
  22. const unsigned char *s = (const unsigned char*)bf;
  23. while (len-- != 0) /* "nemesi": k=257, r=r*257 */
  24. hash = hash * 257 + *s++;
  25. return (hash * 257);
  26. }
  27. static int MakeDesc(DWORD eScreen,DeviceTypeEnum eDevicetype)
  28. {
  29. if (eScreen == 1)
  30. {
  31. if (eMobilePadType == eDevicetype)
  32. {
  33. return media_desc_encode(
  34. ACM_VIDEO_MODE_SQUARE, ACM_VIDEO_ENCODE_H264, ACM_VIDEO_FPS_MOBILE,
  35. ACM_VIDEO_MODE_QVGA, ACM_VIDEO_ENCODE_H264, ACM_VIDEO_FPS_MOBILEAGENT);
  36. }
  37. else if((ePadtype == eDevicetype)||(eDesk2SType == eDevicetype))
  38. {
  39. return media_desc_encode(
  40. ACM_VIDEO_MODE_SQUARE, ACM_VIDEO_ENCODE_H264, ACM_VIDEO_FPS_MOBILE,
  41. ACM_VIDEO_MODE_QVGA, ACM_VIDEO_ENCODE_H264, ACM_VIDEO_FPS_MOBILE);
  42. }
  43. else
  44. {
  45. return media_desc_encode(
  46. ACM_VIDEO_MODE_SQUARE, ACM_VIDEO_ENCODE_H264, ACM_VIDEO_FPS_BASELINE,
  47. ACM_VIDEO_MODE_QVGA, ACM_VIDEO_ENCODE_H264, ACM_VIDEO_FPS_BASELINE);
  48. }
  49. }
  50. else if (eScreen == 2)
  51. {
  52. return media_desc_encode(
  53. ACM_VIDEO_MODE_SQUARE, ACM_VIDEO_ENCODE_H264, ACM_VIDEO_FPS_BASELINE,
  54. ACM_VIDEO_MODE_VGA, ACM_VIDEO_ENCODE_H264, ACM_VIDEO_FPS_BASELINE);
  55. }
  56. else
  57. {
  58. assert(0);
  59. }
  60. return 0;
  61. }
  62. class ChannelServiceSession : public ChannelService_ServerSessionBase
  63. {
  64. public:
  65. ChannelServiceSession(CBizChannelEntity *pEntity, int id) : m_pEntity(pEntity), m_id(id) {}
  66. virtual void Handle_Connect(SpReqAnsContext<ChannelService_Connect_Req, ChannelService_Connect_Ans>::Pointer ctx);
  67. virtual void Handle_Close(SpReqAnsContext<ChannelService_Close_Req, ChannelService_Close_Ans>::Pointer ctx);
  68. virtual void Handle_GetState(SpReqAnsContext<ChannelService_GetState_Req, ChannelService_GetState_Ans>::Pointer ctx);
  69. virtual void Handle_BeginState(SpSubscribeContext<ChannelService_BeginState_Sub, ChannelService_State_Info>::Pointer ctx);
  70. virtual void Handle_EndState(SpOnewayCallContext<ChannelService_EndState_Info>::Pointer ctx);
  71. virtual void Handle_Send(SpOnewayCallContext<ChannelService_Send_Info>::Pointer ctx);
  72. virtual void Handle_BeginRecv(SpSubscribeContext<ChannelService_BeginRecv_Sub, ChannelService_Packet_Info>::Pointer ctx);
  73. virtual void Handle_EndRecv(SpOnewayCallContext<ChannelService_EndRecv_Info>::Pointer ctx);
  74. virtual void OnClose(ErrorCodeEnum eErrorCode);
  75. private:
  76. int m_id;
  77. CBizChannelEntity *m_pEntity;
  78. };
  79. class CBizChannelEntity : public CEntityBase
  80. {
  81. public:
  82. CBizChannelEntity() : m_id_seq(0) {}
  83. virtual ~CBizChannelEntity() {}
  84. virtual const char *GetEntityName() const { return "AssistantChannel"; }
  85. virtual bool IsService()const{return true;}
  86. virtual void OnPreStart(CAutoArray<CSimpleStringA> strArgs,CSmartPointer<ITransactionContext> pTransactionContext)
  87. {
  88. ErrorCodeEnum Error = __OnStart(Error_Succeed);
  89. pTransactionContext->SendAnswer(Error);
  90. }
  91. virtual void OnPreClose(EntityCloseCauseEnum eCloseCause,CSmartPointer<ITransactionContext> pTransactionContext)
  92. {
  93. ErrorCodeEnum Error = __OnClose(Error_Succeed);
  94. pTransactionContext->SendAnswer(Error);
  95. }
  96. ErrorCodeEnum __OnStart(ErrorCodeEnum preOperationError)
  97. {
  98. //MessageBoxA(0,0,0,0);
  99. bizchan_lib_init();
  100. m_eState = eChannelState_Idle;
  101. m_pChan = NULL;
  102. m_eDeviceType = eStand2sType;
  103. //is Pad Version
  104. CSmartPointer<IEntityFunction> spFunction = GetFunction();
  105. CSystemStaticInfo stStaticinfo;
  106. spFunction->GetSystemStaticInfo(stStaticinfo);
  107. if (stricmp(stStaticinfo.strMachineType,"RVC.PAD")==0)
  108. {
  109. if (stricmp(stStaticinfo.strSite,"CMB.FLB")==0)
  110. {
  111. LOG_TRACE("the type is mobile pad");
  112. m_eDeviceType = eMobilePadType;
  113. }
  114. else
  115. {
  116. LOG_TRACE("the type is pad");
  117. m_eDeviceType = ePadtype;
  118. }
  119. }
  120. else if (stricmp(stStaticinfo.strMachineType,"RVC.Desk2S")==0)
  121. {
  122. LOG_TRACE("the type is Desk2S");
  123. m_eDeviceType = eDesk2SType;
  124. }
  125. else if (stricmp(stStaticinfo.strMachineType,"RPM.Stand1S")==0)
  126. {
  127. LOG_TRACE("the type is RPM.Stand1S");
  128. m_eDeviceType = eRpm1sType;
  129. }
  130. else
  131. {
  132. LOG_TRACE("the type is standard");
  133. m_eDeviceType = eStand2sType;
  134. }
  135. ListEntry_InitHead(&m_stateList);
  136. ListEntry_InitHead(&m_rxpktList);
  137. return Error_Succeed;
  138. }
  139. ErrorCodeEnum __OnClose(ErrorCodeEnum preOperationError)
  140. {
  141. //.....
  142. bizchan_lib_term();
  143. return Error_Succeed;
  144. }
  145. virtual CServerSessionBase *OnNewSession(const char* pszRemoteEntityName, const char * pszClass)
  146. {
  147. LOG_FUNCTION();
  148. LOG_TRACE("%s connected class = %s!", pszRemoteEntityName, pszClass);
  149. return new ChannelServiceSession(this, m_id_seq++);
  150. }
  151. ErrorCodeEnum Connect(const char *ip, int port, const char *callno, CallingTypeEnum eType)
  152. {
  153. ErrorCodeEnum Error = Error_Succeed;
  154. if (m_eState == eChannelState_Idle)
  155. {
  156. CSystemStaticInfo Info;
  157. bizchan_config_t config = {0};
  158. bizchan_callback_t cb = {0};
  159. GetFunction()->GetSystemStaticInfo(Info);
  160. config.proxy_server = const_cast<char*>(ip);
  161. config.proxy_server_port = port;
  162. if (MOBILETOPAD_CALLTYPE == eType || PADTOPAD_CALLTYPE == eType){
  163. config.session_id = const_cast<char*>(callno);
  164. }else{
  165. config.session_id = const_cast<char*>(((const char*)Info.strTerminalID));
  166. }
  167. if (MOBILETOPAD_CALLTYPE == eType){
  168. config.crypt_type = 1;
  169. }
  170. config.call_no = const_cast<char*>(callno);
  171. config.client_id = "";
  172. config.video.desc = MakeDesc(Info.eScreen,m_eDeviceType);
  173. config.video.rtp_port = REC_COMMON_VIDEO_PORT;
  174. cb.user_data = this;
  175. cb.on_close = &__on_close;
  176. cb.on_connect = &__on_connect;
  177. cb.on_destroy = &__on_destroy;
  178. cb.on_recv_pkt = &__on_recv_pkt;
  179. int rc = bizchan_create(&config, &cb, &m_pChan);
  180. if (rc == 0)
  181. {
  182. rc = bizchan_start_connect(m_pChan);
  183. }
  184. if (rc != 0)
  185. Error = Error_Unexpect;
  186. else
  187. ChangeState(eChannelState_Connecting);
  188. }
  189. else
  190. {
  191. Error = Error_InvalidState;
  192. }
  193. return Error;
  194. }
  195. ErrorCodeEnum Close()
  196. {
  197. ErrorCodeEnum Error = Error_Succeed;
  198. if (m_eState == eChannelState_Connecting || m_eState == eChannelState_Connected) {
  199. int rc = bizchan_start_close(m_pChan);
  200. if (rc == 0) {
  201. ChangeState(eChannelState_Closing);
  202. } else {
  203. Error = Error_Unexpect;
  204. }
  205. } else {
  206. Error = Error_InvalidState;
  207. }
  208. return Error_Succeed;
  209. }
  210. int GetState() { return m_eState; }
  211. ErrorCodeEnum RegisterState(int id, SpSubscribeContext<ChannelService_BeginState_Sub, ChannelService_State_Info>::Pointer ctx)
  212. {
  213. state_entry *pos;
  214. ListEntry_ForEach(pos, &m_stateList, state_entry, entry)
  215. {
  216. if (pos->id == id)
  217. {
  218. return Error_AlreadyExist;
  219. }
  220. }
  221. pos = new state_entry();
  222. pos->ctx = ctx;
  223. pos->id = id;
  224. ListEntry_AddTail(&m_stateList, &pos->entry);
  225. return Error_Succeed;
  226. }
  227. ErrorCodeEnum RegisterRxPkt(int id, SpSubscribeContext<ChannelService_BeginRecv_Sub, ChannelService_Packet_Info>::Pointer ctx)
  228. {
  229. rxpkt_entry *pos;
  230. ListEntry_ForEach(pos, &m_rxpktList, rxpkt_entry, entry)
  231. {
  232. if ((pos->id == id)&&(pos->ctx->Req.type == ctx->Req.type))
  233. {
  234. return Error_AlreadyExist;
  235. }
  236. }
  237. Dbg("RegisterRxPkt id = %d",id);
  238. pos = new rxpkt_entry();
  239. pos->id = id;
  240. pos->ctx = ctx;
  241. ListEntry_AddTail(&m_rxpktList, &pos->entry);
  242. return Error_Succeed;
  243. }
  244. void UnregisterState(int id)
  245. {
  246. state_entry *pos,*n;
  247. ListEntry_ForEachSafe(pos,n, &m_stateList, state_entry, entry) {
  248. if (pos->id == id) {
  249. ListEntry_DeleteNode(&pos->entry);
  250. delete pos;
  251. }
  252. }
  253. }
  254. void UnregisterRxpkt(int id)
  255. {
  256. rxpkt_entry *pos,*n;
  257. //ListEntry_ForEach(pos, &m_rxpktList, rxpkt_entry, entry)
  258. ListEntry_ForEachSafe(pos, n, &m_rxpktList, rxpkt_entry, entry)
  259. {
  260. if((pos->id == id))
  261. {
  262. Dbg("UnregisterRxpkt id = %d",pos->id);
  263. ListEntry_DeleteNode(&pos->entry);
  264. delete pos;
  265. }
  266. }
  267. }
  268. ErrorCodeEnum Send(int type, bool compress, bool encrypt, int sub_type, int id, CBlob &data)
  269. {
  270. if (m_eState == eChannelState_Connected) {
  271. LOG_TRACE("tx pkt, %d bytes, type = %d, compress = %d, encrypt = %d, sub_type = %d, id = %d, hash=%d", data.m_iLength, type, !!compress, !!encrypt, sub_type, id, hash32_buf(data.m_pData, data.m_iLength, 0));
  272. Dbg("tx pkt, %d bytes, type = %d, compress = %d, encrypt = %d, sub_type = %d, id = %d, hash=%d", data.m_iLength, type, !!compress, !!encrypt, sub_type, id, hash32_buf(data.m_pData, data.m_iLength, 0));
  273. int rc = bizchan_post_pkt(m_pChan, type, compress, encrypt, sub_type, id, (const char*)data.m_pData, data.m_iLength);
  274. return rc == 0 ? Error_Succeed : Error_NetBroken;
  275. }
  276. else
  277. {
  278. return Error_NetBroken;
  279. }
  280. }
  281. private:
  282. struct NotifyOnClose : public ITaskSp
  283. {
  284. CBizChannelEntity *m_pEntity;
  285. virtual void Process()
  286. {
  287. m_pEntity->on_close();
  288. }
  289. };
  290. struct NotifyOnRecvPkt : public ITaskSp
  291. {
  292. CBizChannelEntity *m_pEntity;
  293. int type;
  294. int sub_type;
  295. int id;
  296. CBlob data;
  297. virtual void Process()
  298. {
  299. m_pEntity->on_recv_pkt(type, sub_type, id, data);
  300. }
  301. };
  302. struct NotifyOnConnect : public ITaskSp
  303. {
  304. CBizChannelEntity *m_pEntity;
  305. int error;
  306. CSimpleStringA remote_rtp_ip;
  307. int remote_video_port;
  308. int remote_video_desc;
  309. virtual void Process()
  310. {
  311. m_pEntity->on_connect(error, (LPCSTR)remote_rtp_ip, remote_video_port, remote_video_desc);
  312. }
  313. };
  314. void ChangeState(int new_state, const char *param = NULL)
  315. {
  316. if (m_eState != new_state) {
  317. LOG_TRACE("change state from %s to %s", state2str(m_eState), state2str(new_state));
  318. m_eState = new_state;
  319. state_entry *pos;
  320. ListEntry_ForEach(pos, &m_stateList, state_entry, entry) {
  321. ChannelService_State_Info State;
  322. State.state = new_state;
  323. State.status = state2str(new_state);
  324. if (param) {
  325. State.param = param;
  326. }
  327. pos->ctx->SendMessage(State);
  328. }
  329. }
  330. }
  331. //void on_recv_pkt(int type, int sub_type, const char *pkt, int pkt_size)
  332. void on_recv_pkt(int type, int sub_type, int id, CBlob &data)
  333. {
  334. LOG_TRACE("rx pkt, %d bytes, type = %d, sub_type = %d, id = %d, hash = %d", data.m_iLength, type, sub_type, id, hash32_buf(data.m_pData, data.m_iLength, 0));
  335. Dbg("rx pkt, %d bytes, type = %d, sub_type = %d, id = %d, hash = %d", data.m_iLength, type, sub_type, id, hash32_buf(data.m_pData, data.m_iLength, 0));
  336. rxpkt_entry *pos;
  337. ListEntry_ForEach(pos, &m_rxpktList, rxpkt_entry, entry)
  338. {
  339. if (pos->ctx->Req.type == type)
  340. {
  341. ChannelService_Packet_Info pkt;
  342. pkt.type = type;
  343. pkt.sub_type = sub_type;
  344. pkt.id = id;
  345. //pkt.data.m_bManaged = true;
  346. pkt.data = data;
  347. //data.m_bManaged = false;
  348. pos->ctx->SendMessage(pkt);
  349. //break;
  350. }
  351. }
  352. }
  353. void on_connect(int error, const char *remote_ip, int remote_video_rtp, int remote_video_desc)
  354. {
  355. if (!error) {
  356. if (m_eState == eChannelState_Connecting) {
  357. CSimpleStringA strValue;
  358. ErrorCodeEnum Error = GetFunction()->GetSysVar("VideoWindowInitializeParam", strValue);
  359. if (Error == Error_Succeed) {
  360. int local_view_x;
  361. int local_view_y;
  362. int local_view_cx;
  363. int local_view_cy;
  364. int remote_view_x;
  365. int remote_view_y;
  366. int remote_view_cx;
  367. int remote_view_cy;
  368. int remote_video_width = 0;
  369. int remote_video_height = 0;
  370. {
  371. CSystemStaticInfo Info;
  372. GetFunction()->GetSystemStaticInfo(Info);
  373. if (Info.eScreen == 1)
  374. {
  375. remote_video_width = REC_COMMON_VIDEO_SSM_AGENT_WIDTH;
  376. remote_video_height = REC_COMMON_VIDEO_SSM_AGENT_HEIGHT;
  377. }
  378. else
  379. {
  380. remote_video_width = REC_COMMON_VIDEO_DSM_AGENT_WIDTH;
  381. remote_video_height = REC_COMMON_VIDEO_DSM_AGENT_HEIGHT;
  382. }
  383. }
  384. ParseVideoViewParam((LPCSTR)strValue, local_view_x, local_view_y, local_view_cx, local_view_cy,
  385. remote_view_x, remote_view_y, remote_view_cx, remote_view_cy);
  386. Dbg("Get Video Window Initialize Param:%d,%d,%d,%d %d,%d,%d,%d",local_view_x, local_view_y, local_view_cx, local_view_cy,
  387. remote_view_x, remote_view_y, remote_view_cx, remote_view_cy);
  388. CSimpleStringA param;
  389. if (eMobilePadType == m_eDeviceType)
  390. {
  391. param = BuildVideoDesc(remote_ip, remote_video_rtp, remote_video_width, remote_video_height,
  392. REC_COMMON_VIDEO_FPS_MOBILE_AGENT, local_view_x, local_view_y, local_view_cx, local_view_cy,
  393. remote_view_x, remote_view_y, remote_view_cx, remote_view_cy);
  394. }
  395. else if((ePadtype == m_eDeviceType)||(eDesk2SType == m_eDeviceType))
  396. {
  397. param = BuildVideoDesc(remote_ip, remote_video_rtp, remote_video_width, remote_video_height,
  398. REC_COMMON_VIDEO_FPS_MOBILE, local_view_x, local_view_y, local_view_cx, local_view_cy,
  399. remote_view_x, remote_view_y, remote_view_cx, remote_view_cy);
  400. }
  401. else
  402. {
  403. param = BuildVideoDesc(remote_ip, remote_video_rtp, remote_video_width, remote_video_height,
  404. REC_COMMON_VIDEO_FPS, local_view_x, local_view_y, local_view_cx, local_view_cy,
  405. remote_view_x, remote_view_y, remote_view_cx, remote_view_cy);
  406. }
  407. ChangeState(eChannelState_Connected, (LPCSTR)param);
  408. } else {
  409. Dbg("get VideoWindowInitializeParam failed!");
  410. bizchan_start_close(m_pChan);
  411. }
  412. }
  413. } else {
  414. if (m_pChan) {
  415. bizchan_close(m_pChan);
  416. bizchan_destroy(m_pChan);
  417. m_pChan = NULL;
  418. }
  419. ChangeState(eChannelState_Idle);
  420. }
  421. }
  422. void on_close()
  423. {
  424. if (m_pChan) {
  425. bizchan_close(m_pChan);
  426. bizchan_destroy(m_pChan);
  427. m_pChan = NULL;
  428. }
  429. ChangeState(eChannelState_Idle);
  430. }
  431. void _on_recv_pkt(int type, int sub_type, int id, const char *pkt, int pkt_size)
  432. {
  433. LOG_TRACE("_on rx pkt, %d bytes, type = %d, sub_type = %d, id = %d, hash = %d", pkt_size, type, sub_type, id, hash32_buf(pkt, pkt_size, 0));
  434. NotifyOnRecvPkt *task = new NotifyOnRecvPkt();
  435. task->m_pEntity = this;
  436. task->type = type;
  437. task->sub_type = sub_type;
  438. task->id = id;
  439. task->data.m_bManaged = true;
  440. task->data.m_iLength = pkt_size;
  441. if (pkt_size)
  442. {
  443. task->data.m_pData = new char[pkt_size];
  444. memcpy(task->data.m_pData, pkt, pkt_size);
  445. } else {
  446. task->data.m_pData = NULL;
  447. }
  448. GetFunction()->PostEntityTaskFIFO(task);
  449. }
  450. void _on_connect(int error, const char *remote_ip, int remote_video_rtp, int remote_video_desc)
  451. {
  452. NotifyOnConnect *task = new NotifyOnConnect();
  453. task->m_pEntity = this;
  454. task->error = error;
  455. task->remote_rtp_ip = remote_ip;
  456. task->remote_video_port = remote_video_rtp;
  457. task->remote_video_desc = remote_video_desc;
  458. GetFunction()->PostEntityTaskFIFO(task);
  459. }
  460. void _on_close()
  461. {
  462. NotifyOnClose *task = new NotifyOnClose();
  463. task->m_pEntity = this;
  464. GetFunction()->PostEntityTaskFIFO(task);
  465. }
  466. static void __on_recv_pkt(bizchan_t *chan, int type, int sub_type, int id, const char *pkt, int pkt_size, void *user_data)
  467. {
  468. CBizChannelEntity *pThis = static_cast<CBizChannelEntity *>(user_data);
  469. pThis->_on_recv_pkt(type, sub_type, id, pkt, pkt_size);
  470. }
  471. 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)
  472. {
  473. CBizChannelEntity *pThis = static_cast<CBizChannelEntity *>(user_data);
  474. pThis->_on_connect(error, remote_ip, remote_video_rtp, remote_video_desc);
  475. }
  476. static void __on_close(bizchan_t *chan, void *user_data)
  477. {
  478. CBizChannelEntity *pThis = static_cast<CBizChannelEntity *>(user_data);
  479. pThis->_on_close();
  480. }
  481. static void __on_destroy(bizchan_t *chan, void *user_data)
  482. {
  483. }
  484. private:
  485. DeviceTypeEnum m_eDeviceType;
  486. int m_eState;
  487. bizchan_t *m_pChan;
  488. int m_id_seq;
  489. struct state_entry
  490. {
  491. LIST_ENTRY entry;
  492. int id;
  493. SpSubscribeContext<ChannelService_BeginState_Sub, ChannelService_State_Info>::Pointer ctx;
  494. };
  495. LIST_ENTRY m_stateList;
  496. struct rxpkt_entry
  497. {
  498. LIST_ENTRY entry;
  499. int id;
  500. SpSubscribeContext<ChannelService_BeginRecv_Sub, ChannelService_Packet_Info>::Pointer ctx;
  501. };
  502. LIST_ENTRY m_rxpktList;
  503. };
  504. void ChannelServiceSession::Handle_Connect( SpReqAnsContext<ChannelService_Connect_Req, ChannelService_Connect_Ans>::Pointer ctx )
  505. {
  506. LOG_TRACE("start connect, %s:%d [%s]", (LPCSTR)ctx->Req.ip, ctx->Req.port, (LPCSTR)ctx->Req.callno);
  507. ErrorCodeEnum Error = m_pEntity->Connect(ctx->Req.ip, ctx->Req.port, ctx->Req.callno, (CallingTypeEnum)ctx->Req.etype);
  508. LOG_TRACE("connect Error = %d", Error);
  509. ctx->Answer(Error);
  510. }
  511. void ChannelServiceSession::Handle_Close( SpReqAnsContext<ChannelService_Close_Req, ChannelService_Close_Ans>::Pointer ctx )
  512. {
  513. LOG_TRACE("connect close!");
  514. ErrorCodeEnum Error = m_pEntity->Close();
  515. ctx->Answer(Error);
  516. }
  517. void ChannelServiceSession::Handle_GetState( SpReqAnsContext<ChannelService_GetState_Req, ChannelService_GetState_Ans>::Pointer ctx )
  518. {
  519. ctx->Ans.status = state2str(m_pEntity->GetState());
  520. ctx->Answer(Error_Succeed);
  521. }
  522. void ChannelServiceSession::Handle_BeginState( SpSubscribeContext<ChannelService_BeginState_Sub, ChannelService_State_Info>::Pointer ctx )
  523. {
  524. m_pEntity->RegisterState(m_id, ctx);
  525. }
  526. void ChannelServiceSession::Handle_EndState( SpOnewayCallContext<ChannelService_EndState_Info>::Pointer ctx )
  527. {
  528. m_pEntity->UnregisterState(m_id);
  529. }
  530. void ChannelServiceSession::Handle_Send( SpOnewayCallContext<ChannelService_Send_Info>::Pointer ctx )
  531. {
  532. m_pEntity->Send(ctx->Info.type, ctx->Info.compress, ctx->Info.encrypt, ctx->Info.sub_type, ctx->Info.id, ctx->Info.data);
  533. }
  534. void ChannelServiceSession::Handle_BeginRecv( SpSubscribeContext<ChannelService_BeginRecv_Sub, ChannelService_Packet_Info>::Pointer ctx )
  535. {
  536. m_pEntity->RegisterRxPkt(m_id, ctx);
  537. }
  538. void ChannelServiceSession::Handle_EndRecv( SpOnewayCallContext<ChannelService_EndRecv_Info>::Pointer ctx )
  539. {
  540. m_pEntity->UnregisterRxpkt(m_id);
  541. }
  542. void ChannelServiceSession::OnClose( ErrorCodeEnum eErrorCode )
  543. {
  544. m_pEntity->UnregisterRxpkt(m_id);
  545. m_pEntity->UnregisterState(m_id);
  546. }
  547. SP_BEGIN_ENTITY_MAP()
  548. SP_ENTITY(CBizChannelEntity)
  549. SP_END_ENTITY_MAP()