1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007 |
- #include "stdafx.h"
- #include <algorithm>
- #include <winpr/file.h>
- #include "fileutil.h"
- #include "VtmLoaderFSM.h"
- #include "VtmLoader_UserCode.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());
- 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()
- {
- 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);
- }
- }
- 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;
- 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:
- {
- //oiltmp@20240415 to be delete after x months
- if (_strnicmp("CardIssuer", it->first, it->first.GetLength()) == 0)
- {
- if (m_sysInfo.strMachineType.Compare("RVC.CardStore") == 0 || m_sysInfo.strMachineType.Compare("RVC.CardPrinter") == 0)
- pFuncPrivilege->StartEntity("CardIssuerStore", NULL, spWait);
- else
- pFuncPrivilege->StartEntity("CardIssuerStand", NULL, spWait);
- }
- else
- 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_BootInfoPrint, 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;
- 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;
- 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)) {
- 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
- 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);
- }
- }
- 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()));
- }
- //if have PinPad module
- //if (m_sysInfo.strMachineType.Compare("RVC.CardStore", true) == 0)
- // csCoreBootList = "HealthManager=0|TokenKeeper=0|Alarm=0|UpgradeManager=0|DeviceControl=0|ResourceWatcher=0|AccessAuthorization=0|HeartBeat=0|EventConverter=0|CenterSetting=0";
- //else
- // csCoreBootList = "HealthManager=0|TokenKeeper=0|Alarm=0|UpgradeManager=0|DeviceControl=0|ResourceWatcher=0|AccessAuthorization=0|HeartBeat=0|EventConverter=0|CenterSetting=0|PinPad=0";
- }
- 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;
- 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("");
- ErrorCodeEnum eErrCode = GetEntityBase()->GetFunction()->GetSysVar("TerminalStage", csTermStage);
- 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()
- {
- //拉取配置前先检查root.ini文件
- CSimpleStringA csTmpRootIni("");
- if (!IsRootINIExist(csTmpRootIni) && m_terminalNoFromWeb.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
- eErr = SubscribeEntitysEvents();
- if (eErr != Error_Succeed)
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("subscribe event fail, 0x%x", eErr);
- else
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("subscribe event succeed");
- 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;
- }
- ErrorCodeEnum CVtmLoaderFSM::SubscribeEntitysEvents()
- {
- //want to do what?
- auto rc = Error_Succeed;
- return rc;
- }
- 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());
- 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)
- {
- string tmpDns;
- GetDns(tmpDns);
- 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.c_str()).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;
- }
- void CVtmLoaderFSM::GetDns(string& dns)
- {
- dns = "";
- #if defined(RVC_OS_LINUX)
- FILE* stream;
- char* line = NULL;
- size_t len = 0;
- ssize_t read;
- stream = popen("cat /etc/resolv.conf", "r");
- string tmpStr;
- while ((read = getline(&line, &len, stream)) != -1)
- {
- tmpStr = line;
- int pos = tmpStr.find("nameserver");
- if (pos != string::npos)
- {
- tmpStr = tmpStr.replace(pos, strlen("nameserver"), "dns");
- dns += tmpStr + ";";
- }
- }
- int rnPos = dns.find("\n");
- while (rnPos != string::npos)
- {
- dns.replace(rnPos, 1, " ");
- rnPos = dns.find("\n");
- }
- #else
- #endif
- return;
- }
- 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;
- //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";
- }
- 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;
- }
- 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"))
- {
- LogWarn(Severity_High, Error_Unexpect, VtmLoader_BootInfoPrint, CSimpleStringA::Format("机型(%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))
- {
- #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;
- }
- 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);
- }
- }
|