VtmLoaderFSM.cpp 79 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286
  1. #include "stdafx.h"
  2. #include <algorithm>
  3. #include "VtmLoaderFSM.h"
  4. #include "VtmLoader_UserCode.h"
  5. #include "EventCode.h"
  6. #if defined(RVC_OS_WIN)
  7. #include <io.h>
  8. #include "..\RvcVer.h"
  9. #else
  10. #include <unistd.h>
  11. #include <fcntl.h>
  12. #include <errno.h>
  13. #include "RestfulFunc.h"
  14. #endif //RVC_OS_WIN
  15. #include "../mod_healthmanager/HealthManager_client_g.h"
  16. #include "../mod_pinpad/PinPad_client_g.h"
  17. #include "../mod_cardissuer/CardIssuer_client_g.h"
  18. #include "../mod_IDCertificate/IDCertificate_client_g.h"
  19. #include "../mod_HSPScanner/HSPScanner_client_g.h"
  20. #include "../mod_ContactlessCard/ContactlessCard_client_g.h"
  21. #include "../mod_FingerPrint/FingerPrint_client_g.h"
  22. #include "../mod_gpio/Gpio_client_g.h"
  23. using namespace HealthManager;
  24. using namespace PinPad;
  25. using namespace CardIssuer;
  26. using namespace IDCertificate;
  27. using namespace HSPScanner;
  28. using namespace ContactlessCard;
  29. using namespace FingerPrint;
  30. using namespace Gpio;
  31. using namespace SP::Module::Net;
  32. #define ALLOW_MULTI_NETWORKD_CARDS
  33. const int MAX_AYSNC_TIMEOUT = 60000;
  34. const int MAX_IGNORE_TIMEOUT = 100;
  35. enum EntityOP
  36. {
  37. OP_STOP_ENTITY,
  38. OP_START_ENTITY,
  39. OP_PAUSE_ENTITY,
  40. OP_TERMINATE_ENTITY,
  41. OP_CONTINUE_ENTITY,
  42. };
  43. struct callback_entry : public IReleasable
  44. {
  45. virtual ~callback_entry() {}
  46. CSimpleStringA EntityName;
  47. union {
  48. void* pRawData;
  49. int state;
  50. };
  51. int op;
  52. ErrorCodeEnum ErrorResult;
  53. };
  54. DWORD tokenUpdate(void* param)
  55. {
  56. CVtmLoaderFSM* t_entity = (CVtmLoaderFSM*)param;
  57. while (true)
  58. {
  59. if (t_entity->refreshToken())
  60. Sleep(t_entity->m_refreshWaitSec * 1000);
  61. else
  62. Sleep(20 * 1000);
  63. }
  64. return 0;
  65. }
  66. DWORD checkUrlActive(LPVOID param)
  67. {
  68. CVtmLoaderFSM* entityInfo = (CVtmLoaderFSM*)param;
  69. CSmartPointer<IConfigInfo> pConfig;
  70. CSimpleString t_endpoint, t_materialUrl;
  71. CSimpleString errMsg;
  72. Sleep(60 * 1000);
  73. long srcClo = clock();
  74. entityInfo->GetEntityBase()->GetFunction()->OpenConfig(Config_CenterSetting, pConfig);
  75. do {
  76. if (Error_Succeed != pConfig->ReadConfigValue("Common", "SendEndpoint", t_endpoint))
  77. {
  78. errMsg = "checkUrlActive read Common::SendEndpoint err";
  79. break;
  80. }
  81. if (t_endpoint.GetLength() == 0)
  82. {
  83. errMsg = "checkUrlActive endpoint len=0 err";
  84. break;
  85. }
  86. //if (!checkHttpActive(t_endpoint.GetData()))
  87. // errMsg.Append(CSimpleString::Format("checkHttpActive endpoint err:%s !", t_endpoint.GetData()));
  88. //else if((clock() - srcClo) > 3000)
  89. // errMsg.Append(CSimpleString::Format("checkHttpActive endpoint too long:%d !", clock() - srcClo));
  90. srcClo = clock();
  91. } while (false);
  92. if (errMsg.GetLength() > 0)
  93. LogWarn(SeverityLevelEnum::Severity_Middle, Error_Unexpect, WARN_SendEndpoint_URL_ERR, errMsg.GetData());
  94. //do get upload log Info for a while
  95. while (true)
  96. {
  97. if (entityInfo->m_uploadLogInfo_waitSec <= 0)
  98. break;
  99. Sleep(entityInfo->m_uploadLogInfo_waitSec * 1000);
  100. unsigned long t_upload_TerminalSys_Suc, t_upload_TerminalUser_Suc, t_upload_BussinessSys_Suc, t_upload_BussinessUser_Suc, t_upload_beidou_Suc;
  101. unsigned long t_upload_TerminalSys_Err, t_upload_TerminalUser_Err, t_upload_BussinessSys_Err, t_upload_BussinessUser_Err, t_upload_beidou_Err;
  102. entityInfo->GetEntityBase()->GetFunction()->GetPrivilegeFunction()->GetSendLogInfo(&t_upload_TerminalSys_Suc, &t_upload_TerminalUser_Suc,
  103. &t_upload_BussinessSys_Suc, &t_upload_BussinessUser_Suc, &t_upload_beidou_Suc,
  104. &t_upload_TerminalSys_Err, &t_upload_TerminalUser_Err, &t_upload_BussinessSys_Err, &t_upload_BussinessUser_Err, &t_upload_beidou_Err);
  105. LogWarn(SeverityLevelEnum::Severity_Low, Error_Trace, WARN_SendEndpoint_LOG_INFO,
  106. CSimpleString::Format("checkUrlActive::GetSendLogInfo, TS_Suc:%d, TU_Suc:%d, BS_Suc:%d, BU_Suc:%d, beidou_Suc:%d, TS_Err:%d, TU_Err:%d, BS_Err:%d, BU_Err:%d, beidou_Err:%d"
  107. , t_upload_TerminalSys_Suc, t_upload_TerminalUser_Suc, t_upload_BussinessSys_Suc, t_upload_BussinessUser_Suc, t_upload_beidou_Suc,
  108. t_upload_TerminalSys_Err, t_upload_TerminalUser_Err, t_upload_BussinessSys_Err, t_upload_BussinessUser_Err, t_upload_beidou_Err).GetData());
  109. }
  110. return 0;
  111. }
  112. DWORD AlarmVersionErr(LPVOID param)
  113. {
  114. CVtmLoaderFSM* cur = (CVtmLoaderFSM*)param;
  115. Sleep(5000);//wait mod_alarm start
  116. LogWarn(Severity_Middle, Error_Bug, VtmLoader_DETECT_VERSION_ERR, cur->m_verShowMsg.GetData());
  117. return 0;
  118. }
  119. bool CVtmLoaderFSM::refreshToken()
  120. {
  121. CSimpleString oldToken, newToken;
  122. ErrorCodeEnum eErr = Error_Succeed;
  123. if (Error_Succeed != (eErr = GetEntityBase()->GetFunction()->GetPrivilegeFunction()->TryUpdateToken(oldToken, newToken)))
  124. {
  125. DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_USER).setLogCode("QLR040210F13").setResultCode("RTA1F02")("Get center setting, TryUpdateToken failed:0x%x", eErr);
  126. return false;
  127. }
  128. return true;
  129. }
  130. CVtmLoaderFSM::CVtmLoaderFSM()
  131. {
  132. m_refreshWaitSec = 1200;
  133. m_uploadLogInfo_waitSec = 3600;
  134. m_defaultSystemId = "LR04.02_Terminal";
  135. m_iCanIgnoreAddrDetect = 0;
  136. m_ullMaxAddrDetectTime = 10*60*1000;//10 minutes
  137. m_iDetectInterval = 5000;
  138. m_terminalNoFromWeb = m_verShowMsg = "";
  139. }
  140. CVtmLoaderFSM::~CVtmLoaderFSM()
  141. {
  142. }
  143. ErrorCodeEnum CVtmLoaderFSM::OnInit()
  144. {
  145. AddStateHooker(this);
  146. GetEntityBase()->GetFunction()->GetSystemStaticInfo(m_sysInfo);
  147. return Error_Succeed;
  148. }
  149. ErrorCodeEnum CVtmLoaderFSM::OnExit()
  150. {
  151. RemoveStateHooker(this);
  152. return Error_Succeed;
  153. }
  154. void CVtmLoaderFSM::OnStateTrans(int iSrcState, int iDstState)
  155. {
  156. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("state change from %s to %s", GetStateName(iSrcState), GetStateName(iDstState));
  157. }
  158. void CVtmLoaderFSM::s0_on_entry()
  159. {
  160. LogWarn(Severity_Low, Error_Succeed, VtmLoader_BootInfoPrint, "开始网卡、网络连通性检查");
  161. NetWorkCheckAndGetSettingTask* task = new NetWorkCheckAndGetSettingTask(this);
  162. GetEntityBase()->GetFunction()->PostThreadPoolTask(task);
  163. }
  164. void CVtmLoaderFSM::s0_on_exit()
  165. {
  166. }
  167. unsigned int CVtmLoaderFSM::s0_on_event(FSMEvent* pEvt)
  168. {
  169. DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("s0_on_event,pEvt:%d,pEvt->param1:%d", pEvt->iEvt, pEvt->param1);
  170. switch (pEvt->iEvt)
  171. {
  172. case USER_EVT_NetworkCheck_Passed:
  173. pEvt->SetHandled();
  174. return pEvt->param1;
  175. case USER_EVT_CHECK_DEVICE_ENTITY:
  176. pEvt->SetHandled();
  177. {
  178. CheckDeviceEntityEvent* cdee = dynamic_cast<CheckDeviceEntityEvent*>(pEvt);
  179. CheckDeviceEntityTask* pTask = new CheckDeviceEntityTask(this);
  180. pTask->ctx = cdee->ctx;
  181. GetEntityBase()->GetFunction()->PostThreadPoolTask(pTask);
  182. }
  183. break;
  184. case USER_EVT_SAVE_TERMINALNO:
  185. pEvt->SetHandled();
  186. {
  187. SaveTerminalNoEvent* stne = dynamic_cast<SaveTerminalNoEvent*>(pEvt);
  188. SaveTerminalNoTask* pTask = new SaveTerminalNoTask(this);
  189. pTask->ctx = stne->ctx;
  190. GetEntityBase()->GetFunction()->PostThreadPoolTask(pTask);
  191. }
  192. break;
  193. default:
  194. break;
  195. }
  196. return 0;
  197. }
  198. void CVtmLoaderFSM::ShowEntityBootFailedAtFront(LPCTSTR lpcszEntityName, ErrorCodeEnum bootFailedResult, bool isBlock)
  199. {
  200. #if defined(RVC_OS_LINUX)
  201. CEntityLastErrorInfo errInfo = {};
  202. ErrorCodeEnum errCode = GetEntityBase()->GetFunction()->GetEntityLastError(lpcszEntityName, errInfo);
  203. CSimpleStringA strErrMsg(true);
  204. if (!errInfo.strErrMsg.IsNullOrEmpty()) {
  205. strErrMsg = CSimpleStringA::Format("%s:%s", lpcszEntityName, (LPCTSTR)errInfo.strErrMsg);
  206. }
  207. else {
  208. strErrMsg = CSimpleStringA::Format("%s模块初始化失败: %s", lpcszEntityName, (LPCTSTR)SpStrError(bootFailedResult));
  209. }
  210. if (CSimpleStringA(lpcszEntityName).Compare("SIPPhone", true) == 0)
  211. {
  212. GetEntityBase()->GetFunction()->SetSysVar("AuthErrMsg", strErrMsg.GetData());//实体启动失败保存到错误页字段
  213. }
  214. if (isBlock) {
  215. SP::Module::Comm::LogErrorNotiyStruct notifyItem(bootFailedResult, 0);
  216. SP::Module::Comm::LogNotiyMessageStruct notifyMsg(strErrMsg);
  217. notifyItem.Notify(notifyMsg);
  218. }
  219. else {
  220. LogError(Severity_High, bootFailedResult, 0, strErrMsg);
  221. }
  222. #endif //RVC_OS_LINUX
  223. }
  224. //CoreBoot
  225. void CVtmLoaderFSM::s1_on_entry()
  226. {
  227. DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("s1_on_entry");
  228. ErrorCodeEnum eErrCode;
  229. CSmartPointer<IEntityFunction> spEntityFunction = GetEntityBase()->GetFunction();
  230. CSmartPointer<IEntityFunctionPrivilege> pFuncPrivilege = spEntityFunction.ConvertCase<IEntityFunctionPrivilege>();
  231. bool bAsync = false;
  232. m_eStage = LOADSTAGE_COREBOOT;
  233. int ret = 0;
  234. map<CSimpleStringA, EntityLoadInfo>::iterator it;
  235. //start entity
  236. vector<CSimpleStringA>::iterator vIt;
  237. if (m_coreBootOpt.size() == 0)
  238. goto COREBOOT_FINISH;
  239. char startMsg[128];
  240. for (vIt = m_vCoreBoot.begin(); vIt != m_vCoreBoot.end(); ++vIt)
  241. {
  242. CSmartPointer<IAsynWaitSp> spWait;//oilyang 20160325 see the following comment
  243. it = m_coreBootOpt.find(*vIt);
  244. if (it == m_coreBootOpt.end())
  245. {
  246. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("cannot find %s", (LPCSTR)* vIt);
  247. continue;
  248. }
  249. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("start,%s,%d", (LPCSTR)it->first, it->second.loadOpt);
  250. CEntityRunInfo entRunInfo;
  251. ErrorCodeEnum errCode = spEntityFunction->GetEntityRunInfo(it->first, entRunInfo);
  252. if (errCode == Error_Succeed && entRunInfo.eState == EntityState_Idle)
  253. {
  254. it->second.eResult = LOADING_SUCCEED;
  255. ret = CheckLoadResult(LOADSTAGE_COREBOOT);
  256. if (ret == 0 || ret == 2)
  257. goto COREBOOT_FINISH;
  258. else
  259. continue;
  260. }
  261. ZeroMemory(startMsg, 128);
  262. //sprintf(startMsg, "正在启动实体%s...", it->first.GetData());
  263. //GetEntityBase()->GetFunction()->ShowStartupInfo(startMsg);
  264. switch (it->second.loadOpt)
  265. {
  266. case LOADOPT_IGNORE:
  267. {
  268. pFuncPrivilege->StartEntity(it->first, NULL, spWait);
  269. if (spWait != NULL)
  270. spWait->WaitAnswer(MAX_IGNORE_TIMEOUT);//oilyang 20160325 the null pointer
  271. it->second.eResult = LOADING_SUCCEED;
  272. ret = CheckLoadResult(LOADSTAGE_COREBOOT);
  273. if (ret == 0 || ret == 2)
  274. goto COREBOOT_FINISH;
  275. }
  276. break;
  277. case LOADOPT_ASYNC_VERIFY:
  278. errCode = AsyncStartEntity(it->first, NULL, NULL);
  279. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("AsyncStartEntity:%d", errCode);
  280. bAsync = true;
  281. break;
  282. case LOADOPT_SYNC_VERIFY:
  283. {
  284. pFuncPrivilege->StartEntity(it->first, NULL, spWait);
  285. if (spWait != NULL)
  286. errCode = spWait->WaitAnswer(MAX_AYSNC_TIMEOUT);
  287. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("(coreboot)sync...%d", errCode);
  288. if (errCode == Error_Succeed)
  289. it->second.eResult = LOADING_SUCCEED;
  290. else if (errCode == Error_TimeOut)
  291. it->second.eResult = LOADING_TIMEOUT;
  292. else
  293. it->second.eResult = LOADING_FAILED;
  294. if (errCode != Error_Succeed) {
  295. return;
  296. #if defined(RVC_OS_LINUX)
  297. ShowEntityBootFailedAtFront(it->first, errCode);
  298. return;
  299. #endif //RVC_OS_LINUX
  300. }
  301. else
  302. ret = CheckLoadResult(LOADSTAGE_COREBOOT);
  303. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("s1 check ret %d", ret);
  304. if (ret == 0 || ret == 2)
  305. goto COREBOOT_FINISH;
  306. }
  307. break;
  308. default:
  309. break;
  310. }
  311. }
  312. COREBOOT_FINISH:
  313. if (!bAsync)
  314. {
  315. FSMEvent* e = new FSMEvent(USER_EVT_COREBOOT_FINISHED);
  316. e->param1 = ret;
  317. PostEventFIFO(e);
  318. }
  319. else
  320. {
  321. ret = CheckLoadResult(LOADSTAGE_COREBOOT);
  322. if (ret == 0 || ret == 2)
  323. {
  324. FSMEvent* e = new FSMEvent(USER_EVT_COREBOOT_FINISHED);
  325. e->param1 = ret;
  326. PostEventFIFO(e);
  327. }
  328. }
  329. return;
  330. }
  331. void CVtmLoaderFSM::s1_on_exit()
  332. {
  333. LOG_FUNCTION();
  334. }
  335. unsigned int CVtmLoaderFSM::s1_on_event(FSMEvent* pEvt)
  336. {
  337. LOG_FUNCTION();
  338. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("s1 evt %d", pEvt->iEvt);
  339. switch (pEvt->iEvt)
  340. {
  341. case USER_EVT_COREBOOT_FINISHED:
  342. pEvt->SetHandled();
  343. if (pEvt->param1 == 2) {
  344. #if defined(RVC_OS_LINUX)
  345. ShowEntityBootFailedAtFront(m_csErrEntity, Error_InvalidState);
  346. #endif
  347. }
  348. return pEvt->param1;
  349. break;
  350. default:
  351. break;
  352. }
  353. return 0;
  354. }
  355. //SafeLoad
  356. void CVtmLoaderFSM::s2_on_entry()
  357. {
  358. LOG_FUNCTION();
  359. LogWarn(Severity_Low, Error_Succeed, VtmLoader_BootInfoPrint, "CoreBoot 阶段实体加载完成");
  360. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_USER).setLogCode("QLR040210F14")("Stage Coreboot have done.");
  361. ULONGLONG dwElapse = SP::Module::Comm::RVCGetTickCount();//使用机器启动时间秒数
  362. DWORD elapseTimeTemp = dwElapse / 1000;
  363. CSimpleStringA xMsg = CSimpleStringA::Format("{\"Decripstion\":\"Enter safeload state.\",\"version\":\"%s\",\"elapseTime\":\"%d\"}", m_sysInfo.InstallVersion.ToString().GetData(), elapseTimeTemp);
  364. //LogWarn(Severity_Low, Error_Unexpect, HealthManager_UserErrorCode_Enter_SafeLoad_State, xMsg.GetData());
  365. if (!VerifyVer())
  366. return;
  367. bool bAsync = false;
  368. m_eStage = LOADSTAGE_SAFELOAD;
  369. int ret = 0;
  370. map<CSimpleStringA, EntityLoadInfo>::iterator it;
  371. CSmartPointer<IEntityFunction> pFunc = GetEntityBase()->GetFunction();
  372. CSmartPointer<IEntityFunctionPrivilege> pFuncPrivilege = pFunc.ConvertCase<IEntityFunctionPrivilege>();
  373. ErrorCodeEnum errCode;
  374. vector<CSimpleStringA>::iterator vIt;
  375. if (m_safeLoadOpt.size() == 0)
  376. goto SAFELOAD_FINISH;
  377. char startMsg[128];
  378. for (vIt = m_vSafeLoad.begin(); vIt != m_vSafeLoad.end(); ++vIt)
  379. {
  380. CSmartPointer<IAsynWaitSp> spWait;
  381. it = m_safeLoadOpt.find(*vIt);
  382. if (it == m_safeLoadOpt.end())
  383. {
  384. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("cannot find %s", (LPCSTR)* vIt);
  385. continue;
  386. }
  387. CEntityRunInfo entRunInfo;
  388. errCode = pFunc->GetEntityRunInfo(it->first, entRunInfo);
  389. if (errCode == Error_Succeed && entRunInfo.eState == EntityState_Idle)
  390. {
  391. it->second.eResult = LOADING_SUCCEED;
  392. ret = CheckLoadResult(LOADSTAGE_SAFELOAD);
  393. if (ret == 0 || ret == 2)
  394. goto SAFELOAD_FINISH;
  395. else
  396. continue;
  397. }
  398. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("start %s,%d", (LPCTSTR)it->first, it->second.loadOpt);
  399. switch (it->second.loadOpt)
  400. {
  401. case LOADOPT_IGNORE:
  402. {
  403. pFuncPrivilege->StartEntity(it->first, NULL, spWait);
  404. if (spWait != NULL)
  405. spWait->WaitAnswer(MAX_IGNORE_TIMEOUT);
  406. it->second.eResult = LOADING_SUCCEED;
  407. ret = CheckLoadResult(LOADSTAGE_SAFELOAD);
  408. if (ret == 0 || ret == 2)
  409. goto SAFELOAD_FINISH;
  410. }
  411. break;
  412. case LOADOPT_ASYNC_VERIFY:
  413. AsyncStartEntity(it->first, NULL, NULL);
  414. bAsync = true;
  415. break;
  416. case LOADOPT_SYNC_VERIFY:
  417. {
  418. ZeroMemory(startMsg, 128);
  419. sprintf(startMsg, "正在启动实体%s...", it->first.GetData());
  420. GetEntityBase()->GetFunction()->ShowStartupInfo(startMsg);
  421. pFuncPrivilege->StartEntity(it->first, NULL, spWait);
  422. if (spWait != NULL)
  423. errCode = spWait->WaitAnswer(MAX_AYSNC_TIMEOUT);
  424. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("sync...%d", errCode);
  425. if (errCode == Error_Succeed) {
  426. it->second.eResult = LOADING_SUCCEED;
  427. }
  428. else if (errCode == Error_TimeOut)
  429. it->second.eResult = LOADING_TIMEOUT;
  430. else
  431. it->second.eResult = LOADING_FAILED;
  432. if (it->second.eResult != Error_Succeed)
  433. {
  434. char tmp[128] = { 0 };
  435. if (it->first.Compare("SIPPhone", true) == 0) {
  436. if (LOADING_TIMEOUT == it->second.eResult) {
  437. sprintf(tmp, "实体 %s 启动超时(%d),请尝试重启应用解决", it->first.GetData(), it->second.eResult);
  438. }
  439. else {
  440. sprintf(tmp, "实体 %s 启动失败(%d),识别不到声卡,请尝试重启计算机解决,多次无效后请联系厂商处理", it->first.GetData(), it->second.eResult);
  441. }
  442. }
  443. else {
  444. sprintf(tmp, "实体 %s 启动失败 %d", it->first.GetData(), it->second.eResult);
  445. }
  446. #if defined(RVC_OS_WIN)
  447. GetEntityBase()->GetFunction()->ShowFatalError(tmp);
  448. GetEntityBase()->GetFunction()->SetSysVar("AuthErrMsg", tmp);//实体启动失败保存到错误页字段
  449. #else
  450. ShowEntityBootFailedAtFront(it->first, errCode);
  451. #endif
  452. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("启动失败:%s", tmp);
  453. m_csErrEntity = m_csErrEntity + "|" + it->first;
  454. FSMEvent* e = new FSMEvent(USER_EVT_SAFELOAD_FINISHED);
  455. e->param1 = 2;//"SYNC START" enity started failed.
  456. PostEventFIFO(e);
  457. return;
  458. }
  459. //if (errCode != Error_Succeed)
  460. // return;
  461. //else
  462. ret = CheckLoadResult(LOADSTAGE_SAFELOAD);
  463. if (ret == 0 || ret == 2)
  464. goto SAFELOAD_FINISH;
  465. }
  466. break;
  467. default:
  468. break;
  469. }
  470. }
  471. SAFELOAD_FINISH:
  472. if (!bAsync)
  473. {
  474. FSMEvent* e = new FSMEvent(USER_EVT_SAFELOAD_FINISHED);
  475. e->param1 = ret;
  476. PostEventFIFO(e);
  477. }
  478. else
  479. {
  480. ret = CheckLoadResult(LOADSTAGE_SAFELOAD);
  481. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("s2 %d", ret);
  482. if (ret == 0 || ret == 2)
  483. {
  484. FSMEvent* e = new FSMEvent(USER_EVT_SAFELOAD_FINISHED);
  485. e->param1 = ret;
  486. PostEventFIFO(e);
  487. }
  488. }
  489. SAFELOAD_END:
  490. return;
  491. }
  492. void CVtmLoaderFSM::s2_on_exit()
  493. {
  494. LOG_FUNCTION();
  495. }
  496. unsigned int CVtmLoaderFSM::s2_on_event(FSMEvent* pEvt)
  497. {
  498. LOG_FUNCTION();
  499. int ret = 0;
  500. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("s2 event %d,%d", pEvt->iEvt, pEvt->param1);
  501. switch (pEvt->iEvt)
  502. {
  503. case USER_EVT_SAFELOAD_FINISHED:
  504. {
  505. pEvt->SetHandled();
  506. //oiltmp
  507. //according to the system varible TerminalState to do sth.
  508. //Configed
  509. //Breakdown
  510. //Blocking
  511. //Authentication
  512. {
  513. if (pEvt->param1 == 0)
  514. {
  515. //initializer if configured
  516. CSimpleStringA csTermStage("");
  517. ErrorCodeEnum eErrCode;
  518. eErrCode = GetEntityBase()->GetFunction()->GetSysVar("TerminalStage", csTermStage);
  519. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("after safeload to get termstage %s", (LPCTSTR)csTermStage);
  520. if (csTermStage == "B" || csTermStage == "N")
  521. return 1;
  522. }
  523. else if (pEvt->param1 == 2)
  524. {
  525. #if defined(RVC_OS_LINUX)
  526. ShowEntityBootFailedAtFront(m_csErrEntity, Error_InvalidState);
  527. #endif
  528. ret = 2;
  529. }
  530. }
  531. //Unsubscrible
  532. }
  533. break;
  534. case USER_EVT_SAFELOAD_EXMINE_FINISHED:
  535. if (pEvt->param1 == 0)
  536. ret = 0;
  537. //do something else oiltmp
  538. pEvt->SetHandled();
  539. break;
  540. case USER_EVT_ACCESSAUTH_FINISHED:
  541. pEvt->SetHandled();
  542. ret = pEvt->param1;
  543. break;
  544. default:
  545. break;
  546. }
  547. return ret;
  548. }
  549. //Operating
  550. void CVtmLoaderFSM::s3_on_entry()
  551. {
  552. LogWarn(Severity_Low, Error_Succeed, VtmLoader_BootInfoPrint, "SafeLoad 阶段实体加载完成");
  553. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_USER).setLogCode("QLR040210F15")("Stage Safeload have done.");
  554. Sleep(m_sleepEnterOpMS);
  555. bool bAsync = false;
  556. m_eStage = LOADSTAGE_OPERATING;
  557. int ret = 0;
  558. map<CSimpleStringA, EntityLoadInfo>::iterator it;
  559. CSmartPointer<IEntityFunction> pFunc = GetEntityBase()->GetFunction();
  560. CSmartPointer<IEntityFunctionPrivilege> pFuncPrivilege = pFunc.ConvertCase<IEntityFunctionPrivilege>();
  561. //start entity
  562. ErrorCodeEnum errCode;
  563. vector<CSimpleStringA>::iterator vIt;
  564. if (m_operatingOpt.size() == 0)
  565. goto OPERATING_FINISH;
  566. char startMsg[128];
  567. for (vIt = m_vOperating.begin(); vIt != m_vOperating.end(); ++vIt)
  568. {
  569. CSmartPointer<IAsynWaitSp> spWait;
  570. it = m_operatingOpt.find(*vIt);
  571. if (it == m_operatingOpt.end())
  572. {
  573. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("cannot find %s", (LPCSTR)* vIt);
  574. continue;
  575. }
  576. CEntityRunInfo entRunInfo;
  577. errCode = pFunc->GetEntityRunInfo(it->first, entRunInfo);
  578. if (errCode == Error_Succeed && entRunInfo.eState == EntityState_Idle)
  579. {
  580. it->second.eResult = LOADING_SUCCEED;
  581. ret = CheckLoadResult(LOADSTAGE_OPERATING);
  582. if (ret == 0 || ret == 2)
  583. goto OPERATING_FINISH;
  584. else
  585. continue;
  586. }
  587. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("op start %s,%d", (LPCTSTR)it->first, it->second.loadOpt);
  588. switch (it->second.loadOpt)
  589. {
  590. case LOADOPT_IGNORE:
  591. {
  592. pFuncPrivilege->StartEntity(it->first, NULL, spWait);
  593. if (spWait != NULL)
  594. spWait->WaitAnswer(MAX_IGNORE_TIMEOUT);
  595. it->second.eResult = LOADING_SUCCEED;
  596. ret = CheckLoadResult(LOADSTAGE_OPERATING);
  597. if (ret == 0 || ret == 2)
  598. goto OPERATING_FINISH;
  599. }
  600. break;
  601. case LOADOPT_ASYNC_VERIFY:
  602. errCode = AsyncStartEntity(it->first, NULL, NULL);
  603. bAsync = true;
  604. break;
  605. case LOADOPT_SYNC_VERIFY:
  606. {
  607. ZeroMemory(startMsg, 128);
  608. sprintf(startMsg, "正在启动实体%s...", it->first.GetData());
  609. GetEntityBase()->GetFunction()->ShowStartupInfo(startMsg);
  610. errCode = pFuncPrivilege->StartEntity(it->first, NULL, spWait);
  611. if (errCode == Error_Succeed)
  612. {
  613. if (spWait != NULL)
  614. errCode = spWait->WaitAnswer(MAX_AYSNC_TIMEOUT);
  615. }
  616. else
  617. {
  618. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("StartEntity %s failed(%d).", (LPCSTR)it->first, errCode);
  619. break;
  620. }
  621. if (errCode == Error_Succeed)
  622. it->second.eResult = LOADING_SUCCEED;
  623. else if (errCode == Error_TimeOut)
  624. it->second.eResult = LOADING_TIMEOUT;
  625. else
  626. it->second.eResult = LOADING_FAILED;
  627. if (it->second.eResult != Error_Succeed)
  628. {
  629. char tmp[128] = { 0 };
  630. if (it->first.Compare("SIPPhone", true) == 0) {
  631. if (LOADING_TIMEOUT == it->second.eResult) {
  632. sprintf(tmp, "实体 %s 启动超时(%d),请尝试重启应用解决", it->first.GetData(), it->second.eResult);
  633. }
  634. else {
  635. sprintf(tmp, "实体 %s 启动失败(%d),识别不到声卡,请尝试重启计算机解决,多次无效后请联系厂商处理", it->first.GetData(), it->second.eResult);
  636. }
  637. }
  638. else {
  639. sprintf(tmp, "实体 %s 启动失败 %d", it->first.GetData(), it->second.eResult);
  640. }
  641. #if defined(RVC_OS_WIN)
  642. GetEntityBase()->GetFunction()->ShowFatalError(tmp);
  643. #else
  644. ShowEntityBootFailedAtFront(it->first, errCode);
  645. #endif
  646. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("启动失败:%s", tmp);
  647. m_csErrEntity = m_csErrEntity + "|" + it->first;
  648. FSMEvent* e = new FSMEvent(USER_EVT_OPERATING_FINISHED);
  649. e->param1 = 2;//"SYNC START" enity started failed.
  650. PostEventFIFO(e);
  651. return;
  652. }
  653. if (errCode != Error_Succeed)
  654. return;
  655. else
  656. ret = CheckLoadResult(LOADSTAGE_OPERATING);
  657. if (ret == 0 || ret == 2)
  658. goto OPERATING_FINISH;
  659. }
  660. break;
  661. default:
  662. break;
  663. }
  664. }
  665. OPERATING_FINISH:
  666. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("s3 ret %d", ret);
  667. if (!bAsync)
  668. {
  669. FSMEvent* e = new FSMEvent(USER_EVT_OPERATING_FINISHED);
  670. e->param1 = ret;
  671. PostEventFIFO(e);
  672. }
  673. else
  674. {
  675. ret = CheckLoadResult(LOADSTAGE_OPERATING);
  676. if (ret == 0 || ret == 2)
  677. {
  678. FSMEvent* e = new FSMEvent(USER_EVT_OPERATING_FINISHED);
  679. e->param1 = ret;
  680. PostEventFIFO(e);
  681. }
  682. }
  683. return;
  684. }
  685. void CVtmLoaderFSM::s3_on_exit()
  686. {
  687. LOG_FUNCTION();
  688. }
  689. unsigned int CVtmLoaderFSM::s3_on_event(FSMEvent* pEvt)
  690. {
  691. LOG_FUNCTION();
  692. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("s3(Operating) event %d,%d", pEvt->iEvt, pEvt->param1);
  693. int ret = 0;
  694. switch (pEvt->iEvt)
  695. {
  696. case USER_EVT_OPERATING_FINISHED:
  697. ret = pEvt->param1;
  698. if (ret == 2) {
  699. #if defined(RVC_OS_LINUX)
  700. ShowEntityBootFailedAtFront(m_csErrEntity, Error_InvalidState);
  701. #endif
  702. }
  703. pEvt->SetHandled();
  704. break;
  705. default:
  706. break;
  707. }
  708. return ret;
  709. }
  710. //Idle(Operating finished)
  711. void CVtmLoaderFSM::s4_on_entry()
  712. {
  713. LOG_FUNCTION();
  714. LogWarn(Severity_Low, Error_Succeed, VtmLoader_BootInfoPrint, "Operating 阶段实体加载完成");
  715. //oiltmp wait for analyse progress, then change to app log format
  716. LogWarn(Severity_Low, Error_Succeed, VtmLoader_NetCard_Cost, CSimpleStringA::Format("%d", m_ullNetCardCost).GetData());
  717. LogWarn(Severity_Low, Error_Succeed, VtmLoader_NetworkDetect_Cost, CSimpleStringA::Format("%d", m_ullNetDetectCost).GetData());
  718. LogWarn(Severity_Low, Error_Succeed, VtmLoader_GetConfig_Cost, CSimpleStringA::Format("%d", m_ullGetConfigCost).GetData());
  719. LogWarn(Severity_Low, Error_Succeed, VtmLoader_EntityLoad_Cost, CSimpleStringA::Format("%d", (SP::Module::Comm::RVCGetTickCount() - m_ullEntityLoadStart)/1000).GetData());
  720. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_USER).setLogCode("QLR040210F16")("Stage Operating have done.");
  721. NoticeEntityLoadTask* pTask = new NoticeEntityLoadTask(this,Event_VtmLoader_EntityLoad_Finished);
  722. GetEntityBase()->GetFunction()->PostThreadPoolTask(pTask);
  723. }
  724. void CVtmLoaderFSM::s4_on_exit()
  725. {
  726. LOG_FUNCTION();
  727. }
  728. unsigned int CVtmLoaderFSM::s4_on_event(FSMEvent* pEvt)
  729. {
  730. LOG_FUNCTION();
  731. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("s4 event %d,%d", pEvt->iEvt, pEvt->param1);
  732. switch (pEvt->iEvt)
  733. {
  734. default:
  735. break;
  736. }
  737. return 0;
  738. }
  739. //Fault
  740. void CVtmLoaderFSM::s5_on_entry()
  741. {
  742. LOG_FUNCTION();
  743. LogWarn(Severity_High, Error_Unexpect, VtmLoader_EntityLoad_Failed, "实体加载失败,启动终止。请排查启动失败实体或重启应用");
  744. NoticeEntityLoadTask* pTask = new NoticeEntityLoadTask(this, Event_VtmLoader_EntityLoad_Failed);
  745. GetEntityBase()->GetFunction()->PostThreadPoolTask(pTask);
  746. CSmartPointer<IConfigInfo> spConfigCen, spConfigRun;
  747. ErrorCodeEnum eErr = GetEntityBase()->GetFunction()->OpenConfig(Config_CenterSetting, spConfigCen);
  748. eErr = GetEntityBase()->GetFunction()->OpenConfig(Config_Run, spConfigRun);
  749. int failTimes = 0, maxFailTimes = 2;
  750. do {
  751. int value(0);
  752. spConfigCen->ReadConfigValueInt(GetEntityBase()->GetEntityName(), "MaxFailTimes", value);
  753. if (value > 0) {
  754. maxFailTimes = value;
  755. }
  756. } while (false);
  757. spConfigRun->ReadConfigValueInt("Run", "FailTimes", failTimes);
  758. failTimes++;
  759. //LogWarn(Severity_High, Error_Unexpect, LOG_ERR_HEALTH_FAILED, "HealthManager failed.");
  760. //oilyang@20210930 add to call for Close Page
  761. //GetEntityBase()->GetFunction()->SetSysVar("TerminalStage", "C");
  762. //if (failTimes > maxFailTimes)
  763. //{
  764. // //LogEvent(Severity_Middle, LOG_EVT_HEADLIGHT_RED_ON, "设备故障");
  765. // eErr = GetEntityBase()->GetFunction()->SetSysVar("TerminalStage", "D");
  766. // if (eErr != Error_Succeed) {
  767. // DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("set termstage D failed (%d).", eErr);
  768. // }
  769. // else {
  770. // DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("Set TerminalStage D.");
  771. // }
  772. //}
  773. //else
  774. //{
  775. // DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("have failed %d times.", failTimes);
  776. // spConfigRun->WriteConfigValueInt("Run", "FailTimes", failTimes);
  777. // eErr = GetEntityBase()->GetFunction()->SetSysVar("RunState", "F");
  778. // if (eErr != Error_Succeed)
  779. // {
  780. // DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("set RunState failed (%d).", eErr);
  781. // }
  782. //}
  783. }
  784. void CVtmLoaderFSM::s5_on_exit()
  785. {
  786. LOG_FUNCTION();
  787. }
  788. unsigned int CVtmLoaderFSM::s5_on_event(FSMEvent* pEvt)
  789. {
  790. LOG_FUNCTION();
  791. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("s5(Fault) event %d,%d", pEvt->iEvt, pEvt->param1);
  792. switch (pEvt->iEvt)
  793. {
  794. case USER_EVT_ACCESSAUTH_FINISHED:
  795. pEvt->SetHandled();
  796. if (pEvt->param1 == 1)
  797. {
  798. return 1;
  799. }
  800. break;
  801. default:
  802. break;
  803. }
  804. return 0;
  805. }
  806. BOOL CVtmLoaderFSM::DetectNetworkLegality(CSimpleStringA& strInfo)
  807. {
  808. BOOL result(TRUE);
  809. strInfo.Clear();
  810. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("Detect network legality...");
  811. BOOL fLocalLANConnected(FALSE);
  812. unsigned int curTimes = 1;
  813. const unsigned int maxTimes = 3;
  814. do {
  815. CAutoArray<NetworkAdapterItem> netList;
  816. if (SP::Module::Net::GetINETMacAddresses(netList) == Error_Succeed)
  817. {
  818. for (int i = 0; i < netList.GetCount(); i++) {
  819. DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("interface(%d):%s", i, netList[i].description.c_str());
  820. DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("ip(%d):%s", i, netList[i].ip.c_str());
  821. DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("mac(%d):%s", i, netList[i].mac.c_str());
  822. DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("operStatus(%d):%d", i, netList[i].operStatus);
  823. DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("type(%d):%d", i, netList[i].type);
  824. //if (netList[i].type == IF_TYPE_ETHERNET_CSMACD && netList[i].operStatus == IfOperStatusUp)
  825. if (netList[i].operStatus == 1)//oiltest
  826. {
  827. fLocalLANConnected = TRUE;
  828. break;
  829. }
  830. }
  831. }
  832. Sleep(500);
  833. curTimes++;
  834. } while (curTimes < maxTimes && !fLocalLANConnected);
  835. if (!fLocalLANConnected) {
  836. strInfo = "未检查到有网卡连接,请检查网络连接";
  837. result = FALSE;
  838. }
  839. return result;
  840. }
  841. int CVtmLoaderFSM::NetWorkCheckAndGetSetting()
  842. {
  843. //检查网卡状态
  844. DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("to check network status");
  845. CSimpleStringA strMsg(true), tmpTS("X");
  846. //GetEntityBase()->GetFunction()->GetSysVar("TerminalStage", tmpTS);
  847. int netcheckCount = 1;
  848. ULLINT ullTmpStart = SP::Module::Comm::RVCGetTickCount();
  849. //for rvc.pad only
  850. if (!m_sysInfo.strTerminalID.IsNullOrEmpty() && m_sysInfo.strTerminalID.SubString(m_sysInfo.strTerminalID.GetLength() - 4, 1).Compare("5") == 0)
  851. DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("%s is pad,no network connection detect.", m_sysInfo.strTerminalID.GetData());
  852. else
  853. {
  854. while (true)
  855. {
  856. if (!DetectNetworkLegality(strMsg)) {
  857. DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_USER).setLogCode("QLR040210F10").setResultCode("RTA1F00")("can't find valid network interface");
  858. LogWarn(Severity_High, Error_Unexpect, VtmLoader_BootInfoPrint, CSimpleStringA::Format("%s。%d 秒后自动重试(第%d次重试)。请检查网线是否插好、网络是否正常"
  859. , strMsg.GetData(), m_iDetectInterval / 1000, netcheckCount).GetData());
  860. //if (tmpTS.Compare("E") != 0)
  861. //{
  862. // GetEntityBase()->GetFunction()->SetSysVar("TerminalStage", "E");
  863. // tmpTS = "E";
  864. //}
  865. Sleep(5000);
  866. netcheckCount++;
  867. }
  868. else
  869. {
  870. m_ullNetCardCost = (SP::Module::Comm::RVCGetTickCount() - ullTmpStart) / 1000;//second
  871. LogWarn(Severity_Low, Error_Succeed, VtmLoader_BootInfoPrint, "网卡状态正常");
  872. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_USER).setLogCode("QLR040210F10")("network interface ok.");
  873. break;
  874. }
  875. }
  876. ullTmpStart = SP::Module::Comm::RVCGetTickCount();
  877. //检查网络连通性(网络连通性是否作为关键路径走配置,默认不是关键路径)
  878. if (!DetectHttpActive())
  879. {
  880. //网络连通性检查未通过,提示确认网络后重启应用?界面加一个重启按钮?
  881. LogWarn(Severity_High, Error_Unexpect, VtmLoader_BootInfoPrint, "网络连通性检查失败,请检查网络");
  882. return -1;
  883. }
  884. }
  885. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_USER).setLogCode("QLR040210F11")("connect to http(s) service ok.");
  886. m_ullNetDetectCost = (SP::Module::Comm::RVCGetTickCount() - ullTmpStart) / 1000;//second
  887. ToCheckIfInstalling();
  888. ullTmpStart = SP::Module::Comm::RVCGetTickCount();
  889. //拉取配置并通知提前启动的实体(Chromium)
  890. //重试5次,失败则放弃
  891. int getRetry = 0;
  892. while(true)
  893. {
  894. if (GetConfig())
  895. break;
  896. else
  897. {
  898. if (getRetry >= 5)
  899. return -2;
  900. getRetry++;
  901. Sleep(5000 * getRetry);
  902. }
  903. }
  904. m_ullGetConfigCost = (SP::Module::Comm::RVCGetTickCount() - ullTmpStart) / 1000;//second
  905. //加载实体列表
  906. CSimpleStringA csTmpRootIni("");
  907. if (!IsRootINIExist(csTmpRootIni))
  908. {
  909. DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_USER)(CSimpleStringA::Format("root.ini不存在(%s),Set TerminalStage N ", csTmpRootIni.GetData()).GetData());
  910. GetEntityBase()->GetFunction()->SetSysVar("TerminalStage", "N");
  911. }
  912. return EntityLoad();
  913. }
  914. int CVtmLoaderFSM::EntityLoad()
  915. {
  916. //前提:收到了配置拉取完成的指令,才会进入到这里
  917. //为了测试,假装已经拿到了集中配置
  918. m_ullEntityLoadStart = SP::Module::Comm::RVCGetTickCount();
  919. LogWarn(Severity_Low, Error_Succeed, VtmLoader_BootInfoPrint, "开始加载实体");
  920. CSmartPointer<IConfigInfo> spConfigCen,spRunCfg;
  921. GetEntityBase()->GetFunction()->OpenConfig(Config_CenterSetting, spConfigCen);
  922. GetEntityBase()->GetFunction()->OpenConfig(Config_Run, spRunCfg);
  923. CSimpleStringA csCoreBootList(true), csSafeLoadList(true), csOperatingList(true),csKeyCB("CoreBootList."),csKeySL("SafeLoadList."),csKeyOp("OperatingList.");
  924. spConfigCen->ReadConfigValue(GetEntityBase()->GetEntityName(), (csKeyCB + m_sysInfo.strMachineType).GetData(), csCoreBootList);
  925. spConfigCen->ReadConfigValue(GetEntityBase()->GetEntityName(), (csKeySL + m_sysInfo.strMachineType).GetData(), csSafeLoadList);
  926. spConfigCen->ReadConfigValue(GetEntityBase()->GetEntityName(), (csKeyOp + m_sysInfo.strMachineType).GetData(), csOperatingList);
  927. DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("CoreBoot.EntityList.%s:%s", m_sysInfo.strMachineType.GetData(), csCoreBootList.GetData());
  928. DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("SafeLoad.EntityList.%s:%s", m_sysInfo.strMachineType.GetData(), csSafeLoadList.GetData());
  929. DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("Operating.EntityList.%s:%s", m_sysInfo.strMachineType.GetData(), csOperatingList.GetData());
  930. //oiltmp 如果没有配置,则走默认配置
  931. if (csCoreBootList.IsNullOrEmpty() || csCoreBootList.IndexOf("HealthManager") < 0 || csCoreBootList.IndexOf("AccessAuthorization") < 0
  932. || csCoreBootList.IndexOf("UpgradeManager") < 0 || csCoreBootList.IndexOf("HeartBeat") < 0
  933. || csCoreBootList.IndexOf("TokenKeeper") < 0 || csCoreBootList.IndexOf("ResourceWatcher") < 0
  934. || csCoreBootList.IndexOf("EventConverter") < 0 || csCoreBootList.IndexOf("Alarm") < 0
  935. || csCoreBootList.IndexOf("CenterSetting") < 0 || csCoreBootList.IndexOf("DeviceControl") < 0)
  936. {
  937. if (csCoreBootList.IsNullOrEmpty())
  938. {
  939. LogWarn(Severity_High, Error_Unexpect, VtmLoader_BootInfoPrint, "CoreBoot配置为空,请联系总行开发人员检查");
  940. DbgWithLink(LOG_LEVEL_ERROR, LOG_TYPE_SYSTEM).setLogCode("QLR040210F14").setResultCode("RTA1F05")("CoreBoot配置为空,请联系总行开发人员检查");
  941. }
  942. else
  943. {
  944. LogWarn(Severity_High, Error_Unexpect, VtmLoader_BootInfoPrint, CSimpleStringA::Format("CoreBoot配置异常,请联系总行开发人员检查(%s)", csCoreBootList.GetData()).GetData());
  945. DbgWithLink(LOG_LEVEL_ERROR, LOG_TYPE_SYSTEM).setLogCode("QLR040210F14").setResultCode("RTA1F05")(CSimpleStringA::Format("CoreBoot配置异常,请联系总行开发人员检查(%s)", csCoreBootList.GetData()));
  946. }
  947. //if have PinPad module
  948. //if (m_sysInfo.strMachineType.Compare("RVC.CardStore", true) == 0)
  949. // csCoreBootList = "HealthManager=0|TokenKeeper=0|Alarm=0|UpgradeManager=0|DeviceControl=0|ResourceWatcher=0|AccessAuthorization=0|HeartBeat=0|EventConverter=0|CenterSetting=0";
  950. //else
  951. // csCoreBootList = "HealthManager=0|TokenKeeper=0|Alarm=0|UpgradeManager=0|DeviceControl=0|ResourceWatcher=0|AccessAuthorization=0|HeartBeat=0|EventConverter=0|CenterSetting=0|PinPad=0";
  952. }
  953. spConfigCen->ReadConfigValueInt(GetEntityBase()->GetEntityName(), "SleepEnterOpMS", m_sleepEnterOpMS);
  954. if (m_sleepEnterOpMS <= 0 || m_sleepEnterOpMS > 20000)
  955. m_sleepEnterOpMS = 1000;//default
  956. //save centersetting to runcfg for vtmloader. using it before download centersetting
  957. int iTmp = 0;
  958. if (spConfigCen->ReadConfigValueInt("Common", "CanIgnoreAddrDetect", iTmp) == Error_Succeed && iTmp > 0)
  959. spRunCfg->WriteConfigValueInt("Common", "CanIgnoreAddrDetect", iTmp);
  960. iTmp = 0;
  961. if (spConfigCen->ReadConfigValueInt("Common", "MaxAddrDetectTimes", iTmp) == Error_Succeed && iTmp > 0)
  962. spRunCfg->WriteConfigValueInt("Common", "MaxAddrDetectTimes", iTmp);
  963. iTmp = 0;
  964. if (spConfigCen->ReadConfigValueInt("Common", "AddrDetectInterval", iTmp) == Error_Succeed && iTmp > 0)
  965. spRunCfg->WriteConfigValueInt("Common", "AddrDetectInterval", iTmp);
  966. CSimpleStringA csTmpAddr(true);
  967. if (spConfigCen->ReadConfigValue("Common", "SettingDetectAddr", csTmpAddr) == Error_Succeed && !csTmpAddr.IsNullOrEmpty())
  968. spRunCfg->WriteConfigValue("Common", "SettingDetectAddr", csTmpAddr.GetData());
  969. csTmpAddr = "";
  970. if (spConfigCen->ReadConfigValue("Common", "AccessAuthDetectAddr", csTmpAddr) == Error_Succeed && !csTmpAddr.IsNullOrEmpty())
  971. spRunCfg->WriteConfigValue("Common", "AccessAuthDetectAddr", csTmpAddr.GetData());
  972. //int count, cbNum, slNum, opNum;
  973. //count = cbNum = slNum = opNum = 0;
  974. CAutoArray<CSimpleStringA> arrCoreBoot;
  975. arrCoreBoot.Init(64);
  976. arrCoreBoot = csCoreBootList.Split('|');
  977. for (int i = 0; i < arrCoreBoot.GetCount(); ++i)
  978. {
  979. CAutoArray<CSimpleStringA> arrEntity;
  980. arrEntity.Init(2);
  981. arrEntity = arrCoreBoot[i].Split('=');
  982. if (arrEntity.GetCount() < 2)
  983. break;
  984. if (arrEntity[0].Compare("VtmLoader", true) == 0 || arrEntity[0].Compare("Chromium", true) == 0
  985. || arrEntity[0].Compare("GuiConsole", true) == 0)
  986. continue;
  987. m_vCoreBoot.push_back(arrEntity[0]);
  988. if (arrEntity[1].Compare("1") == 0)
  989. m_coreBootOpt[arrEntity[0]].loadOpt = LOADOPT_ASYNC_VERIFY;
  990. else if (arrEntity[1].Compare("2") == 0)
  991. m_coreBootOpt[arrEntity[0]].loadOpt = LOADOPT_SYNC_VERIFY;
  992. else
  993. m_coreBootOpt[arrEntity[0]].loadOpt = LOADOPT_IGNORE;
  994. m_coreBootOpt[arrEntity[0].GetData()].eResult = LOADING_INIT;
  995. //m_entityBootOpt[arrEntity[0].GetData()].initSn = cbNum;
  996. //cbNum++;
  997. }
  998. CAutoArray<CSimpleStringA> arrSafeLoad;
  999. arrSafeLoad.Init(64);
  1000. arrSafeLoad = csSafeLoadList.Split('|');
  1001. for (int i = 0; i < arrSafeLoad.GetCount(); ++i)
  1002. {
  1003. CAutoArray<CSimpleStringA> arrEntity;
  1004. arrEntity.Init(2);
  1005. arrEntity = arrSafeLoad[i].Split('=');
  1006. if (arrEntity.GetCount() < 2)
  1007. break;
  1008. if (arrEntity[0].Compare("VtmLoader", true) == 0 || arrEntity[0].Compare("Chromium", true) == 0
  1009. || arrEntity[0].Compare("GuiConsole", true) == 0)
  1010. continue;
  1011. //去重,防止前面已经加载了
  1012. if (find(m_vCoreBoot.begin(), m_vCoreBoot.end(), arrEntity[0].GetData()) != m_vCoreBoot.end())
  1013. continue;
  1014. m_vSafeLoad.push_back(arrEntity[0].GetData());
  1015. if (arrEntity[1].Compare("1") == 0)
  1016. m_safeLoadOpt[arrEntity[0]].loadOpt = LOADOPT_ASYNC_VERIFY;
  1017. else if (arrEntity[1].Compare("2") == 0)
  1018. m_safeLoadOpt[arrEntity[0]].loadOpt = LOADOPT_SYNC_VERIFY;
  1019. else
  1020. m_safeLoadOpt[arrEntity[0]].loadOpt = LOADOPT_IGNORE;
  1021. m_safeLoadOpt[arrEntity[0].GetData()].eResult = LOADING_INIT;
  1022. //m_safeLoadOpt[arrEntity[0].GetData()].initSn = slNum;
  1023. //slNum++;
  1024. }
  1025. CAutoArray<CSimpleStringA> arrOperating;
  1026. arrOperating.Init(64);
  1027. arrOperating = csOperatingList.Split('|');
  1028. for (int i = 0; i < arrOperating.GetCount(); ++i)
  1029. {
  1030. CAutoArray<CSimpleStringA> arrEntity;
  1031. arrEntity.Init(2);
  1032. arrEntity = arrOperating[i].Split('=');
  1033. if (arrEntity.GetCount() < 2)
  1034. break;
  1035. if (arrEntity[0].Compare("VtmLoader", true) == 0 || arrEntity[0].Compare("Chromium", true) == 0
  1036. || arrEntity[0].Compare("GuiConsole", true) == 0)
  1037. continue;
  1038. //去重,防止前面已经加载了
  1039. if (find(m_vCoreBoot.begin(), m_vCoreBoot.end(), arrEntity[0].GetData()) != m_vCoreBoot.end()
  1040. || find(m_vSafeLoad.begin(), m_vSafeLoad.end(), arrEntity[0].GetData()) != m_vSafeLoad.end())
  1041. continue;
  1042. m_vOperating.push_back(arrEntity[0].GetData());
  1043. if (arrEntity[1].Compare("1") == 0)
  1044. m_operatingOpt[arrEntity[0]].loadOpt = LOADOPT_ASYNC_VERIFY;
  1045. else if (arrEntity[1].Compare("2") == 0)
  1046. m_operatingOpt[arrEntity[0]].loadOpt = LOADOPT_SYNC_VERIFY;
  1047. else
  1048. m_operatingOpt[arrEntity[0]].loadOpt = LOADOPT_IGNORE;
  1049. m_operatingOpt[arrEntity[0].GetData()].eResult = LOADING_INIT;
  1050. //m_operatingOpt[arrEntity[0].GetData()].initSn = opNum;
  1051. //opNum++;
  1052. }
  1053. //oilyang if install VTM ,just wait for msg to start entity
  1054. CSimpleStringA csTermStage("");
  1055. ErrorCodeEnum eErrCode;
  1056. eErrCode = GetEntityBase()->GetFunction()->GetSysVar("TerminalStage", csTermStage);
  1057. DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("TerminalStage %s.", csTermStage.GetData());
  1058. if (csTermStage.Compare("N") == 0)//"N" for installing
  1059. {
  1060. //start UpgradeManager
  1061. CSmartPointer<IEntityFunctionPrivilege> pFuncPrivilege = m_pEntity->GetFunction().ConvertCase<IEntityFunctionPrivilege>();
  1062. CSmartPointer<IAsynWaitSp> spWait;
  1063. eErrCode = pFuncPrivilege->StartEntity("UpgradeManager", NULL, spWait);
  1064. if (eErrCode == Error_Succeed)
  1065. {
  1066. if (spWait != NULL)
  1067. eErrCode = spWait->WaitAnswer(MAX_AYSNC_TIMEOUT);
  1068. }
  1069. else
  1070. {
  1071. DbgWithLink(LOG_LEVEL_ERROR, LOG_TYPE_SYSTEM)("StartEntity UpgradeManager failed(%d).", eErrCode);
  1072. return -1;
  1073. }
  1074. eErrCode = pFuncPrivilege->StartEntity("HealthManager", NULL, spWait);
  1075. if (eErrCode == Error_Succeed)
  1076. {
  1077. if (spWait != NULL)
  1078. eErrCode = spWait->WaitAnswer(MAX_AYSNC_TIMEOUT);
  1079. }
  1080. else
  1081. {
  1082. DbgWithLink(LOG_LEVEL_ERROR, LOG_TYPE_SYSTEM)("StartEntity HealthManager failed(%d).", eErrCode);
  1083. return -1;
  1084. }
  1085. eErrCode = pFuncPrivilege->StartEntity("InteractiveControl", NULL, spWait);
  1086. if (eErrCode == Error_Succeed)
  1087. {
  1088. if (spWait != NULL)
  1089. eErrCode = spWait->WaitAnswer(MAX_AYSNC_TIMEOUT);
  1090. }
  1091. else
  1092. {
  1093. DbgWithLink(LOG_LEVEL_ERROR, LOG_TYPE_SYSTEM)("StartEntity InteractiveControl failed(%d).", eErrCode);
  1094. return -1;
  1095. }
  1096. //wait for all the things have beed done,then save TerminalNo to root.ini
  1097. while (true)
  1098. {
  1099. m_hSaveTerminalNoVar.Wait();
  1100. return 1;
  1101. }
  1102. }
  1103. return 0;
  1104. }
  1105. int CVtmLoaderFSM::CheckLoadResult(LoadStage eStage)
  1106. {
  1107. int ret = 0;
  1108. CSimpleStringA csLogCode = "QLR040210F14";
  1109. map<CSimpleStringA, EntityLoadInfo>::iterator it;
  1110. if (eStage == LOADSTAGE_COREBOOT)
  1111. it = m_coreBootOpt.begin();
  1112. else if (eStage == LOADSTAGE_SAFELOAD)
  1113. {
  1114. it = m_safeLoadOpt.begin();
  1115. csLogCode = "QLR040210F15";
  1116. }
  1117. else
  1118. {
  1119. it = m_operatingOpt.begin();
  1120. csLogCode = "QLR040210F16";
  1121. }
  1122. while (1)
  1123. {
  1124. switch (it->second.loadOpt)
  1125. {
  1126. case LOADOPT_IGNORE:
  1127. if (it->second.eResult == LOADING_INIT)
  1128. return 1;
  1129. break;
  1130. case LOADOPT_ASYNC_VERIFY:
  1131. case LOADOPT_SYNC_VERIFY:
  1132. default:
  1133. if (it->second.eResult == LOADING_INIT)
  1134. return 3;
  1135. else if (it->second.eResult != LOADING_SUCCEED)
  1136. {
  1137. DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_USER).setLogCode(csLogCode).setResultCode("RTA1F04")("%s start failed", m_csErrEntity);
  1138. m_csErrEntity = m_csErrEntity + "|" + it->first;
  1139. ret = 2;
  1140. }
  1141. break;
  1142. }
  1143. it++;
  1144. if (eStage == LOADSTAGE_COREBOOT && it == m_coreBootOpt.end())
  1145. break;
  1146. else if (eStage == LOADSTAGE_SAFELOAD && it == m_safeLoadOpt.end())
  1147. break;
  1148. else if (eStage == LOADSTAGE_OPERATING && it == m_operatingOpt.end())
  1149. break;
  1150. }
  1151. return ret;
  1152. }
  1153. ErrorCodeEnum CVtmLoaderFSM::AsyncStartEntity(const char* entity_name, const char* cmdline, void* pData)
  1154. {
  1155. CSmartPointer<IEntityFunction> pFunc = m_pEntity->GetFunction();
  1156. ErrorCodeEnum errCode;
  1157. CSmartPointer<IEntityFunctionPrivilege> pFuncPrivilege = pFunc.ConvertCase<IEntityFunctionPrivilege>();
  1158. if (pFuncPrivilege != NULL) {
  1159. CSmartPointer<IAsynWaitSp> spWait;
  1160. errCode = pFuncPrivilege->StartEntity(entity_name, cmdline, spWait);
  1161. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI("AsyncStartEntity")("start entity %s", entity_name);
  1162. if (errCode == Error_Succeed) {
  1163. callback_entry* entry = new callback_entry();
  1164. entry->pRawData = pData;
  1165. entry->EntityName = entity_name;
  1166. entry->ErrorResult = Error_Unexpect;
  1167. entry->op = OP_START_ENTITY;
  1168. if (spWait != NULL)
  1169. spWait->SetCallback(this, entry);
  1170. }
  1171. return errCode;
  1172. }
  1173. else {
  1174. return Error_NoPrivilege;
  1175. }
  1176. }
  1177. void CVtmLoaderFSM::OnAnswer(CSmartPointer<IAsynWaitSp> pAsynWaitSp)
  1178. {
  1179. CSmartPointer<ICallbackListener> spCallback;
  1180. CSmartPointer<IReleasable> pData;
  1181. pAsynWaitSp->GetCallback(spCallback, pData);
  1182. callback_entry* entry = dynamic_cast<callback_entry*>((IReleasable*)(pData.GetRawPointer()));
  1183. entry->ErrorResult = pAsynWaitSp->AsyncGetAnswer();
  1184. callback_entry* new_entry = new callback_entry();
  1185. new_entry->EntityName = entry->EntityName;
  1186. new_entry->ErrorResult = entry->ErrorResult;
  1187. new_entry->op = entry->op;
  1188. new_entry->state = entry->state;
  1189. map<CSimpleStringA, EntityLoadInfo>::iterator it;
  1190. int ret;
  1191. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI("OnAnswer")("stage %d,%s,result %d", m_eStage, (LPCSTR)new_entry->EntityName, new_entry->ErrorResult);
  1192. switch (m_eStage)
  1193. {
  1194. case LOADSTAGE_COREBOOT:
  1195. it = m_coreBootOpt.find(new_entry->EntityName);
  1196. if (it != m_coreBootOpt.end())
  1197. {
  1198. if (new_entry->ErrorResult == Error_Succeed)
  1199. it->second.eResult = LOADING_SUCCEED;
  1200. else if (new_entry->ErrorResult == Error_TimeOut)
  1201. it->second.eResult = LOADING_TIMEOUT;
  1202. else
  1203. it->second.eResult = LOADING_FAILED;
  1204. if (it->second.eResult != Error_Succeed)
  1205. {
  1206. char tmp[64] = { 0 };
  1207. sprintf(tmp, "实体 %s 启动失败-----", it->first.GetData());
  1208. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI("OnAnswer")("启动失败:%s -----", tmp);
  1209. }
  1210. ret = CheckLoadResult(LOADSTAGE_COREBOOT);
  1211. if (ret == 0 || ret == 2)
  1212. {
  1213. FSMEvent* e = new FSMEvent(USER_EVT_COREBOOT_FINISHED);
  1214. e->param1 = ret;
  1215. PostEventFIFO(e);
  1216. }
  1217. }
  1218. break;
  1219. case LOADSTAGE_SAFELOAD:
  1220. it = m_safeLoadOpt.find(new_entry->EntityName);
  1221. if (it != m_safeLoadOpt.end())
  1222. {
  1223. if (new_entry->ErrorResult == Error_Succeed)
  1224. it->second.eResult = LOADING_SUCCEED;
  1225. else if (new_entry->ErrorResult == Error_TimeOut)
  1226. it->second.eResult = LOADING_TIMEOUT;
  1227. else
  1228. it->second.eResult = LOADING_FAILED;
  1229. ret = CheckLoadResult(LOADSTAGE_SAFELOAD);
  1230. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI("OnAnswer")("safeload answer %d", ret);
  1231. if (ret == 0 || ret == 2)
  1232. {
  1233. FSMEvent* e = new FSMEvent(USER_EVT_SAFELOAD_FINISHED);
  1234. e->param1 = ret;
  1235. PostEventFIFO(e);
  1236. }
  1237. }
  1238. else {
  1239. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI("OnAnswer")("cannot find %s", (LPCTSTR)new_entry->EntityName);
  1240. }
  1241. break;
  1242. case LOADSTAGE_OPERATING:
  1243. it = m_operatingOpt.find(new_entry->EntityName);
  1244. if (it != m_operatingOpt.end())
  1245. {
  1246. if (new_entry->ErrorResult == Error_Succeed)
  1247. it->second.eResult = LOADING_SUCCEED;
  1248. else if (new_entry->ErrorResult == Error_TimeOut)
  1249. it->second.eResult = LOADING_TIMEOUT;
  1250. else
  1251. it->second.eResult = LOADING_FAILED;
  1252. ret = CheckLoadResult(LOADSTAGE_OPERATING);
  1253. if (ret == 0 || ret == 2)
  1254. {
  1255. FSMEvent* e = new FSMEvent(USER_EVT_OPERATING_FINISHED);
  1256. e->param1 = ret;
  1257. PostEventFIFO(e);
  1258. }
  1259. }
  1260. break;
  1261. default:
  1262. break;
  1263. }
  1264. }
  1265. void CVtmLoaderFSM::NoticeEntityLoad(int evtCode)
  1266. {
  1267. HealthManagerService_ClientBase* pHMClient = new HealthManagerService_ClientBase(m_pEntity);
  1268. int count = 0;
  1269. bool bConnected = false;
  1270. do
  1271. {
  1272. ErrorCodeEnum eErrConn = Error_Unexpect;
  1273. ErrorCodeEnum eErrCall = Error_Unexpect;
  1274. if (!bConnected)
  1275. {
  1276. eErrConn = pHMClient->Connect();
  1277. if (eErrConn == Error_Succeed)
  1278. bConnected = true;
  1279. }
  1280. if (bConnected)
  1281. {
  1282. HealthManagerService_DoEvent_Req req;
  1283. HealthManagerService_DoEvent_Ans ans;
  1284. req.code = evtCode;
  1285. eErrCall = pHMClient->DoEvent(req, ans, 5000);
  1286. if (eErrCall == Error_Succeed)
  1287. break;
  1288. }
  1289. DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM)("Notice HealthManager failed,eErrConn:%d,eErrCall:%d", eErrConn, eErrCall);
  1290. Sleep(2000);
  1291. count++;
  1292. } while (count < 100);
  1293. }
  1294. bool CVtmLoaderFSM::DetectHttpActive()
  1295. {
  1296. memset(m_httpCheckResult, 0, sizeof(m_httpCheckResult));
  1297. CSmartPointer<IConfigInfo> pConfigRun;
  1298. CSimpleStringA strSettingAddr(true),strAccessAuthAddr(true);
  1299. CSimpleStringA errMsg;
  1300. ErrorCodeEnum eErr = GetEntityBase()->GetFunction()->OpenConfig(Config_Run, pConfigRun);
  1301. if (eErr == Error_Succeed)
  1302. {
  1303. int iTmp = 0;
  1304. if (pConfigRun->ReadConfigValueInt("Common", "CanIgnoreAddrDetect", iTmp) == Error_Succeed && iTmp > 0)
  1305. m_iCanIgnoreAddrDetect = iTmp;
  1306. iTmp = 0;
  1307. if (pConfigRun->ReadConfigValueInt("Common", "MaxAddrDetectTime", iTmp) == Error_Succeed && iTmp > 0)
  1308. m_ullMaxAddrDetectTime = iTmp;
  1309. iTmp = 0;
  1310. if (pConfigRun->ReadConfigValueInt("Common", "AddrDetectInterval", iTmp) == Error_Succeed && iTmp > 0)
  1311. m_iDetectInterval = iTmp;
  1312. }
  1313. DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("eErr:%d, iDetectInterval:%d", eErr, m_iDetectInterval);
  1314. //oiltmp 由于行外pad即将下线,暂时不考虑行外地址探测
  1315. CSimpleStringA csTmpAddr(true);
  1316. //集中配置探测地址
  1317. pConfigRun->ReadConfigValue("Common", "SettingDetectAddr", csTmpAddr);
  1318. if (csTmpAddr.IsNullOrEmpty())
  1319. {
  1320. #ifdef DEVOPS_ON_ST /*DevOps流水线编译,ST环境*/
  1321. strSettingAddr = "https://accessproxy-service.paasst.cmbchina.cn/centerconfig/rvc/detect";
  1322. #elif defined(DEVOPS_ON_PRD)/*DevOps流水线编译,PRD环境*/
  1323. strSettingAddr = "https://accessproxy-service.paas.cmbchina.cn/centerconfig/rvc/detect";
  1324. #elif defined(DEVOPS_ON_UAT)/*DevOps流水线编译,UAT环境*/
  1325. strSettingAddr = "https://accessproxy-service.paasuat.cmbchina.cn/centerconfig/rvc/detect";
  1326. #elif defined(DEVOPS_ON_DEV)/*DevOps流水线编译,Dev环境*/
  1327. strSettingAddr = "https://accessproxy-service.paas.cmbchina.cn/centerconfig/rvc/detect";
  1328. #else/*本地编译等非DevOps环境编译的版本*/
  1329. strSettingAddr = "https://accessproxy-service.paasst.cmbchina.cn/centerconfig/rvc/detect";
  1330. #endif
  1331. }
  1332. else
  1333. strSettingAddr = csTmpAddr;
  1334. csTmpAddr = "";
  1335. pConfigRun->ReadConfigValue("Common", "AccessAuthDetectAddr", strAccessAuthAddr);
  1336. //准入探测地址
  1337. if (strAccessAuthAddr.IsNullOrEmpty())
  1338. {
  1339. #ifdef DEVOPS_ON_ST /*DevOps流水线编译,ST环境*/
  1340. strAccessAuthAddr = "https://terminalaccess.paasst.cmbchina.cn/tsas/detect";
  1341. #elif defined(DEVOPS_ON_PRD)/*DevOps流水线编译,PRD环境*/
  1342. strAccessAuthAddr = "https://accessproxy-service.paas.cmbchina.cn/tsaccess/tsas/detect";
  1343. #elif defined(DEVOPS_ON_UAT)/*DevOps流水线编译,UAT环境*/
  1344. strAccessAuthAddr = "https://terminalaccess.paasuat.cmbchina.cn/tsas/detect";
  1345. #elif defined(DEVOPS_ON_DEV)/*DevOps流水线编译,Dev环境*/
  1346. strAccessAuthAddr = "https://terminalaccess.paas.cmbchina.cn/tsas/detect";
  1347. #else/*本地编译等非DevOps环境编译的版本*/
  1348. strAccessAuthAddr = "https://terminalaccess.paasst.cmbchina.cn/tsas/detect";
  1349. #endif
  1350. }
  1351. else
  1352. strAccessAuthAddr = csTmpAddr;
  1353. DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("CenterSetting addr:%s, strAccessAuthAddr:%s", strSettingAddr.GetData(), strAccessAuthAddr.GetData());
  1354. HttpConnCheckTask* pCSTask = new HttpConnCheckTask(this, strSettingAddr, HttpAddr_CenterSetting);
  1355. GetEntityBase()->GetFunction()->PostThreadPoolTask(pCSTask);
  1356. HttpConnCheckTask* pAATask = new HttpConnCheckTask(this, strAccessAuthAddr, HttpAddr_AccessAuth);
  1357. GetEntityBase()->GetFunction()->PostThreadPoolTask(pAATask);
  1358. ULLINT beginTick, endTick;
  1359. beginTick = SP::Module::Comm::RVCGetTickCount();
  1360. do {
  1361. Sleep(2000);
  1362. if (m_httpCheckResult[HttpAddr_CenterSetting] == HttpConnResult_OK || m_httpCheckResult[HttpAddr_AccessAuth] == HttpConnResult_OK)
  1363. return true;
  1364. else
  1365. {
  1366. endTick = SP::Module::Comm::RVCGetTickCount();
  1367. }
  1368. } while (endTick - beginTick < m_ullMaxAddrDetectTime);
  1369. if (m_iCanIgnoreAddrDetect > 0)
  1370. return true;
  1371. else
  1372. return false;
  1373. }
  1374. bool CVtmLoaderFSM::IsRootINIExist(CSimpleStringA& path)
  1375. {
  1376. CSimpleStringA csHardwareCfg(true);
  1377. ErrorCodeEnum eErr = GetEntityBase()->GetFunction()->GetPath("HardwareCfg", csHardwareCfg);
  1378. if (eErr != Error_Succeed)
  1379. {
  1380. path = CSimpleStringA::Format("GetPath of HardwareCfg failed(%d)", eErr);
  1381. DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM)("get path of Run failed:%s", SpStrError(eErr));
  1382. return false;
  1383. }
  1384. path = csHardwareCfg + SPLIT_SLASH_STR + "root.ini";
  1385. #if defined(RVC_OS_WIN)
  1386. if (_access(path.GetData(), 0) == 0) {
  1387. #else
  1388. if (access(path.GetData(), F_OK) == 0) {
  1389. #endif
  1390. return true;
  1391. }
  1392. else
  1393. {
  1394. DbgWithLink(LOG_LEVEL_ERROR, LOG_TYPE_SYSTEM)("root.ini(%s) is not exist.", path.GetData());
  1395. return false;
  1396. }
  1397. }
  1398. bool CVtmLoaderFSM::VerifyVer()
  1399. {
  1400. CSmartPointer<IConfigInfo> pConfig;
  1401. GetEntityBase()->GetFunction()->OpenConfig(Config_CenterSetting, pConfig);
  1402. int VerifyVersion = 0;
  1403. CSimpleStringA activeVer;
  1404. bool isVerEqual = false;
  1405. if (Error_Succeed != pConfig->ReadConfigValueInt("Common", "VerifyVersion", VerifyVersion) || Error_Succeed != GetEntityBase()->GetFunction()->GetRunningVersion(activeVer))
  1406. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("read [Common]VerifyVersion failed");
  1407. #ifdef RVC_OS_WIN
  1408. std::string curVer = std::to_string((ULONGLONG)VER_Major) + "." + std::to_string((ULONGLONG)VER_Minor)
  1409. + "." + std::to_string((ULONGLONG)VER_Revision) + "." + std::to_string((ULONGLONG)VER_Build);
  1410. #else
  1411. std::string curVer = std::string(RVC_VERSION_STR);
  1412. #endif
  1413. if (curVer == activeVer.GetData())
  1414. isVerEqual = true;
  1415. if (!isVerEqual)
  1416. {
  1417. CSimpleString showMsg = CSimpleString::Format("version not equal, file version:%s, acitve verion:%s", curVer.c_str(), activeVer.GetData());
  1418. switch (VerifyVersion)
  1419. {
  1420. case 0:
  1421. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)(showMsg.GetData());
  1422. break;
  1423. case 1:
  1424. m_verShowMsg = showMsg;
  1425. CloseHandle(CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)&AlarmVersionErr, this, 0, NULL));
  1426. break;
  1427. case 2:
  1428. m_verShowMsg = showMsg;
  1429. CloseHandle(CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)&AlarmVersionErr, this, 0, NULL));
  1430. return false;
  1431. break;
  1432. default:
  1433. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("VerifyVersion not support param:%d", VerifyVersion);
  1434. break;
  1435. }
  1436. }
  1437. return true;
  1438. }
  1439. bool CVtmLoaderFSM::GetConfig()
  1440. {
  1441. //拉取配置前先检查root.ini文件
  1442. CSimpleStringA csTmpRootIni("");
  1443. if (!IsRootINIExist(csTmpRootIni) && m_terminalNoFromWeb.IsNullOrEmpty())
  1444. {
  1445. LogWarn(Severity_High, Error_Unexpect, VtmLoader_BootInfoPrint, CSimpleStringA::Format("root.ini不存在或安装页面未设置终端号,请检查(%s)", csTmpRootIni.GetData()).GetData());
  1446. return false;
  1447. }
  1448. ErrorCodeEnum eErr = Error_Succeed;
  1449. #ifdef DEVOPS_ON_ST /*DevOps流水线编译,ST环境*/
  1450. CSimpleString channelId = "5fdd82e3b90a4de69f9da4738e5f1216";
  1451. CSimpleString tokenSecret = "eca829c78067c686561bd844129321c8a78af3";
  1452. CSimpleString CommonLaunchUrl = "https://rvc-gateway.paasst.cmbchina.cn|https://rvc-gateway-out.paasst.cmbchina.cn";
  1453. CSimpleString CenterConfigTotal = "https://accessproxy-service.paasst.cmbchina.cn/centerconfig";
  1454. #elif defined(DEVOPS_ON_UAT)/*DevOps流水线编译,UAT环境*/
  1455. CSimpleString channelId = "7eb748cb71744c87b5c126e05af8cce7";
  1456. CSimpleString tokenSecret = "eca529c78967c640561bd844229391c8a78af3";
  1457. CSimpleString CommonLaunchUrl = "https://rvc-gateway.paasuat.cmbchina.cn|https://rvc-gateway-out.paasuat.cmbchina.cn";
  1458. CSimpleString CenterConfigTotal = "https://accessproxy-service.paasuat.cmbchina.cn/centerconfig|https://accessproxy-service.paasuat.cmbchina.cn/centerconfigdmz";
  1459. #elif defined(DEVOPS_ON_PRD)/*DevOps流水线编译,PRD环境*/
  1460. CSimpleString channelId = "572f7577fa9f425c8475a8d77db4ae31";
  1461. CSimpleString tokenSecret = "eca129c78767c670561bd844629361c8a78af3";
  1462. CSimpleString CommonLaunchUrl = "https://rvc-gateway.paas.cmbchina.cn|https://vtmunify.paas.cmbchina.com/gateway";
  1463. CSimpleString CenterConfigTotal = "https://accessproxy-service.paas.cmbchina.cn/centerconfig|https://vtmunify.paas.cmbchina.com/centerconfig";
  1464. #else/*本地编译等非DevOps环境编译的版本*/
  1465. CSimpleString channelId = "5fdd82e3b90a4de69f9da4738e5f1216";
  1466. CSimpleString tokenSecret = "eca829c78067c686561bd844129321c8a78af3";
  1467. CSimpleString CommonLaunchUrl = "https://rvc-gateway.paasst.cmbchina.cn";
  1468. CSimpleString CenterConfigTotal = "https://accessproxy-service.paasst.cmbchina.cn/centerconfig";
  1469. #endif
  1470. LogWarn(Severity_Low, Error_Succeed, VtmLoader_BootInfoPrint, "开始拉取配置");
  1471. VTMInitParam vtmInitParam(m_terminalNoFromWeb.GetData(), channelId, tokenSecret, CommonLaunchUrl, CenterConfigTotal);
  1472. if (Error_Succeed != (eErr = GetEntityBase()->GetFunction()->GetPrivilegeFunction()->InitCfgUrl(vtmInitParam)))
  1473. {
  1474. LogWarn(Severity_High, Error_Unexpect, VtmLoader_BootInfoPrint, CSimpleStringA::Format("拉取配置,初始化配置地址失败:0x%x(%s)", eErr, SpStrError(eErr)).GetData());
  1475. DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_USER).setLogCode("QLR040210F13").setResultCode("RTA1F01")("Get config,InitCfgUrl failed.");
  1476. LogEvent(Severity_High, Event_VtmLoader_GetConfig_Fail, "拉取配置,初始化配置地址失败");
  1477. return false;
  1478. }
  1479. else
  1480. {
  1481. CSimpleString oldToken, newToken;
  1482. if (Error_Succeed != (eErr = GetEntityBase()->GetFunction()->GetPrivilegeFunction()->TryUpdateToken(oldToken, newToken)))
  1483. DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_USER).setLogCode("QLR040210F13").setResultCode("RTA1F02")("Get config, TryUpdateToken failed:0x%x", eErr);
  1484. //if token update failed,we can also update cfg suc
  1485. if (Error_Succeed != (eErr = GetEntityBase()->GetFunction()->GetPrivilegeFunction()->TryUpdateCfg()))
  1486. {
  1487. LogWarn(Severity_High, Error_Unexpect, VtmLoader_BootInfoPrint, CSimpleStringA::Format("拉取配置失败:0x%x(%s)", eErr, SpStrError(eErr)).GetData());
  1488. DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_USER).setLogCode("QLR040210F13").setResultCode("RTA1F03")("Get config, TryUpdateCfg failed:0x%x", eErr);
  1489. LogEvent(Severity_High, Event_VtmLoader_GetConfig_Fail, "拉取配置失败");
  1490. return false;
  1491. }
  1492. }
  1493. refreshLogLevel();
  1494. //all cfg is ready, then init the entity
  1495. eErr = SubscribeEntitysEvents();
  1496. if (eErr != Error_Succeed)
  1497. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("subscribe event fail, 0x%x", eErr);
  1498. else
  1499. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("subscribe event succeed");
  1500. CSmartPointer<IConfigInfo> pConfig;
  1501. CSimpleString t_endpoint, t_topicSys, t_topicUser, t_topicBeidou, t_bussSys, t_bussUser;
  1502. eErr = GetEntityBase()->GetFunction()->OpenConfig(Config_CenterSetting, pConfig);
  1503. if (eErr == Error_Succeed && Error_Succeed == pConfig->ReadConfigValue("Common", "SendEndpoint", t_endpoint)
  1504. && Error_Succeed == pConfig->ReadConfigValue("Common", "SendSys", t_topicSys)
  1505. && Error_Succeed == pConfig->ReadConfigValue("Common", "SendUser", t_topicUser)
  1506. && Error_Succeed == pConfig->ReadConfigValue("Common", "SendBeidou", t_topicBeidou)
  1507. && Error_Succeed == pConfig->ReadConfigValue("Common", "BusinessSys", t_bussSys)
  1508. && Error_Succeed == pConfig->ReadConfigValue("Common", "BusinessUser", t_bussUser)
  1509. && 0 != t_topicSys.GetLength()
  1510. && 0 != t_topicUser.GetLength()
  1511. && 0 != t_topicBeidou.GetLength()
  1512. && 0 != t_bussSys.GetLength()
  1513. && 0 != t_bussUser.GetLength())
  1514. {
  1515. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("endpoint:%s, topicSys:%s, topicUser:%s, topicBeidou:%s, bussSys:%s, bussUser:%s", t_endpoint.GetData(), t_topicSys.GetData(), t_topicUser.GetData(), t_topicBeidou.GetData(), t_bussSys.GetData(), t_bussUser.GetData());
  1516. if (0 != t_endpoint.GetLength())
  1517. {
  1518. GetEntityBase()->GetFunction()->GetPrivilegeFunction()->BeginLogSend(t_endpoint.GetData(), t_topicSys.GetData(), t_topicUser.GetData(), t_topicBeidou.GetData(), t_bussSys.GetData(), t_bussUser.GetData());
  1519. }
  1520. else
  1521. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("endpoint is empty, do not begin send log");
  1522. }
  1523. else
  1524. {
  1525. const char* default_endpoint = "https://kafkaproxy.paas.cmbchina.cn/api/kafka/log/send";
  1526. const char* topicSys = "LR18_23_VTMTerminalLogService_L_sys_VTMTerminalSysLog_SRC_SZ";
  1527. const char* topicUser = "LR18_23_VTMTerminalLogService_L_biz_VTMTerminalUserLog_SRC_SZ";
  1528. const char* topicBeidou = "LR18_23_VTMTerminalLogService_L_trace_VTMTerminalTraceLog_SRC_SZ";
  1529. const char* topicBussSys = "LR18_23_VTMTerminalLogService_L_sys_VTMBusiness_SRC_SZ";
  1530. const char* topicBussUser = "LR18_23_VTMTerminalLogService_L_biz_VTMBusiness_SRC_SZ";
  1531. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("read endpoint and topic err, need check centersetting, use default %s-%s-%s-%s-%s-%s", default_endpoint, topicSys, topicUser, topicBeidou, topicBussSys, topicBussUser);
  1532. GetEntityBase()->GetFunction()->GetPrivilegeFunction()->BeginLogSend(default_endpoint, topicSys, topicUser, topicBeidou, topicBussSys, topicBussUser);
  1533. }
  1534. GetEntityBase()->GetFunction()->GetSystemStaticInfo(m_sysInfo);
  1535. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("terminalNo:%s, MachineType:%s, MachineVersion:%s, Site:%s, Screen:%d, EnrolGPS:%f.%f, EnrolAddr:%s"
  1536. , m_sysInfo.strTerminalID.GetData(), m_sysInfo.strMachineType.GetData(), m_sysInfo.MachineVersion.ToString().GetData()
  1537. , m_sysInfo.strSite.GetData(), m_sysInfo.eScreen, m_sysInfo.EnrolGPS.GetLatitude(), m_sysInfo.EnrolGPS.GetLongitude(), m_sysInfo.strEnrolAddr.GetData());
  1538. int tmpSec = 0;
  1539. if (Error_Succeed == pConfig->ReadConfigValueInt(GetEntityBase()->GetEntityName(), "refreshTokenWaitSec", tmpSec) && tmpSec > 0)
  1540. m_refreshWaitSec = tmpSec;
  1541. int t_sec = 0;
  1542. pConfig->ReadConfigValueInt(GetEntityBase()->GetEntityName(), "UploadLogWaitSec", t_sec);
  1543. if (t_sec > 0)
  1544. m_uploadLogInfo_waitSec = t_sec;
  1545. CloseHandle(CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)& checkUrlActive, this, 0, NULL));
  1546. CloseHandle(CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)& tokenUpdate, this, 0, NULL));
  1547. //通知Chromium实体
  1548. LogEvent(Severity_High, Event_VtmLoader_GetConfig_Suc, "Get config succeed.");
  1549. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_USER).setLogCode("QLR040210F13")("Get config succeed.");
  1550. return true;
  1551. }
  1552. ErrorCodeEnum CVtmLoaderFSM::SubscribeEntitysEvents()
  1553. {
  1554. //want to do what?
  1555. auto rc = Error_Succeed;
  1556. //auto pFunc = GetEntityBase()->GetFunction();
  1557. //auto rc = pFunc->SubscribeLog(m_SubLogID2, this, Log_Event, Severity_None, Error_IgnoreAll, -1, "Gpio");
  1558. //// 准入成功事件
  1559. //rc = pFunc->SubscribeLog(m_SubLogID3, this, Log_Event, Severity_None, Error_IgnoreAll, 0x50200001, "AccessAuthorization");
  1560. // 业务首页加载事件
  1561. //rc = pFunc->SubscribeLog(m_SubLogID3, this, Log_Event, Severity_None, Error_IgnoreAll, LOG_EVT_HEALTH_FIRST_ENTER_MAINPADE, "HealthManager");
  1562. return rc;
  1563. }
  1564. int CVtmLoaderFSM::HttpConnCheck(CSimpleStringA csHttAddr, HttpAddrType eType)
  1565. {
  1566. DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("to HttpConnCheck");
  1567. ULLINT beginTick = SP::Module::Comm::RVCGetTickCount();
  1568. int httpcheckCount = 1;
  1569. bool bCheckOK = false;
  1570. while(true){
  1571. #if defined(RVC_OS_LINUX)
  1572. string msg;
  1573. int curFlag = HttpProbe(csHttAddr.GetData(), msg, 5);
  1574. if (curFlag > 0 && curFlag < 400)
  1575. bCheckOK = true;
  1576. #else
  1577. bCheckOK = checkHttpActive(csHttAddr.GetData());
  1578. #endif
  1579. if (!bCheckOK)
  1580. {
  1581. LogWarn(Severity_Middle, Error_Unexpect, VtmLoader_ConnectDetect_Failed, CSimpleStringA::Format("尝试连接总行服务失败(%s),%d 秒后自动重试(第%d次重试)。请确认终端到总行服务网络是否正常", csHttAddr.GetData(), m_iDetectInterval/1000, httpcheckCount).GetData());
  1582. DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_USER).setLogCode("QLR040210F11").setResultCode("RTA1F06")("connect to http(s) service(%s) failed.", csHttAddr.GetData());
  1583. m_httpCheckResult[eType] = HttpConnResult_Failed;
  1584. Sleep(m_iDetectInterval);
  1585. httpcheckCount++;
  1586. CAutoArray<NetworkAdapterItem> netList;
  1587. if (SP::Module::Net::GetINETMacAddresses(netList) == Error_Succeed)
  1588. {
  1589. string tmpDns;
  1590. GetDns(tmpDns);
  1591. for (int i = 0; i < netList.GetCount(); i++) {
  1592. LogWarn(Severity_Low, Error_Unexpect, VtmLoader_BootInfoPrint, CSimpleStringA::Format("(%d)interface:%s; ip:%s; mac:%s; %s", i, netList[i].description.c_str()
  1593. , netList[i].ip.c_str(), netList[i].mac.c_str(), tmpDns.c_str()).GetData());
  1594. }
  1595. }
  1596. }
  1597. else
  1598. {
  1599. m_httpCheckResult[eType] = HttpConnResult_OK;
  1600. if ((SP::Module::Comm::RVCGetTickCount() - beginTick) > 3000)
  1601. {
  1602. LogWarn(Severity_Middle, Error_Unexpect, VtmLoader_ConnectDetect_Slow, CSimpleStringA::Format("第(%d)次尝试连接总行服务成功(%s),但是网络偏慢,连接花了(%d)秒,请检查网络!"
  1603. , httpcheckCount, csHttAddr.GetData(), (SP::Module::Comm::RVCGetTickCount() - beginTick)/1000).GetData());
  1604. }
  1605. DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_USER).setLogCode("QLR040210F11")("尝试连接总行服务成功(%s)", csHttAddr.GetData());
  1606. return 0;
  1607. }
  1608. }
  1609. return -1;
  1610. }
  1611. void CVtmLoaderFSM::GetDns(string& dns)
  1612. {
  1613. dns = "";
  1614. #if defined(RVC_OS_LINUX)
  1615. FILE* stream;
  1616. char* line = NULL;
  1617. size_t len = 0;
  1618. ssize_t read;
  1619. stream = popen("cat /etc/resolv.conf", "r");
  1620. string tmpStr;
  1621. while ((read = getline(&line, &len, stream)) != -1)
  1622. {
  1623. tmpStr = line;
  1624. int pos = tmpStr.find("nameserver");
  1625. if (pos != string::npos)
  1626. {
  1627. tmpStr = tmpStr.replace(pos, strlen("nameserver"), "dns");
  1628. dns += tmpStr + ";";
  1629. }
  1630. }
  1631. int rnPos = dns.find("\n");
  1632. while (rnPos != string::npos)
  1633. {
  1634. dns.replace(rnPos, 1, " ");
  1635. rnPos = dns.find("\n");
  1636. }
  1637. #else
  1638. #endif
  1639. return;
  1640. }
  1641. void CVtmLoaderFSM::ToCheckIfInstalling()
  1642. {
  1643. //拉取配置前先检查root.ini文件
  1644. CSimpleStringA csTmpRootIni("");
  1645. if (!IsRootINIExist(csTmpRootIni))
  1646. {
  1647. DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_USER)(CSimpleStringA::Format("root.ini is not exist(%s).maybe we are in installing,to wait for terminalno", csTmpRootIni.GetData()).GetData());
  1648. //oiltest
  1649. //OilTestTask* task = new OilTestTask(this);
  1650. //GetEntityBase()->GetFunction()->PostThreadPoolTask(task);
  1651. while (true)
  1652. {
  1653. m_hWaitTerminalNoVar.Wait();
  1654. break;
  1655. }
  1656. }
  1657. }
  1658. void CVtmLoaderFSM::CheckDeviceEntity(SpReqAnsContext<VtmLoaderService_CheckDeviceEntity_Req, VtmLoaderService_CheckDeviceEntity_Ans>::Pointer ctx)
  1659. {
  1660. if (!RefreshDeviceConfig(ctx))
  1661. {
  1662. DbgWithLink(LOG_LEVEL_ERROR, LOG_TYPE_SYSTEM)("RefreshDeviceConfig failed.");
  1663. ctx->Answer(Error_Unexpect);
  1664. }
  1665. CEntityStaticInfo staticInfo;
  1666. if (m_pEntity->GetFunction()->GetEntityStaticInfo(ctx->Req.entityName.GetData(), staticInfo) != Error_Succeed)
  1667. {
  1668. ctx->Answer(Error_Unexpect, VtmLoader_FailToGetEntityInfo);
  1669. return;
  1670. }
  1671. switch (staticInfo.wEntityDevelopID)
  1672. {
  1673. case 0x201:
  1674. case 0x203:
  1675. case 0x204:
  1676. case 0x206:
  1677. case 0x213:
  1678. case 0x217:
  1679. CheckDeviceBaseEntity(ctx, staticInfo.wEntityDevelopID);
  1680. break;
  1681. case 0x209://Gpio
  1682. case 0x301://SIPPhone
  1683. CheckEntityRestartIdle(ctx);
  1684. break;
  1685. case 0x208://MediaController
  1686. CheckVideo(ctx);
  1687. default:
  1688. break;
  1689. }
  1690. return;
  1691. }
  1692. void CVtmLoaderFSM::SaveTerminalNo(SpReqAnsContext<VtmLoaderService_SaveTerminalNo_Req, VtmLoaderService_SaveTerminalNo_Ans>::Pointer ctx)
  1693. {
  1694. if (ctx->Req.terminalNo.IsNullOrEmpty())
  1695. {
  1696. DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM)("terminalNo is null or empty");
  1697. ctx->Answer(Error_Param);
  1698. return;
  1699. }
  1700. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_USER)("write terminalNo[%s] to root.ini", ctx->Req.terminalNo.GetData());
  1701. ErrorCodeEnum eErr = GetEntityBase()->GetFunction()->GetPrivilegeFunction()->WriteTerminalNoToRootIni(ctx->Req.terminalNo);
  1702. ctx->Answer(eErr);
  1703. }
  1704. bool CVtmLoaderFSM::RefreshDeviceConfig(SpReqAnsContext<VtmLoaderService_CheckDeviceEntity_Req, VtmLoaderService_CheckDeviceEntity_Ans>::Pointer ctx)
  1705. {
  1706. if (ctx->Req.entityName.IsNullOrEmpty() || ctx->Req.paramNum <= 0)
  1707. {
  1708. DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_USER)("param error! nothing to refresh");
  1709. return false;
  1710. }
  1711. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_USER)("entityName:%s,paramNum:%d,module.GetCount:%d",ctx->Req.entityName.GetData(),ctx->Req.paramNum,ctx->Req.module.GetCount());
  1712. if (ctx->Req.module.GetCount() < ctx->Req.paramNum || ctx->Req.name.GetCount() < ctx->Req.paramNum || ctx->Req.value.GetCount() < ctx->Req.paramNum)
  1713. {
  1714. DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_USER)("param array length error! nothing to refresh");
  1715. return false;
  1716. }
  1717. for (int i = 0; i < ctx->Req.paramNum; i++)
  1718. {
  1719. MemCfgParam tmpParam("root", ctx->Req.module[i].GetData(), ctx->Req.name[i].GetData(), ctx->Req.value[i].GetData());
  1720. GetEntityBase()->GetFunction()->GetPrivilegeFunction()->ModifyMemCfgParam(tmpParam);
  1721. }
  1722. return true;
  1723. }
  1724. void CVtmLoaderFSM::CheckDeviceBaseEntity(SpReqAnsContext<VtmLoaderService_CheckDeviceEntity_Req, VtmLoaderService_CheckDeviceEntity_Ans>::Pointer ctx, WORD wEntityID)
  1725. {
  1726. CSmartPointer<IEntityFunctionPrivilege> pFuncPrivilege = m_pEntity->GetFunction().ConvertCase<IEntityFunctionPrivilege>();
  1727. CSmartPointer<IAsynWaitSp> spWait;
  1728. CEntityRunInfo runInfo;
  1729. //to check entity state
  1730. ErrorCodeEnum eErrCode = m_pEntity->GetFunction()->GetEntityRunInfo(ctx->Req.entityName.GetData(), runInfo);
  1731. if (eErrCode == Error_Succeed)
  1732. {
  1733. if (runInfo.eState != EntityState_NoStart)
  1734. {
  1735. eErrCode = pFuncPrivilege->TerminateEntity(ctx->Req.entityName.GetData(), spWait);
  1736. if (spWait != NULL)
  1737. eErrCode = spWait->WaitAnswer(MAX_AYSNC_TIMEOUT);
  1738. }
  1739. }
  1740. else
  1741. {
  1742. DbgWithLink(LOG_LEVEL_ERROR, LOG_TYPE_SYSTEM)("GetEntityRunInfo %s failed(%d).", ctx->Req.entityName.GetData(), eErrCode);
  1743. ctx->Answer(Error_Unexpect, VtmLoader_FailToGetEntityInfo);
  1744. return;
  1745. }
  1746. //(re)start entity
  1747. eErrCode = pFuncPrivilege->StartEntity(ctx->Req.entityName.GetData(), NULL, spWait);
  1748. if (eErrCode == Error_Succeed)
  1749. {
  1750. if (spWait != NULL)
  1751. eErrCode = spWait->WaitAnswer(MAX_AYSNC_TIMEOUT);
  1752. }
  1753. else
  1754. {
  1755. DbgWithLink(LOG_LEVEL_ERROR, LOG_TYPE_SYSTEM)("StartEntity %s failed(%d).", ctx->Req.entityName.GetData(), eErrCode);
  1756. ctx->Answer(Error_Unexpect, VtmLoader_FailToStartEntity);
  1757. return;
  1758. }
  1759. //TODO we should wait for device entity open suc?
  1760. int count = 0;
  1761. do
  1762. {
  1763. CEntityRunInfo runInfo;
  1764. eErrCode = m_pEntity->GetFunction()->GetEntityRunInfo(ctx->Req.entityName.GetData(), runInfo);
  1765. if (eErrCode == Error_Succeed)
  1766. {
  1767. if (runInfo.eState == EntityState_Idle)
  1768. break;
  1769. else if (runInfo.eState == EntityState_Lost || runInfo.eState == EntityState_Close || runInfo.eState == EntityState_Killed)
  1770. {
  1771. ctx->Answer(Error_Unexpect, VtmLoader_FailToStartEntity);
  1772. return;
  1773. }
  1774. count++;
  1775. if (count > 3)
  1776. {
  1777. ctx->Answer(Error_Unexpect, VtmLoader_FailToStartEntity);
  1778. return;
  1779. }
  1780. Sleep(1000);
  1781. }
  1782. else
  1783. {
  1784. ctx->Answer(Error_Unexpect, VtmLoader_FailToStartEntity);
  1785. return;
  1786. }
  1787. } while (true);
  1788. const int retryGetDevInfoInterval = 5000;//5 seconds
  1789. CClientSessionBase* pClient;
  1790. int entityState = 0;
  1791. switch (wEntityID)
  1792. {
  1793. case 0x206: //pinpad
  1794. {
  1795. PinPadService_ClientBase* pClient = new PinPadService_ClientBase(this->m_pEntity);
  1796. if (pClient != NULL)
  1797. {
  1798. eErrCode = pClient->Connect();
  1799. if (eErrCode == Error_Succeed)
  1800. {
  1801. int retryTimes = 12;
  1802. do {
  1803. PinPadService_GetDevInfo_Req reqQ;
  1804. PinPadService_GetDevInfo_Ans ansQ;
  1805. eErrCode = (*pClient)(EntityResource::getLink().upgradeLink())->GetDevInfo(reqQ, ansQ, 5000);
  1806. DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("eErrCode:%d,ansQ.state:%d", eErrCode, ansQ.state);
  1807. if (eErrCode == Error_Succeed && ansQ.state == 1)// 1 for "DEVICE_STATUS_NORMAL" defined in DeviceBaseClass.h
  1808. {
  1809. DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("return to caller");
  1810. ctx->Answer(Error_Succeed);
  1811. break;
  1812. }
  1813. Sleep(retryGetDevInfoInterval);
  1814. retryTimes--;
  1815. } while (retryTimes > 0);
  1816. if (retryTimes == 0)
  1817. ctx->Answer(Error_Unexpect, VtmLoader_EntityNotInNormal);
  1818. }
  1819. else {
  1820. DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM)("connect to %s failed.error code:%d", ctx->Req.entityName.GetData(), eErrCode);
  1821. ctx->Answer(Error_Unexpect, VtmLoader_FailToConnectEntity);
  1822. }
  1823. }
  1824. else
  1825. ctx->Answer(Error_Unexpect, VtmLoader_FailToConnectEntity);
  1826. }
  1827. break;
  1828. case 0x201: //IDCertificate
  1829. {
  1830. IDCertService_ClientBase* pClient = new IDCertService_ClientBase(this->m_pEntity);
  1831. if (pClient != NULL)
  1832. {
  1833. eErrCode = pClient->Connect();
  1834. if (eErrCode == Error_Succeed)
  1835. {
  1836. int retryTimes = 12;
  1837. do {
  1838. IDCertService_GetDevInfo_Req reqQ;
  1839. IDCertService_GetDevInfo_Ans ansQ;
  1840. eErrCode = (*pClient)(EntityResource::getLink().upgradeLink())->GetDevInfo(reqQ, ansQ, 5000);
  1841. if (eErrCode == Error_Succeed && ansQ.state == 1)// 1 for "DEVICE_STATUS_NORMAL" defined in DeviceBaseClass.h
  1842. {
  1843. DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("return to caller");
  1844. ctx->Answer(Error_Succeed);
  1845. break;
  1846. }
  1847. Sleep(retryGetDevInfoInterval);
  1848. retryTimes--;
  1849. } while (retryTimes > 0);
  1850. if (retryTimes == 0)
  1851. ctx->Answer(Error_Unexpect, VtmLoader_EntityNotInNormal);
  1852. }
  1853. else {
  1854. DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM)("connect to %s failed.error code:%d", ctx->Req.entityName.GetData(), eErrCode);
  1855. ctx->Answer(Error_Unexpect, VtmLoader_FailToConnectEntity);
  1856. }
  1857. }
  1858. else
  1859. ctx->Answer(Error_Unexpect, VtmLoader_FailToConnectEntity);
  1860. }
  1861. break;
  1862. case 0x204: //FingerPrint
  1863. {
  1864. FingerPrintService_ClientBase* pClient = new FingerPrintService_ClientBase(this->m_pEntity);
  1865. if (pClient != NULL)
  1866. {
  1867. eErrCode = pClient->Connect();
  1868. if (eErrCode == Error_Succeed)
  1869. {
  1870. int retryTimes = 12;
  1871. do {
  1872. FingerPrintService_GetDevInfo_Req reqQ;
  1873. FingerPrintService_GetDevInfo_Ans ansQ;
  1874. eErrCode = (*pClient)(EntityResource::getLink().upgradeLink())->GetDevInfo(reqQ, ansQ, 5000);
  1875. if (eErrCode == Error_Succeed && ansQ.state == 1)// 1 for "DEVICE_STATUS_NORMAL" defined in DeviceBaseClass.h
  1876. {
  1877. DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("return to caller");
  1878. ctx->Answer(Error_Succeed);
  1879. break;
  1880. }
  1881. Sleep(retryGetDevInfoInterval);
  1882. retryTimes--;
  1883. } while (retryTimes > 0);
  1884. if (retryTimes == 0)
  1885. ctx->Answer(Error_Unexpect, VtmLoader_EntityNotInNormal);
  1886. }
  1887. else {
  1888. DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM)("connect to %s failed.error code:%d", ctx->Req.entityName.GetData(), eErrCode);
  1889. ctx->Answer(Error_Unexpect, VtmLoader_FailToConnectEntity);
  1890. }
  1891. }
  1892. else
  1893. ctx->Answer(Error_Unexpect, VtmLoader_FailToConnectEntity);
  1894. }
  1895. break;
  1896. case 0x203: //CardIssuer
  1897. {
  1898. CardIssuerService_ClientBase* pClient = new CardIssuerService_ClientBase(this->m_pEntity);
  1899. if (pClient != NULL)
  1900. {
  1901. eErrCode = pClient->Connect();
  1902. if (eErrCode == Error_Succeed)
  1903. {
  1904. int retryTimes = 12;
  1905. do {
  1906. CardIssuerService_GetDevInfo_Req reqQ;
  1907. CardIssuerService_GetDevInfo_Ans ansQ;
  1908. eErrCode = (*pClient)(EntityResource::getLink().upgradeLink())->GetDevInfo(reqQ, ansQ, 5000);
  1909. if (eErrCode == Error_Succeed && ansQ.state == 1)// 1 for "DEVICE_STATUS_NORMAL" defined in DeviceBaseClass.h
  1910. {
  1911. DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("return to caller");
  1912. ctx->Answer(Error_Succeed);
  1913. break;
  1914. }
  1915. Sleep(retryGetDevInfoInterval);
  1916. retryTimes--;
  1917. } while (retryTimes > 0);
  1918. if (retryTimes == 0)
  1919. ctx->Answer(Error_Unexpect, VtmLoader_EntityNotInNormal);
  1920. }
  1921. else {
  1922. DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM)("connect to %s failed.error code:%d", ctx->Req.entityName.GetData(), eErrCode);
  1923. ctx->Answer(Error_Unexpect, VtmLoader_FailToConnectEntity);
  1924. }
  1925. }
  1926. else
  1927. ctx->Answer(Error_Unexpect, VtmLoader_FailToConnectEntity);
  1928. }
  1929. break;
  1930. case 0x213: //ContactlessCard
  1931. {
  1932. ContactlessCardService_ClientBase* pClient = new ContactlessCardService_ClientBase(this->m_pEntity);
  1933. if (pClient != NULL)
  1934. {
  1935. eErrCode = pClient->Connect();
  1936. if (eErrCode == Error_Succeed)
  1937. {
  1938. int retryTimes = 12;
  1939. do {
  1940. ContactlessCardService_GetDevInfo_Req reqQ;
  1941. ContactlessCardService_GetDevInfo_Ans ansQ;
  1942. eErrCode = (*pClient)(EntityResource::getLink().upgradeLink())->GetDevInfo(reqQ, ansQ, 5000);
  1943. if (eErrCode == Error_Succeed && ansQ.state == 1)// 1 for "DEVICE_STATUS_NORMAL" defined in DeviceBaseClass.h
  1944. {
  1945. DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("return to caller");
  1946. ctx->Answer(Error_Succeed);
  1947. break;
  1948. }
  1949. Sleep(retryGetDevInfoInterval);
  1950. retryTimes--;
  1951. } while (retryTimes > 0);
  1952. if (retryTimes == 0)
  1953. ctx->Answer(Error_Unexpect, VtmLoader_EntityNotInNormal);
  1954. }
  1955. else {
  1956. DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM)("connect to %s failed.error code:%d", ctx->Req.entityName.GetData(), eErrCode);
  1957. ctx->Answer(Error_Unexpect, VtmLoader_FailToConnectEntity);
  1958. }
  1959. }
  1960. else
  1961. ctx->Answer(Error_Unexpect, VtmLoader_FailToConnectEntity);
  1962. }
  1963. break;
  1964. case 0x217:
  1965. {
  1966. HSPScannerService_ClientBase* pClient = new HSPScannerService_ClientBase(this->m_pEntity);
  1967. if (pClient != NULL)
  1968. {
  1969. eErrCode = pClient->Connect();
  1970. if (eErrCode == Error_Succeed)
  1971. {
  1972. int retryTimes = 12;
  1973. do {
  1974. HSPScannerService_GetDevInfo_Req reqQ;
  1975. HSPScannerService_GetDevInfo_Ans ansQ;
  1976. eErrCode = (*pClient)(EntityResource::getLink().upgradeLink())->GetDevInfo(reqQ, ansQ, 5000);
  1977. if (eErrCode == Error_Succeed && ansQ.state == 1)// 1 for "DEVICE_STATUS_NORMAL" defined in DeviceBaseClass.h
  1978. {
  1979. DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("return to caller");
  1980. ctx->Answer(Error_Succeed);
  1981. break;
  1982. }
  1983. Sleep(retryGetDevInfoInterval);
  1984. retryTimes--;
  1985. } while (retryTimes > 0);
  1986. if (retryTimes == 0)
  1987. ctx->Answer(Error_Unexpect, VtmLoader_EntityNotInNormal);
  1988. }
  1989. else {
  1990. DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM)("connect to %s failed.error code:%d", ctx->Req.entityName.GetData(), eErrCode);
  1991. ctx->Answer(Error_Unexpect, VtmLoader_FailToConnectEntity);
  1992. }
  1993. }
  1994. else
  1995. ctx->Answer(Error_Unexpect, VtmLoader_FailToConnectEntity);
  1996. }
  1997. break;
  1998. default:
  1999. break;
  2000. }
  2001. return;
  2002. }
  2003. void CVtmLoaderFSM::CheckEntityRestartIdle(SpReqAnsContext<VtmLoaderService_CheckDeviceEntity_Req, VtmLoaderService_CheckDeviceEntity_Ans>::Pointer ctx)
  2004. {
  2005. CSmartPointer<IEntityFunctionPrivilege> pFuncPrivilege = m_pEntity->GetFunction().ConvertCase<IEntityFunctionPrivilege>();
  2006. CSmartPointer<IAsynWaitSp> spWait;
  2007. CEntityRunInfo runInfo;
  2008. //to check entity state
  2009. ErrorCodeEnum eErrCode = m_pEntity->GetFunction()->GetEntityRunInfo(ctx->Req.entityName.GetData(), runInfo);
  2010. if (eErrCode == Error_Succeed)
  2011. {
  2012. if (runInfo.eState != EntityState_NoStart)
  2013. {
  2014. eErrCode = pFuncPrivilege->TerminateEntity(ctx->Req.entityName.GetData(), spWait);
  2015. if (spWait != NULL)
  2016. eErrCode = spWait->WaitAnswer(MAX_AYSNC_TIMEOUT);
  2017. }
  2018. }
  2019. else
  2020. {
  2021. DbgWithLink(LOG_LEVEL_ERROR, LOG_TYPE_SYSTEM)("GetEntityRunInfo %s failed(%d).", ctx->Req.entityName.GetData(), eErrCode);
  2022. ctx->Answer(Error_Unexpect, VtmLoader_FailToGetEntityInfo);
  2023. return;
  2024. }
  2025. //(re)start entity
  2026. eErrCode = pFuncPrivilege->StartEntity(ctx->Req.entityName.GetData(), NULL, spWait);
  2027. if (eErrCode == Error_Succeed)
  2028. {
  2029. if (spWait != NULL)
  2030. eErrCode = spWait->WaitAnswer(MAX_AYSNC_TIMEOUT);
  2031. }
  2032. else
  2033. {
  2034. DbgWithLink(LOG_LEVEL_ERROR, LOG_TYPE_SYSTEM)("StartEntity %s failed(%d).", ctx->Req.entityName.GetData(), eErrCode);
  2035. ctx->Answer(Error_Unexpect, VtmLoader_FailToStartEntity);
  2036. return;
  2037. }
  2038. //TODO we should wait for device entity open suc?
  2039. int count = 0;
  2040. do
  2041. {
  2042. CEntityRunInfo runInfo;
  2043. eErrCode = m_pEntity->GetFunction()->GetEntityRunInfo(ctx->Req.entityName.GetData(), runInfo);
  2044. if (eErrCode == Error_Succeed)
  2045. {
  2046. if (runInfo.eState == EntityState_Idle)
  2047. {
  2048. ctx->Answer(Error_Succeed);
  2049. return;
  2050. }
  2051. else if (runInfo.eState == EntityState_Lost || runInfo.eState == EntityState_Close || runInfo.eState == EntityState_Killed)
  2052. {
  2053. ctx->Answer(Error_Unexpect, VtmLoader_FailToStartEntity);
  2054. return;
  2055. }
  2056. count++;
  2057. if (count > 5)
  2058. {
  2059. ctx->Answer(Error_Unexpect, VtmLoader_FailToStartEntity);
  2060. return;
  2061. }
  2062. Sleep(2000);
  2063. }
  2064. else
  2065. {
  2066. ctx->Answer(Error_Unexpect, VtmLoader_FailToStartEntity);
  2067. return;
  2068. }
  2069. } while (true);
  2070. }
  2071. void CVtmLoaderFSM::CheckVideo(SpReqAnsContext<VtmLoaderService_CheckDeviceEntity_Req, VtmLoaderService_CheckDeviceEntity_Ans>::Pointer ctx)
  2072. {
  2073. CSmartPointer<IEntityFunctionPrivilege> pFuncPrivilege = m_pEntity->GetFunction().ConvertCase<IEntityFunctionPrivilege>();
  2074. CSmartPointer<IAsynWaitSp> spWait;
  2075. CEntityRunInfo runInfo;
  2076. //to check entity state
  2077. ErrorCodeEnum eErrCode = m_pEntity->GetFunction()->GetEntityRunInfo(ctx->Req.entityName.GetData(), runInfo);
  2078. if (eErrCode == Error_Succeed)
  2079. {
  2080. if (runInfo.eState != EntityState_NoStart)
  2081. {
  2082. eErrCode = pFuncPrivilege->TerminateEntity(ctx->Req.entityName.GetData(), spWait);
  2083. if (spWait != NULL)
  2084. eErrCode = spWait->WaitAnswer(MAX_AYSNC_TIMEOUT);
  2085. }
  2086. }
  2087. else
  2088. {
  2089. DbgWithLink(LOG_LEVEL_ERROR, LOG_TYPE_SYSTEM)("GetEntityRunInfo %s failed(%d).", ctx->Req.entityName.GetData(), eErrCode);
  2090. ctx->Answer(Error_Unexpect, VtmLoader_FailToGetEntityInfo);
  2091. return;
  2092. }
  2093. //(re)start entity
  2094. eErrCode = pFuncPrivilege->StartEntity(ctx->Req.entityName.GetData(), NULL, spWait);
  2095. if (eErrCode == Error_Succeed)
  2096. {
  2097. if (spWait != NULL)
  2098. eErrCode = spWait->WaitAnswer(MAX_AYSNC_TIMEOUT);
  2099. }
  2100. else
  2101. {
  2102. DbgWithLink(LOG_LEVEL_ERROR, LOG_TYPE_SYSTEM)("StartEntity %s failed(%d).", ctx->Req.entityName.GetData(), eErrCode);
  2103. ctx->Answer(Error_Unexpect, VtmLoader_FailToStartEntity);
  2104. return;
  2105. }
  2106. //TODO we should wait for device entity open suc?
  2107. int count = 0;
  2108. do
  2109. {
  2110. CEntityRunInfo runInfo;
  2111. eErrCode = m_pEntity->GetFunction()->GetEntityRunInfo(ctx->Req.entityName.GetData(), runInfo);
  2112. if (eErrCode == Error_Succeed)
  2113. {
  2114. if (runInfo.eState == EntityState_Idle)
  2115. {
  2116. CSimpleStringA csCameraState("");
  2117. eErrCode = GetEntityBase()->GetFunction()->GetSysVar("CameraState", csCameraState);
  2118. if (eErrCode == Error_Succeed && csCameraState.Compare("N") == 0)
  2119. ctx->Answer(Error_Succeed);
  2120. else
  2121. ctx->Answer(Error_Unexpect, VtmLoader_FailToStartEntity);
  2122. return;
  2123. }
  2124. else if (runInfo.eState == EntityState_Lost || runInfo.eState == EntityState_Close || runInfo.eState == EntityState_Killed)
  2125. {
  2126. ctx->Answer(Error_Unexpect, VtmLoader_FailToStartEntity);
  2127. return;
  2128. }
  2129. count++;
  2130. if (count > 5)
  2131. {
  2132. ctx->Answer(Error_Unexpect, VtmLoader_FailToStartEntity);
  2133. return;
  2134. }
  2135. Sleep(2000);
  2136. }
  2137. else
  2138. {
  2139. ctx->Answer(Error_Unexpect, VtmLoader_FailToStartEntity);
  2140. return;
  2141. }
  2142. } while (true);
  2143. }
  2144. void CVtmLoaderFSM::Oiltest()
  2145. {
  2146. CSmartPointer<IEntityFunctionPrivilege> pFuncPrivilege = m_pEntity->GetFunction().ConvertCase<IEntityFunctionPrivilege>();
  2147. CSmartPointer<IAsynWaitSp> spWait;
  2148. //(re)start entity
  2149. ErrorCodeEnum eErrCode = pFuncPrivilege->StartEntity("HealthManager", NULL, spWait);
  2150. if (eErrCode == Error_Succeed)
  2151. {
  2152. if (spWait != NULL)
  2153. eErrCode = spWait->WaitAnswer(MAX_AYSNC_TIMEOUT);
  2154. }
  2155. else
  2156. {
  2157. DbgWithLink(LOG_LEVEL_ERROR, LOG_TYPE_SYSTEM)("StartEntity %s failed(%d).", "HealthManager", eErrCode);
  2158. return;
  2159. }
  2160. DbgWithLink(LOG_LEVEL_ERROR, LOG_TYPE_SYSTEM)("StartEntity %s suc.", "HealthManager");
  2161. return;
  2162. SetTerminalNo(NULL);
  2163. Sleep(11000);
  2164. DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("to save to root.ini");
  2165. SaveTerminalNo(NULL);
  2166. m_hSaveTerminalNoVar.Broadcast();
  2167. DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("continue boot");
  2168. }