VtmLoaderFSM.cpp 118 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213
  1. #include "stdafx.h"
  2. #include <algorithm>
  3. #include <fstream>
  4. #include <winpr/file.h>
  5. #include "fileutil.h"
  6. #include "iniutil.h"
  7. #include "RVCEventCode.h"
  8. #include "VtmLoaderFSM.h"
  9. #include "EventCode.h"
  10. #if defined(RVC_OS_WIN)
  11. #include <io.h>
  12. #else
  13. #include <unistd.h>
  14. #include <fcntl.h>
  15. #include <errno.h>
  16. #include "RestfulFunc.h"
  17. #endif //RVC_OS_WIN
  18. #include "../mod_healthmanager/HealthManager_client_g.h"
  19. #include "../mod_pinpad/PinPad_client_g.h"
  20. #include "../mod_CardIssuerStand/CardIssuerStand_client_g.h"
  21. #include "../mod_cardissuerstore/CardIssuerStore_client_g.h"
  22. #include "../mod_IDCertificate/IDCertificate_client_g.h"
  23. #include "../mod_HSPScanner/HSPScanner_client_g.h"
  24. #include "../mod_ContactlessCard/ContactlessCard_client_g.h"
  25. #include "../mod_FingerPrint/FingerPrint_client_g.h"
  26. #include "../mod_gpio/Gpio_client_g.h"
  27. #include "SpDefine.h"
  28. using namespace HealthManager;
  29. using namespace PinPad;
  30. using namespace CardIssuerStand;
  31. using namespace CardIssuerStore;
  32. using namespace IDCertificate;
  33. using namespace HSPScanner;
  34. using namespace ContactlessCard;
  35. using namespace FingerPrint;
  36. using namespace Gpio;
  37. using namespace SP::Module::Net;
  38. #define ALLOW_MULTI_NETWORKD_CARDS
  39. const int MAX_AYSNC_TIMEOUT = 60000;
  40. const int MAX_IGNORE_TIMEOUT = 100;
  41. enum EntityOP
  42. {
  43. OP_STOP_ENTITY,
  44. OP_START_ENTITY,
  45. OP_PAUSE_ENTITY,
  46. OP_TERMINATE_ENTITY,
  47. OP_CONTINUE_ENTITY,
  48. };
  49. struct callback_entry : public IReleasable
  50. {
  51. virtual ~callback_entry() {}
  52. CSimpleStringA EntityName;
  53. union {
  54. void* pRawData;
  55. int state;
  56. };
  57. int op;
  58. ErrorCodeEnum ErrorResult;
  59. };
  60. DWORD tokenUpdate(void* param)
  61. {
  62. CVtmLoaderFSM* t_entity = (CVtmLoaderFSM*)param;
  63. DWORD lastUpdateTime = 0; // 获取当前时间(以毫秒为单位)
  64. while (true)
  65. {
  66. DWORD currentTime = SP::Module::Comm::RVCGetTickCount(); // 获取当前时间
  67. DWORD elapsedTime = currentTime - lastUpdateTime; // 计算与上次更新的时间间隔(毫秒)
  68. if (elapsedTime >= (t_entity->m_refreshWaitSec * 1000))
  69. {
  70. // 如果距离上次更新时间已经超过了指定的刷新间隔
  71. if (t_entity->refreshToken())
  72. {
  73. // 更新成功,更新上次更新时间
  74. lastUpdateTime = currentTime;
  75. }
  76. else
  77. {
  78. // 更新失败,可以处理一些错误逻辑
  79. }
  80. }
  81. // 等待一段时间后再次检查
  82. Sleep(20000); // 20秒
  83. }
  84. return 0;
  85. }
  86. DWORD errMsgListUpdate(void* param)
  87. {
  88. CVtmLoaderFSM* t_entity = (CVtmLoaderFSM*)param;
  89. static bool msgErrThreadExist = false;
  90. if (msgErrThreadExist)
  91. return true;
  92. else
  93. {
  94. msgErrThreadExist = true;
  95. }
  96. /*
  97. CSimpleString code, des;
  98. t_entity->GetEntityBase()->GetFunction()->GetVTMErrMsg(VtmLoader_DETECT_VERSION_ERR, code, des);
  99. DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_USER)("VtmLoader_DETECT_VERSION_ERR, %s, %s", code.GetData(), des.GetData());
  100. */
  101. //update err list after setting centersetting urls
  102. //try updating every 20s until success
  103. int times = 0;
  104. ErrorCodeEnum rc = Error_Succeed;
  105. while (times < 5 && Error_Succeed != (rc = t_entity->GetEntityBase()->GetFunction()->GetPrivilegeFunction()->TryUpdateVTMERRMSG()))
  106. {
  107. LogWarn(SeverityLevelEnum::Severity_Low, Error_Unexpect, LOG_WARN_VtmLoader_GetVTMERRMSG_Failed, "Get errMsgListUpdate config failed.");
  108. Sleep(20000);
  109. times++;
  110. }
  111. if(rc == Error_Succeed)
  112. LogEvent(Severity_High, Event_VtmLoader_GetVTMERRMSG_Suc, "Get errMsgListUpdate config succeed.");
  113. /*
  114. t_entity->GetEntityBase()->GetFunction()->GetVTMErrMsg(VtmLoader_DETECT_VERSION_ERR, code, des);
  115. DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_USER)("VtmLoader_DETECT_VERSION_ERR, %s, %s", code.GetData(), des.GetData());
  116. t_entity->GetEntityBase()->GetFunction()->GetVTMErrMsg(123456, code, des);
  117. DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_USER)("123456, %s, %s", code.GetData(), des.GetData());
  118. t_entity->GetEntityBase()->GetFunction()->GetVTMErrMsg(VtmLoader_FailToConnectEntity, code, des);
  119. DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_USER)("VtmLoader_FailToConnectEntity, %s, %s", code.GetData(), des.GetData());
  120. t_entity->GetEntityBase()->GetFunction()->GetVTMErrMsg(WARN_SendEndpoint_URL_ERR, code, des);
  121. DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_USER)("WARN_SendEndpoint_URL_ERR, %s, %s", code.GetData(), des.GetData());
  122. t_entity->GetEntityBase()->GetFunction()->GetVTMErrMsg(VtmLoader_GetConfig_UpdateCfg_Failed, code, des);
  123. DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_USER)("VtmLoader_GetConfig_UpdateCfg_Failed, %s, %s", code.GetData(), des.GetData());
  124. t_entity->GetEntityBase()->GetFunction()->GetVTMErrMsg(0x50100215, code, des);
  125. DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_USER)("0x50100215, %s, %s", code.GetData(), des.GetData());
  126. */
  127. return 0;
  128. }
  129. DWORD checkUrlActive(LPVOID param)
  130. {
  131. CVtmLoaderFSM* entityInfo = (CVtmLoaderFSM*)param;
  132. CSmartPointer<IConfigInfo> pConfig;
  133. CSimpleString t_endpoint, t_materialUrl;
  134. CSimpleString errMsg;
  135. Sleep(60 * 1000);
  136. long srcClo = clock();
  137. entityInfo->GetEntityBase()->GetFunction()->OpenConfig(Config_CenterSetting, pConfig);
  138. do {
  139. if (Error_Succeed != pConfig->ReadConfigValue("Common", "SendEndpoint", t_endpoint))
  140. {
  141. errMsg = "checkUrlActive read Common::SendEndpoint err";
  142. break;
  143. }
  144. if (t_endpoint.GetLength() == 0)
  145. {
  146. errMsg = "checkUrlActive endpoint len=0 err";
  147. break;
  148. }
  149. //if (!checkHttpActive(t_endpoint.GetData()))
  150. // errMsg.Append(CSimpleString::Format("checkHttpActive endpoint err:%s !", t_endpoint.GetData()));
  151. //else if((clock() - srcClo) > 3000)
  152. // errMsg.Append(CSimpleString::Format("checkHttpActive endpoint too long:%d !", clock() - srcClo));
  153. srcClo = clock();
  154. } while (false);
  155. if (errMsg.GetLength() > 0)
  156. LogWarn(SeverityLevelEnum::Severity_Middle, Error_Unexpect, WARN_SendEndpoint_URL_ERR, errMsg.GetData());
  157. //do get upload log Info for a while
  158. while (true)
  159. {
  160. if (entityInfo->m_uploadLogInfo_waitSec <= 0)
  161. break;
  162. unsigned long t_upload_TerminalSys_Suc, t_upload_TerminalUser_Suc, t_upload_BussinessSys_Suc, t_upload_BussinessUser_Suc, t_upload_beidou_Suc;
  163. unsigned long t_upload_TerminalSys_Err, t_upload_TerminalUser_Err, t_upload_BussinessSys_Err, t_upload_BussinessUser_Err, t_upload_beidou_Err;
  164. unsigned long t_discard_full, t_discard_RTI1002, curLogNum;
  165. entityInfo->GetEntityBase()->GetFunction()->GetPrivilegeFunction()->GetSendLogInfo(&t_upload_TerminalSys_Suc, &t_upload_TerminalUser_Suc,
  166. &t_upload_BussinessSys_Suc, &t_upload_BussinessUser_Suc, &t_upload_beidou_Suc,
  167. &t_upload_TerminalSys_Err, &t_upload_TerminalUser_Err, &t_upload_BussinessSys_Err, &t_upload_BussinessUser_Err, &t_upload_beidou_Err,
  168. &t_discard_full, &t_discard_RTI1002, &curLogNum);
  169. /*LogWarn(SeverityLevelEnum::Severity_Low, Error_Trace, WARN_SendEndpoint_LOG_INFO,
  170. 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, discard_forFull:%d, discard_forRTI1002:%d, curNum:%d"
  171. , t_upload_TerminalSys_Suc, t_upload_TerminalUser_Suc, t_upload_BussinessSys_Suc, t_upload_BussinessUser_Suc, t_upload_beidou_Suc,
  172. t_upload_TerminalSys_Err, t_upload_TerminalUser_Err, t_upload_BussinessSys_Err, t_upload_BussinessUser_Err, t_upload_beidou_Err
  173. , t_discard_full, t_discard_RTI1002, curLogNum).GetData());
  174. */
  175. DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("%s",
  176. 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, discard_forFull:%d, discard_forRTI1002:%d, curNum:%d"
  177. , t_upload_TerminalSys_Suc, t_upload_TerminalUser_Suc, t_upload_BussinessSys_Suc, t_upload_BussinessUser_Suc, t_upload_beidou_Suc,
  178. t_upload_TerminalSys_Err, t_upload_TerminalUser_Err, t_upload_BussinessSys_Err, t_upload_BussinessUser_Err, t_upload_beidou_Err
  179. , t_discard_full, t_discard_RTI1002, curLogNum).GetData());
  180. Sleep(entityInfo->m_uploadLogInfo_waitSec * 1000);
  181. }
  182. return 0;
  183. }
  184. DWORD AlarmVersionErr(LPVOID param)
  185. {
  186. CVtmLoaderFSM* cur = (CVtmLoaderFSM*)param;
  187. Sleep(5000);//wait mod_alarm start
  188. LogWarn(Severity_Middle, Error_Bug, VtmLoader_DETECT_VERSION_ERR, cur->m_verShowMsg.GetData());
  189. return 0;
  190. }
  191. bool CVtmLoaderFSM::refreshToken()
  192. {
  193. CSimpleString oldToken, newToken;
  194. ErrorCodeEnum eErr = Error_Succeed;
  195. if (Error_Succeed != (eErr = GetEntityBase()->GetFunction()->GetPrivilegeFunction()->TryUpdateToken(oldToken, newToken)))
  196. {
  197. DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_USER).setLogCode("QLR040210F13").setResultCode("RTA1F02")("Get center setting, TryUpdateToken failed:0x%x", eErr);
  198. LogWarn(Severity_High, Error_Unexpect, VtmLoader_GetConfig_UpdateToken_Failed, CSimpleStringA::Format("拉取配置失败:0x%x(%s)", eErr, SpStrError(eErr)).GetData());
  199. return false;
  200. }
  201. return true;
  202. }
  203. CVtmLoaderFSM::CVtmLoaderFSM()
  204. {
  205. m_refreshWaitSec = 1200;
  206. m_uploadLogInfo_waitSec = 3600;
  207. m_defaultSystemId = "LR04.02_Terminal";
  208. m_iCanIgnoreAddrDetect = 0;
  209. m_ullMaxAddrDetectTime = 10*60*1000;//10 minutes
  210. m_iDetectInterval = 5000;
  211. m_terminalNoFromWeb = m_verShowMsg = "";
  212. m_iNoCheckMachineModel = 0;
  213. m_bSIPPhoneStartFail = false;
  214. m_eDepCopyStage = DepDirInitCopy_NoNeed;
  215. }
  216. CVtmLoaderFSM::~CVtmLoaderFSM()
  217. {
  218. }
  219. ErrorCodeEnum CVtmLoaderFSM::OnInit()
  220. {
  221. AddStateHooker(this);
  222. GetEntityBase()->GetFunction()->GetSystemStaticInfo(m_sysInfo);
  223. return Error_Succeed;
  224. }
  225. ErrorCodeEnum CVtmLoaderFSM::OnExit()
  226. {
  227. GetEntityBase()->GetFunction()->KillTimer(TIMER_CENTERSETTING_UPDATE_CHECK);
  228. RemoveStateHooker(this);
  229. return Error_Succeed;
  230. }
  231. void CVtmLoaderFSM::OnStateTrans(int iSrcState, int iDstState)
  232. {
  233. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("state change from %s to %s", GetStateName(iSrcState), GetStateName(iDstState));
  234. }
  235. void CVtmLoaderFSM::s0_on_entry()
  236. {
  237. CSimpleStringA csTmpTS("");
  238. ErrorCodeEnum eErr = GetEntityBase()->GetFunction()->GetSysVar("TerminalStage", csTmpTS);
  239. if (eErr == Error_Succeed && !csTmpTS.IsNullOrEmpty() && csTmpTS.Compare("X") != 0)
  240. {
  241. DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_USER)(" eErr:%d", eErr);
  242. DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_USER)("TerminalStage:%s, The entity maybe lost, and have beed restart by healthmanager.To do GetConfig only", csTmpTS.GetData());
  243. GetConfig();
  244. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_USER)("redo GetConfig finished.");
  245. }
  246. else
  247. {
  248. if (CheckIfNeedCopyDepFiles())
  249. {
  250. m_eDepCopyStage = DepDirInitCopy_Copying;
  251. CopyDepFilesToNewDepPathTask* pCopyTask = new CopyDepFilesToNewDepPathTask(this);
  252. GetEntityBase()->GetFunction()->PostThreadPoolTask(pCopyTask);
  253. }
  254. LogWarn(Severity_Low, Error_Succeed, VtmLoader_BootInfoPrint, "开始网卡、网络连通性检查");
  255. NetWorkCheckAndGetSettingTask* task = new NetWorkCheckAndGetSettingTask(this);
  256. GetEntityBase()->GetFunction()->PostThreadPoolTask(task);
  257. }
  258. GetOsVersion();
  259. }
  260. void CVtmLoaderFSM::s0_on_exit()
  261. {
  262. }
  263. unsigned int CVtmLoaderFSM::s0_on_event(FSMEvent* pEvt)
  264. {
  265. DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("s0_on_event,pEvt:%d,pEvt->param1:%d", pEvt->iEvt, pEvt->param1);
  266. switch (pEvt->iEvt)
  267. {
  268. case USER_EVT_NetworkCheck_Passed:
  269. pEvt->SetHandled();
  270. return pEvt->param1;
  271. case USER_EVT_CHECK_DEVICE_ENTITY:
  272. pEvt->SetHandled();
  273. {
  274. CheckDeviceEntityEvent* cdee = dynamic_cast<CheckDeviceEntityEvent*>(pEvt);
  275. CheckDeviceEntityTask* pTask = new CheckDeviceEntityTask(this);
  276. pTask->ctx = cdee->ctx;
  277. GetEntityBase()->GetFunction()->PostThreadPoolTask(pTask);
  278. }
  279. break;
  280. case USER_EVT_SAVE_TERMINALNO:
  281. pEvt->SetHandled();
  282. {
  283. SaveTerminalNoEvent* stne = dynamic_cast<SaveTerminalNoEvent*>(pEvt);
  284. SaveTerminalNoTask* pTask = new SaveTerminalNoTask(this);
  285. pTask->ctx = stne->ctx;
  286. GetEntityBase()->GetFunction()->PostThreadPoolTask(pTask);
  287. }
  288. break;
  289. case USER_EVT_DEALWITH_OLD_EVENT:
  290. pEvt->SetHandled();
  291. {
  292. DealWithOldEvent_Event *evt = dynamic_cast<DealWithOldEvent_Event*>(pEvt);
  293. DealWithOldEvent_Task* pTask = new DealWithOldEvent_Task(this);
  294. pTask->ctx = evt->ctx;
  295. GetEntityBase()->GetFunction()->PostThreadPoolTask(pTask);
  296. }
  297. break;
  298. case USER_EVT_QUERY_LOCAL_INFO:
  299. pEvt->SetHandled();
  300. {
  301. QueryLocalInfoEvent* qlie = dynamic_cast<QueryLocalInfoEvent*>(pEvt);
  302. QueryLocalInfoTask* pTask = new QueryLocalInfoTask(this);
  303. pTask->ctx = qlie->ctx;
  304. GetEntityBase()->GetFunction()->PostThreadPoolTask(pTask);
  305. }
  306. break;
  307. default:
  308. break;
  309. }
  310. return 0;
  311. }
  312. //CoreBoot
  313. void CVtmLoaderFSM::s1_on_entry()
  314. {
  315. DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("s1_on_entry");
  316. ErrorCodeEnum eErrCode;
  317. CSmartPointer<IEntityFunction> spEntityFunction = GetEntityBase()->GetFunction();
  318. CSmartPointer<IEntityFunctionPrivilege> pFuncPrivilege = spEntityFunction.ConvertCase<IEntityFunctionPrivilege>();
  319. bool bAsync = false;
  320. m_eStage = LOADSTAGE_COREBOOT;
  321. int ret = 0;
  322. map<CSimpleStringA, EntityLoadInfo>::iterator it;
  323. //start entity
  324. vector<CSimpleStringA>::iterator vIt;
  325. if (m_coreBootOpt.size() == 0)
  326. goto COREBOOT_FINISH;
  327. char startMsg[128];
  328. for (vIt = m_vCoreBoot.begin(); vIt != m_vCoreBoot.end(); ++vIt)
  329. {
  330. CSmartPointer<IAsynWaitSp> spWait;//oilyang 20160325 see the following comment
  331. it = m_coreBootOpt.find(*vIt);
  332. if (it == m_coreBootOpt.end())
  333. {
  334. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("cannot find %s", (LPCSTR)* vIt);
  335. continue;
  336. }
  337. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("start,%s,%d", (LPCSTR)it->first, it->second.loadOpt);
  338. CEntityRunInfo entRunInfo;
  339. ErrorCodeEnum errCode = spEntityFunction->GetEntityRunInfo(it->first, entRunInfo);
  340. if (errCode == Error_Succeed && entRunInfo.eState == EntityState_Idle)
  341. {
  342. it->second.eResult = LOADING_SUCCEED;
  343. ret = CheckLoadResult(LOADSTAGE_COREBOOT);
  344. if (ret == 0 || ret == 2)
  345. goto COREBOOT_FINISH;
  346. else
  347. continue;
  348. }
  349. ZeroMemory(startMsg, 128);
  350. //sprintf(startMsg, "正在启动实体%s...", it->first.GetData());
  351. //GetEntityBase()->GetFunction()->ShowStartupInfo(startMsg);
  352. switch (it->second.loadOpt)
  353. {
  354. case LOADOPT_IGNORE:
  355. {
  356. pFuncPrivilege->StartEntity(it->first, NULL, spWait);
  357. if (spWait != NULL)
  358. spWait->WaitAnswer(MAX_IGNORE_TIMEOUT);//oilyang 20160325 the null pointer
  359. it->second.eResult = LOADING_SUCCEED;
  360. ret = CheckLoadResult(LOADSTAGE_COREBOOT);
  361. if (ret == 0 || ret == 2)
  362. goto COREBOOT_FINISH;
  363. }
  364. break;
  365. case LOADOPT_ASYNC_VERIFY:
  366. errCode = AsyncStartEntity(it->first, NULL, NULL);
  367. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("AsyncStartEntity:%d", errCode);
  368. bAsync = true;
  369. break;
  370. case LOADOPT_SYNC_VERIFY:
  371. {
  372. ULONGLONG dwEntityStart = SP::Module::Comm::RVCGetTickCount();
  373. pFuncPrivilege->StartEntity(it->first, NULL, spWait);
  374. if (spWait != NULL)
  375. errCode = spWait->WaitAnswer(MAX_AYSNC_TIMEOUT);
  376. ULONGLONG dwEntityEnd = SP::Module::Comm::RVCGetTickCount();
  377. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI("SyncStartEntity").setCostTime((dwEntityEnd - dwEntityStart) / 1000)("%d", errCode);
  378. if (errCode == Error_Succeed)
  379. it->second.eResult = LOADING_SUCCEED;
  380. else if (errCode == Error_TimeOut)
  381. it->second.eResult = LOADING_TIMEOUT;
  382. else
  383. it->second.eResult = LOADING_FAILED;
  384. if (errCode != Error_Succeed) {
  385. CSimpleStringA tmpAuthErrMsg("");
  386. if (GetEntityBase()->GetFunction()->GetSysVar("AuthErrMsg", tmpAuthErrMsg) == Error_Succeed && tmpAuthErrMsg.IsNullOrEmpty())
  387. GetEntityBase()->GetFunction()->SetSysVar("AuthErrMsg", CSimpleStringA::Format("%s 启动失败,请尝试重启应用或重启系统恢复", it->first.GetData()).GetData());
  388. if (it->first.Compare("SIPPhone") == 0)
  389. m_bSIPPhoneStartFail = true;
  390. DbgWithLink(LOG_LEVEL_ERROR, LOG_TYPE_SYSTEM)("启动失败:%s", it->first.GetData());
  391. m_csErrEntity = m_csErrEntity + "|" + it->first;
  392. FSMEvent* e = new FSMEvent(USER_EVT_COREBOOT_FINISHED);
  393. e->param1 = 2;//"SYNC START" enity started failed.
  394. PostEventFIFO(e);
  395. return;
  396. }
  397. else
  398. ret = CheckLoadResult(LOADSTAGE_COREBOOT);
  399. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("s1 check ret %d", ret);
  400. if (ret == 0 || ret == 2)
  401. goto COREBOOT_FINISH;
  402. }
  403. break;
  404. default:
  405. break;
  406. }
  407. }
  408. COREBOOT_FINISH:
  409. if (!bAsync)
  410. {
  411. FSMEvent* e = new FSMEvent(USER_EVT_COREBOOT_FINISHED);
  412. e->param1 = ret;
  413. PostEventFIFO(e);
  414. }
  415. else
  416. {
  417. ret = CheckLoadResult(LOADSTAGE_COREBOOT);
  418. if (ret == 0 || ret == 2)
  419. {
  420. FSMEvent* e = new FSMEvent(USER_EVT_COREBOOT_FINISHED);
  421. e->param1 = ret;
  422. PostEventFIFO(e);
  423. }
  424. }
  425. return;
  426. }
  427. void CVtmLoaderFSM::s1_on_exit()
  428. {
  429. LOG_FUNCTION();
  430. }
  431. unsigned int CVtmLoaderFSM::s1_on_event(FSMEvent* pEvt)
  432. {
  433. LOG_FUNCTION();
  434. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("s1 evt %d", pEvt->iEvt);
  435. switch (pEvt->iEvt)
  436. {
  437. case USER_EVT_COREBOOT_FINISHED:
  438. pEvt->SetHandled();
  439. return pEvt->param1;
  440. default:
  441. break;
  442. }
  443. return 0;
  444. }
  445. //SafeLoad
  446. void CVtmLoaderFSM::s2_on_entry()
  447. {
  448. LOG_FUNCTION();
  449. LogWarn(Severity_Low, Error_Succeed, VtmLoader_BootInfoPrint, "CoreBoot 阶段实体加载完成");
  450. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_USER).setLogCode("QLR040210F14")("Stage Coreboot have done.");
  451. ULONGLONG dwElapse = SP::Module::Comm::RVCGetTickCount();//使用机器启动时间秒数
  452. DWORD elapseTimeTemp = dwElapse / 1000;
  453. CSimpleStringA xMsg = CSimpleStringA::Format("{\"Decripstion\":\"Enter safeload state.\",\"version\":\"%s\",\"elapseTime\":\"%d\"}", m_sysInfo.InstallVersion.ToString().GetData(), elapseTimeTemp);
  454. //LogWarn(Severity_Low, Error_Unexpect, HealthManager_UserErrorCode_Enter_SafeLoad_State, xMsg.GetData());
  455. if (!VerifyVer())
  456. return;
  457. bool bAsync = false;
  458. m_eStage = LOADSTAGE_SAFELOAD;
  459. int ret = 0;
  460. map<CSimpleStringA, EntityLoadInfo>::iterator it;
  461. CSmartPointer<IEntityFunction> pFunc = GetEntityBase()->GetFunction();
  462. CSmartPointer<IEntityFunctionPrivilege> pFuncPrivilege = pFunc.ConvertCase<IEntityFunctionPrivilege>();
  463. ErrorCodeEnum errCode;
  464. vector<CSimpleStringA>::iterator vIt;
  465. if (m_safeLoadOpt.size() == 0)
  466. goto SAFELOAD_FINISH;
  467. char startMsg[128];
  468. for (vIt = m_vSafeLoad.begin(); vIt != m_vSafeLoad.end(); ++vIt)
  469. {
  470. CSmartPointer<IAsynWaitSp> spWait;
  471. it = m_safeLoadOpt.find(*vIt);
  472. if (it == m_safeLoadOpt.end())
  473. {
  474. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("cannot find %s", (LPCSTR)* vIt);
  475. continue;
  476. }
  477. CEntityRunInfo entRunInfo;
  478. errCode = pFunc->GetEntityRunInfo(it->first, entRunInfo);
  479. if (errCode == Error_Succeed && entRunInfo.eState == EntityState_Idle)
  480. {
  481. it->second.eResult = LOADING_SUCCEED;
  482. ret = CheckLoadResult(LOADSTAGE_SAFELOAD);
  483. if (ret == 0 || ret == 2)
  484. goto SAFELOAD_FINISH;
  485. else
  486. continue;
  487. }
  488. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("start %s,%d", (LPCTSTR)it->first, it->second.loadOpt);
  489. switch (it->second.loadOpt)
  490. {
  491. case LOADOPT_IGNORE:
  492. {
  493. pFuncPrivilege->StartEntity(it->first, NULL, spWait);
  494. if (spWait != NULL)
  495. spWait->WaitAnswer(MAX_IGNORE_TIMEOUT);
  496. it->second.eResult = LOADING_SUCCEED;
  497. ret = CheckLoadResult(LOADSTAGE_SAFELOAD);
  498. if (ret == 0 || ret == 2)
  499. goto SAFELOAD_FINISH;
  500. }
  501. break;
  502. case LOADOPT_ASYNC_VERIFY:
  503. AsyncStartEntity(it->first, NULL, NULL);
  504. bAsync = true;
  505. break;
  506. case LOADOPT_SYNC_VERIFY:
  507. {
  508. ZeroMemory(startMsg, 128);
  509. sprintf(startMsg, "正在启动实体%s...", it->first.GetData());
  510. GetEntityBase()->GetFunction()->ShowStartupInfo(startMsg);
  511. ULONGLONG dwEntityStart = SP::Module::Comm::RVCGetTickCount();
  512. pFuncPrivilege->StartEntity(it->first, NULL, spWait);
  513. if (spWait != NULL)
  514. errCode = spWait->WaitAnswer(MAX_AYSNC_TIMEOUT);
  515. ULONGLONG dwEntityEnd = SP::Module::Comm::RVCGetTickCount();
  516. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI("SyncStartEntity").setCostTime((dwEntityEnd - dwEntityStart) / 1000)("%d", errCode);
  517. if (it->first.Compare("SIPPhone") == 0)
  518. LogWarn(Severity_Low, Error_Succeed, VtmLoader_SIPPhoneEntityLoad_Cost, CSimpleStringA::Format("%d", (dwEntityEnd - dwEntityStart) / 1000));
  519. if (errCode == Error_Succeed) {
  520. it->second.eResult = LOADING_SUCCEED;
  521. }
  522. else if (errCode == Error_TimeOut)
  523. it->second.eResult = LOADING_TIMEOUT;
  524. else
  525. it->second.eResult = LOADING_FAILED;
  526. if (it->second.eResult != Error_Succeed)
  527. {
  528. CSimpleStringA tmpAuthErrMsg("");
  529. if (GetEntityBase()->GetFunction()->GetSysVar("AuthErrMsg", tmpAuthErrMsg) == Error_Succeed && tmpAuthErrMsg.IsNullOrEmpty())
  530. GetEntityBase()->GetFunction()->SetSysVar("AuthErrMsg", CSimpleStringA::Format("%s 启动失败,请尝试重启应用或重启系统恢复", it->first.GetData()).GetData());
  531. if (it->first.Compare("SIPPhone") == 0)
  532. m_bSIPPhoneStartFail = true;
  533. DbgWithLink(LOG_LEVEL_ERROR, LOG_TYPE_SYSTEM)("启动失败:%s", it->first.GetData());
  534. m_csErrEntity = m_csErrEntity + "|" + it->first;
  535. FSMEvent* e = new FSMEvent(USER_EVT_SAFELOAD_FINISHED);
  536. e->param1 = 2;//"SYNC START" enity started failed.
  537. PostEventFIFO(e);
  538. return;
  539. }
  540. //if (errCode != Error_Succeed)
  541. // return;
  542. //else
  543. ret = CheckLoadResult(LOADSTAGE_SAFELOAD);
  544. if (ret == 0 || ret == 2)
  545. goto SAFELOAD_FINISH;
  546. }
  547. break;
  548. default:
  549. break;
  550. }
  551. }
  552. SAFELOAD_FINISH:
  553. if (!bAsync)
  554. {
  555. FSMEvent* e = new FSMEvent(USER_EVT_SAFELOAD_FINISHED);
  556. e->param1 = ret;
  557. PostEventFIFO(e);
  558. }
  559. else
  560. {
  561. ret = CheckLoadResult(LOADSTAGE_SAFELOAD);
  562. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("s2 %d", ret);
  563. if (ret == 0 || ret == 2)
  564. {
  565. FSMEvent* e = new FSMEvent(USER_EVT_SAFELOAD_FINISHED);
  566. e->param1 = ret;
  567. PostEventFIFO(e);
  568. }
  569. }
  570. SAFELOAD_END:
  571. return;
  572. }
  573. void CVtmLoaderFSM::s2_on_exit()
  574. {
  575. LOG_FUNCTION();
  576. }
  577. unsigned int CVtmLoaderFSM::s2_on_event(FSMEvent* pEvt)
  578. {
  579. LOG_FUNCTION();
  580. int ret = 0;
  581. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("s2 event %d,%d", pEvt->iEvt, pEvt->param1);
  582. switch (pEvt->iEvt)
  583. {
  584. case USER_EVT_SAFELOAD_FINISHED:
  585. {
  586. pEvt->SetHandled();
  587. //oiltmp
  588. //according to the system varible TerminalState to do sth.
  589. //Configed
  590. //Breakdown
  591. //Blocking
  592. //Authentication
  593. {
  594. if (pEvt->param1 == 0)
  595. {
  596. //initializer if configured
  597. CSimpleStringA csTermStage("");
  598. ErrorCodeEnum eErrCode;
  599. eErrCode = GetEntityBase()->GetFunction()->GetSysVar("TerminalStage", csTermStage);
  600. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("after safeload to get termstage %s", (LPCTSTR)csTermStage);
  601. if (csTermStage == "B" || csTermStage == "N")
  602. return 1;
  603. }
  604. else if (pEvt->param1 == 2)
  605. ret = 2;
  606. }
  607. //Unsubscrible
  608. }
  609. break;
  610. case USER_EVT_SAFELOAD_EXMINE_FINISHED:
  611. if (pEvt->param1 == 0)
  612. ret = 0;
  613. //do something else oiltmp
  614. pEvt->SetHandled();
  615. break;
  616. default:
  617. break;
  618. }
  619. return ret;
  620. }
  621. //Operating
  622. void CVtmLoaderFSM::s3_on_entry()
  623. {
  624. LogWarn(Severity_Low, Error_Succeed, VtmLoader_BootInfoPrint, "SafeLoad 阶段实体加载完成");
  625. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_USER).setLogCode("QLR040210F15")("Stage Safeload have done.");
  626. Sleep(m_sleepEnterOpMS);
  627. bool bAsync = false;
  628. m_eStage = LOADSTAGE_OPERATING;
  629. int ret = 0;
  630. map<CSimpleStringA, EntityLoadInfo>::iterator it;
  631. CSmartPointer<IEntityFunction> pFunc = GetEntityBase()->GetFunction();
  632. CSmartPointer<IEntityFunctionPrivilege> pFuncPrivilege = pFunc.ConvertCase<IEntityFunctionPrivilege>();
  633. //start entity
  634. ErrorCodeEnum errCode;
  635. vector<CSimpleStringA>::iterator vIt;
  636. if (m_operatingOpt.size() == 0)
  637. goto OPERATING_FINISH;
  638. char startMsg[128];
  639. for (vIt = m_vOperating.begin(); vIt != m_vOperating.end(); ++vIt)
  640. {
  641. CSmartPointer<IAsynWaitSp> spWait;
  642. it = m_operatingOpt.find(*vIt);
  643. if (it == m_operatingOpt.end())
  644. {
  645. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("cannot find %s", (LPCSTR)* vIt);
  646. continue;
  647. }
  648. CEntityRunInfo entRunInfo;
  649. errCode = pFunc->GetEntityRunInfo(it->first, entRunInfo);
  650. if (errCode == Error_Succeed && entRunInfo.eState == EntityState_Idle)
  651. {
  652. it->second.eResult = LOADING_SUCCEED;
  653. ret = CheckLoadResult(LOADSTAGE_OPERATING);
  654. if (ret == 0 || ret == 2)
  655. goto OPERATING_FINISH;
  656. else
  657. continue;
  658. }
  659. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("op start %s,%d", (LPCTSTR)it->first, it->second.loadOpt);
  660. switch (it->second.loadOpt)
  661. {
  662. case LOADOPT_IGNORE:
  663. {
  664. pFuncPrivilege->StartEntity(it->first, NULL, spWait);
  665. if (spWait != NULL)
  666. spWait->WaitAnswer(MAX_IGNORE_TIMEOUT);
  667. it->second.eResult = LOADING_SUCCEED;
  668. ret = CheckLoadResult(LOADSTAGE_OPERATING);
  669. if (ret == 0 || ret == 2)
  670. goto OPERATING_FINISH;
  671. }
  672. break;
  673. case LOADOPT_ASYNC_VERIFY:
  674. errCode = AsyncStartEntity(it->first, NULL, NULL);
  675. bAsync = true;
  676. break;
  677. case LOADOPT_SYNC_VERIFY:
  678. {
  679. ZeroMemory(startMsg, 128);
  680. sprintf(startMsg, "正在启动实体%s...", it->first.GetData());
  681. GetEntityBase()->GetFunction()->ShowStartupInfo(startMsg);
  682. ULONGLONG dwEntityStart = SP::Module::Comm::RVCGetTickCount();
  683. errCode = pFuncPrivilege->StartEntity(it->first, NULL, spWait);
  684. if (errCode == Error_Succeed)
  685. {
  686. if (spWait != NULL)
  687. errCode = spWait->WaitAnswer(MAX_AYSNC_TIMEOUT);
  688. }
  689. else
  690. {
  691. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("StartEntity %s failed(%d).", (LPCSTR)it->first, errCode);
  692. break;
  693. }
  694. ULONGLONG dwEntityEnd = SP::Module::Comm::RVCGetTickCount();
  695. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI("SyncStartEntity").setCostTime((dwEntityEnd - dwEntityStart) / 1000)("%d", errCode);
  696. if (errCode == Error_Succeed)
  697. it->second.eResult = LOADING_SUCCEED;
  698. else if (errCode == Error_TimeOut)
  699. it->second.eResult = LOADING_TIMEOUT;
  700. else
  701. it->second.eResult = LOADING_FAILED;
  702. if (it->second.eResult != Error_Succeed)
  703. {
  704. if (it->first.Compare("SIPPhone") == 0)
  705. m_bSIPPhoneStartFail = true;
  706. DbgWithLink(LOG_LEVEL_ERROR, LOG_TYPE_SYSTEM)("启动失败:%s", it->first.GetData());
  707. m_csErrEntity = m_csErrEntity + "|" + it->first;
  708. FSMEvent* e = new FSMEvent(USER_EVT_OPERATING_FINISHED);
  709. e->param1 = 2;//"SYNC START" enity started failed.
  710. PostEventFIFO(e);
  711. return;
  712. }
  713. if (errCode != Error_Succeed)
  714. return;
  715. else
  716. ret = CheckLoadResult(LOADSTAGE_OPERATING);
  717. if (ret == 0 || ret == 2)
  718. goto OPERATING_FINISH;
  719. }
  720. break;
  721. default:
  722. break;
  723. }
  724. }
  725. OPERATING_FINISH:
  726. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("s3 ret %d", ret);
  727. if (!bAsync)
  728. {
  729. FSMEvent* e = new FSMEvent(USER_EVT_OPERATING_FINISHED);
  730. e->param1 = ret;
  731. PostEventFIFO(e);
  732. }
  733. else
  734. {
  735. ret = CheckLoadResult(LOADSTAGE_OPERATING);
  736. if (ret == 0 || ret == 2)
  737. {
  738. FSMEvent* e = new FSMEvent(USER_EVT_OPERATING_FINISHED);
  739. e->param1 = ret;
  740. PostEventFIFO(e);
  741. }
  742. }
  743. return;
  744. }
  745. void CVtmLoaderFSM::s3_on_exit()
  746. {
  747. LOG_FUNCTION();
  748. }
  749. unsigned int CVtmLoaderFSM::s3_on_event(FSMEvent* pEvt)
  750. {
  751. LOG_FUNCTION();
  752. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("s3(Operating) event %d,%d", pEvt->iEvt, pEvt->param1);
  753. int ret = 0;
  754. switch (pEvt->iEvt)
  755. {
  756. case USER_EVT_OPERATING_FINISHED:
  757. ret = pEvt->param1;
  758. pEvt->SetHandled();
  759. break;
  760. default:
  761. break;
  762. }
  763. return ret;
  764. }
  765. //Idle(Operating finished)
  766. void CVtmLoaderFSM::s4_on_entry()
  767. {
  768. LOG_FUNCTION();
  769. std::map<std::string, std::string> msgInfo;
  770. msgInfo["NetCardCheckCost"] = CSimpleStringA::Format("%d", m_ullNetCardCost).GetData();
  771. msgInfo["NetworkDetectCost"] = CSimpleStringA::Format("%d", m_ullNetDetectCost).GetData();
  772. msgInfo["GetConfigCost"] = CSimpleStringA::Format("%d", m_ullGetConfigCost).GetData();
  773. msgInfo["EntityLoadCost"] = CSimpleStringA::Format("%d", (SP::Module::Comm::RVCGetTickCount() - m_ullEntityLoadStart) / 1000).GetData();
  774. std::pair<bool, std::string> strResult;
  775. strResult = generateJsonStr(msgInfo);
  776. LogWarn(Severity_Low, Error_Succeed, VtmLoader_InfoAboutBootCost, strResult.second.c_str());
  777. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_USER).setLogCode("QLR040210F16")("%s", strResult.second.c_str());
  778. //oiltmp wait for analyse progress, then change to app log format
  779. LogWarn(Severity_Low, Error_Succeed, VtmLoader_NetCard_Cost, msgInfo["NetCardCheckCost"].c_str());
  780. LogWarn(Severity_Low, Error_Succeed, VtmLoader_NetworkDetect_Cost, msgInfo["NetworkDetectCost"].c_str());
  781. LogWarn(Severity_Low, Error_Succeed, VtmLoader_GetConfig_Cost, msgInfo["GetConfigCost"].c_str());
  782. LogWarn(Severity_Low, Error_Succeed, VtmLoader_EntityLoad_Cost, msgInfo["EntityLoadCost"].c_str());
  783. NoticeEntityLoadTask* pTask = new NoticeEntityLoadTask(this,Event_VtmLoader_EntityLoad_Finished);
  784. GetEntityBase()->GetFunction()->PostThreadPoolTask(pTask);
  785. }
  786. void CVtmLoaderFSM::s4_on_exit()
  787. {
  788. LOG_FUNCTION();
  789. }
  790. unsigned int CVtmLoaderFSM::s4_on_event(FSMEvent* pEvt)
  791. {
  792. LOG_FUNCTION();
  793. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("s4 event %d,%d", pEvt->iEvt, pEvt->param1);
  794. switch (pEvt->iEvt)
  795. {
  796. case USER_EVT_CHECK_DEVICE_ENTITY:
  797. pEvt->SetHandled();
  798. {
  799. CheckDeviceEntityEvent* cdee = dynamic_cast<CheckDeviceEntityEvent*>(pEvt);
  800. CheckDeviceEntityTask* pTask = new CheckDeviceEntityTask(this);
  801. pTask->ctx = cdee->ctx;
  802. GetEntityBase()->GetFunction()->PostThreadPoolTask(pTask);
  803. }
  804. break;
  805. case USER_EVT_QUERY_LOCAL_INFO:
  806. pEvt->SetHandled();
  807. {
  808. QueryLocalInfoEvent* qlie = dynamic_cast<QueryLocalInfoEvent*>(pEvt);
  809. QueryLocalInfoTask* pTask = new QueryLocalInfoTask(this);
  810. pTask->ctx = qlie->ctx;
  811. GetEntityBase()->GetFunction()->PostThreadPoolTask(pTask);
  812. }
  813. break;
  814. default:
  815. break;
  816. }
  817. return 0;
  818. }
  819. //Fault
  820. void CVtmLoaderFSM::s5_on_entry()
  821. {
  822. LOG_FUNCTION();
  823. if (m_bSIPPhoneStartFail)
  824. {
  825. NoticeEntityLoadTask* pTask = new NoticeEntityLoadTask(this, Event_VtmLoader_SIPPhoneEntityLoad_Failed);
  826. GetEntityBase()->GetFunction()->PostThreadPoolTask(pTask);
  827. }
  828. else
  829. {
  830. NoticeEntityLoadTask* pTask = new NoticeEntityLoadTask(this, Event_VtmLoader_OtherSyncEntityLoad_Failed);
  831. GetEntityBase()->GetFunction()->PostThreadPoolTask(pTask);
  832. }
  833. }
  834. void CVtmLoaderFSM::s5_on_exit()
  835. {
  836. LOG_FUNCTION();
  837. }
  838. unsigned int CVtmLoaderFSM::s5_on_event(FSMEvent* pEvt)
  839. {
  840. LOG_FUNCTION();
  841. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("s5(Fault) event %d,%d", pEvt->iEvt, pEvt->param1);
  842. switch (pEvt->iEvt)
  843. {
  844. case USER_EVT_CHECK_DEVICE_ENTITY:
  845. pEvt->SetHandled();
  846. {
  847. CheckDeviceEntityEvent* cdee = dynamic_cast<CheckDeviceEntityEvent*>(pEvt);
  848. CheckDeviceEntityTask* pTask = new CheckDeviceEntityTask(this);
  849. pTask->ctx = cdee->ctx;
  850. GetEntityBase()->GetFunction()->PostThreadPoolTask(pTask);
  851. }
  852. break;
  853. case USER_EVT_QUERY_LOCAL_INFO:
  854. pEvt->SetHandled();
  855. {
  856. QueryLocalInfoEvent* qlie = dynamic_cast<QueryLocalInfoEvent*>(pEvt);
  857. QueryLocalInfoTask* pTask = new QueryLocalInfoTask(this);
  858. pTask->ctx = qlie->ctx;
  859. GetEntityBase()->GetFunction()->PostThreadPoolTask(pTask);
  860. }
  861. break;
  862. default:
  863. break;
  864. }
  865. return 0;
  866. }
  867. BOOL CVtmLoaderFSM::DetectNetworkLegality(CSimpleStringA& strInfo)
  868. {
  869. BOOL result(TRUE);
  870. strInfo.Clear();
  871. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("Detect network legality...");
  872. BOOL fLocalLANConnected(FALSE);
  873. unsigned int curTimes = 1;
  874. const unsigned int maxTimes = 3;
  875. do {
  876. CAutoArray<NetworkAdapterItem> netList;
  877. if (SP::Module::Net::GetINETMacAddresses(netList) == Error_Succeed)
  878. {
  879. for (int i = 0; i < netList.GetCount(); i++) {
  880. DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("interface(%d):%s", i, netList[i].description.c_str());
  881. DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("ip(%d):%s", i, netList[i].ip.c_str());
  882. DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("mac(%d):%s", i, netList[i].mac.c_str());
  883. DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("operStatus(%d):%d", i, netList[i].operStatus);
  884. DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("type(%d):%d", i, netList[i].type);
  885. //if (netList[i].type == IF_TYPE_ETHERNET_CSMACD && netList[i].operStatus == IfOperStatusUp)
  886. if (netList[i].operStatus == 1)//oiltest
  887. {
  888. fLocalLANConnected = TRUE;
  889. break;
  890. }
  891. }
  892. }
  893. Sleep(500);
  894. curTimes++;
  895. } while (curTimes < maxTimes && !fLocalLANConnected);
  896. if (!fLocalLANConnected) {
  897. strInfo = "未检查到有网卡连接,请检查网络连接";
  898. result = FALSE;
  899. }
  900. return result;
  901. }
  902. int CVtmLoaderFSM::NetWorkCheckAndGetSetting()
  903. {
  904. //检查网卡状态
  905. DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("to check network status");
  906. CSimpleStringA strMsg(true), tmpTS("X");
  907. //GetEntityBase()->GetFunction()->GetSysVar("TerminalStage", tmpTS);
  908. int netcheckCount = 1;
  909. ULLINT ullTmpStart = SP::Module::Comm::RVCGetTickCount();
  910. while (true)
  911. {
  912. if (!DetectNetworkLegality(strMsg)) {
  913. if (netcheckCount == 1)//oilyang@20250415 only the first time we log RTAxxxx
  914. DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_USER).setLogCode("QLR040210F10").setResultCode("RTA1F00")("can't find valid network interface");
  915. LogWarn(Severity_High, Error_Unexpect, VtmLoader_UserCode_NetCard_UnAvaible, CSimpleStringA::Format("%s。%d 秒后自动重试(第%d次重试)。请检查网线是否插好、网络是否正常"
  916. , strMsg.GetData(), m_iDetectInterval / 1000, netcheckCount).GetData());
  917. //if (tmpTS.Compare("E") != 0)
  918. //{
  919. // GetEntityBase()->GetFunction()->SetSysVar("TerminalStage", "E");
  920. // tmpTS = "E";
  921. //}
  922. Sleep(5000);
  923. netcheckCount++;
  924. }
  925. else
  926. {
  927. m_ullNetCardCost = (SP::Module::Comm::RVCGetTickCount() - ullTmpStart) / 1000;//second
  928. LogWarn(Severity_Low, Error_Succeed, VtmLoader_BootInfoPrint, "网卡状态正常");
  929. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_USER).setLogCode("QLR040210F10")("network interface ok.");
  930. break;
  931. }
  932. }
  933. ullTmpStart = SP::Module::Comm::RVCGetTickCount();
  934. //检查网络连通性(网络连通性是否作为关键路径走配置,默认不是关键路径)
  935. if (!DetectHttpActive())
  936. {
  937. //网络连通性检查未通过,提示确认网络后重启应用?界面加一个重启按钮?
  938. LogWarn(Severity_High, Error_Unexpect, VtmLoader_BootInfoPrint, "网络连通性检查失败,请检查网络");
  939. return -1;
  940. }
  941. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_USER).setLogCode("QLR040210F11")("connect to http(s) service ok.");
  942. m_ullNetDetectCost = (SP::Module::Comm::RVCGetTickCount() - ullTmpStart) / 1000;//second
  943. ToCheckIfInstalling();
  944. ullTmpStart = SP::Module::Comm::RVCGetTickCount();
  945. //拉取配置并通知提前启动的实体(Chromium)
  946. //重试5次,失败则放弃
  947. int getRetry = 0;
  948. while(true)
  949. {
  950. if (GetConfig())
  951. break;
  952. else
  953. {
  954. if (getRetry >= 5)
  955. return -2;
  956. getRetry++;
  957. Sleep(5000 * getRetry);
  958. }
  959. }
  960. m_ullGetConfigCost = (SP::Module::Comm::RVCGetTickCount() - ullTmpStart) / 1000;//second
  961. //加载实体列表
  962. CSimpleStringA csTmpRootIni("");
  963. if (!IsRootINIExist(csTmpRootIni))
  964. {
  965. DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_USER)(CSimpleStringA::Format("root.ini不存在(%s),Set TerminalStage N ", csTmpRootIni.GetData()).GetData());
  966. GetEntityBase()->GetFunction()->SetSysVar("TerminalStage", "N");
  967. }
  968. //oilyang@20241017 to check if have copied dep directory
  969. int copyTries = 0;
  970. while (true)
  971. {
  972. if (m_eDepCopyStage == DepDirInitCopy_NoNeed || m_eDepCopyStage == DepDirInitCopy_CopySuc)
  973. {
  974. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("no need or have done dep copy, DepCopyStage:%d", m_eDepCopyStage);
  975. break;
  976. }
  977. else if (m_eDepCopyStage == DepDirInitCopy_Copying)
  978. {
  979. Sleep(1000);
  980. continue;
  981. }
  982. else
  983. {
  984. LogWarn(Severity_High, Error_Unexpect, VtmLoader_DepDirCopyFailed, "厂商适配器Dep文件拷贝失败,请联系分行IT排查是否安全软件干扰文件拷贝");
  985. Sleep(60000);
  986. copyTries++;
  987. if (copyTries > 4)
  988. {
  989. DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM)("have tried %d times, give up", copyTries);
  990. return -1;
  991. }
  992. m_eDepCopyStage = DepDirInitCopy_Copying;
  993. CopyDepFilesToNewDepPathTask* pCopyTask = new CopyDepFilesToNewDepPathTask(this);
  994. GetEntityBase()->GetFunction()->PostThreadPoolTask(pCopyTask);
  995. }
  996. }
  997. return EntityLoad();
  998. }
  999. int CVtmLoaderFSM::EntityLoad()
  1000. {
  1001. //前提:收到了配置拉取完成的指令,才会进入到这里
  1002. //为了测试,假装已经拿到了集中配置
  1003. m_ullEntityLoadStart = SP::Module::Comm::RVCGetTickCount();
  1004. CSmartPointer<IConfigInfo> spConfigCen,spRunCfg;
  1005. GetEntityBase()->GetFunction()->OpenConfig(Config_CenterSetting, spConfigCen);
  1006. GetEntityBase()->GetFunction()->OpenConfig(Config_Run, spRunCfg);
  1007. CSimpleStringA csCoreBootList(true), csSafeLoadList(true), csOperatingList(true), csKeyCB("CoreBootList."), csKeySL("SafeLoadList."), csKeyOp("OperatingList."), csExcludedLoadList(true);
  1008. spConfigCen->ReadConfigValue(GetEntityBase()->GetEntityName(), (csKeyCB + m_sysInfo.strMachineType).GetData(), csCoreBootList);
  1009. spConfigCen->ReadConfigValue(GetEntityBase()->GetEntityName(), (csKeySL + m_sysInfo.strMachineType).GetData(), csSafeLoadList);
  1010. spConfigCen->ReadConfigValue(GetEntityBase()->GetEntityName(), (csKeyOp + m_sysInfo.strMachineType).GetData(), csOperatingList);
  1011. spConfigCen->ReadConfigValue(GetEntityBase()->GetEntityName(), "ExcludedLoadList", csExcludedLoadList);
  1012. DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("CoreBoot.EntityList.%s:%s", m_sysInfo.strMachineType.GetData(), csCoreBootList.GetData());
  1013. DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("SafeLoad.EntityList.%s:%s", m_sysInfo.strMachineType.GetData(), csSafeLoadList.GetData());
  1014. DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("Operating.EntityList.%s:%s", m_sysInfo.strMachineType.GetData(), csOperatingList.GetData());
  1015. //oiltmp 如果没有配置,则走默认配置
  1016. if (csCoreBootList.IsNullOrEmpty() || csCoreBootList.IndexOf("HealthManager") < 0 || csCoreBootList.IndexOf("AccessAuthorization") < 0
  1017. || csCoreBootList.IndexOf("UpgradeManager") < 0 || csCoreBootList.IndexOf("HeartBeat") < 0
  1018. || csCoreBootList.IndexOf("TokenKeeper") < 0 || csCoreBootList.IndexOf("ResourceWatcher") < 0
  1019. || csCoreBootList.IndexOf("EventConverter") < 0 || csCoreBootList.IndexOf("Alarm") < 0)
  1020. {
  1021. if (csCoreBootList.IsNullOrEmpty())
  1022. {
  1023. LogWarn(Severity_High, Error_Unexpect, VtmLoader_CoreBootCfg_Err, CSimpleStringA::Format("terminalNo[%s] CoreBoot配置为空,请联系总行开发人员检查", m_sysInfo.strTerminalID.GetData()).GetData());
  1024. DbgWithLink(LOG_LEVEL_ERROR, LOG_TYPE_SYSTEM).setLogCode("QLR040210F14").setResultCode("RTA1F05")("terminalNo[%s] CoreBoot配置为空,请联系总行开发人员检查", m_sysInfo.strTerminalID.GetData());
  1025. }
  1026. else
  1027. {
  1028. LogWarn(Severity_High, Error_Unexpect, VtmLoader_CoreBootCfg_Err, CSimpleStringA::Format("terminalNo[%s] CoreBoot配置异常,请联系总行开发人员检查(%s)", m_sysInfo.strTerminalID.GetData(), csCoreBootList.GetData()).GetData());
  1029. DbgWithLink(LOG_LEVEL_ERROR, LOG_TYPE_SYSTEM).setLogCode("QLR040210F14").setResultCode("RTA1F05")(CSimpleStringA::Format("terminalNo[%s] CoreBoot配置异常,请联系总行开发人员检查(%s)",m_sysInfo.strTerminalID.GetData(), csCoreBootList.GetData()));
  1030. }
  1031. }
  1032. spConfigCen->ReadConfigValueInt(GetEntityBase()->GetEntityName(), "SleepEnterOpMS", m_sleepEnterOpMS);
  1033. if (m_sleepEnterOpMS <= 0 || m_sleepEnterOpMS > 20000)
  1034. m_sleepEnterOpMS = 1000;//default
  1035. //save centersetting to runcfg for vtmloader. using it before download centersetting
  1036. int iTmp = 0;
  1037. if (spConfigCen->ReadConfigValueInt("Common", "CanIgnoreAddrDetect", iTmp) == Error_Succeed && iTmp > 0)
  1038. spRunCfg->WriteConfigValueInt("Common", "CanIgnoreAddrDetect", iTmp);
  1039. iTmp = 0;
  1040. if (spConfigCen->ReadConfigValueInt("Common", "MaxAddrDetectTimes", iTmp) == Error_Succeed && iTmp > 0)
  1041. spRunCfg->WriteConfigValueInt("Common", "MaxAddrDetectTimes", iTmp);
  1042. iTmp = 0;
  1043. if (spConfigCen->ReadConfigValueInt("Common", "AddrDetectInterval", iTmp) == Error_Succeed && iTmp > 0)
  1044. spRunCfg->WriteConfigValueInt("Common", "AddrDetectInterval", iTmp);
  1045. CSimpleStringA csTmpAddr(true);
  1046. if (spConfigCen->ReadConfigValue("Common", "SettingDetectAddr", csTmpAddr) == Error_Succeed && !csTmpAddr.IsNullOrEmpty())
  1047. spRunCfg->WriteConfigValue("Common", "SettingDetectAddr", csTmpAddr.GetData());
  1048. csTmpAddr = "";
  1049. if (spConfigCen->ReadConfigValue("Common", "AccessAuthDetectAddr", csTmpAddr) == Error_Succeed && !csTmpAddr.IsNullOrEmpty())
  1050. spRunCfg->WriteConfigValue("Common", "AccessAuthDetectAddr", csTmpAddr.GetData());
  1051. iTmp = 0;
  1052. if (spConfigCen->ReadConfigValueInt(GetEntityBase()->GetEntityName(), "NoCheckMachineModel", iTmp) == Error_Succeed && iTmp == 1)
  1053. m_iNoCheckMachineModel = 1;
  1054. //oilyang@20240407 add check machine model in ST/UAT test room
  1055. if (!CheckConfigInfoInTestRoom())
  1056. return -1;
  1057. CSystemRunInfo sysRunInfo;
  1058. if (GetEntityBase()->GetFunction()->GetSystemRunInfo(sysRunInfo) != Error_Succeed || sysRunInfo.eAppBootState == AppBootState_Init)
  1059. GetEntityBase()->GetFunction()->GetPrivilegeFunction()->RefreshAppBootState(AppBootState_StartEntity);
  1060. else
  1061. DbgWithLink(LOG_LEVEL_ERROR, LOG_TYPE_SYSTEM)("GetSystemRunInfo failed:%d");
  1062. //oilyang@20250715 before load entitys, to set sysvar "AuthErrMsg" to ""
  1063. //oiltmp@20250715 several months later,we can delete this
  1064. ErrorCodeEnum eErrCode = Error_Unexpect;
  1065. if ((eErrCode = GetEntityBase()->GetFunction()->SetSysVar("AuthErrMsg", "",true)) != Error_Succeed)
  1066. DbgWithLink(LOG_LEVEL_ERROR, LOG_TYPE_SYSTEM).setResultCode(RTAERR_SYSVAR_SET_FAILED)("Set sysvar \"AuthErrMsg\" failed:%d", eErrCode);
  1067. LogWarn(Severity_Low, Error_Succeed, VtmLoader_BootInfoPrint, "开始加载实体");
  1068. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI("StartLoadEntity")("开始加载实体");
  1069. m_arrExCludedList.Init(64);
  1070. m_arrExCludedList = csExcludedLoadList.Split('|');
  1071. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("ExcludedLoadList:%s, count:%d", csExcludedLoadList.GetData(), m_arrExCludedList.GetCount());
  1072. m_csEntityList = "GuiConsole|Chromium|VtmLoader|";
  1073. CAutoArray<CSimpleStringA> arrCoreBoot;
  1074. arrCoreBoot.Init(64);
  1075. arrCoreBoot = csCoreBootList.Split('|');
  1076. DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("arrCoreBoot count:%d", arrCoreBoot.GetCount());
  1077. for (int i = 0; i < arrCoreBoot.GetCount(); ++i)
  1078. {
  1079. CAutoArray<CSimpleStringA> arrEntity;
  1080. arrEntity.Init(2);
  1081. arrEntity = arrCoreBoot[i].Split('=');
  1082. if (arrEntity.GetCount() < 2)
  1083. break;
  1084. if (arrEntity[0].Compare("VtmLoader", true) == 0 || arrEntity[0].Compare("Chromium", true) == 0
  1085. || arrEntity[0].Compare("GuiConsole", true) == 0)
  1086. continue;
  1087. //Exclude the "ExcludedLoadList" entity
  1088. if (IfInExcludedLoadList(arrEntity[0]))
  1089. continue;
  1090. m_vCoreBoot.push_back(arrEntity[0]);
  1091. m_csEntityList += arrEntity[0] + "|";
  1092. if (arrEntity[1].Compare("1") == 0)
  1093. m_coreBootOpt[arrEntity[0]].loadOpt = LOADOPT_ASYNC_VERIFY;
  1094. else if (arrEntity[1].Compare("2") == 0)
  1095. m_coreBootOpt[arrEntity[0]].loadOpt = LOADOPT_SYNC_VERIFY;
  1096. else
  1097. m_coreBootOpt[arrEntity[0]].loadOpt = LOADOPT_IGNORE;
  1098. m_coreBootOpt[arrEntity[0].GetData()].eResult = LOADING_INIT;
  1099. //m_entityBootOpt[arrEntity[0].GetData()].initSn = cbNum;
  1100. //cbNum++;
  1101. }
  1102. CAutoArray<CSimpleStringA> arrSafeLoad;
  1103. arrSafeLoad.Init(64);
  1104. arrSafeLoad = csSafeLoadList.Split('|');
  1105. for (int i = 0; i < arrSafeLoad.GetCount(); ++i)
  1106. {
  1107. CAutoArray<CSimpleStringA> arrEntity;
  1108. arrEntity.Init(2);
  1109. arrEntity = arrSafeLoad[i].Split('=');
  1110. if (arrEntity.GetCount() < 2)
  1111. break;
  1112. if (arrEntity[0].Compare("VtmLoader", true) == 0 || arrEntity[0].Compare("Chromium", true) == 0
  1113. || arrEntity[0].Compare("GuiConsole", true) == 0)
  1114. continue;
  1115. //Exclude the "ExcludedLoadList" entity
  1116. if (IfInExcludedLoadList(arrEntity[0]))
  1117. continue;
  1118. //去重,防止前面已经加载了
  1119. if (find(m_vCoreBoot.begin(), m_vCoreBoot.end(), arrEntity[0].GetData()) != m_vCoreBoot.end())
  1120. continue;
  1121. m_vSafeLoad.push_back(arrEntity[0].GetData());
  1122. m_csEntityList += arrEntity[0] + "|";
  1123. if (arrEntity[1].Compare("1") == 0)
  1124. m_safeLoadOpt[arrEntity[0]].loadOpt = LOADOPT_ASYNC_VERIFY;
  1125. else if (arrEntity[1].Compare("2") == 0)
  1126. m_safeLoadOpt[arrEntity[0]].loadOpt = LOADOPT_SYNC_VERIFY;
  1127. else
  1128. m_safeLoadOpt[arrEntity[0]].loadOpt = LOADOPT_IGNORE;
  1129. m_safeLoadOpt[arrEntity[0].GetData()].eResult = LOADING_INIT;
  1130. //m_safeLoadOpt[arrEntity[0].GetData()].initSn = slNum;
  1131. //slNum++;
  1132. }
  1133. CAutoArray<CSimpleStringA> arrOperating;
  1134. arrOperating.Init(64);
  1135. arrOperating = csOperatingList.Split('|');
  1136. for (int i = 0; i < arrOperating.GetCount(); ++i)
  1137. {
  1138. CAutoArray<CSimpleStringA> arrEntity;
  1139. arrEntity.Init(2);
  1140. arrEntity = arrOperating[i].Split('=');
  1141. if (arrEntity.GetCount() < 2)
  1142. break;
  1143. if (arrEntity[0].Compare("VtmLoader", true) == 0 || arrEntity[0].Compare("Chromium", true) == 0
  1144. || arrEntity[0].Compare("GuiConsole", true) == 0)
  1145. continue;
  1146. //Exclude the "ExcludedLoadList" entity
  1147. if (IfInExcludedLoadList(arrEntity[0]))
  1148. continue;
  1149. //去重,防止前面已经加载了
  1150. if (find(m_vCoreBoot.begin(), m_vCoreBoot.end(), arrEntity[0].GetData()) != m_vCoreBoot.end()
  1151. || find(m_vSafeLoad.begin(), m_vSafeLoad.end(), arrEntity[0].GetData()) != m_vSafeLoad.end())
  1152. continue;
  1153. m_vOperating.push_back(arrEntity[0].GetData());
  1154. m_csEntityList += arrEntity[0] + "|";
  1155. if (arrEntity[1].Compare("1") == 0)
  1156. m_operatingOpt[arrEntity[0]].loadOpt = LOADOPT_ASYNC_VERIFY;
  1157. else if (arrEntity[1].Compare("2") == 0)
  1158. m_operatingOpt[arrEntity[0]].loadOpt = LOADOPT_SYNC_VERIFY;
  1159. else
  1160. m_operatingOpt[arrEntity[0]].loadOpt = LOADOPT_IGNORE;
  1161. m_operatingOpt[arrEntity[0].GetData()].eResult = LOADING_INIT;
  1162. //m_operatingOpt[arrEntity[0].GetData()].initSn = opNum;
  1163. //opNum++;
  1164. }
  1165. //oilyang if install VTM ,just wait for msg to start entity
  1166. CSimpleStringA csTermStage("");
  1167. if ((eErrCode = GetEntityBase()->GetFunction()->GetSysVar("TerminalStage", csTermStage)) != Error_Succeed)
  1168. DbgWithLink(LOG_LEVEL_ERROR, LOG_TYPE_SYSTEM).setResultCode(RTAERR_SYSVAR_GET_FAILED)("Get sysvar \"TerminalStage\" failed:%d", eErrCode);
  1169. else
  1170. DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("TerminalStage %s.", csTermStage.GetData());
  1171. if (csTermStage.Compare("N") == 0)//"N" for installing
  1172. {
  1173. //start UpgradeManager
  1174. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("to start entity UpgradeManager");
  1175. CSmartPointer<IEntityFunctionPrivilege> pFuncPrivilege = m_pEntity->GetFunction().ConvertCase<IEntityFunctionPrivilege>();
  1176. CSmartPointer<IAsynWaitSp> spWait;
  1177. eErrCode = pFuncPrivilege->StartEntity("UpgradeManager", NULL, spWait);
  1178. if (eErrCode == Error_Succeed)
  1179. {
  1180. if (spWait != NULL)
  1181. eErrCode = spWait->WaitAnswer(MAX_AYSNC_TIMEOUT);
  1182. }
  1183. else
  1184. {
  1185. DbgWithLink(LOG_LEVEL_ERROR, LOG_TYPE_SYSTEM)("StartEntity UpgradeManager failed(%d).", eErrCode);
  1186. return -1;
  1187. }
  1188. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("to start entity HealthManager");
  1189. eErrCode = pFuncPrivilege->StartEntity("HealthManager", NULL, spWait);
  1190. if (eErrCode == Error_Succeed)
  1191. {
  1192. if (spWait != NULL)
  1193. eErrCode = spWait->WaitAnswer(MAX_AYSNC_TIMEOUT);
  1194. }
  1195. else
  1196. {
  1197. DbgWithLink(LOG_LEVEL_ERROR, LOG_TYPE_SYSTEM)("StartEntity HealthManager failed(%d).", eErrCode);
  1198. return -1;
  1199. }
  1200. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("to start entity InteractiveControl");
  1201. eErrCode = pFuncPrivilege->StartEntity("InteractiveControl", NULL, spWait);
  1202. if (eErrCode == Error_Succeed)
  1203. {
  1204. if (spWait != NULL)
  1205. eErrCode = spWait->WaitAnswer(MAX_AYSNC_TIMEOUT);
  1206. }
  1207. else
  1208. {
  1209. DbgWithLink(LOG_LEVEL_ERROR, LOG_TYPE_SYSTEM)("StartEntity InteractiveControl failed(%d).", eErrCode);
  1210. return -1;
  1211. }
  1212. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("to start entity MediaController");
  1213. eErrCode = pFuncPrivilege->StartEntity("MediaController", NULL, spWait);
  1214. if (eErrCode == Error_Succeed)
  1215. {
  1216. if (spWait != NULL)
  1217. eErrCode = spWait->WaitAnswer(MAX_AYSNC_TIMEOUT);
  1218. }
  1219. else
  1220. {
  1221. DbgWithLink(LOG_LEVEL_ERROR, LOG_TYPE_SYSTEM)("StartEntity MediaController failed(%d).", eErrCode);
  1222. return -1;
  1223. }
  1224. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("to start entity AccessAuthorization");
  1225. eErrCode = pFuncPrivilege->StartEntity("AccessAuthorization", NULL, spWait);
  1226. if (eErrCode == Error_Succeed)
  1227. {
  1228. if (spWait != NULL)
  1229. eErrCode = spWait->WaitAnswer(MAX_AYSNC_TIMEOUT);
  1230. }
  1231. else
  1232. {
  1233. DbgWithLink(LOG_LEVEL_ERROR, LOG_TYPE_SYSTEM)("StartEntity AccessAuthorization failed(%d).", eErrCode);
  1234. return -1;
  1235. }
  1236. //wait for all the things have beed done,then save TerminalNo to root.ini
  1237. while (true)
  1238. {
  1239. m_hSaveTerminalNoVar.Wait();
  1240. return 1;
  1241. }
  1242. }
  1243. return 0;
  1244. }
  1245. int CVtmLoaderFSM::CheckLoadResult(LoadStage eStage)
  1246. {
  1247. int ret = 0;
  1248. CSimpleStringA csLogCode = "QLR040210F14";
  1249. map<CSimpleStringA, EntityLoadInfo>::iterator it;
  1250. if (eStage == LOADSTAGE_COREBOOT)
  1251. it = m_coreBootOpt.begin();
  1252. else if (eStage == LOADSTAGE_SAFELOAD)
  1253. {
  1254. it = m_safeLoadOpt.begin();
  1255. csLogCode = "QLR040210F15";
  1256. }
  1257. else
  1258. {
  1259. it = m_operatingOpt.begin();
  1260. csLogCode = "QLR040210F16";
  1261. }
  1262. while (1)
  1263. {
  1264. switch (it->second.loadOpt)
  1265. {
  1266. case LOADOPT_IGNORE:
  1267. if (it->second.eResult == LOADING_INIT)
  1268. return 1;
  1269. break;
  1270. case LOADOPT_ASYNC_VERIFY:
  1271. case LOADOPT_SYNC_VERIFY:
  1272. default:
  1273. if (it->second.eResult == LOADING_INIT)
  1274. return 3;
  1275. else if (it->second.eResult != LOADING_SUCCEED)
  1276. {
  1277. DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_USER).setLogCode(csLogCode).setResultCode("RTA1F04")("%s start failed", m_csErrEntity);
  1278. LogWarn(Severity_High, Error_Unexpect, VtmLoader_EntityLoad_Failed, CSimpleStringA::Format("实体%s加载失败,启动终止。请排查启动失败实体或重启应用", m_csErrEntity.GetData()));
  1279. m_csErrEntity = m_csErrEntity + "|" + it->first;
  1280. ret = 2;
  1281. if (it->first.Compare("SIPPhone") == 0)
  1282. m_bSIPPhoneStartFail = true;
  1283. }
  1284. break;
  1285. }
  1286. it++;
  1287. if (eStage == LOADSTAGE_COREBOOT && it == m_coreBootOpt.end())
  1288. break;
  1289. else if (eStage == LOADSTAGE_SAFELOAD && it == m_safeLoadOpt.end())
  1290. break;
  1291. else if (eStage == LOADSTAGE_OPERATING && it == m_operatingOpt.end())
  1292. break;
  1293. }
  1294. return ret;
  1295. }
  1296. ErrorCodeEnum CVtmLoaderFSM::AsyncStartEntity(const char* entity_name, const char* cmdline, void* pData)
  1297. {
  1298. CSmartPointer<IEntityFunction> pFunc = m_pEntity->GetFunction();
  1299. ErrorCodeEnum errCode;
  1300. CSmartPointer<IEntityFunctionPrivilege> pFuncPrivilege = pFunc.ConvertCase<IEntityFunctionPrivilege>();
  1301. if (pFuncPrivilege != NULL) {
  1302. CSmartPointer<IAsynWaitSp> spWait;
  1303. errCode = pFuncPrivilege->StartEntity(entity_name, cmdline, spWait);
  1304. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI("AsyncStartEntity")("start entity %s", entity_name);
  1305. if (errCode == Error_Succeed) {
  1306. callback_entry* entry = new callback_entry();
  1307. entry->pRawData = pData;
  1308. entry->EntityName = entity_name;
  1309. entry->ErrorResult = Error_Unexpect;
  1310. entry->op = OP_START_ENTITY;
  1311. if (spWait != NULL)
  1312. spWait->SetCallback(this, entry);
  1313. }
  1314. return errCode;
  1315. }
  1316. else {
  1317. return Error_NoPrivilege;
  1318. }
  1319. }
  1320. void CVtmLoaderFSM::OnAnswer(CSmartPointer<IAsynWaitSp> pAsynWaitSp)
  1321. {
  1322. CSmartPointer<ICallbackListener> spCallback;
  1323. CSmartPointer<IReleasable> pData;
  1324. pAsynWaitSp->GetCallback(spCallback, pData);
  1325. callback_entry* entry = dynamic_cast<callback_entry*>((IReleasable*)(pData.GetRawPointer()));
  1326. entry->ErrorResult = pAsynWaitSp->AsyncGetAnswer();
  1327. callback_entry* new_entry = new callback_entry();
  1328. new_entry->EntityName = entry->EntityName;
  1329. new_entry->ErrorResult = entry->ErrorResult;
  1330. new_entry->op = entry->op;
  1331. new_entry->state = entry->state;
  1332. map<CSimpleStringA, EntityLoadInfo>::iterator it;
  1333. int ret;
  1334. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI("OnAnswer")("stage %d,%s,result %d", m_eStage, (LPCSTR)new_entry->EntityName, new_entry->ErrorResult);
  1335. switch (m_eStage)
  1336. {
  1337. case LOADSTAGE_COREBOOT:
  1338. it = m_coreBootOpt.find(new_entry->EntityName);
  1339. if (it != m_coreBootOpt.end())
  1340. {
  1341. if (new_entry->ErrorResult == Error_Succeed)
  1342. it->second.eResult = LOADING_SUCCEED;
  1343. else if (new_entry->ErrorResult == Error_TimeOut)
  1344. it->second.eResult = LOADING_TIMEOUT;
  1345. else
  1346. it->second.eResult = LOADING_FAILED;
  1347. if (it->second.eResult != Error_Succeed)
  1348. {
  1349. char tmp[64] = { 0 };
  1350. sprintf(tmp, "实体 %s 启动失败-----", it->first.GetData());
  1351. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI("OnAnswer")("启动失败:%s -----", tmp);
  1352. }
  1353. ret = CheckLoadResult(LOADSTAGE_COREBOOT);
  1354. if (ret == 0 || ret == 2)
  1355. {
  1356. FSMEvent* e = new FSMEvent(USER_EVT_COREBOOT_FINISHED);
  1357. e->param1 = ret;
  1358. PostEventFIFO(e);
  1359. }
  1360. }
  1361. break;
  1362. case LOADSTAGE_SAFELOAD:
  1363. it = m_safeLoadOpt.find(new_entry->EntityName);
  1364. if (it != m_safeLoadOpt.end())
  1365. {
  1366. if (new_entry->ErrorResult == Error_Succeed)
  1367. it->second.eResult = LOADING_SUCCEED;
  1368. else if (new_entry->ErrorResult == Error_TimeOut)
  1369. it->second.eResult = LOADING_TIMEOUT;
  1370. else
  1371. it->second.eResult = LOADING_FAILED;
  1372. ret = CheckLoadResult(LOADSTAGE_SAFELOAD);
  1373. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI("OnAnswer")("safeload answer %d", ret);
  1374. if (ret == 0 || ret == 2)
  1375. {
  1376. FSMEvent* e = new FSMEvent(USER_EVT_SAFELOAD_FINISHED);
  1377. e->param1 = ret;
  1378. PostEventFIFO(e);
  1379. }
  1380. }
  1381. else {
  1382. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI("OnAnswer")("cannot find %s", (LPCTSTR)new_entry->EntityName);
  1383. }
  1384. break;
  1385. case LOADSTAGE_OPERATING:
  1386. it = m_operatingOpt.find(new_entry->EntityName);
  1387. if (it != m_operatingOpt.end())
  1388. {
  1389. if (new_entry->ErrorResult == Error_Succeed)
  1390. it->second.eResult = LOADING_SUCCEED;
  1391. else if (new_entry->ErrorResult == Error_TimeOut)
  1392. it->second.eResult = LOADING_TIMEOUT;
  1393. else
  1394. it->second.eResult = LOADING_FAILED;
  1395. ret = CheckLoadResult(LOADSTAGE_OPERATING);
  1396. if (ret == 0 || ret == 2)
  1397. {
  1398. FSMEvent* e = new FSMEvent(USER_EVT_OPERATING_FINISHED);
  1399. e->param1 = ret;
  1400. PostEventFIFO(e);
  1401. }
  1402. }
  1403. break;
  1404. default:
  1405. break;
  1406. }
  1407. }
  1408. DWORD GetDualTime(SYSTEMTIME& t1, SYSTEMTIME& t2)
  1409. {
  1410. //assume t2 > t1...
  1411. //oiltest for simple
  1412. int s1, s2;
  1413. s1 = (t1.wMinute * 60 + t1.wSecond) * 1000 + t1.wMilliseconds;
  1414. s2 = (t2.wMinute * 60 + t2.wSecond) * 1000 + t2.wMilliseconds;
  1415. return s2 - s1;
  1416. }
  1417. void CVtmLoaderFSM::NoticeEntityLoad(int evtCode)
  1418. {
  1419. //oilyang@20240520 in case of healthmanager started failed, we should to restart healthmanager first
  1420. CSimpleStringA csEntityName("HealthManager");
  1421. CSmartPointer<IEntityFunction> spEntityFunction = GetEntityBase()->GetFunction();
  1422. CSmartPointer<IAsynWaitSp> spWait;
  1423. CSmartPointer<IEntityFunctionPrivilege> pFuncPrivilege = spEntityFunction.ConvertCase<IEntityFunctionPrivilege>();
  1424. CEntityRunInfo acInfo;
  1425. ErrorCodeEnum eErrCode = spEntityFunction->GetEntityRunInfo(csEntityName.GetData(), acInfo);
  1426. if (eErrCode == Error_Succeed && acInfo.eState == EntityState_NoStart)
  1427. {
  1428. eErrCode = pFuncPrivilege->StartEntity(csEntityName, NULL, spWait);
  1429. if (eErrCode == Error_Succeed)
  1430. {
  1431. if (spWait != NULL)
  1432. eErrCode = spWait->WaitAnswer(MAX_AYSNC_TIMEOUT);
  1433. }
  1434. else
  1435. DbgWithLink(LOG_LEVEL_ERROR, LOG_TYPE_SYSTEM)("StartEntity HealthManager failed(%d).", eErrCode);
  1436. }
  1437. else if (eErrCode == Error_Succeed && acInfo.eState != EntityState_Idle)
  1438. {
  1439. eErrCode = pFuncPrivilege->TerminateEntity(csEntityName.GetData(), spWait);
  1440. if (eErrCode == Error_Succeed)
  1441. {
  1442. if (spWait != NULL)
  1443. eErrCode = spWait->WaitAnswer(MAX_AYSNC_TIMEOUT);
  1444. }
  1445. else
  1446. DbgWithLink(LOG_LEVEL_ERROR, LOG_TYPE_SYSTEM)("TerminateEntity HealthManager failed(%d).", eErrCode);
  1447. Sleep(5000);
  1448. //(re)start entity
  1449. eErrCode = pFuncPrivilege->StartEntity(csEntityName.GetData(), NULL, spWait);
  1450. if (eErrCode == Error_Succeed)
  1451. {
  1452. if (spWait != NULL)
  1453. eErrCode = spWait->WaitAnswer(MAX_AYSNC_TIMEOUT);
  1454. }
  1455. else
  1456. DbgWithLink(LOG_LEVEL_ERROR, LOG_TYPE_SYSTEM)("StartEntity HealthManager failed(%d).", eErrCode);
  1457. }
  1458. HealthManagerService_ClientBase* pHMClient = new HealthManagerService_ClientBase(m_pEntity);
  1459. int count = 0;
  1460. bool bConnected = false;
  1461. do
  1462. {
  1463. ErrorCodeEnum eErrConn = Error_Unexpect;
  1464. ErrorCodeEnum eErrCall = Error_Unexpect;
  1465. if (!bConnected)
  1466. {
  1467. eErrConn = pHMClient->Connect();
  1468. if (eErrConn == Error_Succeed)
  1469. bConnected = true;
  1470. }
  1471. if (bConnected)
  1472. {
  1473. HealthManagerService_DoEvent_Req req;
  1474. HealthManagerService_DoEvent_Ans ans;
  1475. req.code = evtCode;
  1476. req.entityList = m_csEntityList;
  1477. eErrCall = pHMClient->DoEvent(req, ans, 5000);
  1478. if (eErrCall == Error_Succeed)
  1479. {
  1480. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("Notice HealthManager suc");
  1481. break;
  1482. }
  1483. }
  1484. DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM)("Notice HealthManager failed,eErrConn:%d,eErrCall:%d", eErrConn, eErrCall);
  1485. Sleep(2000);
  1486. count++;
  1487. } while (count < 100);
  1488. //oilyang@20240517 to calculate cost time of entity start after notice healthmanager 4 minutes later (a time that set experientially)
  1489. ULLINT ullStart = SP::Module::Comm::RVCGetTickCount();
  1490. ULLINT ullEnd = SP::Module::Comm::RVCGetTickCount();
  1491. while (1)
  1492. {
  1493. Sleep(60000);
  1494. ullEnd = SP::Module::Comm::RVCGetTickCount();
  1495. if (ullEnd - ullStart > 4 * 60000 - 5000)//leave 5 second for system call?
  1496. break;
  1497. }
  1498. CAutoArray<CSimpleStringA> strEntityNames;
  1499. CAutoArray<int> strEntityIdx;
  1500. CAutoArray<CEntityStartInfo> Infos;
  1501. ErrorCodeEnum eErr = GetEntityBase()->GetFunction()->GetAllEntityStartInfo(strEntityNames, strEntityIdx, Infos);
  1502. for (int i = 0; i < Infos.GetCount(); ++i)
  1503. {
  1504. if (m_csEntityList.IndexOf(strEntityNames[i]) != -1)
  1505. {
  1506. //LogWarn(Severity_Low, Error_Debug, LOG_TRACE_ENTITY_START_TIME,
  1507. // SP::Module::Util::generateConsumeTimeJson(strEntityNames[i], SP::Module::Util::formatTime(Infos[i].startTime).c_str(), GetDualTime(Infos[i].startTime, Infos[i].startEndTime)).GetData());
  1508. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI("EntityStartCost")
  1509. (SP::Module::Util::generateConsumeTimeJson(strEntityNames[i], SP::Module::Util::formatTime(Infos[i].startTime).c_str(), GetDualTime(Infos[i].startTime, Infos[i].startEndTime)).GetData());
  1510. }
  1511. }
  1512. }
  1513. bool CVtmLoaderFSM::DetectHttpActive()
  1514. {
  1515. memset(m_httpCheckResult, 0, sizeof(m_httpCheckResult));
  1516. CSmartPointer<IConfigInfo> pConfigRun;
  1517. CSimpleStringA strSettingAddr(true),strAccessAuthAddr(true);
  1518. CSimpleStringA errMsg;
  1519. ErrorCodeEnum eErr = GetEntityBase()->GetFunction()->OpenConfig(Config_Run, pConfigRun);
  1520. if (eErr == Error_Succeed)
  1521. {
  1522. int iTmp = 0;
  1523. if (pConfigRun->ReadConfigValueInt("Common", "CanIgnoreAddrDetect", iTmp) == Error_Succeed && iTmp > 0)
  1524. m_iCanIgnoreAddrDetect = iTmp;
  1525. iTmp = 0;
  1526. if (pConfigRun->ReadConfigValueInt("Common", "MaxAddrDetectTime", iTmp) == Error_Succeed && iTmp > 0)
  1527. m_ullMaxAddrDetectTime = iTmp;
  1528. iTmp = 0;
  1529. if (pConfigRun->ReadConfigValueInt("Common", "AddrDetectInterval", iTmp) == Error_Succeed && iTmp > 0)
  1530. m_iDetectInterval = iTmp;
  1531. }
  1532. DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("eErr:%d, iDetectInterval:%d", eErr, m_iDetectInterval);
  1533. CSimpleStringA csTmpAddr(true);
  1534. //集中配置探测地址
  1535. pConfigRun->ReadConfigValue("Common", "SettingDetectAddr", csTmpAddr);
  1536. if (csTmpAddr.IsNullOrEmpty())
  1537. {
  1538. #ifdef DEVOPS_ON_ST /*DevOps流水线编译,ST环境*/
  1539. strSettingAddr = "https://accessproxy-service.paasst.cmbchina.cn/centerconfig/rvc/detect";
  1540. #elif defined(DEVOPS_ON_PRD)/*DevOps流水线编译,PRD环境*/
  1541. strSettingAddr = "https://accessproxy-service.paas.cmbchina.cn/centerconfig/rvc/detect";
  1542. #elif defined(DEVOPS_ON_UAT)/*DevOps流水线编译,UAT环境*/
  1543. strSettingAddr = "https://accessproxy-service.paasuat.cmbchina.cn/centerconfig/rvc/detect";
  1544. #elif defined(DEVOPS_ON_DEV)/*DevOps流水线编译,Dev环境*/
  1545. strSettingAddr = "https://accessproxy-service.paas.cmbchina.cn/centerconfig/rvc/detect";
  1546. #else/*本地编译等非DevOps环境编译的版本*/
  1547. strSettingAddr = "https://accessproxy-service.paasst.cmbchina.cn/centerconfig/rvc/detect";
  1548. #endif
  1549. }
  1550. else
  1551. strSettingAddr = csTmpAddr;
  1552. csTmpAddr = "";
  1553. pConfigRun->ReadConfigValue("Common", "AccessAuthDetectAddr", strAccessAuthAddr);
  1554. //准入探测地址
  1555. if (strAccessAuthAddr.IsNullOrEmpty())
  1556. {
  1557. #ifdef DEVOPS_ON_ST /*DevOps流水线编译,ST环境*/
  1558. strAccessAuthAddr = "https://terminalaccess.paasst.cmbchina.cn/tsas/detect";
  1559. #elif defined(DEVOPS_ON_PRD)/*DevOps流水线编译,PRD环境*/
  1560. strAccessAuthAddr = "https://accessproxy-service.paas.cmbchina.cn/tsaccess/tsas/detect";
  1561. #elif defined(DEVOPS_ON_UAT)/*DevOps流水线编译,UAT环境*/
  1562. strAccessAuthAddr = "https://terminalaccess.paasuat.cmbchina.cn/tsas/detect";
  1563. #elif defined(DEVOPS_ON_DEV)/*DevOps流水线编译,Dev环境*/
  1564. strAccessAuthAddr = "https://terminalaccess.paas.cmbchina.cn/tsas/detect";
  1565. #else/*本地编译等非DevOps环境编译的版本*/
  1566. strAccessAuthAddr = "https://terminalaccess.paasst.cmbchina.cn/tsas/detect";
  1567. #endif
  1568. }
  1569. else
  1570. strAccessAuthAddr = csTmpAddr;
  1571. DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("CenterSetting addr:%s, strAccessAuthAddr:%s", strSettingAddr.GetData(), strAccessAuthAddr.GetData());
  1572. HttpConnCheckTask* pCSTask = new HttpConnCheckTask(this, strSettingAddr, HttpAddr_CenterSetting);
  1573. GetEntityBase()->GetFunction()->PostThreadPoolTask(pCSTask);
  1574. HttpConnCheckTask* pAATask = new HttpConnCheckTask(this, strAccessAuthAddr, HttpAddr_AccessAuth);
  1575. GetEntityBase()->GetFunction()->PostThreadPoolTask(pAATask);
  1576. ULLINT beginTick, endTick;
  1577. beginTick = SP::Module::Comm::RVCGetTickCount();
  1578. do {
  1579. Sleep(2000);
  1580. if (m_httpCheckResult[HttpAddr_CenterSetting] == HttpConnResult_OK || m_httpCheckResult[HttpAddr_AccessAuth] == HttpConnResult_OK)
  1581. return true;
  1582. else
  1583. {
  1584. endTick = SP::Module::Comm::RVCGetTickCount();
  1585. }
  1586. } while (endTick - beginTick < m_ullMaxAddrDetectTime);
  1587. if (m_iCanIgnoreAddrDetect > 0)
  1588. return true;
  1589. else
  1590. return false;
  1591. }
  1592. bool CVtmLoaderFSM::IsRootINIExist(CSimpleStringA& path)
  1593. {
  1594. CSimpleStringA csHardwareCfg(true);
  1595. ErrorCodeEnum eErr = GetEntityBase()->GetFunction()->GetPath("HardwareCfg", csHardwareCfg);
  1596. if (eErr != Error_Succeed)
  1597. {
  1598. path = CSimpleStringA::Format("GetPath of HardwareCfg failed(%d)", eErr);
  1599. DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM)("get path of Run failed:%s", SpStrError(eErr));
  1600. return false;
  1601. }
  1602. path = csHardwareCfg + SPLIT_SLASH_STR + "root.ini";
  1603. #if defined(RVC_OS_WIN)
  1604. if (_access(path.GetData(), 0) == 0) {
  1605. #else
  1606. if (access(path.GetData(), F_OK) == 0) {
  1607. #endif
  1608. return true;
  1609. }
  1610. else
  1611. {
  1612. DbgWithLink(LOG_LEVEL_ERROR, LOG_TYPE_SYSTEM)("root.ini(%s) is not exist.", path.GetData());
  1613. return false;
  1614. }
  1615. }
  1616. bool CVtmLoaderFSM::VerifyVer()
  1617. {
  1618. CSmartPointer<IConfigInfo> pConfig;
  1619. GetEntityBase()->GetFunction()->OpenConfig(Config_CenterSetting, pConfig);
  1620. int VerifyVersion = 0;
  1621. CSimpleStringA activeVer;
  1622. bool isVerEqual = false;
  1623. if (Error_Succeed != pConfig->ReadConfigValueInt("Common", "VerifyVersion", VerifyVersion) || Error_Succeed != GetEntityBase()->GetFunction()->GetRunningVersion(activeVer))
  1624. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("read [Common]VerifyVersion failed");
  1625. std::string curVer = std::string(RVC_VERSION_STR);
  1626. if (curVer == activeVer.GetData())
  1627. isVerEqual = true;
  1628. if (!isVerEqual)
  1629. {
  1630. CSimpleString showMsg = CSimpleString::Format("version not equal, file version:%s, acitve verion:%s", curVer.c_str(), activeVer.GetData());
  1631. switch (VerifyVersion)
  1632. {
  1633. case 0:
  1634. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)(showMsg.GetData());
  1635. break;
  1636. case 1:
  1637. m_verShowMsg = showMsg;
  1638. CloseHandle(CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)&AlarmVersionErr, this, 0, NULL));
  1639. break;
  1640. case 2:
  1641. m_verShowMsg = showMsg;
  1642. CloseHandle(CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)&AlarmVersionErr, this, 0, NULL));
  1643. return false;
  1644. break;
  1645. default:
  1646. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("VerifyVersion not support param:%d", VerifyVersion);
  1647. break;
  1648. }
  1649. }
  1650. return true;
  1651. }
  1652. bool CVtmLoaderFSM::GetConfig()
  1653. {
  1654. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("before GetConfig terminalNo:[%s]", m_sysInfo.strTerminalID.GetData());
  1655. //拉取配置前先检查root.ini文件
  1656. CSimpleStringA csTmpRootIni("");
  1657. if (!IsRootINIExist(csTmpRootIni))
  1658. {
  1659. if (m_terminalNoFromWeb.IsNullOrEmpty())
  1660. {
  1661. LogWarn(Severity_High, Error_Unexpect, VtmLoader_BootInfoPrint, CSimpleStringA::Format("安装页面未设置终端号,请检查(%s)", csTmpRootIni.GetData()).GetData());
  1662. return false;
  1663. }
  1664. }
  1665. else if (m_sysInfo.strTerminalID.IsNullOrEmpty())
  1666. {
  1667. LogWarn(Severity_High, Error_Unexpect, VtmLoader_BootInfoPrint, CSimpleStringA::Format("root.ini中终端号为空,请检查(%s)", csTmpRootIni.GetData()).GetData());
  1668. return false;
  1669. }
  1670. ErrorCodeEnum eErr = Error_Succeed;
  1671. LogWarn(Severity_Low, Error_Succeed, VtmLoader_BootInfoPrint, "开始拉取配置");
  1672. VTMInitParam vtmInitParam(m_terminalNoFromWeb.GetData(), SpDefine::channelId, SpDefine::tokenSecret, SpDefine::CommonLaunchUrl, SpDefine::CenterConfigTotal);
  1673. if (Error_Succeed != (eErr = GetEntityBase()->GetFunction()->GetPrivilegeFunction()->InitCfgUrl(vtmInitParam)))
  1674. {
  1675. LogWarn(Severity_High, Error_Unexpect, VtmLoader_GetConfig_InitCfgUrl_Failed, CSimpleStringA::Format("拉取配置,初始化配置地址失败:0x%x(%s)", eErr, SpStrError(eErr)).GetData());
  1676. DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_USER).setLogCode("QLR040210F13").setResultCode("RTA1F01")("Get config,InitCfgUrl failed.");
  1677. LogEvent(Severity_High, Event_VtmLoader_GetConfig_Fail, "拉取配置,初始化配置地址失败");
  1678. return false;
  1679. }
  1680. else
  1681. {
  1682. CSimpleString oldToken, newToken;
  1683. if (Error_Succeed != (eErr = GetEntityBase()->GetFunction()->GetPrivilegeFunction()->TryUpdateToken(oldToken, newToken)))
  1684. {
  1685. DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_USER).setLogCode("QLR040210F13").setResultCode("RTA1F02")("Get config, TryUpdateToken failed:0x%x", eErr);
  1686. LogWarn(Severity_High, Error_Unexpect, VtmLoader_GetConfig_UpdateToken_Failed, CSimpleStringA::Format("拉取配置失败:0x%x(%s)", eErr, SpStrError(eErr)).GetData());
  1687. }
  1688. //update err msg list
  1689. CloseHandle(CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)&errMsgListUpdate, this, 0, NULL));
  1690. //if token update failed,we can also update cfg suc
  1691. if (Error_Succeed != (eErr = GetEntityBase()->GetFunction()->GetPrivilegeFunction()->TryUpdateCfg()))
  1692. {
  1693. LogWarn(Severity_High, Error_Unexpect, VtmLoader_GetConfig_UpdateCfg_Failed, CSimpleStringA::Format("拉取配置失败:0x%x(%s)", eErr, SpStrError(eErr)).GetData());
  1694. DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_USER).setLogCode("QLR040210F13").setResultCode("RTA1F03")("Get config, TryUpdateCfg failed:0x%x", eErr);
  1695. LogEvent(Severity_High, Event_VtmLoader_GetConfig_Fail, "拉取配置失败");
  1696. return false;
  1697. }
  1698. }
  1699. refreshLogLevel();
  1700. //all cfg is ready, then init the entity, set centersetting update timer
  1701. void* pTmpData = NULL;
  1702. ITimerListener* pListener = new TimerOutHelper<CVtmLoaderFSM>(this, &CVtmLoaderFSM::OnCentersettingUpdateTimeout, pTmpData);
  1703. GetEntityBase()->GetFunction()->SetTimer(TIMER_CENTERSETTING_UPDATE_CHECK, pListener, CENTERSETTING_UPDATE_CHECK_TIME);
  1704. CSmartPointer<IConfigInfo> pConfig;
  1705. CSimpleString t_endpoint, t_topicSys, t_topicUser, t_topicBeidou, t_bussSys, t_bussUser, t_VTMWeb;
  1706. eErr = GetEntityBase()->GetFunction()->OpenConfig(Config_CenterSetting, pConfig);
  1707. if (eErr == Error_Succeed && Error_Succeed == pConfig->ReadConfigValue("Common", "SendEndpoint", t_endpoint)
  1708. && Error_Succeed == pConfig->ReadConfigValue("Common", "SendSys", t_topicSys)
  1709. && Error_Succeed == pConfig->ReadConfigValue("Common", "SendUser", t_topicUser)
  1710. && Error_Succeed == pConfig->ReadConfigValue("Common", "SendBeidou", t_topicBeidou)
  1711. && Error_Succeed == pConfig->ReadConfigValue("Common", "BusinessSys", t_bussSys)
  1712. && Error_Succeed == pConfig->ReadConfigValue("Common", "BusinessUser", t_bussUser)
  1713. && Error_Succeed == pConfig->ReadConfigValue("Common", "VTMWeb", t_VTMWeb)
  1714. && 0 != t_topicSys.GetLength()
  1715. && 0 != t_topicUser.GetLength()
  1716. && 0 != t_topicBeidou.GetLength()
  1717. && 0 != t_bussSys.GetLength()
  1718. && 0 != t_bussUser.GetLength()
  1719. && 0 != t_VTMWeb.GetLength())
  1720. {
  1721. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("endpoint:%s, topicSys:%s, topicUser:%s, topicBeidou:%s, bussSys:%s, bussUser:%s, vtmWeb:%s"
  1722. , t_endpoint.GetData(), t_topicSys.GetData(), t_topicUser.GetData(), t_topicBeidou.GetData(), t_bussSys.GetData(), t_bussUser.GetData(), t_VTMWeb.GetData());
  1723. if (0 != t_endpoint.GetLength())
  1724. {
  1725. GetEntityBase()->GetFunction()->GetPrivilegeFunction()->BeginLogSend(t_endpoint.GetData()
  1726. , t_topicSys.GetData(), t_topicUser.GetData(), t_topicBeidou.GetData(), t_bussSys.GetData(), t_bussUser.GetData(), t_VTMWeb.GetData());
  1727. }
  1728. else
  1729. LogWarn(Severity_High, ErrorCodeEnum::Error_Cancel, Event_VtmLoader_GetConfig_Suc, "endpoint is empty, do not begin send log");
  1730. }
  1731. else
  1732. {
  1733. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("read endpoint and topic err, need check centersetting, use default %s-%s-%s-%s-%s-%s-%s"
  1734. , SpDefine::endpoint, SpDefine::topicSys, SpDefine::topicUser, SpDefine::topicBeidou, SpDefine::topicBussSys, SpDefine::topicBussUser, SpDefine::topicVTMWeb);
  1735. GetEntityBase()->GetFunction()->GetPrivilegeFunction()->BeginLogSend(SpDefine::endpoint, SpDefine::topicSys, SpDefine::topicUser, SpDefine::topicBeidou,
  1736. SpDefine::topicBussSys, SpDefine::topicBussUser, SpDefine::topicVTMWeb);
  1737. }
  1738. GetEntityBase()->GetFunction()->GetSystemStaticInfo(m_sysInfo);
  1739. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("terminalNo:%s, MachineModel:%s, MachineType:%s, MachineVersion:%s, DepVersion:%s,Site:%s, Screen:%d, EnrolGPS:%f.%f, EnrolAddr:%s"
  1740. , m_sysInfo.strTerminalID.GetData(), m_sysInfo.strMachineModel.GetData(), m_sysInfo.strMachineType.GetData(), m_sysInfo.MachineVersion.ToString().GetData(),m_sysInfo.CurrDepVersion.GetData()
  1741. , m_sysInfo.strSite.GetData(), m_sysInfo.eScreen, m_sysInfo.EnrolGPS.GetLatitude(), m_sysInfo.EnrolGPS.GetLongitude(), m_sysInfo.strEnrolAddr.GetData());
  1742. int tmpSec = 0;
  1743. if (Error_Succeed == pConfig->ReadConfigValueInt(GetEntityBase()->GetEntityName(), "refreshTokenWaitSec", tmpSec) && tmpSec > 0)
  1744. m_refreshWaitSec = tmpSec;
  1745. int t_sec = 0;
  1746. pConfig->ReadConfigValueInt(GetEntityBase()->GetEntityName(), "UploadLogWaitSec", t_sec);
  1747. if (t_sec > 0)
  1748. m_uploadLogInfo_waitSec = t_sec;
  1749. CloseHandle(CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)& checkUrlActive, this, 0, NULL));
  1750. CloseHandle(CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)& tokenUpdate, this, 0, NULL));
  1751. //通知Chromium实体
  1752. LogEvent(Severity_High, Event_VtmLoader_GetConfig_Suc, "Get config succeed.");
  1753. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_USER).setLogCode("QLR040210F13")("Get config succeed.");
  1754. return true;
  1755. }
  1756. int CVtmLoaderFSM::HttpConnCheck(CSimpleStringA csHttAddr, HttpAddrType eType)
  1757. {
  1758. DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("to HttpConnCheck");
  1759. ULLINT beginTick = SP::Module::Comm::RVCGetTickCount();
  1760. int httpcheckCount = 1;
  1761. bool bCheckOK = false;
  1762. while(true){
  1763. if (m_httpCheckResult[HttpAddr_CenterSetting] == HttpConnResult_OK)
  1764. {
  1765. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("check centersetting ok.");
  1766. return 0;
  1767. }
  1768. else if (m_httpCheckResult[HttpAddr_AccessAuth] == HttpConnResult_OK)
  1769. {
  1770. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("check AccessAuth ok.");
  1771. return 0;
  1772. }
  1773. #if defined(RVC_OS_LINUX)
  1774. string msg;
  1775. int curFlag = HttpProbe(csHttAddr.GetData(), msg, 5);
  1776. if (curFlag > 0 && curFlag < 400)
  1777. bCheckOK = true;
  1778. #else
  1779. bCheckOK = checkHttpActive(csHttAddr.GetData());
  1780. #endif
  1781. if (!bCheckOK)
  1782. {
  1783. LogWarn(Severity_High, Error_Unexpect, VtmLoader_ConnectDetect_Failed, CSimpleStringA::Format("尝试连接总行服务失败(%s),%d 秒后自动重试(第%d次重试)。请确认终端到总行服务网络是否正常", csHttAddr.GetData(), m_iDetectInterval/1000, httpcheckCount).GetData());
  1784. if (httpcheckCount == 1)//oilyang@20250415 only the first time we log RTAxxxx
  1785. DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_USER).setLogCode("QLR040210F11").setResultCode("RTA1F06")("connect to http(s) service(%s) failed.", csHttAddr.GetData());
  1786. m_httpCheckResult[eType] = HttpConnResult_Failed;
  1787. Sleep(m_iDetectInterval);
  1788. httpcheckCount++;
  1789. CAutoArray<NetworkAdapterItem> netList;
  1790. if (SP::Module::Net::GetINETMacAddresses(netList) == Error_Succeed)
  1791. {
  1792. CSimpleStringA tmpDns = GetDns();
  1793. for (int i = 0; i < netList.GetCount(); i++) {
  1794. LogWarn(Severity_Low, Error_Unexpect, VtmLoader_BootInfoPrint, CSimpleStringA::Format("(%d)interface:%s; ip:%s; mac:%s; %s", i, netList[i].description.c_str()
  1795. , netList[i].ip.c_str(), netList[i].mac.c_str(), tmpDns.GetData()).GetData());
  1796. }
  1797. }
  1798. }
  1799. else
  1800. {
  1801. m_httpCheckResult[eType] = HttpConnResult_OK;
  1802. if ((SP::Module::Comm::RVCGetTickCount() - beginTick) > 3000)
  1803. {
  1804. LogWarn(Severity_Middle, Error_Unexpect, VtmLoader_ConnectDetect_Slow, CSimpleStringA::Format("第(%d)次尝试连接总行服务成功(%s),但是网络偏慢,连接花了(%d)秒,请检查网络!"
  1805. , httpcheckCount, csHttAddr.GetData(), (SP::Module::Comm::RVCGetTickCount() - beginTick)/1000).GetData());
  1806. DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_USER).setResultCode("RTA1F07")("尝试连接总行服务成功,但是网络偏慢");
  1807. }
  1808. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_USER).setLogCode("QLR040210F11")("尝试连接总行服务成功(%s)", csHttAddr.GetData());
  1809. return 0;
  1810. }
  1811. }
  1812. return -1;
  1813. }
  1814. CSimpleStringA CVtmLoaderFSM::GetDns()
  1815. {
  1816. CSimpleStringA runInfoPath, csDNSKeyword, csTmpDns("");
  1817. ErrorCodeEnum eErr = GetEntityBase()->GetFunction()->GetPath("runinfo", runInfoPath);
  1818. if (eErr != Error_Succeed) {
  1819. DbgWithLink(LOG_LEVEL_ERROR, LOG_TYPE_SYSTEM)("GetPath runinfo error=%d.", eErr);
  1820. return "";
  1821. }
  1822. runInfoPath = runInfoPath + SPLIT_SLASH_STR + "runcfg" + SPLIT_SLASH_STR + "dns";
  1823. #if defined(RVC_OS_WIN)
  1824. CSimpleStringA csCmd;
  1825. csCmd = CSimpleStringA::Format("cmd /c ipconfig /all >%s", runInfoPath.GetData());
  1826. WinExec((LPCSTR)csCmd, SW_HIDE);
  1827. csDNSKeyword = "DNS 服务器";
  1828. #else
  1829. std::string sucContent, failedContent;
  1830. CSimpleStringA strCmd;
  1831. strCmd = CSimpleStringA::Format("cat /etc/resolv.conf | grep \"nameserver\" >%s", runInfoPath.GetData());
  1832. bool ret = SP::Module::Util::ShellExecute(strCmd.GetData(), sucContent, failedContent);
  1833. csDNSKeyword = "nameserver";
  1834. #endif //RVC_OS_WIN
  1835. ifstream is;
  1836. is.open(runInfoPath.GetData(), ios::binary);
  1837. if (!is.is_open())
  1838. {
  1839. DWORD dwErr = GetLastError();
  1840. DbgWithLink(LOG_LEVEL_ERROR, LOG_TYPE_SYSTEM)("open %s file failed. [%d]", runInfoPath.GetData(), dwErr);
  1841. return "";
  1842. }
  1843. string line;
  1844. while (!is.eof()) {
  1845. getline(is, line);
  1846. //DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("line:%s", line.c_str());
  1847. size_t start = line.find(csDNSKeyword.GetData());
  1848. if (start != string::npos)
  1849. {
  1850. #if defined(RVC_OS_WIN)
  1851. int dnsStart = line.find(": ");
  1852. if (dnsStart != string::npos)
  1853. {
  1854. string xDns = SP::Utility::ToTrim(line.substr(dnsStart + 1, line.length() - dnsStart - 1));
  1855. csTmpDns += xDns.c_str();
  1856. csTmpDns += ";";
  1857. }
  1858. #else
  1859. string xDns = SP::Utility::ToTrim(line.substr(start + csDNSKeyword.GetLength() + 1, line.length() - start - csDNSKeyword.GetLength() - 1));
  1860. csTmpDns += xDns.c_str();
  1861. csTmpDns += ";";
  1862. #endif
  1863. }
  1864. else
  1865. continue;
  1866. }
  1867. return csTmpDns;
  1868. }
  1869. void CVtmLoaderFSM::ToCheckIfInstalling()
  1870. {
  1871. //拉取配置前先检查root.ini文件
  1872. CSimpleStringA csTmpRootIni("");
  1873. if (!IsRootINIExist(csTmpRootIni))
  1874. {
  1875. 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());
  1876. //oiltest
  1877. //OilTestTask* task = new OilTestTask(this);
  1878. //GetEntityBase()->GetFunction()->PostThreadPoolTask(task);
  1879. while (true)
  1880. {
  1881. m_hWaitTerminalNoVar.Wait();
  1882. break;
  1883. }
  1884. }
  1885. }
  1886. void CVtmLoaderFSM::CheckDeviceEntity(SpReqAnsContext<VtmLoaderService_CheckDeviceEntity_Req, VtmLoaderService_CheckDeviceEntity_Ans>::Pointer ctx)
  1887. {
  1888. if (ctx->Req.entityName.IsNullOrEmpty())
  1889. {
  1890. DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM)("ctx->Req.entityName is null or empty.");
  1891. ctx->Answer(Error_Param, VtmLoader_FailToStartEntity);
  1892. return;
  1893. }
  1894. if (!RefreshDeviceConfig(ctx))
  1895. {
  1896. DbgWithLink(LOG_LEVEL_ERROR, LOG_TYPE_SYSTEM)("RefreshDeviceConfig failed.");
  1897. ctx->Answer(Error_Unexpect);
  1898. }
  1899. CEntityStaticInfo staticInfo;
  1900. ErrorCodeEnum eErrCode = Error_Unexpect;
  1901. CSimpleStringA csEntityName = ctx->Req.entityName;
  1902. if ((eErrCode = m_pEntity->GetFunction()->GetEntityStaticInfo(csEntityName.GetData(), staticInfo)) != Error_Succeed)
  1903. {
  1904. DbgWithLink(LOG_LEVEL_ERROR, LOG_TYPE_SYSTEM)("GetEntityStaticInfo(%s), failed:%d", ctx->Req.entityName.GetData(), eErrCode);
  1905. ctx->Answer(Error_Unexpect, VtmLoader_FailToGetEntityInfo);
  1906. return;
  1907. }
  1908. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("staticInfo.wEntityDevelopID:%x", staticInfo.wEntityDevelopID);
  1909. switch (staticInfo.wEntityDevelopID)
  1910. {
  1911. case 0x201:
  1912. case 0x203:
  1913. case 0x204:
  1914. case 0x206:
  1915. case 0x209:
  1916. case 0x213:
  1917. case 0x217:
  1918. case 0x220:
  1919. CheckDeviceBaseEntity(ctx, staticInfo.wEntityDevelopID);
  1920. break;
  1921. case 0x301://SIPPhone
  1922. CheckAudio(ctx);
  1923. break;
  1924. case 0x208://MediaController
  1925. CheckVideo(ctx);
  1926. break;
  1927. default:
  1928. break;
  1929. }
  1930. return;
  1931. }
  1932. void CVtmLoaderFSM::SaveTerminalNo(SpReqAnsContext<VtmLoaderService_SaveTerminalNo_Req, VtmLoaderService_SaveTerminalNo_Ans>::Pointer ctx)
  1933. {
  1934. if (ctx->Req.terminalNo.IsNullOrEmpty())
  1935. {
  1936. DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM)("terminalNo is null or empty");
  1937. ctx->Answer(Error_Param);
  1938. return;
  1939. }
  1940. LogWarn(Severity_Low, Error_Trace, VtmLoader_SetTerminalNo, CSimpleStringA::Format("SaveTerminalNo:[%s]", ctx->Req.terminalNo.GetData()));
  1941. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_USER).setLogCode(VtmLoaderService_LogCode_SaveTerminalNo)("write terminalNo[%s] to root.ini", ctx->Req.terminalNo.GetData());
  1942. ErrorCodeEnum eErr = GetEntityBase()->GetFunction()->GetPrivilegeFunction()->WriteTerminalNoToRootIni(ctx->Req.terminalNo);
  1943. ctx->Answer(eErr);
  1944. }
  1945. void CVtmLoaderFSM::DealWithOldEvent(SpReqAnsContext<VtmLoaderService_DealWithOldEvent_Req, VtmLoaderService_DealWithOldEvent_Ans>::Pointer ctx)
  1946. {
  1947. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("DealWithOldEvent called, %d, %s, %s, %d, %d",
  1948. ctx->Req.eventId, ctx->Req.reqStrRev1.GetData(), ctx->Req.reqStrRev2.GetData(), ctx->Req.reqIntRev1, ctx->Req.reqIntRev2);
  1949. ErrorCodeEnum eErr = ErrorCodeEnum::Error_Succeed;
  1950. switch (ctx->Req.eventId)
  1951. {
  1952. case EVENT_CONSOLE_REQ_SHUTDOWN_SHELL:
  1953. LogWarn(Severity_Low, Error_Unexpect, 0x50100215, CSimpleStringA::Format("%x, reason:%s", EVENT_CONSOLE_REQ_SHUTDOWN_SHELL, ctx->Req.reqStrRev1.GetData()));
  1954. if (RebootWayEnum::RebootWay_OS == ctx->Req.reqIntRev1)
  1955. {
  1956. GetEntityBase()->GetFunction()->GetPrivilegeFunction()->Reboot(RebootTriggerEnum::RebootTrigger_Unknown, RebootWayEnum::RebootWay_OS);
  1957. return;
  1958. }
  1959. #if defined(RVC_OS_WIN)
  1960. do
  1961. {
  1962. STARTUPINFO si;
  1963. PROCESS_INFORMATION pi;
  1964. ZeroMemory(&si, sizeof(si));
  1965. si.cb = sizeof(si);
  1966. ZeroMemory(&pi, sizeof(pi));
  1967. GetEntityBase()->GetFunction()->FlushLogFile();
  1968. CSimpleStringA csRestart, csVerPath, csAll, csSep("\""), csBlank(" "), csScript("wscript.exe"), csReFlag("r");
  1969. csRestart = "sprestart.exe ";
  1970. ErrorCodeEnum Error = GetEntityBase()->GetFunction()->GetPath("RootVer", csVerPath);
  1971. //csVerPath +="\\spexplorerfast.vbs";
  1972. csVerPath += "\\VTM.exe";
  1973. csReFlag = "n";
  1974. csAll = csSep + csRestart + csSep + csBlank + csSep + csVerPath + csSep
  1975. + csBlank + csSep + csReFlag + csSep;
  1976. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("allpath[%s]", (LPCTSTR)csAll);
  1977. LPTSTR szCmdline = _strdup(csAll);
  1978. if (!CreateProcess(NULL, szCmdline, NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi))
  1979. {
  1980. DbgWithLink(LOG_LEVEL_ERROR, LOG_TYPE_SYSTEM)("framework shutdown from console failed, CreateProcess failed (%d).\n", GetLastError());
  1981. eErr = ErrorCodeEnum::Error_Unexpect;
  1982. break;
  1983. }
  1984. DWORD dwErr = GetLastError();
  1985. // Wait until child process exits.
  1986. WaitForSingleObject(pi.hProcess, INFINITE);
  1987. // Close process and thread handles.
  1988. CloseHandle(pi.hProcess);
  1989. CloseHandle(pi.hThread);
  1990. } while (false);
  1991. #endif
  1992. break;
  1993. case LOG_EVT_IEBROWSER_RESET_SITE_RESTART:
  1994. GetEntityBase()->GetFunction()->GetPrivilegeFunction()->Reboot(RebootTriggerEnum::RebootTrigger_Unknown, RebootWayEnum::RebootWay_Framework);
  1995. break;
  1996. default:
  1997. break;
  1998. }
  1999. ctx->Answer(eErr);
  2000. }
  2001. bool CVtmLoaderFSM::RefreshDeviceConfig(SpReqAnsContext<VtmLoaderService_CheckDeviceEntity_Req, VtmLoaderService_CheckDeviceEntity_Ans>::Pointer ctx)
  2002. {
  2003. if (ctx->Req.entityName.IsNullOrEmpty() || ctx->Req.paramNum <= 0)
  2004. {
  2005. DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_USER)("param error! nothing to refresh");
  2006. return false;
  2007. }
  2008. 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());
  2009. if (ctx->Req.module.GetCount() < ctx->Req.paramNum || ctx->Req.name.GetCount() < ctx->Req.paramNum || ctx->Req.value.GetCount() < ctx->Req.paramNum)
  2010. {
  2011. DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_USER)("param array length error! nothing to refresh");
  2012. return false;
  2013. }
  2014. for (int i = 0; i < ctx->Req.paramNum; i++)
  2015. {
  2016. MemCfgParam tmpParam("root", ctx->Req.module[i].GetData(), ctx->Req.name[i].GetData(), ctx->Req.value[i].GetData());
  2017. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_USER)("module:%s,name:%s,value:%s", ctx->Req.module[i].GetData(), ctx->Req.name[i].GetData(), ctx->Req.value[i].GetData());
  2018. GetEntityBase()->GetFunction()->GetPrivilegeFunction()->ModifyMemCfgParam(tmpParam);
  2019. }
  2020. return true;
  2021. }
  2022. void CVtmLoaderFSM::CheckDeviceBaseEntity(SpReqAnsContext<VtmLoaderService_CheckDeviceEntity_Req, VtmLoaderService_CheckDeviceEntity_Ans>::Pointer ctx, WORD wEntityID)
  2023. {
  2024. CSmartPointer<IEntityFunctionPrivilege> pFuncPrivilege = m_pEntity->GetFunction().ConvertCase<IEntityFunctionPrivilege>();
  2025. CSmartPointer<IAsynWaitSp> spWait;
  2026. CEntityRunInfo runInfo;
  2027. CSimpleStringA csEntityName = ctx->Req.entityName;
  2028. //oiltmp@20240415 to be delete after x months
  2029. if (ctx->Req.entityName.Compare("CardIssuer") == 0)
  2030. {
  2031. if (m_sysInfo.strMachineType.Compare("RVC.CardStore") == 0 || m_sysInfo.strMachineType.Compare("RVC.CardPrinter") == 0)
  2032. csEntityName = "CardIssuerStore";
  2033. else
  2034. csEntityName = "CardIssuerStand";
  2035. }
  2036. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("csEntityName:[%s]", csEntityName.GetData());
  2037. //to check entity state
  2038. ErrorCodeEnum eErrCode = m_pEntity->GetFunction()->GetEntityRunInfo(csEntityName.GetData(), runInfo);
  2039. if (eErrCode == Error_Succeed)
  2040. {
  2041. if (runInfo.eState != EntityState_NoStart)
  2042. {
  2043. eErrCode = pFuncPrivilege->TerminateEntity(csEntityName.GetData(), spWait);
  2044. if (spWait != NULL)
  2045. eErrCode = spWait->WaitAnswer(MAX_AYSNC_TIMEOUT);
  2046. }
  2047. }
  2048. else
  2049. {
  2050. DbgWithLink(LOG_LEVEL_ERROR, LOG_TYPE_SYSTEM).setLogCode(VtmLoaderService_LogCode_CheckDeviceEntity).setResultCode("RTA1F24")
  2051. ("GetEntityRunInfo %s failed(%d).", csEntityName.GetData(), eErrCode);
  2052. ctx->Answer(Error_Unexpect, VtmLoader_FailToGetEntityInfo);
  2053. return;
  2054. }
  2055. //(re)start entity
  2056. eErrCode = pFuncPrivilege->StartEntity(csEntityName.GetData(), NULL, spWait);
  2057. if (eErrCode == Error_Succeed)
  2058. {
  2059. if (spWait != NULL)
  2060. eErrCode = spWait->WaitAnswer(MAX_AYSNC_TIMEOUT);
  2061. }
  2062. else
  2063. {
  2064. DbgWithLink(LOG_LEVEL_ERROR, LOG_TYPE_SYSTEM).setLogCode(VtmLoaderService_LogCode_CheckDeviceEntity).setResultCode("RTA1F21")
  2065. ("StartEntity %s failed(%d).", csEntityName.GetData(), eErrCode);
  2066. ctx->Answer(Error_Unexpect, VtmLoader_FailToStartEntity);
  2067. return;
  2068. }
  2069. //TODO we should wait for device entity open suc?
  2070. //Sleep 2 second for simple
  2071. Sleep(2000);
  2072. int count = 0;
  2073. do
  2074. {
  2075. CEntityRunInfo runInfo;
  2076. eErrCode = m_pEntity->GetFunction()->GetEntityRunInfo(csEntityName.GetData(), runInfo);
  2077. if (eErrCode == Error_Succeed)
  2078. {
  2079. if (runInfo.eState == EntityState_Idle)
  2080. break;
  2081. else if (runInfo.eState == EntityState_Lost || runInfo.eState == EntityState_Close || runInfo.eState == EntityState_Killed)
  2082. {
  2083. DbgWithLink(LOG_LEVEL_ERROR, LOG_TYPE_SYSTEM).setLogCode(VtmLoaderService_LogCode_CheckDeviceEntity).setResultCode("RTA1F21")
  2084. ("entity state:%d", runInfo.eState);
  2085. ctx->Answer(Error_Unexpect, VtmLoader_FailToStartEntity);
  2086. return;
  2087. }
  2088. count++;
  2089. if (count > 3)
  2090. {
  2091. DbgWithLink(LOG_LEVEL_ERROR, LOG_TYPE_SYSTEM).setLogCode(VtmLoaderService_LogCode_CheckDeviceEntity).setResultCode("RTA1F21")
  2092. ("entity state:%d", runInfo.eState);
  2093. ctx->Answer(Error_Unexpect, VtmLoader_FailToStartEntity);
  2094. return;
  2095. }
  2096. Sleep(1000);
  2097. }
  2098. else
  2099. {
  2100. DbgWithLink(LOG_LEVEL_ERROR, LOG_TYPE_SYSTEM).setLogCode(VtmLoaderService_LogCode_CheckDeviceEntity).setResultCode("RTA1F21")
  2101. ("GetEntityRunInfo failed:%d", eErrCode);
  2102. ctx->Answer(Error_Unexpect, VtmLoader_FailToStartEntity);
  2103. return;
  2104. }
  2105. } while (true);
  2106. const int retryGetDevInfoInterval = 5000;//5 seconds
  2107. const int maxRetryTimes = 16;//16*5 = 80 seconds ,the web timeout setting is 90s
  2108. CClientSessionBase* pClient;
  2109. int entityState = 0;
  2110. switch (wEntityID)
  2111. {
  2112. case 0x206: //pinpad
  2113. {
  2114. PinPadService_ClientBase* pClient = new PinPadService_ClientBase(this->m_pEntity);
  2115. if (pClient != NULL)
  2116. {
  2117. eErrCode = pClient->Connect();
  2118. if (eErrCode == Error_Succeed)
  2119. {
  2120. int retryTimes = maxRetryTimes;
  2121. do {
  2122. PinPadService_GetDevInfo_Req reqQ;
  2123. PinPadService_GetDevInfo_Ans ansQ;
  2124. eErrCode = (*pClient)(EntityResource::getLink().upgradeLink())->GetDevInfo(reqQ, ansQ, 5000);
  2125. DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("eErrCode:%d,ansQ.state:%d", eErrCode, ansQ.state);
  2126. if (eErrCode == Error_DevNotAvailable)
  2127. {
  2128. DbgWithLink(LOG_LEVEL_ERROR, LOG_TYPE_SYSTEM).setLogCode(VtmLoaderService_LogCode_CheckDeviceEntity).setResultCode("RTA1F23")("%d", eErrCode);
  2129. ctx->Answer(Error_Unexpect, VtmLoader_EntityNotInNormal);
  2130. return;
  2131. }
  2132. else if (eErrCode == Error_Succeed)
  2133. {
  2134. DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("return to caller");
  2135. ctx->Answer(Error_Succeed);
  2136. return;
  2137. }
  2138. Sleep(retryGetDevInfoInterval);
  2139. retryTimes--;
  2140. } while (retryTimes > 0);
  2141. if (retryTimes == 0)
  2142. {
  2143. DbgWithLink(LOG_LEVEL_ERROR, LOG_TYPE_SYSTEM).setLogCode(VtmLoaderService_LogCode_CheckDeviceEntity).setResultCode("RTA1F23")
  2144. ("after have tried x times");
  2145. ctx->Answer(Error_Unexpect, VtmLoader_EntityNotInNormal);
  2146. }
  2147. }
  2148. else {
  2149. DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM).setLogCode(VtmLoaderService_LogCode_CheckDeviceEntity).setResultCode("RTA1F22")
  2150. ("connect to %s failed.error code:%d", csEntityName.GetData(), eErrCode);
  2151. ctx->Answer(Error_Unexpect, VtmLoader_FailToConnectEntity);
  2152. }
  2153. }
  2154. else
  2155. {
  2156. DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM).setLogCode(VtmLoaderService_LogCode_CheckDeviceEntity).setResultCode("RTA1F22")
  2157. ("new client failed.");
  2158. ctx->Answer(Error_Unexpect, VtmLoader_FailToConnectEntity);
  2159. }
  2160. }
  2161. break;
  2162. case 0x201: //IDCertificate
  2163. {
  2164. IDCertService_ClientBase* pClient = new IDCertService_ClientBase(this->m_pEntity);
  2165. if (pClient != NULL)
  2166. {
  2167. eErrCode = pClient->Connect();
  2168. if (eErrCode == Error_Succeed)
  2169. {
  2170. int retryTimes = maxRetryTimes;
  2171. do {
  2172. IDCertService_GetDevInfo_Req reqQ;
  2173. IDCertService_GetDevInfo_Ans ansQ;
  2174. eErrCode = (*pClient)(EntityResource::getLink().upgradeLink())->GetDevInfo(reqQ, ansQ, 5000);
  2175. DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("eErrCode:%d,ansQ.state:%d", eErrCode, ansQ.state);
  2176. if (eErrCode == Error_DevNotAvailable)
  2177. {
  2178. DbgWithLink(LOG_LEVEL_ERROR, LOG_TYPE_SYSTEM).setLogCode(VtmLoaderService_LogCode_CheckDeviceEntity).setResultCode("RTA1F23")("%d", eErrCode);
  2179. ctx->Answer(Error_Unexpect, VtmLoader_EntityNotInNormal);
  2180. return;
  2181. }
  2182. else if (eErrCode == Error_Succeed)
  2183. {
  2184. DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("return to caller");
  2185. ctx->Answer(Error_Succeed);
  2186. return;
  2187. }
  2188. Sleep(retryGetDevInfoInterval);
  2189. retryTimes--;
  2190. } while (retryTimes > 0);
  2191. if (retryTimes == 0)
  2192. {
  2193. DbgWithLink(LOG_LEVEL_ERROR, LOG_TYPE_SYSTEM).setLogCode(VtmLoaderService_LogCode_CheckDeviceEntity).setResultCode("RTA1F23")
  2194. ("after have tried x times");
  2195. ctx->Answer(Error_Unexpect, VtmLoader_EntityNotInNormal);
  2196. }
  2197. }
  2198. else {
  2199. DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM).setLogCode(VtmLoaderService_LogCode_CheckDeviceEntity).setResultCode("RTA1F22")
  2200. ("connect to %s failed.error code:%d", csEntityName.GetData(), eErrCode);
  2201. ctx->Answer(Error_Unexpect, VtmLoader_FailToConnectEntity);
  2202. }
  2203. }
  2204. else
  2205. {
  2206. DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM).setLogCode(VtmLoaderService_LogCode_CheckDeviceEntity).setResultCode("RTA1F22")
  2207. ("new client failed.");
  2208. ctx->Answer(Error_Unexpect, VtmLoader_FailToConnectEntity);
  2209. }
  2210. }
  2211. break;
  2212. case 0x204: //FingerPrint
  2213. {
  2214. FingerPrintService_ClientBase* pClient = new FingerPrintService_ClientBase(this->m_pEntity);
  2215. if (pClient != NULL)
  2216. {
  2217. eErrCode = pClient->Connect();
  2218. if (eErrCode == Error_Succeed)
  2219. {
  2220. int retryTimes = maxRetryTimes;
  2221. do {
  2222. FingerPrintService_GetDevInfo_Req reqQ;
  2223. FingerPrintService_GetDevInfo_Ans ansQ;
  2224. eErrCode = (*pClient)(EntityResource::getLink().upgradeLink())->GetDevInfo(reqQ, ansQ, 5000);
  2225. DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("eErrCode:%d,ansQ.state:%d", eErrCode, ansQ.state);
  2226. if (eErrCode == Error_DevNotAvailable)
  2227. {
  2228. DbgWithLink(LOG_LEVEL_ERROR, LOG_TYPE_SYSTEM).setLogCode(VtmLoaderService_LogCode_CheckDeviceEntity).setResultCode("RTA1F23")("%d", eErrCode);
  2229. ctx->Answer(Error_Unexpect, VtmLoader_EntityNotInNormal);
  2230. return;
  2231. }
  2232. else if (eErrCode == Error_Succeed)
  2233. {
  2234. DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("return to caller");
  2235. ctx->Answer(Error_Succeed);
  2236. return;
  2237. }
  2238. Sleep(retryGetDevInfoInterval);
  2239. retryTimes--;
  2240. } while (retryTimes > 0);
  2241. if (retryTimes == 0)
  2242. {
  2243. DbgWithLink(LOG_LEVEL_ERROR, LOG_TYPE_SYSTEM).setLogCode(VtmLoaderService_LogCode_CheckDeviceEntity).setResultCode("RTA1F23")
  2244. ("after have tried x times");
  2245. ctx->Answer(Error_Unexpect, VtmLoader_EntityNotInNormal);
  2246. }
  2247. }
  2248. else {
  2249. DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM).setLogCode(VtmLoaderService_LogCode_CheckDeviceEntity).setResultCode("RTA1F22")
  2250. ("connect to %s failed.error code:%d", csEntityName.GetData(), eErrCode);
  2251. ctx->Answer(Error_Unexpect, VtmLoader_FailToConnectEntity);
  2252. }
  2253. }
  2254. else
  2255. {
  2256. DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM).setLogCode(VtmLoaderService_LogCode_CheckDeviceEntity).setResultCode("RTA1F22")
  2257. ("new client failed.");
  2258. ctx->Answer(Error_Unexpect, VtmLoader_FailToConnectEntity);
  2259. }
  2260. }
  2261. break;
  2262. case 0x203: //CardIssuerStand
  2263. case 0x220: //CardIssuerStore
  2264. {
  2265. if (m_sysInfo.strMachineType.Compare("RVC.CardStore") == 0 || m_sysInfo.strMachineType.Compare("RVC.CardPrinter") == 0)
  2266. {
  2267. CardIssuerStoreService_ClientBase* pClient = new CardIssuerStoreService_ClientBase(this->m_pEntity);
  2268. if (pClient != NULL)
  2269. {
  2270. eErrCode = pClient->Connect();
  2271. if (eErrCode == Error_Succeed)
  2272. {
  2273. int retryTimes = maxRetryTimes;
  2274. do {
  2275. CardIssuerStoreService_GetDevInfo_Req reqQ;
  2276. CardIssuerStoreService_GetDevInfo_Ans ansQ;
  2277. eErrCode = (*pClient)(EntityResource::getLink().upgradeLink())->GetDevInfo(reqQ, ansQ, 5000);
  2278. DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("eErrCode:%d,ansQ.state:%d", eErrCode, ansQ.state);
  2279. if (eErrCode == Error_DevNotAvailable)
  2280. {
  2281. DbgWithLink(LOG_LEVEL_ERROR, LOG_TYPE_SYSTEM).setLogCode(VtmLoaderService_LogCode_CheckDeviceEntity).setResultCode("RTA1F23")("%d", eErrCode);
  2282. ctx->Answer(Error_Unexpect, VtmLoader_EntityNotInNormal);
  2283. return;
  2284. }
  2285. else if (eErrCode == Error_Succeed)
  2286. {
  2287. DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("return to caller");
  2288. ctx->Answer(Error_Succeed);
  2289. return;
  2290. }
  2291. Sleep(retryGetDevInfoInterval);
  2292. retryTimes--;
  2293. } while (retryTimes > 0);
  2294. if (retryTimes == 0)
  2295. {
  2296. DbgWithLink(LOG_LEVEL_ERROR, LOG_TYPE_SYSTEM).setLogCode(VtmLoaderService_LogCode_CheckDeviceEntity).setResultCode("RTA1F23")
  2297. ("after have tried x times");
  2298. ctx->Answer(Error_Unexpect, VtmLoader_EntityNotInNormal);
  2299. }
  2300. }
  2301. else {
  2302. DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM).setLogCode(VtmLoaderService_LogCode_CheckDeviceEntity).setResultCode("RTA1F22")
  2303. ("connect to %s failed.error code:%d", csEntityName.GetData(), eErrCode);
  2304. ctx->Answer(Error_Unexpect, VtmLoader_FailToConnectEntity);
  2305. }
  2306. }
  2307. else
  2308. {
  2309. DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM).setLogCode(VtmLoaderService_LogCode_CheckDeviceEntity).setResultCode("RTA1F22")
  2310. ("new client failed.");
  2311. ctx->Answer(Error_Unexpect, VtmLoader_FailToConnectEntity);
  2312. }
  2313. }
  2314. else
  2315. {
  2316. CardIssuerStandService_ClientBase* pClient = new CardIssuerStandService_ClientBase(this->m_pEntity);
  2317. if (pClient != NULL)
  2318. {
  2319. eErrCode = pClient->Connect();
  2320. if (eErrCode == Error_Succeed)
  2321. {
  2322. int retryTimes = maxRetryTimes;
  2323. do {
  2324. CardIssuerStandService_GetDevInfo_Req reqQ;
  2325. CardIssuerStandService_GetDevInfo_Ans ansQ;
  2326. eErrCode = (*pClient)(EntityResource::getLink().upgradeLink())->GetDevInfo(reqQ, ansQ, 5000);
  2327. DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("eErrCode:%d,ansQ.state:%d", eErrCode, ansQ.state);
  2328. if (eErrCode == Error_DevNotAvailable)
  2329. {
  2330. DbgWithLink(LOG_LEVEL_ERROR, LOG_TYPE_SYSTEM).setLogCode(VtmLoaderService_LogCode_CheckDeviceEntity).setResultCode("RTA1F23")("%d", eErrCode);
  2331. ctx->Answer(Error_Unexpect, VtmLoader_EntityNotInNormal);
  2332. return;
  2333. }
  2334. else if (eErrCode == Error_Succeed)
  2335. {
  2336. DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("return to caller");
  2337. ctx->Answer(Error_Succeed);
  2338. return;
  2339. }
  2340. Sleep(retryGetDevInfoInterval);
  2341. retryTimes--;
  2342. } while (retryTimes > 0);
  2343. if (retryTimes == 0)
  2344. {
  2345. DbgWithLink(LOG_LEVEL_ERROR, LOG_TYPE_SYSTEM).setLogCode(VtmLoaderService_LogCode_CheckDeviceEntity).setResultCode("RTA1F23")
  2346. ("after have tried x times");
  2347. ctx->Answer(Error_Unexpect, VtmLoader_EntityNotInNormal);
  2348. }
  2349. }
  2350. else {
  2351. DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM).setLogCode(VtmLoaderService_LogCode_CheckDeviceEntity).setResultCode("RTA1F22")
  2352. ("connect to %s failed.error code:%d", csEntityName.GetData(), eErrCode);
  2353. ctx->Answer(Error_Unexpect, VtmLoader_FailToConnectEntity);
  2354. }
  2355. }
  2356. else
  2357. {
  2358. DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM).setLogCode(VtmLoaderService_LogCode_CheckDeviceEntity).setResultCode("RTA1F22")
  2359. ("new client failed.");
  2360. ctx->Answer(Error_Unexpect, VtmLoader_FailToConnectEntity);
  2361. }
  2362. }
  2363. }
  2364. break;
  2365. case 0x209: //gpio
  2366. {
  2367. GpioService_ClientBase* pClient = new GpioService_ClientBase(this->m_pEntity);
  2368. if (pClient != NULL)
  2369. {
  2370. eErrCode = pClient->Connect();
  2371. if (eErrCode == Error_Succeed)
  2372. {
  2373. int retryTimes = maxRetryTimes;
  2374. do {
  2375. GpioService_GetDevInfo_Req reqQ;
  2376. GpioService_GetDevInfo_Ans ansQ;
  2377. eErrCode = (*pClient)(EntityResource::getLink().upgradeLink())->GetDevInfo(reqQ, ansQ, 5000);
  2378. DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("eErrCode:%d,ansQ.state:%d", eErrCode, ansQ.state);
  2379. if (eErrCode == Error_DevNotAvailable)
  2380. {
  2381. DbgWithLink(LOG_LEVEL_ERROR, LOG_TYPE_SYSTEM).setLogCode(VtmLoaderService_LogCode_CheckDeviceEntity).setResultCode("RTA1F23")("%d", eErrCode);
  2382. ctx->Answer(Error_Unexpect, VtmLoader_EntityNotInNormal);
  2383. return;
  2384. }
  2385. else if (eErrCode == Error_Succeed)
  2386. {
  2387. DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("return to caller");
  2388. ctx->Answer(Error_Succeed);
  2389. return;
  2390. }
  2391. Sleep(retryGetDevInfoInterval);
  2392. retryTimes--;
  2393. } while (retryTimes > 0);
  2394. if (retryTimes == 0)
  2395. {
  2396. DbgWithLink(LOG_LEVEL_ERROR, LOG_TYPE_SYSTEM).setLogCode(VtmLoaderService_LogCode_CheckDeviceEntity).setResultCode("RTA1F23")
  2397. ("after have tried x times");
  2398. ctx->Answer(Error_Unexpect, VtmLoader_EntityNotInNormal);
  2399. }
  2400. }
  2401. else {
  2402. DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM).setLogCode(VtmLoaderService_LogCode_CheckDeviceEntity).setResultCode("RTA1F22")
  2403. ("connect to %s failed.error code:%d", csEntityName.GetData(), eErrCode);
  2404. ctx->Answer(Error_Unexpect, VtmLoader_FailToConnectEntity);
  2405. }
  2406. }
  2407. else
  2408. {
  2409. DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM).setLogCode(VtmLoaderService_LogCode_CheckDeviceEntity).setResultCode("RTA1F22")
  2410. ("new client failed.");
  2411. ctx->Answer(Error_Unexpect, VtmLoader_FailToConnectEntity);
  2412. }
  2413. }
  2414. break;
  2415. case 0x213: //ContactlessCard
  2416. {
  2417. ContactlessCardService_ClientBase* pClient = new ContactlessCardService_ClientBase(this->m_pEntity);
  2418. if (pClient != NULL)
  2419. {
  2420. eErrCode = pClient->Connect();
  2421. if (eErrCode == Error_Succeed)
  2422. {
  2423. int retryTimes = maxRetryTimes;
  2424. do {
  2425. ContactlessCardService_GetDevInfo_Req reqQ;
  2426. ContactlessCardService_GetDevInfo_Ans ansQ;
  2427. eErrCode = (*pClient)(EntityResource::getLink().upgradeLink())->GetDevInfo(reqQ, ansQ, 5000);
  2428. DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("eErrCode:%d,ansQ.state:%d", eErrCode, ansQ.state);
  2429. if (eErrCode == Error_DevNotAvailable)
  2430. {
  2431. DbgWithLink(LOG_LEVEL_ERROR, LOG_TYPE_SYSTEM).setLogCode(VtmLoaderService_LogCode_CheckDeviceEntity).setResultCode("RTA1F23")("%d", eErrCode);
  2432. ctx->Answer(Error_Unexpect, VtmLoader_EntityNotInNormal);
  2433. return;
  2434. }
  2435. else if (eErrCode == Error_Succeed)
  2436. {
  2437. DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("return to caller");
  2438. ctx->Answer(Error_Succeed);
  2439. return;
  2440. }
  2441. Sleep(retryGetDevInfoInterval);
  2442. retryTimes--;
  2443. } while (retryTimes > 0);
  2444. if (retryTimes == 0)
  2445. {
  2446. DbgWithLink(LOG_LEVEL_ERROR, LOG_TYPE_SYSTEM).setLogCode(VtmLoaderService_LogCode_CheckDeviceEntity).setResultCode("RTA1F23")
  2447. ("after have tried x times");
  2448. ctx->Answer(Error_Unexpect, VtmLoader_EntityNotInNormal);
  2449. }
  2450. }
  2451. else {
  2452. DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM).setLogCode(VtmLoaderService_LogCode_CheckDeviceEntity).setResultCode("RTA1F22")
  2453. ("connect to %s failed.error code:%d", csEntityName.GetData(), eErrCode);
  2454. ctx->Answer(Error_Unexpect, VtmLoader_FailToConnectEntity);
  2455. }
  2456. }
  2457. else
  2458. {
  2459. DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM).setLogCode(VtmLoaderService_LogCode_CheckDeviceEntity).setResultCode("RTA1F22")
  2460. ("new client failed.");
  2461. ctx->Answer(Error_Unexpect, VtmLoader_FailToConnectEntity);
  2462. }
  2463. }
  2464. break;
  2465. case 0x217:
  2466. {
  2467. HSPScannerService_ClientBase* pClient = new HSPScannerService_ClientBase(this->m_pEntity);
  2468. if (pClient != NULL)
  2469. {
  2470. eErrCode = pClient->Connect();
  2471. if (eErrCode == Error_Succeed)
  2472. {
  2473. int retryTimes = maxRetryTimes;
  2474. do {
  2475. HSPScannerService_GetDevInfo_Req reqQ;
  2476. HSPScannerService_GetDevInfo_Ans ansQ;
  2477. eErrCode = (*pClient)(EntityResource::getLink().upgradeLink())->GetDevInfo(reqQ, ansQ, 5000);
  2478. DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("eErrCode:%d,ansQ.state:%d", eErrCode, ansQ.state);
  2479. if (eErrCode == Error_DevNotAvailable)
  2480. {
  2481. DbgWithLink(LOG_LEVEL_ERROR, LOG_TYPE_SYSTEM).setLogCode(VtmLoaderService_LogCode_CheckDeviceEntity).setResultCode("RTA1F23")("%d", eErrCode);
  2482. ctx->Answer(Error_Unexpect, VtmLoader_EntityNotInNormal);
  2483. return;
  2484. }
  2485. else if (eErrCode == Error_Succeed)
  2486. {
  2487. DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("return to caller");
  2488. ctx->Answer(Error_Succeed);
  2489. return;
  2490. }
  2491. Sleep(retryGetDevInfoInterval);
  2492. retryTimes--;
  2493. } while (retryTimes > 0);
  2494. if (retryTimes == 0)
  2495. {
  2496. DbgWithLink(LOG_LEVEL_ERROR, LOG_TYPE_SYSTEM).setLogCode(VtmLoaderService_LogCode_CheckDeviceEntity).setResultCode("RTA1F23")
  2497. ("after have tried x times");
  2498. ctx->Answer(Error_Unexpect, VtmLoader_EntityNotInNormal);
  2499. }
  2500. }
  2501. else {
  2502. DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM).setLogCode(VtmLoaderService_LogCode_CheckDeviceEntity).setResultCode("RTA1F22")
  2503. ("connect to %s failed.error code:%d", csEntityName.GetData(), eErrCode);
  2504. ctx->Answer(Error_Unexpect, VtmLoader_FailToConnectEntity);
  2505. }
  2506. }
  2507. else
  2508. {
  2509. DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM).setLogCode(VtmLoaderService_LogCode_CheckDeviceEntity).setResultCode("RTA1F22")
  2510. ("new client failed.");
  2511. ctx->Answer(Error_Unexpect, VtmLoader_FailToConnectEntity);
  2512. }
  2513. }
  2514. break;
  2515. default:
  2516. break;
  2517. }
  2518. return;
  2519. }
  2520. void CVtmLoaderFSM::CheckAudio(SpReqAnsContext<VtmLoaderService_CheckDeviceEntity_Req, VtmLoaderService_CheckDeviceEntity_Ans>::Pointer ctx)
  2521. {
  2522. CSmartPointer<IEntityFunctionPrivilege> pFuncPrivilege = m_pEntity->GetFunction().ConvertCase<IEntityFunctionPrivilege>();
  2523. CSmartPointer<IAsynWaitSp> spWait;
  2524. CEntityRunInfo runInfo;
  2525. //to check entity state
  2526. ErrorCodeEnum eErrCode = m_pEntity->GetFunction()->GetEntityRunInfo(ctx->Req.entityName.GetData(), runInfo);
  2527. if (eErrCode == Error_Succeed)
  2528. {
  2529. if (runInfo.eState != EntityState_NoStart)
  2530. {
  2531. eErrCode = pFuncPrivilege->TerminateEntity(ctx->Req.entityName.GetData(), spWait);
  2532. if (spWait != NULL)
  2533. eErrCode = spWait->WaitAnswer(MAX_AYSNC_TIMEOUT);
  2534. }
  2535. }
  2536. else
  2537. {
  2538. DbgWithLink(LOG_LEVEL_ERROR, LOG_TYPE_SYSTEM)("GetEntityRunInfo %s failed(%d).", ctx->Req.entityName.GetData(), eErrCode);
  2539. ctx->Answer(Error_Unexpect, VtmLoader_FailToGetEntityInfo);
  2540. return;
  2541. }
  2542. //(re)start entity
  2543. eErrCode = pFuncPrivilege->StartEntity(ctx->Req.entityName.GetData(), NULL, spWait);
  2544. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("StartEntity %s eErrCode(%d).", ctx->Req.entityName.GetData(), eErrCode);
  2545. if (eErrCode == Error_Succeed)
  2546. {
  2547. if (spWait != NULL)
  2548. eErrCode = spWait->WaitAnswer(MAX_AYSNC_TIMEOUT);
  2549. }
  2550. else
  2551. {
  2552. DbgWithLink(LOG_LEVEL_ERROR, LOG_TYPE_SYSTEM)("StartEntity %s failed(%d).", ctx->Req.entityName.GetData(), eErrCode);
  2553. ctx->Answer(Error_Unexpect, VtmLoader_FailToStartEntity);
  2554. return;
  2555. }
  2556. //TODO we should wait for device entity open suc?
  2557. int count = 0;
  2558. do
  2559. {
  2560. eErrCode = m_pEntity->GetFunction()->GetEntityRunInfo(ctx->Req.entityName.GetData(), runInfo);
  2561. if (eErrCode == Error_Succeed)
  2562. {
  2563. if (runInfo.eState == EntityState_Idle || runInfo.eState == EntityState_Lost)
  2564. {
  2565. CSimpleStringA csSoundCardState("");
  2566. eErrCode = GetEntityBase()->GetFunction()->GetSysVar("SoundCardState", csSoundCardState);
  2567. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("eErrCode:%d csSoundCardState:%s", eErrCode, csSoundCardState.GetData());
  2568. if (eErrCode == Error_Succeed)
  2569. {
  2570. if (csSoundCardState.Compare("N") == 0)
  2571. ctx->Answer(Error_Succeed);
  2572. else if (csSoundCardState.Compare("C") == 0)
  2573. ctx->Answer(Error_Unexpect, VtmLoader_CheckAudio_CfgEmpty);
  2574. else if (csSoundCardState.Compare("B") == 0)
  2575. ctx->Answer(Error_Unexpect, VtmLoader_CheckAudio_CfgBothError);
  2576. else if (csSoundCardState.Compare("P") == 0)
  2577. ctx->Answer(Error_Unexpect, VtmLoader_CheckAudio_CfgPickupError);
  2578. else if (csSoundCardState.Compare("H") == 0)
  2579. ctx->Answer(Error_Unexpect, VtmLoader_CheckAudio_CfgHandFreeError);
  2580. return;
  2581. }
  2582. else
  2583. {
  2584. DbgWithLink(LOG_LEVEL_ERROR, LOG_TYPE_SYSTEM)("failed to get sysvar SoundCardState , eErrCode:%d", eErrCode);
  2585. ctx->Answer(Error_Unexpect, VtmLoader_FailToStartEntity);
  2586. return;
  2587. }
  2588. }
  2589. else
  2590. {
  2591. Sleep(2000);
  2592. count++;
  2593. if (count > 5)
  2594. {
  2595. DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM)("after timeout, entity state is not we want...(Idle or Lost)");
  2596. ctx->Answer(Error_Unexpect, VtmLoader_FailToStartEntity);
  2597. return;
  2598. }
  2599. continue;
  2600. }
  2601. }
  2602. else
  2603. {
  2604. DbgWithLink(LOG_LEVEL_ERROR, LOG_TYPE_SYSTEM)("failed to GetEntityRunInfo, eErrCode:%d", eErrCode);
  2605. ctx->Answer(Error_Unexpect, VtmLoader_FailToStartEntity);
  2606. return;
  2607. }
  2608. } while (true);
  2609. }
  2610. void CVtmLoaderFSM::CheckVideo(SpReqAnsContext<VtmLoaderService_CheckDeviceEntity_Req, VtmLoaderService_CheckDeviceEntity_Ans>::Pointer ctx)
  2611. {
  2612. CSmartPointer<IEntityFunctionPrivilege> pFuncPrivilege = m_pEntity->GetFunction().ConvertCase<IEntityFunctionPrivilege>();
  2613. CSmartPointer<IAsynWaitSp> spWait;
  2614. CEntityRunInfo runInfo;
  2615. //to check entity state
  2616. ErrorCodeEnum eErrCode = m_pEntity->GetFunction()->GetEntityRunInfo(ctx->Req.entityName.GetData(), runInfo);
  2617. if (eErrCode == Error_Succeed)
  2618. {
  2619. if (runInfo.eState != EntityState_NoStart)
  2620. {
  2621. eErrCode = pFuncPrivilege->TerminateEntity(ctx->Req.entityName.GetData(), spWait);
  2622. if (spWait != NULL)
  2623. eErrCode = spWait->WaitAnswer(MAX_AYSNC_TIMEOUT);
  2624. }
  2625. }
  2626. else
  2627. {
  2628. DbgWithLink(LOG_LEVEL_ERROR, LOG_TYPE_SYSTEM)("GetEntityRunInfo %s failed(%d).", ctx->Req.entityName.GetData(), eErrCode);
  2629. ctx->Answer(Error_Unexpect, VtmLoader_FailToGetEntityInfo);
  2630. return;
  2631. }
  2632. m_bMediaControllerOK = false;
  2633. //(re)start entity
  2634. eErrCode = pFuncPrivilege->StartEntity(ctx->Req.entityName.GetData(), NULL, spWait);
  2635. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("StartEntity %s eErrCode(%d).", ctx->Req.entityName.GetData(), eErrCode);
  2636. if (eErrCode == Error_Succeed)
  2637. {
  2638. if (spWait != NULL)
  2639. eErrCode = spWait->WaitAnswer(MAX_AYSNC_TIMEOUT);
  2640. }
  2641. else
  2642. {
  2643. DbgWithLink(LOG_LEVEL_ERROR, LOG_TYPE_SYSTEM)("StartEntity %s failed(%d).", ctx->Req.entityName.GetData(), eErrCode);
  2644. ctx->Answer(Error_Unexpect, VtmLoader_FailToStartEntity);
  2645. return;
  2646. }
  2647. //TODO we should wait for device entity open suc?
  2648. int count = 0;
  2649. do
  2650. {
  2651. if (!m_bMediaControllerOK)
  2652. {
  2653. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("wait for MediaController to check video setting");
  2654. Sleep(2000);
  2655. count++;
  2656. if (count > 5)
  2657. {
  2658. DbgWithLink(LOG_LEVEL_ERROR, LOG_TYPE_SYSTEM)("after timeout, entity state is not right");
  2659. ctx->Answer(Error_Unexpect, VtmLoader_FailToStartEntity);
  2660. return;
  2661. }
  2662. continue;
  2663. }
  2664. CEntityRunInfo runInfo;
  2665. eErrCode = m_pEntity->GetFunction()->GetEntityRunInfo(ctx->Req.entityName.GetData(), runInfo);
  2666. if (eErrCode == Error_Succeed)
  2667. {
  2668. if (runInfo.eState == EntityState_Idle)
  2669. {
  2670. CSimpleStringA csCameraState("");
  2671. eErrCode = GetEntityBase()->GetFunction()->GetSysVar("CameraState", csCameraState);
  2672. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("eErrCode:%d csCameraState:%s", eErrCode, csCameraState.GetData());
  2673. if (eErrCode == Error_Succeed && csCameraState.Compare("N") == 0)
  2674. {
  2675. ctx->Answer(Error_Succeed);
  2676. return;
  2677. }
  2678. else
  2679. {
  2680. ctx->Answer(Error_Unexpect, VtmLoader_CheckVideoCfgFail);
  2681. return;
  2682. }
  2683. }
  2684. else if (runInfo.eState == EntityState_Lost || runInfo.eState == EntityState_Close || runInfo.eState == EntityState_Killed)
  2685. {
  2686. DbgWithLink(LOG_LEVEL_ERROR, LOG_TYPE_SYSTEM)("runInfo.eState:%d", runInfo.eState);
  2687. ctx->Answer(Error_Unexpect, VtmLoader_FailToStartEntity);
  2688. return;
  2689. }
  2690. }
  2691. else
  2692. {
  2693. DbgWithLink(LOG_LEVEL_ERROR, LOG_TYPE_SYSTEM)("failed to GetEntityRunInfo, eErrCode:%d", eErrCode);
  2694. ctx->Answer(Error_Unexpect, VtmLoader_FailToStartEntity);
  2695. return;
  2696. }
  2697. } while (true);
  2698. }
  2699. bool CVtmLoaderFSM::CheckConfigInfoInTestRoom()
  2700. {
  2701. if (m_iNoCheckMachineModel)
  2702. return true;
  2703. bool bNeedCheckOK = false;
  2704. #ifdef DEVOPS_ON_ST /*DevOps流水线编译,ST环境*/
  2705. bNeedCheckOK = true;
  2706. #elif defined(DEVOPS_ON_UAT)/*DevOps流水线编译,UAT环境*/
  2707. bNeedCheckOK = true;
  2708. #endif
  2709. if (bNeedCheckOK)
  2710. {
  2711. DoSpecialJobInTestRoom();
  2712. //to check MachineType
  2713. CSmartPointer<IConfigInfo> spConfigRoot;
  2714. if (GetEntityBase()->GetFunction()->OpenConfig(Config_Root, spConfigRoot) != Error_Succeed)
  2715. {
  2716. return true;
  2717. }
  2718. if (m_sysInfo.strMachineType.Compare("RVC.Stand2S") != 0 && m_sysInfo.strMachineType.Compare("RVC.CardStore")
  2719. && m_sysInfo.strMachineType.Compare("RVC.CardPrinter") && m_sysInfo.strMachineType.Compare("RVC.Stand1SPlus"))
  2720. {
  2721. if (m_sysInfo.strMachineType.IsNullOrEmpty())
  2722. LogWarn(Severity_High, Error_Unexpect, VtmLoader_BootInfoPrint, CSimpleStringA::Format("机型machineType配置为空,请检查", m_sysInfo.strMachineType.GetData()));
  2723. else
  2724. LogWarn(Severity_High, Error_Unexpect, VtmLoader_BootInfoPrint, CSimpleStringA::Format("机型machineType(%s)不对,请检查", m_sysInfo.strMachineType.GetData()));
  2725. return false;
  2726. }
  2727. //to check Terminal App Version
  2728. CSmartPointer<IConfigInfo> spConfigCen;
  2729. if (GetEntityBase()->GetFunction()->OpenConfig(Config_CenterSetting, spConfigCen) == Error_Succeed)
  2730. {
  2731. CSimpleStringA csWinVerPrefix(""), csUosVerPrefix(""), csStaticVerPrefix("");
  2732. spConfigCen->ReadConfigValue(GetEntityBase()->GetEntityName(), "WinVerPrefix", csWinVerPrefix);
  2733. spConfigCen->ReadConfigValue(GetEntityBase()->GetEntityName(), "UosVerPrefix", csUosVerPrefix);
  2734. csStaticVerPrefix = CSimpleStringA::Format("%d.%d",m_sysInfo.InstallVersion.GetMajor(), m_sysInfo.InstallVersion.GetMinor());
  2735. #if defined(RVC_OS_LINUX)
  2736. if (csUosVerPrefix.IsNullOrEmpty())
  2737. return true;
  2738. else
  2739. {
  2740. CAutoArray<CSimpleStringA> arrVer = csUosVerPrefix.Split('.');
  2741. if (arrVer.GetCount() > 1)
  2742. {
  2743. int major = atoi(arrVer[0].GetData());
  2744. int minor = atoi(arrVer[1].GetData());
  2745. if (m_sysInfo.InstallVersion.GetMajor() > major || (m_sysInfo.InstallVersion.GetMajor() == major && m_sysInfo.InstallVersion.GetMinor() > minor))
  2746. {
  2747. DbgWithLink(LOG_LEVEL_ERROR, LOG_TYPE_SYSTEM)("current version:%s, csUosVerPrefix:%s", m_sysInfo.InstallVersion.ToString().GetData(), csUosVerPrefix.GetData());
  2748. return false;
  2749. }
  2750. }
  2751. }
  2752. #else
  2753. if (csWinVerPrefix.IsNullOrEmpty())
  2754. return true;
  2755. else
  2756. {
  2757. CAutoArray<CSimpleStringA> arrVer = csWinVerPrefix.Split('.');
  2758. if (arrVer.GetCount() > 1)
  2759. {
  2760. int major = atoi(arrVer[0].GetData());
  2761. int minor = atoi(arrVer[1].GetData());
  2762. if (m_sysInfo.InstallVersion.GetMajor() > major || (m_sysInfo.InstallVersion.GetMajor() == major && m_sysInfo.InstallVersion.GetMinor() > minor))
  2763. {
  2764. DbgWithLink(LOG_LEVEL_ERROR, LOG_TYPE_SYSTEM)("current version:%s, csWinVerPrefix:%s", m_sysInfo.InstallVersion.ToString().GetData(), csWinVerPrefix.GetData());
  2765. return false;
  2766. }
  2767. }
  2768. }
  2769. #endif
  2770. }
  2771. }
  2772. return true;
  2773. }
  2774. bool CVtmLoaderFSM::CheckIfNeedCopyDepFiles()
  2775. {
  2776. //check if exist root.ini
  2777. CSimpleStringA csTmpRootIni("");
  2778. if (!IsRootINIExist(csTmpRootIni))
  2779. {
  2780. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("not exist root.ini, no need copy dep files.");
  2781. return false;
  2782. }
  2783. //check if exist run/dep/depver.txt
  2784. CSimpleStringA csRun(true), csPath(true);
  2785. ErrorCodeEnum eErr = GetEntityBase()->GetFunction()->GetPath("Run", csRun);
  2786. if (eErr != Error_Succeed)
  2787. {
  2788. DbgWithLink(LOG_LEVEL_ERROR, LOG_TYPE_SYSTEM)("get path of Run failed:%s", SpStrError(eErr));
  2789. return false;
  2790. }
  2791. csPath = csRun + SPLIT_SLASH_STR + "dep" + SPLIT_SLASH_STR + "depver.txt";
  2792. #if defined(RVC_OS_WIN)
  2793. if (_access(csPath.GetData(), 0) == 0) {
  2794. #else
  2795. if (access(csPath.GetData(), F_OK) == 0) {
  2796. #endif
  2797. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("depver.txt(%s) exist, no need to do dep copy.", csPath.GetData());
  2798. return false;
  2799. }
  2800. else
  2801. {
  2802. DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM)("depver.txt(%s) is not exist.", csPath.GetData());
  2803. return true;
  2804. }
  2805. }
  2806. void CVtmLoaderFSM::CopyDepFilesToNewDepPath()
  2807. {
  2808. //create run/dep/0.0.0.1 directory
  2809. CSimpleStringA csRun(true), csDepBakPath(true), csPath(true);
  2810. ErrorCodeEnum eErr = GetEntityBase()->GetFunction()->GetPath("Run", csRun);
  2811. if (eErr != Error_Succeed)
  2812. {
  2813. DbgWithLink(LOG_LEVEL_ERROR, LOG_TYPE_SYSTEM)("get path of Run failed:%s", SpStrError(eErr));
  2814. m_eDepCopyStage = DepDirInitCopy_CopyFailed;
  2815. return;
  2816. }
  2817. csPath = csRun + SPLIT_SLASH_STR + "dep" + SPLIT_SLASH_STR + "0.0.0.1";
  2818. if (!CreateDirA(csPath.GetData(), TRUE))
  2819. {//TODO: CrossPlaform [Gifur@2025730]
  2820. #ifdef RVC_OS_WIN
  2821. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("Create default dep version dir fail: %d", GetLastError());
  2822. #else
  2823. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("Create default dep version dir fail: %d", errno);
  2824. #endif
  2825. m_eDepCopyStage = DepDirInitCopy_CopyFailed;
  2826. return;
  2827. }
  2828. else
  2829. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("Create default dep version dir %s suc", csPath.GetData());
  2830. eErr = GetEntityBase()->GetFunction()->GetPath("DepBak", csDepBakPath);
  2831. if (eErr != Error_Succeed)
  2832. {
  2833. DbgWithLink(LOG_LEVEL_ERROR, LOG_TYPE_SYSTEM)("get path of DepBak failed:%s", SpStrError(eErr));
  2834. m_eDepCopyStage = DepDirInitCopy_CopyFailed;
  2835. return;
  2836. }
  2837. //xcopy C:\sourceDir C:\destDir /E /I /Y
  2838. //cp -r /path/to/source /path/to/destination
  2839. std::string sucContent, failedContent;
  2840. CSimpleStringA strCmd;
  2841. #if defined(RVC_OS_WIN)
  2842. strCmd = CSimpleStringA::Format("cmd.exe /c xcopy %s %s /E /I /Y", csDepBakPath.GetData(), csPath.GetData());
  2843. #else
  2844. strCmd = CSimpleStringA::Format("cp -r -f %s/* %s", csDepBakPath.GetData(), csPath.GetData());
  2845. #endif //RVC_OS_WIN
  2846. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("to execute:%s", strCmd.GetData());
  2847. ULONGLONG ullCopyBeginTick = SP::Module::Comm::RVCGetTickCount();
  2848. bool ret = SP::Module::Util::ShellExecute(strCmd.GetData(), sucContent, failedContent);
  2849. ULONGLONG ullCopyEndTick = SP::Module::Comm::RVCGetTickCount();
  2850. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("ret:%d, sucContent:%s, failedContent:%s, costtime(ms):%d", ret, sucContent.c_str(), failedContent.c_str(), ullCopyEndTick - ullCopyBeginTick);
  2851. if (ret)
  2852. {
  2853. //更新适配器版本号文件内容
  2854. CSimpleStringA csVersion("0.0.0.1");
  2855. eErr = GetEntityBase()->GetFunction()->GetPrivilegeFunction()->RewriteDepVersion(csVersion, true);
  2856. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("[RewriteDepVersion] %s,%s", SpStrError(eErr), csVersion.GetData());
  2857. m_eDepCopyStage = DepDirInitCopy_CopySuc;
  2858. LogWarn(Severity_Low, Error_Succeed, VtmLoader_DepDirCopySuc, CSimpleStringA::Format("%d", ullCopyEndTick - ullCopyBeginTick));
  2859. }
  2860. else
  2861. {
  2862. m_eDepCopyStage = DepDirInitCopy_CopyFailed;
  2863. DbgWithLink(LOG_LEVEL_ERROR, LOG_TYPE_SYSTEM).setResultCode("RTA1F08")("copy dep to new dep path failed, failedContent:%s", failedContent.c_str());
  2864. }
  2865. }
  2866. bool CVtmLoaderFSM::IfInExcludedLoadList(CSimpleStringA csEntityName)
  2867. {
  2868. if (csEntityName.IsNullOrEmpty())
  2869. return true;
  2870. for (int i = 0; i < m_arrExCludedList.GetCount(); ++i)
  2871. {
  2872. if (csEntityName.Compare(m_arrExCludedList[i], true) == 0)
  2873. return true;
  2874. }
  2875. return false;
  2876. }
  2877. void CVtmLoaderFSM::DoSpecialJobInTestRoom()
  2878. {
  2879. //special job including the following things:
  2880. //1.switch to the terminal app version you want
  2881. //2.delete other version directory you want
  2882. //3.just do it simple and straightforward
  2883. CSmartPointer<IConfigInfo> spConfigCen, spRunCfg;
  2884. if (GetEntityBase()->GetFunction()->OpenConfig(Config_CenterSetting, spConfigCen) == Error_Succeed)
  2885. {
  2886. CSimpleStringA csHaveSwitchVerTo("");
  2887. ErrorCodeEnum eErr = GetEntityBase()->GetFunction()->OpenConfig(Config_Run, spRunCfg);
  2888. if (eErr == Error_Succeed)
  2889. spRunCfg->ReadConfigValue(GetEntityBase()->GetEntityName(), "HaveSwitchVerTo", csHaveSwitchVerTo);
  2890. CSimpleStringA csSwitchVerTo("");
  2891. spConfigCen->ReadConfigValue(GetEntityBase()->GetEntityName(), "SwitchVerTo", csSwitchVerTo);
  2892. DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("SwitchVerTo:[%s], HaveSwitchVerTo:[%s]", csSwitchVerTo.GetData(), csHaveSwitchVerTo.GetData());
  2893. if (csSwitchVerTo.IsNullOrEmpty() || csSwitchVerTo.Compare(csHaveSwitchVerTo) == 0)
  2894. return;
  2895. //更新终端应用版本号文件内容
  2896. CSimpleStringA csRun(true), csActiveFilePath(true);
  2897. eErr = GetEntityBase()->GetFunction()->GetPath("Run", csRun);
  2898. if (eErr != Error_Succeed)
  2899. {
  2900. DbgWithLink(LOG_LEVEL_ERROR, LOG_TYPE_SYSTEM)("get path of Run failed:%s", SpStrError(eErr));
  2901. return;
  2902. }
  2903. csActiveFilePath = csRun + SPLIT_SLASH_STR + "version" + SPLIT_SLASH_STR + "active.txt";
  2904. HANDLE hFile = ::CreateFileA(csActiveFilePath.GetData(), GENERIC_WRITE, 0, NULL, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
  2905. BOOL bSetSucc = FALSE;
  2906. if (hFile == INVALID_HANDLE_VALUE)
  2907. {
  2908. DbgWithLink(LOG_LEVEL_ERROR, LOG_TYPE_SYSTEM)("open %s failed! err=%u", csActiveFilePath, GetLastError());
  2909. return;
  2910. }
  2911. DWORD dwWrittenLen(0);
  2912. bSetSucc = WriteFile(hFile, csSwitchVerTo.GetData(), csSwitchVerTo.GetLength(), &dwWrittenLen, NULL);
  2913. FlushFileBuffers(hFile);
  2914. SetEndOfFile(hFile);
  2915. CloseHandle(hFile);
  2916. spRunCfg->WriteConfigValue(GetEntityBase()->GetEntityName(), "HaveSwitchVerTo", csSwitchVerTo.GetData());
  2917. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("write version [%s] succeed", csSwitchVerTo.GetData());
  2918. #if defined(RVC_OS_LINUX)
  2919. if (bSetSucc) {
  2920. mode_t f_attrib = S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | S_IWGRP | S_IXGRP | S_IROTH | S_IXOTH | S_IWOTH;
  2921. chmod(csActiveFilePath.GetData(), f_attrib);
  2922. }
  2923. else {
  2924. DbgWithLink(LOG_LEVEL_ERROR, LOG_TYPE_SYSTEM)("bSetSucc fail");
  2925. }
  2926. #endif //RVC_OS_LINUX
  2927. Sleep(10000);
  2928. GetEntityBase()->GetFunction()->GetPrivilegeFunction()->Reboot(RebootTrigger_ManualLocal, RebootWayEnum::RebootWay_Framework);
  2929. }
  2930. }
  2931. DWORD CVtmLoaderFSM::GetCenterCfgThread()
  2932. {
  2933. bool isUpdate = false, isReset = false;
  2934. CSimpleString version;
  2935. if (false == GetEntityBase()->GetFunction()->HasPrivilege())
  2936. {
  2937. LogWarn(Severity_High, Error_Unexpect, VtmLoader_CenterSettingConnectFailed,
  2938. CSimpleStringA::Format("下载集中配置失败:%s do not has privilege", __FUNCTION__));
  2939. DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_USER).setLogCode("QLR0402101Z01").setResultCode("RTA1104")("集中配置下载失败");
  2940. return -1;
  2941. }
  2942. auto ret = GetEntityBase()->GetFunction()->GetPrivilegeFunction()->TryUpdateCenterCfg(isUpdate, isReset, version);
  2943. if (ret != ErrorCodeEnum::Error_Succeed)
  2944. {
  2945. LogWarn(Severity_High, Error_Unexpect, VtmLoader_CenterSettingConnectFailed,
  2946. CSimpleStringA::Format("下载集中配置失败:%s", SpStrError(ret)));
  2947. DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_USER).setLogCode("QLR0402101Z01").setResultCode("RTA1104")("集中配置下载失败");
  2948. return -1;
  2949. }
  2950. if (!isUpdate)
  2951. {
  2952. return -1;
  2953. }
  2954. LogWarn(Severity_Low, Error_Succeed, VtmLoader_CenterSettingUpdateSucceed,
  2955. CSimpleStringA::Format("下载集中配置成功,版本号变更成:%s", version.GetData()));
  2956. if (isReset)
  2957. LogEvent(Severity_Middle, EVENT_MOD_CENTERSETTING_CRITICAL_UPDATE, "SpShell:Update centersetting with critical items.");
  2958. return 0;
  2959. }
  2960. void CVtmLoaderFSM::OnCentersettingUpdateTimeout(void* pData)
  2961. {
  2962. GetCenterCfgThread();
  2963. GetEntityBase()->GetFunction()->ResetTimer(TIMER_CENTERSETTING_UPDATE_CHECK, CENTERSETTING_UPDATE_CHECK_TIME);
  2964. }
  2965. CSimpleStringA CVtmLoaderFSM::GetOsVersion()
  2966. {
  2967. #if defined(RVC_OS_WIN)
  2968. CSimpleStringA runInfoPath;
  2969. ErrorCodeEnum eErr = GetEntityBase()->GetFunction()->GetPath("runinfo", runInfoPath);
  2970. if (eErr != Error_Succeed) {
  2971. DbgWithLink(LOG_LEVEL_ERROR, LOG_TYPE_SYSTEM).setResultCode(RTAERR_GETPATH_FAILED)("GetPath runinfo error=%d.", eErr);
  2972. return "";
  2973. }
  2974. runInfoPath += "\\runcfg\\osverion";
  2975. CSimpleStringA csCmd;
  2976. csCmd = CSimpleStringA::Format("cmd /c ver >%s", runInfoPath);
  2977. WinExec((LPCSTR)csCmd, SW_HIDE);
  2978. ifstream is;
  2979. is.open(runInfoPath.GetData(), ios::binary);
  2980. if (is.is_open())
  2981. {
  2982. string line;
  2983. while (!is.eof()) {
  2984. getline(is, line);
  2985. int start = line.find("版本");
  2986. if (start != string::npos)
  2987. {
  2988. DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("ver:[%s]", line.c_str());
  2989. return CSimpleStringA(line.c_str());
  2990. }
  2991. else
  2992. continue;
  2993. }
  2994. }
  2995. else
  2996. {
  2997. DWORD dwErr = GetLastError();
  2998. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("open runcfg\\osverion file failed. [%d]", dwErr);
  2999. }
  3000. return "";
  3001. #else
  3002. std::map<std::string, std::string> osInfo;
  3003. const char filePath[] = "/etc/os-version";
  3004. char tmp[33];
  3005. memset(tmp, 0, 33);
  3006. inifile_read_str_s("Version", "SystemName", "unknown", tmp, 32, filePath);
  3007. osInfo["SystemName"] = tmp;
  3008. memset(tmp, 0, 33);
  3009. inifile_read_str_s("Version", "ProductType", "unknown", tmp, 32, filePath);
  3010. osInfo["ProductType"] = tmp;
  3011. memset(tmp, 0, 33);
  3012. inifile_read_str_s("Version", "MajorVersion", "unknown", tmp, 32, filePath);
  3013. osInfo["MajorVersion"] = tmp;
  3014. memset(tmp, 0, 33);
  3015. inifile_read_str_s("Version", "MinorVersion", "unknown", tmp, 32, filePath);
  3016. osInfo["MinorVersion"] = tmp;
  3017. memset(tmp, 0, 33);
  3018. inifile_read_str_s("Version", "OsBuild", "unknown", tmp, 32, filePath);
  3019. osInfo["OsBuild"] = tmp;
  3020. return generateJsonStr(osInfo).second.c_str();
  3021. #endif
  3022. }
  3023. void CVtmLoaderFSM::QueryLocalInfo(SpReqAnsContext<VtmLoaderService_QueryLocalInfo_Req, VtmLoaderService_QueryLocalInfo_Ans>::Pointer ctx)
  3024. {
  3025. #ifdef RVC_OS_WIN
  3026. ctx->Ans.VtmAppType = "Windows";
  3027. #else
  3028. ctx->Ans.VtmAppType = "UOS";
  3029. #endif
  3030. CSimpleStringA csRunPath("");
  3031. GetEntityBase()->GetFunction()->GetPath("Run", csRunPath);
  3032. ctx->Ans.AppPath = csRunPath;
  3033. CAutoArray<NetworkAdapterItem> netList;
  3034. if (SP::Module::Net::GetINETMacAddresses(netList) == Error_Succeed)
  3035. {
  3036. CSimpleStringA csMac(""), csIP("");
  3037. for (int i = 0; i < netList.GetCount(); i++) {
  3038. if (!csMac.IsNullOrEmpty()) {
  3039. csMac += ";";
  3040. }
  3041. csMac += netList[i].mac.c_str();
  3042. if (!csIP.IsNullOrEmpty()) {
  3043. csIP += ";";
  3044. }
  3045. csIP += netList[i].ip.c_str();
  3046. }
  3047. ctx->Ans.IPs = csIP;
  3048. ctx->Ans.MACs = csMac;
  3049. }
  3050. ctx->Ans.DNSs = GetDns();
  3051. ctx->Ans.OSVersion = GetOsVersion();
  3052. ctx->Answer(Error_Succeed);
  3053. }