mod_counterconnector.cpp 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873
  1. /////////////////////////////////
  2. ///// 连线服务
  3. /////////////////////////////////
  4. #include "stdafx.h"
  5. #include "ListEntry.h"
  6. #include "Event.h"
  7. #include "mod_counterconnector.h"
  8. #include "CounterConnector_msg_g.h"
  9. #include "../include/EventCode.h"
  10. using namespace CounterConnector;
  11. #define EVT_CONVERTER "EventConverter"
  12. void CCounterConnectorEntity ::OnPreStart(CAutoArray<CSimpleStringA> strArgs,CSmartPointer<ITransactionContext> pTransactionContext)
  13. {
  14. ErrorCodeEnum Error = __OnStart(Error_Succeed);
  15. CSmartPointer<IEntityFunction> spFunction = GetFunction();
  16. Error = spFunction->SubscribeBroadcast("LivenessDetection", NULL, this, m_uidlivenessListener);
  17. if (Error != Error_Succeed)
  18. {
  19. LOG_TRACE("subscribe LivenessDetection evt failed!");
  20. pTransactionContext->SendAnswer(Error);
  21. return;
  22. }
  23. pTransactionContext->SendAnswer(Error);
  24. }
  25. void CCounterConnectorEntity ::OnPreClose(EntityCloseCauseEnum eCloseCause,CSmartPointer<ITransactionContext> pTransactionContext)
  26. {
  27. ErrorCodeEnum Error = __OnClose(Error_Succeed);
  28. pTransactionContext->SendAnswer(Error);
  29. }
  30. void CCounterConnectorEntity ::OnSelfTest(EntityTestEnum eTestType,CSmartPointer<ITransactionContext> pTransactionContext)
  31. {
  32. if (Test_ShakeHand == eTestType)
  33. {
  34. pTransactionContext->SendAnswer(Error_Succeed);
  35. }
  36. }
  37. ErrorCodeEnum CCounterConnectorEntity ::__OnStart(ErrorCodeEnum preOperationError)
  38. {
  39. if (preOperationError != Error_Succeed)
  40. return preOperationError;
  41. //MessageBoxA(0, 0, 0, 0);
  42. //is Pad Version
  43. m_pCurrentSession = NULL;
  44. m_bIsSalesRecord = FALSE;
  45. m_bIsRemoteRecord = FALSE;
  46. m_bIsRemoteRecordBroadCast = FALSE;
  47. CSmartPointer<IEntityFunction> spFunction = GetFunction();
  48. CSystemStaticInfo stStaticinfo;
  49. spFunction->GetSystemStaticInfo(stStaticinfo);
  50. if (stricmp(stStaticinfo.strMachineType,"RVC.PAD")==0)
  51. {
  52. m_bIsPadType = TRUE;
  53. }
  54. else
  55. {
  56. m_bIsPadType = FALSE;
  57. }
  58. m_IsStand2SType = TRUE;
  59. if (stricmp(stStaticinfo.strMachineType,"RVC.Stand2S")!=0){
  60. m_IsStand2SType = FALSE;
  61. }
  62. ErrorCodeEnum Error;
  63. m_pCounterConnectorChannel = new ChannelCounterConnectorClient(this);
  64. Error = m_pCounterConnectorChannel->Connect();
  65. if (Error != Error_Succeed)
  66. {
  67. m_pCounterConnectorChannel->SafeDelete();
  68. Dbg("ChannelCounterConnectorClient connect fail!");
  69. return Error;
  70. }
  71. {
  72. ChannelService_BeginState_Sub Sub;
  73. Error = m_pCounterConnectorChannel->BeginState(Sub);
  74. if (Error != Error_Succeed)
  75. {
  76. LOG_TRACE("BeginState biz channel failed!");
  77. m_pCounterConnectorChannel->GetFunction()->CloseSession();
  78. m_pCounterConnectorChannel = NULL;
  79. return Error;
  80. }
  81. }
  82. {
  83. ChannelService_BeginRecv_Sub Sub;
  84. Sub.type = ACM_TYPE_DEVICE;
  85. Error = m_pCounterConnectorChannel->BeginRecv(Sub);
  86. if (Error != Error_Succeed)
  87. {
  88. Dbg("Begin BeginRecv ACM_TYPE_DEVICE failed!");
  89. m_pCounterConnectorChannel->GetFunction()->CloseSession();
  90. m_pCounterConnectorChannel = NULL;
  91. return Error;
  92. }
  93. }
  94. {
  95. ChannelService_BeginRecv_Sub Sub;
  96. Sub.type = ACM_TYPE_AGENTVIDEOTYPE;
  97. Error = m_pCounterConnectorChannel->BeginRecv(Sub);
  98. if (Error != Error_Succeed)
  99. {
  100. Dbg("Begin BeginRecv ACM_TYPE_AGENTVIDEOTYPE failed!");
  101. m_pCounterConnectorChannel->GetFunction()->CloseSession();
  102. m_pCounterConnectorChannel = NULL;
  103. return Error;
  104. }
  105. }
  106. {
  107. ChannelService_BeginRecv_Sub Sub;
  108. Sub.type = ACM_TYPE_CALLTRANS;
  109. Error = m_pCounterConnectorChannel->BeginRecv(Sub);
  110. if (Error != Error_Succeed)
  111. {
  112. Dbg("Begin BeginRecv ACM_TYPE_CALLTRANS failed!");
  113. m_pCounterConnectorChannel->GetFunction()->CloseSession();
  114. m_pCounterConnectorChannel = NULL;
  115. return Error;
  116. }
  117. }
  118. m_fsm.Init(this);
  119. int i = 0;
  120. m_arrListener.Init(24);
  121. spFunction->SubscribeLog(m_arrListener[i++], this, Log_Event, Severity_None, Error_IgnoreAll, EVENT_MOD_CONNECT_PICKUP_CALL,NULL,false);
  122. spFunction->SubscribeLog(m_arrListener[i++], this, Log_Event, Severity_None, Error_IgnoreAll, EVENT_MOD_CONNECT_HANDFREE_CALL,NULL,false);
  123. spFunction->SubscribeLog(m_arrListener[i++], this, Log_Event, Severity_None, Error_IgnoreAll, EVENT_MOD_CONNECT_HANDFREE_TO_PICKUP);
  124. spFunction->SubscribeLog(m_arrListener[i++], this, Log_Event, Severity_None, Error_IgnoreAll, EVENT_MOD_CONNECT_PICKUP_TO_HANDFREE);
  125. spFunction->SubscribeLog(m_arrListener[i++], this, Log_Event, Severity_None, Error_IgnoreAll, EVENT_MOD_CONNECT_HANNUP);
  126. spFunction->SubscribeLog(m_arrListener[i++], this, Log_Event, Severity_None, Error_IgnoreAll, EVENT_MOD_CONNECT_HANNUP_BY_CONNECTING);
  127. spFunction->SubscribeLog(m_arrListener[i++], this, Log_Event, Severity_None, Error_IgnoreAll, EVENT_MOD_CONNECT_HANNUP_BY_AGENT);
  128. spFunction->SubscribeLog(m_arrListener[i++], this, Log_Event, Severity_None, Error_IgnoreAll, EVENT_MOD_CONNECT_GPIO_PICKUP);
  129. spFunction->SubscribeLog(m_arrListener[i++], this, Log_Event, Severity_None, Error_IgnoreAll, EVENT_MOD_CONNECT_GPIO_HANDFREE);
  130. spFunction->SubscribeLog(m_arrListener[i++], this, Log_Event, Severity_None, Error_IgnoreAll, EVENT_MOD_CONNECT_AGENT_HANDFREE_PICKUP);
  131. spFunction->SubscribeLog(m_arrListener[i++], this, Log_Event, Severity_None, Error_IgnoreAll, EVENT_MOD_CONNECT_AGENT_PICKUP_HANDFREE);
  132. spFunction->SubscribeLog(m_arrListener[i++], this, Log_Event, Severity_None, Error_IgnoreAll, LOG_EVT_SELFCHECK_ASSISTANTCHANNEL_IDLE);
  133. spFunction->SubscribeLog(m_arrListener[i++], this, Log_Event, Severity_None, Error_IgnoreAll, LOG_EVT_SELFCHECK_SIPPHONE_IDLE);
  134. spFunction->SubscribeLog(m_arrListener[i++], this, Log_Event, Severity_None, Error_IgnoreAll, LOG_EVT_UI_STARTRECORD,NULL,false);
  135. spFunction->SubscribeLog(m_arrListener[i++], this, Log_Event, Severity_None, Error_IgnoreAll, LOG_EVT_UI_STOPRECORD,NULL,false);
  136. spFunction->SubscribeLog(m_arrListener[i++], this, Log_Event, Severity_None, Error_IgnoreAll, LOG_EVT_UI_RETURNMENU,NULL,false);
  137. spFunction->SubscribeLog(m_arrListener[i++], this, Log_Event, Severity_None, Error_IgnoreAll, LOG_EVT_UI_STARTPHOTOGRAPH,NULL,false);
  138. spFunction->SubscribeLog(m_arrListener[i++], this, Log_Event, Severity_None, Error_IgnoreAll, LOG_EVT_DISTRIBUTE_ASSISTANTCHANNEL_IDLE);
  139. spFunction->SubscribeLog(m_arrListener[i++], this, Log_Event, Severity_None, Error_IgnoreAll, LOG_EVT_DISTRIBUTE_SIPPHONE_IDLE);
  140. spFunction->SubscribeLog(m_arrListener[i++], this, Log_Event, Severity_None, Error_IgnoreAll, EVENT_MOD_CONNECT_STOP_RECORD_BROADCAST,NULL,false);
  141. spFunction->SubscribeLog(m_arrListener[i++], this, Log_Event, Severity_None, Error_IgnoreAll, EVENT_MOD_CONNECT_BEGAIN_RECORD_CALL,NULL,false);
  142. spFunction->SubscribeLog(m_arrListener[i++], this, Log_Event, Severity_None, Error_IgnoreAll, LOG_EVT_UI_STARTREMOTERECORD,NULL,false);
  143. spFunction->SubscribeLog(m_arrListener[i++], this, Log_Event, Severity_None, Error_IgnoreAll, LOG_EVT_UI_STOPREMOTERECORD,NULL,false);
  144. spFunction->SubscribeLog(m_arrListener[i++], this, Log_Event, Severity_None, Error_IgnoreAll, LOG_EVT_UI_STARTRECORDPREVIEW,NULL,false);
  145. return Error_Succeed;
  146. }
  147. ErrorCodeEnum CCounterConnectorEntity ::__OnClose(ErrorCodeEnum preOperationError)
  148. {
  149. if (preOperationError != Error_Succeed)
  150. return preOperationError;
  151. int i;
  152. CSmartPointer<IEntityFunction> spFunction = GetFunction();
  153. for (i = 0; i < m_arrListener.GetCount(); ++i) {
  154. spFunction->UnsubscribeLog(m_arrListener[i]);
  155. }
  156. m_arrListener.Clear();
  157. m_fsm.PostEventFIFO(new FSMEvent(USER_EVT_EXIT));
  158. return Error_Succeed;
  159. }
  160. void CCounterConnectorEntity ::OnLog(const CAutoArray<CUUID> &SubIDs, const CUUID nLogID,const LogTypeEnum eLogType, const SeverityLevelEnum eLevel,
  161. const DWORD dwSysError,const DWORD dwUserCode,const DWORD dwEntityInstanceID, const WORD wEntityDevelID,
  162. const CAutoArray<DWORD> &Param, const char *pszEntityName, const char *pszModuleName,const char *pszMessage)
  163. {
  164. LOG_TRACE("user_code = %08x", dwUserCode);
  165. switch (dwUserCode)
  166. {
  167. case EVENT_MOD_CONNECT_GPIO_PICKUP:
  168. {
  169. m_fsm.m_bHandFree = FALSE;
  170. if (!m_fsm.m_bIsAgentControl)
  171. {
  172. m_fsm.m_bAgentHandFree = FALSE;
  173. }
  174. CSimpleStringA strValue;
  175. GetFunction()->GetSysVar("CallState", strValue);
  176. Dbg("摘机,and CallState is %s.", strValue);
  177. }
  178. break;
  179. case EVENT_MOD_CONNECT_GPIO_HANDFREE:
  180. {
  181. m_fsm.m_bHandFree = TRUE;
  182. if (!m_fsm.m_bIsAgentControl)
  183. {
  184. m_fsm.m_bAgentHandFree = TRUE;
  185. }
  186. CSimpleStringA strValue;
  187. GetFunction()->GetSysVar("CallState", strValue);
  188. Dbg("挂机,and CallState is %s.", strValue);
  189. }
  190. break;
  191. case EVENT_MOD_CONNECT_PICKUP_CALL: // 提机呼叫
  192. if (!m_bIsRemoteRecordBroadCast){
  193. Dbg("提机呼叫");
  194. m_fsm.PostEventFIFO(new FSMEvent(USER_EVT_PICKUP_CALL));
  195. }
  196. else{
  197. Dbg("remote recording broadcast time, ignore mod connect pickup call event, and hand free flag is %s.",m_fsm.m_bHandFree?"true": "false");
  198. }
  199. break;
  200. case EVENT_MOD_CONNECT_HANDFREE_CALL: // 免提呼叫
  201. if (m_fsm.m_bHandFree)
  202. {
  203. LogEvent(Severity_Middle,EVENT_MOD_CONNECT_SLV_HANDFREECALL,"handfree call");
  204. Dbg("界面拨号,免提呼叫");
  205. if (pszMessage && strlen(pszMessage) > 0 && isdigit(pszMessage[0]))
  206. {
  207. char tmp[32];
  208. int i = 0;
  209. const char *p = pszMessage;
  210. while (isdigit(*p) && i < 30) {
  211. tmp[i++] = *p++;
  212. }
  213. tmp[i] = 0;
  214. m_fsm.m_strHintCallNum = tmp;
  215. }
  216. else
  217. {
  218. m_fsm.m_strHintCallNum = "";
  219. }
  220. Dbg("recv UI call num = %s",m_fsm.m_strHintCallNum);
  221. m_fsm.PostEventFIFO(new FSMEvent(USER_EVT_HANDFREE_CALL));
  222. }
  223. else
  224. {
  225. LogEvent(Severity_Middle,EVENT_MOD_CONNECT_SLV_PICKUPCALL,"from handfree to pickup call because pickup");
  226. Dbg("界面拨号,话筒呼叫");
  227. if (pszMessage && strlen(pszMessage) > 0 && isdigit(pszMessage[0]))
  228. {
  229. char tmp[32];
  230. int i = 0;
  231. const char *p = pszMessage;
  232. while (isdigit(*p) && i < 30) {
  233. tmp[i++] = *p++;
  234. }
  235. tmp[i] = 0;
  236. m_fsm.m_strHintCallNum = tmp;
  237. }
  238. else
  239. {
  240. m_fsm.m_strHintCallNum = "";
  241. }
  242. Dbg("recv call num = %s",m_fsm.m_strHintCallNum);
  243. m_fsm.PostEventFIFO(new FSMEvent(USER_EVT_PICKUP_CALL));
  244. }
  245. break;
  246. case EVENT_MOD_CONNECT_HANDFREE_TO_PICKUP: // 免提->提机
  247. if (!m_bIsRemoteRecordBroadCast){
  248. Dbg("免提->提机");
  249. m_fsm.PostEventFIFO(new FSMEvent(USER_EVT_TO_PICKUP));
  250. if (strcmp(m_fsm.GetCurrStateName(),"HandFree")==0){
  251. m_fsm.m_bAgentHandFree = FALSE;
  252. }
  253. SendCurAudioDevice();
  254. }
  255. else{
  256. Dbg("remote recording broadcast time, ignore mod connect hand free to pickup event,and hand free flag is %s.",m_fsm.m_bHandFree?"true": "false");
  257. }
  258. break;
  259. case EVENT_MOD_CONNECT_PICKUP_TO_HANDFREE: // 提机->免提
  260. if (!m_bIsRemoteRecordBroadCast){
  261. Dbg("提机->免提");
  262. m_fsm.PostEventFIFO(new FSMEvent(USER_EVT_TO_HANDFREE));
  263. if (strcmp(m_fsm.GetCurrStateName(),"Pickup")==0){
  264. m_fsm.m_bAgentHandFree = TRUE;
  265. }
  266. SendCurAudioDevice();
  267. }
  268. else{
  269. Dbg("remote recording broadcast time, ignore mod connect pickup to hand free event,and hand free flag is %s.",m_fsm.m_bHandFree?"true": "false");
  270. }
  271. break;
  272. case EVENT_MOD_CONNECT_AGENT_HANDFREE_PICKUP: // 坐席控制免提->提机
  273. Dbg("免提->提机");
  274. m_fsm.PostEventFIFO(new FSMEvent(USER_EVT_TO_PICKUP));
  275. SendCurAudioDevice();
  276. break;
  277. case EVENT_MOD_CONNECT_AGENT_PICKUP_HANDFREE: // 坐席控制提机->免提
  278. Dbg("提机->免提");
  279. m_fsm.PostEventFIFO(new FSMEvent(USER_EVT_TO_HANDFREE));
  280. SendCurAudioDevice();
  281. break;
  282. case EVENT_MOD_CONNECT_BEGAIN_RECORD_CALL:
  283. {
  284. Dbg("开始远程双录呼叫.");
  285. m_fsm.PostEventFIFO(new FSMEvent(USER_EVT_DOUBLE_RECORD_CALL));
  286. if (TRUE == m_fsm.m_bHandFree){
  287. LogEvent(Severity_Middle,LOG_EVT_HANDFREE_MODE_REMOTE_CALL,"remote double call start with hand free mode.");
  288. }
  289. else{
  290. LogEvent(Severity_Middle,LOG_EVT_PICKUP_MODE_REMOTE_CALL,"remote double call start with pick up mode.");
  291. }
  292. }
  293. break;
  294. case EVENT_MOD_CONNECT_STOP_RECORD_BROADCAST:
  295. Dbg("双录播报完结束,重置电话状态");
  296. m_fsm.PostEventFIFO(new FSMEvent(USER_EVT_STOP_RECORD_BROADCAST));
  297. m_bIsRemoteRecordBroadCast = FALSE;
  298. break;
  299. case EVENT_MOD_CONNECT_HANNUP: // 挂机
  300. {
  301. Dbg("断开呼叫");
  302. m_fsm.PostEventFIFO(new FSMEvent(USER_EVT_HANGUP));
  303. m_fsm.m_bHangup=TRUE;
  304. }
  305. break;
  306. case EVENT_MOD_CONNECT_HANNUP_BY_CONNECTING: // 话筒未接通时挂机
  307. Dbg("话筒未接通时断开呼叫");
  308. m_fsm.PostEventFIFO(new FSMEvent(USER_EVT_HANGUP));
  309. //m_fsm.m_bHandFree = TRUE;
  310. m_fsm.m_bHangup=TRUE;
  311. break;
  312. case EVENT_MOD_CONNECT_HANNUP_BY_AGENT: // 授权操作
  313. m_fsm.PostEventFIFO(new FSMEvent(USER_EVT_AGENT_WRITABLE));
  314. case LOG_EVT_DISTRIBUTE_ASSISTANTCHANNEL_IDLE:
  315. case LOG_EVT_SELFCHECK_ASSISTANTCHANNEL_IDLE: //若assistchannel重启
  316. Dbg("user_code = %08x", dwUserCode);
  317. m_fsm.PostEventFIFO(new FSMEvent(USER_EVT_ASSISTCHAN_IDEL));
  318. if(m_pCounterConnectorChannel != NULL)
  319. {
  320. m_pCounterConnectorChannel->GetFunction()->CloseSession();
  321. m_pCounterConnectorChannel = NULL;
  322. Dbg("Close AssistChannel Session ");
  323. }
  324. if(m_pCounterConnectorChannel == NULL)
  325. {
  326. Dbg("ReConnection AssistChannel Session");
  327. ErrorCodeEnum Error;
  328. m_pCounterConnectorChannel = new ChannelCounterConnectorClient(this);
  329. Error = m_pCounterConnectorChannel->Connect();
  330. if (Error != Error_Succeed)
  331. {
  332. m_pCounterConnectorChannel->SafeDelete();
  333. m_pCounterConnectorChannel = NULL;
  334. Dbg("ChannelCounterConnectorClient connect fail!");
  335. }
  336. if (Error == Error_Succeed)
  337. {
  338. ChannelService_BeginState_Sub Sub;
  339. Error = m_pCounterConnectorChannel->BeginState(Sub);
  340. if (Error != Error_Succeed)
  341. {
  342. Dbg("BeginState biz channel failed!");
  343. m_pCounterConnectorChannel->GetFunction()->CloseSession();
  344. m_pCounterConnectorChannel = NULL;
  345. }
  346. }
  347. if (Error == Error_Succeed)
  348. {
  349. ChannelService_BeginRecv_Sub Sub;
  350. Sub.type = ACM_TYPE_DEVICE;
  351. Error = m_pCounterConnectorChannel->BeginRecv(Sub);
  352. if (Error != Error_Succeed)
  353. {
  354. Dbg("Begin BeginRecv ACM_TYPE_DEVICE failed!");
  355. m_pCounterConnectorChannel->GetFunction()->CloseSession();
  356. m_pCounterConnectorChannel = NULL;
  357. }
  358. }
  359. if (Error == Error_Succeed)
  360. {
  361. ChannelService_BeginRecv_Sub Sub;
  362. Sub.type = ACM_TYPE_CALLTRANS;
  363. Error = m_pCounterConnectorChannel->BeginRecv(Sub);
  364. if (Error != Error_Succeed)
  365. {
  366. Dbg("Begin BeginRecv ACM_TYPE_CALLTRANS failed!");
  367. m_pCounterConnectorChannel->GetFunction()->CloseSession();
  368. m_pCounterConnectorChannel = NULL;
  369. }
  370. }
  371. }
  372. break;
  373. case LOG_EVT_SELFCHECK_SIPPHONE_IDLE: //sip话机重启
  374. Dbg("recv LOG_EVT_SELFCHECK_SIPPHONE_IDLE");
  375. m_fsm.PostEventFIFO(new FSMEvent(USER_EVT_SIPPHONE_IDEL));
  376. break;
  377. case LOG_EVT_UI_STARTRECORD:
  378. case LOG_EVT_UI_STARTRECORDPREVIEW:
  379. Dbg("start sales record video,get pos = %s",pszMessage);
  380. Handle_StartRecord(pszMessage);
  381. break;
  382. case LOG_EVT_UI_STARTREMOTERECORD:
  383. {
  384. Dbg("start sales remote record video,get pos = %s",pszMessage);
  385. Handle_StartRemoteRecord(pszMessage);
  386. }
  387. break;
  388. case LOG_EVT_UI_STOPRECORD:
  389. Dbg("begin stop sales record video.");
  390. m_fsm.PostEventFIFO(new FSMEvent(USER_EVT_STOPLOCALVIDEO));
  391. m_bIsSalesRecord = FALSE;
  392. break;
  393. case LOG_EVT_UI_STOPREMOTERECORD:
  394. Dbg("begin stop double record video,and cur state name is %s.",m_fsm.GetCurrStateName());
  395. m_fsm.PostEventFIFO(new FSMEvent(USER_EVT_STOPLOACALREMOTEVIDEO));
  396. m_bIsRemoteRecord = FALSE;
  397. m_bIsRemoteRecordBroadCast = FALSE;
  398. break;
  399. case LOG_EVT_UI_RETURNMENU:
  400. if (m_bIsSalesRecord)
  401. {
  402. Dbg("stop sales record video by return menu");
  403. m_fsm.PostEventFIFO(new FSMEvent(USER_EVT_STOPLOCALVIDEO));
  404. m_bIsSalesRecord = FALSE;
  405. }
  406. if (m_bIsRemoteRecord)
  407. {
  408. Dbg("stop remote record video by return menu.");
  409. if (m_fsm.m_CallingParam.nCallType != DOUBLERECORD_CALLTYPE){
  410. m_fsm.PostEventFIFO(new FSMEvent(USER_EVT_STOPLOACALREMOTEVIDEO));
  411. }
  412. else{
  413. Dbg("hangup call by return menu, CurrStateName is %s.", m_fsm.GetCurrStateName());
  414. m_fsm.PostEventFIFO(new FSMEvent(USER_EVT_HANGUP));
  415. m_fsm.m_bHangup=TRUE;
  416. }
  417. m_bIsRemoteRecord = FALSE;
  418. }
  419. break;
  420. case LOG_EVT_UI_STARTPHOTOGRAPH:
  421. if (stricmp(m_fsm.GetCurrStateName(),"Offline")!=0)
  422. {
  423. LogEvent(Severity_Middle,EVENT_MOD_CONNECT_HANNUP,"UI start photograrh, hangup!");
  424. }
  425. else
  426. {
  427. Dbg("offline state,ignore UI_STARTPHOTOGRAPH hangup event");
  428. }
  429. break;
  430. case LOG_EVT_DISTRIBUTE_SIPPHONE_IDLE: //sip话机状态重置
  431. Dbg("recv LOG_EVT_DISTRIBUTE_SIPPHONE_IDLE");
  432. m_fsm.PostEventFIFO(new FSMEvent(USER_EVT_SIPPHONE_IDEL));
  433. break;
  434. default:
  435. break;
  436. }
  437. }
  438. CServerSessionBase*CCounterConnectorEntity::OnNewSession(const char* /*pszRemoteEntityName*/, const char* /*pszClass*/)
  439. {
  440. LOG_FUNCTION();
  441. m_pCurrentSession = new CCounterConnectorSession(this);
  442. return m_pCurrentSession;
  443. }
  444. bool CCounterConnectorEntity ::IsService() const
  445. {
  446. return true;
  447. }
  448. //change audio device message
  449. void CCounterConnectorEntity ::OnReceivePkt(int type, int sub_type, const char *buffer, int size)
  450. {
  451. Dbg("recv pkt type=%d,subtype=%d",type,sub_type);
  452. if ((type == ACM_TYPE_DEVICE)&&!m_bIsPadType)
  453. {
  454. switch (sub_type)
  455. {
  456. //设备切换
  457. //change to handfree
  458. case ACM_CHANGE_HANDFREE:
  459. Dbg("recv change audiodevice to handfree");
  460. if (!m_fsm.m_bAgentHandFree)
  461. {
  462. LogEvent(Severity_Middle,EVENT_MOD_CONNECT_AGENT_PICKUP_HANDFREE,"agent change audio device to handfree");
  463. m_fsm.m_bAgentHandFree = TRUE;
  464. }
  465. else
  466. {
  467. Dbg("agent want change audiodevice to handfree,but the device is handfree now");
  468. }
  469. break;
  470. //change to pickup
  471. case ACM_CHANGE_PICKUP:
  472. Dbg("recv change audiodevice to pickup");
  473. if (m_fsm.m_bAgentHandFree)
  474. {
  475. LogEvent(Severity_Middle,EVENT_MOD_CONNECT_AGENT_HANDFREE_PICKUP,"agent change audio device to pickup");
  476. m_fsm.m_bAgentHandFree = FALSE;
  477. }
  478. else
  479. {
  480. Dbg("agent want change audiodevice to pickup,but the device is pickup now");
  481. }
  482. break;
  483. default:
  484. LOG_TRACE("unknown sub_type %d from agent!", sub_type);
  485. break;
  486. }
  487. }
  488. else if (type == ACM_TYPE_CALLTRANS)
  489. {
  490. Dbg("recv ACM_TYPE_CALLTRANS");
  491. if (sub_type == ACM_CALLTRANS_NUM)
  492. {
  493. //CALL transfer
  494. CallTransferInfo Callnum;
  495. SpBuffer buf;
  496. buf.OpenRead(buffer,size);
  497. Callnum.Serialize(buf);
  498. Dbg("recv ACM_CALLTRANS_NUM = %s",Callnum.CallNum);
  499. //广播,业务中台接收
  500. SpSendBroadcast(GetFunction(), SP_MSG_OF(CallTransferInfo), SP_MSG_SIG_OF(CallTransferInfo), Callnum);
  501. }
  502. }
  503. else if (type == ACM_TYPE_AGENTVIDEOTYPE)
  504. {
  505. if (sub_type == ACM_AGENTVIDEOTYPE_ONEWAY)
  506. {
  507. //广播单向视频
  508. AgentVideoType agentvideotype;
  509. agentvideotype.VideoType = 0;
  510. Dbg("Broadcast Oneway video");
  511. SpSendBroadcast(GetFunction(), SP_MSG_OF(AgentVideoType), SP_MSG_SIG_OF(AgentVideoType), agentvideotype);
  512. }
  513. else if (sub_type == ACM_AGENTVIDEOTYPE_TWOWAY)
  514. {
  515. //广播双向视频
  516. AgentVideoType agentvideotype;
  517. agentvideotype.VideoType = 1;
  518. Dbg("Broadcast Twoway Video");
  519. SpSendBroadcast(GetFunction(), SP_MSG_OF(AgentVideoType), SP_MSG_SIG_OF(AgentVideoType), agentvideotype);
  520. }
  521. }
  522. }
  523. CSimpleStringA CCounterConnectorEntity ::BuildVideoDesc(int local_view_x, int local_view_y, int local_view_cx, int local_view_cy)
  524. {
  525. char param[512];
  526. sprintf(param,
  527. "remote_ip:0\r\n"
  528. "remote_video_rtp:0\r\n"
  529. "remote_video_width:0\r\n"
  530. "remote_video_height:0\r\n"
  531. "remote_video_fps:0\r\n"
  532. "local_view_x:%d\r\n"
  533. "local_view_y:%d\r\n"
  534. "local_view_cx:%d\r\n"
  535. "local_view_cy:%d\r\n"
  536. "remote_view_x:0\r\n"
  537. "remote_view_y:0\r\n"
  538. "remote_view_cx:0\r\n"
  539. "remote_view_cy:0\r\n\r\n",
  540. local_view_x, local_view_y, local_view_cx, local_view_cy);
  541. return CSimpleStringA(param);
  542. }
  543. CSimpleStringA CCounterConnectorEntity ::BuildDoubleVideoDesc(int local_view_x, int local_view_y, int local_view_cx, int local_view_cy, int remote_view_x, int remote_view_y, int remote_view_cx, int remote_view_cy)
  544. {
  545. char param[512];
  546. sprintf(param,
  547. "remote_ip:0\r\n"
  548. "remote_video_rtp:0\r\n"
  549. "remote_video_width:0\r\n"
  550. "remote_video_height:0\r\n"
  551. "remote_video_fps:0\r\n"
  552. "local_view_x:%d\r\n"
  553. "local_view_y:%d\r\n"
  554. "local_view_cx:%d\r\n"
  555. "local_view_cy:%d\r\n"
  556. "remote_view_x:%d\r\n"
  557. "remote_view_y:%d\r\n"
  558. "remote_view_cx:%d\r\n"
  559. "remote_view_cy:%d\r\n\r\n",
  560. local_view_x, local_view_y, local_view_cx, local_view_cy,
  561. remote_view_x, remote_view_y, remote_view_cx, remote_view_cy);
  562. return CSimpleStringA(param);
  563. }
  564. CSimpleStringA CCounterConnectorEntity ::ConstructVideoParam(CSimpleStringA strMsg, bool bDoubleVideo)
  565. {
  566. int lxPos,lyPos,lwidth,lheight,rxPos,ryPos,rwidth,rheight;
  567. CSimpleStringA strVideoParam;
  568. CSimpleStringA str;
  569. if (false == bDoubleVideo){
  570. sscanf(strMsg.GetData(), "%d@%d@%d@%d@%d@%s", &lxPos, &lyPos, &lwidth, &lheight, &str);
  571. Dbg("local video param : (x=%d,y=%d,width=%d,height=%d).",lxPos,lyPos,lwidth,lheight);
  572. strVideoParam = BuildVideoDesc(lxPos,lyPos,lwidth,lheight);
  573. }
  574. else{
  575. int iPostionArr[4][2] = {0};
  576. if (strMsg.GetLength() >0)
  577. {
  578. CAutoArray<CSimpleStringA> arrstr = strMsg.Split('@');
  579. if (arrstr.GetCount() >= 4)
  580. {
  581. for(int i=0; i<4; i++)
  582. {
  583. sscanf(arrstr[i].GetData(), "%d|%d", &iPostionArr[i][0], &iPostionArr[i][1]);
  584. }
  585. }
  586. }
  587. Dbg("remote record local video param : (x=%d,y=%d,width=%d,height=%d), remote video param : (x=%d,y=%d,width=%d,height=%d)",
  588. iPostionArr[0][0], iPostionArr[1][0],iPostionArr[2][0], iPostionArr[3][0],iPostionArr[0][1], iPostionArr[1][1],iPostionArr[2][1], iPostionArr[3][1]);
  589. strVideoParam = BuildDoubleVideoDesc(iPostionArr[0][0], iPostionArr[1][0],iPostionArr[2][0], iPostionArr[3][0],iPostionArr[0][1], iPostionArr[1][1],iPostionArr[2][1], iPostionArr[3][1]);
  590. }
  591. return strVideoParam;
  592. }
  593. void CCounterConnectorEntity::Handle_StartRecord(const char* pszMessage)
  594. {
  595. // edit by ly@2019/04/18
  596. CSimpleStringA strMsg = pszMessage;
  597. if (strMsg.IsStartWith("ews|",true)){
  598. strMsg = strMsg.SubString(4,strMsg.GetLength()-4);
  599. }
  600. CSimpleStringA strVideo;
  601. strVideo = ConstructVideoParam(strMsg, false);
  602. m_fsm.PostEventFIFO(new ShowLocalVideoEvent(strVideo)); // 非连坐席双录
  603. m_bIsSalesRecord = TRUE;
  604. }
  605. void CCounterConnectorEntity::Handle_StartRemoteRecord(const char* pszMessage)
  606. {
  607. // edit by ly@2019/04/18
  608. CSimpleStringA strMsg = pszMessage;
  609. CSimpleStringA strVideo = ConstructVideoParam(strMsg, true);
  610. m_fsm.PostEventFIFO(new ShowLocalAndRemoteVideoEvent(strVideo)); // 连坐席双录
  611. m_bIsRemoteRecord = TRUE;
  612. m_bIsRemoteRecordBroadCast = TRUE;
  613. m_bIsRemoteRecordStopSpeakerCapture = FALSE;
  614. }
  615. void CCounterConnectorEntity::StopRemoteRecordSpeakerAudioCapture()
  616. {
  617. if(DOUBLERECORD_CALLTYPE == m_fsm.m_CallingParam.nCallType){
  618. if (TRUE == m_IsStand2SType){
  619. if (FALSE == m_bIsRemoteRecordStopSpeakerCapture){
  620. if (Error_Succeed == m_fsm.StopSpeakerAudioCapture()){
  621. m_bIsRemoteRecordStopSpeakerCapture = TRUE;
  622. }
  623. }
  624. else{
  625. Dbg("remote record has stop speaker capture.");
  626. }
  627. }
  628. }
  629. }
  630. void CCounterConnectorEntity::Handle_StartRecordPreview(const char* pszMessage)
  631. {
  632. CSimpleStringA strMsg = pszMessage;
  633. if (strMsg.IsStartWith("ews|",true)){
  634. strMsg = strMsg.SubString(4,strMsg.GetLength()-4);
  635. }
  636. CSimpleStringA strVideo;
  637. strVideo = ConstructVideoParam(strMsg, false);
  638. m_fsm.PostEventFIFO(new ShowLocalVideoEvent(strVideo)); // 非连坐席双录
  639. m_bIsSalesRecord = TRUE;
  640. }
  641. //send cur audio device to agent
  642. void CCounterConnectorEntity ::SendCurAudioDevice()
  643. {
  644. if (m_fsm.m_nSysCallType == 0)
  645. {
  646. ChannelService_Send_Info Info;
  647. Info.compress = false;
  648. Info.encrypt = false;
  649. Info.type = ACM_TYPE_DEVICE;
  650. Info.id = 0;
  651. Info.sub_type = ACM_AUDIO_DEVICE;
  652. Info.data.Alloc(sizeof(int));
  653. SpBuffer buf;
  654. buf.OpenWrite();
  655. int nDevice = 0;
  656. if (m_fsm.m_bIsAgentControl)
  657. {
  658. if (m_fsm.m_bAgentHandFree)
  659. {
  660. nDevice = 0;
  661. }
  662. else
  663. {
  664. nDevice = 1;
  665. }
  666. }
  667. else
  668. {
  669. if (m_fsm.m_bHandFree)
  670. {
  671. nDevice = 0;
  672. }
  673. else
  674. {
  675. nDevice = 1;
  676. }
  677. }
  678. buf & nDevice;
  679. Info.data = buf.ToBlob();
  680. m_pCounterConnectorChannel->Send(Info);
  681. Dbg("send cur Audio device = %d",nDevice);
  682. }
  683. else
  684. {
  685. Dbg("cur call type cannot send pkt");
  686. }
  687. }
  688. void CCounterConnectorEntity::SetCallType(CallingTypeEnum eType)
  689. {
  690. m_fsm.SetCallingType(eType);
  691. }
  692. void CCounterConnectorEntity::OnLivenessDetectionStarted(const char *pszEntityName, DWORD dwMessageId, DWORD dwMessageSignature, LivenessDetection::ActiveDetectionStarted &evt)
  693. {
  694. Dbg("LiveDetectionStarted %s", (LPCTSTR)evt.Param);
  695. LogEvent(Severity_Middle,LOG_EVT_STARTLIVEDETECTDISPLAY,"start live detection");
  696. Sleep(400);
  697. int rxPos,ryPos,rwidth,rheight,xPos,yPos,width,height;
  698. CSimpleStringA str;
  699. sscanf((LPCTSTR)evt.Param, "%d@%d@%d@%d@%d@%d@%d@%d", &rxPos, &ryPos, &rwidth, &rheight,&xPos, &yPos, &width, &height);
  700. Dbg("live detection display window x=%d,y=%d,width=%d,height=%d",xPos,yPos,width,height);
  701. CSimpleStringA strVideo = BuildVideoDesc(xPos,yPos,width,height);
  702. m_fsm.PostEventFIFO(new StartVideoDisplayEvent(strVideo));
  703. }
  704. void CCounterConnectorEntity::OnLivenessDetectionStopped(const char *pszEntityName, DWORD dwMessageId, DWORD dwMessageSignature, LivenessDetection::ActiveDetectionStopped &evt)
  705. {
  706. Dbg("LiveDetectionStopped %s", (LPCTSTR)evt.Param);
  707. LogEvent(Severity_Middle,LOG_EVT_STOPLIVEDETECTDISPLAY,"stop live detection");
  708. m_fsm.PostEventFIFO(new FSMEvent(USER_EVT_STOPVIDEODISPLAY));
  709. }
  710. void CCounterConnectorEntity::OnActiveDetectionDone(const char *pszEntityName, DWORD dwMessageId, DWORD dwMessageSignature, LivenessDetection::ActiveDetectionDone &evt)
  711. {
  712. }
  713. void CCounterConnectorEntity::OnAutoSnapshotRemind(const char *pszEntityName, DWORD dwMessageId, DWORD dwMessageSignature, LivenessDetection::AutoSnapshotRemind &evt)
  714. {
  715. }
  716. void CCounterConnectorEntity::OnLivenessDetectionHeartBeat(const char *pszEntityName, DWORD dwMessageId, DWORD dwMessageSignature, LivenessDetection::LivenessDetectionHeartBeat &evt)
  717. {
  718. }
  719. void CCounterConnectorEntity::OnDetectionStopUnExpected(const char *pszEntityName, DWORD dwMessageId, DWORD dwMessageSignature, LivenessDetection::DetectionStopUnExpected &evt)
  720. {
  721. }
  722. ChannelCounterConnectorClient::ChannelCounterConnectorClient( CCounterConnectorEntity *pEntity ) : ChannelService_ClientBase(pEntity)
  723. {
  724. }
  725. void ChannelCounterConnectorClient::OnMessage(ErrorCodeEnum Error, ChannelService_State_Info &Msg, CSmartPointer<IReleasable> pData)
  726. {
  727. if (Error == Error_Succeed)
  728. {
  729. CCounterConnectorEntity *pEntity = static_cast<CCounterConnectorEntity*>(m_pEntityBase);
  730. if (Msg.state == eChannelState_Idle)
  731. {
  732. pEntity->m_fsm.m_bIsAgentControl = FALSE;
  733. }
  734. else if (Msg.state == eChannelState_Connected)
  735. {
  736. pEntity->m_fsm.m_bIsAgentControl = TRUE;
  737. pEntity->SendCurAudioDevice();
  738. }
  739. }
  740. }
  741. void ChannelCounterConnectorClient::OnMessage( ErrorCodeEnum Error, ChannelService_Packet_Info &Msg, CSmartPointer<IReleasable> pData )
  742. {
  743. LOG_FUNCTION();
  744. if (Error == Error_Succeed)
  745. {
  746. CCounterConnectorEntity *pEntity = static_cast<CCounterConnectorEntity*>(m_pEntityBase);
  747. pEntity->OnReceivePkt(Msg.type, Msg.sub_type, (const char*)Msg.data.m_pData, Msg.data.m_iLength);
  748. }
  749. }
  750. void CCounterConnectorSession::Handle_StartCall(SpReqAnsContext<ConnectService_StartCall_Req, ConnectService_StartCall_Ans>::Pointer ctx)
  751. {
  752. LOG_FUNCTION();
  753. ErrorCodeEnum rc = Error_Succeed;
  754. m_pEntity->m_fsm.m_CallingParam.connect_ip = ctx->Req.connect_ip;
  755. m_pEntity->m_fsm.m_CallingParam.connect_port = ctx->Req.connect_port;
  756. m_pEntity->m_fsm.m_CallingParam.nCallType = (CallingTypeEnum)ctx->Req.callingtype;
  757. m_pEntity->m_fsm.m_CallingParam.connect_session = ctx->Req.connect_session;
  758. m_pEntity->m_fsm.m_CallingParam.assistant_port = ctx->Req.assistant_port;
  759. m_pEntity->m_fsm.m_CallingParam.subid = ctx->Req.subid;
  760. m_pEntity->m_fsm.PostEventFIFO(new FSMEvent(USER_EVT_COMMAND_CALL));
  761. ctx->Answer((ErrorCodeEnum)rc);
  762. }
  763. void CCounterConnectorSession::Handle_StartCallExternal(SpReqAnsContext<ConnectService_StartCallExternal_Req, ConnectService_StartCallExternal_Ans>::Pointer ctx)
  764. {
  765. LOG_FUNCTION();
  766. ErrorCodeEnum rc = Error_Succeed;
  767. RVCCallingParam* callparam = (RVCCallingParam*)ctx->Req.CommandParam.m_pData;
  768. if (callparam)
  769. {
  770. m_pEntity->m_fsm.m_CallingParam.connect_ip = callparam->strConnectIp ;
  771. m_pEntity->m_fsm.m_CallingParam.connect_port = callparam->nSipPort;
  772. m_pEntity->m_fsm.m_CallingParam.nCallType = (CallingTypeEnum)callparam->nCallType;
  773. m_pEntity->m_fsm.m_CallingParam.connect_session = callparam->strConnectSession;
  774. m_pEntity->m_fsm.m_CallingParam.subid = callparam->strSubid;
  775. m_pEntity->m_fsm.m_CallingParam.assistant_port = callparam->nAsisstPort;
  776. Dbg("Handle_StartCallExternal strConnectIp=%s, nSipPort=%d, nCallType=%d, strConnectSession=%s, strSubid=%s, nAsisstPort=%d", callparam->strConnectIp,
  777. callparam->nSipPort, callparam->nCallType, callparam->strConnectSession, callparam->strSubid, callparam->nAsisstPort);
  778. }
  779. else
  780. {
  781. Dbg("Get RVCCallingParam Failed!\n");
  782. }
  783. m_pEntity->m_fsm.PostEventFIFO(new FSMEvent(USER_EVT_COMMAND_CALL));
  784. ctx->Answer((ErrorCodeEnum)rc);
  785. }
  786. void CCounterConnectorSession::Handle_StopCall(SpReqAnsContext<ConnectService_StopCall_Req, ConnectService_StopCall_Ans>::Pointer ctx)
  787. {
  788. LOG_FUNCTION();
  789. ErrorCodeEnum rc = Error_Succeed;
  790. RVCCallingParam* callparam = (RVCCallingParam*)ctx->Req.SessionParam.m_pData;
  791. if (callparam){
  792. m_pEntity->m_fsm.m_SessionParam.connect_ip = callparam->strConnectIp ;
  793. m_pEntity->m_fsm.m_SessionParam.connect_session = callparam->strConnectSession;
  794. m_pEntity->m_fsm.m_SessionParam.event_port = callparam->nInstructPort;
  795. Dbg("Handle_StopCall strConnectIp=%s, strConnectSession=%s,event_port=%d", m_pEntity->m_fsm.m_SessionParam.connect_ip.GetData(),
  796. m_pEntity->m_fsm.m_SessionParam.connect_session.GetData(), m_pEntity->m_fsm.m_SessionParam.event_port);
  797. }
  798. else
  799. {
  800. Dbg("Get SessionParam Failed!\n");
  801. }
  802. Dbg("holder hangup call!");
  803. m_pEntity->m_fsm.PostEventFIFO(new FSMEvent(USER_EVT_HANGUP));
  804. ctx->Answer((ErrorCodeEnum)rc);
  805. }
  806. void CCounterConnectorSession::OnClose( ErrorCodeEnum eErrorCode )
  807. {
  808. LOG_FUNCTION();
  809. }
  810. SP_BEGIN_ENTITY_MAP()
  811. SP_ENTITY(CCounterConnectorEntity)
  812. SP_END_ENTITY_MAP()