VtmLoaderFSM.cpp 117 KB

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