VtmLoaderFSM.cpp 117 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186
  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 "HealthManager_client_g.h"
  19. #include "PinPad_client_g.h"
  20. #include "CardIssuerStand_client_g.h"
  21. #include "CardIssuerStore_client_g.h"
  22. #include "IDCertificate_client_g.h"
  23. #include "HSPScanner_client_g.h"
  24. #include "ContactlessCard_client_g.h"
  25. #include "FingerPrint_client_g.h"
  26. #include "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(ExistsFileA(path)) {
  1604. return true;
  1605. }
  1606. else
  1607. {
  1608. DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM).setResultCode("RTA1f09")("root.ini(%s) is not exist.", path.GetData());
  1609. return false;
  1610. }
  1611. }
  1612. bool CVtmLoaderFSM::VerifyVer()
  1613. {
  1614. CSmartPointer<IConfigInfo> pConfig;
  1615. GetEntityBase()->GetFunction()->OpenConfig(Config_CenterSetting, pConfig);
  1616. int VerifyVersion = 0;
  1617. CSimpleStringA activeVer;
  1618. bool isVerEqual = false;
  1619. if (Error_Succeed != pConfig->ReadConfigValueInt("Common", "VerifyVersion", VerifyVersion) || Error_Succeed != GetEntityBase()->GetFunction()->GetRunningVersion(activeVer))
  1620. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("read [Common]VerifyVersion failed");
  1621. std::string curVer = std::string(RVC_VERSION_STR);
  1622. if (curVer == activeVer.GetData())
  1623. isVerEqual = true;
  1624. if (!isVerEqual)
  1625. {
  1626. CSimpleString showMsg = CSimpleString::Format("version not equal, file version:%s, acitve verion:%s", curVer.c_str(), activeVer.GetData());
  1627. switch (VerifyVersion)
  1628. {
  1629. case 0:
  1630. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)(showMsg.GetData());
  1631. break;
  1632. case 1:
  1633. m_verShowMsg = showMsg;
  1634. CloseHandle(CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)&AlarmVersionErr, this, 0, NULL));
  1635. break;
  1636. case 2:
  1637. m_verShowMsg = showMsg;
  1638. CloseHandle(CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)&AlarmVersionErr, this, 0, NULL));
  1639. return false;
  1640. break;
  1641. default:
  1642. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("VerifyVersion not support param:%d", VerifyVersion);
  1643. break;
  1644. }
  1645. }
  1646. return true;
  1647. }
  1648. bool CVtmLoaderFSM::GetConfig()
  1649. {
  1650. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("before GetConfig terminalNo:[%s]", m_sysInfo.strTerminalID.GetData());
  1651. //拉取配置前先检查root.ini文件
  1652. CSimpleStringA csTmpRootIni("");
  1653. if (!IsRootINIExist(csTmpRootIni))
  1654. {
  1655. if (m_terminalNoFromWeb.IsNullOrEmpty())
  1656. {
  1657. LogWarn(Severity_High, Error_Unexpect, VtmLoader_BootInfoPrint, CSimpleStringA::Format("安装页面未设置终端号,请检查(%s)", csTmpRootIni.GetData()).GetData());
  1658. return false;
  1659. }
  1660. }
  1661. else if (m_sysInfo.strTerminalID.IsNullOrEmpty())
  1662. {
  1663. LogWarn(Severity_High, Error_Unexpect, VtmLoader_BootInfoPrint, CSimpleStringA::Format("root.ini中终端号为空,请检查(%s)", csTmpRootIni.GetData()).GetData());
  1664. return false;
  1665. }
  1666. ErrorCodeEnum eErr = Error_Succeed;
  1667. LogWarn(Severity_Low, Error_Succeed, VtmLoader_BootInfoPrint, "开始拉取配置");
  1668. VTMInitParam vtmInitParam(m_terminalNoFromWeb.GetData(), SpDefine::channelId, SpDefine::tokenSecret, SpDefine::CommonLaunchUrl, SpDefine::CenterConfigTotal);
  1669. if (Error_Succeed != (eErr = GetEntityBase()->GetFunction()->GetPrivilegeFunction()->InitCfgUrl(vtmInitParam)))
  1670. {
  1671. LogWarn(Severity_High, Error_Unexpect, VtmLoader_GetConfig_InitCfgUrl_Failed, CSimpleStringA::Format("拉取配置,初始化配置地址失败:0x%x(%s)", eErr, SpStrError(eErr)).GetData());
  1672. DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_USER).setLogCode("QLR040210F13").setResultCode("RTA1F01")("Get config,InitCfgUrl failed.");
  1673. LogEvent(Severity_High, Event_VtmLoader_GetConfig_Fail, "拉取配置,初始化配置地址失败");
  1674. return false;
  1675. }
  1676. else
  1677. {
  1678. CSimpleString oldToken, newToken;
  1679. if (Error_Succeed != (eErr = GetEntityBase()->GetFunction()->GetPrivilegeFunction()->TryUpdateToken(oldToken, newToken)))
  1680. {
  1681. DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_USER).setLogCode("QLR040210F13").setResultCode("RTA1F02")("Get config, TryUpdateToken failed:0x%x", eErr);
  1682. LogWarn(Severity_High, Error_Unexpect, VtmLoader_GetConfig_UpdateToken_Failed, CSimpleStringA::Format("拉取配置失败:0x%x(%s)", eErr, SpStrError(eErr)).GetData());
  1683. }
  1684. //update err msg list
  1685. CloseHandle(CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)&errMsgListUpdate, this, 0, NULL));
  1686. //if token update failed,we can also update cfg suc
  1687. if (Error_Succeed != (eErr = GetEntityBase()->GetFunction()->GetPrivilegeFunction()->TryUpdateCfg()))
  1688. {
  1689. LogWarn(Severity_High, Error_Unexpect, VtmLoader_GetConfig_UpdateCfg_Failed, CSimpleStringA::Format("拉取配置失败:0x%x(%s)", eErr, SpStrError(eErr)).GetData());
  1690. DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_USER).setLogCode("QLR040210F13").setResultCode("RTA1F03")("Get config, TryUpdateCfg failed:0x%x", eErr);
  1691. LogEvent(Severity_High, Event_VtmLoader_GetConfig_Fail, "拉取配置失败");
  1692. return false;
  1693. }
  1694. }
  1695. refreshLogLevel();
  1696. //all cfg is ready, then init the entity, set centersetting update timer
  1697. void* pTmpData = NULL;
  1698. ITimerListener* pListener = new TimerOutHelper<CVtmLoaderFSM>(this, &CVtmLoaderFSM::OnCentersettingUpdateTimeout, pTmpData);
  1699. GetEntityBase()->GetFunction()->SetTimer(TIMER_CENTERSETTING_UPDATE_CHECK, pListener, CENTERSETTING_UPDATE_CHECK_TIME);
  1700. CSmartPointer<IConfigInfo> pConfig;
  1701. CSimpleString t_endpoint, t_topicSys, t_topicUser, t_topicBeidou, t_bussSys, t_bussUser, t_VTMWeb;
  1702. eErr = GetEntityBase()->GetFunction()->OpenConfig(Config_CenterSetting, pConfig);
  1703. if (eErr == Error_Succeed && Error_Succeed == pConfig->ReadConfigValue("Common", "SendEndpoint", t_endpoint)
  1704. && Error_Succeed == pConfig->ReadConfigValue("Common", "SendSys", t_topicSys)
  1705. && Error_Succeed == pConfig->ReadConfigValue("Common", "SendUser", t_topicUser)
  1706. && Error_Succeed == pConfig->ReadConfigValue("Common", "SendBeidou", t_topicBeidou)
  1707. && Error_Succeed == pConfig->ReadConfigValue("Common", "BusinessSys", t_bussSys)
  1708. && Error_Succeed == pConfig->ReadConfigValue("Common", "BusinessUser", t_bussUser)
  1709. && Error_Succeed == pConfig->ReadConfigValue("Common", "VTMWeb", t_VTMWeb)
  1710. && 0 != t_topicSys.GetLength()
  1711. && 0 != t_topicUser.GetLength()
  1712. && 0 != t_topicBeidou.GetLength()
  1713. && 0 != t_bussSys.GetLength()
  1714. && 0 != t_bussUser.GetLength()
  1715. && 0 != t_VTMWeb.GetLength())
  1716. {
  1717. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("endpoint:%s, topicSys:%s, topicUser:%s, topicBeidou:%s, bussSys:%s, bussUser:%s, vtmWeb:%s"
  1718. , t_endpoint.GetData(), t_topicSys.GetData(), t_topicUser.GetData(), t_topicBeidou.GetData(), t_bussSys.GetData(), t_bussUser.GetData(), t_VTMWeb.GetData());
  1719. if (0 != t_endpoint.GetLength())
  1720. {
  1721. GetEntityBase()->GetFunction()->GetPrivilegeFunction()->BeginLogSend(t_endpoint.GetData()
  1722. , t_topicSys.GetData(), t_topicUser.GetData(), t_topicBeidou.GetData(), t_bussSys.GetData(), t_bussUser.GetData(), t_VTMWeb.GetData());
  1723. }
  1724. else
  1725. LogWarn(Severity_High, ErrorCodeEnum::Error_Cancel, Event_VtmLoader_GetConfig_Suc, "endpoint is empty, do not begin send log");
  1726. }
  1727. else
  1728. {
  1729. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("read endpoint and topic err, need check centersetting, use default %s-%s-%s-%s-%s-%s-%s"
  1730. , SpDefine::endpoint, SpDefine::topicSys, SpDefine::topicUser, SpDefine::topicBeidou, SpDefine::topicBussSys, SpDefine::topicBussUser, SpDefine::topicVTMWeb);
  1731. GetEntityBase()->GetFunction()->GetPrivilegeFunction()->BeginLogSend(SpDefine::endpoint, SpDefine::topicSys, SpDefine::topicUser, SpDefine::topicBeidou,
  1732. SpDefine::topicBussSys, SpDefine::topicBussUser, SpDefine::topicVTMWeb);
  1733. }
  1734. GetEntityBase()->GetFunction()->GetSystemStaticInfo(m_sysInfo);
  1735. 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"
  1736. , m_sysInfo.strTerminalID.GetData(), m_sysInfo.strMachineModel.GetData(), m_sysInfo.strMachineType.GetData(), m_sysInfo.MachineVersion.ToString().GetData(),m_sysInfo.CurrDepVersion.GetData()
  1737. , m_sysInfo.strSite.GetData(), m_sysInfo.eScreen, m_sysInfo.EnrolGPS.GetLatitude(), m_sysInfo.EnrolGPS.GetLongitude(), m_sysInfo.strEnrolAddr.GetData());
  1738. int tmpSec = 0;
  1739. if (Error_Succeed == pConfig->ReadConfigValueInt(GetEntityBase()->GetEntityName(), "refreshTokenWaitSec", tmpSec) && tmpSec > 0)
  1740. m_refreshWaitSec = tmpSec;
  1741. int t_sec = 0;
  1742. pConfig->ReadConfigValueInt(GetEntityBase()->GetEntityName(), "UploadLogWaitSec", t_sec);
  1743. if (t_sec > 0)
  1744. m_uploadLogInfo_waitSec = t_sec;
  1745. CloseHandle(CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)& checkUrlActive, this, 0, NULL));
  1746. CloseHandle(CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)& tokenUpdate, this, 0, NULL));
  1747. //通知Chromium实体
  1748. LogEvent(Severity_High, Event_VtmLoader_GetConfig_Suc, "Get config succeed.");
  1749. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_USER).setLogCode("QLR040210F13")("Get config succeed.");
  1750. return true;
  1751. }
  1752. int CVtmLoaderFSM::HttpConnCheck(CSimpleStringA csHttAddr, HttpAddrType eType)
  1753. {
  1754. DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("to HttpConnCheck");
  1755. ULLINT beginTick = SP::Module::Comm::RVCGetTickCount();
  1756. int httpcheckCount = 1;
  1757. bool bCheckOK = false;
  1758. while(true){
  1759. if (m_httpCheckResult[HttpAddr_CenterSetting] == HttpConnResult_OK)
  1760. {
  1761. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("check centersetting ok.");
  1762. return 0;
  1763. }
  1764. else if (m_httpCheckResult[HttpAddr_AccessAuth] == HttpConnResult_OK)
  1765. {
  1766. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("check AccessAuth ok.");
  1767. return 0;
  1768. }
  1769. #if defined(RVC_OS_LINUX)
  1770. string msg;
  1771. int curFlag = HttpProbe(csHttAddr.GetData(), msg, 5);
  1772. if (curFlag > 0 && curFlag < 400)
  1773. bCheckOK = true;
  1774. #else
  1775. bCheckOK = checkHttpActive(csHttAddr.GetData());
  1776. #endif
  1777. if (!bCheckOK)
  1778. {
  1779. LogWarn(Severity_High, Error_Unexpect, VtmLoader_ConnectDetect_Failed, CSimpleStringA::Format("尝试连接总行服务失败(%s),%d 秒后自动重试(第%d次重试)。请确认终端到总行服务网络是否正常", csHttAddr.GetData(), m_iDetectInterval/1000, httpcheckCount).GetData());
  1780. if (httpcheckCount == 1)//oilyang@20250415 only the first time we log RTAxxxx
  1781. DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_USER).setLogCode("QLR040210F11").setResultCode("RTA1F06")("connect to http(s) service(%s) failed.", csHttAddr.GetData());
  1782. m_httpCheckResult[eType] = HttpConnResult_Failed;
  1783. Sleep(m_iDetectInterval);
  1784. httpcheckCount++;
  1785. CAutoArray<NetworkAdapterItem> netList;
  1786. if (SP::Module::Net::GetINETMacAddresses(netList) == Error_Succeed)
  1787. {
  1788. CSimpleStringA tmpDns = GetDns();
  1789. for (int i = 0; i < netList.GetCount(); i++) {
  1790. LogWarn(Severity_Low, Error_Unexpect, VtmLoader_BootInfoPrint, CSimpleStringA::Format("(%d)interface:%s; ip:%s; mac:%s; %s", i, netList[i].description.c_str()
  1791. , netList[i].ip.c_str(), netList[i].mac.c_str(), tmpDns.GetData()).GetData());
  1792. }
  1793. }
  1794. }
  1795. else
  1796. {
  1797. m_httpCheckResult[eType] = HttpConnResult_OK;
  1798. if ((SP::Module::Comm::RVCGetTickCount() - beginTick) > 3000)
  1799. {
  1800. LogWarn(Severity_Middle, Error_Unexpect, VtmLoader_ConnectDetect_Slow, CSimpleStringA::Format("第(%d)次尝试连接总行服务成功(%s),但是网络偏慢,连接花了(%d)秒,请检查网络!"
  1801. , httpcheckCount, csHttAddr.GetData(), (SP::Module::Comm::RVCGetTickCount() - beginTick)/1000).GetData());
  1802. DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_USER).setResultCode("RTA1F07")("尝试连接总行服务成功,但是网络偏慢");
  1803. }
  1804. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_USER).setLogCode("QLR040210F11")("尝试连接总行服务成功(%s)", csHttAddr.GetData());
  1805. return 0;
  1806. }
  1807. }
  1808. return -1;
  1809. }
  1810. CSimpleStringA CVtmLoaderFSM::GetDns()
  1811. {
  1812. CSimpleStringA runInfoPath, csDNSKeyword, csTmpDns("");
  1813. ErrorCodeEnum eErr = GetEntityBase()->GetFunction()->GetPath("runinfo", runInfoPath);
  1814. if (eErr != Error_Succeed) {
  1815. DbgWithLink(LOG_LEVEL_ERROR, LOG_TYPE_SYSTEM)("GetPath runinfo error=%d.", eErr);
  1816. return "";
  1817. }
  1818. runInfoPath = runInfoPath + SPLIT_SLASH_STR + "runcfg" + SPLIT_SLASH_STR + "dns";
  1819. #if defined(RVC_OS_WIN)
  1820. CSimpleStringA csCmd;
  1821. csCmd = CSimpleStringA::Format("cmd /c ipconfig /all >%s", runInfoPath.GetData());
  1822. WinExec((LPCSTR)csCmd, SW_HIDE);
  1823. csDNSKeyword = "DNS 服务器";
  1824. #else
  1825. std::string sucContent, failedContent;
  1826. CSimpleStringA strCmd;
  1827. strCmd = CSimpleStringA::Format("cat /etc/resolv.conf | grep \"nameserver\" >%s", runInfoPath.GetData());
  1828. bool ret = SP::Module::Util::ShellExecute(strCmd.GetData(), sucContent, failedContent);
  1829. csDNSKeyword = "nameserver";
  1830. #endif //RVC_OS_WIN
  1831. ifstream is;
  1832. is.open(runInfoPath.GetData(), ios::binary);
  1833. if (!is.is_open())
  1834. {
  1835. DWORD dwErr = GetLastError();
  1836. DbgWithLink(LOG_LEVEL_ERROR, LOG_TYPE_SYSTEM)("open %s file failed. [%d]", runInfoPath.GetData(), dwErr);
  1837. return "";
  1838. }
  1839. string line;
  1840. while (!is.eof()) {
  1841. getline(is, line);
  1842. //DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("line:%s", line.c_str());
  1843. size_t start = line.find(csDNSKeyword.GetData());
  1844. if (start != string::npos)
  1845. {
  1846. #if defined(RVC_OS_WIN)
  1847. int dnsStart = line.find(": ");
  1848. if (dnsStart != string::npos)
  1849. {
  1850. string xDns = SP::Utility::ToTrim(line.substr(dnsStart + 1, line.length() - dnsStart - 1));
  1851. csTmpDns += xDns.c_str();
  1852. csTmpDns += ";";
  1853. }
  1854. #else
  1855. string xDns = SP::Utility::ToTrim(line.substr(start + csDNSKeyword.GetLength() + 1, line.length() - start - csDNSKeyword.GetLength() - 1));
  1856. csTmpDns += xDns.c_str();
  1857. csTmpDns += ";";
  1858. #endif
  1859. }
  1860. else
  1861. continue;
  1862. }
  1863. return csTmpDns;
  1864. }
  1865. void CVtmLoaderFSM::ToCheckIfInstalling()
  1866. {
  1867. //拉取配置前先检查root.ini文件
  1868. CSimpleStringA csTmpRootIni("");
  1869. if (!IsRootINIExist(csTmpRootIni))
  1870. {
  1871. 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());
  1872. //oiltest
  1873. //OilTestTask* task = new OilTestTask(this);
  1874. //GetEntityBase()->GetFunction()->PostThreadPoolTask(task);
  1875. while (true)
  1876. {
  1877. m_hWaitTerminalNoVar.Wait();
  1878. break;
  1879. }
  1880. }
  1881. }
  1882. void CVtmLoaderFSM::CheckDeviceEntity(SpReqAnsContext<VtmLoaderService_CheckDeviceEntity_Req, VtmLoaderService_CheckDeviceEntity_Ans>::Pointer ctx)
  1883. {
  1884. if (ctx->Req.entityName.IsNullOrEmpty())
  1885. {
  1886. DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM)("ctx->Req.entityName is null or empty.");
  1887. ctx->Answer(Error_Param, VtmLoader_FailToStartEntity);
  1888. return;
  1889. }
  1890. if (!RefreshDeviceConfig(ctx))
  1891. {
  1892. DbgWithLink(LOG_LEVEL_ERROR, LOG_TYPE_SYSTEM)("RefreshDeviceConfig failed.");
  1893. ctx->Answer(Error_Unexpect);
  1894. }
  1895. CEntityStaticInfo staticInfo;
  1896. ErrorCodeEnum eErrCode = Error_Unexpect;
  1897. CSimpleStringA csEntityName = ctx->Req.entityName;
  1898. if ((eErrCode = m_pEntity->GetFunction()->GetEntityStaticInfo(csEntityName.GetData(), staticInfo)) != Error_Succeed)
  1899. {
  1900. DbgWithLink(LOG_LEVEL_ERROR, LOG_TYPE_SYSTEM)("GetEntityStaticInfo(%s), failed:%d", ctx->Req.entityName.GetData(), eErrCode);
  1901. ctx->Answer(Error_Unexpect, VtmLoader_FailToGetEntityInfo);
  1902. return;
  1903. }
  1904. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("staticInfo.wEntityDevelopID:%x", staticInfo.wEntityDevelopID);
  1905. switch (staticInfo.wEntityDevelopID)
  1906. {
  1907. case 0x201:
  1908. case 0x203:
  1909. case 0x204:
  1910. case 0x206:
  1911. case 0x209:
  1912. case 0x213:
  1913. case 0x217:
  1914. case 0x220:
  1915. CheckDeviceBaseEntity(ctx, staticInfo.wEntityDevelopID);
  1916. break;
  1917. case 0x301://SIPPhone
  1918. CheckAudio(ctx);
  1919. break;
  1920. case 0x208://MediaController
  1921. CheckVideo(ctx);
  1922. break;
  1923. default:
  1924. break;
  1925. }
  1926. return;
  1927. }
  1928. void CVtmLoaderFSM::SaveTerminalNo(SpReqAnsContext<VtmLoaderService_SaveTerminalNo_Req, VtmLoaderService_SaveTerminalNo_Ans>::Pointer ctx)
  1929. {
  1930. if (ctx->Req.terminalNo.IsNullOrEmpty())
  1931. {
  1932. DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM)("terminalNo is null or empty");
  1933. ctx->Answer(Error_Param);
  1934. return;
  1935. }
  1936. LogWarn(Severity_Low, Error_Trace, VtmLoader_SaveTerminalNo, CSimpleStringA::Format("SaveTerminalNo:[%s]", ctx->Req.terminalNo.GetData()));
  1937. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_USER).setLogCode(VtmLoaderService_LogCode_SaveTerminalNo)("write terminalNo[%s] to root.ini", ctx->Req.terminalNo.GetData());
  1938. ErrorCodeEnum eErr = GetEntityBase()->GetFunction()->GetPrivilegeFunction()->WriteTerminalNoToRootIni(ctx->Req.terminalNo);
  1939. ctx->Answer(eErr);
  1940. }
  1941. void CVtmLoaderFSM::DealWithOldEvent(SpReqAnsContext<VtmLoaderService_DealWithOldEvent_Req, VtmLoaderService_DealWithOldEvent_Ans>::Pointer ctx)
  1942. {
  1943. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("DealWithOldEvent called, %d, %s, %s, %d, %d",
  1944. ctx->Req.eventId, ctx->Req.reqStrRev1.GetData(), ctx->Req.reqStrRev2.GetData(), ctx->Req.reqIntRev1, ctx->Req.reqIntRev2);
  1945. ErrorCodeEnum eErr = ErrorCodeEnum::Error_Succeed;
  1946. switch (ctx->Req.eventId)
  1947. {
  1948. case EVENT_CONSOLE_REQ_SHUTDOWN_SHELL:
  1949. LogWarn(Severity_Low, Error_Unexpect, 0x50100215, CSimpleStringA::Format("%x, reason:%s", EVENT_CONSOLE_REQ_SHUTDOWN_SHELL, ctx->Req.reqStrRev1.GetData()));
  1950. if (RebootWayEnum::RebootWay_OS == ctx->Req.reqIntRev1)
  1951. {
  1952. GetEntityBase()->GetFunction()->GetPrivilegeFunction()->Reboot(RebootTriggerEnum::RebootTrigger_Unknown, RebootWayEnum::RebootWay_OS);
  1953. return;
  1954. }
  1955. #if defined(RVC_OS_WIN)
  1956. do
  1957. {
  1958. STARTUPINFO si;
  1959. PROCESS_INFORMATION pi;
  1960. ZeroMemory(&si, sizeof(si));
  1961. si.cb = sizeof(si);
  1962. ZeroMemory(&pi, sizeof(pi));
  1963. GetEntityBase()->GetFunction()->FlushLogFile();
  1964. CSimpleStringA csRestart, csVerPath, csAll, csSep("\""), csBlank(" "), csScript("wscript.exe"), csReFlag("r");
  1965. csRestart = "sprestart.exe ";
  1966. ErrorCodeEnum Error = GetEntityBase()->GetFunction()->GetPath("RootVer", csVerPath);
  1967. //csVerPath +="\\spexplorerfast.vbs";
  1968. csVerPath += "\\VTM.exe";
  1969. csReFlag = "n";
  1970. csAll = csSep + csRestart + csSep + csBlank + csSep + csVerPath + csSep
  1971. + csBlank + csSep + csReFlag + csSep;
  1972. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("allpath[%s]", (LPCTSTR)csAll);
  1973. LPTSTR szCmdline = _strdup(csAll);
  1974. if (!CreateProcess(NULL, szCmdline, NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi))
  1975. {
  1976. DbgWithLink(LOG_LEVEL_ERROR, LOG_TYPE_SYSTEM)("framework shutdown from console failed, CreateProcess failed (%d).\n", GetLastError());
  1977. eErr = ErrorCodeEnum::Error_Unexpect;
  1978. break;
  1979. }
  1980. DWORD dwErr = GetLastError();
  1981. // Wait until child process exits.
  1982. WaitForSingleObject(pi.hProcess, INFINITE);
  1983. // Close process and thread handles.
  1984. CloseHandle(pi.hProcess);
  1985. CloseHandle(pi.hThread);
  1986. } while (false);
  1987. #endif
  1988. break;
  1989. case LOG_EVT_IEBROWSER_RESET_SITE_RESTART:
  1990. GetEntityBase()->GetFunction()->GetPrivilegeFunction()->Reboot(RebootTriggerEnum::RebootTrigger_Unknown, RebootWayEnum::RebootWay_Framework);
  1991. break;
  1992. default:
  1993. break;
  1994. }
  1995. ctx->Answer(eErr);
  1996. }
  1997. bool CVtmLoaderFSM::RefreshDeviceConfig(SpReqAnsContext<VtmLoaderService_CheckDeviceEntity_Req, VtmLoaderService_CheckDeviceEntity_Ans>::Pointer ctx)
  1998. {
  1999. if (ctx->Req.entityName.IsNullOrEmpty() || ctx->Req.paramNum <= 0)
  2000. {
  2001. DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_USER)("param error! nothing to refresh");
  2002. return false;
  2003. }
  2004. 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());
  2005. if (ctx->Req.module.GetCount() < ctx->Req.paramNum || ctx->Req.name.GetCount() < ctx->Req.paramNum || ctx->Req.value.GetCount() < ctx->Req.paramNum)
  2006. {
  2007. DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_USER)("param array length error! nothing to refresh");
  2008. return false;
  2009. }
  2010. for (int i = 0; i < ctx->Req.paramNum; i++)
  2011. {
  2012. MemCfgParam tmpParam("root", ctx->Req.module[i].GetData(), ctx->Req.name[i].GetData(), ctx->Req.value[i].GetData());
  2013. 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());
  2014. GetEntityBase()->GetFunction()->GetPrivilegeFunction()->ModifyMemCfgParam(tmpParam);
  2015. }
  2016. return true;
  2017. }
  2018. void CVtmLoaderFSM::CheckDeviceBaseEntity(SpReqAnsContext<VtmLoaderService_CheckDeviceEntity_Req, VtmLoaderService_CheckDeviceEntity_Ans>::Pointer ctx, WORD wEntityID)
  2019. {
  2020. CSmartPointer<IEntityFunctionPrivilege> pFuncPrivilege = m_pEntity->GetFunction().ConvertCase<IEntityFunctionPrivilege>();
  2021. CSmartPointer<IAsynWaitSp> spWait;
  2022. CEntityRunInfo runInfo;
  2023. CSimpleStringA csEntityName = ctx->Req.entityName;
  2024. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("csEntityName:[%s]", csEntityName.GetData());
  2025. //to check entity state
  2026. ErrorCodeEnum eErrCode = m_pEntity->GetFunction()->GetEntityRunInfo(csEntityName.GetData(), runInfo);
  2027. if (eErrCode == Error_Succeed)
  2028. {
  2029. if (runInfo.eState != EntityState_NoStart)
  2030. {
  2031. eErrCode = pFuncPrivilege->TerminateEntity(csEntityName.GetData(), spWait);
  2032. if (spWait != NULL)
  2033. eErrCode = spWait->WaitAnswer(MAX_AYSNC_TIMEOUT);
  2034. }
  2035. }
  2036. else
  2037. {
  2038. DbgWithLink(LOG_LEVEL_ERROR, LOG_TYPE_SYSTEM).setLogCode(VtmLoaderService_LogCode_CheckDeviceEntity).setResultCode("RTA1F24")
  2039. ("GetEntityRunInfo %s failed(%d).", csEntityName.GetData(), eErrCode);
  2040. ctx->Answer(Error_Unexpect, VtmLoader_FailToGetEntityInfo);
  2041. return;
  2042. }
  2043. //(re)start entity
  2044. eErrCode = pFuncPrivilege->StartEntity(csEntityName.GetData(), NULL, spWait);
  2045. if (eErrCode == Error_Succeed)
  2046. {
  2047. if (spWait != NULL)
  2048. eErrCode = spWait->WaitAnswer(MAX_AYSNC_TIMEOUT);
  2049. }
  2050. else
  2051. {
  2052. DbgWithLink(LOG_LEVEL_ERROR, LOG_TYPE_SYSTEM).setLogCode(VtmLoaderService_LogCode_CheckDeviceEntity).setResultCode("RTA1F21")
  2053. ("StartEntity %s failed(%d).", csEntityName.GetData(), eErrCode);
  2054. ctx->Answer(Error_Unexpect, VtmLoader_FailToStartEntity);
  2055. return;
  2056. }
  2057. //TODO we should wait for device entity open suc?
  2058. //Sleep 2 second for simple
  2059. Sleep(2000);
  2060. int count = 0;
  2061. do
  2062. {
  2063. CEntityRunInfo runInfo;
  2064. eErrCode = m_pEntity->GetFunction()->GetEntityRunInfo(csEntityName.GetData(), runInfo);
  2065. if (eErrCode == Error_Succeed)
  2066. {
  2067. if (runInfo.eState == EntityState_Idle)
  2068. break;
  2069. else if (runInfo.eState == EntityState_Lost || runInfo.eState == EntityState_Close || runInfo.eState == EntityState_Killed)
  2070. {
  2071. DbgWithLink(LOG_LEVEL_ERROR, LOG_TYPE_SYSTEM).setLogCode(VtmLoaderService_LogCode_CheckDeviceEntity).setResultCode("RTA1F21")
  2072. ("entity state:%d", runInfo.eState);
  2073. ctx->Answer(Error_Unexpect, VtmLoader_FailToStartEntity);
  2074. return;
  2075. }
  2076. count++;
  2077. if (count > 3)
  2078. {
  2079. DbgWithLink(LOG_LEVEL_ERROR, LOG_TYPE_SYSTEM).setLogCode(VtmLoaderService_LogCode_CheckDeviceEntity).setResultCode("RTA1F21")
  2080. ("entity state:%d", runInfo.eState);
  2081. ctx->Answer(Error_Unexpect, VtmLoader_FailToStartEntity);
  2082. return;
  2083. }
  2084. Sleep(1000);
  2085. }
  2086. else
  2087. {
  2088. DbgWithLink(LOG_LEVEL_ERROR, LOG_TYPE_SYSTEM).setLogCode(VtmLoaderService_LogCode_CheckDeviceEntity).setResultCode("RTA1F21")
  2089. ("GetEntityRunInfo failed:%d", eErrCode);
  2090. ctx->Answer(Error_Unexpect, VtmLoader_FailToStartEntity);
  2091. return;
  2092. }
  2093. } while (true);
  2094. const int retryGetDevInfoInterval = 5000;//5 seconds
  2095. const int maxRetryTimes = 16;//16*5 = 80 seconds ,the web timeout setting is 90s
  2096. CClientSessionBase* pClient;
  2097. int entityState = 0;
  2098. switch (wEntityID)
  2099. {
  2100. case 0x206: //pinpad
  2101. {
  2102. PinPadService_ClientBase* pClient = new PinPadService_ClientBase(this->m_pEntity);
  2103. if (pClient != NULL)
  2104. {
  2105. eErrCode = pClient->Connect();
  2106. if (eErrCode == Error_Succeed)
  2107. {
  2108. int retryTimes = maxRetryTimes;
  2109. do {
  2110. PinPadService_GetDevInfo_Req reqQ;
  2111. PinPadService_GetDevInfo_Ans ansQ;
  2112. eErrCode = (*pClient)(EntityResource::getLink().upgradeLink())->GetDevInfo(reqQ, ansQ, 5000);
  2113. DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("eErrCode:%d,ansQ.state:%d", eErrCode, ansQ.state);
  2114. if (eErrCode == Error_DevNotAvailable)
  2115. {
  2116. DbgWithLink(LOG_LEVEL_ERROR, LOG_TYPE_SYSTEM).setLogCode(VtmLoaderService_LogCode_CheckDeviceEntity).setResultCode("RTA1F23")("%d", eErrCode);
  2117. ctx->Answer(Error_Unexpect, VtmLoader_EntityNotInNormal);
  2118. return;
  2119. }
  2120. else if (eErrCode == Error_Succeed)
  2121. {
  2122. DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("return to caller");
  2123. ctx->Answer(Error_Succeed);
  2124. return;
  2125. }
  2126. Sleep(retryGetDevInfoInterval);
  2127. retryTimes--;
  2128. } while (retryTimes > 0);
  2129. if (retryTimes == 0)
  2130. {
  2131. DbgWithLink(LOG_LEVEL_ERROR, LOG_TYPE_SYSTEM).setLogCode(VtmLoaderService_LogCode_CheckDeviceEntity).setResultCode("RTA1F23")
  2132. ("after have tried x times");
  2133. ctx->Answer(Error_Unexpect, VtmLoader_EntityNotInNormal);
  2134. }
  2135. }
  2136. else {
  2137. DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM).setLogCode(VtmLoaderService_LogCode_CheckDeviceEntity).setResultCode("RTA1F22")
  2138. ("connect to %s failed.error code:%d", csEntityName.GetData(), eErrCode);
  2139. ctx->Answer(Error_Unexpect, VtmLoader_FailToConnectEntity);
  2140. }
  2141. }
  2142. else
  2143. {
  2144. DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM).setLogCode(VtmLoaderService_LogCode_CheckDeviceEntity).setResultCode("RTA1F22")
  2145. ("new client failed.");
  2146. ctx->Answer(Error_Unexpect, VtmLoader_FailToConnectEntity);
  2147. }
  2148. }
  2149. break;
  2150. case 0x201: //IDCertificate
  2151. {
  2152. IDCertService_ClientBase* pClient = new IDCertService_ClientBase(this->m_pEntity);
  2153. if (pClient != NULL)
  2154. {
  2155. eErrCode = pClient->Connect();
  2156. if (eErrCode == Error_Succeed)
  2157. {
  2158. int retryTimes = maxRetryTimes;
  2159. do {
  2160. IDCertService_GetDevInfo_Req reqQ;
  2161. IDCertService_GetDevInfo_Ans ansQ;
  2162. eErrCode = (*pClient)(EntityResource::getLink().upgradeLink())->GetDevInfo(reqQ, ansQ, 5000);
  2163. DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("eErrCode:%d,ansQ.state:%d", eErrCode, ansQ.state);
  2164. if (eErrCode == Error_DevNotAvailable)
  2165. {
  2166. DbgWithLink(LOG_LEVEL_ERROR, LOG_TYPE_SYSTEM).setLogCode(VtmLoaderService_LogCode_CheckDeviceEntity).setResultCode("RTA1F23")("%d", eErrCode);
  2167. ctx->Answer(Error_Unexpect, VtmLoader_EntityNotInNormal);
  2168. return;
  2169. }
  2170. else if (eErrCode == Error_Succeed)
  2171. {
  2172. DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("return to caller");
  2173. ctx->Answer(Error_Succeed);
  2174. return;
  2175. }
  2176. Sleep(retryGetDevInfoInterval);
  2177. retryTimes--;
  2178. } while (retryTimes > 0);
  2179. if (retryTimes == 0)
  2180. {
  2181. DbgWithLink(LOG_LEVEL_ERROR, LOG_TYPE_SYSTEM).setLogCode(VtmLoaderService_LogCode_CheckDeviceEntity).setResultCode("RTA1F23")
  2182. ("after have tried x times");
  2183. ctx->Answer(Error_Unexpect, VtmLoader_EntityNotInNormal);
  2184. }
  2185. }
  2186. else {
  2187. DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM).setLogCode(VtmLoaderService_LogCode_CheckDeviceEntity).setResultCode("RTA1F22")
  2188. ("connect to %s failed.error code:%d", csEntityName.GetData(), eErrCode);
  2189. ctx->Answer(Error_Unexpect, VtmLoader_FailToConnectEntity);
  2190. }
  2191. }
  2192. else
  2193. {
  2194. DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM).setLogCode(VtmLoaderService_LogCode_CheckDeviceEntity).setResultCode("RTA1F22")
  2195. ("new client failed.");
  2196. ctx->Answer(Error_Unexpect, VtmLoader_FailToConnectEntity);
  2197. }
  2198. }
  2199. break;
  2200. case 0x204: //FingerPrint
  2201. {
  2202. FingerPrintService_ClientBase* pClient = new FingerPrintService_ClientBase(this->m_pEntity);
  2203. if (pClient != NULL)
  2204. {
  2205. eErrCode = pClient->Connect();
  2206. if (eErrCode == Error_Succeed)
  2207. {
  2208. int retryTimes = maxRetryTimes;
  2209. do {
  2210. FingerPrintService_GetDevInfo_Req reqQ;
  2211. FingerPrintService_GetDevInfo_Ans ansQ;
  2212. eErrCode = (*pClient)(EntityResource::getLink().upgradeLink())->GetDevInfo(reqQ, ansQ, 5000);
  2213. DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("eErrCode:%d,ansQ.state:%d", eErrCode, ansQ.state);
  2214. if (eErrCode == Error_DevNotAvailable)
  2215. {
  2216. DbgWithLink(LOG_LEVEL_ERROR, LOG_TYPE_SYSTEM).setLogCode(VtmLoaderService_LogCode_CheckDeviceEntity).setResultCode("RTA1F23")("%d", eErrCode);
  2217. ctx->Answer(Error_Unexpect, VtmLoader_EntityNotInNormal);
  2218. return;
  2219. }
  2220. else if (eErrCode == Error_Succeed)
  2221. {
  2222. DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("return to caller");
  2223. ctx->Answer(Error_Succeed);
  2224. return;
  2225. }
  2226. Sleep(retryGetDevInfoInterval);
  2227. retryTimes--;
  2228. } while (retryTimes > 0);
  2229. if (retryTimes == 0)
  2230. {
  2231. DbgWithLink(LOG_LEVEL_ERROR, LOG_TYPE_SYSTEM).setLogCode(VtmLoaderService_LogCode_CheckDeviceEntity).setResultCode("RTA1F23")
  2232. ("after have tried x times");
  2233. ctx->Answer(Error_Unexpect, VtmLoader_EntityNotInNormal);
  2234. }
  2235. }
  2236. else {
  2237. DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM).setLogCode(VtmLoaderService_LogCode_CheckDeviceEntity).setResultCode("RTA1F22")
  2238. ("connect to %s failed.error code:%d", csEntityName.GetData(), eErrCode);
  2239. ctx->Answer(Error_Unexpect, VtmLoader_FailToConnectEntity);
  2240. }
  2241. }
  2242. else
  2243. {
  2244. DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM).setLogCode(VtmLoaderService_LogCode_CheckDeviceEntity).setResultCode("RTA1F22")
  2245. ("new client failed.");
  2246. ctx->Answer(Error_Unexpect, VtmLoader_FailToConnectEntity);
  2247. }
  2248. }
  2249. break;
  2250. case 0x203: //CardIssuerStand
  2251. case 0x220: //CardIssuerStore
  2252. {
  2253. if (m_sysInfo.strMachineType.Compare("RVC.CardStore") == 0 || m_sysInfo.strMachineType.Compare("RVC.CardPrinter") == 0)
  2254. {
  2255. CardIssuerStoreService_ClientBase* pClient = new CardIssuerStoreService_ClientBase(this->m_pEntity);
  2256. if (pClient != NULL)
  2257. {
  2258. eErrCode = pClient->Connect();
  2259. if (eErrCode == Error_Succeed)
  2260. {
  2261. int retryTimes = maxRetryTimes;
  2262. do {
  2263. CardIssuerStoreService_GetDevInfo_Req reqQ;
  2264. CardIssuerStoreService_GetDevInfo_Ans ansQ;
  2265. eErrCode = (*pClient)(EntityResource::getLink().upgradeLink())->GetDevInfo(reqQ, ansQ, 5000);
  2266. DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("eErrCode:%d,ansQ.state:%d", eErrCode, ansQ.state);
  2267. if (eErrCode == Error_DevNotAvailable)
  2268. {
  2269. DbgWithLink(LOG_LEVEL_ERROR, LOG_TYPE_SYSTEM).setLogCode(VtmLoaderService_LogCode_CheckDeviceEntity).setResultCode("RTA1F23")("%d", eErrCode);
  2270. ctx->Answer(Error_Unexpect, VtmLoader_EntityNotInNormal);
  2271. return;
  2272. }
  2273. else if (eErrCode == Error_Succeed)
  2274. {
  2275. DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("return to caller");
  2276. ctx->Answer(Error_Succeed);
  2277. return;
  2278. }
  2279. Sleep(retryGetDevInfoInterval);
  2280. retryTimes--;
  2281. } while (retryTimes > 0);
  2282. if (retryTimes == 0)
  2283. {
  2284. DbgWithLink(LOG_LEVEL_ERROR, LOG_TYPE_SYSTEM).setLogCode(VtmLoaderService_LogCode_CheckDeviceEntity).setResultCode("RTA1F23")
  2285. ("after have tried x times");
  2286. ctx->Answer(Error_Unexpect, VtmLoader_EntityNotInNormal);
  2287. }
  2288. }
  2289. else {
  2290. DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM).setLogCode(VtmLoaderService_LogCode_CheckDeviceEntity).setResultCode("RTA1F22")
  2291. ("connect to %s failed.error code:%d", csEntityName.GetData(), eErrCode);
  2292. ctx->Answer(Error_Unexpect, VtmLoader_FailToConnectEntity);
  2293. }
  2294. }
  2295. else
  2296. {
  2297. DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM).setLogCode(VtmLoaderService_LogCode_CheckDeviceEntity).setResultCode("RTA1F22")
  2298. ("new client failed.");
  2299. ctx->Answer(Error_Unexpect, VtmLoader_FailToConnectEntity);
  2300. }
  2301. }
  2302. else
  2303. {
  2304. CardIssuerStandService_ClientBase* pClient = new CardIssuerStandService_ClientBase(this->m_pEntity);
  2305. if (pClient != NULL)
  2306. {
  2307. eErrCode = pClient->Connect();
  2308. if (eErrCode == Error_Succeed)
  2309. {
  2310. int retryTimes = maxRetryTimes;
  2311. do {
  2312. CardIssuerStandService_GetDevInfo_Req reqQ;
  2313. CardIssuerStandService_GetDevInfo_Ans ansQ;
  2314. eErrCode = (*pClient)(EntityResource::getLink().upgradeLink())->GetDevInfo(reqQ, ansQ, 5000);
  2315. DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("eErrCode:%d,ansQ.state:%d", eErrCode, ansQ.state);
  2316. if (eErrCode == Error_DevNotAvailable)
  2317. {
  2318. DbgWithLink(LOG_LEVEL_ERROR, LOG_TYPE_SYSTEM).setLogCode(VtmLoaderService_LogCode_CheckDeviceEntity).setResultCode("RTA1F23")("%d", eErrCode);
  2319. ctx->Answer(Error_Unexpect, VtmLoader_EntityNotInNormal);
  2320. return;
  2321. }
  2322. else if (eErrCode == Error_Succeed)
  2323. {
  2324. DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("return to caller");
  2325. ctx->Answer(Error_Succeed);
  2326. return;
  2327. }
  2328. Sleep(retryGetDevInfoInterval);
  2329. retryTimes--;
  2330. } while (retryTimes > 0);
  2331. if (retryTimes == 0)
  2332. {
  2333. DbgWithLink(LOG_LEVEL_ERROR, LOG_TYPE_SYSTEM).setLogCode(VtmLoaderService_LogCode_CheckDeviceEntity).setResultCode("RTA1F23")
  2334. ("after have tried x times");
  2335. ctx->Answer(Error_Unexpect, VtmLoader_EntityNotInNormal);
  2336. }
  2337. }
  2338. else {
  2339. DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM).setLogCode(VtmLoaderService_LogCode_CheckDeviceEntity).setResultCode("RTA1F22")
  2340. ("connect to %s failed.error code:%d", csEntityName.GetData(), eErrCode);
  2341. ctx->Answer(Error_Unexpect, VtmLoader_FailToConnectEntity);
  2342. }
  2343. }
  2344. else
  2345. {
  2346. DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM).setLogCode(VtmLoaderService_LogCode_CheckDeviceEntity).setResultCode("RTA1F22")
  2347. ("new client failed.");
  2348. ctx->Answer(Error_Unexpect, VtmLoader_FailToConnectEntity);
  2349. }
  2350. }
  2351. }
  2352. break;
  2353. case 0x209: //gpio
  2354. {
  2355. GpioService_ClientBase* pClient = new GpioService_ClientBase(this->m_pEntity);
  2356. if (pClient != NULL)
  2357. {
  2358. eErrCode = pClient->Connect();
  2359. if (eErrCode == Error_Succeed)
  2360. {
  2361. int retryTimes = maxRetryTimes;
  2362. do {
  2363. GpioService_GetDevInfo_Req reqQ;
  2364. GpioService_GetDevInfo_Ans ansQ;
  2365. eErrCode = (*pClient)(EntityResource::getLink().upgradeLink())->GetDevInfo(reqQ, ansQ, 5000);
  2366. DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("eErrCode:%d,ansQ.state:%d", eErrCode, ansQ.state);
  2367. if (eErrCode == Error_DevNotAvailable)
  2368. {
  2369. DbgWithLink(LOG_LEVEL_ERROR, LOG_TYPE_SYSTEM).setLogCode(VtmLoaderService_LogCode_CheckDeviceEntity).setResultCode("RTA1F23")("%d", eErrCode);
  2370. ctx->Answer(Error_Unexpect, VtmLoader_EntityNotInNormal);
  2371. return;
  2372. }
  2373. else if (eErrCode == Error_Succeed)
  2374. {
  2375. DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("return to caller");
  2376. ctx->Answer(Error_Succeed);
  2377. return;
  2378. }
  2379. Sleep(retryGetDevInfoInterval);
  2380. retryTimes--;
  2381. } while (retryTimes > 0);
  2382. if (retryTimes == 0)
  2383. {
  2384. DbgWithLink(LOG_LEVEL_ERROR, LOG_TYPE_SYSTEM).setLogCode(VtmLoaderService_LogCode_CheckDeviceEntity).setResultCode("RTA1F23")
  2385. ("after have tried x times");
  2386. ctx->Answer(Error_Unexpect, VtmLoader_EntityNotInNormal);
  2387. }
  2388. }
  2389. else {
  2390. DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM).setLogCode(VtmLoaderService_LogCode_CheckDeviceEntity).setResultCode("RTA1F22")
  2391. ("connect to %s failed.error code:%d", csEntityName.GetData(), eErrCode);
  2392. ctx->Answer(Error_Unexpect, VtmLoader_FailToConnectEntity);
  2393. }
  2394. }
  2395. else
  2396. {
  2397. DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM).setLogCode(VtmLoaderService_LogCode_CheckDeviceEntity).setResultCode("RTA1F22")
  2398. ("new client failed.");
  2399. ctx->Answer(Error_Unexpect, VtmLoader_FailToConnectEntity);
  2400. }
  2401. }
  2402. break;
  2403. case 0x213: //ContactlessCard
  2404. {
  2405. ContactlessCardService_ClientBase* pClient = new ContactlessCardService_ClientBase(this->m_pEntity);
  2406. if (pClient != NULL)
  2407. {
  2408. eErrCode = pClient->Connect();
  2409. if (eErrCode == Error_Succeed)
  2410. {
  2411. int retryTimes = maxRetryTimes;
  2412. do {
  2413. ContactlessCardService_GetDevInfo_Req reqQ;
  2414. ContactlessCardService_GetDevInfo_Ans ansQ;
  2415. eErrCode = (*pClient)(EntityResource::getLink().upgradeLink())->GetDevInfo(reqQ, ansQ, 5000);
  2416. DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("eErrCode:%d,ansQ.state:%d", eErrCode, ansQ.state);
  2417. if (eErrCode == Error_DevNotAvailable)
  2418. {
  2419. DbgWithLink(LOG_LEVEL_ERROR, LOG_TYPE_SYSTEM).setLogCode(VtmLoaderService_LogCode_CheckDeviceEntity).setResultCode("RTA1F23")("%d", eErrCode);
  2420. ctx->Answer(Error_Unexpect, VtmLoader_EntityNotInNormal);
  2421. return;
  2422. }
  2423. else if (eErrCode == Error_Succeed)
  2424. {
  2425. DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("return to caller");
  2426. ctx->Answer(Error_Succeed);
  2427. return;
  2428. }
  2429. Sleep(retryGetDevInfoInterval);
  2430. retryTimes--;
  2431. } while (retryTimes > 0);
  2432. if (retryTimes == 0)
  2433. {
  2434. DbgWithLink(LOG_LEVEL_ERROR, LOG_TYPE_SYSTEM).setLogCode(VtmLoaderService_LogCode_CheckDeviceEntity).setResultCode("RTA1F23")
  2435. ("after have tried x times");
  2436. ctx->Answer(Error_Unexpect, VtmLoader_EntityNotInNormal);
  2437. }
  2438. }
  2439. else {
  2440. DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM).setLogCode(VtmLoaderService_LogCode_CheckDeviceEntity).setResultCode("RTA1F22")
  2441. ("connect to %s failed.error code:%d", csEntityName.GetData(), eErrCode);
  2442. ctx->Answer(Error_Unexpect, VtmLoader_FailToConnectEntity);
  2443. }
  2444. }
  2445. else
  2446. {
  2447. DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM).setLogCode(VtmLoaderService_LogCode_CheckDeviceEntity).setResultCode("RTA1F22")
  2448. ("new client failed.");
  2449. ctx->Answer(Error_Unexpect, VtmLoader_FailToConnectEntity);
  2450. }
  2451. }
  2452. break;
  2453. case 0x217:
  2454. {
  2455. HSPScannerService_ClientBase* pClient = new HSPScannerService_ClientBase(this->m_pEntity);
  2456. if (pClient != NULL)
  2457. {
  2458. eErrCode = pClient->Connect();
  2459. if (eErrCode == Error_Succeed)
  2460. {
  2461. int retryTimes = maxRetryTimes;
  2462. do {
  2463. HSPScannerService_GetDevInfo_Req reqQ;
  2464. HSPScannerService_GetDevInfo_Ans ansQ;
  2465. eErrCode = (*pClient)(EntityResource::getLink().upgradeLink())->GetDevInfo(reqQ, ansQ, 5000);
  2466. DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("eErrCode:%d,ansQ.state:%d", eErrCode, ansQ.state);
  2467. if (eErrCode == Error_DevNotAvailable)
  2468. {
  2469. DbgWithLink(LOG_LEVEL_ERROR, LOG_TYPE_SYSTEM).setLogCode(VtmLoaderService_LogCode_CheckDeviceEntity).setResultCode("RTA1F23")("%d", eErrCode);
  2470. ctx->Answer(Error_Unexpect, VtmLoader_EntityNotInNormal);
  2471. return;
  2472. }
  2473. else if (eErrCode == Error_Succeed)
  2474. {
  2475. DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("return to caller");
  2476. ctx->Answer(Error_Succeed);
  2477. return;
  2478. }
  2479. Sleep(retryGetDevInfoInterval);
  2480. retryTimes--;
  2481. } while (retryTimes > 0);
  2482. if (retryTimes == 0)
  2483. {
  2484. DbgWithLink(LOG_LEVEL_ERROR, LOG_TYPE_SYSTEM).setLogCode(VtmLoaderService_LogCode_CheckDeviceEntity).setResultCode("RTA1F23")
  2485. ("after have tried x times");
  2486. ctx->Answer(Error_Unexpect, VtmLoader_EntityNotInNormal);
  2487. }
  2488. }
  2489. else {
  2490. DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM).setLogCode(VtmLoaderService_LogCode_CheckDeviceEntity).setResultCode("RTA1F22")
  2491. ("connect to %s failed.error code:%d", csEntityName.GetData(), eErrCode);
  2492. ctx->Answer(Error_Unexpect, VtmLoader_FailToConnectEntity);
  2493. }
  2494. }
  2495. else
  2496. {
  2497. DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM).setLogCode(VtmLoaderService_LogCode_CheckDeviceEntity).setResultCode("RTA1F22")
  2498. ("new client failed.");
  2499. ctx->Answer(Error_Unexpect, VtmLoader_FailToConnectEntity);
  2500. }
  2501. }
  2502. break;
  2503. default:
  2504. break;
  2505. }
  2506. return;
  2507. }
  2508. void CVtmLoaderFSM::CheckAudio(SpReqAnsContext<VtmLoaderService_CheckDeviceEntity_Req, VtmLoaderService_CheckDeviceEntity_Ans>::Pointer ctx)
  2509. {
  2510. CSmartPointer<IEntityFunctionPrivilege> pFuncPrivilege = m_pEntity->GetFunction().ConvertCase<IEntityFunctionPrivilege>();
  2511. CSmartPointer<IAsynWaitSp> spWait;
  2512. CEntityRunInfo runInfo;
  2513. //to check entity state
  2514. ErrorCodeEnum eErrCode = m_pEntity->GetFunction()->GetEntityRunInfo(ctx->Req.entityName.GetData(), runInfo);
  2515. if (eErrCode == Error_Succeed)
  2516. {
  2517. if (runInfo.eState != EntityState_NoStart)
  2518. {
  2519. eErrCode = pFuncPrivilege->TerminateEntity(ctx->Req.entityName.GetData(), spWait);
  2520. if (spWait != NULL)
  2521. eErrCode = spWait->WaitAnswer(MAX_AYSNC_TIMEOUT);
  2522. }
  2523. }
  2524. else
  2525. {
  2526. DbgWithLink(LOG_LEVEL_ERROR, LOG_TYPE_SYSTEM)("GetEntityRunInfo %s failed(%d).", ctx->Req.entityName.GetData(), eErrCode);
  2527. ctx->Answer(Error_Unexpect, VtmLoader_FailToGetEntityInfo);
  2528. return;
  2529. }
  2530. //(re)start entity
  2531. eErrCode = pFuncPrivilege->StartEntity(ctx->Req.entityName.GetData(), NULL, spWait);
  2532. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("StartEntity %s eErrCode(%d).", ctx->Req.entityName.GetData(), eErrCode);
  2533. if (eErrCode == Error_Succeed)
  2534. {
  2535. if (spWait != NULL)
  2536. eErrCode = spWait->WaitAnswer(MAX_AYSNC_TIMEOUT);
  2537. }
  2538. else
  2539. {
  2540. DbgWithLink(LOG_LEVEL_ERROR, LOG_TYPE_SYSTEM)("StartEntity %s failed(%d).", ctx->Req.entityName.GetData(), eErrCode);
  2541. ctx->Answer(Error_Unexpect, VtmLoader_FailToStartEntity);
  2542. return;
  2543. }
  2544. //TODO we should wait for device entity open suc?
  2545. int count = 0;
  2546. do
  2547. {
  2548. eErrCode = m_pEntity->GetFunction()->GetEntityRunInfo(ctx->Req.entityName.GetData(), runInfo);
  2549. if (eErrCode == Error_Succeed)
  2550. {
  2551. if (runInfo.eState == EntityState_Idle || runInfo.eState == EntityState_Lost)
  2552. {
  2553. CSimpleStringA csSoundCardState("");
  2554. eErrCode = GetEntityBase()->GetFunction()->GetSysVar("SoundCardState", csSoundCardState);
  2555. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("eErrCode:%d csSoundCardState:%s", eErrCode, csSoundCardState.GetData());
  2556. if (eErrCode == Error_Succeed)
  2557. {
  2558. if (csSoundCardState.Compare("N") == 0)
  2559. ctx->Answer(Error_Succeed);
  2560. else if (csSoundCardState.Compare("C") == 0)
  2561. ctx->Answer(Error_Unexpect, VtmLoader_CheckAudio_CfgEmpty);
  2562. else if (csSoundCardState.Compare("B") == 0)
  2563. ctx->Answer(Error_Unexpect, VtmLoader_CheckAudio_CfgBothError);
  2564. else if (csSoundCardState.Compare("P") == 0)
  2565. ctx->Answer(Error_Unexpect, VtmLoader_CheckAudio_CfgPickupError);
  2566. else if (csSoundCardState.Compare("H") == 0)
  2567. ctx->Answer(Error_Unexpect, VtmLoader_CheckAudio_CfgHandFreeError);
  2568. return;
  2569. }
  2570. else
  2571. {
  2572. DbgWithLink(LOG_LEVEL_ERROR, LOG_TYPE_SYSTEM)("failed to get sysvar SoundCardState , eErrCode:%d", eErrCode);
  2573. ctx->Answer(Error_Unexpect, VtmLoader_FailToStartEntity);
  2574. return;
  2575. }
  2576. }
  2577. else
  2578. {
  2579. Sleep(2000);
  2580. count++;
  2581. if (count > 5)
  2582. {
  2583. DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM)("after timeout, entity state is not we want...(Idle or Lost)");
  2584. ctx->Answer(Error_Unexpect, VtmLoader_FailToStartEntity);
  2585. return;
  2586. }
  2587. continue;
  2588. }
  2589. }
  2590. else
  2591. {
  2592. DbgWithLink(LOG_LEVEL_ERROR, LOG_TYPE_SYSTEM)("failed to GetEntityRunInfo, eErrCode:%d", eErrCode);
  2593. ctx->Answer(Error_Unexpect, VtmLoader_FailToStartEntity);
  2594. return;
  2595. }
  2596. } while (true);
  2597. }
  2598. void CVtmLoaderFSM::CheckVideo(SpReqAnsContext<VtmLoaderService_CheckDeviceEntity_Req, VtmLoaderService_CheckDeviceEntity_Ans>::Pointer ctx)
  2599. {
  2600. CSmartPointer<IEntityFunctionPrivilege> pFuncPrivilege = m_pEntity->GetFunction().ConvertCase<IEntityFunctionPrivilege>();
  2601. CSmartPointer<IAsynWaitSp> spWait;
  2602. CEntityRunInfo runInfo;
  2603. //to check entity state
  2604. ErrorCodeEnum eErrCode = m_pEntity->GetFunction()->GetEntityRunInfo(ctx->Req.entityName.GetData(), runInfo);
  2605. if (eErrCode == Error_Succeed)
  2606. {
  2607. if (runInfo.eState != EntityState_NoStart)
  2608. {
  2609. eErrCode = pFuncPrivilege->TerminateEntity(ctx->Req.entityName.GetData(), spWait);
  2610. if (spWait != NULL)
  2611. eErrCode = spWait->WaitAnswer(MAX_AYSNC_TIMEOUT);
  2612. }
  2613. }
  2614. else
  2615. {
  2616. DbgWithLink(LOG_LEVEL_ERROR, LOG_TYPE_SYSTEM)("GetEntityRunInfo %s failed(%d).", ctx->Req.entityName.GetData(), eErrCode);
  2617. ctx->Answer(Error_Unexpect, VtmLoader_FailToGetEntityInfo);
  2618. return;
  2619. }
  2620. m_bMediaControllerOK = false;
  2621. //(re)start entity
  2622. eErrCode = pFuncPrivilege->StartEntity(ctx->Req.entityName.GetData(), NULL, spWait);
  2623. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("StartEntity %s eErrCode(%d).", ctx->Req.entityName.GetData(), eErrCode);
  2624. if (eErrCode == Error_Succeed)
  2625. {
  2626. if (spWait != NULL)
  2627. eErrCode = spWait->WaitAnswer(MAX_AYSNC_TIMEOUT);
  2628. }
  2629. else
  2630. {
  2631. DbgWithLink(LOG_LEVEL_ERROR, LOG_TYPE_SYSTEM)("StartEntity %s failed(%d).", ctx->Req.entityName.GetData(), eErrCode);
  2632. ctx->Answer(Error_Unexpect, VtmLoader_FailToStartEntity);
  2633. return;
  2634. }
  2635. //TODO we should wait for device entity open suc?
  2636. int count = 0;
  2637. do
  2638. {
  2639. if (!m_bMediaControllerOK)
  2640. {
  2641. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("wait for MediaController to check video setting");
  2642. Sleep(2000);
  2643. count++;
  2644. if (count > 5)
  2645. {
  2646. DbgWithLink(LOG_LEVEL_ERROR, LOG_TYPE_SYSTEM)("after timeout, entity state is not right");
  2647. ctx->Answer(Error_Unexpect, VtmLoader_FailToStartEntity);
  2648. return;
  2649. }
  2650. continue;
  2651. }
  2652. CEntityRunInfo runInfo;
  2653. eErrCode = m_pEntity->GetFunction()->GetEntityRunInfo(ctx->Req.entityName.GetData(), runInfo);
  2654. if (eErrCode == Error_Succeed)
  2655. {
  2656. if (runInfo.eState == EntityState_Idle)
  2657. {
  2658. CSimpleStringA csCameraState("");
  2659. eErrCode = GetEntityBase()->GetFunction()->GetSysVar("CameraState", csCameraState);
  2660. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("eErrCode:%d csCameraState:%s", eErrCode, csCameraState.GetData());
  2661. if (eErrCode == Error_Succeed && csCameraState.Compare("N") == 0)
  2662. {
  2663. ctx->Answer(Error_Succeed);
  2664. return;
  2665. }
  2666. else
  2667. {
  2668. ctx->Answer(Error_Unexpect, VtmLoader_CheckVideoCfgFail);
  2669. return;
  2670. }
  2671. }
  2672. else if (runInfo.eState == EntityState_Lost || runInfo.eState == EntityState_Close || runInfo.eState == EntityState_Killed)
  2673. {
  2674. DbgWithLink(LOG_LEVEL_ERROR, LOG_TYPE_SYSTEM)("runInfo.eState:%d", runInfo.eState);
  2675. ctx->Answer(Error_Unexpect, VtmLoader_FailToStartEntity);
  2676. return;
  2677. }
  2678. }
  2679. else
  2680. {
  2681. DbgWithLink(LOG_LEVEL_ERROR, LOG_TYPE_SYSTEM)("failed to GetEntityRunInfo, eErrCode:%d", eErrCode);
  2682. ctx->Answer(Error_Unexpect, VtmLoader_FailToStartEntity);
  2683. return;
  2684. }
  2685. } while (true);
  2686. }
  2687. bool CVtmLoaderFSM::CheckConfigInfoInTestRoom()
  2688. {
  2689. if (m_iNoCheckMachineModel)
  2690. return true;
  2691. bool bNeedCheckOK = false;
  2692. #ifdef DEVOPS_ON_ST /*DevOps流水线编译,ST环境*/
  2693. bNeedCheckOK = true;
  2694. #elif defined(DEVOPS_ON_UAT)/*DevOps流水线编译,UAT环境*/
  2695. bNeedCheckOK = true;
  2696. #endif
  2697. if (bNeedCheckOK)
  2698. {
  2699. DoSpecialJobInTestRoom();
  2700. //to check MachineType
  2701. CSmartPointer<IConfigInfo> spConfigRoot;
  2702. if (GetEntityBase()->GetFunction()->OpenConfig(Config_Root, spConfigRoot) != Error_Succeed)
  2703. {
  2704. return true;
  2705. }
  2706. if (m_sysInfo.strMachineType.Compare("RVC.Stand2S") != 0 && m_sysInfo.strMachineType.Compare("RVC.CardStore")
  2707. && m_sysInfo.strMachineType.Compare("RVC.CardPrinter") && m_sysInfo.strMachineType.Compare("RVC.Stand1SPlus"))
  2708. {
  2709. if (m_sysInfo.strMachineType.IsNullOrEmpty())
  2710. LogWarn(Severity_High, Error_Unexpect, VtmLoader_BootInfoPrint, CSimpleStringA::Format("机型machineType配置为空,请检查", m_sysInfo.strMachineType.GetData()));
  2711. else
  2712. LogWarn(Severity_High, Error_Unexpect, VtmLoader_BootInfoPrint, CSimpleStringA::Format("机型machineType(%s)不对,请检查", m_sysInfo.strMachineType.GetData()));
  2713. return false;
  2714. }
  2715. //to check Terminal App Version
  2716. CSmartPointer<IConfigInfo> spConfigCen;
  2717. if (GetEntityBase()->GetFunction()->OpenConfig(Config_CenterSetting, spConfigCen) == Error_Succeed)
  2718. {
  2719. CSimpleStringA csWinVerPrefix(""), csUosVerPrefix(""), csStaticVerPrefix("");
  2720. spConfigCen->ReadConfigValue(GetEntityBase()->GetEntityName(), "WinVerPrefix", csWinVerPrefix);
  2721. spConfigCen->ReadConfigValue(GetEntityBase()->GetEntityName(), "UosVerPrefix", csUosVerPrefix);
  2722. csStaticVerPrefix = CSimpleStringA::Format("%d.%d",m_sysInfo.InstallVersion.GetMajor(), m_sysInfo.InstallVersion.GetMinor());
  2723. #if defined(RVC_OS_LINUX)
  2724. if (csUosVerPrefix.IsNullOrEmpty())
  2725. return true;
  2726. else
  2727. {
  2728. CAutoArray<CSimpleStringA> arrVer = csUosVerPrefix.Split('.');
  2729. if (arrVer.GetCount() > 1)
  2730. {
  2731. int major = atoi(arrVer[0].GetData());
  2732. int minor = atoi(arrVer[1].GetData());
  2733. if (m_sysInfo.InstallVersion.GetMajor() > major || (m_sysInfo.InstallVersion.GetMajor() == major && m_sysInfo.InstallVersion.GetMinor() > minor))
  2734. {
  2735. DbgWithLink(LOG_LEVEL_ERROR, LOG_TYPE_SYSTEM)("current version:%s, csUosVerPrefix:%s", m_sysInfo.InstallVersion.ToString().GetData(), csUosVerPrefix.GetData());
  2736. return false;
  2737. }
  2738. }
  2739. }
  2740. #else
  2741. if (csWinVerPrefix.IsNullOrEmpty())
  2742. return true;
  2743. else
  2744. {
  2745. CAutoArray<CSimpleStringA> arrVer = csWinVerPrefix.Split('.');
  2746. if (arrVer.GetCount() > 1)
  2747. {
  2748. int major = atoi(arrVer[0].GetData());
  2749. int minor = atoi(arrVer[1].GetData());
  2750. if (m_sysInfo.InstallVersion.GetMajor() > major || (m_sysInfo.InstallVersion.GetMajor() == major && m_sysInfo.InstallVersion.GetMinor() > minor))
  2751. {
  2752. DbgWithLink(LOG_LEVEL_ERROR, LOG_TYPE_SYSTEM)("current version:%s, csWinVerPrefix:%s", m_sysInfo.InstallVersion.ToString().GetData(), csWinVerPrefix.GetData());
  2753. return false;
  2754. }
  2755. }
  2756. }
  2757. #endif
  2758. }
  2759. }
  2760. return true;
  2761. }
  2762. bool CVtmLoaderFSM::CheckIfNeedCopyDepFiles()
  2763. {
  2764. //check if exist root.ini
  2765. CSimpleStringA csTmpRootIni("");
  2766. if (!IsRootINIExist(csTmpRootIni))
  2767. {
  2768. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("not exist root.ini, no need copy dep files.");
  2769. return false;
  2770. }
  2771. //check if exist run/dep/depver.txt
  2772. CSimpleStringA csRun(true), csPath(true);
  2773. ErrorCodeEnum eErr = GetEntityBase()->GetFunction()->GetPath("Run", csRun);
  2774. if (eErr != Error_Succeed)
  2775. {
  2776. DbgWithLink(LOG_LEVEL_ERROR, LOG_TYPE_SYSTEM)("get path of Run failed:%s", SpStrError(eErr));
  2777. return false;
  2778. }
  2779. csPath = csRun + SPLIT_SLASH_STR + "dep" + SPLIT_SLASH_STR + "depver.txt";
  2780. if(ExistsFileA(csPath)) {
  2781. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("depver.txt(%s) exist, no need to do dep copy.", csPath.GetData());
  2782. return false;
  2783. }
  2784. else
  2785. {
  2786. DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM)("depver.txt(%s) is not exist.", csPath.GetData());
  2787. return true;
  2788. }
  2789. }
  2790. void CVtmLoaderFSM::CopyDepFilesToNewDepPath()
  2791. {
  2792. //create run/dep/0.0.0.1 directory
  2793. CSimpleStringA csRun(true), csDepBakPath(true), csPath(true);
  2794. ErrorCodeEnum eErr = GetEntityBase()->GetFunction()->GetPath("Run", csRun);
  2795. if (eErr != Error_Succeed)
  2796. {
  2797. DbgWithLink(LOG_LEVEL_ERROR, LOG_TYPE_SYSTEM)("get path of Run failed:%s", SpStrError(eErr));
  2798. m_eDepCopyStage = DepDirInitCopy_CopyFailed;
  2799. return;
  2800. }
  2801. csPath = csRun + SPLIT_SLASH_STR + "dep" + SPLIT_SLASH_STR + "0.0.0.1";
  2802. if (!CreateDirA(csPath.GetData(), TRUE))
  2803. {
  2804. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("Create default dep version dir fail: %d", GetLastError());
  2805. m_eDepCopyStage = DepDirInitCopy_CopyFailed;
  2806. return;
  2807. }
  2808. else
  2809. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("Create default dep version dir %s suc", csPath.GetData());
  2810. eErr = GetEntityBase()->GetFunction()->GetPath("DepBak", csDepBakPath);
  2811. if (eErr != Error_Succeed)
  2812. {
  2813. DbgWithLink(LOG_LEVEL_ERROR, LOG_TYPE_SYSTEM)("get path of DepBak failed:%s", SpStrError(eErr));
  2814. m_eDepCopyStage = DepDirInitCopy_CopyFailed;
  2815. return;
  2816. }
  2817. //xcopy C:\sourceDir C:\destDir /E /I /Y
  2818. //cp -r /path/to/source /path/to/destination
  2819. std::string sucContent, failedContent;
  2820. CSimpleStringA strCmd;
  2821. #if defined(RVC_OS_WIN)
  2822. strCmd = CSimpleStringA::Format("cmd.exe /c xcopy %s %s /E /I /Y", csDepBakPath.GetData(), csPath.GetData());
  2823. #else
  2824. strCmd = CSimpleStringA::Format("cp -r -f %s/* %s", csDepBakPath.GetData(), csPath.GetData());
  2825. #endif //RVC_OS_WIN
  2826. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("to execute:%s", strCmd.GetData());
  2827. ULONGLONG ullCopyBeginTick = SP::Module::Comm::RVCGetTickCount();
  2828. bool ret = SP::Module::Util::ShellExecute(strCmd.GetData(), sucContent, failedContent);
  2829. ULONGLONG ullCopyEndTick = SP::Module::Comm::RVCGetTickCount();
  2830. 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);
  2831. if (ret)
  2832. {
  2833. //更新适配器版本号文件内容
  2834. CSimpleStringA csVersion("0.0.0.1");
  2835. eErr = GetEntityBase()->GetFunction()->GetPrivilegeFunction()->RewriteDepVersion(csVersion, true);
  2836. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("[RewriteDepVersion] %s,%s", SpStrError(eErr), csVersion.GetData());
  2837. m_eDepCopyStage = DepDirInitCopy_CopySuc;
  2838. LogWarn(Severity_Low, Error_Succeed, VtmLoader_DepDirCopySuc, CSimpleStringA::Format("%d", ullCopyEndTick - ullCopyBeginTick));
  2839. }
  2840. else
  2841. {
  2842. m_eDepCopyStage = DepDirInitCopy_CopyFailed;
  2843. DbgWithLink(LOG_LEVEL_ERROR, LOG_TYPE_SYSTEM).setResultCode("RTA1F08")("copy dep to new dep path failed, failedContent:%s", failedContent.c_str());
  2844. }
  2845. }
  2846. bool CVtmLoaderFSM::IfInExcludedLoadList(CSimpleStringA csEntityName)
  2847. {
  2848. if (csEntityName.IsNullOrEmpty())
  2849. return true;
  2850. for (int i = 0; i < m_arrExCludedList.GetCount(); ++i)
  2851. {
  2852. if (csEntityName.Compare(m_arrExCludedList[i], true) == 0)
  2853. return true;
  2854. }
  2855. return false;
  2856. }
  2857. void CVtmLoaderFSM::DoSpecialJobInTestRoom()
  2858. {
  2859. //special job including the following things:
  2860. //1.switch to the terminal app version you want
  2861. //2.delete other version directory you want
  2862. //3.just do it simple and straightforward
  2863. CSmartPointer<IConfigInfo> spConfigCen, spRunCfg;
  2864. if (GetEntityBase()->GetFunction()->OpenConfig(Config_CenterSetting, spConfigCen) == Error_Succeed)
  2865. {
  2866. CSimpleStringA csHaveSwitchVerTo("");
  2867. ErrorCodeEnum eErr = GetEntityBase()->GetFunction()->OpenConfig(Config_Run, spRunCfg);
  2868. if (eErr == Error_Succeed)
  2869. spRunCfg->ReadConfigValue(GetEntityBase()->GetEntityName(), "HaveSwitchVerTo", csHaveSwitchVerTo);
  2870. CSimpleStringA csSwitchVerTo("");
  2871. spConfigCen->ReadConfigValue(GetEntityBase()->GetEntityName(), "SwitchVerTo", csSwitchVerTo);
  2872. DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("SwitchVerTo:[%s], HaveSwitchVerTo:[%s]", csSwitchVerTo.GetData(), csHaveSwitchVerTo.GetData());
  2873. if (csSwitchVerTo.IsNullOrEmpty() || csSwitchVerTo.Compare(csHaveSwitchVerTo) == 0)
  2874. return;
  2875. //更新终端应用版本号文件内容
  2876. CSimpleStringA csRun(true), csActiveFilePath(true);
  2877. eErr = GetEntityBase()->GetFunction()->GetPath("Run", csRun);
  2878. if (eErr != Error_Succeed)
  2879. {
  2880. DbgWithLink(LOG_LEVEL_ERROR, LOG_TYPE_SYSTEM)("get path of Run failed:%s", SpStrError(eErr));
  2881. return;
  2882. }
  2883. csActiveFilePath = csRun + SPLIT_SLASH_STR + "version" + SPLIT_SLASH_STR + "active.txt";
  2884. HANDLE hFile = ::CreateFileA(csActiveFilePath.GetData(), GENERIC_WRITE, 0, NULL, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
  2885. BOOL bSetSucc = FALSE;
  2886. if (hFile == INVALID_HANDLE_VALUE)
  2887. {
  2888. DbgWithLink(LOG_LEVEL_ERROR, LOG_TYPE_SYSTEM)("open %s failed! err=%u", csActiveFilePath, GetLastError());
  2889. return;
  2890. }
  2891. DWORD dwWrittenLen(0);
  2892. bSetSucc = WriteFile(hFile, csSwitchVerTo.GetData(), csSwitchVerTo.GetLength(), &dwWrittenLen, NULL);
  2893. FlushFileBuffers(hFile);
  2894. SetEndOfFile(hFile);
  2895. CloseHandle(hFile);
  2896. spRunCfg->WriteConfigValue(GetEntityBase()->GetEntityName(), "HaveSwitchVerTo", csSwitchVerTo.GetData());
  2897. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("write version [%s] succeed", csSwitchVerTo.GetData());
  2898. if (bSetSucc) {
  2899. SureUnixFileAttributeAccessable(csActiveFilePath);
  2900. }
  2901. Sleep(10000);
  2902. GetEntityBase()->GetFunction()->GetPrivilegeFunction()->Reboot(RebootTrigger_ManualLocal, RebootWayEnum::RebootWay_Framework);
  2903. }
  2904. }
  2905. DWORD CVtmLoaderFSM::GetCenterCfgThread()
  2906. {
  2907. bool isUpdate = false, isReset = false;
  2908. CSimpleString version;
  2909. if (false == GetEntityBase()->GetFunction()->HasPrivilege())
  2910. {
  2911. LogWarn(Severity_High, Error_Unexpect, VtmLoader_CenterSettingConnectFailed,
  2912. CSimpleStringA::Format("下载集中配置失败:%s do not has privilege", __FUNCTION__));
  2913. DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_USER).setLogCode("QLR0402101Z01").setResultCode("RTA1104")("集中配置下载失败");
  2914. return -1;
  2915. }
  2916. auto ret = GetEntityBase()->GetFunction()->GetPrivilegeFunction()->TryUpdateCenterCfg(isUpdate, isReset, version);
  2917. if (ret != ErrorCodeEnum::Error_Succeed)
  2918. {
  2919. LogWarn(Severity_High, Error_Unexpect, VtmLoader_CenterSettingConnectFailed,
  2920. CSimpleStringA::Format("下载集中配置失败:%s", SpStrError(ret)));
  2921. DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_USER).setLogCode("QLR0402101Z01").setResultCode("RTA1104")("集中配置下载失败");
  2922. return -1;
  2923. }
  2924. if (!isUpdate)
  2925. {
  2926. return -1;
  2927. }
  2928. LogWarn(Severity_Low, Error_Succeed, VtmLoader_CenterSettingUpdateSucceed,
  2929. CSimpleStringA::Format("下载集中配置成功,版本号变更成:%s", version.GetData()));
  2930. if (isReset)
  2931. LogEvent(Severity_Middle, EVENT_MOD_CENTERSETTING_CRITICAL_UPDATE, "SpShell:Update centersetting with critical items.");
  2932. return 0;
  2933. }
  2934. void CVtmLoaderFSM::OnCentersettingUpdateTimeout(void* pData)
  2935. {
  2936. GetCenterCfgThread();
  2937. GetEntityBase()->GetFunction()->ResetTimer(TIMER_CENTERSETTING_UPDATE_CHECK, CENTERSETTING_UPDATE_CHECK_TIME);
  2938. }
  2939. CSimpleStringA CVtmLoaderFSM::GetOsVersion()
  2940. {
  2941. #if defined(RVC_OS_WIN)
  2942. CSimpleStringA runInfoPath;
  2943. ErrorCodeEnum eErr = GetEntityBase()->GetFunction()->GetPath("runinfo", runInfoPath);
  2944. if (eErr != Error_Succeed) {
  2945. DbgWithLink(LOG_LEVEL_ERROR, LOG_TYPE_SYSTEM).setResultCode(RTAERR_GETPATH_FAILED)("GetPath runinfo error=%d.", eErr);
  2946. return "";
  2947. }
  2948. runInfoPath += "\\runcfg\\osverion";
  2949. CSimpleStringA csCmd;
  2950. csCmd = CSimpleStringA::Format("cmd /c ver >%s", runInfoPath);
  2951. WinExec((LPCSTR)csCmd, SW_HIDE);
  2952. ifstream is;
  2953. is.open(runInfoPath.GetData(), ios::binary);
  2954. if (is.is_open())
  2955. {
  2956. string line;
  2957. while (!is.eof()) {
  2958. getline(is, line);
  2959. int start = line.find("版本");
  2960. if (start != string::npos)
  2961. {
  2962. DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("ver:[%s]", line.c_str());
  2963. return CSimpleStringA(line.c_str());
  2964. }
  2965. else
  2966. continue;
  2967. }
  2968. }
  2969. else
  2970. {
  2971. DWORD dwErr = GetLastError();
  2972. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("open runcfg\\osverion file failed. [%d]", dwErr);
  2973. }
  2974. return "";
  2975. #else
  2976. std::map<std::string, std::string> osInfo;
  2977. const char filePath[] = "/etc/os-version";
  2978. char tmp[33];
  2979. memset(tmp, 0, 33);
  2980. inifile_read_str_s("Version", "SystemName", "unknown", tmp, 32, filePath);
  2981. osInfo["SystemName"] = tmp;
  2982. memset(tmp, 0, 33);
  2983. inifile_read_str_s("Version", "ProductType", "unknown", tmp, 32, filePath);
  2984. osInfo["ProductType"] = tmp;
  2985. memset(tmp, 0, 33);
  2986. inifile_read_str_s("Version", "MajorVersion", "unknown", tmp, 32, filePath);
  2987. osInfo["MajorVersion"] = tmp;
  2988. memset(tmp, 0, 33);
  2989. inifile_read_str_s("Version", "MinorVersion", "unknown", tmp, 32, filePath);
  2990. osInfo["MinorVersion"] = tmp;
  2991. memset(tmp, 0, 33);
  2992. inifile_read_str_s("Version", "OsBuild", "unknown", tmp, 32, filePath);
  2993. osInfo["OsBuild"] = tmp;
  2994. return generateJsonStr(osInfo).second.c_str();
  2995. #endif
  2996. }
  2997. void CVtmLoaderFSM::QueryLocalInfo(SpReqAnsContext<VtmLoaderService_QueryLocalInfo_Req, VtmLoaderService_QueryLocalInfo_Ans>::Pointer ctx)
  2998. {
  2999. #ifdef RVC_OS_WIN
  3000. ctx->Ans.VtmAppType = "Windows";
  3001. #else
  3002. ctx->Ans.VtmAppType = "UOS";
  3003. #endif
  3004. CSimpleStringA csRunPath("");
  3005. GetEntityBase()->GetFunction()->GetPath("Run", csRunPath);
  3006. ctx->Ans.AppPath = csRunPath;
  3007. CAutoArray<NetworkAdapterItem> netList;
  3008. if (SP::Module::Net::GetINETMacAddresses(netList) == Error_Succeed)
  3009. {
  3010. CSimpleStringA csMac(""), csIP("");
  3011. for (int i = 0; i < netList.GetCount(); i++) {
  3012. if (!csMac.IsNullOrEmpty()) {
  3013. csMac += ";";
  3014. }
  3015. csMac += netList[i].mac.c_str();
  3016. if (!csIP.IsNullOrEmpty()) {
  3017. csIP += ";";
  3018. }
  3019. csIP += netList[i].ip.c_str();
  3020. }
  3021. ctx->Ans.IPs = csIP;
  3022. ctx->Ans.MACs = csMac;
  3023. }
  3024. ctx->Ans.DNSs = GetDns();
  3025. ctx->Ans.OSVersion = GetOsVersion();
  3026. ctx->Answer(Error_Succeed);
  3027. }