VtmLoaderFSM.cpp 109 KB

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