ConnectorFSM.h 32 KB

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