mod_assistantchannel.cpp 17 KB

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