mod_assistantchannel.cpp 18 KB

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