mod_counterconnector.cpp 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062
  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 "y2k_time.h"
  10. #include "../mod_interactivecontrol/Event.h"
  11. using namespace CounterConnector;
  12. #define EVT_CONVERTER "EventConverter"
  13. void CCounterConnectorEntity ::OnPreStart(CAutoArray<CSimpleStringA> strArgs,CSmartPointer<ITransactionContext> pTransactionContext)
  14. {
  15. ErrorCodeEnum Error = __OnStart(Error_Succeed);
  16. CSmartPointer<IEntityFunction> spFunction = GetFunction();
  17. pTransactionContext->SendAnswer(Error);
  18. }
  19. void CCounterConnectorEntity ::OnPreClose(EntityCloseCauseEnum eCloseCause,CSmartPointer<ITransactionContext> pTransactionContext)
  20. {
  21. ErrorCodeEnum Error = __OnClose(Error_Succeed);
  22. pTransactionContext->SendAnswer(Error);
  23. }
  24. void CCounterConnectorEntity ::OnSelfTest(EntityTestEnum eTestType,CSmartPointer<ITransactionContext> pTransactionContext)
  25. {
  26. if (Test_ShakeHand == eTestType)
  27. {
  28. pTransactionContext->SendAnswer(Error_Succeed);
  29. }
  30. }
  31. ErrorCodeEnum CCounterConnectorEntity ::__OnStart(ErrorCodeEnum preOperationError)
  32. {
  33. if (preOperationError != Error_Succeed) {
  34. return preOperationError;
  35. }
  36. //MessageBoxA(0, 0, 0, 0);
  37. //is Pad Version
  38. m_pCurrentSession = NULL;
  39. m_bIsSalesRecord = FALSE;
  40. m_bIsRemoteRecord = FALSE;
  41. m_bHasLaunched = FALSE;
  42. CSmartPointer<IEntityFunction> spFunction = GetFunction();
  43. CSystemStaticInfo stStaticinfo;
  44. spFunction->GetSystemStaticInfo(stStaticinfo);
  45. m_fsm.Init(this);
  46. int i = 0;
  47. m_arrListener.Init(23);
  48. spFunction->SubscribeLog(m_arrListener[i++], this, Log_Event, Severity_None, Error_IgnoreAll, EVENT_MOD_CONNECT_PICKUP_CALL,NULL,false);
  49. spFunction->SubscribeLog(m_arrListener[i++], this, Log_Event, Severity_None, Error_IgnoreAll, EVENT_MOD_CONNECT_HANDFREE_CALL,NULL,false);
  50. spFunction->SubscribeLog(m_arrListener[i++], this, Log_Event, Severity_None, Error_IgnoreAll, EVENT_MOD_CONNECT_HANDFREE_TO_PICKUP);
  51. spFunction->SubscribeLog(m_arrListener[i++], this, Log_Event, Severity_None, Error_IgnoreAll, EVENT_MOD_CONNECT_PICKUP_TO_HANDFREE);
  52. spFunction->SubscribeLog(m_arrListener[i++], this, Log_Event, Severity_None, Error_IgnoreAll, EVENT_MOD_CONNECT_HANNUP);
  53. spFunction->SubscribeLog(m_arrListener[i++], this, Log_Event, Severity_None, Error_IgnoreAll, EVENT_MOD_CONNECT_HANNUP_BY_CONNECTING);
  54. spFunction->SubscribeLog(m_arrListener[i++], this, Log_Event, Severity_None, Error_IgnoreAll, EVENT_MOD_CONNECT_HANNUP_BY_AGENT);
  55. spFunction->SubscribeLog(m_arrListener[i++], this, Log_Event, Severity_None, Error_IgnoreAll, EVENT_MOD_CONNECT_GPIO_PICKUP);
  56. spFunction->SubscribeLog(m_arrListener[i++], this, Log_Event, Severity_None, Error_IgnoreAll, EVENT_MOD_CONNECT_GPIO_HANDFREE);
  57. spFunction->SubscribeLog(m_arrListener[i++], this, Log_Event, Severity_None, Error_IgnoreAll, EVENT_MOD_CONNECT_AGENT_HANDFREE_PICKUP);
  58. spFunction->SubscribeLog(m_arrListener[i++], this, Log_Event, Severity_None, Error_IgnoreAll, EVENT_MOD_CONNECT_AGENT_PICKUP_HANDFREE);
  59. spFunction->SubscribeLog(m_arrListener[i++], this, Log_Event, Severity_None, Error_IgnoreAll, LOG_EVT_MOD_ASSISCHAN_STARTED_SUCCESS);
  60. spFunction->SubscribeLog(m_arrListener[i++], this, Log_Event, Severity_None, Error_IgnoreAll, LOG_EVT_MOD_SIPPHONE_STARTED_SUCCESS);
  61. spFunction->SubscribeLog(m_arrListener[i++], this, Log_Event, Severity_None, Error_IgnoreAll, LOG_EVT_UI_STARTRECORD,NULL,false);
  62. spFunction->SubscribeLog(m_arrListener[i++], this, Log_Event, Severity_None, Error_IgnoreAll, LOG_EVT_UI_STOPRECORD,NULL,false);
  63. spFunction->SubscribeLog(m_arrListener[i++], this, Log_Event, Severity_None, Error_IgnoreAll, LOG_EVT_UI_RETURNMENU,NULL,false);
  64. spFunction->SubscribeLog(m_arrListener[i++], this, Log_Event, Severity_None, Error_IgnoreAll, LOG_EVT_UI_STARTPHOTOGRAPH,NULL,false);
  65. spFunction->SubscribeLog(m_arrListener[i++], this, Log_Event, Severity_None, Error_IgnoreAll, EVENT_MOD_CONNECT_STOP_RECORD_BROADCAST,NULL,false);
  66. spFunction->SubscribeLog(m_arrListener[i++], this, Log_Event, Severity_None, Error_IgnoreAll, EVENT_MOD_CONNECT_BEGAIN_RECORD_CALL,NULL,false);
  67. spFunction->SubscribeLog(m_arrListener[i++], this, Log_Event, Severity_None, Error_IgnoreAll, LOG_EVT_UI_STARTREMOTERECORD,NULL,false);
  68. spFunction->SubscribeLog(m_arrListener[i++], this, Log_Event, Severity_None, Error_IgnoreAll, LOG_EVT_UI_STOPREMOTERECORD,NULL,false);
  69. spFunction->SubscribeLog(m_arrListener[i++], this, Log_Event, Severity_None, Error_IgnoreAll, LOG_EVT_UI_STARTRECORDPREVIEW,NULL,false);
  70. spFunction->SubscribeLog(m_arrListener[i++], this, Log_Event, Severity_None, Error_IgnoreAll, EVENT_MOD_SIP_GET_VIDEO_FAILED, NULL, false);
  71. spFunction->RegistSysVarEvent("UIState", this);
  72. return Error_Succeed;
  73. }
  74. void CCounterConnectorEntity::OnStarted()
  75. {
  76. CSimpleStringA uiState;
  77. GetFunction()->GetSysVar("UIState", uiState);
  78. if (uiState.GetLength() > 0 && uiState[0] == 'M'){
  79. if (false == m_bHasLaunched) {
  80. m_bHasLaunched = true;
  81. }
  82. }
  83. Sleep(500);
  84. m_pCounterConnectorChannel = new ChannelCounterConnectorClient(this);
  85. if (Error_Succeed == ConnectAssistChannel()){
  86. m_bConnectAssist = true;
  87. }
  88. else {
  89. GetFunction()->SetTimer(1, this, 3600);
  90. }
  91. if (m_fsm.ReConnectionAssistchan()){
  92. m_fsm.m_bConAssist = true;
  93. }
  94. else {
  95. GetFunction()->SetTimer(2, this, 3900);
  96. }
  97. Sleep(500);
  98. if (m_fsm.ReConnectionSipphone()){
  99. m_fsm.m_bConSipphone = true;
  100. }
  101. else {
  102. GetFunction()->SetTimer(3, this, 3700);
  103. }
  104. m_fsm.ReConnectionSyncService();
  105. LoadEntityConfig();
  106. m_fsm.m_iCallRouteType = m_iRouteType;
  107. }
  108. ErrorCodeEnum CCounterConnectorEntity::ConnectAssistChannel()
  109. {
  110. if (NULL == m_pCounterConnectorChannel) {
  111. m_pCounterConnectorChannel = new ChannelCounterConnectorClient(this);
  112. }
  113. ErrorCodeEnum Error = m_pCounterConnectorChannel->Connect();
  114. if (Error != Error_Succeed) {
  115. LogWarn(Severity_Low, Error_Debug, EVENT_MOD_CONNECT_ASSIST_ERROR, "connect assistant channel error");
  116. #ifdef RVC_OS_WIN
  117. m_pCounterConnectorChannel->SafeDelete();
  118. #endif
  119. m_pCounterConnectorChannel = NULL;
  120. return Error;
  121. }
  122. {
  123. ChannelService_BeginState_Sub Sub;
  124. Error = m_pCounterConnectorChannel->BeginState(Sub);
  125. if (Error != Error_Succeed){
  126. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("BeginState biz channel failed!");
  127. m_pCounterConnectorChannel->GetFunction()->CloseSession();
  128. #ifdef RVC_OS_WIN
  129. m_pCounterConnectorChannel->SafeDelete();
  130. #endif
  131. m_pCounterConnectorChannel = NULL;
  132. return Error;
  133. }
  134. }
  135. {
  136. ChannelService_BeginRecv_Sub Sub;
  137. Sub.type = ACM_TYPE_DEVICE;
  138. Error = m_pCounterConnectorChannel->BeginRecv(Sub);
  139. if (Error != Error_Succeed) {
  140. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("Begin BeginRecv ACM_TYPE_DEVICE failed!");
  141. m_pCounterConnectorChannel->GetFunction()->CloseSession();
  142. #ifdef RVC_OS_WIN
  143. m_pCounterConnectorChannel->SafeDelete();
  144. #endif
  145. m_pCounterConnectorChannel = NULL;
  146. return Error;
  147. }
  148. }
  149. {
  150. ChannelService_BeginRecv_Sub Sub;
  151. Sub.type = ACM_TYPE_AGENTVIDEOTYPE;
  152. Error = m_pCounterConnectorChannel->BeginRecv(Sub);
  153. if (Error != Error_Succeed){
  154. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("Begin BeginRecv ACM_TYPE_AGENTVIDEOTYPE failed!");
  155. m_pCounterConnectorChannel->GetFunction()->CloseSession();
  156. #ifdef RVC_OS_WIN
  157. m_pCounterConnectorChannel->SafeDelete();
  158. #endif
  159. m_pCounterConnectorChannel = NULL;
  160. return Error;
  161. }
  162. }
  163. {
  164. ChannelService_BeginRecv_Sub Sub;
  165. Sub.type = ACM_TYPE_CALLTRANS;
  166. Error = m_pCounterConnectorChannel->BeginRecv(Sub);
  167. if (Error != Error_Succeed){
  168. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("Begin BeginRecv ACM_TYPE_CALLTRANS failed!");
  169. m_pCounterConnectorChannel->GetFunction()->CloseSession();
  170. #ifdef RVC_OS_WIN
  171. m_pCounterConnectorChannel->SafeDelete();
  172. #endif
  173. m_pCounterConnectorChannel = NULL;
  174. return Error;
  175. }
  176. }
  177. return Error;
  178. }
  179. void CCounterConnectorEntity::OnSysVarEvent(const char *pszKey, const char *pszValue,const char *pszOldValue,const char *pszEntityName)
  180. {
  181. if (_stricmp(pszKey, "UIState") == 0)
  182. {
  183. if (pszValue[0] == 'M')
  184. {
  185. if (false == m_bHasLaunched){
  186. m_bHasLaunched = true;
  187. }
  188. }
  189. }
  190. }
  191. ErrorCodeEnum CCounterConnectorEntity::LoadEntityConfig()
  192. {
  193. SpIniMappingTable table;
  194. int iRouteType = 0;
  195. int iPickUpCallType = 0;
  196. table.AddEntryInt("CounterConnector", "CallRouteType", iRouteType, 0);
  197. table.AddEntryInt("CounterConnector", "PickUpCallType", iPickUpCallType, 0);
  198. CSmartPointer<IConfigInfo> spConfig;
  199. ErrorCodeEnum Error = GetFunction()->OpenConfig(Config_CenterSetting, spConfig);
  200. if (Error == Error_Succeed) {
  201. Error = table.Load(spConfig);
  202. }
  203. if (1 == iRouteType) {
  204. m_iRouteType = 1;
  205. }
  206. if (1 == iPickUpCallType) {
  207. m_iPickUpCallType = 1;
  208. }
  209. if (1 != m_iRouteType) {
  210. LogWarn(Severity_Low, Error_Debug, LOG_WARN_COUNTERCONNECT_CALLROUTE_TYPE, CSimpleStringA::Format("call route type is %d.", m_iRouteType).GetData());
  211. }
  212. return Error;
  213. }
  214. ErrorCodeEnum CCounterConnectorEntity::SetCallRouteParams(CSimpleStringA strQueueName, CSimpleStringA strClientLevel)
  215. {
  216. ErrorCodeEnum Error = Error_Succeed;
  217. m_fsm.m_strQueueName = strQueueName;
  218. m_fsm.m_strAddClientLevel = strClientLevel;
  219. return Error;
  220. }
  221. void CCounterConnectorEntity::HandlePickUpCallEvent()
  222. {
  223. if (1 == m_iPickUpCallType) {
  224. PickUpCallMsg evt;
  225. evt.infos = "pickup call";
  226. SpSendBroadcast(GetFunction(), SP_MSG_OF(PickUpCallMsg), SP_MSG_SIG_OF(PickUpCallMsg), evt);
  227. }
  228. else {
  229. m_fsm.PostEventFIFO(new FSMEvent(USER_EVT_PICKUP_CALL));
  230. m_fsm.m_bNeedQueueName = false;
  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. char strmsg[MAX_PATH] = { 0 };
  243. char strinfo[MAX_PATH] = { 0 };
  244. if (pMSClient->Connect() != Error_Succeed){
  245. snprintf(strmsg, MAX_PATH, "%s", "connect mediacontroller entity failed");
  246. pMSClient->SafeDelete();
  247. pMSClient = NULL;
  248. }
  249. else{
  250. _snprintf(strmsg, MAX_PATH, "%s", "connect mediacontroller entity success");
  251. pMSClient->GetFunction()->CloseSession();
  252. pMSClient->SafeDelete();
  253. pMSClient = NULL;
  254. }
  255. _snprintf(strinfo, MAX_PATH, "%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);
  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. }
  265. ErrorCodeEnum CCounterConnectorEntity ::__OnClose(ErrorCodeEnum preOperationError)
  266. {
  267. if (preOperationError != Error_Succeed) {
  268. return preOperationError;
  269. }
  270. CSmartPointer<IEntityFunction> spFunction = GetFunction();
  271. for (int i = 0; i < m_arrListener.GetCount(); ++i) {
  272. spFunction->UnsubscribeLog(m_arrListener[i]);
  273. }
  274. spFunction->UnregistSysVarEvent("UIState");
  275. m_arrListener.Clear();
  276. m_fsm.PostEventFIFO(new FSMEvent(USER_EVT_EXIT));
  277. return Error_Succeed;
  278. }
  279. void CCounterConnectorEntity ::OnLog(const CAutoArray<CUUID> &SubIDs, const CUUID nLogID,const LogTypeEnum eLogType, const SeverityLevelEnum eLevel,
  280. const DWORD dwSysError,const DWORD dwUserCode,const DWORD dwEntityInstanceID, const WORD wEntityDevelID,
  281. const CAutoArray<DWORD> &Param, const char *pszEntityName, const char *pszModuleName,const char *pszMessage, const linkContext &pLinkInfo)
  282. {
  283. switch (dwUserCode)
  284. {
  285. case EVENT_MOD_CONNECT_GPIO_PICKUP:
  286. {
  287. m_fsm.m_bHandFree = false;
  288. if (!m_fsm.m_bIsAgentControl)
  289. {
  290. m_fsm.m_bAgentHandFree = false;
  291. }
  292. CSimpleStringA strValue;
  293. GetFunction()->GetSysVar("CallState", strValue);
  294. //DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("摘机,and CallState is %s.", strValue.GetData());
  295. HandlePickUpMicroPhoneEvent(1, "pick up microphone.");
  296. }
  297. break;
  298. case EVENT_MOD_CONNECT_GPIO_HANDFREE:
  299. {
  300. m_fsm.m_bHandFree = true;
  301. if (!m_fsm.m_bIsAgentControl)
  302. {
  303. m_fsm.m_bAgentHandFree = true;
  304. }
  305. CSimpleStringA strValue;
  306. GetFunction()->GetSysVar("CallState", strValue);
  307. //DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("挂机,and CallState is %s.", strValue.GetData());
  308. HandlePickUpMicroPhoneEvent(0, "hang up microphone.");
  309. }
  310. break;
  311. case EVENT_MOD_CONNECT_PICKUP_CALL: // 提机呼叫
  312. {
  313. if (m_bHasLaunched){
  314. //DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("提机呼叫");
  315. HandlePickUpCallEvent();
  316. }
  317. else{
  318. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("UI has not launched, ignore it.");
  319. }
  320. }
  321. break;
  322. case EVENT_MOD_CONNECT_HANDFREE_CALL: // 免提呼叫
  323. m_fsm.m_bNeedQueueName = true;
  324. if (m_fsm.m_bHandFree)
  325. {
  326. LogEvent(Severity_Middle,EVENT_MOD_CONNECT_SLV_HANDFREECALL,"handfree call");
  327. //DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("界面拨号,免提呼叫");
  328. if (pszMessage && strlen(pszMessage) > 0 && isdigit(pszMessage[0]))
  329. {
  330. char tmp[32];
  331. int i = 0;
  332. const char *p = pszMessage;
  333. while (isdigit(*p) && i < 30) {
  334. tmp[i++] = *p++;
  335. }
  336. tmp[i] = 0;
  337. m_fsm.m_strHintCallNum = tmp;
  338. }
  339. else
  340. {
  341. m_fsm.m_strHintCallNum = "";
  342. }
  343. //DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("recv UI call num = %s",m_fsm.m_strHintCallNum.GetData());
  344. m_fsm.PostEventFIFO(new FSMEvent(USER_EVT_HANDFREE_CALL));
  345. }
  346. else
  347. {
  348. LogEvent(Severity_Middle,EVENT_MOD_CONNECT_SLV_PICKUPCALL,"from hand free to pickup call because pickup");
  349. //DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("界面拨号,话筒呼叫");
  350. if (pszMessage && strlen(pszMessage) > 0 && isdigit(pszMessage[0]))
  351. {
  352. char tmp[32];
  353. int i = 0;
  354. const char *p = pszMessage;
  355. while (isdigit(*p) && i < 30) {
  356. tmp[i++] = *p++;
  357. }
  358. tmp[i] = 0;
  359. m_fsm.m_strHintCallNum = tmp;
  360. }
  361. else
  362. {
  363. m_fsm.m_strHintCallNum = "";
  364. }
  365. //DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("recv call num = %s",m_fsm.m_strHintCallNum);
  366. m_fsm.PostEventFIFO(new FSMEvent(USER_EVT_PICKUP_CALL));
  367. }
  368. break;
  369. case EVENT_MOD_CONNECT_HANDFREE_TO_PICKUP: // 免提->提机
  370. {
  371. //DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("免提->提机");
  372. m_fsm.PostEventFIFO(new FSMEvent(USER_EVT_TO_PICKUP));
  373. if (strcmp(m_fsm.GetCurrStateName(),"HandFree")==0){
  374. m_fsm.m_bAgentHandFree = false;
  375. }
  376. SendCurAudioDevice();
  377. }
  378. break;
  379. case EVENT_MOD_CONNECT_PICKUP_TO_HANDFREE: // 提机->免提
  380. {
  381. //DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("提机->免提");
  382. m_fsm.PostEventFIFO(new FSMEvent(USER_EVT_TO_HANDFREE));
  383. if (strcmp(m_fsm.GetCurrStateName(),"Pickup")==0){
  384. m_fsm.m_bAgentHandFree = true;
  385. }
  386. SendCurAudioDevice();
  387. }
  388. break;
  389. case EVENT_MOD_CONNECT_AGENT_HANDFREE_PICKUP: // 坐席控制免提->提机
  390. //DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("免提->提机");
  391. m_fsm.PostEventFIFO(new FSMEvent(USER_EVT_TO_PICKUP));
  392. SendCurAudioDevice();
  393. break;
  394. case EVENT_MOD_CONNECT_AGENT_PICKUP_HANDFREE: // 坐席控制提机->免提
  395. //DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("提机->免提");
  396. m_fsm.PostEventFIFO(new FSMEvent(USER_EVT_TO_HANDFREE));
  397. SendCurAudioDevice();
  398. break;
  399. case EVENT_MOD_CONNECT_BEGAIN_RECORD_CALL:
  400. {
  401. //DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("开始远程双录呼叫.");
  402. m_fsm.m_bNeedQueueName = true;
  403. m_fsm.PostEventFIFO(new FSMEvent(USER_EVT_DOUBLE_RECORD_CALL));
  404. if (TRUE == m_fsm.m_bHandFree){
  405. LogEvent(Severity_Middle,LOG_EVT_HANDFREE_MODE_REMOTE_CALL,"remote double call start with hand free mode.");
  406. }
  407. else{
  408. LogEvent(Severity_Middle,LOG_EVT_PICKUP_MODE_REMOTE_CALL,"remote double call start with pick up mode.");
  409. }
  410. }
  411. break;
  412. case EVENT_MOD_CONNECT_STOP_RECORD_BROADCAST:
  413. //DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("双录播报完结束,重置电话状态");
  414. m_fsm.PostEventFIFO(new FSMEvent(USER_EVT_STOP_RECORD_BROADCAST));
  415. break;
  416. case EVENT_MOD_CONNECT_HANNUP: // 挂机
  417. {
  418. //DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("断开呼叫");
  419. m_fsm.PostEventFIFO(new FSMEvent(USER_EVT_HANGUP));
  420. m_fsm.m_bHangup=true;
  421. }
  422. break;
  423. case EVENT_MOD_CONNECT_HANNUP_BY_CONNECTING: // 话筒未接通时挂机
  424. //DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("话筒未接通时断开呼叫");
  425. m_fsm.PostEventFIFO(new FSMEvent(USER_EVT_HANGUP));
  426. //m_fsm.m_bHandFree = TRUE;
  427. m_fsm.m_bHangup=true;
  428. break;
  429. case EVENT_MOD_CONNECT_HANNUP_BY_AGENT: // 授权操作
  430. m_fsm.PostEventFIFO(new FSMEvent(USER_EVT_AGENT_WRITABLE));
  431. case LOG_EVT_MOD_ASSISCHAN_STARTED_SUCCESS:
  432. //DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("recv LOG_EVT_MOD_ASSISCHAN_STARTED_SUCCESS");
  433. //DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("current state name is %s.", m_fsm.GetCurrStateName());
  434. Sleep(500);
  435. m_fsm.PostEventFIFO(new FSMEvent(USER_EVT_ASSISTCHAN_IDEL));
  436. m_fsm.m_bConAssist = false;
  437. GetFunction()->SetTimer(2, this, 3900);
  438. if(NULL != m_pCounterConnectorChannel){
  439. m_bConnectAssist = false;
  440. m_pCounterConnectorChannel->GetFunction()->CloseSession();
  441. #ifdef RVC_OS_WIN
  442. m_pCounterConnectorChannel->SafeDelete();
  443. #endif
  444. m_pCounterConnectorChannel = NULL;
  445. //DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("Close AssistChannel Session.");
  446. }
  447. if(NULL == m_pCounterConnectorChannel){
  448. if (Error_Succeed == ConnectAssistChannel()){
  449. m_bConnectAssist = true;
  450. }
  451. else{
  452. m_bConnectAssist = false;
  453. GetFunction()->SetTimer(1, this, 3600);
  454. }
  455. }
  456. break;
  457. case LOG_EVT_MOD_SIPPHONE_STARTED_SUCCESS:
  458. //DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("recv LOG_EVT_MOD_SIPPHONE_STARTED_SUCCESS");
  459. Sleep(890);
  460. m_fsm.PostEventFIFO(new FSMEvent(USER_EVT_SIPPHONE_IDEL));
  461. m_fsm.m_bConSipphone = false;
  462. GetFunction()->SetTimer(3, this, 3700);
  463. break;
  464. case LOG_EVT_UI_STARTRECORD:
  465. case LOG_EVT_UI_STARTRECORDPREVIEW:
  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. if (m_fsm.m_nSysCallType == 0)
  764. {
  765. ChannelService_Send_Info Info;
  766. Info.compress = false;
  767. Info.encrypt = false;
  768. Info.type = ACM_TYPE_DEVICE;
  769. Info.id = 0;
  770. Info.sub_type = ACM_AUDIO_DEVICE;
  771. Info.data.Alloc(sizeof(int));
  772. SpBuffer buf;
  773. buf.OpenWrite();
  774. int nDevice = 0;
  775. if (m_fsm.m_bIsAgentControl)
  776. {
  777. if (m_fsm.m_bAgentHandFree)
  778. {
  779. nDevice = 0;
  780. }
  781. else
  782. {
  783. nDevice = 1;
  784. }
  785. }
  786. else
  787. {
  788. if (m_fsm.m_bHandFree)
  789. {
  790. nDevice = 0;
  791. }
  792. else
  793. {
  794. nDevice = 1;
  795. }
  796. }
  797. buf & nDevice;
  798. Info.data = buf.ToBlob();
  799. m_pCounterConnectorChannel->Send(Info);
  800. //DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("send cur Audio device = %d",nDevice);
  801. }
  802. else{
  803. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("cur call type cannot send pkt");
  804. }
  805. }
  806. void CCounterConnectorEntity::SetCallType(CallingTypeEnum eType)
  807. {
  808. m_fsm.SetCallingType(eType);
  809. }
  810. DeviceTypeEnum CCounterConnectorEntity::RvcGetDeviceType()
  811. {
  812. DeviceTypeEnum eType = eStand2sType;
  813. CSmartPointer<IEntityFunction> spFunction = GetFunction();
  814. CSystemStaticInfo stStaticinfo;
  815. spFunction->GetSystemStaticInfo(stStaticinfo);
  816. if (_stricmp(stStaticinfo.strMachineType, "RVC.Stand1SPlus") == 0) {
  817. eType = eStand1SPlusType;
  818. }
  819. else if (stricmp(stStaticinfo.strMachineType, "RVC.CardStore") == 0 || stricmp(stStaticinfo.strMachineType, "RVC.CardPrinter") == 0) {
  820. eType = eCardStore;
  821. }
  822. else {
  823. eType = eStand2sType;
  824. }
  825. if (eType >= 0 && eType < sizeof(Device_Type_Table) / sizeof(char*)) {
  826. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("device type is %s.", Device_Type_Table[eType]);
  827. }
  828. return eType;
  829. }
  830. ChannelCounterConnectorClient::ChannelCounterConnectorClient( CCounterConnectorEntity *pEntity ) : ChannelService_ClientBase(pEntity)
  831. {
  832. m_eLastState = eChannelState_Idle;
  833. m_uConnectTime = 0;
  834. }
  835. void ChannelCounterConnectorClient::OnMessage(ErrorCodeEnum Error, ChannelService_State_Info &Msg, CSmartPointer<IReleasable> pData)
  836. {
  837. if (Error == Error_Succeed)
  838. {
  839. CCounterConnectorEntity *pEntity = static_cast<CCounterConnectorEntity*>(m_pEntityBase);
  840. if (Msg.state == eChannelState_Idle)
  841. {
  842. pEntity->m_fsm.m_bIsAgentControl = false;
  843. //DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("ChannelState is eChannelState_Idle");
  844. if (eChannelState_Connected == m_eLastState){
  845. LogWarn(Severity_Low, Error_Debug, LOG_WARN_COUNTERCONNECT_CALL_CONNECT_TIME, CSimpleStringA::Format("call connected time is %us.", y2k_time_now() - m_uConnectTime).GetData());
  846. }
  847. if (eChannelState_Connecting == m_eLastState){
  848. LogWarn(Severity_Low, Error_Debug, LOG_WARN_COUNTERCONNECT_ASSIST_CONNECT_FAILED,"make call failed for assistant channel connect failed!");
  849. }
  850. }
  851. else if (Msg.state == eChannelState_Connected)
  852. {
  853. pEntity->m_fsm.m_bIsAgentControl = true;
  854. pEntity->SendCurAudioDevice();
  855. //DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("ChannelState is eChannelState_Connected");
  856. m_uConnectTime = y2k_time_now();
  857. }
  858. else if (eChannelState_Connecting == Msg.state){
  859. //DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("ChannelState is eChannelState_Connecting");
  860. }
  861. else if(eChannelState_Closing == Msg.state){
  862. //DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("ChannelState is eChannelState_Closing");
  863. if (eChannelState_Connecting == m_eLastState){
  864. LogWarn(Severity_Low, Error_Debug, LOG_WARN_COUNTERCONNECT_ASSIST_CONNECT_FAILED,"make call failed for assistant channel closed.");
  865. }
  866. }
  867. m_eLastState = Msg.state;
  868. }
  869. }
  870. void ChannelCounterConnectorClient::OnMessage( ErrorCodeEnum Error, ChannelService_Packet_Info &Msg, CSmartPointer<IReleasable> pData )
  871. {
  872. if (Error == Error_Succeed) {
  873. CCounterConnectorEntity *pEntity = static_cast<CCounterConnectorEntity*>(m_pEntityBase);
  874. pEntity->OnReceivePkt(Msg.type, Msg.sub_type, (const char*)Msg.data.m_pData, Msg.data.m_iLength);
  875. }
  876. }
  877. void CCounterConnectorSession::Handle_StartCall(SpReqAnsContext<ConnectService_StartCall_Req, ConnectService_StartCall_Ans>::Pointer ctx)
  878. {
  879. DbgToBeidou(ctx->link, __FUNCTION__)();
  880. ErrorCodeEnum rc = Error_Succeed;
  881. m_pEntity->m_fsm.m_CallingParam.connect_ip = ctx->Req.connect_ip;
  882. m_pEntity->m_fsm.m_CallingParam.connect_port = ctx->Req.connect_port;
  883. m_pEntity->m_fsm.m_CallingParam.nCallType = (CallingTypeEnum)ctx->Req.callingtype;
  884. m_pEntity->m_fsm.m_CallingParam.connect_session = ctx->Req.connect_session;
  885. m_pEntity->m_fsm.m_CallingParam.assistant_port = ctx->Req.assistant_port;
  886. m_pEntity->m_fsm.m_CallingParam.subid = ctx->Req.subid;
  887. m_pEntity->m_fsm.PostEventFIFO(new FSMEvent(USER_EVT_COMMAND_CALL));
  888. m_pEntity->m_fsm.m_bNeedQueueName = true;
  889. ctx->Answer((ErrorCodeEnum)rc);
  890. }
  891. void CCounterConnectorSession::Handle_StartCallExternal(SpReqAnsContext<ConnectService_StartCallExternal_Req, ConnectService_StartCallExternal_Ans>::Pointer ctx)
  892. {
  893. DbgToBeidou(ctx->link, __FUNCTION__)();
  894. ErrorCodeEnum rc = Error_Succeed;
  895. m_pEntity->m_fsm.PostEventFIFO(new FSMEvent(USER_EVT_COMMAND_CALL));
  896. ctx->Answer((ErrorCodeEnum)rc);
  897. }
  898. void CCounterConnectorSession::Handle_StopCall(SpReqAnsContext<ConnectService_StopCall_Req, ConnectService_StopCall_Ans>::Pointer ctx)
  899. {
  900. DbgToBeidou(ctx->link, __FUNCTION__)();
  901. ErrorCodeEnum rc = Error_Succeed;
  902. m_pEntity->m_fsm.PostEventFIFO(new FSMEvent(USER_EVT_HANGUP));
  903. ctx->Answer((ErrorCodeEnum)rc);
  904. }
  905. void CCounterConnectorSession::Handle_GetCallRouteType(SpReqAnsContext<ConnectService_GetCallRouteType_Req, ConnectService_GetCallRouteType_Ans>::Pointer ctx)
  906. {
  907. DbgToBeidou(ctx->link, __FUNCTION__)();
  908. ctx->Ans.RouteType = m_pEntity->m_iRouteType;
  909. ctx->Answer(Error_Succeed);
  910. }
  911. void CCounterConnectorSession::Handle_SetVideoCallRouteParams(SpReqAnsContext<ConnectService_SetVideoCallRouteParams_Req, ConnectService_SetVideoCallRouteParams_Ans>::Pointer ctx)
  912. {
  913. DbgToBeidou(ctx->link, __FUNCTION__)();
  914. if (m_pEntity->m_iRouteType) {
  915. m_pEntity->SetCallRouteParams(ctx->Req.BusinessName, ctx->Req.CallPriority);
  916. ctx->Ans.ErrorCode = Error_Succeed;
  917. ctx->Ans.ErrorMsg = CSimpleStringA2W("设置呼叫路由参数成功.");
  918. }
  919. else {
  920. ctx->Ans.ErrorCode = Error_Param;
  921. ctx->Ans.ErrorMsg = CSimpleStringA2W("该设备不支持新模式呼叫路由.");
  922. }
  923. ctx->Answer(Error_Succeed);
  924. }
  925. void CCounterConnectorSession::Handle_GetPickUpStatus(SpReqAnsContext<ConnectService_GetPickUpStatus_Req, ConnectService_GetPickUpStatus_Ans>::Pointer ctx)
  926. {
  927. DbgToBeidou(ctx->link, __FUNCTION__)();
  928. if (m_pEntity->m_fsm.m_bHandFree) {
  929. ctx->Ans.iStatus = 0;
  930. }
  931. else {
  932. ctx->Ans.iStatus = 1;
  933. }
  934. ctx->Answer(Error_Succeed);
  935. }
  936. void CCounterConnectorSession::OnClose(ErrorCodeEnum eErrorCode )
  937. {
  938. }
  939. SP_BEGIN_ENTITY_MAP()
  940. SP_ENTITY(CCounterConnectorEntity)
  941. SP_END_ENTITY_MAP()