VtmLoaderFSM.cpp 113 KB

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