ConnectorFSM.h 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863
  1. #pragma once
  2. #include "SpHelper.h"
  3. #include "SpFSM.h"
  4. #include "SpIni.h"
  5. #include "Event.h"
  6. #ifdef _WIN32
  7. #include "resource.h"
  8. #else
  9. #endif
  10. #include "../mod_assistantchannel/VideoDesc.h"
  11. #include "../mod_sipphone/SIPPhone_client_g.h"
  12. using namespace SIPPhone;
  13. #include "../mod_assistantchannel/AssistantChannel_client_g.h"
  14. using namespace AssistantChannel;
  15. #include "../mod_mediacontroller/MediaController_client_g.h"
  16. using namespace MediaController;
  17. #include "../mod_assistantchannel/chan_protocol.h"
  18. #include "CallType.h"
  19. #include "CounterConnector_def_g.h"
  20. #include "CounterConnector_msg_g.h"
  21. using namespace CounterConnector;
  22. #include "../mod_interactioncontext/InteractionContext_client_g.h"
  23. #include "../mod_interactioncontext/InteractionContext_def_g.h"
  24. using namespace InteractionContext;
  25. #include "../mod_livenessdetection/LivenessDetection_client_g.h"
  26. #include "../mod_livenessdetection/LivenessDetection_msg_g.h"
  27. using namespace LivenessDetection;
  28. #define USER_EVT_PICKUP_CALL EVT_USER+1
  29. #define USER_EVT_HANDFREE_CALL EVT_USER+2
  30. #define USER_EVT_HANGUP EVT_USER+3
  31. #define USER_EVT_COMMAND_CALL EVT_USER+4
  32. #define USER_EVT_DOUBLE_RECORD_CALL EVT_USER+5
  33. #define USER_EVT_JMP_FAIL EVT_USER+11
  34. #define USER_EVT_JMP_HANDFREE EVT_USER+12
  35. #define USER_EVT_JMP_PICKUP EVT_USER+13
  36. #define USER_EVT_TO_HANDFREE EVT_USER+14
  37. #define USER_EVT_TO_PICKUP EVT_USER+15
  38. #define USER_EVT_SIP_STATE_CONNECTED EVT_USER+21
  39. #define USER_EVT_SIP_STATE_IDLE EVT_USER+22
  40. #define USER_EVT_CHAN_STATE_CONNECTED EVT_USER+31
  41. #define USER_EVT_CHAN_STATE_IDLE EVT_USER+33
  42. #define USER_EVT_RECONNECT EVT_USER+40
  43. #define USER_EVT_AGENT_WRITABLE EVT_USER+41
  44. #define USER_EVT_ERROR EVT_USER+10
  45. #define USER_EVT_EXIT EVT_USER+50
  46. #define USER_EVT_STOP_RECORD_BROADCAST EVT_USER+55
  47. #define USER_EVT_ASSISTCHAN_IDEL EVT_USER+60
  48. #define USER_EVT_SIPPHONE_IDEL EVT_USER+61
  49. #define USER_EVT_STARTVIDEODISPLAY EVT_USER+70
  50. #define USER_EVT_STOPVIDEODISPLAY EVT_USER+71
  51. #define USER_EVT_SHOWLOACALVIDEO EVT_USER+72
  52. #define USER_EVT_STOPLOCALVIDEO EVT_USER+73
  53. #define USER_EVT_SHOWLOACALREMOTEVIDEO EVT_USER+74
  54. #define USER_EVT_STOPLOACALREMOTEVIDEO EVT_USER+75
  55. enum CurServerNum
  56. {
  57. Error_Server = -1,
  58. MAIN_SERVER = 0,
  59. BACK_SERVER = 1,
  60. };
  61. struct ChanStateConnectedEvent : public FSMEvent
  62. {
  63. ChanStateConnectedEvent(const char *param) : FSMEvent(USER_EVT_CHAN_STATE_CONNECTED), m_param(param) {}
  64. CSimpleStringA m_param;
  65. };
  66. struct StartVideoDisplayEvent : public FSMEvent
  67. {
  68. StartVideoDisplayEvent(const char *param) : FSMEvent(USER_EVT_STARTVIDEODISPLAY), m_param(param) {}
  69. CSimpleStringA m_param;
  70. };
  71. struct ShowLocalVideoEvent : public FSMEvent
  72. {
  73. ShowLocalVideoEvent(const char *param) : FSMEvent(USER_EVT_SHOWLOACALVIDEO), m_param(param) {}
  74. CSimpleStringA m_param;
  75. };
  76. struct ShowLocalAndRemoteVideoEvent : public FSMEvent
  77. {
  78. ShowLocalAndRemoteVideoEvent(const char *param) : FSMEvent(USER_EVT_SHOWLOACALREMOTEVIDEO), m_param(param) {}
  79. CSimpleStringA m_param;
  80. };
  81. struct CallingParam
  82. {
  83. //呼叫模式,0:可视柜台正常呼叫,1:PAD主动外呼,2:PAD被动呼叫,来源PAD,3:PAD被动呼叫,来源手机端,4:双录连线
  84. CallingTypeEnum nCallType;
  85. //<!--会场ession,用于手机与PAD,或者pad与pad交互的会场号-->
  86. CSimpleStringA connect_session;
  87. CSimpleStringA connect_ip;
  88. int connect_port;
  89. CSimpleStringA subid;
  90. int assistant_port;
  91. };
  92. //<!--会话相关参数,用于主动拒接的场景 -->
  93. struct SessionParam
  94. {
  95. CSimpleStringA connect_session; //会话标识
  96. CSimpleStringA connect_ip; //分行网关服务器ip
  97. int event_port; //分行网关挂断事件监听端口
  98. };
  99. #ifndef MAX_LENGTH_OF_BRANCHNO
  100. #define MAX_LENGTH_OF_BRANCHNO 4
  101. #endif
  102. #ifndef MAX_LENGTH_OF_SESSIONID
  103. #define MAX_LENGTH_OF_SESSIONID 16
  104. #endif
  105. #ifndef MAX_LENGTH_OF_CONNECTIP
  106. #define MAX_LENGTH_OF_CONNECTIP 16
  107. #endif
  108. #ifndef MAX_LENGTH_OF_SUBID
  109. #define MAX_LENGTH_OF_SUBID 16
  110. #endif
  111. #ifndef SUBID_LENGTH
  112. #define SUBID_LENGTH 8
  113. #endif
  114. //被动呼叫模式参数
  115. struct RVCCallingParam
  116. {
  117. //呼叫模式,0:可视柜台正常呼叫,1:PAD主动外呼,2:PAD被动呼叫,来源PAD,3:PAD被动呼叫,来源手机端
  118. int nCallType;
  119. //分行编号
  120. char strBranNo[MAX_LENGTH_OF_BRANCHNO];
  121. //会话标识16位
  122. char strConnectSession[MAX_LENGTH_OF_SESSIONID];
  123. //连接IP 16位
  124. char strConnectIp[MAX_LENGTH_OF_CONNECTIP];
  125. //SIP端口
  126. int nSipPort;
  127. //协助通道端口
  128. int nAsisstPort;
  129. //客户经理subid
  130. char strSubid[MAX_LENGTH_OF_SUBID];
  131. //分行网关指令服务端口
  132. int nInstructPort;
  133. };
  134. class ACMCallFSM : public FSMImpl<ACMCallFSM>, public IFSMStateHooker
  135. {
  136. public:
  137. enum {s0,s7,s8,s9,s10,s11,s12,s13,s14,s20,s21,s22,s23,s24,s3,s4,s50,s51,s52,s53,s60,s61,s62,s63};
  138. BEGIN_FSM_STATE(ACMCallFSM)
  139. FSM_STATE_ENTRY(s0,"Offline",s0_on_entry,s0_on_exit,s0_on_event)
  140. FSM_STATE_ENTRY(s7,"ShowLocalVideo",s7_on_entry,s7_on_exit,s7_on_event)
  141. FSM_STATE_ENTRY(s9,"Livedetect",s9_on_entry,s9_on_exit,s9_on_event)
  142. FSM_STATE_ENTRY(s8,"Delay",s8_on_entry,s8_on_exit,s8_on_event)
  143. FSM_STATE_ENTRY(s10,"Calling_Start",s10_on_entry,s10_on_exit,s10_on_event)
  144. FSM_STATE_ENTRY(s11,"Calling_SipConnect",s11_on_entry,s11_on_exit,s11_on_event)
  145. FSM_STATE_ENTRY(s12,"Calling_ChanConnect",s12_on_entry,s12_on_exit,s12_on_event)
  146. FSM_STATE_ENTRY(s13,"Calling_AllReady",s13_on_entry,s13_on_exit,s13_on_event)
  147. FSM_STATE_ENTRY(s14,"ShowLocalRemoteVideo",s14_on_entry,s14_on_exit,s14_on_event)
  148. FSM_STATE_ENTRY(s20, "ExitCall_Start",s20_on_entry,s20_on_exit,s20_on_event)
  149. FSM_STATE_ENTRY(s21, "ExitChan_Finished",s21_on_entry,s21_on_exit,s21_on_event)
  150. FSM_STATE_ENTRY(s22, "ExitSip_Finished",s22_on_entry,s22_on_exit,s22_on_event)
  151. FSM_STATE_ENTRY(s23, "ExitCall_AllFinished",s23_on_entry,s23_on_exit,s23_on_event)
  152. FSM_STATE_ENTRY(s24, "ExitCall_Delay",s24_on_entry,s24_on_exit,s24_on_event)
  153. FSM_STATE_ENTRY(s3, "HandFree",s3_on_entry,s3_on_exit,s3_on_event)
  154. FSM_STATE_ENTRY(s4, "Pickup",s4_on_entry,s4_on_exit,s4_on_event)
  155. FSM_STATE_ENTRY(s50, "Broken0",s50_on_entry,s50_on_exit,s50_on_event)
  156. FSM_STATE_ENTRY(s51, "Broken_SipFinished",s51_on_entry,s51_on_exit,s51_on_event)
  157. FSM_STATE_ENTRY(s52, "Broken_ChanFinished",s52_on_entry,s52_on_exit,s52_on_event)
  158. FSM_STATE_ENTRY(s53, "Broken_AllFinished",s53_on_entry,s53_on_exit,s53_on_event)
  159. FSM_STATE_ENTRY(s60, "Hangup_Start",s60_on_entry,s60_on_exit,s60_on_event)
  160. FSM_STATE_ENTRY(s61, "Hangup_SipFinished",s61_on_entry,s61_on_exit,s61_on_event)
  161. FSM_STATE_ENTRY(s62, "Hangup_ChanFinished",s62_on_entry,s62_on_exit,s62_on_event)
  162. FSM_STATE_ENTRY(s63, "Hangup_AllFinished",s63_on_entry,s63_on_exit,s63_on_event)
  163. END_FSM_STATE()
  164. BEGIN_FSM_RULE(ACMCallFSM,s0)
  165. FSM_RULE_ENTRY_ANY(s0, s8, USER_EVT_PICKUP_CALL)
  166. FSM_RULE_ENTRY_ANY(s0, s9, USER_EVT_STARTVIDEODISPLAY)
  167. FSM_RULE_ENTRY_ANY(s0, s7, USER_EVT_SHOWLOACALVIDEO)
  168. FSM_RULE_ENTRY_ANY(s0, s14, USER_EVT_SHOWLOACALREMOTEVIDEO)
  169. FSM_RULE_ENTRY_ANY(s7, s0, USER_EVT_STOPLOCALVIDEO)
  170. FSM_RULE_ENTRY_ANY(s9, s0, USER_EVT_STOPVIDEODISPLAY)
  171. FSM_RULE_ENTRY_ANY(s14, s0, USER_EVT_STOPLOACALREMOTEVIDEO)
  172. FSM_RULE_ENTRY_ANY(s0, FSM_STATE_EXIT, USER_EVT_EXIT)
  173. FSM_RULE_ENTRY_ANY(s0, s8, USER_EVT_HANDFREE_CALL)
  174. FSM_RULE_ENTRY_ANY(s0, s8, USER_EVT_COMMAND_CALL)
  175. FSM_RULE_ENTRY_ANY(s0, s8, USER_EVT_DOUBLE_RECORD_CALL)
  176. FSM_RULE_ENTRY_ANY(s14, s0, USER_EVT_STOP_RECORD_BROADCAST)
  177. FSM_RULE_ENTRY_ANY(s8, s11, EVT_TIMER)
  178. FSM_RULE_ENTRY_ANY(s11, s12, USER_EVT_SIP_STATE_CONNECTED)
  179. FSM_RULE_ENTRY_ANY(s11, s23, USER_EVT_JMP_FAIL)
  180. FSM_RULE_ENTRY_ANY(s11, s21, EVT_TIMER)
  181. FSM_RULE_ENTRY_ANY(s11, s23, USER_EVT_SIP_STATE_IDLE)
  182. FSM_RULE_ENTRY_ANY(s11, s21, USER_EVT_HANGUP)
  183. FSM_RULE_ENTRY_ANY(s21, s23, USER_EVT_SIP_STATE_IDLE)
  184. FSM_RULE_ENTRY_ANY(s21, s23, USER_EVT_JMP_FAIL)
  185. FSM_RULE_ENTRY_ANY(s12, s13, USER_EVT_CHAN_STATE_CONNECTED)
  186. FSM_RULE_ENTRY_ANY(s12, s21, USER_EVT_CHAN_STATE_IDLE)
  187. FSM_RULE_ENTRY_ANY(s12, s22, USER_EVT_SIP_STATE_IDLE)
  188. FSM_RULE_ENTRY_ANY(s12, s21, USER_EVT_JMP_FAIL)
  189. FSM_RULE_ENTRY_ANY(s22, s23, USER_EVT_CHAN_STATE_IDLE)
  190. FSM_RULE_ENTRY_ANY(s12, s20, USER_EVT_HANGUP)
  191. FSM_RULE_ENTRY_ANY(s20, s21, USER_EVT_CHAN_STATE_IDLE)
  192. FSM_RULE_ENTRY_ANY(s20, s22, USER_EVT_SIP_STATE_IDLE)
  193. FSM_RULE_ENTRY_ANY(s13, s3, USER_EVT_JMP_HANDFREE)
  194. FSM_RULE_ENTRY_ANY(s13, s4, USER_EVT_JMP_PICKUP)
  195. FSM_RULE_ENTRY_ANY(s23, s0, EVT_TIMER)
  196. FSM_RULE_ENTRY_ANY(s23, s24, USER_EVT_RECONNECT)
  197. FSM_RULE_ENTRY_ANY(s24, s11, EVT_TIMER)
  198. FSM_RULE_ENTRY_ANY(s3, s4, USER_EVT_TO_PICKUP)
  199. FSM_RULE_ENTRY_ANY(s3, s51, USER_EVT_SIP_STATE_IDLE)
  200. FSM_RULE_ENTRY_ANY(s3, s52, USER_EVT_CHAN_STATE_IDLE)
  201. FSM_RULE_ENTRY_ANY(s3, s60, USER_EVT_HANGUP)
  202. FSM_RULE_ENTRY_ANY(s4, s3, USER_EVT_TO_HANDFREE)
  203. FSM_RULE_ENTRY_ANY(s4, s51, USER_EVT_SIP_STATE_IDLE)
  204. FSM_RULE_ENTRY_ANY(s4, s52, USER_EVT_CHAN_STATE_IDLE)
  205. FSM_RULE_ENTRY_ANY(s4, s60, USER_EVT_HANGUP)
  206. FSM_RULE_ENTRY_ANY(s50, s51, USER_EVT_SIP_STATE_IDLE)
  207. FSM_RULE_ENTRY_ANY(s50, s52, USER_EVT_CHAN_STATE_IDLE)
  208. FSM_RULE_ENTRY_ANY(s51, s53, USER_EVT_CHAN_STATE_IDLE)
  209. FSM_RULE_ENTRY_ANY(s52, s53, USER_EVT_SIP_STATE_IDLE)
  210. FSM_RULE_ENTRY_ANY(s52, s53, USER_EVT_JMP_FAIL)
  211. FSM_RULE_ENTRY_ANY(s53, s0, EVT_TIMER)
  212. FSM_RULE_ENTRY_ANY(s60, s61, USER_EVT_SIP_STATE_IDLE)
  213. FSM_RULE_ENTRY_ANY(s60, s62, USER_EVT_CHAN_STATE_IDLE)
  214. FSM_RULE_ENTRY_ANY(s61, s63, USER_EVT_CHAN_STATE_IDLE)
  215. FSM_RULE_ENTRY_ANY(s62, s63, USER_EVT_SIP_STATE_IDLE)
  216. FSM_RULE_ENTRY_ANY(s62, s63, USER_EVT_JMP_FAIL)
  217. FSM_RULE_ENTRY_ANY(s63, s0, EVT_TIMER)
  218. //sipphone重启后,所有状态跳转到Offline
  219. FSM_RULE_ENTRY_ANY(s8, s0, USER_EVT_SIPPHONE_IDEL)
  220. FSM_RULE_ENTRY_ANY(s10, s0, USER_EVT_SIPPHONE_IDEL)
  221. FSM_RULE_ENTRY_ANY(s11, s0, USER_EVT_SIPPHONE_IDEL)
  222. FSM_RULE_ENTRY_ANY(s12, s0, USER_EVT_SIPPHONE_IDEL)
  223. FSM_RULE_ENTRY_ANY(s13, s0, USER_EVT_SIPPHONE_IDEL)
  224. FSM_RULE_ENTRY_ANY(s20, s0, USER_EVT_SIPPHONE_IDEL)
  225. FSM_RULE_ENTRY_ANY(s21, s0, USER_EVT_SIPPHONE_IDEL)
  226. FSM_RULE_ENTRY_ANY(s22, s0, USER_EVT_SIPPHONE_IDEL)
  227. FSM_RULE_ENTRY_ANY(s23, s0, USER_EVT_SIPPHONE_IDEL)
  228. FSM_RULE_ENTRY_ANY(s24, s0, USER_EVT_SIPPHONE_IDEL)
  229. FSM_RULE_ENTRY_ANY(s3, s0, USER_EVT_SIPPHONE_IDEL)
  230. FSM_RULE_ENTRY_ANY(s4, s0, USER_EVT_SIPPHONE_IDEL)
  231. FSM_RULE_ENTRY_ANY(s50, s0, USER_EVT_SIPPHONE_IDEL)
  232. FSM_RULE_ENTRY_ANY(s51, s0, USER_EVT_SIPPHONE_IDEL)
  233. FSM_RULE_ENTRY_ANY(s52, s0, USER_EVT_SIPPHONE_IDEL)
  234. FSM_RULE_ENTRY_ANY(s53, s0, USER_EVT_SIPPHONE_IDEL)
  235. FSM_RULE_ENTRY_ANY(s60, s0, USER_EVT_SIPPHONE_IDEL)
  236. FSM_RULE_ENTRY_ANY(s61, s0, USER_EVT_SIPPHONE_IDEL)
  237. FSM_RULE_ENTRY_ANY(s62, s0, USER_EVT_SIPPHONE_IDEL)
  238. FSM_RULE_ENTRY_ANY(s63, s0, USER_EVT_SIPPHONE_IDEL)
  239. //sipphone重启后,所有状态跳转到Offline
  240. //分布式呼叫场景,拒接主动挂断
  241. FSM_RULE_ENTRY_ANY(s0, s60, USER_EVT_HANGUP)
  242. //分布式呼叫场景,拒接主动挂断
  243. END_FSM_RULE()
  244. ACMCallFSM();
  245. ~ACMCallFSM();
  246. virtual void OnStateTrans(int iSrcState, int iDstState);
  247. virtual ErrorCodeEnum OnInit();
  248. virtual ErrorCodeEnum OnExit();
  249. void s0_on_entry();
  250. void s0_on_exit();
  251. unsigned int s0_on_event(FSMEvent* event);
  252. void s7_on_entry();
  253. void s7_on_exit();
  254. unsigned int s7_on_event(FSMEvent* event);
  255. void s8_on_entry();
  256. void s8_on_exit();
  257. unsigned int s8_on_event(FSMEvent* event);
  258. void s9_on_entry();
  259. void s9_on_exit();
  260. unsigned int s9_on_event(FSMEvent* event);
  261. void s10_on_entry();
  262. void s10_on_exit();
  263. unsigned int s10_on_event(FSMEvent* event);
  264. void s11_on_entry();
  265. void s11_on_exit();
  266. unsigned int s11_on_event(FSMEvent* event);
  267. void s12_on_entry();
  268. void s12_on_exit();
  269. unsigned int s12_on_event(FSMEvent* event);
  270. void s13_on_entry();
  271. void s13_on_exit();
  272. unsigned int s13_on_event(FSMEvent* event);
  273. void s14_on_entry();
  274. void s14_on_exit();
  275. unsigned int s14_on_event(FSMEvent* event);
  276. void s20_on_entry();
  277. void s20_on_exit();
  278. unsigned int s20_on_event(FSMEvent* event);
  279. void s21_on_entry();
  280. void s21_on_exit();
  281. unsigned int s21_on_event(FSMEvent* event);
  282. void s22_on_entry();
  283. void s22_on_exit();
  284. unsigned int s22_on_event(FSMEvent* event);
  285. void s23_on_entry();
  286. void s23_on_exit();
  287. unsigned int s23_on_event(FSMEvent* event);
  288. void s24_on_entry();
  289. void s24_on_exit();
  290. unsigned int s24_on_event(FSMEvent* event);
  291. void s3_on_entry();
  292. void s3_on_exit();
  293. unsigned int s3_on_event(FSMEvent* event);
  294. void s4_on_entry();
  295. void s4_on_exit();
  296. unsigned int s4_on_event(FSMEvent* event);
  297. void s50_on_entry();
  298. void s50_on_exit();
  299. unsigned int s50_on_event(FSMEvent* event);
  300. void s51_on_entry();
  301. void s51_on_exit();
  302. unsigned int s51_on_event(FSMEvent* event);
  303. void s52_on_entry();
  304. void s52_on_exit();
  305. unsigned int s52_on_event(FSMEvent* event);
  306. void s53_on_entry();
  307. void s53_on_exit();
  308. unsigned int s53_on_event(FSMEvent* event);
  309. void s60_on_entry();
  310. void s60_on_exit();
  311. unsigned int s60_on_event(FSMEvent* event);
  312. void s61_on_entry();
  313. void s61_on_exit();
  314. unsigned int s61_on_event(FSMEvent* event);
  315. void s62_on_entry();
  316. void s62_on_exit();
  317. unsigned int s62_on_event(FSMEvent* event);
  318. void s63_on_entry();
  319. void s63_on_exit();
  320. unsigned int s63_on_event(FSMEvent* event);
  321. BOOL m_bHangup;
  322. //sip呼叫失败次数,连续10次SIP呼叫失败触发自检重启SIPPHONE
  323. unsigned int m_nSipErrorNum;
  324. unsigned int m_nLiveDetctionTime;
  325. ErrorCodeEnum StartVideo(const char *param)
  326. {
  327. Dbg("Start Video");
  328. if (!m_pPhoneClient)
  329. return Error_NetBroken;
  330. PhoneService_StartVideo_Info Info;
  331. ErrorCodeEnum Error = ParseVideoDesc(param, Info.remote_ip, Info.remote_port,
  332. Info.remote_width, Info.remote_height, Info.remote_fps,
  333. Info.local_view_x, Info.local_view_y, Info.local_view_cx, Info.local_view_cy,
  334. Info.remote_view_x, Info.remote_view_y, Info.remote_view_cx, Info.remote_view_cy);
  335. Info.local_hwd_move = 0;
  336. Info.remote_hwd_move = 1;
  337. Dbg("start video, remote width:%d, remote height:%d, local(%d,%d,%d,%d),remote(%d,%d,%d,%d), remote_fps:%d",
  338. Info.remote_width, Info.remote_height,
  339. Info.local_view_x, Info.local_view_y, Info.local_view_cx, Info.local_view_cy,
  340. Info.remote_view_x, Info.remote_view_y, Info.remote_view_cx, Info.remote_view_cy,Info.remote_fps);
  341. if (Error == Error_Succeed)
  342. {
  343. Error = m_pPhoneClient->StartVideo(Info);
  344. } else {
  345. Dbg("parse video desc failed!");
  346. }
  347. return Error;
  348. }
  349. ErrorCodeEnum StopVideo()
  350. {
  351. Dbg("Stop Video");
  352. if (!m_pPhoneClient)
  353. return Error_NetBroken;
  354. return m_pPhoneClient->StopVideo();
  355. }
  356. ErrorCodeEnum RealSipErrorCheck()
  357. {
  358. Dbg("Sip connect Fail 6 times,RealSipErrorCheck!");
  359. if (!m_pPhoneClient)
  360. return Error_NetBroken;
  361. return m_pPhoneClient->RealErrorCheck();
  362. }
  363. ErrorCodeEnum SetCallingType(CallingTypeEnum eType)
  364. {
  365. if (!m_pPhoneClient)
  366. return Error_NetBroken;
  367. Dbg("SetCallingType = %d.", eType);
  368. PhoneService_SetCallingParam_Info info;
  369. info.CallType = eType;
  370. return m_pPhoneClient->SetCallingParam(info);
  371. }
  372. ErrorCodeEnum StopSpeakerAudioCapture()
  373. {
  374. ErrorCodeEnum rc = Error_NotImpl;
  375. MediaService_ClientBase* pMSClient = new MediaService_ClientBase(m_pEntity);
  376. if(pMSClient->Connect() != Error_Succeed)
  377. {
  378. pMSClient->SafeDelete();
  379. pMSClient = NULL;
  380. }
  381. else
  382. {
  383. Dbg("MSClient connected success!");
  384. rc = pMSClient->StopSpeakerRender();
  385. Dbg("pMSClient->StopSpeakerRender rc:0x%x",rc);
  386. if(rc != Error_Succeed){
  387. Dbg("Stop Speaker Render failed return 0x%08x", rc);
  388. }
  389. pMSClient->GetFunction()->CloseSession();
  390. pMSClient->SafeDelete();
  391. pMSClient = NULL;
  392. }
  393. return rc;
  394. }
  395. ErrorCodeEnum GetLivenessDetectionStatus()
  396. {
  397. ErrorCodeEnum rc = Error_InvalidState;
  398. LivenessDetectionService_ClientBase* pLDClient = new LivenessDetectionService_ClientBase(m_pEntity);
  399. if(pLDClient->Connect() != Error_Succeed)
  400. {
  401. pLDClient->SafeDelete();
  402. pLDClient = NULL;
  403. }
  404. else{
  405. rc = Error_Succeed;
  406. Dbg("connect liveness detection entity success!");
  407. pLDClient->GetFunction()->CloseSession();
  408. pLDClient->SafeDelete();
  409. pLDClient = NULL;
  410. }
  411. return rc;
  412. }
  413. ErrorCodeEnum StopLivenessDetection()
  414. {
  415. Dbg("stop liveness detection.");
  416. LogEvent(Severity_Middle,LOG_EVT_STOPLIVEDETECTNOTICEDISPLAY,"stop live detection notice display.");
  417. LogEvent(Severity_Middle,LOG_EVT_STOPLIVEDETECTDISPLAY,"stop live detection");
  418. PostEventFIFO(new FSMEvent(USER_EVT_STOPVIDEODISPLAY));
  419. return Error_Succeed;
  420. }
  421. private:
  422. int TranslateState(int innerState);
  423. ErrorCodeEnum SetCallState(int state);
  424. ErrorCodeEnum MakeCall(int nSipServer,CallingParam callingparam)
  425. {
  426. if (!m_pPhoneClient)
  427. return Error_NetBroken;
  428. CSimpleStringA strCode;
  429. PhoneService_MakeCall_Req Req;
  430. PhoneService_MakeCall_Ans Ans;
  431. if ((NULL != callingparam.connect_ip)&&(0 != callingparam.connect_port))
  432. {
  433. if (callingparam.nCallType == PADRINGUP_CALLTYPE)
  434. {
  435. CSimpleStringA session = "80";
  436. session+=callingparam.connect_session;
  437. Req.call_uri = MakeCallUri(session,callingparam.connect_ip,callingparam.connect_port);
  438. }
  439. else if((callingparam.nCallType == PADTOPAD_CALLTYPE)||(callingparam.nCallType == MOBILETOPAD_CALLTYPE))
  440. {
  441. CSimpleStringA session = "90";
  442. session+=callingparam.connect_session;
  443. Req.call_uri = MakeCallUri(session,callingparam.connect_ip,callingparam.connect_port);
  444. }
  445. else
  446. {
  447. Req.call_uri = MakeCallUri(callingparam.connect_session,callingparam.connect_ip,callingparam.connect_port);
  448. }
  449. }
  450. else
  451. {
  452. if((m_strSIPCallNum[nSipServer]=="")&&(m_strSIPProxyIP[nSipServer]=="")&&(m_iSIPProxyPort[nSipServer]==0))
  453. {
  454. return Error_Param;
  455. }
  456. else
  457. {
  458. if (callingparam.nCallType == PADRINGUP_CALLTYPE)
  459. {
  460. CSimpleStringA session = "80";
  461. session+=callingparam.connect_session;
  462. Req.call_uri = MakeCallUri(session,nSipServer);
  463. }
  464. else if((callingparam.nCallType == PADTOPAD_CALLTYPE)||(callingparam.nCallType == MOBILETOPAD_CALLTYPE))
  465. {
  466. CSimpleStringA session = "90";
  467. session+=callingparam.connect_session;
  468. Req.call_uri = MakeCallUri(session,nSipServer);
  469. }
  470. else
  471. {
  472. Req.call_uri = MakeCallUri(callingparam.connect_session,nSipServer);
  473. }
  474. }
  475. }
  476. //设置呼叫参数
  477. PhoneService_SetCallingParam_Info info;
  478. info.CallType = callingparam.nCallType;
  479. info.connect_session = callingparam.connect_session;
  480. info.connect_ip = callingparam.connect_ip;
  481. info.connect_port = callingparam.connect_port;
  482. m_pPhoneClient->SetCallingParam(info);
  483. Dbg("Make Distribute Call CallType = %d", info.CallType);
  484. ErrorCodeEnum Error = m_pPhoneClient->MakeCall(Req, Ans, 10000);
  485. return Error;
  486. }
  487. ErrorCodeEnum MakeCall(const char *hint_callnum,int nSipServer)
  488. {
  489. if (!m_pPhoneClient)
  490. return Error_NetBroken;
  491. if((m_strSIPCallNum[nSipServer]=="")&&(m_strSIPProxyIP[nSipServer]=="")&&(m_iSIPProxyPort[nSipServer]==0))
  492. {
  493. return Error_Param;
  494. }
  495. CSimpleStringA strCode;
  496. PhoneService_MakeCall_Req Req;
  497. PhoneService_MakeCall_Ans Ans;
  498. Req.call_uri = MakeCallUri(hint_callnum,nSipServer);
  499. PhoneService_SetCallingParam_Info info;
  500. info.CallType = NORMAL_CALLTYPE;
  501. if (DOUBLERECORD_CALLTYPE == m_CallingParam.nCallType)
  502. {
  503. info.CallType = DOUBLERECORD_CALLTYPE;
  504. }
  505. m_pPhoneClient->SetCallingParam(info);
  506. Dbg("before make call, call type is %d", info.CallType);
  507. ErrorCodeEnum Error = m_pPhoneClient->MakeCall(Req, Ans, 10000);
  508. return Error;
  509. }
  510. ErrorCodeEnum HangupCall()
  511. {
  512. Dbg("Hangup Call!");
  513. if (!m_pPhoneClient)
  514. return Error_NetBroken;
  515. PhoneService_HangupCall_Req Req;
  516. PhoneService_HangupCall_Ans Ans;
  517. if (!m_SessionParam.connect_session.IsNullOrEmpty())
  518. {
  519. Req.session_num = m_SessionParam.connect_session;
  520. Dbg("Hangup Call connect_session = %s", m_SessionParam.connect_session.GetData());
  521. }
  522. if (!m_SessionParam.connect_ip.IsNullOrEmpty())
  523. {
  524. Req.branch_server_ip = m_SessionParam.connect_ip;
  525. Dbg("Hangup Call connect_ip = %s", m_SessionParam.connect_ip.GetData());
  526. }
  527. if (m_SessionParam.event_port)
  528. {
  529. Req.branch_server_port = m_SessionParam.event_port;
  530. }
  531. return m_pPhoneClient->HangupCall(Req, Ans, 10000);
  532. }
  533. ErrorCodeEnum ReleaseCall(int type)
  534. {
  535. if (!m_pPhoneClient)
  536. return Error_NetBroken;
  537. PhoneService_ReleaseCall_Req Req;
  538. Req.type = type;
  539. PhoneService_ReleaseCall_Ans Ans;
  540. return m_pPhoneClient->ReleaseCall(Req, Ans, 10000);
  541. }
  542. ErrorCodeEnum StartChannel(int nChanServer)
  543. {
  544. if (!m_pChannelClient)
  545. return Error_NetBroken;
  546. if ((m_strChanProxyIP[nChanServer]=="")&&(m_strChanCallNum[nChanServer]=="")&&(m_iChanProxyPort[nChanServer]==0))
  547. {
  548. return Error_Param;
  549. }
  550. ChannelService_Connect_Req Req;
  551. ChannelService_Connect_Ans Ans;
  552. Req.callno = m_strChanCallNum[nChanServer];
  553. Req.ip = m_strChanProxyIP[nChanServer];
  554. Req.port = m_iChanProxyPort[nChanServer];
  555. return m_pChannelClient->Connect(Req, Ans, 10000);
  556. }
  557. CSimpleStringA MakeSubid(CSimpleStringA subid)
  558. {
  559. int idlen = subid.GetLength();
  560. if (idlen > SUBID_LENGTH)
  561. {
  562. return subid.SubString(idlen - SUBID_LENGTH, SUBID_LENGTH);
  563. }
  564. else
  565. {
  566. return subid;
  567. }
  568. }
  569. ErrorCodeEnum StartChannel(int nChanServer,CallingParam callparam)
  570. {
  571. if (!m_pChannelClient)
  572. return Error_NetBroken;
  573. ChannelService_Connect_Req Req;
  574. ChannelService_Connect_Ans Ans;
  575. if(NULL != callparam.connect_ip){
  576. if (callparam.nCallType == PADRINGUP_CALLTYPE) //如果是主叫
  577. {
  578. Req.callno = m_strChanCallNum[nChanServer];
  579. Req.ip =callparam.connect_ip;
  580. Req.port = m_iChanProxyPort[nChanServer];
  581. Req.etype = callparam.nCallType;
  582. return m_pChannelClient->Connect(Req, Ans, 10000);
  583. }
  584. else if((callparam.nCallType == PADTOPAD_CALLTYPE)||(callparam.nCallType == MOBILETOPAD_CALLTYPE)) //如果是被叫
  585. {
  586. //Req.callno = m_strChanCallNum[nChanServer];
  587. CSimpleStringA strsession = callparam.connect_session;
  588. Req.callno = strsession;
  589. Req.ip = callparam.connect_ip;
  590. Req.port = callparam.assistant_port;
  591. Req.etype = callparam.nCallType;
  592. //发起被动连接协助通道,连接proxy_b
  593. return m_pChannelClient->Connect(Req, Ans, 10000);
  594. }
  595. else{
  596. return Error_Param;
  597. }
  598. }
  599. else{
  600. if ((m_strChanProxyIP[nChanServer]=="")&&(m_strChanCallNum[nChanServer]=="")&&(m_iChanProxyPort[nChanServer]==0)){
  601. return Error_Param;
  602. }
  603. else{
  604. Req.callno = m_strChanCallNum[nChanServer];
  605. Req.ip = m_strChanProxyIP[nChanServer];
  606. Req.port = m_iChanProxyPort[nChanServer];
  607. Req.etype = NORMAL_CALLTYPE;
  608. return m_pChannelClient->Connect(Req, Ans, 10000);
  609. }
  610. }
  611. }
  612. ErrorCodeEnum StopChannel()
  613. {
  614. Dbg("stop channel");
  615. if (!m_pPhoneClient)
  616. return Error_NetBroken;
  617. ChannelService_Close_Req Req;
  618. ChannelService_Close_Ans Ans;
  619. return m_pChannelClient->Close(Req, Ans, 10000);
  620. }
  621. CSimpleStringA MakeCallUri(const char *callnum,const char *serverip,int serverport)
  622. {
  623. return CSimpleStringA::Format("sip:%s@%s:%d;transport=UDP",
  624. callnum, (LPCSTR)serverip,serverport);
  625. }
  626. CSimpleStringA MakeCallUri(const char *hint_callnum,int nServer)
  627. {
  628. if (m_iSIPProxyPort[nServer] == 5060)
  629. {
  630. return CSimpleStringA::Format("sip:%s@%s;transport=UDP",
  631. hint_callnum, (LPCSTR)m_strSIPProxyIP[nServer]);
  632. }
  633. else
  634. {
  635. return CSimpleStringA::Format("sip:%s@%s:%d;transport=UDP",
  636. hint_callnum, (LPCSTR)m_strSIPProxyIP[nServer], m_iSIPProxyPort[nServer]);
  637. }
  638. }
  639. ErrorCodeEnum LoadConfig()
  640. {
  641. SpIniMappingTable table;
  642. table.AddEntryString("CounterConnector", "sip_proxy_ip", m_strSIPProxyIP[0], NULL);
  643. table.AddEntryInt("CounterConnector", "sip_proxy_port", m_iSIPProxyPort[0], 0);
  644. table.AddEntryString("CounterConnector", "sip_default_call_no", m_strSIPCallNum[0], NULL);
  645. table.AddEntryString("CounterConnector", "chan_proxy_ip", m_strChanProxyIP[0], NULL);
  646. table.AddEntryInt("CounterConnector", "chan_proxy_port", m_iChanProxyPort[0], 0);
  647. table.AddEntryString("CounterConnector", "chan_default_call_no", m_strChanCallNum[0], NULL);
  648. table.AddEntryString("CounterConnector", "sip_proxy_ip_backup", m_strSIPProxyIP[1], NULL);
  649. table.AddEntryInt("CounterConnector", "sip_proxy_port_backup", m_iSIPProxyPort[1], 0);
  650. table.AddEntryString("CounterConnector", "sip_default_call_no_backup", m_strSIPCallNum[1], NULL);
  651. table.AddEntryString("CounterConnector", "chan_proxy_ip_backup", m_strChanProxyIP[1], NULL);
  652. table.AddEntryInt("CounterConnector", "chan_proxy_port_backup", m_iChanProxyPort[1], 0);
  653. table.AddEntryString("CounterConnector", "chan_default_call_no_backup", m_strChanCallNum[1], NULL);
  654. CSmartPointer<IConfigInfo> spConfig;
  655. ErrorCodeEnum Error = m_pEntity->GetFunction()->OpenConfig(Config_CenterSetting, spConfig);
  656. if (Error == Error_Succeed) {
  657. Error = table.Load(spConfig);
  658. }
  659. return Error;
  660. }
  661. ErrorCodeEnum LoadTerminalId()
  662. {
  663. CSystemStaticInfo Info;
  664. ErrorCodeEnum Error = m_pEntity->GetFunction()->GetSystemStaticInfo(Info);
  665. if (Error == Error_Succeed) {
  666. m_strTerminalId = Info.strTerminalID;
  667. }
  668. return Error;
  669. }
  670. ErrorCodeEnum AllowAgentWrite()
  671. {
  672. if (!m_pChannelClient)
  673. return Error_NetBroken;
  674. ChannelService_Send_Info Info;
  675. Info.compress = false;
  676. Info.encrypt = false;
  677. Info.id = 0;
  678. Info.sub_type = 0;
  679. Info.type = ACM_TYPE_MODE;
  680. return m_pChannelClient->Send(Info);
  681. }
  682. ErrorCodeEnum StartRing()
  683. {
  684. #ifdef _WIN32
  685. BOOL bRet = FALSE;// ::PlaySoundA(MAKEINTRESOURCEA(IDR_RINGOUT), ModuleBase::GetModuleBase()->GetInstance(), SND_ASYNC | SND_RESOURCE | SND_LOOP);
  686. if (bRet) {
  687. m_bRing = TRUE;
  688. return Error_Succeed;
  689. }
  690. else {
  691. Dbg("play sound failed!%d", GetLastError());
  692. return Error_Unexpect;
  693. }
  694. #else
  695. m_bRing = TRUE;
  696. return Error_Succeed;
  697. #endif
  698. }
  699. void StopRing()
  700. {
  701. #ifdef _WIN32
  702. if (m_bRing) {
  703. BOOL bRet = FALSE;
  704. int tries = 0;
  705. //do {
  706. // bRet = ::PlaySoundA(NULL, NULL, SND_ASYNC | SND_LOOP);
  707. //} while (bRet == FALSE && (Sleep(100), tries < 3));
  708. m_bRing = FALSE;
  709. }
  710. #else
  711. if (m_bRing) {
  712. m_bRing = FALSE;
  713. }
  714. #endif
  715. }
  716. BOOL CheckBeginRing(int iSrcState, int iDstState)
  717. {
  718. if (iSrcState == ACMCallFSM::s0 && iDstState == ACMCallFSM::s10)
  719. return TRUE;
  720. return FALSE;
  721. }
  722. BOOL CheckEndRing(int iSrcState, int iDstState)
  723. {
  724. if (m_bRing) {
  725. if (iSrcState == ACMCallFSM::s10 || iSrcState == ACMCallFSM::s12) {
  726. if (iDstState != ACMCallFSM::s10 && iDstState != ACMCallFSM::s12)
  727. return TRUE;
  728. }
  729. }
  730. return FALSE;
  731. }
  732. BOOL ReConnectionAssistchan();
  733. BOOL ReConnectionSipphone();
  734. int GetDelayTime();
  735. void SetDelayTime();
  736. public:
  737. BOOL m_bHandFree;
  738. //坐席控制话筒的当前状态
  739. BOOL m_bAgentHandFree;
  740. BOOL m_bIsAgentControl;
  741. //流程拨号,带技能号
  742. CSimpleStringA m_strHintCallNum;
  743. BOOL m_bAssistchanIdel;
  744. CurServerNum m_nCurSipServer;
  745. CurServerNum m_nCurChanServer;
  746. //呼叫类型,用于区分是分布式呼叫还是常规呼叫,由业务中台设置或者指令模块设置
  747. CallingParam m_CallingParam;
  748. SessionParam m_SessionParam;
  749. int m_nSysCallType;//0:普通模式,1:p2p模式
  750. private:
  751. DWORD m_nStarttime;
  752. PhoneService_ClientBase *m_pPhoneClient;
  753. ChannelService_ClientBase *m_pChannelClient;
  754. SyncService_ClientBase*m_pSyncServiceClient;
  755. CSimpleStringA m_strTerminalId;
  756. CSimpleStringA m_strSIPProxyIP[2];
  757. int m_iSIPProxyPort[2];
  758. CSimpleStringA m_strSIPCallNum[2];
  759. CSimpleStringA m_strChanProxyIP[2];
  760. int m_iChanProxyPort[2];
  761. CSimpleStringA m_strChanCallNum[2];
  762. BOOL m_bRing;
  763. };