ConnectorFSM.h 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797
  1. #pragma once
  2. #include "SpHelper.h"
  3. #include "SpFSM.h"
  4. #include "SpIni.h"
  5. #include "IHttpFunc.h"
  6. #include "Event.h"
  7. #include "../include/EventCode.h"
  8. #include "y2k_time.h"
  9. #include "CommEntityUtil.hpp"
  10. #ifdef _WIN32
  11. #include "resource.h"
  12. #endif
  13. #include "http_callrouter.h"
  14. #include "../mod_assistantchannel/VideoDesc.h"
  15. #include "../mod_sipphone/SIPPhone_client_g.h"
  16. using namespace SIPPhone;
  17. #include "../mod_assistantchannel/AssistantChannel_client_g.h"
  18. using namespace AssistantChannel;
  19. #include "../mod_mediacontroller/MediaController_client_g.h"
  20. using namespace MediaController;
  21. #include "../mod_assistantchannel/chan_protocol.h"
  22. #include "CallType.h"
  23. #include "CounterConnector_def_g.h"
  24. #include "CounterConnector_msg_g.h"
  25. using namespace CounterConnector;
  26. #include "../mod_interactioncontext/InteractionContext_client_g.h"
  27. #include "../mod_interactioncontext/InteractionContext_def_g.h"
  28. using namespace InteractionContext;
  29. #include <vector>
  30. #include <string>
  31. #ifndef RVC_DEFAULT_HTTPTIMEOUT
  32. #define RVC_DEFAULT_HTTPTIMEOUT 10
  33. #endif // !RVC_DEFAULT_HTTPTIMEOUT
  34. #ifndef RVC_DEFAULT_VOIPSERVER_ADDR
  35. #ifdef DEVOPS_ON_PRD
  36. #define RVC_DEFAULT_VOIPSERVER_ADDR "sip:843235023@10.16.129.1,10.16.130.65 2334|sip:843235023@10.16.129.3,10.16.130.66 2334|sip:843235023@10.16.129.5,10.16.130.67 2334|sip:843235023@10.16.129.9,10.16.130.68 2334|sip:843235023@10.16.129.10,10.16.130.131 2334|sip:843235023@10.16.128.1,10.16.130.132 2334|sip:843235023@10.16.128.2,10.16.130.133 2334|sip:843235023@10.16.128.3,10.16.130.134 2334|sip:843235023@10.16.128.4,10.16.130.68 2334|sip:843235023@10.16.128.5,10.16.130.131 2334\0"
  37. #else
  38. #define RVC_DEFAULT_VOIPSERVER_ADDR "sip:843215022@55.9.188.83,55.9.188.83 2334|sip:843215022@55.9.188.83,55.9.188.83 2334\0"
  39. #endif// !DEVOPS_ON_PRD
  40. #endif // !RVC_DEFAULT_VOIPSERVER_ADDR
  41. #define USER_EVT_PICKUP_CALL EVT_USER+1
  42. #define USER_EVT_HANDFREE_CALL EVT_USER+2
  43. #define USER_EVT_HANGUP EVT_USER+3
  44. #define USER_EVT_DOUBLE_RECORD_CALL EVT_USER+5
  45. #define USER_EVT_JMP_FAIL EVT_USER+11
  46. #define USER_EVT_JMP_HANDFREE EVT_USER+12
  47. #define USER_EVT_JMP_PICKUP EVT_USER+13
  48. #define USER_EVT_TO_HANDFREE EVT_USER+14
  49. #define USER_EVT_TO_PICKUP EVT_USER+15
  50. #define USER_EVT_SIP_STATE_CONNECTED EVT_USER+21
  51. #define USER_EVT_SIP_STATE_IDLE EVT_USER+22
  52. #define USER_EVT_CHAN_STATE_CONNECTED EVT_USER+31
  53. #define USER_EVT_CHAN_STATE_IDLE EVT_USER+33
  54. #define USER_EVT_RECONNECT EVT_USER+40
  55. #define USER_EVT_AGENT_WRITABLE EVT_USER+41
  56. #define USER_EVT_ERROR EVT_USER+10
  57. #define USER_EVT_EXIT EVT_USER+50
  58. #define USER_EVT_STOP_RECORD_BROADCAST EVT_USER+55
  59. #define USER_EVT_ASSISTCHAN_IDEL EVT_USER+60
  60. #define USER_EVT_SIPPHONE_IDEL EVT_USER+61
  61. #define USER_EVT_STARTVIDEODISPLAY EVT_USER+70
  62. #define USER_EVT_STOPVIDEODISPLAY EVT_USER+71
  63. #define USER_EVT_SHOWLOACALVIDEO EVT_USER+72
  64. #define USER_EVT_STOPLOCALVIDEO EVT_USER+73
  65. #define USER_EVT_SHOWLOACALREMOTEVIDEO EVT_USER+74
  66. #define USER_EVT_STOPLOACALREMOTEVIDEO EVT_USER+75
  67. enum CurServerNum
  68. {
  69. Error_Server = -1,
  70. MAIN_SERVER,
  71. BACK_SERVER
  72. };
  73. #ifndef MAX_VOIP_SERVER_NUM
  74. #define MAX_VOIP_SERVER_NUM 16
  75. #endif
  76. struct ChanStateConnectedEvent : public FSMEvent
  77. {
  78. ChanStateConnectedEvent(const char *param) : FSMEvent(USER_EVT_CHAN_STATE_CONNECTED), m_param(param) {}
  79. CSimpleStringA m_param;
  80. };
  81. struct StartVideoDisplayEvent : public FSMEvent
  82. {
  83. StartVideoDisplayEvent(const char *param) : FSMEvent(USER_EVT_STARTVIDEODISPLAY), m_param(param) {}
  84. CSimpleStringA m_param;
  85. };
  86. struct ShowLocalVideoEvent : public FSMEvent
  87. {
  88. ShowLocalVideoEvent(const char *param) : FSMEvent(USER_EVT_SHOWLOACALVIDEO), m_param(param) {}
  89. CSimpleStringA m_param;
  90. };
  91. struct ShowLocalAndRemoteVideoEvent : public FSMEvent
  92. {
  93. ShowLocalAndRemoteVideoEvent(const char *param) : FSMEvent(USER_EVT_SHOWLOACALREMOTEVIDEO), m_param(param) {}
  94. CSimpleStringA m_param;
  95. };
  96. struct CallingParam
  97. {
  98. //呼叫模式,0:可视柜台正常呼叫,1:双录连线
  99. CallingTypeEnum nCallType;
  100. CSimpleStringA connect_session;
  101. CSimpleStringA connect_ip;
  102. int connect_port;
  103. CSimpleStringA subid;
  104. int assistant_port;
  105. };
  106. #ifndef MAX_LENGTH_OF_BRANCHNO
  107. #define MAX_LENGTH_OF_BRANCHNO 4
  108. #endif
  109. #ifndef MAX_LENGTH_OF_SESSIONID
  110. #define MAX_LENGTH_OF_SESSIONID 16
  111. #endif
  112. #ifndef MAX_LENGTH_OF_CONNECTIP
  113. #define MAX_LENGTH_OF_CONNECTIP 16
  114. #endif
  115. class ACMCallFSM : public FSMImpl<ACMCallFSM>, public IFSMStateHooker
  116. {
  117. public:
  118. enum {s0,s7,s8,s10,s11,s12,s13,s14,s20,s21,s22,s23,s24,s3,s4,s50,s51,s52,s53,s60,s61,s62,s63};
  119. BEGIN_FSM_STATE(ACMCallFSM)
  120. FSM_STATE_ENTRY(s0,"Offline",s0_on_entry,s0_on_exit,s0_on_event)
  121. FSM_STATE_ENTRY(s7,"ShowLocalVideo",s7_on_entry,s7_on_exit,s7_on_event)
  122. FSM_STATE_ENTRY(s8,"Delay",s8_on_entry,s8_on_exit,s8_on_event)
  123. FSM_STATE_ENTRY(s10,"Calling_Start",s10_on_entry,s10_on_exit,s10_on_event)
  124. FSM_STATE_ENTRY(s11,"Calling_SipConnect",s11_on_entry,s11_on_exit,s11_on_event)
  125. FSM_STATE_ENTRY(s12,"Calling_ChanConnect",s12_on_entry,s12_on_exit,s12_on_event)
  126. FSM_STATE_ENTRY(s13,"Calling_AllReady",s13_on_entry,s13_on_exit,s13_on_event)
  127. FSM_STATE_ENTRY(s14,"ShowLocalRemoteVideo",s14_on_entry,s14_on_exit,s14_on_event)
  128. FSM_STATE_ENTRY(s20, "ExitCall_Start",s20_on_entry,s20_on_exit,s20_on_event)
  129. FSM_STATE_ENTRY(s21, "ExitChan_Finished",s21_on_entry,s21_on_exit,s21_on_event)
  130. FSM_STATE_ENTRY(s22, "ExitSip_Finished",s22_on_entry,s22_on_exit,s22_on_event)
  131. FSM_STATE_ENTRY(s23, "ExitCall_AllFinished",s23_on_entry,s23_on_exit,s23_on_event)
  132. FSM_STATE_ENTRY(s24, "ExitCall_Delay",s24_on_entry,s24_on_exit,s24_on_event)
  133. FSM_STATE_ENTRY(s3, "HandFree",s3_on_entry,s3_on_exit,s3_on_event)
  134. FSM_STATE_ENTRY(s4, "Pickup",s4_on_entry,s4_on_exit,s4_on_event)
  135. FSM_STATE_ENTRY(s50, "Broken0",s50_on_entry,s50_on_exit,s50_on_event)
  136. FSM_STATE_ENTRY(s51, "Broken_SipFinished",s51_on_entry,s51_on_exit,s51_on_event)
  137. FSM_STATE_ENTRY(s52, "Broken_ChanFinished",s52_on_entry,s52_on_exit,s52_on_event)
  138. FSM_STATE_ENTRY(s53, "Broken_AllFinished",s53_on_entry,s53_on_exit,s53_on_event)
  139. FSM_STATE_ENTRY(s60, "Hangup_Start",s60_on_entry,s60_on_exit,s60_on_event)
  140. FSM_STATE_ENTRY(s61, "Hangup_SipFinished",s61_on_entry,s61_on_exit,s61_on_event)
  141. FSM_STATE_ENTRY(s62, "Hangup_ChanFinished",s62_on_entry,s62_on_exit,s62_on_event)
  142. FSM_STATE_ENTRY(s63, "Hangup_AllFinished",s63_on_entry,s63_on_exit,s63_on_event)
  143. END_FSM_STATE()
  144. BEGIN_FSM_RULE(ACMCallFSM,s0)
  145. FSM_RULE_ENTRY_ANY(s0, s8, USER_EVT_PICKUP_CALL)
  146. FSM_RULE_ENTRY_ANY(s0, s7, USER_EVT_SHOWLOACALVIDEO)
  147. FSM_RULE_ENTRY_ANY(s0, s14, USER_EVT_SHOWLOACALREMOTEVIDEO)
  148. FSM_RULE_ENTRY_ANY(s7, s0, USER_EVT_STOPLOCALVIDEO)
  149. FSM_RULE_ENTRY_ANY(s14, s0, USER_EVT_STOPLOACALREMOTEVIDEO)
  150. FSM_RULE_ENTRY_ANY(s0, FSM_STATE_EXIT, USER_EVT_EXIT)
  151. FSM_RULE_ENTRY_ANY(s0, s8, USER_EVT_HANDFREE_CALL)
  152. FSM_RULE_ENTRY_ANY(s0, s8, USER_EVT_DOUBLE_RECORD_CALL)
  153. FSM_RULE_ENTRY_ANY(s14, s0, USER_EVT_STOP_RECORD_BROADCAST)
  154. FSM_RULE_ENTRY_ANY(s8, s11, EVT_TIMER)
  155. FSM_RULE_ENTRY_ANY(s11, s12, USER_EVT_SIP_STATE_CONNECTED)
  156. FSM_RULE_ENTRY_ANY(s11, s23, USER_EVT_JMP_FAIL)
  157. FSM_RULE_ENTRY_ANY(s11, s21, EVT_TIMER)
  158. FSM_RULE_ENTRY_ANY(s11, s23, USER_EVT_SIP_STATE_IDLE)
  159. FSM_RULE_ENTRY_ANY(s11, s21, USER_EVT_HANGUP)
  160. FSM_RULE_ENTRY_ANY(s21, s23, USER_EVT_SIP_STATE_IDLE)
  161. FSM_RULE_ENTRY_ANY(s21, s23, USER_EVT_JMP_FAIL)
  162. FSM_RULE_ENTRY_ANY(s12, s13, USER_EVT_CHAN_STATE_CONNECTED)
  163. FSM_RULE_ENTRY_ANY(s12, s21, USER_EVT_CHAN_STATE_IDLE)
  164. FSM_RULE_ENTRY_ANY(s12, s22, USER_EVT_SIP_STATE_IDLE)
  165. FSM_RULE_ENTRY_ANY(s12, s21, USER_EVT_JMP_FAIL)
  166. FSM_RULE_ENTRY_ANY(s22, s23, USER_EVT_CHAN_STATE_IDLE)
  167. FSM_RULE_ENTRY_ANY(s12, s20, USER_EVT_HANGUP)
  168. FSM_RULE_ENTRY_ANY(s20, s21, USER_EVT_CHAN_STATE_IDLE)
  169. FSM_RULE_ENTRY_ANY(s20, s22, USER_EVT_SIP_STATE_IDLE)
  170. FSM_RULE_ENTRY_ANY(s13, s3, USER_EVT_JMP_HANDFREE)
  171. FSM_RULE_ENTRY_ANY(s13, s4, USER_EVT_JMP_PICKUP)
  172. FSM_RULE_ENTRY_ANY(s23, s0, EVT_TIMER)
  173. FSM_RULE_ENTRY_ANY(s23, s24, USER_EVT_RECONNECT)
  174. FSM_RULE_ENTRY_ANY(s24, s11, EVT_TIMER)
  175. FSM_RULE_ENTRY_ANY(s3, s4, USER_EVT_TO_PICKUP)
  176. FSM_RULE_ENTRY_ANY(s3, s51, USER_EVT_SIP_STATE_IDLE)
  177. FSM_RULE_ENTRY_ANY(s3, s52, USER_EVT_CHAN_STATE_IDLE)
  178. FSM_RULE_ENTRY_ANY(s3, s60, USER_EVT_HANGUP)
  179. FSM_RULE_ENTRY_ANY(s4, s3, USER_EVT_TO_HANDFREE)
  180. FSM_RULE_ENTRY_ANY(s4, s51, USER_EVT_SIP_STATE_IDLE)
  181. FSM_RULE_ENTRY_ANY(s4, s52, USER_EVT_CHAN_STATE_IDLE)
  182. FSM_RULE_ENTRY_ANY(s4, s60, USER_EVT_HANGUP)
  183. FSM_RULE_ENTRY_ANY(s50, s51, USER_EVT_SIP_STATE_IDLE)
  184. FSM_RULE_ENTRY_ANY(s50, s52, USER_EVT_CHAN_STATE_IDLE)
  185. FSM_RULE_ENTRY_ANY(s51, s53, USER_EVT_CHAN_STATE_IDLE)
  186. FSM_RULE_ENTRY_ANY(s52, s53, USER_EVT_SIP_STATE_IDLE)
  187. FSM_RULE_ENTRY_ANY(s52, s53, USER_EVT_JMP_FAIL)
  188. FSM_RULE_ENTRY_ANY(s53, s0, EVT_TIMER)
  189. FSM_RULE_ENTRY_ANY(s60, s61, USER_EVT_SIP_STATE_IDLE)
  190. FSM_RULE_ENTRY_ANY(s60, s62, USER_EVT_CHAN_STATE_IDLE)
  191. FSM_RULE_ENTRY_ANY(s61, s63, USER_EVT_CHAN_STATE_IDLE)
  192. FSM_RULE_ENTRY_ANY(s62, s63, USER_EVT_SIP_STATE_IDLE)
  193. FSM_RULE_ENTRY_ANY(s62, s63, USER_EVT_JMP_FAIL)
  194. FSM_RULE_ENTRY_ANY(s63, s0, EVT_TIMER)
  195. //assitchannel重启后,状态跳转到Offline
  196. FSM_RULE_ENTRY_ANY(s3, s0, USER_EVT_ASSISTCHAN_IDEL)
  197. FSM_RULE_ENTRY_ANY(s4, s0, USER_EVT_ASSISTCHAN_IDEL)
  198. FSM_RULE_ENTRY_ANY(s50, s0, USER_EVT_ASSISTCHAN_IDEL)
  199. FSM_RULE_ENTRY_ANY(s51, s0, USER_EVT_ASSISTCHAN_IDEL)
  200. FSM_RULE_ENTRY_ANY(s52, s0, USER_EVT_ASSISTCHAN_IDEL)
  201. FSM_RULE_ENTRY_ANY(s53, s0, USER_EVT_ASSISTCHAN_IDEL)
  202. FSM_RULE_ENTRY_ANY(s60, s0, USER_EVT_ASSISTCHAN_IDEL)
  203. FSM_RULE_ENTRY_ANY(s61, s0, USER_EVT_ASSISTCHAN_IDEL)
  204. FSM_RULE_ENTRY_ANY(s62, s0, USER_EVT_ASSISTCHAN_IDEL)
  205. FSM_RULE_ENTRY_ANY(s63, s0, USER_EVT_ASSISTCHAN_IDEL)
  206. //sipphone重启后,所有状态跳转到Offline
  207. FSM_RULE_ENTRY_ANY(s8, s0, USER_EVT_SIPPHONE_IDEL)
  208. FSM_RULE_ENTRY_ANY(s10, s0, USER_EVT_SIPPHONE_IDEL)
  209. FSM_RULE_ENTRY_ANY(s11, s0, USER_EVT_SIPPHONE_IDEL)
  210. FSM_RULE_ENTRY_ANY(s12, s0, USER_EVT_SIPPHONE_IDEL)
  211. FSM_RULE_ENTRY_ANY(s13, s0, USER_EVT_SIPPHONE_IDEL)
  212. FSM_RULE_ENTRY_ANY(s20, s0, USER_EVT_SIPPHONE_IDEL)
  213. FSM_RULE_ENTRY_ANY(s21, s0, USER_EVT_SIPPHONE_IDEL)
  214. FSM_RULE_ENTRY_ANY(s22, s0, USER_EVT_SIPPHONE_IDEL)
  215. FSM_RULE_ENTRY_ANY(s23, s0, USER_EVT_SIPPHONE_IDEL)
  216. FSM_RULE_ENTRY_ANY(s24, s0, USER_EVT_SIPPHONE_IDEL)
  217. FSM_RULE_ENTRY_ANY(s3, s0, USER_EVT_SIPPHONE_IDEL)
  218. FSM_RULE_ENTRY_ANY(s4, s0, USER_EVT_SIPPHONE_IDEL)
  219. FSM_RULE_ENTRY_ANY(s50, s0, USER_EVT_SIPPHONE_IDEL)
  220. FSM_RULE_ENTRY_ANY(s51, s0, USER_EVT_SIPPHONE_IDEL)
  221. FSM_RULE_ENTRY_ANY(s52, s0, USER_EVT_SIPPHONE_IDEL)
  222. FSM_RULE_ENTRY_ANY(s53, s0, USER_EVT_SIPPHONE_IDEL)
  223. FSM_RULE_ENTRY_ANY(s60, s0, USER_EVT_SIPPHONE_IDEL)
  224. FSM_RULE_ENTRY_ANY(s61, s0, USER_EVT_SIPPHONE_IDEL)
  225. FSM_RULE_ENTRY_ANY(s62, s0, USER_EVT_SIPPHONE_IDEL)
  226. FSM_RULE_ENTRY_ANY(s63, s0, USER_EVT_SIPPHONE_IDEL)
  227. //sipphone重启后,所有状态跳转到Offline
  228. //分布式呼叫场景,拒接主动挂断
  229. FSM_RULE_ENTRY_ANY(s0, s60, USER_EVT_HANGUP)
  230. //分布式呼叫场景,拒接主动挂断
  231. END_FSM_RULE()
  232. ACMCallFSM();
  233. ~ACMCallFSM();
  234. virtual void OnStateTrans(int iSrcState, int iDstState);
  235. virtual ErrorCodeEnum OnInit();
  236. virtual ErrorCodeEnum OnExit();
  237. void s0_on_entry();
  238. void s0_on_exit();
  239. unsigned int s0_on_event(FSMEvent* event);
  240. void s7_on_entry();
  241. void s7_on_exit();
  242. unsigned int s7_on_event(FSMEvent* event);
  243. void s8_on_entry();
  244. void s8_on_exit();
  245. unsigned int s8_on_event(FSMEvent* event);
  246. void s10_on_entry();
  247. void s10_on_exit();
  248. unsigned int s10_on_event(FSMEvent* event);
  249. void s11_on_entry();
  250. void s11_on_exit();
  251. unsigned int s11_on_event(FSMEvent* event);
  252. void s12_on_entry();
  253. void s12_on_exit();
  254. unsigned int s12_on_event(FSMEvent* event);
  255. void s13_on_entry();
  256. void s13_on_exit();
  257. unsigned int s13_on_event(FSMEvent* event);
  258. void s14_on_entry();
  259. void s14_on_exit();
  260. unsigned int s14_on_event(FSMEvent* event);
  261. void s20_on_entry();
  262. void s20_on_exit();
  263. unsigned int s20_on_event(FSMEvent* event);
  264. void s21_on_entry();
  265. void s21_on_exit();
  266. unsigned int s21_on_event(FSMEvent* event);
  267. void s22_on_entry();
  268. void s22_on_exit();
  269. unsigned int s22_on_event(FSMEvent* event);
  270. void s23_on_entry();
  271. void s23_on_exit();
  272. unsigned int s23_on_event(FSMEvent* event);
  273. void s24_on_entry();
  274. void s24_on_exit();
  275. unsigned int s24_on_event(FSMEvent* event);
  276. void s3_on_entry();
  277. void s3_on_exit();
  278. unsigned int s3_on_event(FSMEvent* event);
  279. void s4_on_entry();
  280. void s4_on_exit();
  281. unsigned int s4_on_event(FSMEvent* event);
  282. void s50_on_entry();
  283. void s50_on_exit();
  284. unsigned int s50_on_event(FSMEvent* event);
  285. void s51_on_entry();
  286. void s51_on_exit();
  287. unsigned int s51_on_event(FSMEvent* event);
  288. void s52_on_entry();
  289. void s52_on_exit();
  290. unsigned int s52_on_event(FSMEvent* event);
  291. void s53_on_entry();
  292. void s53_on_exit();
  293. unsigned int s53_on_event(FSMEvent* event);
  294. void s60_on_entry();
  295. void s60_on_exit();
  296. unsigned int s60_on_event(FSMEvent* event);
  297. void s61_on_entry();
  298. void s61_on_exit();
  299. unsigned int s61_on_event(FSMEvent* event);
  300. void s62_on_entry();
  301. void s62_on_exit();
  302. unsigned int s62_on_event(FSMEvent* event);
  303. void s63_on_entry();
  304. void s63_on_exit();
  305. unsigned int s63_on_event(FSMEvent* event);
  306. bool m_bHangup;
  307. //sip呼叫失败次数,连续10次SIP呼叫失败触发自检重启SIPPHONE
  308. unsigned int m_nSipErrorNum;
  309. unsigned int m_uConnectTime;
  310. bool m_bConnected;
  311. long m_lConnectCostTime;
  312. bool ReConnectionAssistchan();
  313. bool ReConnectionSipphone(bool bLog = true);
  314. bool ReConnectionSyncService();
  315. int GetCallRouteList();
  316. ErrorCodeEnum StartVideo(const char *param)
  317. {
  318. //DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("Start Video");
  319. if (!m_pPhoneClient)
  320. return Error_NetBroken;
  321. PhoneService_StartVideo_Info Info;
  322. ErrorCodeEnum Error = ParseVideoDesc(param, Info.remote_ip, Info.remote_port,
  323. Info.remote_width, Info.remote_height, Info.remote_fps,
  324. Info.local_view_x, Info.local_view_y, Info.local_view_cx, Info.local_view_cy,
  325. Info.remote_view_x, Info.remote_view_y, Info.remote_view_cx, Info.remote_view_cy);
  326. Info.local_hwd_move = 0;
  327. Info.remote_hwd_move = 1;
  328. //DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("start video, remote width:%d, remote height:%d, local(%d,%d,%d,%d),remote(%d,%d,%d,%d), remote_fps:%d",
  329. // Info.remote_width, Info.remote_height,
  330. // Info.local_view_x, Info.local_view_y, Info.local_view_cx, Info.local_view_cy,
  331. // Info.remote_view_x, Info.remote_view_y, Info.remote_view_cx, Info.remote_view_cy, Info.remote_fps);
  332. if (Error == Error_Succeed) {
  333. Error = (*m_pPhoneClient)(EntityResource::getLink().upgradeLink())->StartVideo(Info);
  334. }
  335. else {
  336. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("parse video desc failed!");
  337. }
  338. return Error;
  339. }
  340. ErrorCodeEnum StopVideo()
  341. {
  342. //DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("Stop Video");
  343. if (!m_pPhoneClient)
  344. return Error_NetBroken;
  345. return (*m_pPhoneClient)(EntityResource::getLink().upgradeLink())->StopVideo();
  346. }
  347. ErrorCodeEnum StartVideoRender(const char* param)
  348. {
  349. //DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("Start Record Video Render, and param is %s.", param);
  350. if (!m_pPhoneClient)
  351. return Error_NetBroken;
  352. PhoneService_StartVideoRender_Info Info;
  353. ErrorCodeEnum Error = ParseVideoRenderDesc(param,
  354. Info.local_view_x, Info.local_view_y, Info.local_view_cx, Info.local_view_cy,
  355. Info.remote_view_x, Info.remote_view_y, Info.remote_view_cx, Info.remote_view_cy);
  356. Info.local_hwd_move = 0;
  357. Info.remote_hwd_move = 1;
  358. //DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("start record video render,local(%d,%d,%d,%d),remote(%d,%d,%d,%d)",
  359. //Info.local_view_x, Info.local_view_y, Info.local_view_cx, Info.local_view_cy,
  360. //Info.remote_view_x, Info.remote_view_y, Info.remote_view_cx, Info.remote_view_cy);
  361. if (Error == Error_Succeed) {
  362. Error = (*m_pPhoneClient)(EntityResource::getLink().upgradeLink())->StartVideoRender(Info);
  363. }
  364. else {
  365. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("parse video desc failed!");
  366. }
  367. return Error;
  368. }
  369. ErrorCodeEnum StopVideoRender()
  370. {
  371. /*DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("Stop Record Video Render");*/
  372. if (!m_pPhoneClient)
  373. return Error_NetBroken;
  374. return (*m_pPhoneClient)(EntityResource::getLink().upgradeLink())->StopVideoRender();
  375. }
  376. ErrorCodeEnum RealSipErrorCheck()
  377. {
  378. //DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("Sip connect Fail 6 times,RealSipErrorCheck!");
  379. if (!m_pPhoneClient)
  380. return Error_NetBroken;
  381. return (*m_pPhoneClient)(EntityResource::getLink().upgradeLink())->RealErrorCheck();
  382. }
  383. ErrorCodeEnum SetCallingType(CallingTypeEnum eType)
  384. {
  385. if (!m_pPhoneClient) {
  386. return Error_NetBroken;
  387. }
  388. PhoneService_SetCallingParam_Info info;
  389. info.CallType = eType;
  390. return (*m_pPhoneClient)(EntityResource::getLink().upgradeLink())->SetCallingParam(info);
  391. }
  392. bool IsCameraRenderState()
  393. {
  394. bool brender = false;
  395. if (!m_pPhoneClient) {
  396. return brender;
  397. }
  398. PhoneService_IsCameraRender_Req req;
  399. PhoneService_IsCameraRender_Ans ans;
  400. if (Error_Succeed == (*m_pPhoneClient)(EntityResource::getLink().upgradeLink())->IsCameraRender(req, ans, 5000)) {
  401. brender = ans.result;
  402. }
  403. return brender;
  404. }
  405. private:
  406. int TranslateState(int innerState);
  407. ErrorCodeEnum SetCallState(int state);
  408. //TODO: CrossPlaform IP 框架具备统一支持,但不清楚影响范围(继而无法评估测试范围),未敢轻易改动 [Gifur@2025729]
  409. ErrorCodeEnum GetLocalIP(char *buff, size_t ulen)
  410. {
  411. #if defined(RVC_OS_WIN)
  412. char tmp[MAX_PATH] = { 0 };
  413. gethostname(tmp, sizeof(tmp));
  414. hostent* ent = gethostbyname(tmp);
  415. if (ent) {
  416. int icount = 0;
  417. for (; ent->h_addr_list[icount]; ) {
  418. ++icount;
  419. }
  420. for (int i = 0; ent->h_addr_list[i]; ++i) {
  421. if (ent->h_addrtype == AF_INET) {
  422. struct in_addr* in = (struct in_addr*)ent->h_addr_list[i];
  423. char* p = inet_ntoa(*in);
  424. if (p[0] != '0') {
  425. if (strstr(p, "198.168.") == NULL && 0 != strncmp(p, "2.0.0.1", strlen("2.0.0.1"))) {
  426. strcpy(buff, p);
  427. return Error_Succeed;
  428. }
  429. }
  430. }
  431. }
  432. }
  433. return Error_Unexpect;
  434. #else
  435. ErrorCodeEnum error = Error_Unexpect;
  436. int sockfd = -1;
  437. struct ifconf ifconf;
  438. struct ifreq* ifreq = NULL;
  439. char strbuf[256] = { 0 };
  440. ifconf.ifc_len = 256;
  441. ifconf.ifc_buf = strbuf;
  442. if ((sockfd = socket(AF_INET, SOCK_DGRAM, 0)) < 0) {
  443. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("socket error");
  444. return error;
  445. }
  446. ioctl(sockfd, SIOCGIFCONF, &ifconf); //get all socket info
  447. ifreq = (struct ifreq*)ifconf.ifc_buf;
  448. for (int i = (ifconf.ifc_len / sizeof(struct ifreq)); i > 0; i--) {
  449. if (ifreq->ifr_flags == AF_INET) { //for ipv4
  450. char* strIP = inet_ntoa(((struct sockaddr_in*)&(ifreq->ifr_addr))->sin_addr);
  451. ifreq++;
  452. if (NULL != strIP) {
  453. if (NULL == strstr(strIP, "198.168.") && NULL == strstr(strIP, "127.0.0.1")) {
  454. strcpy(buff, strIP);
  455. error = Error_Succeed;
  456. break;
  457. }
  458. }
  459. }
  460. }
  461. close(sockfd);
  462. return error;
  463. #endif //RVC_OS_WIN
  464. }
  465. ErrorCodeEnum MakeCall(const char *to_uri, const char *from_uri, const char *call_id, CallingParam callingparam)
  466. {
  467. if (!m_pPhoneClient){
  468. return Error_NetBroken;
  469. }
  470. CSimpleStringA strCode;
  471. PhoneService_MakeCall_Req Req;
  472. PhoneService_MakeCall_Ans Ans;
  473. Req.to_uri = to_uri;
  474. Req.from_uri = from_uri;
  475. Req.call_id = call_id;
  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)(EntityResource::getLink().upgradeLink())->SetCallingParam(info);
  483. ErrorCodeEnum Error = (*m_pPhoneClient)(EntityResource::getLink().upgradeLink())->MakeCall(Req, Ans, 10000);
  484. return Error;
  485. }
  486. ErrorCodeEnum HangupCall()
  487. {
  488. if (!m_pPhoneClient) {
  489. return Error_NetBroken;
  490. }
  491. PhoneService_HangupCall_Req Req;
  492. PhoneService_HangupCall_Ans Ans;
  493. return (*m_pPhoneClient)(EntityResource::getLink().upgradeLink())->HangupCall(Req, Ans, 10000);
  494. }
  495. ErrorCodeEnum ReleaseCall(int type)
  496. {
  497. if (!m_pPhoneClient)
  498. return Error_NetBroken;
  499. PhoneService_ReleaseCall_Req Req;
  500. Req.type = type;
  501. PhoneService_ReleaseCall_Ans Ans;
  502. return (*m_pPhoneClient)(EntityResource::getLink().upgradeLink())->ReleaseCall(Req, Ans, 10000);
  503. }
  504. ErrorCodeEnum StartChannel(int nChanServer)
  505. {
  506. if (!m_pChannelClient) {
  507. return Error_NetBroken;
  508. }
  509. if ((m_strChanProxyIP[nChanServer]=="")&&(m_iChanProxyPort[nChanServer]==0)){
  510. return Error_Param;
  511. }
  512. ChannelService_Connect_Req Req;
  513. ChannelService_Connect_Ans Ans;
  514. Req.ip = m_strChanProxyIP[nChanServer];
  515. Req.port = m_iChanProxyPort[nChanServer];
  516. return m_pChannelClient->Connect(Req, Ans, 10000);
  517. }
  518. ErrorCodeEnum StartChannel(int nChanServer,CallingParam callparam)
  519. {
  520. if (!m_pChannelClient) {
  521. return Error_NetBroken;
  522. }
  523. ChannelService_Connect_Req Req;
  524. ChannelService_Connect_Ans Ans;
  525. if ((m_strChanProxyIP[nChanServer]=="")&&(m_iChanProxyPort[nChanServer]==0)){
  526. return Error_Param;
  527. }
  528. else{
  529. Req.ip = m_strChanProxyIP[nChanServer];
  530. Req.port = m_iChanProxyPort[nChanServer];
  531. return m_pChannelClient->Connect(Req, Ans, 10000);
  532. }
  533. }
  534. ErrorCodeEnum StopChannel()
  535. {
  536. if (!m_pPhoneClient) {
  537. return Error_NetBroken;
  538. }
  539. ChannelService_Close_Req Req;
  540. ChannelService_Close_Ans Ans;
  541. return m_pChannelClient->Close(Req, Ans, 10000);
  542. }
  543. CSimpleStringA MakeCallUri(const char *callnum,const char *serverip,int serverport)
  544. {
  545. return CSimpleStringA::Format("sip:%s@%s:%d;transport=UDP",
  546. callnum, serverip, serverport);
  547. }
  548. ErrorCodeEnum LoadConfig()
  549. {
  550. int iTimeOut = RVC_DEFAULT_HTTPTIMEOUT;
  551. int iPrintDbg = 0;
  552. SpIniMappingTable table;
  553. table.AddEntryString("CounterConnector", "default_voip_server", m_strDefaultServer, NULL);
  554. table.AddEntryString("CounterConnector", "http_call_route_addr", m_strHttpCallRouteAddr, NULL);
  555. table.AddEntryInt("CounterConnector", "http_timeout", iTimeOut, 0);
  556. table.AddEntryInt("CounterConnector", "http_printdbg", iPrintDbg, 0);
  557. CSmartPointer<IConfigInfo> spConfig;
  558. ErrorCodeEnum Error = m_pEntity->GetFunction()->OpenConfig(Config_CenterSetting, spConfig);
  559. if (Error == Error_Succeed) {
  560. Error = table.Load(spConfig);
  561. if (Error_Succeed == Error) {
  562. if (iTimeOut > 0 && iTimeOut < 20 * RVC_DEFAULT_HTTPTIMEOUT) {
  563. m_iHttpTimeOut = iTimeOut;
  564. }
  565. if (iPrintDbg) {
  566. m_bHttpPrinttDbg = true;
  567. }
  568. }
  569. }
  570. return Error;
  571. }
  572. ErrorCodeEnum LoadTerminalId()
  573. {
  574. CSystemStaticInfo Info;
  575. ErrorCodeEnum Error = m_pEntity->GetFunction()->GetSystemStaticInfo(Info);
  576. if (Error == Error_Succeed) {
  577. m_strTerminalId = Info.strTerminalID;
  578. }
  579. return Error;
  580. }
  581. ErrorCodeEnum AllowAgentWrite()
  582. {
  583. if (!m_pChannelClient)
  584. return Error_NetBroken;
  585. ChannelService_Send_Info Info;
  586. Info.compress = false;
  587. Info.encrypt = false;
  588. Info.id = 0;
  589. Info.sub_type = 0;
  590. Info.type = ACM_TYPE_MODE;
  591. return (*m_pChannelClient)(EntityResource::getLink().upgradeLink())->Send(Info);
  592. }
  593. ErrorCodeEnum StartRing()
  594. {
  595. #ifdef _WIN32
  596. bool bRet = ::PlaySoundA(MAKEINTRESOURCEA(IDR_RINGOUT), ModuleBase::GetModuleBase()->GetInstance(), SND_ASYNC|SND_RESOURCE|SND_LOOP);
  597. if (bRet) {
  598. m_bRing = true;
  599. return Error_Succeed;
  600. }
  601. else {
  602. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("play sound failed!%d", GetLastError());
  603. return Error_Unexpect;
  604. }
  605. #else
  606. m_bRing = TRUE;
  607. return Error_Succeed;
  608. #endif
  609. }
  610. void StopRing()
  611. {
  612. #ifdef _WIN32
  613. if (m_bRing) {
  614. bool bRet = false;
  615. int tries = 0;
  616. do {
  617. bRet = ::PlaySoundA(NULL, NULL, SND_ASYNC|SND_LOOP);
  618. } while (bRet == false && (Sleep(100), tries < 3));
  619. m_bRing = false;
  620. }
  621. #else
  622. if (m_bRing) {
  623. m_bRing = false;
  624. }
  625. #endif
  626. }
  627. bool CheckBeginRing(int iSrcState, int iDstState)
  628. {
  629. if (iSrcState == ACMCallFSM::s0 && iDstState == ACMCallFSM::s10)
  630. return true;
  631. return false;
  632. }
  633. bool CheckEndRing(int iSrcState, int iDstState)
  634. {
  635. if (m_bRing) {
  636. if (iSrcState == ACMCallFSM::s10 || iSrcState == ACMCallFSM::s12) {
  637. if (iDstState != ACMCallFSM::s10 && iDstState != ACMCallFSM::s12)
  638. return true;
  639. }
  640. }
  641. return false;
  642. }
  643. int GetDelayTime();
  644. void SetDelayTime();
  645. int ParseDefaultServer(const char* strServer);
  646. int GetFailedErrorCode(int iSrcState);
  647. int LogFailedWarns(int iFailedCode, const char* strmsg);
  648. public:
  649. //话机的物理状态
  650. bool m_bHandFree;
  651. //坐席控制话筒的当前状态
  652. bool m_bAgentHandFree;
  653. //是否处于接通坐席状态
  654. bool m_bIsAgentControl;
  655. //流程拨号,带技能号
  656. CSimpleStringA m_strHintCallNum;
  657. bool m_bAssistchanIdel;
  658. CurServerNum m_nCurSipServer;
  659. CurServerNum m_nCurChanServer;
  660. //呼叫类型,用于区分是分布式呼叫还是常规呼叫,由业务中台设置或者指令模块设置
  661. CallingParam m_CallingParam;
  662. int m_iFailedLastState;
  663. bool m_bConAssist;
  664. bool m_bConSipphone;
  665. CSimpleStringA m_strQueueName;
  666. CSimpleStringA m_strAddClientLevel;
  667. bool m_bNeedQueueName;
  668. private:
  669. unsigned int m_nStarttime;
  670. PhoneService_ClientBase *m_pPhoneClient;
  671. ChannelService_ClientBase *m_pChannelClient;
  672. SyncService_ClientBase*m_pSyncServiceClient;
  673. CSimpleStringA m_strTerminalId;
  674. CSimpleStringA m_strChanProxyIP[2];
  675. int m_iChanProxyPort[2];
  676. //去分行化
  677. node_list_head_t *m_pCallRouteList;
  678. CSimpleStringA m_strDefaultServer;
  679. std::vector<std::string> m_voipserver;
  680. ErrorCodeEnum m_LastSipError;
  681. ErrorCodeEnum m_LastAssistError;
  682. CSimpleStringA m_strHttpCallRouteAddr;
  683. CSimpleStringA m_strHttpServerAPI;
  684. int m_iHttpTimeOut;
  685. bool m_bHttpPrinttDbg;
  686. bool m_bRing;
  687. };