VtmLoaderFSM.cpp 110 KB

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