mod_counterconnector.cpp 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056
  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 "../mod_interactivecontrol/Event.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. pTransactionContext->SendAnswer(Error);
  17. }
  18. void CCounterConnectorEntity ::OnPreClose(EntityCloseCauseEnum eCloseCause,CSmartPointer<ITransactionContext> pTransactionContext)
  19. {
  20. ErrorCodeEnum Error = __OnClose(Error_Succeed);
  21. pTransactionContext->SendAnswer(Error);
  22. }
  23. void CCounterConnectorEntity ::OnSelfTest(EntityTestEnum eTestType,CSmartPointer<ITransactionContext> pTransactionContext)
  24. {
  25. if (Test_ShakeHand == eTestType)
  26. {
  27. pTransactionContext->SendAnswer(Error_Succeed);
  28. }
  29. }
  30. ErrorCodeEnum CCounterConnectorEntity ::__OnStart(ErrorCodeEnum preOperationError)
  31. {
  32. if (preOperationError != Error_Succeed) {
  33. return preOperationError;
  34. }
  35. //MessageBoxA(0, 0, 0, 0);
  36. //is Pad Version
  37. m_pCurrentSession = NULL;
  38. m_bIsSalesRecord = false;
  39. m_bIsRemoteRecord = false;
  40. m_bHasLaunched = false;
  41. CSmartPointer<IEntityFunction> spFunction = GetFunction();
  42. CSystemStaticInfo stStaticinfo;
  43. spFunction->GetSystemStaticInfo(stStaticinfo);
  44. m_fsm.Init(this);
  45. int i = 0;
  46. m_arrListener.Init(22);
  47. spFunction->SubscribeLog(m_arrListener[i++], this, Log_Event, Severity_None, Error_IgnoreAll, EVENT_MOD_CONNECT_PICKUP_CALL,NULL,false);
  48. spFunction->SubscribeLog(m_arrListener[i++], this, Log_Event, Severity_None, Error_IgnoreAll, EVENT_MOD_CONNECT_HANDFREE_CALL,NULL,false);
  49. spFunction->SubscribeLog(m_arrListener[i++], this, Log_Event, Severity_None, Error_IgnoreAll, EVENT_MOD_CONNECT_HANDFREE_TO_PICKUP);
  50. spFunction->SubscribeLog(m_arrListener[i++], this, Log_Event, Severity_None, Error_IgnoreAll, EVENT_MOD_CONNECT_PICKUP_TO_HANDFREE);
  51. spFunction->SubscribeLog(m_arrListener[i++], this, Log_Event, Severity_None, Error_IgnoreAll, EVENT_MOD_CONNECT_HANNUP);
  52. spFunction->SubscribeLog(m_arrListener[i++], this, Log_Event, Severity_None, Error_IgnoreAll, EVENT_MOD_CONNECT_HANNUP_BY_CONNECTING);
  53. spFunction->SubscribeLog(m_arrListener[i++], this, Log_Event, Severity_None, Error_IgnoreAll, EVENT_MOD_CONNECT_HANNUP_BY_AGENT);
  54. spFunction->SubscribeLog(m_arrListener[i++], this, Log_Event, Severity_None, Error_IgnoreAll, EVENT_MOD_CONNECT_GPIO_PICKUP);
  55. spFunction->SubscribeLog(m_arrListener[i++], this, Log_Event, Severity_None, Error_IgnoreAll, EVENT_MOD_CONNECT_GPIO_HANDFREE);
  56. spFunction->SubscribeLog(m_arrListener[i++], this, Log_Event, Severity_None, Error_IgnoreAll, EVENT_MOD_CONNECT_AGENT_HANDFREE_PICKUP);
  57. spFunction->SubscribeLog(m_arrListener[i++], this, Log_Event, Severity_None, Error_IgnoreAll, EVENT_MOD_CONNECT_AGENT_PICKUP_HANDFREE);
  58. spFunction->SubscribeLog(m_arrListener[i++], this, Log_Event, Severity_None, Error_IgnoreAll, LOG_EVT_MOD_ASSISCHAN_STARTED_SUCCESS);
  59. spFunction->SubscribeLog(m_arrListener[i++], this, Log_Event, Severity_None, Error_IgnoreAll, LOG_EVT_MOD_SIPPHONE_STARTED_SUCCESS);
  60. spFunction->SubscribeLog(m_arrListener[i++], this, Log_Event, Severity_None, Error_IgnoreAll, LOG_EVT_UI_STARTRECORD,NULL,false);
  61. spFunction->SubscribeLog(m_arrListener[i++], this, Log_Event, Severity_None, Error_IgnoreAll, LOG_EVT_UI_STOPRECORD,NULL,false);
  62. spFunction->SubscribeLog(m_arrListener[i++], this, Log_Event, Severity_None, Error_IgnoreAll, LOG_EVT_UI_RETURNMENU,NULL,false);
  63. spFunction->SubscribeLog(m_arrListener[i++], this, Log_Event, Severity_None, Error_IgnoreAll, LOG_EVT_UI_STARTPHOTOGRAPH,NULL,false);
  64. spFunction->SubscribeLog(m_arrListener[i++], this, Log_Event, Severity_None, Error_IgnoreAll, EVENT_MOD_CONNECT_STOP_RECORD_BROADCAST,NULL,false);
  65. spFunction->SubscribeLog(m_arrListener[i++], this, Log_Event, Severity_None, Error_IgnoreAll, EVENT_MOD_CONNECT_BEGAIN_RECORD_CALL,NULL,false);
  66. spFunction->SubscribeLog(m_arrListener[i++], this, Log_Event, Severity_None, Error_IgnoreAll, LOG_EVT_UI_STARTREMOTERECORD,NULL,false);
  67. spFunction->SubscribeLog(m_arrListener[i++], this, Log_Event, Severity_None, Error_IgnoreAll, LOG_EVT_UI_STOPREMOTERECORD,NULL,false);
  68. spFunction->SubscribeLog(m_arrListener[i++], this, Log_Event, Severity_None, Error_IgnoreAll, EVENT_MOD_SIP_GET_VIDEO_FAILED, NULL, false);
  69. spFunction->RegistSysVarEvent("UIState", this);
  70. return Error_Succeed;
  71. }
  72. void CCounterConnectorEntity::OnStarted()
  73. {
  74. CSimpleStringA uiState;
  75. GetFunction()->GetSysVar("UIState", uiState);
  76. if (uiState.GetLength() > 0 && uiState[0] == 'M'){
  77. if (false == m_bHasLaunched) {
  78. m_bHasLaunched = true;
  79. }
  80. }
  81. Sleep(500);
  82. m_pCounterConnectorChannel = new ChannelCounterConnectorClient(this);
  83. if (Error_Succeed == ConnectAssistChannel()){
  84. m_bConnectAssist = true;
  85. }
  86. else {
  87. GetFunction()->SetTimer(1, this, 3600);
  88. }
  89. if (m_fsm.ReConnectionAssistchan()){
  90. m_fsm.m_bConAssist = true;
  91. }
  92. else {
  93. GetFunction()->SetTimer(2, this, 3900);
  94. }
  95. Sleep(500);
  96. if (m_fsm.ReConnectionSipphone()){
  97. m_fsm.m_bConSipphone = true;
  98. }
  99. else {
  100. GetFunction()->SetTimer(3, this, 3700);
  101. }
  102. m_fsm.ReConnectionSyncService();
  103. LoadEntityConfig();
  104. m_fsm.m_iCallRouteType = m_iRouteType;
  105. }
  106. ErrorCodeEnum CCounterConnectorEntity::ConnectAssistChannel()
  107. {
  108. if (NULL == m_pCounterConnectorChannel) {
  109. m_pCounterConnectorChannel = new ChannelCounterConnectorClient(this);
  110. }
  111. ErrorCodeEnum Error = m_pCounterConnectorChannel->Connect();
  112. if (Error != Error_Succeed) {
  113. LogWarn(Severity_Low, Error_Debug, EVENT_MOD_CONNECT_ASSIST_ERROR, "connect assistant channel error");
  114. #ifdef RVC_OS_WIN
  115. m_pCounterConnectorChannel->SafeDelete();
  116. #endif
  117. m_pCounterConnectorChannel = NULL;
  118. return Error;
  119. }
  120. {
  121. ChannelService_BeginState_Sub Sub;
  122. Error = m_pCounterConnectorChannel->BeginState(Sub);
  123. if (Error != Error_Succeed){
  124. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("BeginState biz channel failed!");
  125. m_pCounterConnectorChannel->GetFunction()->CloseSession();
  126. #ifdef RVC_OS_WIN
  127. m_pCounterConnectorChannel->SafeDelete();
  128. #endif
  129. m_pCounterConnectorChannel = NULL;
  130. return Error;
  131. }
  132. }
  133. {
  134. ChannelService_BeginRecv_Sub Sub;
  135. Sub.type = ACM_TYPE_DEVICE;
  136. Error = m_pCounterConnectorChannel->BeginRecv(Sub);
  137. if (Error != Error_Succeed) {
  138. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("Begin BeginRecv ACM_TYPE_DEVICE failed!");
  139. m_pCounterConnectorChannel->GetFunction()->CloseSession();
  140. #ifdef RVC_OS_WIN
  141. m_pCounterConnectorChannel->SafeDelete();
  142. #endif
  143. m_pCounterConnectorChannel = NULL;
  144. return Error;
  145. }
  146. }
  147. {
  148. ChannelService_BeginRecv_Sub Sub;
  149. Sub.type = ACM_TYPE_AGENTVIDEOTYPE;
  150. Error = m_pCounterConnectorChannel->BeginRecv(Sub);
  151. if (Error != Error_Succeed){
  152. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("Begin BeginRecv ACM_TYPE_AGENTVIDEOTYPE failed!");
  153. m_pCounterConnectorChannel->GetFunction()->CloseSession();
  154. #ifdef RVC_OS_WIN
  155. m_pCounterConnectorChannel->SafeDelete();
  156. #endif
  157. m_pCounterConnectorChannel = NULL;
  158. return Error;
  159. }
  160. }
  161. {
  162. ChannelService_BeginRecv_Sub Sub;
  163. Sub.type = ACM_TYPE_CALLTRANS;
  164. Error = m_pCounterConnectorChannel->BeginRecv(Sub);
  165. if (Error != Error_Succeed){
  166. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("Begin BeginRecv ACM_TYPE_CALLTRANS failed!");
  167. m_pCounterConnectorChannel->GetFunction()->CloseSession();
  168. #ifdef RVC_OS_WIN
  169. m_pCounterConnectorChannel->SafeDelete();
  170. #endif
  171. m_pCounterConnectorChannel = NULL;
  172. return Error;
  173. }
  174. }
  175. return Error;
  176. }
  177. void CCounterConnectorEntity::OnSysVarEvent(const char *pszKey, const char *pszValue,const char *pszOldValue,const char *pszEntityName)
  178. {
  179. if (_stricmp(pszKey, "UIState") == 0)
  180. {
  181. if (pszValue[0] == 'M')
  182. {
  183. if (false == m_bHasLaunched){
  184. m_bHasLaunched = true;
  185. }
  186. }
  187. }
  188. }
  189. ErrorCodeEnum CCounterConnectorEntity::LoadEntityConfig()
  190. {
  191. SpIniMappingTable table;
  192. int iRouteType = 0;
  193. int iPickUpCallType = 0;
  194. table.AddEntryInt("CounterConnector", "CallRouteType", iRouteType, 0);
  195. table.AddEntryInt("CounterConnector", "PickUpCallType", iPickUpCallType, 0);
  196. CSmartPointer<IConfigInfo> spConfig;
  197. ErrorCodeEnum Error = GetFunction()->OpenConfig(Config_CenterSetting, spConfig);
  198. if (Error == Error_Succeed) {
  199. Error = table.Load(spConfig);
  200. }
  201. if (1 == iRouteType) {
  202. m_iRouteType = 1;
  203. }
  204. if (1 == iPickUpCallType) {
  205. m_iPickUpCallType = 1;
  206. }
  207. if (1 != m_iRouteType) {
  208. LogWarn(Severity_Low, Error_Debug, LOG_WARN_COUNTERCONNECT_CALLROUTE_TYPE, CSimpleStringA::Format("call route type is %d.", m_iRouteType).GetData());
  209. }
  210. return Error;
  211. }
  212. ErrorCodeEnum CCounterConnectorEntity::SetCallRouteParams(CSimpleStringA strQueueName, CSimpleStringA strClientLevel)
  213. {
  214. ErrorCodeEnum Error = Error_Succeed;
  215. m_fsm.m_strQueueName = strQueueName;
  216. m_fsm.m_strAddClientLevel = strClientLevel;
  217. return Error;
  218. }
  219. void CCounterConnectorEntity::HandlePickUpCallEvent()
  220. {
  221. if (1 == m_iPickUpCallType) {
  222. PickUpCallMsg evt;
  223. evt.infos = "pickup call";
  224. SpSendBroadcast(GetFunction(), SP_MSG_OF(PickUpCallMsg), SP_MSG_SIG_OF(PickUpCallMsg), evt);
  225. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("SpSendBroadcast PickUpCallMsg to UI.");
  226. }
  227. else {
  228. m_fsm.PostEventFIFO(new FSMEvent(USER_EVT_PICKUP_CALL));
  229. m_fsm.m_bNeedQueueName = false;
  230. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("Terminate pickup call.");
  231. }
  232. }
  233. void CCounterConnectorEntity::HandleGetVideoFailedEvent()
  234. {
  235. MediaService_ClientBase* pMSClient = new MediaService_ClientBase(this);
  236. CSimpleStringA strCustomerBeing;
  237. GetFunction()->GetSysVar("CustomerBeing", strCustomerBeing);
  238. CSimpleStringA strCustomerHandle;
  239. GetFunction()->GetSysVar("CustomerHandle", strCustomerHandle);
  240. CSimpleStringA strCameraState;
  241. GetFunction()->GetSysVar("CameraState", strCameraState);
  242. CSimpleStringA strmsg("");
  243. CSimpleStringA strinfo("");
  244. if (pMSClient->Connect() != Error_Succeed){
  245. strmsg = CSimpleStringA::Format("connect mediacontroller entity failed");
  246. pMSClient->SafeDelete();
  247. pMSClient = NULL;
  248. }
  249. else{
  250. strmsg = CSimpleStringA::Format("connect mediacontroller entity success");
  251. pMSClient->GetFunction()->CloseSession();
  252. pMSClient->SafeDelete();
  253. pMSClient = NULL;
  254. }
  255. strinfo = CSimpleStringA::Format("%s, and CustomerBeing is %s, CustomerHandle is %s, CameraState is %s.", strmsg, strCustomerBeing.GetData(), strCustomerHandle.GetData(), strCameraState.GetData());
  256. LogWarn(Severity_Low, Error_Debug, LOG_WARN_COUNTERCONNECT_GET_VIDEO_FAILED_INFO, strinfo.GetData());
  257. }
  258. void CCounterConnectorEntity::HandlePickUpMicroPhoneEvent(int iEvent, const char* strMsg)
  259. {
  260. PickUpMicroPhoneEvt evt;
  261. evt.state = iEvent;
  262. evt.infos = strMsg;
  263. SpSendBroadcast(GetFunction(), SP_MSG_OF(PickUpMicroPhoneEvt), SP_MSG_SIG_OF(PickUpMicroPhoneEvt), evt);
  264. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("%s", strMsg);
  265. }
  266. ErrorCodeEnum CCounterConnectorEntity ::__OnClose(ErrorCodeEnum preOperationError)
  267. {
  268. if (preOperationError != Error_Succeed) {
  269. return preOperationError;
  270. }
  271. CSmartPointer<IEntityFunction> spFunction = GetFunction();
  272. for (int i = 0; i < m_arrListener.GetCount(); ++i) {
  273. spFunction->UnsubscribeLog(m_arrListener[i]);
  274. }
  275. spFunction->UnregistSysVarEvent("UIState");
  276. m_arrListener.Clear();
  277. m_fsm.PostEventFIFO(new FSMEvent(USER_EVT_EXIT));
  278. return Error_Succeed;
  279. }
  280. void CCounterConnectorEntity ::OnLog(const CAutoArray<CUUID> &SubIDs, const CUUID nLogID,const LogTypeEnum eLogType, const SeverityLevelEnum eLevel,
  281. const DWORD dwSysError,const DWORD dwUserCode,const DWORD dwEntityInstanceID, const WORD wEntityDevelID,
  282. const CAutoArray<DWORD> &Param, const char *pszEntityName, const char *pszModuleName,const char *pszMessage, const linkContext &pLinkInfo)
  283. {
  284. switch (dwUserCode)
  285. {
  286. case EVENT_MOD_CONNECT_GPIO_PICKUP:
  287. {
  288. m_fsm.m_bHandFree = false;
  289. if (!m_fsm.m_bIsAgentControl)
  290. {
  291. m_fsm.m_bAgentHandFree = false;
  292. }
  293. CSimpleStringA strValue;
  294. GetFunction()->GetSysVar("CallState", strValue);
  295. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("摘机,and CallState is %s.", strValue.GetData());
  296. HandlePickUpMicroPhoneEvent(1, "pick up microphone.");
  297. }
  298. break;
  299. case EVENT_MOD_CONNECT_GPIO_HANDFREE:
  300. {
  301. m_fsm.m_bHandFree = true;
  302. if (!m_fsm.m_bIsAgentControl)
  303. {
  304. m_fsm.m_bAgentHandFree = true;
  305. }
  306. CSimpleStringA strValue;
  307. GetFunction()->GetSysVar("CallState", strValue);
  308. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("挂机,and CallState is %s.", strValue.GetData());
  309. HandlePickUpMicroPhoneEvent(0, "hang up microphone.");
  310. }
  311. break;
  312. case EVENT_MOD_CONNECT_PICKUP_CALL: // 提机呼叫
  313. {
  314. if (m_bHasLaunched){
  315. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("提机呼叫");
  316. HandlePickUpCallEvent();
  317. }
  318. else{
  319. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("UI has not launched, ignore it.");
  320. }
  321. }
  322. break;
  323. case EVENT_MOD_CONNECT_HANDFREE_CALL: // 免提呼叫
  324. m_fsm.m_bNeedQueueName = true;
  325. if (m_fsm.m_bHandFree)
  326. {
  327. LogEvent(Severity_Middle,EVENT_MOD_CONNECT_SLV_HANDFREECALL,"handfree call");
  328. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("界面拨号,免提呼叫");
  329. if (pszMessage && strlen(pszMessage) > 0 && isdigit(pszMessage[0]))
  330. {
  331. char tmp[32];
  332. int i = 0;
  333. const char *p = pszMessage;
  334. while (isdigit(*p) && i < 30) {
  335. tmp[i++] = *p++;
  336. }
  337. tmp[i] = 0;
  338. m_fsm.m_strHintCallNum = tmp;
  339. }
  340. else
  341. {
  342. m_fsm.m_strHintCallNum = "";
  343. }
  344. //DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("recv UI call num = %s",m_fsm.m_strHintCallNum.GetData());
  345. m_fsm.PostEventFIFO(new FSMEvent(USER_EVT_HANDFREE_CALL));
  346. }
  347. else
  348. {
  349. LogEvent(Severity_Middle,EVENT_MOD_CONNECT_SLV_PICKUPCALL,"from hand free to pickup call because pickup");
  350. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("界面拨号,话筒呼叫");
  351. if (pszMessage && strlen(pszMessage) > 0 && isdigit(pszMessage[0]))
  352. {
  353. char tmp[32];
  354. int i = 0;
  355. const char *p = pszMessage;
  356. while (isdigit(*p) && i < 30) {
  357. tmp[i++] = *p++;
  358. }
  359. tmp[i] = 0;
  360. m_fsm.m_strHintCallNum = tmp;
  361. }
  362. else
  363. {
  364. m_fsm.m_strHintCallNum = "";
  365. }
  366. //DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("recv call num = %s",m_fsm.m_strHintCallNum);
  367. m_fsm.PostEventFIFO(new FSMEvent(USER_EVT_PICKUP_CALL));
  368. }
  369. break;
  370. case EVENT_MOD_CONNECT_HANDFREE_TO_PICKUP: // 免提->提机
  371. {
  372. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("免提->提机");
  373. m_fsm.PostEventFIFO(new FSMEvent(USER_EVT_TO_PICKUP));
  374. if (strcmp(m_fsm.GetCurrStateName(),"HandFree")==0){
  375. m_fsm.m_bAgentHandFree = false;
  376. }
  377. SendCurAudioDevice();
  378. }
  379. break;
  380. case EVENT_MOD_CONNECT_PICKUP_TO_HANDFREE: // 提机->免提
  381. {
  382. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("提机->免提");
  383. m_fsm.PostEventFIFO(new FSMEvent(USER_EVT_TO_HANDFREE));
  384. if (strcmp(m_fsm.GetCurrStateName(),"Pickup")==0){
  385. m_fsm.m_bAgentHandFree = true;
  386. }
  387. SendCurAudioDevice();
  388. }
  389. break;
  390. case EVENT_MOD_CONNECT_AGENT_HANDFREE_PICKUP: // 坐席控制免提->提机
  391. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("免提->提机");
  392. m_fsm.PostEventFIFO(new FSMEvent(USER_EVT_TO_PICKUP));
  393. SendCurAudioDevice();
  394. break;
  395. case EVENT_MOD_CONNECT_AGENT_PICKUP_HANDFREE: // 坐席控制提机->免提
  396. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("提机->免提");
  397. m_fsm.PostEventFIFO(new FSMEvent(USER_EVT_TO_HANDFREE));
  398. SendCurAudioDevice();
  399. break;
  400. case EVENT_MOD_CONNECT_BEGAIN_RECORD_CALL:
  401. {
  402. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("开始远程双录呼叫.");
  403. m_fsm.m_bNeedQueueName = true;
  404. m_fsm.PostEventFIFO(new FSMEvent(USER_EVT_DOUBLE_RECORD_CALL));
  405. if (m_fsm.m_bHandFree){
  406. LogEvent(Severity_Middle,LOG_EVT_HANDFREE_MODE_REMOTE_CALL,"remote double call start with hand free mode.");
  407. }
  408. else{
  409. LogEvent(Severity_Middle,LOG_EVT_PICKUP_MODE_REMOTE_CALL,"remote double call start with pick up mode.");
  410. }
  411. }
  412. break;
  413. case EVENT_MOD_CONNECT_STOP_RECORD_BROADCAST:
  414. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("双录播报完结束,重置电话状态");
  415. m_fsm.PostEventFIFO(new FSMEvent(USER_EVT_STOP_RECORD_BROADCAST));
  416. break;
  417. case EVENT_MOD_CONNECT_HANNUP: // 挂机
  418. {
  419. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("断开呼叫");
  420. m_fsm.PostEventFIFO(new FSMEvent(USER_EVT_HANGUP));
  421. m_fsm.m_bHangup=true;
  422. }
  423. break;
  424. case EVENT_MOD_CONNECT_HANNUP_BY_CONNECTING: // 话筒未接通时挂机
  425. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("话筒未接通时断开呼叫");
  426. m_fsm.PostEventFIFO(new FSMEvent(USER_EVT_HANGUP));
  427. //m_fsm.m_bHandFree = TRUE;
  428. m_fsm.m_bHangup=true;
  429. break;
  430. case EVENT_MOD_CONNECT_HANNUP_BY_AGENT: // 授权操作
  431. m_fsm.PostEventFIFO(new FSMEvent(USER_EVT_AGENT_WRITABLE));
  432. case LOG_EVT_MOD_ASSISCHAN_STARTED_SUCCESS:
  433. //DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("recv LOG_EVT_MOD_ASSISCHAN_STARTED_SUCCESS");
  434. //DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("current state name is %s.", m_fsm.GetCurrStateName());
  435. Sleep(500);
  436. m_fsm.PostEventFIFO(new FSMEvent(USER_EVT_ASSISTCHAN_IDEL));
  437. m_fsm.m_bConAssist = false;
  438. GetFunction()->SetTimer(2, this, 3900);
  439. if(NULL != m_pCounterConnectorChannel){
  440. m_bConnectAssist = false;
  441. m_pCounterConnectorChannel->GetFunction()->CloseSession();
  442. #ifdef RVC_OS_WIN
  443. m_pCounterConnectorChannel->SafeDelete();
  444. #endif
  445. m_pCounterConnectorChannel = NULL;
  446. //DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("Close AssistChannel Session.");
  447. }
  448. if(NULL == m_pCounterConnectorChannel){
  449. if (Error_Succeed == ConnectAssistChannel()){
  450. m_bConnectAssist = true;
  451. }
  452. else{
  453. m_bConnectAssist = false;
  454. GetFunction()->SetTimer(1, this, 3600);
  455. }
  456. }
  457. break;
  458. case LOG_EVT_MOD_SIPPHONE_STARTED_SUCCESS:
  459. //DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("recv LOG_EVT_MOD_SIPPHONE_STARTED_SUCCESS");
  460. Sleep(890);
  461. m_fsm.PostEventFIFO(new FSMEvent(USER_EVT_SIPPHONE_IDEL));
  462. m_fsm.m_bConSipphone = false;
  463. GetFunction()->SetTimer(3, this, 3700);
  464. break;
  465. case LOG_EVT_UI_STARTRECORD:
  466. //DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("start sales record video,get pos = %s",pszMessage);
  467. Handle_StartRecord(pszMessage);
  468. break;
  469. case LOG_EVT_UI_STARTREMOTERECORD:
  470. {
  471. //DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("start sales remote record video,get pos = %s",pszMessage);
  472. Handle_StartRemoteRecord(pszMessage);
  473. }
  474. break;
  475. case LOG_EVT_UI_STOPRECORD:
  476. //DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("begin stop sales record video.");
  477. m_fsm.PostEventFIFO(new FSMEvent(USER_EVT_STOPLOCALVIDEO));
  478. m_bIsSalesRecord = false;
  479. break;
  480. case LOG_EVT_UI_STOPREMOTERECORD:
  481. //DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("begin stop double record video,and cur state name is %s.",m_fsm.GetCurrStateName());
  482. m_fsm.PostEventFIFO(new FSMEvent(USER_EVT_STOPLOACALREMOTEVIDEO));
  483. m_bIsRemoteRecord = false;
  484. break;
  485. case LOG_EVT_UI_RETURNMENU:
  486. if (m_bIsSalesRecord)
  487. {
  488. //DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("stop sales record video by return menu");
  489. m_fsm.PostEventFIFO(new FSMEvent(USER_EVT_STOPLOCALVIDEO));
  490. m_bIsSalesRecord = false;
  491. }
  492. if (m_bIsRemoteRecord)
  493. {
  494. //DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("stop remote record video by return menu.");
  495. if (m_fsm.m_CallingParam.nCallType != DOUBLERECORD_CALLTYPE){
  496. m_fsm.PostEventFIFO(new FSMEvent(USER_EVT_STOPLOACALREMOTEVIDEO));
  497. }
  498. else{
  499. //DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("hangup call by return menu, CurrStateName is %s.", m_fsm.GetCurrStateName());
  500. m_fsm.PostEventFIFO(new FSMEvent(USER_EVT_HANGUP));
  501. m_fsm.m_bHangup=true;
  502. }
  503. m_bIsRemoteRecord = false;
  504. }
  505. break;
  506. case LOG_EVT_UI_STARTPHOTOGRAPH:
  507. if (_stricmp(m_fsm.GetCurrStateName(),"Offline")!=0){
  508. LogEvent(Severity_Middle,EVENT_MOD_CONNECT_HANNUP,"UI start photograph, hangup!");
  509. }
  510. //else{
  511. // DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("offline state,ignore UI_STARTPHOTOGRAPH hangup event");
  512. //}
  513. break;
  514. case EVENT_MOD_SIP_GET_VIDEO_FAILED:
  515. HandleGetVideoFailedEvent();
  516. break;
  517. default:
  518. break;
  519. }
  520. }
  521. CServerSessionBase*CCounterConnectorEntity::OnNewSession(const char* /*pszRemoteEntityName*/, const char* /*pszClass*/)
  522. {
  523. m_pCurrentSession = new CCounterConnectorSession(this);
  524. return m_pCurrentSession;
  525. }
  526. bool CCounterConnectorEntity ::IsService() const
  527. {
  528. return true;
  529. }
  530. void CCounterConnectorEntity::OnTimeout(DWORD dwTimerID)
  531. {
  532. if (1 == dwTimerID){
  533. if (false == m_bConnectAssist) {
  534. if (Error_Succeed == ConnectAssistChannel()) {
  535. m_bConnectAssist = true;
  536. }
  537. }
  538. if (m_bConnectAssist) {
  539. GetFunction()->KillTimer(1);
  540. }
  541. }
  542. else if(2 == dwTimerID) {
  543. if (false == m_fsm.m_bConAssist) {
  544. if (m_fsm.ReConnectionAssistchan()) {
  545. m_fsm.m_bConAssist = true;
  546. }
  547. }
  548. if (true == m_fsm.m_bConAssist) {
  549. GetFunction()->KillTimer(2);
  550. }
  551. }
  552. else if (3 == dwTimerID) {
  553. if (false == m_fsm.m_bConSipphone) {
  554. if (m_fsm.ReConnectionSipphone(false)) {
  555. m_fsm.m_bConSipphone = true;
  556. }
  557. else {
  558. m_iConSipphoneFaileTimes++;
  559. GetFunction()->ResetTimer(3, m_iConSipphoneFaileTimes*3000);
  560. }
  561. }
  562. if (m_fsm.m_bConSipphone || m_iConSipphoneFaileTimes >= 5) {
  563. GetFunction()->KillTimer(3);
  564. }
  565. }
  566. }
  567. //change audio device message
  568. void CCounterConnectorEntity ::OnReceivePkt(int type, int sub_type, const char *buffer, int size)
  569. {
  570. //DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("recv pkt type=%d,subtype=%d",type,sub_type);
  571. if (type == ACM_TYPE_DEVICE)
  572. {
  573. switch (sub_type)
  574. {
  575. //设备切换
  576. //change to handfree
  577. case ACM_CHANGE_HANDFREE:
  578. DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("recv change audiodevice to handfree");
  579. if (!m_fsm.m_bAgentHandFree)
  580. {
  581. LogEvent(Severity_Middle,EVENT_MOD_CONNECT_AGENT_PICKUP_HANDFREE,"agent change audio device to handfree");
  582. m_fsm.m_bAgentHandFree = true;
  583. }
  584. else
  585. {
  586. DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("agent want change audiodevice to handfree,but the device is handfree now");
  587. }
  588. break;
  589. //change to pickup
  590. case ACM_CHANGE_PICKUP:
  591. DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("recv change audio device to pickup");
  592. if (m_fsm.m_bAgentHandFree)
  593. {
  594. LogEvent(Severity_Middle,EVENT_MOD_CONNECT_AGENT_HANDFREE_PICKUP,"agent change audio device to pickup");
  595. m_fsm.m_bAgentHandFree = false;
  596. }
  597. else
  598. {
  599. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("agent want change audio device to pickup,but the device is pickup now");
  600. }
  601. break;
  602. default:
  603. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("unknown sub_type %d from agent!", sub_type);
  604. break;
  605. }
  606. }
  607. else if (type == ACM_TYPE_CALLTRANS)
  608. {
  609. //DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("recv ACM_TYPE_CALLTRANS");
  610. if (sub_type == ACM_CALLTRANS_NUM)
  611. {
  612. //CALL transfer
  613. CallTransferInfo Callnum;
  614. SpBuffer buf;
  615. buf.OpenRead(buffer,size);
  616. Callnum.Serialize(buf);
  617. //DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("recv ACM_CALLTRANS_NUM = %s",Callnum.CallNum);
  618. //广播,业务中台接收
  619. SpSendBroadcast(GetFunction(), SP_MSG_OF(CallTransferInfo), SP_MSG_SIG_OF(CallTransferInfo), Callnum);
  620. }
  621. }
  622. else if (type == ACM_TYPE_AGENTVIDEOTYPE)
  623. {
  624. if (sub_type == ACM_AGENTVIDEOTYPE_ONEWAY)
  625. {
  626. //广播单向视频
  627. AgentVideoType agentvideotype;
  628. agentvideotype.VideoType = 0;
  629. //DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("Broadcast Oneway video");
  630. SpSendBroadcast(GetFunction(), SP_MSG_OF(AgentVideoType), SP_MSG_SIG_OF(AgentVideoType), agentvideotype);
  631. }
  632. else if (sub_type == ACM_AGENTVIDEOTYPE_TWOWAY)
  633. {
  634. //广播双向视频
  635. AgentVideoType agentvideotype;
  636. agentvideotype.VideoType = 1;
  637. //DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("Broadcast Twoway Video");
  638. SpSendBroadcast(GetFunction(), SP_MSG_OF(AgentVideoType), SP_MSG_SIG_OF(AgentVideoType), agentvideotype);
  639. }
  640. }
  641. }
  642. CSimpleStringA CCounterConnectorEntity ::BuildVideoDesc(int local_view_x, int local_view_y, int local_view_cx, int local_view_cy)
  643. {
  644. char param[512] = {0};
  645. snprintf(param, 512,
  646. "remote_ip:0\r\n"
  647. "remote_video_rtp:0\r\n"
  648. "remote_video_width:0\r\n"
  649. "remote_video_height:0\r\n"
  650. "remote_video_fps:0\r\n"
  651. "local_view_x:%d\r\n"
  652. "local_view_y:%d\r\n"
  653. "local_view_cx:%d\r\n"
  654. "local_view_cy:%d\r\n"
  655. "remote_view_x:0\r\n"
  656. "remote_view_y:0\r\n"
  657. "remote_view_cx:0\r\n"
  658. "remote_view_cy:0\r\n\r\n",
  659. local_view_x, local_view_y, local_view_cx, local_view_cy);
  660. return CSimpleStringA(param);
  661. }
  662. 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)
  663. {
  664. char param[512] = {0};
  665. snprintf(param, 512,
  666. "remote_ip:0\r\n"
  667. "remote_video_rtp:0\r\n"
  668. "remote_video_width:0\r\n"
  669. "remote_video_height:0\r\n"
  670. "remote_video_fps:0\r\n"
  671. "local_view_x:%d\r\n"
  672. "local_view_y:%d\r\n"
  673. "local_view_cx:%d\r\n"
  674. "local_view_cy:%d\r\n"
  675. "remote_view_x:%d\r\n"
  676. "remote_view_y:%d\r\n"
  677. "remote_view_cx:%d\r\n"
  678. "remote_view_cy:%d\r\n\r\n",
  679. local_view_x, local_view_y, local_view_cx, local_view_cy,
  680. remote_view_x, remote_view_y, remote_view_cx, remote_view_cy);
  681. return CSimpleStringA(param);
  682. }
  683. CSimpleStringA CCounterConnectorEntity ::ConstructVideoParam(CSimpleStringA strMsg, bool bDoubleVideo)
  684. {
  685. int lxPos,lyPos,lwidth,lheight;
  686. CSimpleStringA strVideoParam;
  687. CSimpleStringA str;
  688. if (false == bDoubleVideo){
  689. sscanf(strMsg.GetData(), "%d@%d@%d@%d@%d@%s", &lxPos, &lyPos, &lwidth, &lheight, &str);
  690. DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("local video param : (x=%d,y=%d,width=%d,height=%d).",lxPos,lyPos,lwidth,lheight);
  691. strVideoParam = BuildVideoDesc(lxPos,lyPos,lwidth,lheight);
  692. }
  693. else{
  694. int iPostionArr[4][2] = {0};
  695. if (strMsg.GetLength() >0)
  696. {
  697. CAutoArray<CSimpleStringA> arrstr = strMsg.Split('@');
  698. if (arrstr.GetCount() >= 4)
  699. {
  700. for(int i=0; i<4; i++)
  701. {
  702. sscanf(arrstr[i].GetData(), "%d|%d", &iPostionArr[i][0], &iPostionArr[i][1]);
  703. }
  704. }
  705. }
  706. //DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("remote record local video param : (x=%d,y=%d,width=%d,height=%d), remote video param : (x=%d,y=%d,width=%d,height=%d)",
  707. // iPostionArr[0][0], iPostionArr[1][0],iPostionArr[2][0], iPostionArr[3][0],iPostionArr[0][1], iPostionArr[1][1],iPostionArr[2][1], iPostionArr[3][1]);
  708. 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]);
  709. }
  710. return strVideoParam;
  711. }
  712. void CCounterConnectorEntity::Handle_StartRecord(const char* pszMessage)
  713. {
  714. CSimpleStringA strMsg = pszMessage;
  715. CSimpleStringA strVideo;
  716. #ifdef RVC_OS_WIN
  717. strVideo = ConstructVideoParam(strMsg, false);
  718. #else
  719. strVideo = ConstructVideoRenderParam(strMsg, false);
  720. #endif
  721. m_fsm.PostEventFIFO(new ShowLocalVideoEvent(strVideo)); // 非连坐席双录
  722. m_bIsSalesRecord = true;
  723. }
  724. void CCounterConnectorEntity::Handle_StartRemoteRecord(const char* pszMessage)
  725. {
  726. CSimpleStringA strMsg = pszMessage;
  727. #ifdef RVC_OS_WIN
  728. CSimpleStringA strVideo = ConstructVideoParam(strMsg, true);
  729. #else
  730. CSimpleStringA strVideo = ConstructVideoRenderParam(strMsg, true);
  731. #endif
  732. m_fsm.PostEventFIFO(new ShowLocalAndRemoteVideoEvent(strVideo)); // 连坐席双录
  733. m_bIsRemoteRecord = true;
  734. m_bIsRemoteRecordStopSpeakerCapture = false;
  735. }
  736. void CCounterConnectorEntity::StopRemoteRecordSpeakerAudioCapture()
  737. {
  738. if(DOUBLERECORD_CALLTYPE == m_fsm.m_CallingParam.nCallType){
  739. if (m_IsStandType){
  740. if (false == m_bIsRemoteRecordStopSpeakerCapture){
  741. if (Error_Succeed == m_fsm.StopSpeakerAudioCapture()){
  742. m_bIsRemoteRecordStopSpeakerCapture = true;
  743. }
  744. }
  745. }
  746. }
  747. }
  748. void CCounterConnectorEntity::Handle_StartRecordPreview(const char* pszMessage)
  749. {
  750. CSimpleStringA strMsg = pszMessage;
  751. CSimpleStringA strVideo;
  752. #ifdef RVC_OS_WIN
  753. strVideo = ConstructVideoParam(strMsg, false);
  754. #else
  755. strVideo = ConstructVideoRenderParam(strMsg, false);
  756. #endif
  757. m_fsm.PostEventFIFO(new ShowLocalVideoEvent(strVideo)); // 非连坐席双录
  758. m_bIsSalesRecord = true;
  759. }
  760. //send cur audio device to agent
  761. void CCounterConnectorEntity ::SendCurAudioDevice()
  762. {
  763. ChannelService_Send_Info Info;
  764. Info.compress = false;
  765. Info.encrypt = false;
  766. Info.type = ACM_TYPE_DEVICE;
  767. Info.id = 0;
  768. Info.sub_type = ACM_AUDIO_DEVICE;
  769. Info.data.Alloc(sizeof(int));
  770. SpBuffer buf;
  771. buf.OpenWrite();
  772. int nDevice = 0;
  773. if (m_fsm.m_bIsAgentControl)
  774. {
  775. if (m_fsm.m_bAgentHandFree)
  776. {
  777. nDevice = 0;
  778. }
  779. else
  780. {
  781. nDevice = 1;
  782. }
  783. }
  784. else
  785. {
  786. if (m_fsm.m_bHandFree)
  787. {
  788. nDevice = 0;
  789. }
  790. else
  791. {
  792. nDevice = 1;
  793. }
  794. }
  795. buf & nDevice;
  796. Info.data = buf.ToBlob();
  797. m_pCounterConnectorChannel->Send(Info);
  798. //DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("send cur Audio device = %d",nDevice);
  799. }
  800. void CCounterConnectorEntity::SetCallType(CallingTypeEnum eType)
  801. {
  802. m_fsm.SetCallingType(eType);
  803. }
  804. DeviceTypeEnum CCounterConnectorEntity::RvcGetDeviceType()
  805. {
  806. DeviceTypeEnum eType = eStand2sType;
  807. CSmartPointer<IEntityFunction> spFunction = GetFunction();
  808. CSystemStaticInfo stStaticinfo;
  809. spFunction->GetSystemStaticInfo(stStaticinfo);
  810. if (_stricmp(stStaticinfo.strMachineType, "RVC.Stand1SPlus") == 0) {
  811. eType = eStand1SPlusType;
  812. }
  813. else if (_stricmp(stStaticinfo.strMachineType, "RVC.CardStore") == 0 || _stricmp(stStaticinfo.strMachineType, "RVC.CardPrinter") == 0) {
  814. eType = eCardStore;
  815. }
  816. else {
  817. eType = eStand2sType;
  818. }
  819. if (eType >= 0 && eType < sizeof(Device_Type_Table) / sizeof(char*)) {
  820. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("device type is %s.", Device_Type_Table[eType]);
  821. }
  822. return eType;
  823. }
  824. ChannelCounterConnectorClient::ChannelCounterConnectorClient( CCounterConnectorEntity *pEntity ) : ChannelService_ClientBase(pEntity)
  825. {
  826. m_eLastState = eChannelState_Idle;
  827. m_uConnectTime = 0;
  828. }
  829. void ChannelCounterConnectorClient::OnMessage(ErrorCodeEnum Error, ChannelService_State_Info &Msg, CSmartPointer<IReleasable> pData)
  830. {
  831. if (Error == Error_Succeed)
  832. {
  833. CCounterConnectorEntity *pEntity = static_cast<CCounterConnectorEntity*>(m_pEntityBase);
  834. if (Msg.state == eChannelState_Idle)
  835. {
  836. pEntity->m_fsm.m_bIsAgentControl = false;
  837. //DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("ChannelState is eChannelState_Idle");
  838. if (eChannelState_Connected == m_eLastState){
  839. LogWarn(Severity_Low, Error_Debug, LOG_WARN_COUNTERCONNECT_CALL_CONNECT_TIME, CSimpleStringA::Format("call connected time is %us.", y2k_time_now() - m_uConnectTime).GetData());
  840. }
  841. if (eChannelState_Connecting == m_eLastState){
  842. LogWarn(Severity_Low, Error_Debug, LOG_WARN_COUNTERCONNECT_ASSIST_CONNECT_FAILED,"make call failed for assistant channel connect failed!");
  843. }
  844. }
  845. else if (Msg.state == eChannelState_Connected)
  846. {
  847. pEntity->m_fsm.m_bIsAgentControl = true;
  848. pEntity->SendCurAudioDevice();
  849. //DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("ChannelState is eChannelState_Connected");
  850. m_uConnectTime = y2k_time_now();
  851. }
  852. else if (eChannelState_Connecting == Msg.state){
  853. //DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("ChannelState is eChannelState_Connecting");
  854. }
  855. else if(eChannelState_Closing == Msg.state){
  856. //DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("ChannelState is eChannelState_Closing");
  857. if (eChannelState_Connecting == m_eLastState){
  858. LogWarn(Severity_Low, Error_Debug, LOG_WARN_COUNTERCONNECT_ASSIST_CONNECT_FAILED,"make call failed for assistant channel closed.");
  859. }
  860. }
  861. m_eLastState = Msg.state;
  862. }
  863. }
  864. void ChannelCounterConnectorClient::OnMessage( ErrorCodeEnum Error, ChannelService_Packet_Info &Msg, CSmartPointer<IReleasable> pData )
  865. {
  866. if (Error == Error_Succeed) {
  867. CCounterConnectorEntity *pEntity = static_cast<CCounterConnectorEntity*>(m_pEntityBase);
  868. pEntity->OnReceivePkt(Msg.type, Msg.sub_type, (const char*)Msg.data.m_pData, Msg.data.m_iLength);
  869. }
  870. }
  871. void CCounterConnectorSession::Handle_StartCall(SpReqAnsContext<ConnectService_StartCall_Req, ConnectService_StartCall_Ans>::Pointer ctx)
  872. {
  873. DbgToBeidou(ctx->link, __FUNCTION__)();
  874. ErrorCodeEnum rc = Error_Succeed;
  875. m_pEntity->m_fsm.m_CallingParam.connect_ip = ctx->Req.connect_ip;
  876. m_pEntity->m_fsm.m_CallingParam.connect_port = ctx->Req.connect_port;
  877. m_pEntity->m_fsm.m_CallingParam.nCallType = (CallingTypeEnum)ctx->Req.callingtype;
  878. m_pEntity->m_fsm.m_CallingParam.connect_session = ctx->Req.connect_session;
  879. m_pEntity->m_fsm.m_CallingParam.assistant_port = ctx->Req.assistant_port;
  880. m_pEntity->m_fsm.m_CallingParam.subid = ctx->Req.subid;
  881. m_pEntity->m_fsm.m_bNeedQueueName = true;
  882. ctx->Answer((ErrorCodeEnum)rc);
  883. }
  884. void CCounterConnectorSession::Handle_StartCallExternal(SpReqAnsContext<ConnectService_StartCallExternal_Req, ConnectService_StartCallExternal_Ans>::Pointer ctx)
  885. {
  886. DbgToBeidou(ctx->link, __FUNCTION__)();
  887. ErrorCodeEnum rc = Error_Succeed;
  888. ctx->Answer((ErrorCodeEnum)rc);
  889. }
  890. void CCounterConnectorSession::Handle_StopCall(SpReqAnsContext<ConnectService_StopCall_Req, ConnectService_StopCall_Ans>::Pointer ctx)
  891. {
  892. DbgToBeidou(ctx->link, __FUNCTION__)();
  893. ErrorCodeEnum rc = Error_Succeed;
  894. m_pEntity->m_fsm.PostEventFIFO(new FSMEvent(USER_EVT_HANGUP));
  895. ctx->Answer((ErrorCodeEnum)rc);
  896. }
  897. void CCounterConnectorSession::Handle_GetCallRouteType(SpReqAnsContext<ConnectService_GetCallRouteType_Req, ConnectService_GetCallRouteType_Ans>::Pointer ctx)
  898. {
  899. DbgToBeidou(ctx->link, __FUNCTION__)();
  900. ctx->Ans.RouteType = m_pEntity->m_iRouteType;
  901. ctx->Answer(Error_Succeed);
  902. }
  903. void CCounterConnectorSession::Handle_SetVideoCallRouteParams(SpReqAnsContext<ConnectService_SetVideoCallRouteParams_Req, ConnectService_SetVideoCallRouteParams_Ans>::Pointer ctx)
  904. {
  905. DbgToBeidou(ctx->link, __FUNCTION__)();
  906. if (m_pEntity->m_iRouteType) {
  907. m_pEntity->SetCallRouteParams(ctx->Req.BusinessName, ctx->Req.CallPriority);
  908. ctx->Ans.ErrorCode = Error_Succeed;
  909. ctx->Ans.ErrorMsg = CSimpleStringA2W("设置呼叫路由参数成功.");
  910. }
  911. else {
  912. ctx->Ans.ErrorCode = Error_Param;
  913. ctx->Ans.ErrorMsg = CSimpleStringA2W("该设备不支持新模式呼叫路由.");
  914. }
  915. ctx->Answer(Error_Succeed);
  916. }
  917. void CCounterConnectorSession::Handle_GetPickUpStatus(SpReqAnsContext<ConnectService_GetPickUpStatus_Req, ConnectService_GetPickUpStatus_Ans>::Pointer ctx)
  918. {
  919. DbgToBeidou(ctx->link, __FUNCTION__)();
  920. if (m_pEntity->m_fsm.m_bHandFree) {
  921. ctx->Ans.iStatus = 0;
  922. }
  923. else {
  924. ctx->Ans.iStatus = 1;
  925. }
  926. ctx->Answer(Error_Succeed);
  927. }
  928. void CCounterConnectorSession::OnClose(ErrorCodeEnum eErrorCode )
  929. {
  930. }
  931. SP_BEGIN_ENTITY_MAP()
  932. SP_ENTITY(CCounterConnectorEntity)
  933. SP_END_ENTITY_MAP()