123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213 |
- #include "stdafx.h"
- #include <algorithm>
- #include <fstream>
- #include <winpr/file.h>
- #include "fileutil.h"
- #include "iniutil.h"
- #include "RVCEventCode.h"
- #include "VtmLoaderFSM.h"
- #include "EventCode.h"
- #if defined(RVC_OS_WIN)
- #include <io.h>
- #else
- #include <unistd.h>
- #include <fcntl.h>
- #include <errno.h>
- #include "RestfulFunc.h"
- #endif //RVC_OS_WIN
- #include "../mod_healthmanager/HealthManager_client_g.h"
- #include "../mod_pinpad/PinPad_client_g.h"
- #include "../mod_CardIssuerStand/CardIssuerStand_client_g.h"
- #include "../mod_cardissuerstore/CardIssuerStore_client_g.h"
- #include "../mod_IDCertificate/IDCertificate_client_g.h"
- #include "../mod_HSPScanner/HSPScanner_client_g.h"
- #include "../mod_ContactlessCard/ContactlessCard_client_g.h"
- #include "../mod_FingerPrint/FingerPrint_client_g.h"
- #include "../mod_gpio/Gpio_client_g.h"
- #include "SpDefine.h"
- using namespace HealthManager;
- using namespace PinPad;
- using namespace CardIssuerStand;
- using namespace CardIssuerStore;
- using namespace IDCertificate;
- using namespace HSPScanner;
- using namespace ContactlessCard;
- using namespace FingerPrint;
- using namespace Gpio;
- using namespace SP::Module::Net;
- #define ALLOW_MULTI_NETWORKD_CARDS
- const int MAX_AYSNC_TIMEOUT = 60000;
- const int MAX_IGNORE_TIMEOUT = 100;
- enum EntityOP
- {
- OP_STOP_ENTITY,
- OP_START_ENTITY,
- OP_PAUSE_ENTITY,
- OP_TERMINATE_ENTITY,
- OP_CONTINUE_ENTITY,
- };
- struct callback_entry : public IReleasable
- {
- virtual ~callback_entry() {}
- CSimpleStringA EntityName;
- union {
- void* pRawData;
- int state;
- };
- int op;
- ErrorCodeEnum ErrorResult;
- };
- DWORD tokenUpdate(void* param)
- {
- CVtmLoaderFSM* t_entity = (CVtmLoaderFSM*)param;
- DWORD lastUpdateTime = 0; // 获取当前时间(以毫秒为单位)
- while (true)
- {
- DWORD currentTime = SP::Module::Comm::RVCGetTickCount(); // 获取当前时间
- DWORD elapsedTime = currentTime - lastUpdateTime; // 计算与上次更新的时间间隔(毫秒)
- if (elapsedTime >= (t_entity->m_refreshWaitSec * 1000))
- {
- // 如果距离上次更新时间已经超过了指定的刷新间隔
- if (t_entity->refreshToken())
- {
- // 更新成功,更新上次更新时间
- lastUpdateTime = currentTime;
- }
- else
- {
- // 更新失败,可以处理一些错误逻辑
- }
- }
- // 等待一段时间后再次检查
- Sleep(20000); // 20秒
- }
- return 0;
- }
- DWORD errMsgListUpdate(void* param)
- {
- CVtmLoaderFSM* t_entity = (CVtmLoaderFSM*)param;
- static bool msgErrThreadExist = false;
- if (msgErrThreadExist)
- return true;
- else
- {
- msgErrThreadExist = true;
- }
- /*
- CSimpleString code, des;
- t_entity->GetEntityBase()->GetFunction()->GetVTMErrMsg(VtmLoader_DETECT_VERSION_ERR, code, des);
- DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_USER)("VtmLoader_DETECT_VERSION_ERR, %s, %s", code.GetData(), des.GetData());
- */
- //update err list after setting centersetting urls
- //try updating every 20s until success
- int times = 0;
- ErrorCodeEnum rc = Error_Succeed;
- while (times < 5 && Error_Succeed != (rc = t_entity->GetEntityBase()->GetFunction()->GetPrivilegeFunction()->TryUpdateVTMERRMSG()))
- {
- LogWarn(SeverityLevelEnum::Severity_Low, Error_Unexpect, LOG_WARN_VtmLoader_GetVTMERRMSG_Failed, "Get errMsgListUpdate config failed.");
- Sleep(20000);
- times++;
- }
-
- if(rc == Error_Succeed)
- LogEvent(Severity_High, Event_VtmLoader_GetVTMERRMSG_Suc, "Get errMsgListUpdate config succeed.");
-
- /*
- t_entity->GetEntityBase()->GetFunction()->GetVTMErrMsg(VtmLoader_DETECT_VERSION_ERR, code, des);
- DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_USER)("VtmLoader_DETECT_VERSION_ERR, %s, %s", code.GetData(), des.GetData());
- t_entity->GetEntityBase()->GetFunction()->GetVTMErrMsg(123456, code, des);
- DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_USER)("123456, %s, %s", code.GetData(), des.GetData());
- t_entity->GetEntityBase()->GetFunction()->GetVTMErrMsg(VtmLoader_FailToConnectEntity, code, des);
- DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_USER)("VtmLoader_FailToConnectEntity, %s, %s", code.GetData(), des.GetData());
- t_entity->GetEntityBase()->GetFunction()->GetVTMErrMsg(WARN_SendEndpoint_URL_ERR, code, des);
- DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_USER)("WARN_SendEndpoint_URL_ERR, %s, %s", code.GetData(), des.GetData());
- t_entity->GetEntityBase()->GetFunction()->GetVTMErrMsg(VtmLoader_GetConfig_UpdateCfg_Failed, code, des);
- DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_USER)("VtmLoader_GetConfig_UpdateCfg_Failed, %s, %s", code.GetData(), des.GetData());
- t_entity->GetEntityBase()->GetFunction()->GetVTMErrMsg(0x50100215, code, des);
- DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_USER)("0x50100215, %s, %s", code.GetData(), des.GetData());
- */
- return 0;
- }
- DWORD checkUrlActive(LPVOID param)
- {
- CVtmLoaderFSM* entityInfo = (CVtmLoaderFSM*)param;
- CSmartPointer<IConfigInfo> pConfig;
- CSimpleString t_endpoint, t_materialUrl;
- CSimpleString errMsg;
- Sleep(60 * 1000);
- long srcClo = clock();
- entityInfo->GetEntityBase()->GetFunction()->OpenConfig(Config_CenterSetting, pConfig);
- do {
- if (Error_Succeed != pConfig->ReadConfigValue("Common", "SendEndpoint", t_endpoint))
- {
- errMsg = "checkUrlActive read Common::SendEndpoint err";
- break;
- }
- if (t_endpoint.GetLength() == 0)
- {
- errMsg = "checkUrlActive endpoint len=0 err";
- break;
- }
- //if (!checkHttpActive(t_endpoint.GetData()))
- // errMsg.Append(CSimpleString::Format("checkHttpActive endpoint err:%s !", t_endpoint.GetData()));
- //else if((clock() - srcClo) > 3000)
- // errMsg.Append(CSimpleString::Format("checkHttpActive endpoint too long:%d !", clock() - srcClo));
- srcClo = clock();
- } while (false);
- if (errMsg.GetLength() > 0)
- LogWarn(SeverityLevelEnum::Severity_Middle, Error_Unexpect, WARN_SendEndpoint_URL_ERR, errMsg.GetData());
- //do get upload log Info for a while
- while (true)
- {
- if (entityInfo->m_uploadLogInfo_waitSec <= 0)
- break;
- unsigned long t_upload_TerminalSys_Suc, t_upload_TerminalUser_Suc, t_upload_BussinessSys_Suc, t_upload_BussinessUser_Suc, t_upload_beidou_Suc;
- unsigned long t_upload_TerminalSys_Err, t_upload_TerminalUser_Err, t_upload_BussinessSys_Err, t_upload_BussinessUser_Err, t_upload_beidou_Err;
- unsigned long t_discard_full, t_discard_RTI1002, curLogNum;
- entityInfo->GetEntityBase()->GetFunction()->GetPrivilegeFunction()->GetSendLogInfo(&t_upload_TerminalSys_Suc, &t_upload_TerminalUser_Suc,
- &t_upload_BussinessSys_Suc, &t_upload_BussinessUser_Suc, &t_upload_beidou_Suc,
- &t_upload_TerminalSys_Err, &t_upload_TerminalUser_Err, &t_upload_BussinessSys_Err, &t_upload_BussinessUser_Err, &t_upload_beidou_Err,
- &t_discard_full, &t_discard_RTI1002, &curLogNum);
- /*LogWarn(SeverityLevelEnum::Severity_Low, Error_Trace, WARN_SendEndpoint_LOG_INFO,
- 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"
- , t_upload_TerminalSys_Suc, t_upload_TerminalUser_Suc, t_upload_BussinessSys_Suc, t_upload_BussinessUser_Suc, t_upload_beidou_Suc,
- t_upload_TerminalSys_Err, t_upload_TerminalUser_Err, t_upload_BussinessSys_Err, t_upload_BussinessUser_Err, t_upload_beidou_Err
- , t_discard_full, t_discard_RTI1002, curLogNum).GetData());
- */
- DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("%s",
- 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"
- , t_upload_TerminalSys_Suc, t_upload_TerminalUser_Suc, t_upload_BussinessSys_Suc, t_upload_BussinessUser_Suc, t_upload_beidou_Suc,
- t_upload_TerminalSys_Err, t_upload_TerminalUser_Err, t_upload_BussinessSys_Err, t_upload_BussinessUser_Err, t_upload_beidou_Err
- , t_discard_full, t_discard_RTI1002, curLogNum).GetData());
- Sleep(entityInfo->m_uploadLogInfo_waitSec * 1000);
- }
- return 0;
- }
- DWORD AlarmVersionErr(LPVOID param)
- {
- CVtmLoaderFSM* cur = (CVtmLoaderFSM*)param;
- Sleep(5000);//wait mod_alarm start
- LogWarn(Severity_Middle, Error_Bug, VtmLoader_DETECT_VERSION_ERR, cur->m_verShowMsg.GetData());
- return 0;
- }
- bool CVtmLoaderFSM::refreshToken()
- {
- CSimpleString oldToken, newToken;
- ErrorCodeEnum eErr = Error_Succeed;
- if (Error_Succeed != (eErr = GetEntityBase()->GetFunction()->GetPrivilegeFunction()->TryUpdateToken(oldToken, newToken)))
- {
- DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_USER).setLogCode("QLR040210F13").setResultCode("RTA1F02")("Get center setting, TryUpdateToken failed:0x%x", eErr);
- LogWarn(Severity_High, Error_Unexpect, VtmLoader_GetConfig_UpdateToken_Failed, CSimpleStringA::Format("拉取配置失败:0x%x(%s)", eErr, SpStrError(eErr)).GetData());
- return false;
- }
- return true;
- }
- CVtmLoaderFSM::CVtmLoaderFSM()
- {
- m_refreshWaitSec = 1200;
- m_uploadLogInfo_waitSec = 3600;
- m_defaultSystemId = "LR04.02_Terminal";
- m_iCanIgnoreAddrDetect = 0;
- m_ullMaxAddrDetectTime = 10*60*1000;//10 minutes
- m_iDetectInterval = 5000;
- m_terminalNoFromWeb = m_verShowMsg = "";
- m_iNoCheckMachineModel = 0;
- m_bSIPPhoneStartFail = false;
- m_eDepCopyStage = DepDirInitCopy_NoNeed;
- }
- CVtmLoaderFSM::~CVtmLoaderFSM()
- {
- }
- ErrorCodeEnum CVtmLoaderFSM::OnInit()
- {
- AddStateHooker(this);
- GetEntityBase()->GetFunction()->GetSystemStaticInfo(m_sysInfo);
- return Error_Succeed;
- }
- ErrorCodeEnum CVtmLoaderFSM::OnExit()
- {
- GetEntityBase()->GetFunction()->KillTimer(TIMER_CENTERSETTING_UPDATE_CHECK);
- RemoveStateHooker(this);
- return Error_Succeed;
- }
- void CVtmLoaderFSM::OnStateTrans(int iSrcState, int iDstState)
- {
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("state change from %s to %s", GetStateName(iSrcState), GetStateName(iDstState));
- }
- void CVtmLoaderFSM::s0_on_entry()
- {
- CSimpleStringA csTmpTS("");
- ErrorCodeEnum eErr = GetEntityBase()->GetFunction()->GetSysVar("TerminalStage", csTmpTS);
- if (eErr == Error_Succeed && !csTmpTS.IsNullOrEmpty() && csTmpTS.Compare("X") != 0)
- {
- DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_USER)(" eErr:%d", eErr);
- 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());
- GetConfig();
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_USER)("redo GetConfig finished.");
- }
- else
- {
- if (CheckIfNeedCopyDepFiles())
- {
- m_eDepCopyStage = DepDirInitCopy_Copying;
- CopyDepFilesToNewDepPathTask* pCopyTask = new CopyDepFilesToNewDepPathTask(this);
- GetEntityBase()->GetFunction()->PostThreadPoolTask(pCopyTask);
- }
- LogWarn(Severity_Low, Error_Succeed, VtmLoader_BootInfoPrint, "开始网卡、网络连通性检查");
- NetWorkCheckAndGetSettingTask* task = new NetWorkCheckAndGetSettingTask(this);
- GetEntityBase()->GetFunction()->PostThreadPoolTask(task);
- }
- GetOsVersion();
- }
- void CVtmLoaderFSM::s0_on_exit()
- {
- }
- unsigned int CVtmLoaderFSM::s0_on_event(FSMEvent* pEvt)
- {
- DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("s0_on_event,pEvt:%d,pEvt->param1:%d", pEvt->iEvt, pEvt->param1);
- switch (pEvt->iEvt)
- {
- case USER_EVT_NetworkCheck_Passed:
- pEvt->SetHandled();
- return pEvt->param1;
- case USER_EVT_CHECK_DEVICE_ENTITY:
- pEvt->SetHandled();
- {
- CheckDeviceEntityEvent* cdee = dynamic_cast<CheckDeviceEntityEvent*>(pEvt);
- CheckDeviceEntityTask* pTask = new CheckDeviceEntityTask(this);
- pTask->ctx = cdee->ctx;
- GetEntityBase()->GetFunction()->PostThreadPoolTask(pTask);
- }
- break;
- case USER_EVT_SAVE_TERMINALNO:
- pEvt->SetHandled();
- {
- SaveTerminalNoEvent* stne = dynamic_cast<SaveTerminalNoEvent*>(pEvt);
- SaveTerminalNoTask* pTask = new SaveTerminalNoTask(this);
- pTask->ctx = stne->ctx;
- GetEntityBase()->GetFunction()->PostThreadPoolTask(pTask);
- }
- break;
- case USER_EVT_DEALWITH_OLD_EVENT:
- pEvt->SetHandled();
- {
- DealWithOldEvent_Event *evt = dynamic_cast<DealWithOldEvent_Event*>(pEvt);
- DealWithOldEvent_Task* pTask = new DealWithOldEvent_Task(this);
- pTask->ctx = evt->ctx;
- GetEntityBase()->GetFunction()->PostThreadPoolTask(pTask);
- }
- break;
- case USER_EVT_QUERY_LOCAL_INFO:
- pEvt->SetHandled();
- {
- QueryLocalInfoEvent* qlie = dynamic_cast<QueryLocalInfoEvent*>(pEvt);
- QueryLocalInfoTask* pTask = new QueryLocalInfoTask(this);
- pTask->ctx = qlie->ctx;
- GetEntityBase()->GetFunction()->PostThreadPoolTask(pTask);
- }
- break;
- default:
- break;
- }
- return 0;
- }
- //CoreBoot
- void CVtmLoaderFSM::s1_on_entry()
- {
- DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("s1_on_entry");
- ErrorCodeEnum eErrCode;
- CSmartPointer<IEntityFunction> spEntityFunction = GetEntityBase()->GetFunction();
- CSmartPointer<IEntityFunctionPrivilege> pFuncPrivilege = spEntityFunction.ConvertCase<IEntityFunctionPrivilege>();
- bool bAsync = false;
- m_eStage = LOADSTAGE_COREBOOT;
- int ret = 0;
- map<CSimpleStringA, EntityLoadInfo>::iterator it;
- //start entity
- vector<CSimpleStringA>::iterator vIt;
- if (m_coreBootOpt.size() == 0)
- goto COREBOOT_FINISH;
- char startMsg[128];
- for (vIt = m_vCoreBoot.begin(); vIt != m_vCoreBoot.end(); ++vIt)
- {
- CSmartPointer<IAsynWaitSp> spWait;//oilyang 20160325 see the following comment
- it = m_coreBootOpt.find(*vIt);
- if (it == m_coreBootOpt.end())
- {
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("cannot find %s", (LPCSTR)* vIt);
- continue;
- }
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("start,%s,%d", (LPCSTR)it->first, it->second.loadOpt);
- CEntityRunInfo entRunInfo;
- ErrorCodeEnum errCode = spEntityFunction->GetEntityRunInfo(it->first, entRunInfo);
- if (errCode == Error_Succeed && entRunInfo.eState == EntityState_Idle)
- {
- it->second.eResult = LOADING_SUCCEED;
- ret = CheckLoadResult(LOADSTAGE_COREBOOT);
- if (ret == 0 || ret == 2)
- goto COREBOOT_FINISH;
- else
- continue;
- }
- ZeroMemory(startMsg, 128);
- //sprintf(startMsg, "正在启动实体%s...", it->first.GetData());
- //GetEntityBase()->GetFunction()->ShowStartupInfo(startMsg);
- switch (it->second.loadOpt)
- {
- case LOADOPT_IGNORE:
- {
- pFuncPrivilege->StartEntity(it->first, NULL, spWait);
- if (spWait != NULL)
- spWait->WaitAnswer(MAX_IGNORE_TIMEOUT);//oilyang 20160325 the null pointer
- it->second.eResult = LOADING_SUCCEED;
- ret = CheckLoadResult(LOADSTAGE_COREBOOT);
- if (ret == 0 || ret == 2)
- goto COREBOOT_FINISH;
- }
- break;
- case LOADOPT_ASYNC_VERIFY:
- errCode = AsyncStartEntity(it->first, NULL, NULL);
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("AsyncStartEntity:%d", errCode);
- bAsync = true;
- break;
- case LOADOPT_SYNC_VERIFY:
- {
- ULONGLONG dwEntityStart = SP::Module::Comm::RVCGetTickCount();
- pFuncPrivilege->StartEntity(it->first, NULL, spWait);
- if (spWait != NULL)
- errCode = spWait->WaitAnswer(MAX_AYSNC_TIMEOUT);
- ULONGLONG dwEntityEnd = SP::Module::Comm::RVCGetTickCount();
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI("SyncStartEntity").setCostTime((dwEntityEnd - dwEntityStart) / 1000)("%d", errCode);
- if (errCode == Error_Succeed)
- it->second.eResult = LOADING_SUCCEED;
- else if (errCode == Error_TimeOut)
- it->second.eResult = LOADING_TIMEOUT;
- else
- it->second.eResult = LOADING_FAILED;
- if (errCode != Error_Succeed) {
- CSimpleStringA tmpAuthErrMsg("");
- if (GetEntityBase()->GetFunction()->GetSysVar("AuthErrMsg", tmpAuthErrMsg) == Error_Succeed && tmpAuthErrMsg.IsNullOrEmpty())
- GetEntityBase()->GetFunction()->SetSysVar("AuthErrMsg", CSimpleStringA::Format("%s 启动失败,请尝试重启应用或重启系统恢复", it->first.GetData()).GetData());
- if (it->first.Compare("SIPPhone") == 0)
- m_bSIPPhoneStartFail = true;
- DbgWithLink(LOG_LEVEL_ERROR, LOG_TYPE_SYSTEM)("启动失败:%s", it->first.GetData());
- m_csErrEntity = m_csErrEntity + "|" + it->first;
- FSMEvent* e = new FSMEvent(USER_EVT_COREBOOT_FINISHED);
- e->param1 = 2;//"SYNC START" enity started failed.
- PostEventFIFO(e);
- return;
- }
- else
- ret = CheckLoadResult(LOADSTAGE_COREBOOT);
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("s1 check ret %d", ret);
- if (ret == 0 || ret == 2)
- goto COREBOOT_FINISH;
- }
- break;
- default:
- break;
- }
- }
- COREBOOT_FINISH:
- if (!bAsync)
- {
- FSMEvent* e = new FSMEvent(USER_EVT_COREBOOT_FINISHED);
- e->param1 = ret;
- PostEventFIFO(e);
- }
- else
- {
- ret = CheckLoadResult(LOADSTAGE_COREBOOT);
- if (ret == 0 || ret == 2)
- {
- FSMEvent* e = new FSMEvent(USER_EVT_COREBOOT_FINISHED);
- e->param1 = ret;
- PostEventFIFO(e);
- }
- }
- return;
- }
- void CVtmLoaderFSM::s1_on_exit()
- {
- LOG_FUNCTION();
- }
- unsigned int CVtmLoaderFSM::s1_on_event(FSMEvent* pEvt)
- {
- LOG_FUNCTION();
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("s1 evt %d", pEvt->iEvt);
- switch (pEvt->iEvt)
- {
- case USER_EVT_COREBOOT_FINISHED:
- pEvt->SetHandled();
- return pEvt->param1;
- default:
- break;
- }
- return 0;
- }
- //SafeLoad
- void CVtmLoaderFSM::s2_on_entry()
- {
- LOG_FUNCTION();
- LogWarn(Severity_Low, Error_Succeed, VtmLoader_BootInfoPrint, "CoreBoot 阶段实体加载完成");
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_USER).setLogCode("QLR040210F14")("Stage Coreboot have done.");
- ULONGLONG dwElapse = SP::Module::Comm::RVCGetTickCount();//使用机器启动时间秒数
- DWORD elapseTimeTemp = dwElapse / 1000;
- CSimpleStringA xMsg = CSimpleStringA::Format("{\"Decripstion\":\"Enter safeload state.\",\"version\":\"%s\",\"elapseTime\":\"%d\"}", m_sysInfo.InstallVersion.ToString().GetData(), elapseTimeTemp);
- //LogWarn(Severity_Low, Error_Unexpect, HealthManager_UserErrorCode_Enter_SafeLoad_State, xMsg.GetData());
- if (!VerifyVer())
- return;
- bool bAsync = false;
- m_eStage = LOADSTAGE_SAFELOAD;
- int ret = 0;
- map<CSimpleStringA, EntityLoadInfo>::iterator it;
- CSmartPointer<IEntityFunction> pFunc = GetEntityBase()->GetFunction();
- CSmartPointer<IEntityFunctionPrivilege> pFuncPrivilege = pFunc.ConvertCase<IEntityFunctionPrivilege>();
- ErrorCodeEnum errCode;
- vector<CSimpleStringA>::iterator vIt;
- if (m_safeLoadOpt.size() == 0)
- goto SAFELOAD_FINISH;
- char startMsg[128];
- for (vIt = m_vSafeLoad.begin(); vIt != m_vSafeLoad.end(); ++vIt)
- {
- CSmartPointer<IAsynWaitSp> spWait;
- it = m_safeLoadOpt.find(*vIt);
- if (it == m_safeLoadOpt.end())
- {
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("cannot find %s", (LPCSTR)* vIt);
- continue;
- }
- CEntityRunInfo entRunInfo;
- errCode = pFunc->GetEntityRunInfo(it->first, entRunInfo);
- if (errCode == Error_Succeed && entRunInfo.eState == EntityState_Idle)
- {
- it->second.eResult = LOADING_SUCCEED;
- ret = CheckLoadResult(LOADSTAGE_SAFELOAD);
- if (ret == 0 || ret == 2)
- goto SAFELOAD_FINISH;
- else
- continue;
- }
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("start %s,%d", (LPCTSTR)it->first, it->second.loadOpt);
- switch (it->second.loadOpt)
- {
- case LOADOPT_IGNORE:
- {
- pFuncPrivilege->StartEntity(it->first, NULL, spWait);
- if (spWait != NULL)
- spWait->WaitAnswer(MAX_IGNORE_TIMEOUT);
- it->second.eResult = LOADING_SUCCEED;
- ret = CheckLoadResult(LOADSTAGE_SAFELOAD);
- if (ret == 0 || ret == 2)
- goto SAFELOAD_FINISH;
- }
- break;
- case LOADOPT_ASYNC_VERIFY:
- AsyncStartEntity(it->first, NULL, NULL);
- bAsync = true;
- break;
- case LOADOPT_SYNC_VERIFY:
- {
- ZeroMemory(startMsg, 128);
- sprintf(startMsg, "正在启动实体%s...", it->first.GetData());
- GetEntityBase()->GetFunction()->ShowStartupInfo(startMsg);
- ULONGLONG dwEntityStart = SP::Module::Comm::RVCGetTickCount();
- pFuncPrivilege->StartEntity(it->first, NULL, spWait);
- if (spWait != NULL)
- errCode = spWait->WaitAnswer(MAX_AYSNC_TIMEOUT);
- ULONGLONG dwEntityEnd = SP::Module::Comm::RVCGetTickCount();
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI("SyncStartEntity").setCostTime((dwEntityEnd - dwEntityStart) / 1000)("%d", errCode);
- if (it->first.Compare("SIPPhone") == 0)
- LogWarn(Severity_Low, Error_Succeed, VtmLoader_SIPPhoneEntityLoad_Cost, CSimpleStringA::Format("%d", (dwEntityEnd - dwEntityStart) / 1000));
-
- if (errCode == Error_Succeed) {
- it->second.eResult = LOADING_SUCCEED;
- }
- else if (errCode == Error_TimeOut)
- it->second.eResult = LOADING_TIMEOUT;
- else
- it->second.eResult = LOADING_FAILED;
- if (it->second.eResult != Error_Succeed)
- {
- CSimpleStringA tmpAuthErrMsg("");
- if (GetEntityBase()->GetFunction()->GetSysVar("AuthErrMsg", tmpAuthErrMsg) == Error_Succeed && tmpAuthErrMsg.IsNullOrEmpty())
- GetEntityBase()->GetFunction()->SetSysVar("AuthErrMsg", CSimpleStringA::Format("%s 启动失败,请尝试重启应用或重启系统恢复", it->first.GetData()).GetData());
- if (it->first.Compare("SIPPhone") == 0)
- m_bSIPPhoneStartFail = true;
- DbgWithLink(LOG_LEVEL_ERROR, LOG_TYPE_SYSTEM)("启动失败:%s", it->first.GetData());
- m_csErrEntity = m_csErrEntity + "|" + it->first;
- FSMEvent* e = new FSMEvent(USER_EVT_SAFELOAD_FINISHED);
- e->param1 = 2;//"SYNC START" enity started failed.
- PostEventFIFO(e);
- return;
- }
- //if (errCode != Error_Succeed)
- // return;
- //else
- ret = CheckLoadResult(LOADSTAGE_SAFELOAD);
- if (ret == 0 || ret == 2)
- goto SAFELOAD_FINISH;
- }
- break;
- default:
- break;
- }
- }
- SAFELOAD_FINISH:
- if (!bAsync)
- {
- FSMEvent* e = new FSMEvent(USER_EVT_SAFELOAD_FINISHED);
- e->param1 = ret;
- PostEventFIFO(e);
- }
- else
- {
- ret = CheckLoadResult(LOADSTAGE_SAFELOAD);
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("s2 %d", ret);
- if (ret == 0 || ret == 2)
- {
- FSMEvent* e = new FSMEvent(USER_EVT_SAFELOAD_FINISHED);
- e->param1 = ret;
- PostEventFIFO(e);
- }
- }
- SAFELOAD_END:
- return;
- }
- void CVtmLoaderFSM::s2_on_exit()
- {
- LOG_FUNCTION();
- }
- unsigned int CVtmLoaderFSM::s2_on_event(FSMEvent* pEvt)
- {
- LOG_FUNCTION();
- int ret = 0;
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("s2 event %d,%d", pEvt->iEvt, pEvt->param1);
- switch (pEvt->iEvt)
- {
- case USER_EVT_SAFELOAD_FINISHED:
- {
- pEvt->SetHandled();
- //oiltmp
- //according to the system varible TerminalState to do sth.
- //Configed
- //Breakdown
- //Blocking
- //Authentication
- {
- if (pEvt->param1 == 0)
- {
- //initializer if configured
- CSimpleStringA csTermStage("");
- ErrorCodeEnum eErrCode;
- eErrCode = GetEntityBase()->GetFunction()->GetSysVar("TerminalStage", csTermStage);
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("after safeload to get termstage %s", (LPCTSTR)csTermStage);
- if (csTermStage == "B" || csTermStage == "N")
- return 1;
- }
- else if (pEvt->param1 == 2)
- ret = 2;
- }
- //Unsubscrible
- }
- break;
- case USER_EVT_SAFELOAD_EXMINE_FINISHED:
- if (pEvt->param1 == 0)
- ret = 0;
- //do something else oiltmp
- pEvt->SetHandled();
- break;
- default:
- break;
- }
- return ret;
- }
- //Operating
- void CVtmLoaderFSM::s3_on_entry()
- {
- LogWarn(Severity_Low, Error_Succeed, VtmLoader_BootInfoPrint, "SafeLoad 阶段实体加载完成");
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_USER).setLogCode("QLR040210F15")("Stage Safeload have done.");
- Sleep(m_sleepEnterOpMS);
- bool bAsync = false;
- m_eStage = LOADSTAGE_OPERATING;
- int ret = 0;
- map<CSimpleStringA, EntityLoadInfo>::iterator it;
- CSmartPointer<IEntityFunction> pFunc = GetEntityBase()->GetFunction();
- CSmartPointer<IEntityFunctionPrivilege> pFuncPrivilege = pFunc.ConvertCase<IEntityFunctionPrivilege>();
- //start entity
- ErrorCodeEnum errCode;
- vector<CSimpleStringA>::iterator vIt;
- if (m_operatingOpt.size() == 0)
- goto OPERATING_FINISH;
- char startMsg[128];
- for (vIt = m_vOperating.begin(); vIt != m_vOperating.end(); ++vIt)
- {
- CSmartPointer<IAsynWaitSp> spWait;
- it = m_operatingOpt.find(*vIt);
- if (it == m_operatingOpt.end())
- {
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("cannot find %s", (LPCSTR)* vIt);
- continue;
- }
- CEntityRunInfo entRunInfo;
- errCode = pFunc->GetEntityRunInfo(it->first, entRunInfo);
- if (errCode == Error_Succeed && entRunInfo.eState == EntityState_Idle)
- {
- it->second.eResult = LOADING_SUCCEED;
- ret = CheckLoadResult(LOADSTAGE_OPERATING);
- if (ret == 0 || ret == 2)
- goto OPERATING_FINISH;
- else
- continue;
- }
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("op start %s,%d", (LPCTSTR)it->first, it->second.loadOpt);
- switch (it->second.loadOpt)
- {
- case LOADOPT_IGNORE:
- {
- pFuncPrivilege->StartEntity(it->first, NULL, spWait);
- if (spWait != NULL)
- spWait->WaitAnswer(MAX_IGNORE_TIMEOUT);
- it->second.eResult = LOADING_SUCCEED;
- ret = CheckLoadResult(LOADSTAGE_OPERATING);
- if (ret == 0 || ret == 2)
- goto OPERATING_FINISH;
- }
- break;
- case LOADOPT_ASYNC_VERIFY:
- errCode = AsyncStartEntity(it->first, NULL, NULL);
- bAsync = true;
- break;
- case LOADOPT_SYNC_VERIFY:
- {
- ZeroMemory(startMsg, 128);
- sprintf(startMsg, "正在启动实体%s...", it->first.GetData());
- GetEntityBase()->GetFunction()->ShowStartupInfo(startMsg);
- ULONGLONG dwEntityStart = SP::Module::Comm::RVCGetTickCount();
- errCode = pFuncPrivilege->StartEntity(it->first, NULL, spWait);
- if (errCode == Error_Succeed)
- {
- if (spWait != NULL)
- errCode = spWait->WaitAnswer(MAX_AYSNC_TIMEOUT);
- }
- else
- {
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("StartEntity %s failed(%d).", (LPCSTR)it->first, errCode);
- break;
- }
- ULONGLONG dwEntityEnd = SP::Module::Comm::RVCGetTickCount();
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI("SyncStartEntity").setCostTime((dwEntityEnd - dwEntityStart) / 1000)("%d", errCode);
- if (errCode == Error_Succeed)
- it->second.eResult = LOADING_SUCCEED;
- else if (errCode == Error_TimeOut)
- it->second.eResult = LOADING_TIMEOUT;
- else
- it->second.eResult = LOADING_FAILED;
- if (it->second.eResult != Error_Succeed)
- {
- if (it->first.Compare("SIPPhone") == 0)
- m_bSIPPhoneStartFail = true;
- DbgWithLink(LOG_LEVEL_ERROR, LOG_TYPE_SYSTEM)("启动失败:%s", it->first.GetData());
- m_csErrEntity = m_csErrEntity + "|" + it->first;
- FSMEvent* e = new FSMEvent(USER_EVT_OPERATING_FINISHED);
- e->param1 = 2;//"SYNC START" enity started failed.
- PostEventFIFO(e);
- return;
- }
- if (errCode != Error_Succeed)
- return;
- else
- ret = CheckLoadResult(LOADSTAGE_OPERATING);
- if (ret == 0 || ret == 2)
- goto OPERATING_FINISH;
- }
- break;
- default:
- break;
- }
- }
- OPERATING_FINISH:
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("s3 ret %d", ret);
- if (!bAsync)
- {
- FSMEvent* e = new FSMEvent(USER_EVT_OPERATING_FINISHED);
- e->param1 = ret;
- PostEventFIFO(e);
- }
- else
- {
- ret = CheckLoadResult(LOADSTAGE_OPERATING);
- if (ret == 0 || ret == 2)
- {
- FSMEvent* e = new FSMEvent(USER_EVT_OPERATING_FINISHED);
- e->param1 = ret;
- PostEventFIFO(e);
- }
- }
- return;
- }
- void CVtmLoaderFSM::s3_on_exit()
- {
- LOG_FUNCTION();
- }
- unsigned int CVtmLoaderFSM::s3_on_event(FSMEvent* pEvt)
- {
- LOG_FUNCTION();
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("s3(Operating) event %d,%d", pEvt->iEvt, pEvt->param1);
- int ret = 0;
- switch (pEvt->iEvt)
- {
- case USER_EVT_OPERATING_FINISHED:
- ret = pEvt->param1;
- pEvt->SetHandled();
- break;
- default:
- break;
- }
- return ret;
- }
- //Idle(Operating finished)
- void CVtmLoaderFSM::s4_on_entry()
- {
- LOG_FUNCTION();
- std::map<std::string, std::string> msgInfo;
- msgInfo["NetCardCheckCost"] = CSimpleStringA::Format("%d", m_ullNetCardCost).GetData();
- msgInfo["NetworkDetectCost"] = CSimpleStringA::Format("%d", m_ullNetDetectCost).GetData();
- msgInfo["GetConfigCost"] = CSimpleStringA::Format("%d", m_ullGetConfigCost).GetData();
- msgInfo["EntityLoadCost"] = CSimpleStringA::Format("%d", (SP::Module::Comm::RVCGetTickCount() - m_ullEntityLoadStart) / 1000).GetData();
- std::pair<bool, std::string> strResult;
- strResult = generateJsonStr(msgInfo);
- LogWarn(Severity_Low, Error_Succeed, VtmLoader_InfoAboutBootCost, strResult.second.c_str());
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_USER).setLogCode("QLR040210F16")("%s", strResult.second.c_str());
- //oiltmp wait for analyse progress, then change to app log format
- LogWarn(Severity_Low, Error_Succeed, VtmLoader_NetCard_Cost, msgInfo["NetCardCheckCost"].c_str());
- LogWarn(Severity_Low, Error_Succeed, VtmLoader_NetworkDetect_Cost, msgInfo["NetworkDetectCost"].c_str());
- LogWarn(Severity_Low, Error_Succeed, VtmLoader_GetConfig_Cost, msgInfo["GetConfigCost"].c_str());
- LogWarn(Severity_Low, Error_Succeed, VtmLoader_EntityLoad_Cost, msgInfo["EntityLoadCost"].c_str());
- NoticeEntityLoadTask* pTask = new NoticeEntityLoadTask(this,Event_VtmLoader_EntityLoad_Finished);
- GetEntityBase()->GetFunction()->PostThreadPoolTask(pTask);
- }
- void CVtmLoaderFSM::s4_on_exit()
- {
- LOG_FUNCTION();
- }
- unsigned int CVtmLoaderFSM::s4_on_event(FSMEvent* pEvt)
- {
- LOG_FUNCTION();
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("s4 event %d,%d", pEvt->iEvt, pEvt->param1);
- switch (pEvt->iEvt)
- {
- case USER_EVT_CHECK_DEVICE_ENTITY:
- pEvt->SetHandled();
- {
- CheckDeviceEntityEvent* cdee = dynamic_cast<CheckDeviceEntityEvent*>(pEvt);
- CheckDeviceEntityTask* pTask = new CheckDeviceEntityTask(this);
- pTask->ctx = cdee->ctx;
- GetEntityBase()->GetFunction()->PostThreadPoolTask(pTask);
- }
- break;
- case USER_EVT_QUERY_LOCAL_INFO:
- pEvt->SetHandled();
- {
- QueryLocalInfoEvent* qlie = dynamic_cast<QueryLocalInfoEvent*>(pEvt);
- QueryLocalInfoTask* pTask = new QueryLocalInfoTask(this);
- pTask->ctx = qlie->ctx;
- GetEntityBase()->GetFunction()->PostThreadPoolTask(pTask);
- }
- break;
- default:
- break;
- }
- return 0;
- }
- //Fault
- void CVtmLoaderFSM::s5_on_entry()
- {
- LOG_FUNCTION();
- if (m_bSIPPhoneStartFail)
- {
- NoticeEntityLoadTask* pTask = new NoticeEntityLoadTask(this, Event_VtmLoader_SIPPhoneEntityLoad_Failed);
- GetEntityBase()->GetFunction()->PostThreadPoolTask(pTask);
- }
- else
- {
- NoticeEntityLoadTask* pTask = new NoticeEntityLoadTask(this, Event_VtmLoader_OtherSyncEntityLoad_Failed);
- GetEntityBase()->GetFunction()->PostThreadPoolTask(pTask);
- }
- }
- void CVtmLoaderFSM::s5_on_exit()
- {
- LOG_FUNCTION();
- }
- unsigned int CVtmLoaderFSM::s5_on_event(FSMEvent* pEvt)
- {
- LOG_FUNCTION();
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("s5(Fault) event %d,%d", pEvt->iEvt, pEvt->param1);
- switch (pEvt->iEvt)
- {
- case USER_EVT_CHECK_DEVICE_ENTITY:
- pEvt->SetHandled();
- {
- CheckDeviceEntityEvent* cdee = dynamic_cast<CheckDeviceEntityEvent*>(pEvt);
- CheckDeviceEntityTask* pTask = new CheckDeviceEntityTask(this);
- pTask->ctx = cdee->ctx;
- GetEntityBase()->GetFunction()->PostThreadPoolTask(pTask);
- }
- break;
- case USER_EVT_QUERY_LOCAL_INFO:
- pEvt->SetHandled();
- {
- QueryLocalInfoEvent* qlie = dynamic_cast<QueryLocalInfoEvent*>(pEvt);
- QueryLocalInfoTask* pTask = new QueryLocalInfoTask(this);
- pTask->ctx = qlie->ctx;
- GetEntityBase()->GetFunction()->PostThreadPoolTask(pTask);
- }
- break;
- default:
- break;
- }
- return 0;
- }
- BOOL CVtmLoaderFSM::DetectNetworkLegality(CSimpleStringA& strInfo)
- {
- BOOL result(TRUE);
- strInfo.Clear();
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("Detect network legality...");
- BOOL fLocalLANConnected(FALSE);
- unsigned int curTimes = 1;
- const unsigned int maxTimes = 3;
- do {
- CAutoArray<NetworkAdapterItem> netList;
- if (SP::Module::Net::GetINETMacAddresses(netList) == Error_Succeed)
- {
- for (int i = 0; i < netList.GetCount(); i++) {
- DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("interface(%d):%s", i, netList[i].description.c_str());
- DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("ip(%d):%s", i, netList[i].ip.c_str());
- DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("mac(%d):%s", i, netList[i].mac.c_str());
- DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("operStatus(%d):%d", i, netList[i].operStatus);
- DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("type(%d):%d", i, netList[i].type);
- //if (netList[i].type == IF_TYPE_ETHERNET_CSMACD && netList[i].operStatus == IfOperStatusUp)
- if (netList[i].operStatus == 1)//oiltest
- {
- fLocalLANConnected = TRUE;
- break;
- }
- }
- }
- Sleep(500);
- curTimes++;
- } while (curTimes < maxTimes && !fLocalLANConnected);
- if (!fLocalLANConnected) {
- strInfo = "未检查到有网卡连接,请检查网络连接";
- result = FALSE;
- }
- return result;
- }
- int CVtmLoaderFSM::NetWorkCheckAndGetSetting()
- {
- //检查网卡状态
- DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("to check network status");
- CSimpleStringA strMsg(true), tmpTS("X");
- //GetEntityBase()->GetFunction()->GetSysVar("TerminalStage", tmpTS);
- int netcheckCount = 1;
- ULLINT ullTmpStart = SP::Module::Comm::RVCGetTickCount();
- while (true)
- {
- if (!DetectNetworkLegality(strMsg)) {
- if (netcheckCount == 1)//oilyang@20250415 only the first time we log RTAxxxx
- DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_USER).setLogCode("QLR040210F10").setResultCode("RTA1F00")("can't find valid network interface");
- LogWarn(Severity_High, Error_Unexpect, VtmLoader_UserCode_NetCard_UnAvaible, CSimpleStringA::Format("%s。%d 秒后自动重试(第%d次重试)。请检查网线是否插好、网络是否正常"
- , strMsg.GetData(), m_iDetectInterval / 1000, netcheckCount).GetData());
- //if (tmpTS.Compare("E") != 0)
- //{
- // GetEntityBase()->GetFunction()->SetSysVar("TerminalStage", "E");
- // tmpTS = "E";
- //}
- Sleep(5000);
- netcheckCount++;
- }
- else
- {
- m_ullNetCardCost = (SP::Module::Comm::RVCGetTickCount() - ullTmpStart) / 1000;//second
- LogWarn(Severity_Low, Error_Succeed, VtmLoader_BootInfoPrint, "网卡状态正常");
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_USER).setLogCode("QLR040210F10")("network interface ok.");
- break;
- }
- }
- ullTmpStart = SP::Module::Comm::RVCGetTickCount();
- //检查网络连通性(网络连通性是否作为关键路径走配置,默认不是关键路径)
- if (!DetectHttpActive())
- {
- //网络连通性检查未通过,提示确认网络后重启应用?界面加一个重启按钮?
- LogWarn(Severity_High, Error_Unexpect, VtmLoader_BootInfoPrint, "网络连通性检查失败,请检查网络");
- return -1;
- }
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_USER).setLogCode("QLR040210F11")("connect to http(s) service ok.");
- m_ullNetDetectCost = (SP::Module::Comm::RVCGetTickCount() - ullTmpStart) / 1000;//second
- ToCheckIfInstalling();
- ullTmpStart = SP::Module::Comm::RVCGetTickCount();
- //拉取配置并通知提前启动的实体(Chromium)
- //重试5次,失败则放弃
- int getRetry = 0;
- while(true)
- {
- if (GetConfig())
- break;
- else
- {
- if (getRetry >= 5)
- return -2;
- getRetry++;
- Sleep(5000 * getRetry);
- }
- }
- m_ullGetConfigCost = (SP::Module::Comm::RVCGetTickCount() - ullTmpStart) / 1000;//second
- //加载实体列表
- CSimpleStringA csTmpRootIni("");
- if (!IsRootINIExist(csTmpRootIni))
- {
- DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_USER)(CSimpleStringA::Format("root.ini不存在(%s),Set TerminalStage N ", csTmpRootIni.GetData()).GetData());
- GetEntityBase()->GetFunction()->SetSysVar("TerminalStage", "N");
- }
- //oilyang@20241017 to check if have copied dep directory
- int copyTries = 0;
- while (true)
- {
- if (m_eDepCopyStage == DepDirInitCopy_NoNeed || m_eDepCopyStage == DepDirInitCopy_CopySuc)
- {
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("no need or have done dep copy, DepCopyStage:%d", m_eDepCopyStage);
- break;
- }
- else if (m_eDepCopyStage == DepDirInitCopy_Copying)
- {
- Sleep(1000);
- continue;
- }
- else
- {
- LogWarn(Severity_High, Error_Unexpect, VtmLoader_DepDirCopyFailed, "厂商适配器Dep文件拷贝失败,请联系分行IT排查是否安全软件干扰文件拷贝");
- Sleep(60000);
- copyTries++;
- if (copyTries > 4)
- {
- DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM)("have tried %d times, give up", copyTries);
- return -1;
- }
- m_eDepCopyStage = DepDirInitCopy_Copying;
- CopyDepFilesToNewDepPathTask* pCopyTask = new CopyDepFilesToNewDepPathTask(this);
- GetEntityBase()->GetFunction()->PostThreadPoolTask(pCopyTask);
- }
- }
- return EntityLoad();
- }
- int CVtmLoaderFSM::EntityLoad()
- {
- //前提:收到了配置拉取完成的指令,才会进入到这里
- //为了测试,假装已经拿到了集中配置
- m_ullEntityLoadStart = SP::Module::Comm::RVCGetTickCount();
-
- CSmartPointer<IConfigInfo> spConfigCen,spRunCfg;
- GetEntityBase()->GetFunction()->OpenConfig(Config_CenterSetting, spConfigCen);
- GetEntityBase()->GetFunction()->OpenConfig(Config_Run, spRunCfg);
- CSimpleStringA csCoreBootList(true), csSafeLoadList(true), csOperatingList(true), csKeyCB("CoreBootList."), csKeySL("SafeLoadList."), csKeyOp("OperatingList."), csExcludedLoadList(true);
- spConfigCen->ReadConfigValue(GetEntityBase()->GetEntityName(), (csKeyCB + m_sysInfo.strMachineType).GetData(), csCoreBootList);
- spConfigCen->ReadConfigValue(GetEntityBase()->GetEntityName(), (csKeySL + m_sysInfo.strMachineType).GetData(), csSafeLoadList);
- spConfigCen->ReadConfigValue(GetEntityBase()->GetEntityName(), (csKeyOp + m_sysInfo.strMachineType).GetData(), csOperatingList);
- spConfigCen->ReadConfigValue(GetEntityBase()->GetEntityName(), "ExcludedLoadList", csExcludedLoadList);
- DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("CoreBoot.EntityList.%s:%s", m_sysInfo.strMachineType.GetData(), csCoreBootList.GetData());
- DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("SafeLoad.EntityList.%s:%s", m_sysInfo.strMachineType.GetData(), csSafeLoadList.GetData());
- DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("Operating.EntityList.%s:%s", m_sysInfo.strMachineType.GetData(), csOperatingList.GetData());
- //oiltmp 如果没有配置,则走默认配置
- if (csCoreBootList.IsNullOrEmpty() || csCoreBootList.IndexOf("HealthManager") < 0 || csCoreBootList.IndexOf("AccessAuthorization") < 0
- || csCoreBootList.IndexOf("UpgradeManager") < 0 || csCoreBootList.IndexOf("HeartBeat") < 0
- || csCoreBootList.IndexOf("TokenKeeper") < 0 || csCoreBootList.IndexOf("ResourceWatcher") < 0
- || csCoreBootList.IndexOf("EventConverter") < 0 || csCoreBootList.IndexOf("Alarm") < 0)
- {
- if (csCoreBootList.IsNullOrEmpty())
- {
- LogWarn(Severity_High, Error_Unexpect, VtmLoader_CoreBootCfg_Err, CSimpleStringA::Format("terminalNo[%s] CoreBoot配置为空,请联系总行开发人员检查", m_sysInfo.strTerminalID.GetData()).GetData());
- DbgWithLink(LOG_LEVEL_ERROR, LOG_TYPE_SYSTEM).setLogCode("QLR040210F14").setResultCode("RTA1F05")("terminalNo[%s] CoreBoot配置为空,请联系总行开发人员检查", m_sysInfo.strTerminalID.GetData());
- }
- else
- {
- LogWarn(Severity_High, Error_Unexpect, VtmLoader_CoreBootCfg_Err, CSimpleStringA::Format("terminalNo[%s] CoreBoot配置异常,请联系总行开发人员检查(%s)", m_sysInfo.strTerminalID.GetData(), csCoreBootList.GetData()).GetData());
- DbgWithLink(LOG_LEVEL_ERROR, LOG_TYPE_SYSTEM).setLogCode("QLR040210F14").setResultCode("RTA1F05")(CSimpleStringA::Format("terminalNo[%s] CoreBoot配置异常,请联系总行开发人员检查(%s)",m_sysInfo.strTerminalID.GetData(), csCoreBootList.GetData()));
- }
- }
- spConfigCen->ReadConfigValueInt(GetEntityBase()->GetEntityName(), "SleepEnterOpMS", m_sleepEnterOpMS);
- if (m_sleepEnterOpMS <= 0 || m_sleepEnterOpMS > 20000)
- m_sleepEnterOpMS = 1000;//default
- //save centersetting to runcfg for vtmloader. using it before download centersetting
- int iTmp = 0;
- if (spConfigCen->ReadConfigValueInt("Common", "CanIgnoreAddrDetect", iTmp) == Error_Succeed && iTmp > 0)
- spRunCfg->WriteConfigValueInt("Common", "CanIgnoreAddrDetect", iTmp);
- iTmp = 0;
- if (spConfigCen->ReadConfigValueInt("Common", "MaxAddrDetectTimes", iTmp) == Error_Succeed && iTmp > 0)
- spRunCfg->WriteConfigValueInt("Common", "MaxAddrDetectTimes", iTmp);
- iTmp = 0;
- if (spConfigCen->ReadConfigValueInt("Common", "AddrDetectInterval", iTmp) == Error_Succeed && iTmp > 0)
- spRunCfg->WriteConfigValueInt("Common", "AddrDetectInterval", iTmp);
- CSimpleStringA csTmpAddr(true);
- if (spConfigCen->ReadConfigValue("Common", "SettingDetectAddr", csTmpAddr) == Error_Succeed && !csTmpAddr.IsNullOrEmpty())
- spRunCfg->WriteConfigValue("Common", "SettingDetectAddr", csTmpAddr.GetData());
- csTmpAddr = "";
- if (spConfigCen->ReadConfigValue("Common", "AccessAuthDetectAddr", csTmpAddr) == Error_Succeed && !csTmpAddr.IsNullOrEmpty())
- spRunCfg->WriteConfigValue("Common", "AccessAuthDetectAddr", csTmpAddr.GetData());
- iTmp = 0;
- if (spConfigCen->ReadConfigValueInt(GetEntityBase()->GetEntityName(), "NoCheckMachineModel", iTmp) == Error_Succeed && iTmp == 1)
- m_iNoCheckMachineModel = 1;
- //oilyang@20240407 add check machine model in ST/UAT test room
- if (!CheckConfigInfoInTestRoom())
- return -1;
- CSystemRunInfo sysRunInfo;
- if (GetEntityBase()->GetFunction()->GetSystemRunInfo(sysRunInfo) != Error_Succeed || sysRunInfo.eAppBootState == AppBootState_Init)
- GetEntityBase()->GetFunction()->GetPrivilegeFunction()->RefreshAppBootState(AppBootState_StartEntity);
- else
- DbgWithLink(LOG_LEVEL_ERROR, LOG_TYPE_SYSTEM)("GetSystemRunInfo failed:%d");
- //oilyang@20250715 before load entitys, to set sysvar "AuthErrMsg" to ""
- //oiltmp@20250715 several months later,we can delete this
- ErrorCodeEnum eErrCode = Error_Unexpect;
- if ((eErrCode = GetEntityBase()->GetFunction()->SetSysVar("AuthErrMsg", "",true)) != Error_Succeed)
- DbgWithLink(LOG_LEVEL_ERROR, LOG_TYPE_SYSTEM).setResultCode(RTAERR_SYSVAR_SET_FAILED)("Set sysvar \"AuthErrMsg\" failed:%d", eErrCode);
- LogWarn(Severity_Low, Error_Succeed, VtmLoader_BootInfoPrint, "开始加载实体");
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI("StartLoadEntity")("开始加载实体");
- m_arrExCludedList.Init(64);
- m_arrExCludedList = csExcludedLoadList.Split('|');
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("ExcludedLoadList:%s, count:%d", csExcludedLoadList.GetData(), m_arrExCludedList.GetCount());
- m_csEntityList = "GuiConsole|Chromium|VtmLoader|";
- CAutoArray<CSimpleStringA> arrCoreBoot;
- arrCoreBoot.Init(64);
- arrCoreBoot = csCoreBootList.Split('|');
- DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("arrCoreBoot count:%d", arrCoreBoot.GetCount());
- for (int i = 0; i < arrCoreBoot.GetCount(); ++i)
- {
- CAutoArray<CSimpleStringA> arrEntity;
- arrEntity.Init(2);
- arrEntity = arrCoreBoot[i].Split('=');
- if (arrEntity.GetCount() < 2)
- break;
- if (arrEntity[0].Compare("VtmLoader", true) == 0 || arrEntity[0].Compare("Chromium", true) == 0
- || arrEntity[0].Compare("GuiConsole", true) == 0)
- continue;
- //Exclude the "ExcludedLoadList" entity
- if (IfInExcludedLoadList(arrEntity[0]))
- continue;
- m_vCoreBoot.push_back(arrEntity[0]);
- m_csEntityList += arrEntity[0] + "|";
- if (arrEntity[1].Compare("1") == 0)
- m_coreBootOpt[arrEntity[0]].loadOpt = LOADOPT_ASYNC_VERIFY;
- else if (arrEntity[1].Compare("2") == 0)
- m_coreBootOpt[arrEntity[0]].loadOpt = LOADOPT_SYNC_VERIFY;
- else
- m_coreBootOpt[arrEntity[0]].loadOpt = LOADOPT_IGNORE;
- m_coreBootOpt[arrEntity[0].GetData()].eResult = LOADING_INIT;
- //m_entityBootOpt[arrEntity[0].GetData()].initSn = cbNum;
- //cbNum++;
- }
- CAutoArray<CSimpleStringA> arrSafeLoad;
- arrSafeLoad.Init(64);
- arrSafeLoad = csSafeLoadList.Split('|');
- for (int i = 0; i < arrSafeLoad.GetCount(); ++i)
- {
- CAutoArray<CSimpleStringA> arrEntity;
- arrEntity.Init(2);
- arrEntity = arrSafeLoad[i].Split('=');
- if (arrEntity.GetCount() < 2)
- break;
- if (arrEntity[0].Compare("VtmLoader", true) == 0 || arrEntity[0].Compare("Chromium", true) == 0
- || arrEntity[0].Compare("GuiConsole", true) == 0)
- continue;
- //Exclude the "ExcludedLoadList" entity
- if (IfInExcludedLoadList(arrEntity[0]))
- continue;
- //去重,防止前面已经加载了
- if (find(m_vCoreBoot.begin(), m_vCoreBoot.end(), arrEntity[0].GetData()) != m_vCoreBoot.end())
- continue;
- m_vSafeLoad.push_back(arrEntity[0].GetData());
- m_csEntityList += arrEntity[0] + "|";
- if (arrEntity[1].Compare("1") == 0)
- m_safeLoadOpt[arrEntity[0]].loadOpt = LOADOPT_ASYNC_VERIFY;
- else if (arrEntity[1].Compare("2") == 0)
- m_safeLoadOpt[arrEntity[0]].loadOpt = LOADOPT_SYNC_VERIFY;
- else
- m_safeLoadOpt[arrEntity[0]].loadOpt = LOADOPT_IGNORE;
- m_safeLoadOpt[arrEntity[0].GetData()].eResult = LOADING_INIT;
- //m_safeLoadOpt[arrEntity[0].GetData()].initSn = slNum;
- //slNum++;
- }
- CAutoArray<CSimpleStringA> arrOperating;
- arrOperating.Init(64);
- arrOperating = csOperatingList.Split('|');
- for (int i = 0; i < arrOperating.GetCount(); ++i)
- {
- CAutoArray<CSimpleStringA> arrEntity;
- arrEntity.Init(2);
- arrEntity = arrOperating[i].Split('=');
- if (arrEntity.GetCount() < 2)
- break;
- if (arrEntity[0].Compare("VtmLoader", true) == 0 || arrEntity[0].Compare("Chromium", true) == 0
- || arrEntity[0].Compare("GuiConsole", true) == 0)
- continue;
- //Exclude the "ExcludedLoadList" entity
- if (IfInExcludedLoadList(arrEntity[0]))
- continue;
- //去重,防止前面已经加载了
- if (find(m_vCoreBoot.begin(), m_vCoreBoot.end(), arrEntity[0].GetData()) != m_vCoreBoot.end()
- || find(m_vSafeLoad.begin(), m_vSafeLoad.end(), arrEntity[0].GetData()) != m_vSafeLoad.end())
- continue;
- m_vOperating.push_back(arrEntity[0].GetData());
- m_csEntityList += arrEntity[0] + "|";
- if (arrEntity[1].Compare("1") == 0)
- m_operatingOpt[arrEntity[0]].loadOpt = LOADOPT_ASYNC_VERIFY;
- else if (arrEntity[1].Compare("2") == 0)
- m_operatingOpt[arrEntity[0]].loadOpt = LOADOPT_SYNC_VERIFY;
- else
- m_operatingOpt[arrEntity[0]].loadOpt = LOADOPT_IGNORE;
- m_operatingOpt[arrEntity[0].GetData()].eResult = LOADING_INIT;
- //m_operatingOpt[arrEntity[0].GetData()].initSn = opNum;
- //opNum++;
- }
- //oilyang if install VTM ,just wait for msg to start entity
- CSimpleStringA csTermStage("");
- if ((eErrCode = GetEntityBase()->GetFunction()->GetSysVar("TerminalStage", csTermStage)) != Error_Succeed)
- DbgWithLink(LOG_LEVEL_ERROR, LOG_TYPE_SYSTEM).setResultCode(RTAERR_SYSVAR_GET_FAILED)("Get sysvar \"TerminalStage\" failed:%d", eErrCode);
- else
- DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("TerminalStage %s.", csTermStage.GetData());
- if (csTermStage.Compare("N") == 0)//"N" for installing
- {
- //start UpgradeManager
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("to start entity UpgradeManager");
- CSmartPointer<IEntityFunctionPrivilege> pFuncPrivilege = m_pEntity->GetFunction().ConvertCase<IEntityFunctionPrivilege>();
- CSmartPointer<IAsynWaitSp> spWait;
- eErrCode = pFuncPrivilege->StartEntity("UpgradeManager", NULL, spWait);
- if (eErrCode == Error_Succeed)
- {
- if (spWait != NULL)
- eErrCode = spWait->WaitAnswer(MAX_AYSNC_TIMEOUT);
- }
- else
- {
- DbgWithLink(LOG_LEVEL_ERROR, LOG_TYPE_SYSTEM)("StartEntity UpgradeManager failed(%d).", eErrCode);
- return -1;
- }
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("to start entity HealthManager");
- eErrCode = pFuncPrivilege->StartEntity("HealthManager", NULL, spWait);
- if (eErrCode == Error_Succeed)
- {
- if (spWait != NULL)
- eErrCode = spWait->WaitAnswer(MAX_AYSNC_TIMEOUT);
- }
- else
- {
- DbgWithLink(LOG_LEVEL_ERROR, LOG_TYPE_SYSTEM)("StartEntity HealthManager failed(%d).", eErrCode);
- return -1;
- }
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("to start entity InteractiveControl");
- eErrCode = pFuncPrivilege->StartEntity("InteractiveControl", NULL, spWait);
- if (eErrCode == Error_Succeed)
- {
- if (spWait != NULL)
- eErrCode = spWait->WaitAnswer(MAX_AYSNC_TIMEOUT);
- }
- else
- {
- DbgWithLink(LOG_LEVEL_ERROR, LOG_TYPE_SYSTEM)("StartEntity InteractiveControl failed(%d).", eErrCode);
- return -1;
- }
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("to start entity MediaController");
- eErrCode = pFuncPrivilege->StartEntity("MediaController", NULL, spWait);
- if (eErrCode == Error_Succeed)
- {
- if (spWait != NULL)
- eErrCode = spWait->WaitAnswer(MAX_AYSNC_TIMEOUT);
- }
- else
- {
- DbgWithLink(LOG_LEVEL_ERROR, LOG_TYPE_SYSTEM)("StartEntity MediaController failed(%d).", eErrCode);
- return -1;
- }
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("to start entity AccessAuthorization");
- eErrCode = pFuncPrivilege->StartEntity("AccessAuthorization", NULL, spWait);
- if (eErrCode == Error_Succeed)
- {
- if (spWait != NULL)
- eErrCode = spWait->WaitAnswer(MAX_AYSNC_TIMEOUT);
- }
- else
- {
- DbgWithLink(LOG_LEVEL_ERROR, LOG_TYPE_SYSTEM)("StartEntity AccessAuthorization failed(%d).", eErrCode);
- return -1;
- }
- //wait for all the things have beed done,then save TerminalNo to root.ini
- while (true)
- {
- m_hSaveTerminalNoVar.Wait();
- return 1;
- }
- }
- return 0;
- }
- int CVtmLoaderFSM::CheckLoadResult(LoadStage eStage)
- {
- int ret = 0;
- CSimpleStringA csLogCode = "QLR040210F14";
- map<CSimpleStringA, EntityLoadInfo>::iterator it;
- if (eStage == LOADSTAGE_COREBOOT)
- it = m_coreBootOpt.begin();
- else if (eStage == LOADSTAGE_SAFELOAD)
- {
- it = m_safeLoadOpt.begin();
- csLogCode = "QLR040210F15";
- }
- else
- {
- it = m_operatingOpt.begin();
- csLogCode = "QLR040210F16";
- }
- while (1)
- {
- switch (it->second.loadOpt)
- {
- case LOADOPT_IGNORE:
- if (it->second.eResult == LOADING_INIT)
- return 1;
- break;
- case LOADOPT_ASYNC_VERIFY:
- case LOADOPT_SYNC_VERIFY:
- default:
- if (it->second.eResult == LOADING_INIT)
- return 3;
- else if (it->second.eResult != LOADING_SUCCEED)
- {
- DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_USER).setLogCode(csLogCode).setResultCode("RTA1F04")("%s start failed", m_csErrEntity);
- LogWarn(Severity_High, Error_Unexpect, VtmLoader_EntityLoad_Failed, CSimpleStringA::Format("实体%s加载失败,启动终止。请排查启动失败实体或重启应用", m_csErrEntity.GetData()));
- m_csErrEntity = m_csErrEntity + "|" + it->first;
- ret = 2;
- if (it->first.Compare("SIPPhone") == 0)
- m_bSIPPhoneStartFail = true;
- }
- break;
- }
- it++;
- if (eStage == LOADSTAGE_COREBOOT && it == m_coreBootOpt.end())
- break;
- else if (eStage == LOADSTAGE_SAFELOAD && it == m_safeLoadOpt.end())
- break;
- else if (eStage == LOADSTAGE_OPERATING && it == m_operatingOpt.end())
- break;
- }
- return ret;
- }
- ErrorCodeEnum CVtmLoaderFSM::AsyncStartEntity(const char* entity_name, const char* cmdline, void* pData)
- {
- CSmartPointer<IEntityFunction> pFunc = m_pEntity->GetFunction();
- ErrorCodeEnum errCode;
- CSmartPointer<IEntityFunctionPrivilege> pFuncPrivilege = pFunc.ConvertCase<IEntityFunctionPrivilege>();
- if (pFuncPrivilege != NULL) {
- CSmartPointer<IAsynWaitSp> spWait;
- errCode = pFuncPrivilege->StartEntity(entity_name, cmdline, spWait);
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI("AsyncStartEntity")("start entity %s", entity_name);
- if (errCode == Error_Succeed) {
- callback_entry* entry = new callback_entry();
- entry->pRawData = pData;
- entry->EntityName = entity_name;
- entry->ErrorResult = Error_Unexpect;
- entry->op = OP_START_ENTITY;
- if (spWait != NULL)
- spWait->SetCallback(this, entry);
- }
- return errCode;
- }
- else {
- return Error_NoPrivilege;
- }
- }
- void CVtmLoaderFSM::OnAnswer(CSmartPointer<IAsynWaitSp> pAsynWaitSp)
- {
- CSmartPointer<ICallbackListener> spCallback;
- CSmartPointer<IReleasable> pData;
- pAsynWaitSp->GetCallback(spCallback, pData);
- callback_entry* entry = dynamic_cast<callback_entry*>((IReleasable*)(pData.GetRawPointer()));
- entry->ErrorResult = pAsynWaitSp->AsyncGetAnswer();
- callback_entry* new_entry = new callback_entry();
- new_entry->EntityName = entry->EntityName;
- new_entry->ErrorResult = entry->ErrorResult;
- new_entry->op = entry->op;
- new_entry->state = entry->state;
- map<CSimpleStringA, EntityLoadInfo>::iterator it;
- int ret;
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI("OnAnswer")("stage %d,%s,result %d", m_eStage, (LPCSTR)new_entry->EntityName, new_entry->ErrorResult);
- switch (m_eStage)
- {
- case LOADSTAGE_COREBOOT:
- it = m_coreBootOpt.find(new_entry->EntityName);
- if (it != m_coreBootOpt.end())
- {
- if (new_entry->ErrorResult == Error_Succeed)
- it->second.eResult = LOADING_SUCCEED;
- else if (new_entry->ErrorResult == Error_TimeOut)
- it->second.eResult = LOADING_TIMEOUT;
- else
- it->second.eResult = LOADING_FAILED;
- if (it->second.eResult != Error_Succeed)
- {
- char tmp[64] = { 0 };
- sprintf(tmp, "实体 %s 启动失败-----", it->first.GetData());
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI("OnAnswer")("启动失败:%s -----", tmp);
- }
- ret = CheckLoadResult(LOADSTAGE_COREBOOT);
- if (ret == 0 || ret == 2)
- {
- FSMEvent* e = new FSMEvent(USER_EVT_COREBOOT_FINISHED);
- e->param1 = ret;
- PostEventFIFO(e);
- }
- }
- break;
- case LOADSTAGE_SAFELOAD:
- it = m_safeLoadOpt.find(new_entry->EntityName);
- if (it != m_safeLoadOpt.end())
- {
- if (new_entry->ErrorResult == Error_Succeed)
- it->second.eResult = LOADING_SUCCEED;
- else if (new_entry->ErrorResult == Error_TimeOut)
- it->second.eResult = LOADING_TIMEOUT;
- else
- it->second.eResult = LOADING_FAILED;
- ret = CheckLoadResult(LOADSTAGE_SAFELOAD);
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI("OnAnswer")("safeload answer %d", ret);
- if (ret == 0 || ret == 2)
- {
- FSMEvent* e = new FSMEvent(USER_EVT_SAFELOAD_FINISHED);
- e->param1 = ret;
- PostEventFIFO(e);
- }
- }
- else {
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI("OnAnswer")("cannot find %s", (LPCTSTR)new_entry->EntityName);
- }
- break;
- case LOADSTAGE_OPERATING:
- it = m_operatingOpt.find(new_entry->EntityName);
- if (it != m_operatingOpt.end())
- {
- if (new_entry->ErrorResult == Error_Succeed)
- it->second.eResult = LOADING_SUCCEED;
- else if (new_entry->ErrorResult == Error_TimeOut)
- it->second.eResult = LOADING_TIMEOUT;
- else
- it->second.eResult = LOADING_FAILED;
- ret = CheckLoadResult(LOADSTAGE_OPERATING);
- if (ret == 0 || ret == 2)
- {
- FSMEvent* e = new FSMEvent(USER_EVT_OPERATING_FINISHED);
- e->param1 = ret;
- PostEventFIFO(e);
- }
- }
- break;
- default:
- break;
- }
- }
- DWORD GetDualTime(SYSTEMTIME& t1, SYSTEMTIME& t2)
- {
- //assume t2 > t1...
- //oiltest for simple
- int s1, s2;
- s1 = (t1.wMinute * 60 + t1.wSecond) * 1000 + t1.wMilliseconds;
- s2 = (t2.wMinute * 60 + t2.wSecond) * 1000 + t2.wMilliseconds;
- return s2 - s1;
- }
- void CVtmLoaderFSM::NoticeEntityLoad(int evtCode)
- {
- //oilyang@20240520 in case of healthmanager started failed, we should to restart healthmanager first
- CSimpleStringA csEntityName("HealthManager");
- CSmartPointer<IEntityFunction> spEntityFunction = GetEntityBase()->GetFunction();
- CSmartPointer<IAsynWaitSp> spWait;
- CSmartPointer<IEntityFunctionPrivilege> pFuncPrivilege = spEntityFunction.ConvertCase<IEntityFunctionPrivilege>();
- CEntityRunInfo acInfo;
- ErrorCodeEnum eErrCode = spEntityFunction->GetEntityRunInfo(csEntityName.GetData(), acInfo);
- if (eErrCode == Error_Succeed && acInfo.eState == EntityState_NoStart)
- {
- eErrCode = pFuncPrivilege->StartEntity(csEntityName, NULL, spWait);
- if (eErrCode == Error_Succeed)
- {
- if (spWait != NULL)
- eErrCode = spWait->WaitAnswer(MAX_AYSNC_TIMEOUT);
- }
- else
- DbgWithLink(LOG_LEVEL_ERROR, LOG_TYPE_SYSTEM)("StartEntity HealthManager failed(%d).", eErrCode);
- }
- else if (eErrCode == Error_Succeed && acInfo.eState != EntityState_Idle)
- {
- eErrCode = pFuncPrivilege->TerminateEntity(csEntityName.GetData(), spWait);
- if (eErrCode == Error_Succeed)
- {
- if (spWait != NULL)
- eErrCode = spWait->WaitAnswer(MAX_AYSNC_TIMEOUT);
- }
- else
- DbgWithLink(LOG_LEVEL_ERROR, LOG_TYPE_SYSTEM)("TerminateEntity HealthManager failed(%d).", eErrCode);
- Sleep(5000);
- //(re)start entity
- eErrCode = pFuncPrivilege->StartEntity(csEntityName.GetData(), NULL, spWait);
- if (eErrCode == Error_Succeed)
- {
- if (spWait != NULL)
- eErrCode = spWait->WaitAnswer(MAX_AYSNC_TIMEOUT);
- }
- else
- DbgWithLink(LOG_LEVEL_ERROR, LOG_TYPE_SYSTEM)("StartEntity HealthManager failed(%d).", eErrCode);
- }
- HealthManagerService_ClientBase* pHMClient = new HealthManagerService_ClientBase(m_pEntity);
- int count = 0;
- bool bConnected = false;
- do
- {
- ErrorCodeEnum eErrConn = Error_Unexpect;
- ErrorCodeEnum eErrCall = Error_Unexpect;
- if (!bConnected)
- {
- eErrConn = pHMClient->Connect();
- if (eErrConn == Error_Succeed)
- bConnected = true;
- }
-
- if (bConnected)
- {
- HealthManagerService_DoEvent_Req req;
- HealthManagerService_DoEvent_Ans ans;
- req.code = evtCode;
- req.entityList = m_csEntityList;
- eErrCall = pHMClient->DoEvent(req, ans, 5000);
- if (eErrCall == Error_Succeed)
- {
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("Notice HealthManager suc");
- break;
- }
- }
- DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM)("Notice HealthManager failed,eErrConn:%d,eErrCall:%d", eErrConn, eErrCall);
- Sleep(2000);
- count++;
- } while (count < 100);
- //oilyang@20240517 to calculate cost time of entity start after notice healthmanager 4 minutes later (a time that set experientially)
- ULLINT ullStart = SP::Module::Comm::RVCGetTickCount();
- ULLINT ullEnd = SP::Module::Comm::RVCGetTickCount();
- while (1)
- {
- Sleep(60000);
- ullEnd = SP::Module::Comm::RVCGetTickCount();
- if (ullEnd - ullStart > 4 * 60000 - 5000)//leave 5 second for system call?
- break;
- }
- CAutoArray<CSimpleStringA> strEntityNames;
- CAutoArray<int> strEntityIdx;
- CAutoArray<CEntityStartInfo> Infos;
- ErrorCodeEnum eErr = GetEntityBase()->GetFunction()->GetAllEntityStartInfo(strEntityNames, strEntityIdx, Infos);
- for (int i = 0; i < Infos.GetCount(); ++i)
- {
- if (m_csEntityList.IndexOf(strEntityNames[i]) != -1)
- {
- //LogWarn(Severity_Low, Error_Debug, LOG_TRACE_ENTITY_START_TIME,
- // SP::Module::Util::generateConsumeTimeJson(strEntityNames[i], SP::Module::Util::formatTime(Infos[i].startTime).c_str(), GetDualTime(Infos[i].startTime, Infos[i].startEndTime)).GetData());
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI("EntityStartCost")
- (SP::Module::Util::generateConsumeTimeJson(strEntityNames[i], SP::Module::Util::formatTime(Infos[i].startTime).c_str(), GetDualTime(Infos[i].startTime, Infos[i].startEndTime)).GetData());
- }
- }
- }
- bool CVtmLoaderFSM::DetectHttpActive()
- {
- memset(m_httpCheckResult, 0, sizeof(m_httpCheckResult));
- CSmartPointer<IConfigInfo> pConfigRun;
- CSimpleStringA strSettingAddr(true),strAccessAuthAddr(true);
- CSimpleStringA errMsg;
-
- ErrorCodeEnum eErr = GetEntityBase()->GetFunction()->OpenConfig(Config_Run, pConfigRun);
- if (eErr == Error_Succeed)
- {
- int iTmp = 0;
- if (pConfigRun->ReadConfigValueInt("Common", "CanIgnoreAddrDetect", iTmp) == Error_Succeed && iTmp > 0)
- m_iCanIgnoreAddrDetect = iTmp;
- iTmp = 0;
- if (pConfigRun->ReadConfigValueInt("Common", "MaxAddrDetectTime", iTmp) == Error_Succeed && iTmp > 0)
- m_ullMaxAddrDetectTime = iTmp;
- iTmp = 0;
- if (pConfigRun->ReadConfigValueInt("Common", "AddrDetectInterval", iTmp) == Error_Succeed && iTmp > 0)
- m_iDetectInterval = iTmp;
- }
- DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("eErr:%d, iDetectInterval:%d", eErr, m_iDetectInterval);
- CSimpleStringA csTmpAddr(true);
- //集中配置探测地址
- pConfigRun->ReadConfigValue("Common", "SettingDetectAddr", csTmpAddr);
- if (csTmpAddr.IsNullOrEmpty())
- {
- #ifdef DEVOPS_ON_ST /*DevOps流水线编译,ST环境*/
- strSettingAddr = "https://accessproxy-service.paasst.cmbchina.cn/centerconfig/rvc/detect";
- #elif defined(DEVOPS_ON_PRD)/*DevOps流水线编译,PRD环境*/
- strSettingAddr = "https://accessproxy-service.paas.cmbchina.cn/centerconfig/rvc/detect";
- #elif defined(DEVOPS_ON_UAT)/*DevOps流水线编译,UAT环境*/
- strSettingAddr = "https://accessproxy-service.paasuat.cmbchina.cn/centerconfig/rvc/detect";
- #elif defined(DEVOPS_ON_DEV)/*DevOps流水线编译,Dev环境*/
- strSettingAddr = "https://accessproxy-service.paas.cmbchina.cn/centerconfig/rvc/detect";
- #else/*本地编译等非DevOps环境编译的版本*/
- strSettingAddr = "https://accessproxy-service.paasst.cmbchina.cn/centerconfig/rvc/detect";
- #endif
- }
- else
- strSettingAddr = csTmpAddr;
- csTmpAddr = "";
- pConfigRun->ReadConfigValue("Common", "AccessAuthDetectAddr", strAccessAuthAddr);
- //准入探测地址
- if (strAccessAuthAddr.IsNullOrEmpty())
- {
- #ifdef DEVOPS_ON_ST /*DevOps流水线编译,ST环境*/
- strAccessAuthAddr = "https://terminalaccess.paasst.cmbchina.cn/tsas/detect";
- #elif defined(DEVOPS_ON_PRD)/*DevOps流水线编译,PRD环境*/
- strAccessAuthAddr = "https://accessproxy-service.paas.cmbchina.cn/tsaccess/tsas/detect";
- #elif defined(DEVOPS_ON_UAT)/*DevOps流水线编译,UAT环境*/
- strAccessAuthAddr = "https://terminalaccess.paasuat.cmbchina.cn/tsas/detect";
- #elif defined(DEVOPS_ON_DEV)/*DevOps流水线编译,Dev环境*/
- strAccessAuthAddr = "https://terminalaccess.paas.cmbchina.cn/tsas/detect";
- #else/*本地编译等非DevOps环境编译的版本*/
- strAccessAuthAddr = "https://terminalaccess.paasst.cmbchina.cn/tsas/detect";
- #endif
- }
- else
- strAccessAuthAddr = csTmpAddr;
- DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("CenterSetting addr:%s, strAccessAuthAddr:%s", strSettingAddr.GetData(), strAccessAuthAddr.GetData());
- HttpConnCheckTask* pCSTask = new HttpConnCheckTask(this, strSettingAddr, HttpAddr_CenterSetting);
- GetEntityBase()->GetFunction()->PostThreadPoolTask(pCSTask);
- HttpConnCheckTask* pAATask = new HttpConnCheckTask(this, strAccessAuthAddr, HttpAddr_AccessAuth);
- GetEntityBase()->GetFunction()->PostThreadPoolTask(pAATask);
- ULLINT beginTick, endTick;
- beginTick = SP::Module::Comm::RVCGetTickCount();
- do {
- Sleep(2000);
- if (m_httpCheckResult[HttpAddr_CenterSetting] == HttpConnResult_OK || m_httpCheckResult[HttpAddr_AccessAuth] == HttpConnResult_OK)
- return true;
- else
- {
- endTick = SP::Module::Comm::RVCGetTickCount();
- }
- } while (endTick - beginTick < m_ullMaxAddrDetectTime);
- if (m_iCanIgnoreAddrDetect > 0)
- return true;
- else
- return false;
- }
- bool CVtmLoaderFSM::IsRootINIExist(CSimpleStringA& path)
- {
- CSimpleStringA csHardwareCfg(true);
- ErrorCodeEnum eErr = GetEntityBase()->GetFunction()->GetPath("HardwareCfg", csHardwareCfg);
- if (eErr != Error_Succeed)
- {
- path = CSimpleStringA::Format("GetPath of HardwareCfg failed(%d)", eErr);
- DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM)("get path of Run failed:%s", SpStrError(eErr));
- return false;
- }
- path = csHardwareCfg + SPLIT_SLASH_STR + "root.ini";
- #if defined(RVC_OS_WIN)
- if (_access(path.GetData(), 0) == 0) {
- #else
- if (access(path.GetData(), F_OK) == 0) {
- #endif
- return true;
- }
- else
- {
- DbgWithLink(LOG_LEVEL_ERROR, LOG_TYPE_SYSTEM)("root.ini(%s) is not exist.", path.GetData());
- return false;
- }
- }
- bool CVtmLoaderFSM::VerifyVer()
- {
- CSmartPointer<IConfigInfo> pConfig;
- GetEntityBase()->GetFunction()->OpenConfig(Config_CenterSetting, pConfig);
- int VerifyVersion = 0;
- CSimpleStringA activeVer;
- bool isVerEqual = false;
- if (Error_Succeed != pConfig->ReadConfigValueInt("Common", "VerifyVersion", VerifyVersion) || Error_Succeed != GetEntityBase()->GetFunction()->GetRunningVersion(activeVer))
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("read [Common]VerifyVersion failed");
- std::string curVer = std::string(RVC_VERSION_STR);
- if (curVer == activeVer.GetData())
- isVerEqual = true;
-
- if (!isVerEqual)
- {
- CSimpleString showMsg = CSimpleString::Format("version not equal, file version:%s, acitve verion:%s", curVer.c_str(), activeVer.GetData());
- switch (VerifyVersion)
- {
- case 0:
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)(showMsg.GetData());
- break;
- case 1:
- m_verShowMsg = showMsg;
- CloseHandle(CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)&AlarmVersionErr, this, 0, NULL));
- break;
- case 2:
- m_verShowMsg = showMsg;
- CloseHandle(CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)&AlarmVersionErr, this, 0, NULL));
- return false;
- break;
- default:
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("VerifyVersion not support param:%d", VerifyVersion);
- break;
- }
- }
- return true;
- }
- bool CVtmLoaderFSM::GetConfig()
- {
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("before GetConfig terminalNo:[%s]", m_sysInfo.strTerminalID.GetData());
- //拉取配置前先检查root.ini文件
- CSimpleStringA csTmpRootIni("");
- if (!IsRootINIExist(csTmpRootIni))
- {
- if (m_terminalNoFromWeb.IsNullOrEmpty())
- {
- LogWarn(Severity_High, Error_Unexpect, VtmLoader_BootInfoPrint, CSimpleStringA::Format("安装页面未设置终端号,请检查(%s)", csTmpRootIni.GetData()).GetData());
- return false;
- }
- }
- else if (m_sysInfo.strTerminalID.IsNullOrEmpty())
- {
- LogWarn(Severity_High, Error_Unexpect, VtmLoader_BootInfoPrint, CSimpleStringA::Format("root.ini中终端号为空,请检查(%s)", csTmpRootIni.GetData()).GetData());
- return false;
- }
- ErrorCodeEnum eErr = Error_Succeed;
- LogWarn(Severity_Low, Error_Succeed, VtmLoader_BootInfoPrint, "开始拉取配置");
- VTMInitParam vtmInitParam(m_terminalNoFromWeb.GetData(), SpDefine::channelId, SpDefine::tokenSecret, SpDefine::CommonLaunchUrl, SpDefine::CenterConfigTotal);
- if (Error_Succeed != (eErr = GetEntityBase()->GetFunction()->GetPrivilegeFunction()->InitCfgUrl(vtmInitParam)))
- {
- LogWarn(Severity_High, Error_Unexpect, VtmLoader_GetConfig_InitCfgUrl_Failed, CSimpleStringA::Format("拉取配置,初始化配置地址失败:0x%x(%s)", eErr, SpStrError(eErr)).GetData());
- DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_USER).setLogCode("QLR040210F13").setResultCode("RTA1F01")("Get config,InitCfgUrl failed.");
- LogEvent(Severity_High, Event_VtmLoader_GetConfig_Fail, "拉取配置,初始化配置地址失败");
- return false;
- }
- else
- {
- CSimpleString oldToken, newToken;
- if (Error_Succeed != (eErr = GetEntityBase()->GetFunction()->GetPrivilegeFunction()->TryUpdateToken(oldToken, newToken)))
- {
- DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_USER).setLogCode("QLR040210F13").setResultCode("RTA1F02")("Get config, TryUpdateToken failed:0x%x", eErr);
- LogWarn(Severity_High, Error_Unexpect, VtmLoader_GetConfig_UpdateToken_Failed, CSimpleStringA::Format("拉取配置失败:0x%x(%s)", eErr, SpStrError(eErr)).GetData());
- }
- //update err msg list
- CloseHandle(CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)&errMsgListUpdate, this, 0, NULL));
- //if token update failed,we can also update cfg suc
- if (Error_Succeed != (eErr = GetEntityBase()->GetFunction()->GetPrivilegeFunction()->TryUpdateCfg()))
- {
- LogWarn(Severity_High, Error_Unexpect, VtmLoader_GetConfig_UpdateCfg_Failed, CSimpleStringA::Format("拉取配置失败:0x%x(%s)", eErr, SpStrError(eErr)).GetData());
- DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_USER).setLogCode("QLR040210F13").setResultCode("RTA1F03")("Get config, TryUpdateCfg failed:0x%x", eErr);
- LogEvent(Severity_High, Event_VtmLoader_GetConfig_Fail, "拉取配置失败");
- return false;
- }
- }
- refreshLogLevel();
- //all cfg is ready, then init the entity, set centersetting update timer
- void* pTmpData = NULL;
- ITimerListener* pListener = new TimerOutHelper<CVtmLoaderFSM>(this, &CVtmLoaderFSM::OnCentersettingUpdateTimeout, pTmpData);
- GetEntityBase()->GetFunction()->SetTimer(TIMER_CENTERSETTING_UPDATE_CHECK, pListener, CENTERSETTING_UPDATE_CHECK_TIME);
- CSmartPointer<IConfigInfo> pConfig;
- CSimpleString t_endpoint, t_topicSys, t_topicUser, t_topicBeidou, t_bussSys, t_bussUser, t_VTMWeb;
- eErr = GetEntityBase()->GetFunction()->OpenConfig(Config_CenterSetting, pConfig);
- if (eErr == Error_Succeed && Error_Succeed == pConfig->ReadConfigValue("Common", "SendEndpoint", t_endpoint)
- && Error_Succeed == pConfig->ReadConfigValue("Common", "SendSys", t_topicSys)
- && Error_Succeed == pConfig->ReadConfigValue("Common", "SendUser", t_topicUser)
- && Error_Succeed == pConfig->ReadConfigValue("Common", "SendBeidou", t_topicBeidou)
- && Error_Succeed == pConfig->ReadConfigValue("Common", "BusinessSys", t_bussSys)
- && Error_Succeed == pConfig->ReadConfigValue("Common", "BusinessUser", t_bussUser)
- && Error_Succeed == pConfig->ReadConfigValue("Common", "VTMWeb", t_VTMWeb)
- && 0 != t_topicSys.GetLength()
- && 0 != t_topicUser.GetLength()
- && 0 != t_topicBeidou.GetLength()
- && 0 != t_bussSys.GetLength()
- && 0 != t_bussUser.GetLength()
- && 0 != t_VTMWeb.GetLength())
- {
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("endpoint:%s, topicSys:%s, topicUser:%s, topicBeidou:%s, bussSys:%s, bussUser:%s, vtmWeb:%s"
- , t_endpoint.GetData(), t_topicSys.GetData(), t_topicUser.GetData(), t_topicBeidou.GetData(), t_bussSys.GetData(), t_bussUser.GetData(), t_VTMWeb.GetData());
- if (0 != t_endpoint.GetLength())
- {
- GetEntityBase()->GetFunction()->GetPrivilegeFunction()->BeginLogSend(t_endpoint.GetData()
- , t_topicSys.GetData(), t_topicUser.GetData(), t_topicBeidou.GetData(), t_bussSys.GetData(), t_bussUser.GetData(), t_VTMWeb.GetData());
- }
- else
- LogWarn(Severity_High, ErrorCodeEnum::Error_Cancel, Event_VtmLoader_GetConfig_Suc, "endpoint is empty, do not begin send log");
- }
- else
- {
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("read endpoint and topic err, need check centersetting, use default %s-%s-%s-%s-%s-%s-%s"
- , SpDefine::endpoint, SpDefine::topicSys, SpDefine::topicUser, SpDefine::topicBeidou, SpDefine::topicBussSys, SpDefine::topicBussUser, SpDefine::topicVTMWeb);
- GetEntityBase()->GetFunction()->GetPrivilegeFunction()->BeginLogSend(SpDefine::endpoint, SpDefine::topicSys, SpDefine::topicUser, SpDefine::topicBeidou,
- SpDefine::topicBussSys, SpDefine::topicBussUser, SpDefine::topicVTMWeb);
- }
- GetEntityBase()->GetFunction()->GetSystemStaticInfo(m_sysInfo);
- 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"
- , m_sysInfo.strTerminalID.GetData(), m_sysInfo.strMachineModel.GetData(), m_sysInfo.strMachineType.GetData(), m_sysInfo.MachineVersion.ToString().GetData(),m_sysInfo.CurrDepVersion.GetData()
- , m_sysInfo.strSite.GetData(), m_sysInfo.eScreen, m_sysInfo.EnrolGPS.GetLatitude(), m_sysInfo.EnrolGPS.GetLongitude(), m_sysInfo.strEnrolAddr.GetData());
- int tmpSec = 0;
- if (Error_Succeed == pConfig->ReadConfigValueInt(GetEntityBase()->GetEntityName(), "refreshTokenWaitSec", tmpSec) && tmpSec > 0)
- m_refreshWaitSec = tmpSec;
- int t_sec = 0;
- pConfig->ReadConfigValueInt(GetEntityBase()->GetEntityName(), "UploadLogWaitSec", t_sec);
- if (t_sec > 0)
- m_uploadLogInfo_waitSec = t_sec;
- CloseHandle(CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)& checkUrlActive, this, 0, NULL));
- CloseHandle(CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)& tokenUpdate, this, 0, NULL));
- //通知Chromium实体
- LogEvent(Severity_High, Event_VtmLoader_GetConfig_Suc, "Get config succeed.");
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_USER).setLogCode("QLR040210F13")("Get config succeed.");
- return true;
- }
- int CVtmLoaderFSM::HttpConnCheck(CSimpleStringA csHttAddr, HttpAddrType eType)
- {
- DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("to HttpConnCheck");
- ULLINT beginTick = SP::Module::Comm::RVCGetTickCount();
- int httpcheckCount = 1;
- bool bCheckOK = false;
- while(true){
- if (m_httpCheckResult[HttpAddr_CenterSetting] == HttpConnResult_OK)
- {
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("check centersetting ok.");
- return 0;
- }
- else if (m_httpCheckResult[HttpAddr_AccessAuth] == HttpConnResult_OK)
- {
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("check AccessAuth ok.");
- return 0;
- }
- #if defined(RVC_OS_LINUX)
- string msg;
- int curFlag = HttpProbe(csHttAddr.GetData(), msg, 5);
- if (curFlag > 0 && curFlag < 400)
- bCheckOK = true;
- #else
- bCheckOK = checkHttpActive(csHttAddr.GetData());
- #endif
- if (!bCheckOK)
- {
- LogWarn(Severity_High, Error_Unexpect, VtmLoader_ConnectDetect_Failed, CSimpleStringA::Format("尝试连接总行服务失败(%s),%d 秒后自动重试(第%d次重试)。请确认终端到总行服务网络是否正常", csHttAddr.GetData(), m_iDetectInterval/1000, httpcheckCount).GetData());
- if (httpcheckCount == 1)//oilyang@20250415 only the first time we log RTAxxxx
- DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_USER).setLogCode("QLR040210F11").setResultCode("RTA1F06")("connect to http(s) service(%s) failed.", csHttAddr.GetData());
- m_httpCheckResult[eType] = HttpConnResult_Failed;
- Sleep(m_iDetectInterval);
- httpcheckCount++;
- CAutoArray<NetworkAdapterItem> netList;
- if (SP::Module::Net::GetINETMacAddresses(netList) == Error_Succeed)
- {
- CSimpleStringA tmpDns = GetDns();
- for (int i = 0; i < netList.GetCount(); i++) {
- LogWarn(Severity_Low, Error_Unexpect, VtmLoader_BootInfoPrint, CSimpleStringA::Format("(%d)interface:%s; ip:%s; mac:%s; %s", i, netList[i].description.c_str()
- , netList[i].ip.c_str(), netList[i].mac.c_str(), tmpDns.GetData()).GetData());
- }
- }
- }
- else
- {
- m_httpCheckResult[eType] = HttpConnResult_OK;
- if ((SP::Module::Comm::RVCGetTickCount() - beginTick) > 3000)
- {
- LogWarn(Severity_Middle, Error_Unexpect, VtmLoader_ConnectDetect_Slow, CSimpleStringA::Format("第(%d)次尝试连接总行服务成功(%s),但是网络偏慢,连接花了(%d)秒,请检查网络!"
- , httpcheckCount, csHttAddr.GetData(), (SP::Module::Comm::RVCGetTickCount() - beginTick)/1000).GetData());
- DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_USER).setResultCode("RTA1F07")("尝试连接总行服务成功,但是网络偏慢");
- }
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_USER).setLogCode("QLR040210F11")("尝试连接总行服务成功(%s)", csHttAddr.GetData());
- return 0;
- }
- }
- return -1;
- }
- CSimpleStringA CVtmLoaderFSM::GetDns()
- {
- CSimpleStringA runInfoPath, csDNSKeyword, csTmpDns("");
- ErrorCodeEnum eErr = GetEntityBase()->GetFunction()->GetPath("runinfo", runInfoPath);
- if (eErr != Error_Succeed) {
- DbgWithLink(LOG_LEVEL_ERROR, LOG_TYPE_SYSTEM)("GetPath runinfo error=%d.", eErr);
- return "";
- }
- runInfoPath = runInfoPath + SPLIT_SLASH_STR + "runcfg" + SPLIT_SLASH_STR + "dns";
- #if defined(RVC_OS_WIN)
- CSimpleStringA csCmd;
- csCmd = CSimpleStringA::Format("cmd /c ipconfig /all >%s", runInfoPath.GetData());
- WinExec((LPCSTR)csCmd, SW_HIDE);
- csDNSKeyword = "DNS 服务器";
- #else
- std::string sucContent, failedContent;
- CSimpleStringA strCmd;
- strCmd = CSimpleStringA::Format("cat /etc/resolv.conf | grep \"nameserver\" >%s", runInfoPath.GetData());
- bool ret = SP::Module::Util::ShellExecute(strCmd.GetData(), sucContent, failedContent);
- csDNSKeyword = "nameserver";
- #endif //RVC_OS_WIN
- ifstream is;
- is.open(runInfoPath.GetData(), ios::binary);
- if (!is.is_open())
- {
- DWORD dwErr = GetLastError();
- DbgWithLink(LOG_LEVEL_ERROR, LOG_TYPE_SYSTEM)("open %s file failed. [%d]", runInfoPath.GetData(), dwErr);
- return "";
- }
- string line;
- while (!is.eof()) {
- getline(is, line);
- //DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("line:%s", line.c_str());
- size_t start = line.find(csDNSKeyword.GetData());
- if (start != string::npos)
- {
- #if defined(RVC_OS_WIN)
- int dnsStart = line.find(": ");
- if (dnsStart != string::npos)
- {
- string xDns = SP::Utility::ToTrim(line.substr(dnsStart + 1, line.length() - dnsStart - 1));
- csTmpDns += xDns.c_str();
- csTmpDns += ";";
- }
- #else
- string xDns = SP::Utility::ToTrim(line.substr(start + csDNSKeyword.GetLength() + 1, line.length() - start - csDNSKeyword.GetLength() - 1));
- csTmpDns += xDns.c_str();
- csTmpDns += ";";
- #endif
- }
- else
- continue;
- }
-
- return csTmpDns;
- }
- void CVtmLoaderFSM::ToCheckIfInstalling()
- {
- //拉取配置前先检查root.ini文件
- CSimpleStringA csTmpRootIni("");
- if (!IsRootINIExist(csTmpRootIni))
- {
- 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());
- //oiltest
- //OilTestTask* task = new OilTestTask(this);
- //GetEntityBase()->GetFunction()->PostThreadPoolTask(task);
- while (true)
- {
- m_hWaitTerminalNoVar.Wait();
- break;
- }
- }
- }
- void CVtmLoaderFSM::CheckDeviceEntity(SpReqAnsContext<VtmLoaderService_CheckDeviceEntity_Req, VtmLoaderService_CheckDeviceEntity_Ans>::Pointer ctx)
- {
- if (ctx->Req.entityName.IsNullOrEmpty())
- {
- DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM)("ctx->Req.entityName is null or empty.");
- ctx->Answer(Error_Param, VtmLoader_FailToStartEntity);
- return;
- }
- if (!RefreshDeviceConfig(ctx))
- {
- DbgWithLink(LOG_LEVEL_ERROR, LOG_TYPE_SYSTEM)("RefreshDeviceConfig failed.");
- ctx->Answer(Error_Unexpect);
- }
- CEntityStaticInfo staticInfo;
- ErrorCodeEnum eErrCode = Error_Unexpect;
- CSimpleStringA csEntityName = ctx->Req.entityName;
-
- if ((eErrCode = m_pEntity->GetFunction()->GetEntityStaticInfo(csEntityName.GetData(), staticInfo)) != Error_Succeed)
- {
- DbgWithLink(LOG_LEVEL_ERROR, LOG_TYPE_SYSTEM)("GetEntityStaticInfo(%s), failed:%d", ctx->Req.entityName.GetData(), eErrCode);
- ctx->Answer(Error_Unexpect, VtmLoader_FailToGetEntityInfo);
- return;
- }
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("staticInfo.wEntityDevelopID:%x", staticInfo.wEntityDevelopID);
- switch (staticInfo.wEntityDevelopID)
- {
- case 0x201:
- case 0x203:
- case 0x204:
- case 0x206:
- case 0x209:
- case 0x213:
- case 0x217:
- case 0x220:
- CheckDeviceBaseEntity(ctx, staticInfo.wEntityDevelopID);
- break;
- case 0x301://SIPPhone
- CheckAudio(ctx);
- break;
- case 0x208://MediaController
- CheckVideo(ctx);
- break;
- default:
- break;
- }
- return;
- }
- void CVtmLoaderFSM::SaveTerminalNo(SpReqAnsContext<VtmLoaderService_SaveTerminalNo_Req, VtmLoaderService_SaveTerminalNo_Ans>::Pointer ctx)
- {
- if (ctx->Req.terminalNo.IsNullOrEmpty())
- {
- DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM)("terminalNo is null or empty");
- ctx->Answer(Error_Param);
- return;
- }
- LogWarn(Severity_Low, Error_Trace, VtmLoader_SetTerminalNo, CSimpleStringA::Format("SaveTerminalNo:[%s]", ctx->Req.terminalNo.GetData()));
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_USER).setLogCode(VtmLoaderService_LogCode_SaveTerminalNo)("write terminalNo[%s] to root.ini", ctx->Req.terminalNo.GetData());
- ErrorCodeEnum eErr = GetEntityBase()->GetFunction()->GetPrivilegeFunction()->WriteTerminalNoToRootIni(ctx->Req.terminalNo);
- ctx->Answer(eErr);
- }
- void CVtmLoaderFSM::DealWithOldEvent(SpReqAnsContext<VtmLoaderService_DealWithOldEvent_Req, VtmLoaderService_DealWithOldEvent_Ans>::Pointer ctx)
- {
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("DealWithOldEvent called, %d, %s, %s, %d, %d",
- ctx->Req.eventId, ctx->Req.reqStrRev1.GetData(), ctx->Req.reqStrRev2.GetData(), ctx->Req.reqIntRev1, ctx->Req.reqIntRev2);
- ErrorCodeEnum eErr = ErrorCodeEnum::Error_Succeed;
- switch (ctx->Req.eventId)
- {
- case EVENT_CONSOLE_REQ_SHUTDOWN_SHELL:
- LogWarn(Severity_Low, Error_Unexpect, 0x50100215, CSimpleStringA::Format("%x, reason:%s", EVENT_CONSOLE_REQ_SHUTDOWN_SHELL, ctx->Req.reqStrRev1.GetData()));
- if (RebootWayEnum::RebootWay_OS == ctx->Req.reqIntRev1)
- {
- GetEntityBase()->GetFunction()->GetPrivilegeFunction()->Reboot(RebootTriggerEnum::RebootTrigger_Unknown, RebootWayEnum::RebootWay_OS);
- return;
- }
-
- #if defined(RVC_OS_WIN)
- do
- {
- STARTUPINFO si;
- PROCESS_INFORMATION pi;
- ZeroMemory(&si, sizeof(si));
- si.cb = sizeof(si);
- ZeroMemory(&pi, sizeof(pi));
- GetEntityBase()->GetFunction()->FlushLogFile();
- CSimpleStringA csRestart, csVerPath, csAll, csSep("\""), csBlank(" "), csScript("wscript.exe"), csReFlag("r");
- csRestart = "sprestart.exe ";
- ErrorCodeEnum Error = GetEntityBase()->GetFunction()->GetPath("RootVer", csVerPath);
- //csVerPath +="\\spexplorerfast.vbs";
- csVerPath += "\\VTM.exe";
- csReFlag = "n";
- csAll = csSep + csRestart + csSep + csBlank + csSep + csVerPath + csSep
- + csBlank + csSep + csReFlag + csSep;
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("allpath[%s]", (LPCTSTR)csAll);
- LPTSTR szCmdline = _strdup(csAll);
- if (!CreateProcess(NULL, szCmdline, NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi))
- {
- DbgWithLink(LOG_LEVEL_ERROR, LOG_TYPE_SYSTEM)("framework shutdown from console failed, CreateProcess failed (%d).\n", GetLastError());
- eErr = ErrorCodeEnum::Error_Unexpect;
- break;
- }
- DWORD dwErr = GetLastError();
- // Wait until child process exits.
- WaitForSingleObject(pi.hProcess, INFINITE);
- // Close process and thread handles.
- CloseHandle(pi.hProcess);
- CloseHandle(pi.hThread);
- } while (false);
- #endif
- break;
- case LOG_EVT_IEBROWSER_RESET_SITE_RESTART:
- GetEntityBase()->GetFunction()->GetPrivilegeFunction()->Reboot(RebootTriggerEnum::RebootTrigger_Unknown, RebootWayEnum::RebootWay_Framework);
- break;
- default:
- break;
- }
- ctx->Answer(eErr);
- }
- bool CVtmLoaderFSM::RefreshDeviceConfig(SpReqAnsContext<VtmLoaderService_CheckDeviceEntity_Req, VtmLoaderService_CheckDeviceEntity_Ans>::Pointer ctx)
- {
- if (ctx->Req.entityName.IsNullOrEmpty() || ctx->Req.paramNum <= 0)
- {
- DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_USER)("param error! nothing to refresh");
- return false;
- }
- 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());
- if (ctx->Req.module.GetCount() < ctx->Req.paramNum || ctx->Req.name.GetCount() < ctx->Req.paramNum || ctx->Req.value.GetCount() < ctx->Req.paramNum)
- {
- DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_USER)("param array length error! nothing to refresh");
- return false;
- }
- for (int i = 0; i < ctx->Req.paramNum; i++)
- {
- MemCfgParam tmpParam("root", ctx->Req.module[i].GetData(), ctx->Req.name[i].GetData(), ctx->Req.value[i].GetData());
- 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());
- GetEntityBase()->GetFunction()->GetPrivilegeFunction()->ModifyMemCfgParam(tmpParam);
- }
- return true;
- }
- void CVtmLoaderFSM::CheckDeviceBaseEntity(SpReqAnsContext<VtmLoaderService_CheckDeviceEntity_Req, VtmLoaderService_CheckDeviceEntity_Ans>::Pointer ctx, WORD wEntityID)
- {
- CSmartPointer<IEntityFunctionPrivilege> pFuncPrivilege = m_pEntity->GetFunction().ConvertCase<IEntityFunctionPrivilege>();
- CSmartPointer<IAsynWaitSp> spWait;
- CEntityRunInfo runInfo;
- CSimpleStringA csEntityName = ctx->Req.entityName;
- //oiltmp@20240415 to be delete after x months
- if (ctx->Req.entityName.Compare("CardIssuer") == 0)
- {
- if (m_sysInfo.strMachineType.Compare("RVC.CardStore") == 0 || m_sysInfo.strMachineType.Compare("RVC.CardPrinter") == 0)
- csEntityName = "CardIssuerStore";
- else
- csEntityName = "CardIssuerStand";
- }
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("csEntityName:[%s]", csEntityName.GetData());
- //to check entity state
- ErrorCodeEnum eErrCode = m_pEntity->GetFunction()->GetEntityRunInfo(csEntityName.GetData(), runInfo);
- if (eErrCode == Error_Succeed)
- {
- if (runInfo.eState != EntityState_NoStart)
- {
- eErrCode = pFuncPrivilege->TerminateEntity(csEntityName.GetData(), spWait);
- if (spWait != NULL)
- eErrCode = spWait->WaitAnswer(MAX_AYSNC_TIMEOUT);
- }
- }
- else
- {
- DbgWithLink(LOG_LEVEL_ERROR, LOG_TYPE_SYSTEM).setLogCode(VtmLoaderService_LogCode_CheckDeviceEntity).setResultCode("RTA1F24")
- ("GetEntityRunInfo %s failed(%d).", csEntityName.GetData(), eErrCode);
- ctx->Answer(Error_Unexpect, VtmLoader_FailToGetEntityInfo);
- return;
- }
- //(re)start entity
- eErrCode = pFuncPrivilege->StartEntity(csEntityName.GetData(), NULL, spWait);
- if (eErrCode == Error_Succeed)
- {
- if (spWait != NULL)
- eErrCode = spWait->WaitAnswer(MAX_AYSNC_TIMEOUT);
- }
- else
- {
- DbgWithLink(LOG_LEVEL_ERROR, LOG_TYPE_SYSTEM).setLogCode(VtmLoaderService_LogCode_CheckDeviceEntity).setResultCode("RTA1F21")
- ("StartEntity %s failed(%d).", csEntityName.GetData(), eErrCode);
- ctx->Answer(Error_Unexpect, VtmLoader_FailToStartEntity);
- return;
- }
-
- //TODO we should wait for device entity open suc?
- //Sleep 2 second for simple
- Sleep(2000);
- int count = 0;
- do
- {
- CEntityRunInfo runInfo;
- eErrCode = m_pEntity->GetFunction()->GetEntityRunInfo(csEntityName.GetData(), runInfo);
- if (eErrCode == Error_Succeed)
- {
- if (runInfo.eState == EntityState_Idle)
- break;
- else if (runInfo.eState == EntityState_Lost || runInfo.eState == EntityState_Close || runInfo.eState == EntityState_Killed)
- {
- DbgWithLink(LOG_LEVEL_ERROR, LOG_TYPE_SYSTEM).setLogCode(VtmLoaderService_LogCode_CheckDeviceEntity).setResultCode("RTA1F21")
- ("entity state:%d", runInfo.eState);
- ctx->Answer(Error_Unexpect, VtmLoader_FailToStartEntity);
- return;
- }
- count++;
- if (count > 3)
- {
- DbgWithLink(LOG_LEVEL_ERROR, LOG_TYPE_SYSTEM).setLogCode(VtmLoaderService_LogCode_CheckDeviceEntity).setResultCode("RTA1F21")
- ("entity state:%d", runInfo.eState);
- ctx->Answer(Error_Unexpect, VtmLoader_FailToStartEntity);
- return;
- }
- Sleep(1000);
- }
- else
- {
- DbgWithLink(LOG_LEVEL_ERROR, LOG_TYPE_SYSTEM).setLogCode(VtmLoaderService_LogCode_CheckDeviceEntity).setResultCode("RTA1F21")
- ("GetEntityRunInfo failed:%d", eErrCode);
- ctx->Answer(Error_Unexpect, VtmLoader_FailToStartEntity);
- return;
- }
- } while (true);
-
- const int retryGetDevInfoInterval = 5000;//5 seconds
- const int maxRetryTimes = 16;//16*5 = 80 seconds ,the web timeout setting is 90s
- CClientSessionBase* pClient;
- int entityState = 0;
- switch (wEntityID)
- {
- case 0x206: //pinpad
- {
- PinPadService_ClientBase* pClient = new PinPadService_ClientBase(this->m_pEntity);
- if (pClient != NULL)
- {
- eErrCode = pClient->Connect();
- if (eErrCode == Error_Succeed)
- {
- int retryTimes = maxRetryTimes;
- do {
- PinPadService_GetDevInfo_Req reqQ;
- PinPadService_GetDevInfo_Ans ansQ;
- eErrCode = (*pClient)(EntityResource::getLink().upgradeLink())->GetDevInfo(reqQ, ansQ, 5000);
- DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("eErrCode:%d,ansQ.state:%d", eErrCode, ansQ.state);
- if (eErrCode == Error_DevNotAvailable)
- {
- DbgWithLink(LOG_LEVEL_ERROR, LOG_TYPE_SYSTEM).setLogCode(VtmLoaderService_LogCode_CheckDeviceEntity).setResultCode("RTA1F23")("%d", eErrCode);
- ctx->Answer(Error_Unexpect, VtmLoader_EntityNotInNormal);
- return;
- }
- else if (eErrCode == Error_Succeed)
- {
- DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("return to caller");
- ctx->Answer(Error_Succeed);
- return;
- }
- Sleep(retryGetDevInfoInterval);
- retryTimes--;
- } while (retryTimes > 0);
- if (retryTimes == 0)
- {
- DbgWithLink(LOG_LEVEL_ERROR, LOG_TYPE_SYSTEM).setLogCode(VtmLoaderService_LogCode_CheckDeviceEntity).setResultCode("RTA1F23")
- ("after have tried x times");
- ctx->Answer(Error_Unexpect, VtmLoader_EntityNotInNormal);
- }
- }
- else {
- DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM).setLogCode(VtmLoaderService_LogCode_CheckDeviceEntity).setResultCode("RTA1F22")
- ("connect to %s failed.error code:%d", csEntityName.GetData(), eErrCode);
- ctx->Answer(Error_Unexpect, VtmLoader_FailToConnectEntity);
- }
- }
- else
- {
- DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM).setLogCode(VtmLoaderService_LogCode_CheckDeviceEntity).setResultCode("RTA1F22")
- ("new client failed.");
- ctx->Answer(Error_Unexpect, VtmLoader_FailToConnectEntity);
- }
- }
- break;
- case 0x201: //IDCertificate
- {
- IDCertService_ClientBase* pClient = new IDCertService_ClientBase(this->m_pEntity);
- if (pClient != NULL)
- {
- eErrCode = pClient->Connect();
- if (eErrCode == Error_Succeed)
- {
- int retryTimes = maxRetryTimes;
- do {
- IDCertService_GetDevInfo_Req reqQ;
- IDCertService_GetDevInfo_Ans ansQ;
- eErrCode = (*pClient)(EntityResource::getLink().upgradeLink())->GetDevInfo(reqQ, ansQ, 5000);
- DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("eErrCode:%d,ansQ.state:%d", eErrCode, ansQ.state);
- if (eErrCode == Error_DevNotAvailable)
- {
- DbgWithLink(LOG_LEVEL_ERROR, LOG_TYPE_SYSTEM).setLogCode(VtmLoaderService_LogCode_CheckDeviceEntity).setResultCode("RTA1F23")("%d", eErrCode);
- ctx->Answer(Error_Unexpect, VtmLoader_EntityNotInNormal);
- return;
- }
- else if (eErrCode == Error_Succeed)
- {
- DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("return to caller");
- ctx->Answer(Error_Succeed);
- return;
- }
- Sleep(retryGetDevInfoInterval);
- retryTimes--;
- } while (retryTimes > 0);
- if (retryTimes == 0)
- {
- DbgWithLink(LOG_LEVEL_ERROR, LOG_TYPE_SYSTEM).setLogCode(VtmLoaderService_LogCode_CheckDeviceEntity).setResultCode("RTA1F23")
- ("after have tried x times");
- ctx->Answer(Error_Unexpect, VtmLoader_EntityNotInNormal);
- }
- }
- else {
- DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM).setLogCode(VtmLoaderService_LogCode_CheckDeviceEntity).setResultCode("RTA1F22")
- ("connect to %s failed.error code:%d", csEntityName.GetData(), eErrCode);
- ctx->Answer(Error_Unexpect, VtmLoader_FailToConnectEntity);
- }
- }
- else
- {
- DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM).setLogCode(VtmLoaderService_LogCode_CheckDeviceEntity).setResultCode("RTA1F22")
- ("new client failed.");
- ctx->Answer(Error_Unexpect, VtmLoader_FailToConnectEntity);
- }
- }
- break;
- case 0x204: //FingerPrint
- {
- FingerPrintService_ClientBase* pClient = new FingerPrintService_ClientBase(this->m_pEntity);
- if (pClient != NULL)
- {
- eErrCode = pClient->Connect();
- if (eErrCode == Error_Succeed)
- {
- int retryTimes = maxRetryTimes;
- do {
- FingerPrintService_GetDevInfo_Req reqQ;
- FingerPrintService_GetDevInfo_Ans ansQ;
- eErrCode = (*pClient)(EntityResource::getLink().upgradeLink())->GetDevInfo(reqQ, ansQ, 5000);
- DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("eErrCode:%d,ansQ.state:%d", eErrCode, ansQ.state);
- if (eErrCode == Error_DevNotAvailable)
- {
- DbgWithLink(LOG_LEVEL_ERROR, LOG_TYPE_SYSTEM).setLogCode(VtmLoaderService_LogCode_CheckDeviceEntity).setResultCode("RTA1F23")("%d", eErrCode);
- ctx->Answer(Error_Unexpect, VtmLoader_EntityNotInNormal);
- return;
- }
- else if (eErrCode == Error_Succeed)
- {
- DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("return to caller");
- ctx->Answer(Error_Succeed);
- return;
- }
- Sleep(retryGetDevInfoInterval);
- retryTimes--;
- } while (retryTimes > 0);
- if (retryTimes == 0)
- {
- DbgWithLink(LOG_LEVEL_ERROR, LOG_TYPE_SYSTEM).setLogCode(VtmLoaderService_LogCode_CheckDeviceEntity).setResultCode("RTA1F23")
- ("after have tried x times");
- ctx->Answer(Error_Unexpect, VtmLoader_EntityNotInNormal);
- }
- }
- else {
- DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM).setLogCode(VtmLoaderService_LogCode_CheckDeviceEntity).setResultCode("RTA1F22")
- ("connect to %s failed.error code:%d", csEntityName.GetData(), eErrCode);
- ctx->Answer(Error_Unexpect, VtmLoader_FailToConnectEntity);
- }
- }
- else
- {
- DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM).setLogCode(VtmLoaderService_LogCode_CheckDeviceEntity).setResultCode("RTA1F22")
- ("new client failed.");
- ctx->Answer(Error_Unexpect, VtmLoader_FailToConnectEntity);
- }
- }
- break;
- case 0x203: //CardIssuerStand
- case 0x220: //CardIssuerStore
- {
- if (m_sysInfo.strMachineType.Compare("RVC.CardStore") == 0 || m_sysInfo.strMachineType.Compare("RVC.CardPrinter") == 0)
- {
- CardIssuerStoreService_ClientBase* pClient = new CardIssuerStoreService_ClientBase(this->m_pEntity);
- if (pClient != NULL)
- {
- eErrCode = pClient->Connect();
- if (eErrCode == Error_Succeed)
- {
- int retryTimes = maxRetryTimes;
- do {
- CardIssuerStoreService_GetDevInfo_Req reqQ;
- CardIssuerStoreService_GetDevInfo_Ans ansQ;
- eErrCode = (*pClient)(EntityResource::getLink().upgradeLink())->GetDevInfo(reqQ, ansQ, 5000);
- DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("eErrCode:%d,ansQ.state:%d", eErrCode, ansQ.state);
- if (eErrCode == Error_DevNotAvailable)
- {
- DbgWithLink(LOG_LEVEL_ERROR, LOG_TYPE_SYSTEM).setLogCode(VtmLoaderService_LogCode_CheckDeviceEntity).setResultCode("RTA1F23")("%d", eErrCode);
- ctx->Answer(Error_Unexpect, VtmLoader_EntityNotInNormal);
- return;
- }
- else if (eErrCode == Error_Succeed)
- {
- DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("return to caller");
- ctx->Answer(Error_Succeed);
- return;
- }
- Sleep(retryGetDevInfoInterval);
- retryTimes--;
- } while (retryTimes > 0);
- if (retryTimes == 0)
- {
- DbgWithLink(LOG_LEVEL_ERROR, LOG_TYPE_SYSTEM).setLogCode(VtmLoaderService_LogCode_CheckDeviceEntity).setResultCode("RTA1F23")
- ("after have tried x times");
- ctx->Answer(Error_Unexpect, VtmLoader_EntityNotInNormal);
- }
- }
- else {
- DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM).setLogCode(VtmLoaderService_LogCode_CheckDeviceEntity).setResultCode("RTA1F22")
- ("connect to %s failed.error code:%d", csEntityName.GetData(), eErrCode);
- ctx->Answer(Error_Unexpect, VtmLoader_FailToConnectEntity);
- }
- }
- else
- {
- DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM).setLogCode(VtmLoaderService_LogCode_CheckDeviceEntity).setResultCode("RTA1F22")
- ("new client failed.");
- ctx->Answer(Error_Unexpect, VtmLoader_FailToConnectEntity);
- }
- }
- else
- {
- CardIssuerStandService_ClientBase* pClient = new CardIssuerStandService_ClientBase(this->m_pEntity);
- if (pClient != NULL)
- {
- eErrCode = pClient->Connect();
- if (eErrCode == Error_Succeed)
- {
- int retryTimes = maxRetryTimes;
- do {
- CardIssuerStandService_GetDevInfo_Req reqQ;
- CardIssuerStandService_GetDevInfo_Ans ansQ;
- eErrCode = (*pClient)(EntityResource::getLink().upgradeLink())->GetDevInfo(reqQ, ansQ, 5000);
- DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("eErrCode:%d,ansQ.state:%d", eErrCode, ansQ.state);
- if (eErrCode == Error_DevNotAvailable)
- {
- DbgWithLink(LOG_LEVEL_ERROR, LOG_TYPE_SYSTEM).setLogCode(VtmLoaderService_LogCode_CheckDeviceEntity).setResultCode("RTA1F23")("%d", eErrCode);
- ctx->Answer(Error_Unexpect, VtmLoader_EntityNotInNormal);
- return;
- }
- else if (eErrCode == Error_Succeed)
- {
- DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("return to caller");
- ctx->Answer(Error_Succeed);
- return;
- }
- Sleep(retryGetDevInfoInterval);
- retryTimes--;
- } while (retryTimes > 0);
- if (retryTimes == 0)
- {
- DbgWithLink(LOG_LEVEL_ERROR, LOG_TYPE_SYSTEM).setLogCode(VtmLoaderService_LogCode_CheckDeviceEntity).setResultCode("RTA1F23")
- ("after have tried x times");
- ctx->Answer(Error_Unexpect, VtmLoader_EntityNotInNormal);
- }
- }
- else {
- DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM).setLogCode(VtmLoaderService_LogCode_CheckDeviceEntity).setResultCode("RTA1F22")
- ("connect to %s failed.error code:%d", csEntityName.GetData(), eErrCode);
- ctx->Answer(Error_Unexpect, VtmLoader_FailToConnectEntity);
- }
- }
- else
- {
- DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM).setLogCode(VtmLoaderService_LogCode_CheckDeviceEntity).setResultCode("RTA1F22")
- ("new client failed.");
- ctx->Answer(Error_Unexpect, VtmLoader_FailToConnectEntity);
- }
- }
- }
- break;
- case 0x209: //gpio
- {
- GpioService_ClientBase* pClient = new GpioService_ClientBase(this->m_pEntity);
- if (pClient != NULL)
- {
- eErrCode = pClient->Connect();
- if (eErrCode == Error_Succeed)
- {
- int retryTimes = maxRetryTimes;
- do {
- GpioService_GetDevInfo_Req reqQ;
- GpioService_GetDevInfo_Ans ansQ;
- eErrCode = (*pClient)(EntityResource::getLink().upgradeLink())->GetDevInfo(reqQ, ansQ, 5000);
- DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("eErrCode:%d,ansQ.state:%d", eErrCode, ansQ.state);
- if (eErrCode == Error_DevNotAvailable)
- {
- DbgWithLink(LOG_LEVEL_ERROR, LOG_TYPE_SYSTEM).setLogCode(VtmLoaderService_LogCode_CheckDeviceEntity).setResultCode("RTA1F23")("%d", eErrCode);
- ctx->Answer(Error_Unexpect, VtmLoader_EntityNotInNormal);
- return;
- }
- else if (eErrCode == Error_Succeed)
- {
- DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("return to caller");
- ctx->Answer(Error_Succeed);
- return;
- }
- Sleep(retryGetDevInfoInterval);
- retryTimes--;
- } while (retryTimes > 0);
- if (retryTimes == 0)
- {
- DbgWithLink(LOG_LEVEL_ERROR, LOG_TYPE_SYSTEM).setLogCode(VtmLoaderService_LogCode_CheckDeviceEntity).setResultCode("RTA1F23")
- ("after have tried x times");
- ctx->Answer(Error_Unexpect, VtmLoader_EntityNotInNormal);
- }
- }
- else {
- DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM).setLogCode(VtmLoaderService_LogCode_CheckDeviceEntity).setResultCode("RTA1F22")
- ("connect to %s failed.error code:%d", csEntityName.GetData(), eErrCode);
- ctx->Answer(Error_Unexpect, VtmLoader_FailToConnectEntity);
- }
- }
- else
- {
- DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM).setLogCode(VtmLoaderService_LogCode_CheckDeviceEntity).setResultCode("RTA1F22")
- ("new client failed.");
- ctx->Answer(Error_Unexpect, VtmLoader_FailToConnectEntity);
- }
- }
- break;
- case 0x213: //ContactlessCard
- {
- ContactlessCardService_ClientBase* pClient = new ContactlessCardService_ClientBase(this->m_pEntity);
- if (pClient != NULL)
- {
- eErrCode = pClient->Connect();
- if (eErrCode == Error_Succeed)
- {
- int retryTimes = maxRetryTimes;
- do {
- ContactlessCardService_GetDevInfo_Req reqQ;
- ContactlessCardService_GetDevInfo_Ans ansQ;
- eErrCode = (*pClient)(EntityResource::getLink().upgradeLink())->GetDevInfo(reqQ, ansQ, 5000);
- DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("eErrCode:%d,ansQ.state:%d", eErrCode, ansQ.state);
- if (eErrCode == Error_DevNotAvailable)
- {
- DbgWithLink(LOG_LEVEL_ERROR, LOG_TYPE_SYSTEM).setLogCode(VtmLoaderService_LogCode_CheckDeviceEntity).setResultCode("RTA1F23")("%d", eErrCode);
- ctx->Answer(Error_Unexpect, VtmLoader_EntityNotInNormal);
- return;
- }
- else if (eErrCode == Error_Succeed)
- {
- DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("return to caller");
- ctx->Answer(Error_Succeed);
- return;
- }
- Sleep(retryGetDevInfoInterval);
- retryTimes--;
- } while (retryTimes > 0);
- if (retryTimes == 0)
- {
- DbgWithLink(LOG_LEVEL_ERROR, LOG_TYPE_SYSTEM).setLogCode(VtmLoaderService_LogCode_CheckDeviceEntity).setResultCode("RTA1F23")
- ("after have tried x times");
- ctx->Answer(Error_Unexpect, VtmLoader_EntityNotInNormal);
- }
- }
- else {
- DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM).setLogCode(VtmLoaderService_LogCode_CheckDeviceEntity).setResultCode("RTA1F22")
- ("connect to %s failed.error code:%d", csEntityName.GetData(), eErrCode);
- ctx->Answer(Error_Unexpect, VtmLoader_FailToConnectEntity);
- }
- }
- else
- {
- DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM).setLogCode(VtmLoaderService_LogCode_CheckDeviceEntity).setResultCode("RTA1F22")
- ("new client failed.");
- ctx->Answer(Error_Unexpect, VtmLoader_FailToConnectEntity);
- }
- }
- break;
- case 0x217:
- {
- HSPScannerService_ClientBase* pClient = new HSPScannerService_ClientBase(this->m_pEntity);
- if (pClient != NULL)
- {
- eErrCode = pClient->Connect();
- if (eErrCode == Error_Succeed)
- {
- int retryTimes = maxRetryTimes;
- do {
- HSPScannerService_GetDevInfo_Req reqQ;
- HSPScannerService_GetDevInfo_Ans ansQ;
- eErrCode = (*pClient)(EntityResource::getLink().upgradeLink())->GetDevInfo(reqQ, ansQ, 5000);
- DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("eErrCode:%d,ansQ.state:%d", eErrCode, ansQ.state);
- if (eErrCode == Error_DevNotAvailable)
- {
- DbgWithLink(LOG_LEVEL_ERROR, LOG_TYPE_SYSTEM).setLogCode(VtmLoaderService_LogCode_CheckDeviceEntity).setResultCode("RTA1F23")("%d", eErrCode);
- ctx->Answer(Error_Unexpect, VtmLoader_EntityNotInNormal);
- return;
- }
- else if (eErrCode == Error_Succeed)
- {
- DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("return to caller");
- ctx->Answer(Error_Succeed);
- return;
- }
- Sleep(retryGetDevInfoInterval);
- retryTimes--;
- } while (retryTimes > 0);
- if (retryTimes == 0)
- {
- DbgWithLink(LOG_LEVEL_ERROR, LOG_TYPE_SYSTEM).setLogCode(VtmLoaderService_LogCode_CheckDeviceEntity).setResultCode("RTA1F23")
- ("after have tried x times");
- ctx->Answer(Error_Unexpect, VtmLoader_EntityNotInNormal);
- }
- }
- else {
- DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM).setLogCode(VtmLoaderService_LogCode_CheckDeviceEntity).setResultCode("RTA1F22")
- ("connect to %s failed.error code:%d", csEntityName.GetData(), eErrCode);
- ctx->Answer(Error_Unexpect, VtmLoader_FailToConnectEntity);
- }
- }
- else
- {
- DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM).setLogCode(VtmLoaderService_LogCode_CheckDeviceEntity).setResultCode("RTA1F22")
- ("new client failed.");
- ctx->Answer(Error_Unexpect, VtmLoader_FailToConnectEntity);
- }
- }
- break;
- default:
- break;
- }
- return;
- }
- void CVtmLoaderFSM::CheckAudio(SpReqAnsContext<VtmLoaderService_CheckDeviceEntity_Req, VtmLoaderService_CheckDeviceEntity_Ans>::Pointer ctx)
- {
- CSmartPointer<IEntityFunctionPrivilege> pFuncPrivilege = m_pEntity->GetFunction().ConvertCase<IEntityFunctionPrivilege>();
- CSmartPointer<IAsynWaitSp> spWait;
- CEntityRunInfo runInfo;
- //to check entity state
- ErrorCodeEnum eErrCode = m_pEntity->GetFunction()->GetEntityRunInfo(ctx->Req.entityName.GetData(), runInfo);
- if (eErrCode == Error_Succeed)
- {
- if (runInfo.eState != EntityState_NoStart)
- {
- eErrCode = pFuncPrivilege->TerminateEntity(ctx->Req.entityName.GetData(), spWait);
- if (spWait != NULL)
- eErrCode = spWait->WaitAnswer(MAX_AYSNC_TIMEOUT);
- }
- }
- else
- {
- DbgWithLink(LOG_LEVEL_ERROR, LOG_TYPE_SYSTEM)("GetEntityRunInfo %s failed(%d).", ctx->Req.entityName.GetData(), eErrCode);
- ctx->Answer(Error_Unexpect, VtmLoader_FailToGetEntityInfo);
- return;
- }
- //(re)start entity
- eErrCode = pFuncPrivilege->StartEntity(ctx->Req.entityName.GetData(), NULL, spWait);
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("StartEntity %s eErrCode(%d).", ctx->Req.entityName.GetData(), eErrCode);
- if (eErrCode == Error_Succeed)
- {
- if (spWait != NULL)
- eErrCode = spWait->WaitAnswer(MAX_AYSNC_TIMEOUT);
- }
- else
- {
- DbgWithLink(LOG_LEVEL_ERROR, LOG_TYPE_SYSTEM)("StartEntity %s failed(%d).", ctx->Req.entityName.GetData(), eErrCode);
- ctx->Answer(Error_Unexpect, VtmLoader_FailToStartEntity);
- return;
- }
- //TODO we should wait for device entity open suc?
- int count = 0;
- do
- {
- eErrCode = m_pEntity->GetFunction()->GetEntityRunInfo(ctx->Req.entityName.GetData(), runInfo);
- if (eErrCode == Error_Succeed)
- {
- if (runInfo.eState == EntityState_Idle || runInfo.eState == EntityState_Lost)
- {
- CSimpleStringA csSoundCardState("");
- eErrCode = GetEntityBase()->GetFunction()->GetSysVar("SoundCardState", csSoundCardState);
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("eErrCode:%d csSoundCardState:%s", eErrCode, csSoundCardState.GetData());
- if (eErrCode == Error_Succeed)
- {
- if (csSoundCardState.Compare("N") == 0)
- ctx->Answer(Error_Succeed);
- else if (csSoundCardState.Compare("C") == 0)
- ctx->Answer(Error_Unexpect, VtmLoader_CheckAudio_CfgEmpty);
- else if (csSoundCardState.Compare("B") == 0)
- ctx->Answer(Error_Unexpect, VtmLoader_CheckAudio_CfgBothError);
- else if (csSoundCardState.Compare("P") == 0)
- ctx->Answer(Error_Unexpect, VtmLoader_CheckAudio_CfgPickupError);
- else if (csSoundCardState.Compare("H") == 0)
- ctx->Answer(Error_Unexpect, VtmLoader_CheckAudio_CfgHandFreeError);
- return;
- }
- else
- {
- DbgWithLink(LOG_LEVEL_ERROR, LOG_TYPE_SYSTEM)("failed to get sysvar SoundCardState , eErrCode:%d", eErrCode);
- ctx->Answer(Error_Unexpect, VtmLoader_FailToStartEntity);
- return;
- }
- }
- else
- {
- Sleep(2000);
- count++;
- if (count > 5)
- {
- DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM)("after timeout, entity state is not we want...(Idle or Lost)");
- ctx->Answer(Error_Unexpect, VtmLoader_FailToStartEntity);
- return;
- }
- continue;
- }
- }
- else
- {
- DbgWithLink(LOG_LEVEL_ERROR, LOG_TYPE_SYSTEM)("failed to GetEntityRunInfo, eErrCode:%d", eErrCode);
- ctx->Answer(Error_Unexpect, VtmLoader_FailToStartEntity);
- return;
- }
- } while (true);
- }
- void CVtmLoaderFSM::CheckVideo(SpReqAnsContext<VtmLoaderService_CheckDeviceEntity_Req, VtmLoaderService_CheckDeviceEntity_Ans>::Pointer ctx)
- {
- CSmartPointer<IEntityFunctionPrivilege> pFuncPrivilege = m_pEntity->GetFunction().ConvertCase<IEntityFunctionPrivilege>();
- CSmartPointer<IAsynWaitSp> spWait;
- CEntityRunInfo runInfo;
- //to check entity state
- ErrorCodeEnum eErrCode = m_pEntity->GetFunction()->GetEntityRunInfo(ctx->Req.entityName.GetData(), runInfo);
- if (eErrCode == Error_Succeed)
- {
- if (runInfo.eState != EntityState_NoStart)
- {
- eErrCode = pFuncPrivilege->TerminateEntity(ctx->Req.entityName.GetData(), spWait);
- if (spWait != NULL)
- eErrCode = spWait->WaitAnswer(MAX_AYSNC_TIMEOUT);
- }
- }
- else
- {
- DbgWithLink(LOG_LEVEL_ERROR, LOG_TYPE_SYSTEM)("GetEntityRunInfo %s failed(%d).", ctx->Req.entityName.GetData(), eErrCode);
- ctx->Answer(Error_Unexpect, VtmLoader_FailToGetEntityInfo);
- return;
- }
- m_bMediaControllerOK = false;
- //(re)start entity
- eErrCode = pFuncPrivilege->StartEntity(ctx->Req.entityName.GetData(), NULL, spWait);
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("StartEntity %s eErrCode(%d).", ctx->Req.entityName.GetData(), eErrCode);
- if (eErrCode == Error_Succeed)
- {
- if (spWait != NULL)
- eErrCode = spWait->WaitAnswer(MAX_AYSNC_TIMEOUT);
- }
- else
- {
- DbgWithLink(LOG_LEVEL_ERROR, LOG_TYPE_SYSTEM)("StartEntity %s failed(%d).", ctx->Req.entityName.GetData(), eErrCode);
- ctx->Answer(Error_Unexpect, VtmLoader_FailToStartEntity);
- return;
- }
- //TODO we should wait for device entity open suc?
- int count = 0;
- do
- {
- if (!m_bMediaControllerOK)
- {
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("wait for MediaController to check video setting");
- Sleep(2000);
- count++;
- if (count > 5)
- {
- DbgWithLink(LOG_LEVEL_ERROR, LOG_TYPE_SYSTEM)("after timeout, entity state is not right");
- ctx->Answer(Error_Unexpect, VtmLoader_FailToStartEntity);
- return;
- }
- continue;
- }
- CEntityRunInfo runInfo;
- eErrCode = m_pEntity->GetFunction()->GetEntityRunInfo(ctx->Req.entityName.GetData(), runInfo);
- if (eErrCode == Error_Succeed)
- {
- if (runInfo.eState == EntityState_Idle)
- {
- CSimpleStringA csCameraState("");
- eErrCode = GetEntityBase()->GetFunction()->GetSysVar("CameraState", csCameraState);
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("eErrCode:%d csCameraState:%s", eErrCode, csCameraState.GetData());
- if (eErrCode == Error_Succeed && csCameraState.Compare("N") == 0)
- {
- ctx->Answer(Error_Succeed);
- return;
- }
- else
- {
- ctx->Answer(Error_Unexpect, VtmLoader_CheckVideoCfgFail);
- return;
- }
- }
- else if (runInfo.eState == EntityState_Lost || runInfo.eState == EntityState_Close || runInfo.eState == EntityState_Killed)
- {
- DbgWithLink(LOG_LEVEL_ERROR, LOG_TYPE_SYSTEM)("runInfo.eState:%d", runInfo.eState);
- ctx->Answer(Error_Unexpect, VtmLoader_FailToStartEntity);
- return;
- }
- }
- else
- {
- DbgWithLink(LOG_LEVEL_ERROR, LOG_TYPE_SYSTEM)("failed to GetEntityRunInfo, eErrCode:%d", eErrCode);
- ctx->Answer(Error_Unexpect, VtmLoader_FailToStartEntity);
- return;
- }
- } while (true);
- }
- bool CVtmLoaderFSM::CheckConfigInfoInTestRoom()
- {
- if (m_iNoCheckMachineModel)
- return true;
-
- bool bNeedCheckOK = false;
- #ifdef DEVOPS_ON_ST /*DevOps流水线编译,ST环境*/
- bNeedCheckOK = true;
- #elif defined(DEVOPS_ON_UAT)/*DevOps流水线编译,UAT环境*/
- bNeedCheckOK = true;
- #endif
- if (bNeedCheckOK)
- {
- DoSpecialJobInTestRoom();
- //to check MachineType
- CSmartPointer<IConfigInfo> spConfigRoot;
- if (GetEntityBase()->GetFunction()->OpenConfig(Config_Root, spConfigRoot) != Error_Succeed)
- {
- return true;
- }
- if (m_sysInfo.strMachineType.Compare("RVC.Stand2S") != 0 && m_sysInfo.strMachineType.Compare("RVC.CardStore")
- && m_sysInfo.strMachineType.Compare("RVC.CardPrinter") && m_sysInfo.strMachineType.Compare("RVC.Stand1SPlus"))
- {
- if (m_sysInfo.strMachineType.IsNullOrEmpty())
- LogWarn(Severity_High, Error_Unexpect, VtmLoader_BootInfoPrint, CSimpleStringA::Format("机型machineType配置为空,请检查", m_sysInfo.strMachineType.GetData()));
- else
- LogWarn(Severity_High, Error_Unexpect, VtmLoader_BootInfoPrint, CSimpleStringA::Format("机型machineType(%s)不对,请检查", m_sysInfo.strMachineType.GetData()));
- return false;
- }
- //to check Terminal App Version
- CSmartPointer<IConfigInfo> spConfigCen;
- if (GetEntityBase()->GetFunction()->OpenConfig(Config_CenterSetting, spConfigCen) == Error_Succeed)
- {
- CSimpleStringA csWinVerPrefix(""), csUosVerPrefix(""), csStaticVerPrefix("");
- spConfigCen->ReadConfigValue(GetEntityBase()->GetEntityName(), "WinVerPrefix", csWinVerPrefix);
- spConfigCen->ReadConfigValue(GetEntityBase()->GetEntityName(), "UosVerPrefix", csUosVerPrefix);
- csStaticVerPrefix = CSimpleStringA::Format("%d.%d",m_sysInfo.InstallVersion.GetMajor(), m_sysInfo.InstallVersion.GetMinor());
- #if defined(RVC_OS_LINUX)
- if (csUosVerPrefix.IsNullOrEmpty())
- return true;
- else
- {
- CAutoArray<CSimpleStringA> arrVer = csUosVerPrefix.Split('.');
- if (arrVer.GetCount() > 1)
- {
- int major = atoi(arrVer[0].GetData());
- int minor = atoi(arrVer[1].GetData());
- if (m_sysInfo.InstallVersion.GetMajor() > major || (m_sysInfo.InstallVersion.GetMajor() == major && m_sysInfo.InstallVersion.GetMinor() > minor))
- {
- DbgWithLink(LOG_LEVEL_ERROR, LOG_TYPE_SYSTEM)("current version:%s, csUosVerPrefix:%s", m_sysInfo.InstallVersion.ToString().GetData(), csUosVerPrefix.GetData());
- return false;
- }
- }
- }
- #else
- if (csWinVerPrefix.IsNullOrEmpty())
- return true;
- else
- {
- CAutoArray<CSimpleStringA> arrVer = csWinVerPrefix.Split('.');
- if (arrVer.GetCount() > 1)
- {
- int major = atoi(arrVer[0].GetData());
- int minor = atoi(arrVer[1].GetData());
- if (m_sysInfo.InstallVersion.GetMajor() > major || (m_sysInfo.InstallVersion.GetMajor() == major && m_sysInfo.InstallVersion.GetMinor() > minor))
- {
- DbgWithLink(LOG_LEVEL_ERROR, LOG_TYPE_SYSTEM)("current version:%s, csWinVerPrefix:%s", m_sysInfo.InstallVersion.ToString().GetData(), csWinVerPrefix.GetData());
- return false;
- }
- }
- }
- #endif
- }
- }
-
- return true;
- }
- bool CVtmLoaderFSM::CheckIfNeedCopyDepFiles()
- {
- //check if exist root.ini
- CSimpleStringA csTmpRootIni("");
- if (!IsRootINIExist(csTmpRootIni))
- {
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("not exist root.ini, no need copy dep files.");
- return false;
- }
- //check if exist run/dep/depver.txt
- CSimpleStringA csRun(true), csPath(true);
- ErrorCodeEnum eErr = GetEntityBase()->GetFunction()->GetPath("Run", csRun);
- if (eErr != Error_Succeed)
- {
- DbgWithLink(LOG_LEVEL_ERROR, LOG_TYPE_SYSTEM)("get path of Run failed:%s", SpStrError(eErr));
- return false;
- }
- csPath = csRun + SPLIT_SLASH_STR + "dep" + SPLIT_SLASH_STR + "depver.txt";
- #if defined(RVC_OS_WIN)
- if (_access(csPath.GetData(), 0) == 0) {
- #else
- if (access(csPath.GetData(), F_OK) == 0) {
- #endif
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("depver.txt(%s) exist, no need to do dep copy.", csPath.GetData());
- return false;
- }
- else
- {
- DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM)("depver.txt(%s) is not exist.", csPath.GetData());
- return true;
- }
- }
- void CVtmLoaderFSM::CopyDepFilesToNewDepPath()
- {
- //create run/dep/0.0.0.1 directory
- CSimpleStringA csRun(true), csDepBakPath(true), csPath(true);
- ErrorCodeEnum eErr = GetEntityBase()->GetFunction()->GetPath("Run", csRun);
- if (eErr != Error_Succeed)
- {
- DbgWithLink(LOG_LEVEL_ERROR, LOG_TYPE_SYSTEM)("get path of Run failed:%s", SpStrError(eErr));
- m_eDepCopyStage = DepDirInitCopy_CopyFailed;
- return;
- }
- csPath = csRun + SPLIT_SLASH_STR + "dep" + SPLIT_SLASH_STR + "0.0.0.1";
- if (!CreateDirA(csPath.GetData(), TRUE))
- {//TODO: CrossPlaform [Gifur@2025730]
- #ifdef RVC_OS_WIN
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("Create default dep version dir fail: %d", GetLastError());
- #else
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("Create default dep version dir fail: %d", errno);
- #endif
- m_eDepCopyStage = DepDirInitCopy_CopyFailed;
- return;
- }
- else
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("Create default dep version dir %s suc", csPath.GetData());
- eErr = GetEntityBase()->GetFunction()->GetPath("DepBak", csDepBakPath);
- if (eErr != Error_Succeed)
- {
- DbgWithLink(LOG_LEVEL_ERROR, LOG_TYPE_SYSTEM)("get path of DepBak failed:%s", SpStrError(eErr));
- m_eDepCopyStage = DepDirInitCopy_CopyFailed;
- return;
- }
- //xcopy C:\sourceDir C:\destDir /E /I /Y
- //cp -r /path/to/source /path/to/destination
- std::string sucContent, failedContent;
- CSimpleStringA strCmd;
- #if defined(RVC_OS_WIN)
- strCmd = CSimpleStringA::Format("cmd.exe /c xcopy %s %s /E /I /Y", csDepBakPath.GetData(), csPath.GetData());
- #else
- strCmd = CSimpleStringA::Format("cp -r -f %s/* %s", csDepBakPath.GetData(), csPath.GetData());
- #endif //RVC_OS_WIN
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("to execute:%s", strCmd.GetData());
- ULONGLONG ullCopyBeginTick = SP::Module::Comm::RVCGetTickCount();
- bool ret = SP::Module::Util::ShellExecute(strCmd.GetData(), sucContent, failedContent);
- ULONGLONG ullCopyEndTick = SP::Module::Comm::RVCGetTickCount();
- 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);
- if (ret)
- {
- //更新适配器版本号文件内容
- CSimpleStringA csVersion("0.0.0.1");
- eErr = GetEntityBase()->GetFunction()->GetPrivilegeFunction()->RewriteDepVersion(csVersion, true);
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("[RewriteDepVersion] %s,%s", SpStrError(eErr), csVersion.GetData());
- m_eDepCopyStage = DepDirInitCopy_CopySuc;
- LogWarn(Severity_Low, Error_Succeed, VtmLoader_DepDirCopySuc, CSimpleStringA::Format("%d", ullCopyEndTick - ullCopyBeginTick));
- }
- else
- {
- m_eDepCopyStage = DepDirInitCopy_CopyFailed;
- DbgWithLink(LOG_LEVEL_ERROR, LOG_TYPE_SYSTEM).setResultCode("RTA1F08")("copy dep to new dep path failed, failedContent:%s", failedContent.c_str());
- }
- }
- bool CVtmLoaderFSM::IfInExcludedLoadList(CSimpleStringA csEntityName)
- {
- if (csEntityName.IsNullOrEmpty())
- return true;
- for (int i = 0; i < m_arrExCludedList.GetCount(); ++i)
- {
- if (csEntityName.Compare(m_arrExCludedList[i], true) == 0)
- return true;
- }
- return false;
- }
- void CVtmLoaderFSM::DoSpecialJobInTestRoom()
- {
- //special job including the following things:
- //1.switch to the terminal app version you want
- //2.delete other version directory you want
- //3.just do it simple and straightforward
- CSmartPointer<IConfigInfo> spConfigCen, spRunCfg;
- if (GetEntityBase()->GetFunction()->OpenConfig(Config_CenterSetting, spConfigCen) == Error_Succeed)
- {
- CSimpleStringA csHaveSwitchVerTo("");
- ErrorCodeEnum eErr = GetEntityBase()->GetFunction()->OpenConfig(Config_Run, spRunCfg);
- if (eErr == Error_Succeed)
- spRunCfg->ReadConfigValue(GetEntityBase()->GetEntityName(), "HaveSwitchVerTo", csHaveSwitchVerTo);
- CSimpleStringA csSwitchVerTo("");
- spConfigCen->ReadConfigValue(GetEntityBase()->GetEntityName(), "SwitchVerTo", csSwitchVerTo);
- DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("SwitchVerTo:[%s], HaveSwitchVerTo:[%s]", csSwitchVerTo.GetData(), csHaveSwitchVerTo.GetData());
- if (csSwitchVerTo.IsNullOrEmpty() || csSwitchVerTo.Compare(csHaveSwitchVerTo) == 0)
- return;
- //更新终端应用版本号文件内容
- CSimpleStringA csRun(true), csActiveFilePath(true);
- eErr = GetEntityBase()->GetFunction()->GetPath("Run", csRun);
- if (eErr != Error_Succeed)
- {
- DbgWithLink(LOG_LEVEL_ERROR, LOG_TYPE_SYSTEM)("get path of Run failed:%s", SpStrError(eErr));
- return;
- }
- csActiveFilePath = csRun + SPLIT_SLASH_STR + "version" + SPLIT_SLASH_STR + "active.txt";
- HANDLE hFile = ::CreateFileA(csActiveFilePath.GetData(), GENERIC_WRITE, 0, NULL, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
- BOOL bSetSucc = FALSE;
- if (hFile == INVALID_HANDLE_VALUE)
- {
- DbgWithLink(LOG_LEVEL_ERROR, LOG_TYPE_SYSTEM)("open %s failed! err=%u", csActiveFilePath, GetLastError());
- return;
- }
- DWORD dwWrittenLen(0);
- bSetSucc = WriteFile(hFile, csSwitchVerTo.GetData(), csSwitchVerTo.GetLength(), &dwWrittenLen, NULL);
- FlushFileBuffers(hFile);
- SetEndOfFile(hFile);
- CloseHandle(hFile);
- spRunCfg->WriteConfigValue(GetEntityBase()->GetEntityName(), "HaveSwitchVerTo", csSwitchVerTo.GetData());
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("write version [%s] succeed", csSwitchVerTo.GetData());
- #if defined(RVC_OS_LINUX)
- if (bSetSucc) {
- mode_t f_attrib = S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | S_IWGRP | S_IXGRP | S_IROTH | S_IXOTH | S_IWOTH;
- chmod(csActiveFilePath.GetData(), f_attrib);
- }
- else {
- DbgWithLink(LOG_LEVEL_ERROR, LOG_TYPE_SYSTEM)("bSetSucc fail");
- }
- #endif //RVC_OS_LINUX
- Sleep(10000);
- GetEntityBase()->GetFunction()->GetPrivilegeFunction()->Reboot(RebootTrigger_ManualLocal, RebootWayEnum::RebootWay_Framework);
- }
- }
- DWORD CVtmLoaderFSM::GetCenterCfgThread()
- {
- bool isUpdate = false, isReset = false;
- CSimpleString version;
- if (false == GetEntityBase()->GetFunction()->HasPrivilege())
- {
- LogWarn(Severity_High, Error_Unexpect, VtmLoader_CenterSettingConnectFailed,
- CSimpleStringA::Format("下载集中配置失败:%s do not has privilege", __FUNCTION__));
- DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_USER).setLogCode("QLR0402101Z01").setResultCode("RTA1104")("集中配置下载失败");
- return -1;
- }
- auto ret = GetEntityBase()->GetFunction()->GetPrivilegeFunction()->TryUpdateCenterCfg(isUpdate, isReset, version);
- if (ret != ErrorCodeEnum::Error_Succeed)
- {
- LogWarn(Severity_High, Error_Unexpect, VtmLoader_CenterSettingConnectFailed,
- CSimpleStringA::Format("下载集中配置失败:%s", SpStrError(ret)));
- DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_USER).setLogCode("QLR0402101Z01").setResultCode("RTA1104")("集中配置下载失败");
- return -1;
- }
- if (!isUpdate)
- {
- return -1;
- }
- LogWarn(Severity_Low, Error_Succeed, VtmLoader_CenterSettingUpdateSucceed,
- CSimpleStringA::Format("下载集中配置成功,版本号变更成:%s", version.GetData()));
- if (isReset)
- LogEvent(Severity_Middle, EVENT_MOD_CENTERSETTING_CRITICAL_UPDATE, "SpShell:Update centersetting with critical items.");
- return 0;
- }
- void CVtmLoaderFSM::OnCentersettingUpdateTimeout(void* pData)
- {
- GetCenterCfgThread();
- GetEntityBase()->GetFunction()->ResetTimer(TIMER_CENTERSETTING_UPDATE_CHECK, CENTERSETTING_UPDATE_CHECK_TIME);
- }
- CSimpleStringA CVtmLoaderFSM::GetOsVersion()
- {
- #if defined(RVC_OS_WIN)
- CSimpleStringA runInfoPath;
- ErrorCodeEnum eErr = GetEntityBase()->GetFunction()->GetPath("runinfo", runInfoPath);
- if (eErr != Error_Succeed) {
- DbgWithLink(LOG_LEVEL_ERROR, LOG_TYPE_SYSTEM).setResultCode(RTAERR_GETPATH_FAILED)("GetPath runinfo error=%d.", eErr);
- return "";
- }
- runInfoPath += "\\runcfg\\osverion";
- CSimpleStringA csCmd;
- csCmd = CSimpleStringA::Format("cmd /c ver >%s", runInfoPath);
- WinExec((LPCSTR)csCmd, SW_HIDE);
- ifstream is;
- is.open(runInfoPath.GetData(), ios::binary);
- if (is.is_open())
- {
- string line;
- while (!is.eof()) {
- getline(is, line);
- int start = line.find("版本");
- if (start != string::npos)
- {
- DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("ver:[%s]", line.c_str());
- return CSimpleStringA(line.c_str());
- }
- else
- continue;
- }
- }
- else
- {
- DWORD dwErr = GetLastError();
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("open runcfg\\osverion file failed. [%d]", dwErr);
- }
- return "";
- #else
- std::map<std::string, std::string> osInfo;
- const char filePath[] = "/etc/os-version";
- char tmp[33];
- memset(tmp, 0, 33);
- inifile_read_str_s("Version", "SystemName", "unknown", tmp, 32, filePath);
- osInfo["SystemName"] = tmp;
- memset(tmp, 0, 33);
- inifile_read_str_s("Version", "ProductType", "unknown", tmp, 32, filePath);
- osInfo["ProductType"] = tmp;
- memset(tmp, 0, 33);
- inifile_read_str_s("Version", "MajorVersion", "unknown", tmp, 32, filePath);
- osInfo["MajorVersion"] = tmp;
- memset(tmp, 0, 33);
- inifile_read_str_s("Version", "MinorVersion", "unknown", tmp, 32, filePath);
- osInfo["MinorVersion"] = tmp;
- memset(tmp, 0, 33);
- inifile_read_str_s("Version", "OsBuild", "unknown", tmp, 32, filePath);
- osInfo["OsBuild"] = tmp;
- return generateJsonStr(osInfo).second.c_str();
- #endif
- }
- void CVtmLoaderFSM::QueryLocalInfo(SpReqAnsContext<VtmLoaderService_QueryLocalInfo_Req, VtmLoaderService_QueryLocalInfo_Ans>::Pointer ctx)
- {
- #ifdef RVC_OS_WIN
- ctx->Ans.VtmAppType = "Windows";
- #else
- ctx->Ans.VtmAppType = "UOS";
- #endif
- CSimpleStringA csRunPath("");
- GetEntityBase()->GetFunction()->GetPath("Run", csRunPath);
- ctx->Ans.AppPath = csRunPath;
- CAutoArray<NetworkAdapterItem> netList;
- if (SP::Module::Net::GetINETMacAddresses(netList) == Error_Succeed)
- {
- CSimpleStringA csMac(""), csIP("");
- for (int i = 0; i < netList.GetCount(); i++) {
- if (!csMac.IsNullOrEmpty()) {
- csMac += ";";
- }
- csMac += netList[i].mac.c_str();
- if (!csIP.IsNullOrEmpty()) {
- csIP += ";";
- }
- csIP += netList[i].ip.c_str();
- }
- ctx->Ans.IPs = csIP;
- ctx->Ans.MACs = csMac;
- }
- ctx->Ans.DNSs = GetDns();
- ctx->Ans.OSVersion = GetOsVersion();
- ctx->Answer(Error_Succeed);
- }
|