HolderContextFSM.cpp 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599
  1. #include "stdafx.h"
  2. #include "windows.h"
  3. #include "HolderContextFSM.h"
  4. #include "..\EventCode.h"
  5. #define OP_START_ENTITY 1
  6. #define OP_STOP_ENTITY 0
  7. struct callback_entry : public IReleasable
  8. {
  9. virtual ~callback_entry() {}
  10. CSimpleStringA EntityName;
  11. union {
  12. void *pRawData;
  13. int state;
  14. };
  15. int op;
  16. ErrorCodeEnum ErrorResult;
  17. };
  18. namespace StateTask{
  19. //add code by @wb
  20. //定时上报持有者状态
  21. struct ReportStateTask : public ITaskSp
  22. {
  23. HolderContextFSM* fsm;
  24. explicit ReportStateTask(HolderContextFSM* f) : fsm(f) {}
  25. void Process()
  26. {
  27. Dbg("@wb TimerUploadHolderState init");
  28. while(1)
  29. {
  30. Dbg("@wb m_bLogon%d",fsm->m_bLogon);
  31. //持有者从签入到签出时间之内,定期上报一次状态
  32. if (fsm->m_bLogon)
  33. {
  34. Dbg("@wb TimerUploadHolderState m_bLogon");
  35. if (!fsm->UploadHolderState())
  36. {
  37. Dbg("TimerUploadHolderState failed!");
  38. //将业务层状态置为N,避免分行断开服务时,无效呼入
  39. /*
  40. Sleep(FIX_SETSTATE_TIMER);
  41. EnterCriticalSection(&fsm->cs);
  42. Dbg("Set HolderState to N state!");
  43. fsm->SetHolderState("N");
  44. LeaveCriticalSection(&fsm->cs);
  45. Sleep(FIX_SETSTATE_TIMER);
  46. */
  47. Sleep(FIX_SETSTATE_TIMER_1);
  48. EnterCriticalSection(&fsm->cs);
  49. Dbg("Set HolderState to N State!");
  50. fsm->SetHolderState("N");
  51. LeaveCriticalSection(&fsm->cs);
  52. Sleep(FIX_SETSTATE_TIMER_1);
  53. }
  54. }
  55. Dbg("@wb TimerUploadHolderState Sleep");
  56. //定时时间
  57. Sleep(FIX_UPLOAD_TIMER);
  58. }
  59. }
  60. };
  61. struct HandlePackageTask : public ITaskSp
  62. {
  63. HolderContextFSM* fsm;
  64. explicit HandlePackageTask(HolderContextFSM* f) : fsm(f) {}
  65. //依据reqStateVec中未确认包个数和时戳来实现重传与确认机制
  66. void Process()
  67. {
  68. Dbg("@wb enter before Thread for retransmit");
  69. while(1)
  70. {
  71. if (fsm->m_bLogon)
  72. {
  73. // 记录当前时间
  74. long indexNow;
  75. //记录标识
  76. int countID = 1;
  77. // 统计个数判断是否需要断开连接后重连
  78. EnterCriticalSection(&fsm->cs);
  79. Dbg("@wb indentified values for retransmit");
  80. //针对分行
  81. int count = fsm->reqStateVec.size();
  82. Dbg("count %d", count);
  83. //针对总行
  84. int countN = fsm->hdStateReqVec.size();
  85. Dbg("countN %d", countN);
  86. //针对recvState
  87. int countRecSta = fsm->recvState.size();
  88. //超出 最大个数进行清空list,关闭与分行连接,重新连接的操作
  89. if(count > PACKAGE_MAX_NUM)
  90. {
  91. Dbg("@wb Disconnect for retransmit");
  92. fsm->Disconnect();
  93. //执行清空操作
  94. fsm->reqStateVec.clear();
  95. //将业务层状态置为N,避免分行断开服务时,无效呼入
  96. Dbg("Set HolderState to N state!");
  97. EnterCriticalSection(&fsm->cs);
  98. fsm->SetHolderState("N");
  99. LeaveCriticalSection(&fsm->cs);
  100. Dbg("@wb Reconnect for retransmit");
  101. fsm->Reconnect();
  102. LeaveCriticalSection(&fsm->cs);
  103. }
  104. else
  105. {
  106. //遍历进行超时重传
  107. int m_size = fsm->reqStateVec.size();
  108. Dbg("m_size %d", m_size);
  109. for (int i = 0; i < m_size; i ++)
  110. {
  111. Dbg("@wb GetTickCount for retransmit");
  112. indexNow = GetTickCount(); //获取当前时间
  113. Dbg("indexNow %d", indexNow);
  114. long timeRecord = 0; //存储状态上报包中的时间
  115. Dbg("fsm->reqStateVec[i].dwNow %s",fsm->reqStateVec[i].dwNow);
  116. sscanf(fsm->reqStateVec[i].dwNow, "%d", &timeRecord );
  117. Dbg("timeRecord %d", timeRecord);
  118. //出现超时进行重传,生成新的SerialID和当前时间
  119. if((indexNow - timeRecord) > FIX_DWTICK_TIMER)
  120. {
  121. countID ++;
  122. Dbg("countID%d", countID);
  123. sprintf(fsm->reqStateVec[i].SerialID, "%d", countID);
  124. char time[16] = {0};
  125. ltoa(indexNow, time, 10);
  126. memcpy(fsm->reqStateVec[i].dwNow, time, strlen(time));
  127. Dbg("@wb retransmit req success!");
  128. if(!fsm->ReTransmissReq(fsm->reqStateVec[i]))
  129. {
  130. Dbg("retransmit req not success!");
  131. }
  132. else
  133. Dbg("retransmit req success!");
  134. }
  135. }
  136. }
  137. if(countN >= PACKAGE_MAX_NUM)
  138. {
  139. //将业务层状态置为N,避免总行断开服务时,无效呼入
  140. Dbg("Set HolderState to N state!");
  141. EnterCriticalSection(&fsm->cs);
  142. fsm->SetHolderState("N");
  143. LeaveCriticalSection(&fsm->cs);
  144. Dbg("Clear all the hdStateReqVec element!");
  145. fsm->hdStateReqVec.clear();
  146. }
  147. if(countRecSta >= RECV_MAX_NUM)
  148. {
  149. fsm->recvState.clear();
  150. }
  151. LeaveCriticalSection(&fsm->cs);
  152. }
  153. Dbg("@wb Sleep retransmit!");
  154. Sleep(FIX_CHECK_LIST_TIMER);
  155. }
  156. }
  157. };
  158. }
  159. using namespace StateTask;
  160. class HolderContextFSM;
  161. HolderContextFSM::HolderContextFSM():m_pConnection(NULL)
  162. {
  163. m_HolderState.State = "N";//默认持有者状态,N
  164. m_pConnectService = NULL;
  165. m_bLogon = FALSE;
  166. m_nErrcode = Error_Succeed;
  167. m_strErrmsg = "";
  168. m_bHolderBusy = FALSE;
  169. m_bMenu = TRUE;
  170. m_CurCallState = "O";
  171. m_bIncomeHangup = FALSE;
  172. memset(m_cTaskData, 0, 1024);
  173. memset(m_cHolderSkill, 0, 128);
  174. }
  175. HolderContextFSM::~HolderContextFSM()
  176. {
  177. }
  178. void HolderContextFSM::OnStateTrans( int iSrcState, int iDstState )
  179. {
  180. Dbg("trans from %s to %s", GetStateName(iSrcState), GetStateName(iDstState));
  181. }
  182. void HolderContextFSM::OnSysVarEvent( const char *pszKey, const char *pszValue,const char *pszOldValue,const char *pszEntityName )
  183. {
  184. }
  185. ErrorCodeEnum HolderContextFSM::OnInit()
  186. {
  187. ErrorCodeEnum Error;
  188. Error = LoadRootConfig();
  189. if (Error != Error_Succeed)
  190. {
  191. LOG_TRACE("load root.ini config failed!");
  192. return Error;
  193. }
  194. Dbg("LoadRootConfig ok, m_strMachineType[%s],m_strSite[%s]",m_strMachineType.GetData(),m_strSite.GetData());
  195. if (Error == Error_Succeed)
  196. {
  197. AddStateHooker(this);
  198. }
  199. //add广播界面退出通知消息eMsg
  200. Connecting e;
  201. SpSendBroadcast(m_pEntity->GetFunction(), eMsg_exitRecordUI , eMsgSig_exitRecordUI , e);
  202. Dbg("SpSendBroadcast eMsgexitRecordUI");
  203. InitializeCriticalSection(&cs);
  204. //获取终端号
  205. CSystemStaticInfo si;
  206. m_pEntity->GetFunction()->GetSystemStaticInfo(si);
  207. m_strTerminalNo = si.strTerminalID;
  208. Dbg("Get TerminalId[%s] from root.ini",m_strTerminalNo);
  209. m_HolderState.TerminalNo = m_strTerminalNo;
  210. //初始化分行、总行状态发送记录vector
  211. reqStateVec.reserve(1000);
  212. hdStateReqVec.reserve(1000);
  213. StateAnsNum.reserve(10);
  214. recvState.reserve(1000);
  215. recvState.push_back('S');
  216. //add code by @wb
  217. //创建定时上报状态线程
  218. ReportStateTask* pReportTask = new ReportStateTask(this);
  219. GetEntityBase()->GetFunction()->PostThreadPoolTask(pReportTask);
  220. Dbg("task1 created");
  221. //add code by @wb
  222. //创建处理状态上报确认线程
  223. HandlePackageTask* pHandleTask = new HandlePackageTask(this);
  224. GetEntityBase()->GetFunction()->PostThreadPoolTask(pHandleTask);
  225. Dbg("task2 created");
  226. //......
  227. return Error;
  228. }
  229. ErrorCodeEnum HolderContextFSM::OnExit()
  230. {
  231. DeleteCriticalSection(&cs);
  232. return Error_Succeed;
  233. }
  234. /*
  235. 状态上报规则
  236. 1.None、Identified、NotHeld为客户不在现场,用户不在现场的状态无需更新用户状态
  237. 2.
  238. */
  239. void HolderContextFSM::s0_on_entry()
  240. {
  241. Dbg("enter s0[None]!");
  242. m_HolderState.State = "N";
  243. //Sleep(15000);
  244. //非Pad,不需要上报状态
  245. if (0 != strcmp(m_strMachineType.GetData(), MACHINETYPE_PAD))
  246. {
  247. Dbg("非Pad,无需状态上报!");
  248. return;
  249. }
  250. ////开始获取用户状态
  251. //BOOL bRet = GetHolderState();
  252. //if (!bRet)
  253. //{
  254. //}
  255. //Dbg("when s0_on_entry, start get hodler state!");
  256. //Test
  257. //if (1)
  258. //{
  259. // m_HolderState.HolderID = "074168";
  260. // //m_HolderState.State = "S";
  261. // //UploadHolderState();
  262. // //Test,进入Standby状态
  263. // //PostEventLIFO(new FSMEvent(USER_EVT_JMP_STANDBY));
  264. //}
  265. //Test
  266. /*m_HolderState.HolderID = "00210706";
  267. QueryHolderSkill();*/
  268. ScheduleTimer(1, 1000);
  269. }
  270. void HolderContextFSM::s0_on_exit()
  271. {
  272. CancelTimer(1);
  273. }
  274. unsigned int HolderContextFSM::s0_on_event( FSMEvent* event )
  275. {
  276. Connecting e;
  277. switch (event->iEvt)
  278. {
  279. case EVT_TIMER:
  280. ScheduleTimer(1, 1000); //没有收到状态循环等待
  281. break;
  282. case USER_EVT_JMP_IDENTIFIED:
  283. //进入S1:Identified状态
  284. Dbg("s0_on_event, recieve USER_EVT_JMP_IDENTIFIED, go to S1!");
  285. break;
  286. case USER_EVT_JMP_STANDBY:
  287. //进入S3:Standby状态
  288. Dbg("s0_on_event, recieve USER_EVT_JMP_STANDBY, go to S3!");
  289. //add广播 eMsg_OnlineStandBy为S的消息
  290. SpSendBroadcast(m_pEntity->GetFunction(), eMsg_OnlineStandBy, eMsgSig_OnlineStandBy, e);
  291. Dbg("SpSendBroadcast eMsg_OnlineStandBy");
  292. break;
  293. case USER_EVT_JMP_BUSY:
  294. //进入S5:Busy状态
  295. Dbg("s0_on_event, recieve USER_EVT_JMP_BUSY, go to S5!");
  296. //add广播Busy消息
  297. SpSendBroadcast(m_pEntity->GetFunction(), eMsg_OnlineBusy, eMsgSig_OnlineBusy, e);
  298. Dbg("SpSendBroadcast eMsg_OnlineBusy");
  299. break;
  300. default:
  301. Dbg("s0_on_event, recieve no defined event,[%d], continue wait!",event->iEvt);
  302. ScheduleTimer(1, 1000);
  303. break;
  304. }
  305. return 0;
  306. }
  307. //open console
  308. void HolderContextFSM::s1_on_entry()
  309. {
  310. //Identified,暂时不需要此状态
  311. m_HolderState.State = "I";
  312. Dbg("enter s1[Identified]");
  313. ScheduleTimer(2, 1000);
  314. }
  315. void HolderContextFSM::s1_on_exit()
  316. {
  317. CancelTimer(2);
  318. }
  319. unsigned int HolderContextFSM::s1_on_event(FSMEvent* event)
  320. {
  321. if (event->iEvt == EVT_TIMER)
  322. {
  323. Dbg("s1_on_event, recieve timer, goto s0");
  324. }
  325. return 0;
  326. }
  327. void HolderContextFSM::s2_on_entry()
  328. {
  329. //Unservice状态,暂时不需要此状态
  330. Dbg("enter s2[Unservice]");
  331. m_HolderState.State = "U";
  332. if (!UploadHolderState())
  333. {
  334. Dbg("UploadHolderState s2 failed!");
  335. }
  336. ScheduleTimer(3, 1000);
  337. }
  338. void HolderContextFSM::s2_on_exit()
  339. {
  340. CancelTimer(3);
  341. }
  342. unsigned int HolderContextFSM::s2_on_event(FSMEvent* event)
  343. {
  344. if (event->iEvt == EVT_TIMER)
  345. {
  346. Dbg("s2_on_event, recieve timer, goto s0");
  347. }
  348. return 0;
  349. }
  350. void HolderContextFSM::s3_on_entry()
  351. {
  352. Dbg("enter s3[Standby]");
  353. //每次登录都重新下载任务, TODO:下载后怎么发起通话请求?
  354. //连线任务无需主动下载,其它任务待定
  355. /*BOOL bRet = GetConnectTaskFromInstrationServer();
  356. if (!bRet)
  357. {
  358. Dbg("从分行获取任务失败");
  359. }*/
  360. m_HolderState.State = "S";
  361. if (!UploadHolderState())
  362. {
  363. Dbg("UploadHolderState s3 failed!");
  364. }
  365. }
  366. void HolderContextFSM::s3_on_exit()
  367. {
  368. CancelTimer(4);
  369. }
  370. unsigned int HolderContextFSM::s3_on_event(FSMEvent* event)
  371. {
  372. Connecting e;
  373. switch (event->iEvt)
  374. {
  375. case EVT_TIMER:
  376. //TODO:什么场景触发?又业务界面通知?
  377. Dbg("s3_on_event, recieve timer, go to S0!");
  378. break;
  379. case USER_EVT_JMP_NOTHELD:
  380. //进入S4:NotHeld状态
  381. Dbg("s3_on_event, recieve USER_EVT_JMP_IDENTIFIED, go to S4!");
  382. break;
  383. case USER_EVT_JMP_BUSY:
  384. //进入S5:Busy状态
  385. Dbg("s3_on_event, recieve USER_EVT_JMP_BUSY, go to S5!");
  386. //add广播Busy消息
  387. SpSendBroadcast(m_pEntity->GetFunction(), eMsg_OnlineBusy, eMsgSig_OnlineBusy, e);
  388. Dbg("SpSendBroadcast eMsg_OnlineBusy");
  389. break;
  390. case USER_EVT_JMP_LOCAL:
  391. //进入S6:Local状态
  392. Dbg("s3_on_event, recieve USER_EVT_JMP_LOCAL, go to S6!");
  393. break;
  394. case USER_EVT_JMP_RINGING:
  395. //进入S8:Ringing状态
  396. Dbg("s3_on_event, recieve USER_EVT_JMP_RINGING, go to S8!");
  397. break;
  398. case USER_EVT_JMP_DISCONNECT:
  399. //进入S12:Disconnect状态
  400. Dbg("s3_on_event, recieve USER_EVT_JMP_DISCONNECT, go to S12!");
  401. break;
  402. case USER_EVT_JMP_NONE:
  403. //进入0:None状态
  404. Dbg("s3_on_event, recieve USER_EVT_JMP_NONE, go to S0!");
  405. //add广播 eMsg_Offline消息
  406. SpSendBroadcast(m_pEntity->GetFunction(), eMsg_Offline, eMsgSig_Offline, e);
  407. Dbg("SpSendBroadcast eMsg_Offline");
  408. break;
  409. default:
  410. Dbg("s3_on_event, recieve no defined event,[%d], continue wait!",event->iEvt);
  411. //ScheduleTimer(1, 1000);
  412. break;
  413. }
  414. return 0;
  415. }
  416. void HolderContextFSM::s4_on_entry()
  417. {
  418. Dbg("enter s4[NotHeld]");
  419. //m_HolderState.State = "B";//对应什么状态值?
  420. if (!UploadHolderState())
  421. {
  422. Dbg("UploadHolderState s4 failed!");
  423. }
  424. }
  425. void HolderContextFSM::s4_on_exit()
  426. {
  427. CancelTimer(5);
  428. }
  429. unsigned int HolderContextFSM::s4_on_event(FSMEvent* event)
  430. {
  431. if (event->iEvt == EVT_TIMER)
  432. {
  433. Dbg("Verify cert err");
  434. }
  435. return 0;
  436. }
  437. void HolderContextFSM::s5_on_entry()
  438. {
  439. Dbg("enter s5[Busy]");
  440. m_HolderState.State = "B";
  441. if (!UploadHolderState())
  442. {
  443. Dbg("UploadHolderState s5 failed!");
  444. }
  445. }
  446. void HolderContextFSM::s5_on_exit()
  447. {
  448. }
  449. unsigned int HolderContextFSM::s5_on_event(FSMEvent* event)
  450. {
  451. Connecting e;
  452. switch (event->iEvt)
  453. {
  454. case EVT_TIMER:
  455. //TODO:什么场景触发?又业务界面通知?
  456. Dbg("s5_on_event, recieve timer, go to S0!");
  457. break;
  458. //add by zl 2017.12.08
  459. case USER_EVT_JMP_NONE:
  460. Dbg("s5_on_event, recieve USER_EVT_JMP_NONE, go to S0!");
  461. //add广播 eMsg_Offline消息
  462. SpSendBroadcast(m_pEntity->GetFunction(), eMsg_Offline, eMsgSig_Offline, e);
  463. Dbg("SpSendBroadcast eMsg_Offline");
  464. break;
  465. case USER_EVT_JMP_STANDBY:
  466. //进入S3:Standby状态
  467. Dbg("s5_on_event, recieve USER_EVT_JMP_STANDBY, go to S3!");
  468. //add广播 eMsg_OnlineStandBy为S的消息
  469. SpSendBroadcast(m_pEntity->GetFunction(), eMsg_OnlineStandBy, eMsgSig_OnlineStandBy, e);
  470. Dbg("SpSendBroadcast eMsg_OnlineStandBy");
  471. break;
  472. default:
  473. Dbg("s5_on_event, recieve no defined event,[%d], continue wait!",event->iEvt);
  474. //ScheduleTimer(1, 1000);
  475. break;
  476. }
  477. return 0;
  478. }
  479. void HolderContextFSM::s6_on_entry()
  480. {
  481. Dbg("enter s6[Local]");
  482. m_HolderState.State = "L";
  483. if (!UploadHolderState())
  484. {
  485. Dbg("UploadHolderState s6 failed!");
  486. }
  487. }
  488. void HolderContextFSM::s6_on_exit()
  489. {
  490. //CancelTimer(1);
  491. }
  492. unsigned int HolderContextFSM::s6_on_event(FSMEvent* event)
  493. {
  494. Dbg("s6_on_event");
  495. return 0;
  496. }
  497. void HolderContextFSM::s7_on_entry()
  498. {
  499. Dbg("enter s7[Working]");
  500. m_HolderState.State = "W";
  501. if (!UploadHolderState())
  502. {
  503. Dbg("UploadHolderState s7 failed!");
  504. }
  505. }
  506. void HolderContextFSM::s7_on_exit()
  507. {
  508. //CancelTimer(1);
  509. }
  510. unsigned int HolderContextFSM::s7_on_event(FSMEvent* event)
  511. {
  512. Dbg("s7_on_event");
  513. return 0;
  514. }
  515. void HolderContextFSM::s8_on_entry()
  516. {
  517. Dbg("enter s8[Ringing]");
  518. m_HolderState.State = "R";
  519. if (!UploadHolderState())
  520. {
  521. Dbg("UploadHolderState s8 failed!");
  522. }
  523. //给业务层广播振铃消息
  524. Connecting e;
  525. SpSendBroadcast(m_pEntity->GetFunction(), eMsg_Ringing, eMsgSig_Ringing, e);
  526. Dbg("SpSendBroadcast eMsg_Ringing");
  527. }
  528. void HolderContextFSM::s8_on_exit()
  529. {
  530. //CancelTimer(1);
  531. }
  532. unsigned int HolderContextFSM::s8_on_event(FSMEvent* event)
  533. {
  534. switch (event->iEvt)
  535. {
  536. case EVT_TIMER:
  537. //TODO:什么场景触发?又业务界面通知?
  538. Dbg("s8_on_event, recieve timer, go to S0!");
  539. break;
  540. case USER_EVT_JMP_STANDBY:
  541. //进入S3:Standby状态
  542. Dbg("s8_on_event, recieve USER_EVT_JMP_STANDBY, go to S3!");
  543. break;
  544. case USER_EVT_JMP_BUSY:
  545. //进入S5:Busy状态
  546. Dbg("s8_on_event, recieve USER_EVT_JMP_BUSY, go to S5!");
  547. break;
  548. case USER_EVT_JMP_ONLINE:
  549. //进入S9:Online状态
  550. Dbg("s8_on_event, recieve USER_EVT_JMP_ONLINE, go to S9!");
  551. break;
  552. case USER_EVT_JMP_DEALING:
  553. //进入S10:Dealing状态
  554. Dbg("s8_on_event, recieve USER_EVT_JMP_DEALING, go to S10!");
  555. break;
  556. default:
  557. Dbg("s8_on_event, recieve no defined event, continue wait!");
  558. //ScheduleTimer(1, 1000);
  559. break;
  560. }
  561. return 0;
  562. }
  563. void HolderContextFSM::s9_on_entry()
  564. {
  565. Dbg("enter s9[Online]");
  566. //m_HolderState.State = "B";//对应什么状态值?
  567. if (!UploadHolderState())
  568. {
  569. Dbg("UploadHolderState s9 failed!");
  570. }
  571. }
  572. void HolderContextFSM::s9_on_exit()
  573. {
  574. //CancelTimer(1);
  575. }
  576. unsigned int HolderContextFSM::s9_on_event(FSMEvent* event)
  577. {
  578. switch (event->iEvt)
  579. {
  580. case EVT_TIMER:
  581. //TODO:什么场景触发?又业务界面通知?
  582. Dbg("s9_on_event, recieve timer, go to S0!");
  583. break;
  584. case USER_EVT_JMP_DEALING:
  585. //进入S10:Dealing状态
  586. Dbg("s9_on_event, recieve USER_EVT_JMP_DEALING, go to S10!");
  587. break;
  588. case USER_EVT_JMP_EDIT:
  589. //进入S11:Edit状态
  590. Dbg("s9_on_event, recieve USER_EVT_JMP_EDIT, go to S11!");
  591. break;
  592. default:
  593. Dbg("s9_on_event, recieve no defined event, continue wait!");
  594. //ScheduleTimer(1, 1000);
  595. break;
  596. }
  597. return 0;
  598. }
  599. void HolderContextFSM::s10_on_entry()
  600. {
  601. Dbg("enter s10[Dealing]");
  602. m_HolderState.State = "D";
  603. if (!UploadHolderState())
  604. {
  605. Dbg("UploadHolderState s10 failed!");
  606. }
  607. }
  608. void HolderContextFSM::s10_on_exit()
  609. {
  610. //CancelTimer(1);
  611. }
  612. unsigned int HolderContextFSM::s10_on_event(FSMEvent* event)
  613. {
  614. switch (event->iEvt)
  615. {
  616. case EVT_TIMER:
  617. //TODO:什么场景触发?又业务界面通知?
  618. Dbg("s10_on_event, recieve timer, go to S0!");
  619. break;
  620. case USER_EVT_JMP_EDIT:
  621. //进入S11:Edit状态
  622. Dbg("s10_on_event, recieve USER_EVT_JMP_EDIT, go to S11!");
  623. break;
  624. default:
  625. Dbg("s10_on_event, recieve no defined event, continue wait!");
  626. //ScheduleTimer(1, 1000);
  627. break;
  628. }
  629. return 0;
  630. }
  631. void HolderContextFSM::s11_on_entry()
  632. {
  633. Dbg("enter s11[Edit]");
  634. m_HolderState.State = "E";
  635. if (!UploadHolderState())
  636. {
  637. Dbg("UploadHolderState s11 failed!");
  638. }
  639. }
  640. void HolderContextFSM::s11_on_exit()
  641. {
  642. //CancelTimer(1);
  643. }
  644. unsigned int HolderContextFSM::s11_on_event(FSMEvent* event)
  645. {
  646. switch (event->iEvt)
  647. {
  648. case EVT_TIMER:
  649. //TODO:什么场景触发?又业务界面通知?
  650. Dbg("s11_on_event, recieve timer, go to S0!");
  651. break;
  652. case USER_EVT_JMP_EDITEND:
  653. //进入S11:Edit状态
  654. Dbg("s11_on_event, recieve USER_EVT_JMP_EDITEND, go to S11!");
  655. break;
  656. default:
  657. Dbg("s11_on_event, recieve no defined event, continue wait!");
  658. //ScheduleTimer(1, 1000);
  659. break;
  660. }
  661. return 0;
  662. }
  663. void HolderContextFSM::s12_on_entry()
  664. {
  665. Dbg("enter s12[Disconnect]");
  666. m_HolderState.State = "D";
  667. if (!UploadHolderState())
  668. {
  669. Dbg("UploadHolderState s12 failed!");
  670. }
  671. }
  672. void HolderContextFSM::s12_on_exit()
  673. {
  674. //CancelTimer(1);
  675. }
  676. unsigned int HolderContextFSM::s12_on_event(FSMEvent* event)
  677. {
  678. switch (event->iEvt)
  679. {
  680. case EVT_TIMER:
  681. //TODO:什么场景触发?又业务界面通知?
  682. Dbg("s12_on_event, recieve timer, go to S0!");
  683. break;
  684. case USER_EVT_JMP_EDITEND:
  685. //进入S3:Standby状态
  686. Dbg("s12_on_event, recieve USER_EVT_JMP_STANDBY, go to S11!");
  687. break;
  688. default:
  689. Dbg("s12_on_event, recieve no defined event, continue wait!");
  690. //ScheduleTimer(1, 1000);
  691. break;
  692. }
  693. return 0;
  694. }
  695. ErrorCodeEnum HolderContextFSM::LoadCenterConfig()
  696. {
  697. CSmartPointer<IEntityFunction> spFunction = m_pEntity->GetFunction();
  698. CSmartPointer<IConfigInfo> spConfig;
  699. ErrorCodeEnum Error = spFunction->OpenConfig(Config_CenterSetting, spConfig);
  700. if (Error_Succeed == Error)
  701. {
  702. /*Error = spConfig->ReadConfigValueInt("MaintainWatcher", "CheckTerMinalNo", m_nCheckTerminalNo);
  703. if (Error_Succeed == Error)
  704. {
  705. Dbg("get CheckTerMinalNo=%d from CenterSetting.ini", m_nCheckTerminalNo);
  706. }
  707. else
  708. {
  709. Dbg("get CheckTerMinalNo from CenterSetting.ini failed");
  710. }
  711. Error = spConfig->ReadConfigValueInt("MaintainWatcher", "CheckMaintainTask", m_nCheckMaintainTask);
  712. if (Error_Succeed == Error)
  713. {
  714. Dbg("get CheckMaintainTask=%d from CenterSetting.ini", m_nCheckMaintainTask);
  715. }
  716. else
  717. {
  718. Dbg("get CheckMaintainTask from CenterSetting.ini failed");
  719. }
  720. Error = spConfig->ReadConfigValueInt("MaintainWatcher", "Verify_BlackList", m_nVerifyBlackList);
  721. if (Error_Succeed == Error)
  722. {
  723. Dbg("get Verify_BlackList=%d from CenterSetting.ini", m_nVerifyBlackList);
  724. }
  725. else
  726. {
  727. Dbg("get Verify_BlackList from CenterSetting.ini failed");
  728. }*/
  729. }
  730. return Error;
  731. }
  732. ErrorCodeEnum HolderContextFSM::LoadRootConfig()
  733. {
  734. CSmartPointer<IEntityFunction> spFunction = m_pEntity->GetFunction();
  735. CSmartPointer<IConfigInfo> spConfig;
  736. ErrorCodeEnum Error = spFunction->OpenConfig(Config_Root, spConfig);
  737. if (Error == Error_Succeed)
  738. {
  739. Error = spConfig->ReadConfigValue("Terminal", "MachineType", m_strMachineType);
  740. if(Error == Error_Succeed)
  741. {
  742. Error = spConfig->ReadConfigValue("Terminal", "Site", m_strSite);
  743. if (Error != Error_Succeed)
  744. {
  745. Dbg("ReadConfigValue, get Site value failed");
  746. }
  747. }
  748. else
  749. {
  750. Dbg("ReadConfigValue, get MachineType value failed");
  751. }
  752. }
  753. return Error;
  754. }
  755. //add code by @wb
  756. //上报持有者状态
  757. BOOL HolderContextFSM::UploadHolderState()
  758. {
  759. EnterCriticalSection(&cs);
  760. if (!m_pConnection)
  761. {
  762. m_pConnection = new instructionsServerConnection(m_pEntity, this);
  763. if (m_pConnection)
  764. {
  765. if (!m_pConnection->ConnectFromCentralSetting())
  766. {
  767. Dbg("connect instructions server fail,config or Servers Error!");
  768. m_pConnection->handleDisconnect();
  769. m_pConnection = NULL;
  770. LeaveCriticalSection(&cs);
  771. return FALSE;
  772. }
  773. }
  774. else
  775. {
  776. Dbg("UploadHolderState new instructionsServerConnection failed!");
  777. LeaveCriticalSection(&cs);
  778. return FALSE;
  779. }
  780. }
  781. if (m_pConnection->IsConnectionOK())
  782. {
  783. m_pConnection->SendHolderStateReq();
  784. }
  785. else
  786. {
  787. //连接失败,关闭链接重连
  788. if (NULL != m_pConnection)
  789. {
  790. m_pConnection->handleDisconnect();
  791. m_pConnection = NULL;
  792. Dbg("Close m_pConnection");
  793. }
  794. Dbg("connect to instructions server failed, can not update holder state!");
  795. LeaveCriticalSection(&cs);
  796. return FALSE;
  797. }
  798. LeaveCriticalSection(&cs);
  799. return TRUE;
  800. }
  801. //add code by @wb
  802. //重传持有者状态确认包
  803. BOOL HolderContextFSM::ReTransmissReq(HolderStateReqEx req)
  804. {
  805. EnterCriticalSection(&cs);
  806. if (!m_pConnection)
  807. {
  808. m_pConnection = new instructionsServerConnection(m_pEntity, this);
  809. if (m_pConnection)
  810. {
  811. if (!m_pConnection->ConnectFromCentralSetting())
  812. {
  813. Dbg("connect instructions server fail,config or Servers Error!");
  814. m_pConnection->handleDisconnect();
  815. m_pConnection = NULL;
  816. LeaveCriticalSection(&cs);
  817. return FALSE;
  818. }
  819. }
  820. else
  821. {
  822. Dbg("UploadHolderState new instructionsServerConnection failed!");
  823. LeaveCriticalSection(&cs);
  824. return FALSE;
  825. }
  826. }
  827. if (m_pConnection->IsConnectionOK())
  828. {
  829. m_pConnection->reSendHdStateReq(req);
  830. }
  831. else
  832. {
  833. //连接失败,关闭链接重连
  834. if (NULL != m_pConnection)
  835. {
  836. m_pConnection->handleDisconnect();
  837. m_pConnection = NULL;
  838. Dbg("Close m_pConnection");
  839. }
  840. Dbg("connect to instructions server failed, can not reSend holder state!");
  841. LeaveCriticalSection(&cs);
  842. return FALSE;
  843. }
  844. LeaveCriticalSection(&cs);
  845. return TRUE;
  846. }
  847. //add code by @wb
  848. //断开与分行服务连接
  849. void HolderContextFSM::Disconnect()
  850. {
  851. EnterCriticalSection(&cs);
  852. if (m_pConnection != NULL)
  853. {
  854. m_pConnection->handleDisconnect();
  855. m_pConnection = NULL;
  856. Dbg("Close m_pConnection");
  857. }
  858. LeaveCriticalSection(&cs);
  859. }
  860. //add code by @wb
  861. //重新与分行服务进行连接
  862. void HolderContextFSM::Reconnect()
  863. {
  864. EnterCriticalSection(&cs);
  865. if (!m_pConnection)
  866. {
  867. m_pConnection = new instructionsServerConnection(m_pEntity, this);
  868. if (m_pConnection)
  869. {
  870. if (!m_pConnection->ConnectFromCentralSetting())
  871. {
  872. Dbg("connect instructions server fail,config or Servers Error!");
  873. m_pConnection->handleDisconnect();
  874. m_pConnection = NULL;
  875. LeaveCriticalSection(&cs);
  876. }
  877. else
  878. {
  879. Dbg("connect instructions server success!");
  880. }
  881. }
  882. else
  883. {
  884. Dbg("UploadHolderState new instructionsServerConnection failed!");
  885. LeaveCriticalSection(&cs);
  886. }
  887. }
  888. if(m_pConnection->IsConnectionOK())
  889. Dbg("Reconnect is success!");
  890. else
  891. {
  892. //连接失败,关闭链接重连
  893. if (NULL != m_pConnection)
  894. {
  895. m_pConnection->handleDisconnect();
  896. m_pConnection = NULL;
  897. Dbg("Close m_pConnection");
  898. }
  899. LeaveCriticalSection(&cs);
  900. }
  901. LeaveCriticalSection(&cs);
  902. }
  903. //发送连线请求
  904. BOOL HolderContextFSM::SendConnectTask()
  905. {
  906. //调用陈晃提供的实体接口发起请求
  907. ErrorCodeEnum eErr = Error_Succeed;
  908. ConnectService_StartCallExternal_Ans ans;
  909. ConnectService_StartCallExternal_Req req;
  910. req.CommandParam.Alloc(1024);
  911. memcpy(req.CommandParam.m_pData,m_cTaskData,1024);
  912. if (m_pConnectService == NULL)
  913. {
  914. m_pConnectService = new ConnectService_ClientBase(this->GetEntityBase());
  915. eErr = m_pConnectService->Connect();
  916. if (Error_Succeed != eErr)
  917. {
  918. Dbg("counter connector connected failed.");
  919. m_pConnectService = NULL;
  920. return FALSE;
  921. }
  922. else
  923. {
  924. Dbg("counter connector connected succeed.");
  925. }
  926. }
  927. //TODO:根据错误原因是否来决定是否重试,失败原因要及时通知总行
  928. eErr = m_pConnectService->StartCallExternal(req, ans,10000);
  929. if (Error_Succeed != eErr)
  930. {
  931. Dbg("StartCallExternal failed.");
  932. m_pConnectService = NULL;
  933. return FALSE;
  934. }
  935. else
  936. {
  937. Dbg("StartCallExternal succeed");
  938. }
  939. req.CommandParam.Clear();
  940. return TRUE;
  941. }
  942. BOOL HolderContextFSM::HangupTask()
  943. {
  944. //TODO:调用陈晃提供的实体接口发起请求
  945. ErrorCodeEnum eErr = Error_Succeed;
  946. ConnectService_StopCall_Ans ans;
  947. ConnectService_StopCall_Req req;
  948. req.SessionParam.Alloc(1024);
  949. memcpy(req.SessionParam.m_pData,m_cTaskData,1024);
  950. //TODO:根据错误原因是否来决定是否重试,失败原因要及时通知总行
  951. if (m_pConnectService == NULL)
  952. {
  953. m_pConnectService = new ConnectService_ClientBase(this->GetEntityBase());
  954. eErr = m_pConnectService->Connect();
  955. if (Error_Succeed != eErr) {
  956. Dbg("counter connector connected failed.");
  957. m_pConnectService = NULL;
  958. return FALSE;
  959. }
  960. else{
  961. Dbg("counter connector connected succeed!");
  962. }
  963. }
  964. eErr = m_pConnectService->StopCall(req, ans,10000);
  965. if (Error_Succeed != eErr)
  966. {
  967. Dbg("StopCall failed.");
  968. m_pConnectService = NULL;
  969. return FALSE;
  970. }
  971. else
  972. {
  973. Dbg("StopCall succeed!");
  974. }
  975. req.SessionParam.Clear();
  976. return TRUE;
  977. }
  978. //查询持有人技能
  979. DWORD HolderContextFSM::QueryHolderSkill()
  980. {
  981. EnterCriticalSection(&cs);
  982. if (!m_pConnection)
  983. {
  984. m_pConnection = new instructionsServerConnection(m_pEntity, this);
  985. if (!m_pConnection->ConnectFromCentralSetting())
  986. {
  987. Dbg("connect instruction server fail,config or Servers Error!");
  988. m_pConnection->handleDisconnect();
  989. m_pConnection = NULL;
  990. LeaveCriticalSection(&cs);
  991. SetErrMsg(ERR_CONNECTSERVICE_FROM_CENTER,"根据集中配置连接指令服务失败");
  992. return ERR_CONNECTSERVICE_FROM_CENTER;
  993. }
  994. }
  995. if (m_pConnection->IsConnectionOK())
  996. {
  997. DWORD dwRet = m_pConnection->SendHolderSkillReq();
  998. if (Error_Succeed == dwRet)
  999. {
  1000. Dbg("send SendHolderSkillReq success");
  1001. }
  1002. else
  1003. {
  1004. Dbg("send SendHolderSkillReq failed");
  1005. LeaveCriticalSection(&cs);
  1006. return dwRet;
  1007. }
  1008. }
  1009. else
  1010. {
  1011. //连接失败,关闭链接重连
  1012. if (NULL != m_pConnection)
  1013. {
  1014. m_pConnection->handleDisconnect();
  1015. m_pConnection = NULL;
  1016. Dbg("Close m_pConnection");
  1017. }
  1018. Dbg("connect to instructions server failed, can not get holder skill!");
  1019. LeaveCriticalSection(&cs);
  1020. SetErrMsg(ERR_CONNECT,"网络异常,无法连接指令服务");
  1021. return ERR_CONNECT;
  1022. }
  1023. LeaveCriticalSection(&cs);
  1024. return Error_Succeed;
  1025. }
  1026. //TODO:监控IEbrowser状态,如果为非Idle状态,持有者状态设置为“N”,但“N”状态不上报,怎么处理?(新加一个错误状态)
  1027. //获取通话状态
  1028. BOOL HolderContextFSM::GetCallState()
  1029. {
  1030. //判断终端是否在业务界面首页,不在首页不弹出客户经理登录框
  1031. ErrorCodeEnum Error = GetEntityBase()->GetFunction()->GetSysVar("CallState",m_strCallstate);
  1032. if (Error_NotExist == Error)
  1033. {
  1034. Dbg("CallState is not exist, errcode=%d!", Error);
  1035. return FALSE;
  1036. }
  1037. else if (Error_Succeed != Error)
  1038. {
  1039. Dbg("Get CallState failed, errcode=%d!", Error);
  1040. return FALSE;
  1041. }
  1042. else
  1043. {
  1044. /* "O", Offline
  1045. "C", Connecting
  1046. "H", HandFree
  1047. "P", Pickup
  1048. "B", Broken
  1049. "F", Fail
  1050. "R", Releasing
  1051. */
  1052. ////Dbg("Get UIState success, m_strUIstate=%s!", m_strUIstate);
  1053. //if ((-1 != FindSubStr(m_strUIstate, "M"))
  1054. // || (-1 != FindSubStr(m_strUIstate, "A"))
  1055. // || (-1 != FindSubStr(m_strUIstate, "T")))
  1056. //{
  1057. // //界面状态UIState。定义当前交互层所处的交互模式。有8种状态:目录浏览M、随机广告A、目标广告T、业务填单F、交易确认C、业务提交S、请求回报R、暂停响应Z。初始状态为M。
  1058. // //M、A、T三种状态都认为在首页
  1059. // //Dbg("At Menu status!");
  1060. // m_bMenu = TRUE;
  1061. //}
  1062. //else
  1063. //{
  1064. // //不在首页
  1065. // //Dbg("Not at Menu status!");
  1066. // m_bMenu = FALSE;
  1067. //}
  1068. return TRUE;
  1069. }
  1070. }
  1071. //获取持有者状态,TODO:增加系统变量HolderState
  1072. BOOL HolderContextFSM::GetHolderState()
  1073. {
  1074. ErrorCodeEnum Error = GetEntityBase()->GetFunction()->GetSysVar("HolderState",(CSimpleStringA)m_HolderState.State);
  1075. if (Error_NotExist == Error)
  1076. {
  1077. Dbg("HolderState is not exist, errcode=%d!", Error);
  1078. return FALSE;
  1079. }
  1080. else if (Error_Succeed != Error)
  1081. {
  1082. Dbg("Get HolderState failed, errcode=%d!", Error);
  1083. return FALSE;
  1084. }
  1085. else
  1086. {
  1087. /* "O", Offline
  1088. "C", Connecting
  1089. "H", HandFree
  1090. "P", Pickup
  1091. "B", Broken
  1092. "F", Fail
  1093. "R", Releasing
  1094. */
  1095. ////Dbg("Get UIState success, m_strUIstate=%s!", m_strUIstate);
  1096. //if ((-1 != FindSubStr(m_strUIstate, "M"))
  1097. // || (-1 != FindSubStr(m_strUIstate, "A"))
  1098. // || (-1 != FindSubStr(m_strUIstate, "T")))
  1099. //{
  1100. // //界面状态UIState。定义当前交互层所处的交互模式。有8种状态:目录浏览M、随机广告A、目标广告T、业务填单F、交易确认C、业务提交S、请求回报R、暂停响应Z。初始状态为M。
  1101. // //M、A、T三种状态都认为在首页
  1102. // //Dbg("At Menu status!");
  1103. // m_bMenu = TRUE;
  1104. //}
  1105. //else
  1106. //{
  1107. // //不在首页
  1108. // //Dbg("Not at Menu status!");
  1109. // m_bMenu = FALSE;
  1110. //}
  1111. return TRUE;
  1112. }
  1113. }
  1114. //由业务层设置持有者状态
  1115. BOOL HolderContextFSM::SetHolderState(CSimpleStringA strState)
  1116. {
  1117. Dbg("SetHolderState[%s]", strState);
  1118. string State = strState;
  1119. //根据的状态值发送事件跳转到相应的状态机
  1120. if ("S" == State)
  1121. {
  1122. //就绪(S)
  1123. PostEventLIFO(new FSMEvent(USER_EVT_JMP_STANDBY));
  1124. }
  1125. else if ("B" == State)
  1126. {
  1127. //示忙(B)
  1128. PostEventLIFO(new FSMEvent(USER_EVT_JMP_BUSY));
  1129. }
  1130. else if ("R" == State)
  1131. {
  1132. //振铃(R)
  1133. PostEventLIFO(new FSMEvent(USER_EVT_JMP_RINGING));
  1134. }
  1135. else if ("E" == State)
  1136. {
  1137. //会话整理(E)
  1138. PostEventLIFO(new FSMEvent(USER_EVT_JMP_EDIT));
  1139. }
  1140. else if ("N" == State)
  1141. {
  1142. //未绑定(N),签出时处于此状态
  1143. PostEventLIFO(new FSMEvent(USER_EVT_JMP_NONE));
  1144. }
  1145. else
  1146. {
  1147. Dbg("SetHolderState failed, unkonwn state value");
  1148. return FALSE;
  1149. }
  1150. return TRUE;
  1151. }
  1152. //校验持有者技能
  1153. DWORD HolderContextFSM::CheckHolderRights()
  1154. {
  1155. //add by zl 20170811 暂时放开远程服务资质校验
  1156. return Error_Succeed;
  1157. //获取权限
  1158. /*DWORD dwRet = QueryHolderSkill();
  1159. if (Error_Succeed != dwRet)
  1160. {
  1161. return dwRet;
  1162. }
  1163. //校验权限
  1164. CSimpleStringA strSkillList = m_cHolderSkill;
  1165. Dbg("[%s]技能列表[%s]",m_HolderState.HolderID.GetData(),strSkillList.GetData());
  1166. if (-1 == FindSubStr(strSkillList, "ConnectService"))
  1167. {
  1168. SetErrMsg(ERR_NO_CONNECTRIGHT,"用户没有远程服务资质");
  1169. return ERR_NO_CONNECTRIGHT;
  1170. }
  1171. return Error_Succeed;*/
  1172. }
  1173. //获取持有者信息
  1174. BOOL GetSAPFromUserInfo(const char *strHolderInfo, char *cSAP)
  1175. {
  1176. if (NULL == strHolderInfo || NULL == cSAP)
  1177. {
  1178. return FALSE;
  1179. }
  1180. string strUserInfo = strHolderInfo;
  1181. int len = strUserInfo.length();
  1182. int nPos = strUserInfo.find("SAP=");
  1183. if (nPos < 0)
  1184. {
  1185. return FALSE;
  1186. }
  1187. string strRecord = strUserInfo.substr(nPos, len-1);
  1188. nPos = strRecord.find_first_of(";");
  1189. if (nPos < 0)
  1190. {
  1191. return FALSE;
  1192. }
  1193. string strUserIDRecord = strRecord.substr(0, nPos);
  1194. if (strUserIDRecord.length() <= 4)
  1195. {
  1196. return FALSE;
  1197. }
  1198. string userID = strUserIDRecord.substr(4,nPos -4);
  1199. memcpy(cSAP, userID.c_str(), 8);
  1200. return TRUE;
  1201. }
  1202. BOOL GetAgentIDFromUserInfo(const char *strHolderInfo, char *cAgentID)
  1203. {
  1204. if (NULL == strHolderInfo || NULL == cAgentID)
  1205. {
  1206. return FALSE;
  1207. }
  1208. string strUserInfo = strHolderInfo;
  1209. int len = strUserInfo.length();
  1210. int nPos = strUserInfo.find("UserID=");
  1211. if (nPos < 0)
  1212. {
  1213. return FALSE;
  1214. }
  1215. string strRecord = strUserInfo.substr(nPos, len-1);
  1216. nPos = strRecord.find_first_of(";");
  1217. if (nPos < 0)
  1218. {
  1219. return FALSE;
  1220. }
  1221. string strUserIDRecord = strRecord.substr(0, nPos);
  1222. if (strUserIDRecord.length() <= 7)
  1223. {
  1224. return FALSE;
  1225. }
  1226. string userID = strUserIDRecord.substr(7,nPos -7);
  1227. memcpy(cAgentID, userID.c_str(), 10);
  1228. return TRUE;
  1229. }
  1230. BOOL HolderContextFSM::GetHolderMsg(CSimpleStringA strHolderInfo)
  1231. {
  1232. Dbg("GetHolderMsg success!");
  1233. m_strHolderInfo = strHolderInfo;
  1234. //解析持有者信息
  1235. char cSAP[9] = {0};
  1236. if (!GetSAPFromUserInfo(m_strHolderInfo.GetData(),cSAP))
  1237. {
  1238. Dbg("GetSAPFromUserInfo failed!");
  1239. return FALSE;
  1240. }
  1241. m_HolderState.HolderID = cSAP;
  1242. Dbg("SAP=%s", m_HolderState.HolderID);
  1243. //判断HolderID是否为空 add by zl 20171129
  1244. if (m_HolderState.HolderID.IsNullOrEmpty())
  1245. {
  1246. Dbg("SAP is not exist!");
  1247. SetErrMsg(ERR_NO_CONNECTRIGHT,"当前用户没有SAP号");
  1248. return FALSE;
  1249. }
  1250. else
  1251. {
  1252. //PostEventLIFO(new FSMEvent(USER_EVT_JMP_STANDBY)); D:\BranchServer\RvcBranchServer1.9.5\RvcFramework.exe
  1253. }
  1254. return TRUE;
  1255. }
  1256. //查找子串
  1257. DWORD HolderContextFSM::FindSubStr(const char* source, const char* target)
  1258. {
  1259. unsigned int i,j;
  1260. if (strlen(source) < strlen(target))
  1261. {
  1262. return -1;
  1263. }
  1264. if (1 == strlen(source)
  1265. && 1== strlen(target)
  1266. && source[0] == target[0])
  1267. {
  1268. return 0;
  1269. }
  1270. for (i = 0;i<=strlen(source)-strlen(target);i++)
  1271. {
  1272. if (source[i]==target[0])
  1273. {
  1274. for (j = 1;j<=strlen(target);j++)
  1275. {
  1276. if (source[i+j]!=target[j])
  1277. break;
  1278. }
  1279. if ((j == strlen(target))
  1280. || (j == strlen(target)+1))
  1281. {
  1282. return i;
  1283. }
  1284. j = 0;
  1285. }
  1286. }
  1287. return -1;
  1288. }
  1289. void HolderContextFSM::SetErrMsg(DWORD dwErrcode, CSimpleStringA strErrmsg)
  1290. {
  1291. m_nErrcode = dwErrcode;
  1292. m_strErrmsg = strErrmsg;
  1293. }
  1294. //获取指定实体状态
  1295. BOOL HolderContextFSM::GetEntityState(CSimpleStringA strEntityName, int &nState)
  1296. {
  1297. ErrorCodeEnum eErr;
  1298. CSmartPointer<IEntityFunction> pFunc = GetEntityBase()->GetFunction();
  1299. CSmartPointer<IEntityFunctionPrivilege> pFuncPrivilege = pFunc.ConvertCase<IEntityFunctionPrivilege>();
  1300. CEntityRunInfo acInfo;
  1301. eErr = pFunc->GetEntityRunInfo(strEntityName,acInfo);
  1302. Dbg("[%s] state return %d",strEntityName, eErr);
  1303. if (eErr == Error_Succeed)
  1304. {
  1305. nState = acInfo.eState;
  1306. Dbg("[%s] state is [%d]", strEntityName, acInfo.eState);
  1307. }
  1308. else
  1309. {
  1310. Dbg("GetEntityRunInfo failed, errcode[%d]",eErr);
  1311. }
  1312. return TRUE;
  1313. }
  1314. ErrorCodeEnum HolderContextFSM::AsyncStartEntity(const char *entity_name, const char *cmdline, void *pData)
  1315. {
  1316. CSmartPointer<IEntityFunction> pFunc = m_pEntity->GetFunction();
  1317. CSmartPointer<IEntityFunctionPrivilege> pFuncPrivilege = pFunc.ConvertCase<IEntityFunctionPrivilege>();
  1318. if (pFuncPrivilege != NULL) {
  1319. CSmartPointer<IAsynWaitSp> spWait;
  1320. ErrorCodeEnum Error = pFuncPrivilege->StartEntity(entity_name, cmdline, spWait);
  1321. //if (Error == Error_Succeed) {
  1322. // callback_entry *entry = new callback_entry();
  1323. // entry->pRawData = pData;
  1324. // entry->EntityName = entity_name;
  1325. // entry->ErrorResult = Error_Unexpect;
  1326. // entry->op = OP_START_ENTITY;
  1327. // //spWait->SetCallback(this, entry);
  1328. //}z
  1329. return Error;
  1330. } else {
  1331. return Error_NoPrivilege;
  1332. }
  1333. }
  1334. ErrorCodeEnum HolderContextFSM::AsyncStopEntity(const char *entity_name, void *pData)
  1335. {
  1336. CSmartPointer<IEntityFunction> pFunc = m_pEntity->GetFunction();
  1337. CSmartPointer<IEntityFunctionPrivilege> pFuncPrivilege = pFunc.ConvertCase<IEntityFunctionPrivilege>();
  1338. if (pFuncPrivilege != NULL) {
  1339. CSmartPointer<IAsynWaitSp> spWait;
  1340. ErrorCodeEnum Error = pFuncPrivilege->StopEntity(entity_name, spWait);
  1341. //if (Error == Error_Succeed) {
  1342. // callback_entry *entry = new callback_entry();
  1343. // entry->pRawData = pData;
  1344. // entry->EntityName = entity_name;
  1345. // entry->ErrorResult = Error_Unexpect;
  1346. // entry->op = OP_STOP_ENTITY;
  1347. // //spWait->SetCallback(this, entry);
  1348. //}
  1349. return Error;
  1350. }
  1351. else
  1352. {
  1353. return Error_NoPrivilege;
  1354. }
  1355. }