mod_healthmanager.cpp 123 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661
  1. // mod_healthmanager.cpp : Defines the exported functions for the DLL application.
  2. //
  3. #include "stdafx.h"
  4. #if defined(RVC_OS_WIN)
  5. #include <TlHelp32.h>
  6. #include <iphlpapi.h>
  7. #include <ws2tcpip.h>
  8. #include <Winsock2.h>
  9. #pragma comment( lib, "User32.lib" )
  10. #pragma comment( lib, "advapi32.lib" )
  11. #pragma comment(lib, "IPHLPAPI.lib")
  12. #include "..\mod_chromium\Chromium_client_g.h" //启动浏览器接口
  13. using namespace Chromium;
  14. #include <WinUser.h>
  15. #else
  16. #include <sys/wait.h>
  17. #include <unistd.h>
  18. #include <time.h>
  19. #include <signal.h>
  20. #include <dlfcn.h>
  21. #include <fcntl.h>
  22. #include <sys/reboot.h>
  23. #endif //RVC_OS_WIN
  24. #include <vector>
  25. #include <iostream>
  26. #include <fstream>
  27. #include "toolkit.h"
  28. #include "array.h"
  29. #include "fileutil.h"
  30. #include "iniutil.h"
  31. #include "osutil.h"
  32. #if defined(RVC_OS_LINUX)
  33. #include "EntityBootStruct.h"
  34. #include <regex.h>
  35. #include "RestfulFunc.h"
  36. #include "api_manage_list.h"
  37. #include "api_manufacture_controller.h"
  38. #include "JsonConvertHelper.hpp"
  39. #endif
  40. using namespace std;
  41. #include "mod_healthmanager.h"
  42. #include "CommEntityUtil.hpp"
  43. #include "GetDevInfoHelper.h"
  44. #include "TerminalInfoQueryConn.h"
  45. const DWORD HEALTHMANAGER_TIMER_ID = 1;
  46. const DWORD HEALTHMANAGER_WAIT_MAINPAGE_OPEN_TIMER_ID = 2;
  47. const DWORD HEALTHMANAGER_TIMER_INTERVAL = 60000;
  48. const DWORD HEALTHMANAGER_WAIT_MAINPAGE_OPEN_TIMER_INTERVAL = 60000;
  49. const DWORD HEALTHMANAGER_TIMER_INTERVAL_MINUTE = (HEALTHMANAGER_TIMER_INTERVAL/60000)*3;
  50. #define WORKING_BUFFER_SIZE 15000
  51. #define MAX_TRIES 3
  52. #define MALLOC(x) HeapAlloc(GetProcessHeap(), 0, (x))
  53. #define FREE(x) HeapFree(GetProcessHeap(), 0, (x))
  54. #if defined(RVC_OS_LINUX)//oiltmp
  55. #include "CenterSetting_client_g.h"
  56. using namespace CenterSetting;
  57. //for defines in header file
  58. #include "CameraConfigManage_def_g.h"
  59. using namespace CameraConfigManage;
  60. #include "Chromium_client_g.h"
  61. using namespace Chromium;
  62. #endif
  63. template<class T>
  64. class TimerOutHelper : public ITimerListener
  65. {
  66. public:
  67. typedef void (T::*FuncTimer)();
  68. TimerOutHelper(T *p, FuncTimer pTimerFunc, bool bDeleteSelf = false)
  69. : m_pObject(p), m_pTimer(pTimerFunc), m_bDeleteSelf(bDeleteSelf) {}
  70. virtual void OnTimeout(DWORD dwTimerID)
  71. {
  72. (m_pObject->*m_pTimer)();
  73. if (m_bDeleteSelf)
  74. delete this;
  75. }
  76. private:
  77. T *m_pObject;
  78. FuncTimer m_pTimer;
  79. bool m_bDeleteSelf;
  80. };
  81. static void PrintTerminalRegistInfo(const TerminalRegistRet* info)
  82. {
  83. Dbg("TerminalNo: %s", info->TerminalNo);
  84. Dbg("DeviceNo: %s", info->DeviceNo);
  85. Dbg("OutletNo: %s", info->OutletNo);
  86. Dbg("Initializer: %s", info->Initializer);
  87. Dbg("PadDeviceID: %s", info->PadDeviceID);
  88. Dbg("MachineType: %s", info->MachineType);
  89. Dbg("MachineVersion: %s", info->MachineVersion);
  90. Dbg("Sites: %s", info->Sites);
  91. Dbg("EnrolAddr: %s", info->EnrolAddr);
  92. Dbg("Editor: %s", info->Editor);
  93. Dbg("State: %c", info->State);
  94. Dbg("PublicKey: %s", info->PublicKey);
  95. Dbg("FingerPrint: %s", info->FingerPrint);
  96. }
  97. void HealthManagerSession::Handle_EnterState(SpReqAnsContext<HealthManagerService_EnterState_Req, HealthManagerService_EnterState_Ans>::Pointer ctx)
  98. {
  99. LOG_FUNCTION();
  100. m_pEntity->EnterState(ctx);
  101. }
  102. void HealthManagerSession::Handle_ExitState(SpReqAnsContext<HealthManagerService_ExitState_Req, HealthManagerService_ExitState_Ans>::Pointer ctx)
  103. {
  104. LOG_FUNCTION();
  105. m_pEntity->ExitState(ctx);
  106. }
  107. void HealthManagerSession::Handle_DoEvent(SpReqAnsContext<HealthManagerService_DoEvent_Req, HealthManagerService_DoEvent_Ans>::Pointer ctx)
  108. {
  109. LOG_FUNCTION();
  110. m_pEntity->DoEvent(ctx);
  111. }
  112. void HealthManagerSession::Handle_GetEntityCfgInfo(SpReqAnsContext<HealthManagerService_GetEntityCfgInfo_Req, HealthManagerService_GetEntityCfgInfo_Ans>::Pointer ctx)
  113. {
  114. m_pEntity->GetEntityCfgInfo(ctx);
  115. }
  116. void HealthManagerSession::Handle_GetNetworkState(SpReqAnsContext<HealthManagerService_GetNetworkState_Req, HealthManagerService_GetNetworkState_Ans>::Pointer ctx)
  117. {
  118. m_pEntity->GetNetworkState(ctx);
  119. }
  120. void HealthManagerSession::Handle_QueryHardwareInfo(SpReqAnsContext<HealthManagerService_QueryHardwareInfo_Req, HealthManagerService_QueryHardwareInfo_Ans>::Pointer ctx)
  121. {
  122. m_pEntity->QueryHardwareInfo(ctx);
  123. }
  124. void HealthManagerSession::Handle_ReadCenterConfigStr(SpReqAnsContext<HealthManagerService_ReadCenterConfigStr_Req, HealthManagerService_ReadCenterConfigStr_Ans>::Pointer ctx)
  125. {
  126. LOG_FUNCTION();
  127. }
  128. void HealthManagerSession::Handle_GetAuthErrMsg(SpReqAnsContext<HealthManagerService_GetAuthErrMsg_Req, HealthManagerService_GetAuthErrMsg_Ans>::Pointer ctx)
  129. {
  130. m_pEntity->GetAuthErrMsg(ctx);
  131. }
  132. void HealthManagerSession::Handle_ControlTerminalLife(
  133. SpReqAnsContext<HealthManagerService_ControlTerminalLife_Req, HealthManagerService_ControlTerminalLife_Ans>::Pointer ctx)
  134. {
  135. LOG_FUNCTION();
  136. m_pEntity->ControlTerminalLife(ctx);
  137. }
  138. void HealthManagerSession::Handle_DeployTerminal(SpReqAnsContext<HealthManagerService_DeployTerminal_Req, HealthManagerService_DeployTerminal_Ans>::Pointer ctx)
  139. {
  140. LOG_FUNCTION();
  141. m_pEntity->DeployTerminal(ctx);
  142. }
  143. void HealthManagerSession::Handle_ControlEntityLife(SpReqAnsContext<HealthManagerService_ControlEntityLife_Req, HealthManagerService_ControlEntityLife_Ans>::Pointer ctx)
  144. {
  145. LOG_FUNCTION();
  146. m_pEntity->ControlEntityLife(ctx);
  147. }
  148. void HealthManagerSession::Handle_Gateway(SpReqAnsContext<HealthManagerService_Gateway_Req, HealthManagerService_Gateway_Ans>::Pointer ctx)
  149. {
  150. LOG_FUNCTION();
  151. m_pEntity->Gateway(ctx);
  152. }
  153. //通过当前实施步骤判断当前为第几次的临时重启
  154. static inline int GetDeployStepFromStatus(int status)
  155. {
  156. int result(-1);
  157. switch (status) {
  158. case DeployStep_Begin:
  159. case DeployStep_3rdParty_FontInstall:
  160. case DeployStep_3rdParty_SogouInstall:
  161. case DeployStep_GetTerminalInfo:
  162. result = 0;
  163. break;
  164. case DeployStep_AdapterConfig:
  165. result = 1;
  166. break;
  167. case DeployStep_MediaConfig:
  168. case DeployStep_FetchCenterSettings:
  169. case DeployStep_AccessAuthorize:
  170. result = 2;
  171. break;
  172. default:
  173. result = 0;
  174. break;
  175. }
  176. return result;
  177. }
  178. /**
  179. TerminalStage
  180. A: 准入通过?
  181. C: 准入不通过?
  182. D:设备故障
  183. B:
  184. N:
  185. U:
  186. */
  187. void CHealthManagerEntity::OnStarted()
  188. {
  189. #if defined(RVC_OS_LINUX)
  190. ErrorCodeEnum result(Error_NotInit);
  191. int curStep(0);
  192. m_fConfigMode = IsNotConfigMode(curStep);
  193. if (m_fConfigMode) {
  194. //kill guardin process if exists
  195. char* relates[] = { "guardian" };
  196. alive_process_info processes[1];
  197. memset(processes, 0, sizeof(processes));
  198. int count = 1;
  199. osutil_detect_unique_app(relates, array_size(relates), &count, processes);
  200. if (count > 0) {
  201. DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("to kill guardian process which is seem alive.");
  202. osutil_terminate_related_process(relates, array_size(relates));
  203. }
  204. if (curStep >= 0) {
  205. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("Change Framework status to NotConfig");
  206. this->GetFunction()->GetPrivilegeFunction()->RefreshFrameworkState(FrameworkState_NotConfig);
  207. }
  208. //挑一个状态判断为配置模式,以此操作其他实体的逻辑,比如:
  209. //集中配置实体不因无集中配置文件进行弹窗报错
  210. //初始化实体不会自行进行准入验证
  211. CSimpleStringA strSysValue = CSimpleStringA::Format("Z=%d", curStep);
  212. result = GetFunction()->SetSysVar("TerminalStage", strSysValue);
  213. DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("update TerminalStage=%s return %s", strSysValue.GetData(), SpStrError(result));
  214. /** 安装的时候是否需要延迟,毕竟涉及到重启 [Gifur@202231]*/
  215. m_fsm.WaitALittleIfNecessary();
  216. CSimpleStringA machineType = SP::Module::Comm::GetCurrMachineType(this);
  217. CSimpleStringA configPath = SP::Module::Comm::GetCurrEntityConfigPath(this);
  218. const int stepCount = GetDeployStepFromStatus(curStep);
  219. for (int i = stepCount, j=0; i >= 0; --i, j++) {
  220. switch (j) {
  221. case 0:
  222. {
  223. DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("Initial Boot Step.");
  224. std::shared_ptr<TerminalDeployStep> step = std::make_shared<TerminalDeployStep>("");
  225. step->LoadConfig(configPath);
  226. result = step->StartStartupEntities(this);
  227. if (result != Error_Succeed) {
  228. LogError(Severity_Middle, result, 0, CSimpleStringA::Format("Initial Boot Step failed: %s", SpStrError(result)));
  229. return;
  230. }
  231. }
  232. break;
  233. case 1:
  234. {
  235. DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("Second Boot Step.");
  236. LOG_ASSERT(!machineType.IsNullOrEmpty());
  237. std::shared_ptr<TerminalDeploySecondStep> step(nullptr);
  238. step = std::make_shared<TerminalDeploySecondStep>(machineType);
  239. step->LoadConfig(configPath);
  240. result = step->StartStartupEntities(this);
  241. if (result != Error_Succeed) {
  242. LogError(Severity_Middle, result, 0, CSimpleStringA::Format("Second Boot Step failed: %s", SpStrError(result)));
  243. return;
  244. }
  245. }
  246. break;
  247. case 2:
  248. {
  249. DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("Third Boot Step.");
  250. LOG_ASSERT(!machineType.IsNullOrEmpty());
  251. std::shared_ptr<TerminalDeployThirdStep> step(nullptr);
  252. step = std::make_shared<TerminalDeployThirdStep>(machineType);
  253. step->LoadConfig(configPath);
  254. result = step->StartStartupEntities(this);
  255. if (result != Error_Succeed) {
  256. LogError(Severity_Middle, result, 0, CSimpleStringA::Format("Third Boot Step failed: %s", SpStrError(result)));
  257. return;
  258. }
  259. }
  260. break;
  261. default:
  262. break;
  263. }
  264. }
  265. CSimpleStringA strUrl;
  266. result = GetGuidePageUrlWithStep(curStep, strUrl);
  267. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("Url:{%s}", (LPCTSTR)strUrl);
  268. result = TellChromiumOpenGuidePage(strUrl);
  269. }
  270. #else
  271. return;
  272. #endif
  273. }
  274. int CHealthManagerEntity::SystemRestart(bool bPeriod, bool bImmediately,bool bNow)
  275. {
  276. if (bPeriod)
  277. {
  278. DbgWithLink(LOG_LEVEL_INFO,LOG_TYPE_SYSTEM).setAPI("SystemRestart")("restart periodly.");
  279. m_restartTimes = 0;
  280. }
  281. if (bNow)
  282. {
  283. m_fsm.QuitFrameworkAndSaveInfo(m_eRebootTrigger, m_eRebootWay);
  284. int x = SystemShutdown(TRUE);
  285. DbgWithLink(LOG_LEVEL_INFO,LOG_TYPE_SYSTEM).setAPI("SystemRestart")("From ie to shutdown %d",x);
  286. return 0;
  287. }
  288. SYSTEMTIME localTime;
  289. GetLocalTimeRVC(localTime);
  290. CSmartPointer<IConfigInfo> spConfigRun;
  291. ErrorCodeEnum err = GetFunction()->OpenConfig(Config_Run, spConfigRun);
  292. if (err != Error_Succeed) {
  293. DbgWithLink(LOG_LEVEL_INFO,LOG_TYPE_SYSTEM).setAPI("SystemRestart")("open cfg file failed!");
  294. return -1;
  295. }
  296. //
  297. //ups restart
  298. if (m_pUpsClient != NULL)
  299. {
  300. if (!m_bToRestart)
  301. {
  302. m_restartTimes++;
  303. if (m_restartTimes > m_maxRestartTimes)
  304. {
  305. DbgWithLink(LOG_LEVEL_INFO,LOG_TYPE_SYSTEM).setAPI("SystemRestart")("restart too many times(%d,%d),give up.",m_restartTimes,m_maxRestartTimes);
  306. m_restartTimes--;
  307. return -1;
  308. }
  309. DbgWithLink(LOG_LEVEL_INFO,LOG_TYPE_SYSTEM).setAPI("SystemRestart")("the %d restart.",m_restartTimes);
  310. spConfigRun->WriteConfigValueInt("Run","RestartTimes",m_restartTimes);
  311. if (m_lastHour != localTime.wHour)
  312. {
  313. m_lastHour = localTime.wHour;
  314. DbgWithLink(LOG_LEVEL_INFO,LOG_TYPE_SYSTEM)("set last hour to %d", m_lastHour);
  315. spConfigRun->WriteConfigValueInt("Run", "LastHour", m_lastHour);
  316. }
  317. }
  318. else
  319. return 0;
  320. UpsService_Shutdown_Req req;
  321. UpsService_Shutdown_Ans ans;
  322. if (bImmediately)
  323. {
  324. req.ShutdownTime = 1;
  325. req.UpTime = 1;
  326. }
  327. else
  328. {
  329. req.ShutdownTime = 1;//oiltmp
  330. req.UpTime = 3; //oiltmp
  331. }
  332. ErrorCodeEnum eErrShutdown = m_pUpsClient->Shutdown(req,ans,10000);
  333. if (eErrShutdown == Error_Succeed)
  334. {
  335. //m_lastHour = localTime.wHour;
  336. DbgWithLink(LOG_LEVEL_INFO,LOG_TYPE_SYSTEM).setAPI("SystemRestart")("to shutdown");
  337. m_bToRestart = true;
  338. Sleep(20000);
  339. m_fsm.QuitFrameworkAndSaveInfo(m_eRebootTrigger,m_eRebootWay);
  340. int ret;
  341. if (m_bGetUpsStateFlag)
  342. ret = SystemShutdown();
  343. else
  344. ret = SystemShutdown(TRUE);
  345. DbgWithLink(LOG_LEVEL_INFO,LOG_TYPE_SYSTEM)("after ups,SystemShutdown result %d",ret);
  346. }
  347. else
  348. DbgWithLink(LOG_LEVEL_INFO,LOG_TYPE_SYSTEM)("shutdown failed(%d)",eErrShutdown);
  349. }
  350. else
  351. {
  352. DbgWithLink(LOG_LEVEL_INFO,LOG_TYPE_SYSTEM)("no ups,so to restart directly.");
  353. if (!m_bToRestart)
  354. {
  355. m_restartTimes++;
  356. if (m_restartTimes > m_maxRestartTimes)
  357. {
  358. DbgWithLink(LOG_LEVEL_INFO,LOG_TYPE_SYSTEM).setAPI("SystemRestart")("restart too many times(%d,%d),give up.",m_restartTimes,m_maxRestartTimes);
  359. m_restartTimes--;
  360. return -1;
  361. }
  362. DbgWithLink(LOG_LEVEL_INFO,LOG_TYPE_SYSTEM).setAPI("SystemRestart")("the %d restart.",m_restartTimes);
  363. spConfigRun->WriteConfigValueInt("Run","RestartTimes",m_restartTimes);
  364. if (m_lastHour != localTime.wHour)
  365. {
  366. m_lastHour = localTime.wHour;
  367. DbgWithLink(LOG_LEVEL_INFO,LOG_TYPE_SYSTEM).setAPI("SystemRestart")("set last hour to %d", m_lastHour);
  368. spConfigRun->WriteConfigValueInt("Run", "LastHour", m_lastHour);
  369. }
  370. //oilyang 20140606
  371. //framework to reboot os
  372. //int ret = SystemShutdown(TRUE);
  373. m_fsm.QuitFrameworkAndSaveInfo(m_eRebootTrigger,RebootWay_OS);
  374. //Dbg("no ups,SystemShutdown result %d",ret);
  375. }
  376. }
  377. return 0;
  378. }
  379. /** 这里建议改用调用框架提供的接口,关机、重启均支持 [Gifur@202135]*/
  380. //system api shutdown
  381. int CHealthManagerEntity::SystemShutdown(BOOL bReboot)
  382. {
  383. #ifdef RVC_OS_WIN
  384. HANDLE hToken; // handle to process token
  385. TOKEN_PRIVILEGES tkp; // pointer to token structure
  386. BOOL fResult; // system shutdown flag
  387. // Get the current process token handle so we can get shutdown
  388. // privilege.
  389. if (!OpenProcessToken(GetCurrentProcess(),
  390. TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &hToken))
  391. return FALSE;
  392. // Get the LUID for shutdown privilege.
  393. LookupPrivilegeValue(NULL, SE_SHUTDOWN_NAME,
  394. &tkp.Privileges[0].Luid);
  395. tkp.PrivilegeCount = 1; // one privilege to set
  396. tkp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
  397. // Get shutdown privilege for this process.
  398. AdjustTokenPrivileges(hToken, FALSE, &tkp, 0,
  399. (PTOKEN_PRIVILEGES) NULL, 0);
  400. // Cannot test the return value of AdjustTokenPrivileges.
  401. if (GetLastError() != ERROR_SUCCESS)
  402. return FALSE;
  403. // Display the shutdown dialog box and start the countdown.
  404. fResult = InitiateSystemShutdown(
  405. NULL, // shut down local computer
  406. NULL, // message for user
  407. 0, // time-out period, in seconds
  408. FALSE, // ask user to close apps
  409. bReboot); // reboot after shutdown
  410. if (!fResult)
  411. return FALSE;
  412. // Disable shutdown privilege.
  413. tkp.Privileges[0].Attributes = 0;
  414. AdjustTokenPrivileges(hToken, FALSE, &tkp, 0,
  415. (PTOKEN_PRIVILEGES) NULL, 0);
  416. return 0;
  417. #else
  418. sync();
  419. if (bReboot)
  420. system("init 6");
  421. else
  422. system("init 0");
  423. return 0;//oiltestlinux
  424. #endif //RVC_OS_WIN
  425. }
  426. ErrorCodeEnum CHealthManagerEntity::SystemShutdownThroughUPS(DWORD msPreShutdown, DWORD msPreRestart)
  427. {
  428. bool upsIsNull = true;
  429. ErrorCodeEnum result = Error_Unexpect;
  430. if (m_pUpsClient) {
  431. m_pUpsClient->GetFunction()->CloseSession();
  432. m_pUpsClient = NULL;
  433. upsIsNull = false;
  434. }
  435. m_pUpsClient = new UpsService_ClientBase(this);
  436. ErrorCodeEnum eErrConn = m_pUpsClient->Connect();
  437. if (eErrConn != Error_Succeed) {
  438. Dbg("Ups connected failed: %s", SpStrError(eErrConn));
  439. m_pUpsClient->SafeDelete();
  440. m_pUpsClient = NULL;
  441. return eErrConn;
  442. }
  443. do
  444. {
  445. UpsService_GetStatus_Req req;
  446. UpsService_GetStatus_Ans ans;
  447. ErrorCodeEnum eErrState = m_pUpsClient->GetStatus(req, ans, 3000);
  448. Dbg("current state %d", ans.Status);
  449. } while (false);
  450. do
  451. {
  452. UpsService_Shutdown_Req req;
  453. UpsService_Shutdown_Ans ans;
  454. req.ShutdownTime = msPreShutdown; //刚好可以等到框架退出
  455. req.UpTime = msPreRestart; //要求5分钟内拔掉电源来实现真正断电关机
  456. ErrorCodeEnum eErrShutdown = m_pUpsClient->Shutdown(req, ans, 10000);
  457. if (eErrShutdown == Error_Succeed) {
  458. Dbg("Invoke UPS::Shutdown successfully.");
  459. result = Error_Succeed;
  460. }
  461. else {
  462. CSimpleStringA tmp = CSimpleStringA::Format("通过UPS关机失败:%s", SpStrError(eErrShutdown));
  463. this->GetFunction()->ShowFatalError(tmp);
  464. result = eErrShutdown;
  465. }
  466. } while (false);
  467. if (upsIsNull && m_pUpsClient) {
  468. m_pUpsClient->GetFunction()->CloseSession();
  469. m_pUpsClient = NULL;
  470. }
  471. return result;
  472. }
  473. int CHealthManagerEntity::FrameworkShutdown(bool bRestart)
  474. {
  475. #if defined(RVC_OS_WIN)
  476. //oilyang@20211213 if reboot Framework,just call "pFuncPrivilege->Reboot";if shutdown only,call sprestart
  477. if (bRestart)
  478. {
  479. m_fsm.QuitFrameworkAndSaveInfo(m_eRebootTrigger, m_eRebootWay);
  480. return 0;
  481. }
  482. STARTUPINFO si;
  483. PROCESS_INFORMATION pi;
  484. ZeroMemory( &si, sizeof(si) );
  485. si.cb = sizeof(si);
  486. ZeroMemory( &pi, sizeof(pi) );
  487. GetFunction()->FlushLogFile();
  488. // LPTSTR szCmdline[] = _tcsdup(TEXT("\"C:\\Program Files\\MyApp\" -L -S"));
  489. //CreateProcess(NULL, szCmdline, /*...*/);
  490. // Start the child process.
  491. CSimpleStringA csRestart,csVerPath,csAll,csSep("\""),csBlank(" "),csScript("wscript.exe"),csReFlag("r");
  492. csRestart = "sprestart.exe ";
  493. ErrorCodeEnum Error = GetFunction()->GetPath("RootVer", csVerPath);
  494. //csVerPath +="\\spexplorerfast.vbs";
  495. csVerPath +="\\VTM.exe";
  496. if (!bRestart)
  497. csReFlag = "n";
  498. //csAll = csSep + csRestart + csSep + csBlank + csSep + csScript+csBlank + csVerPath + csSep
  499. // + csBlank + csSep + csReFlag + csSep;
  500. csAll = csSep + csRestart + csSep + csBlank + csSep + csVerPath + csSep
  501. + csBlank + csSep + csReFlag + csSep;
  502. DbgWithLink(LOG_LEVEL_INFO,LOG_TYPE_SYSTEM).setAPI("FrameworkShutdown")("allpath[%s]",(LPCTSTR)csAll);
  503. LPTSTR szCmdline = _strdup(csAll);
  504. if( !CreateProcess( NULL,szCmdline,NULL,NULL,FALSE,0,NULL,NULL,&si,&pi))
  505. {
  506. DbgWithLink(LOG_LEVEL_INFO,LOG_TYPE_SYSTEM).setAPI("FrameworkShutdown")("CreateProcess failed (%d).\n", GetLastError());
  507. return -1;
  508. }
  509. //MessageBoxA(0,0,0,0);
  510. DWORD dwErr = GetLastError();
  511. // Wait until child process exits.
  512. WaitForSingleObject( pi.hProcess, INFINITE );
  513. // Close process and thread handles.
  514. CloseHandle( pi.hProcess );
  515. CloseHandle( pi.hThread );
  516. return 0;
  517. #else
  518. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("FrameworkShutdown to call QuitFrameworkAndSaveInfo:%d,%d", m_eRebootTrigger, m_eRebootWay);
  519. m_fsm.QuitFrameworkAndSaveInfo(m_eRebootTrigger, m_eRebootWay);
  520. return 0;//oiltestlinux
  521. #endif
  522. }
  523. //almost disused.
  524. //the function moved to Entity "SelfChecker"
  525. ErrorCodeEnum CHealthManagerEntity::RestartModule(const char* pEntityName)
  526. {
  527. CSmartPointer<IEntityFunction> pFunc = GetFunction();
  528. CSmartPointer<IEntityFunctionPrivilege> pFuncPrivilege = pFunc.ConvertCase<IEntityFunctionPrivilege>();
  529. if (pFuncPrivilege == NULL)
  530. {
  531. DbgWithLink(LOG_LEVEL_INFO,LOG_TYPE_SYSTEM).setAPI("RestartModule")("restart mc NoPrivilege");
  532. return Error_NoPrivilege;
  533. }
  534. map<CSimpleStringA,ModuleRunInfo>::iterator it;
  535. it = m_modRunInfo.find(pEntityName);
  536. if (it == m_modRunInfo.end())
  537. {
  538. DbgWithLink(LOG_LEVEL_INFO,LOG_TYPE_SYSTEM).setAPI("RestartModule")("add %s to modfuninfo(%d).",pEntityName,m_modRunInfo.size());
  539. m_modRunInfo[pEntityName].count = 1;
  540. m_modRunInfo[pEntityName].dwStart = GetTickCountRVC();
  541. }
  542. else
  543. {
  544. (m_modRunInfo[pEntityName].count)++;
  545. DbgWithLink(LOG_LEVEL_INFO,LOG_TYPE_SYSTEM).setAPI("RestartModule")("modruninfo EntityName=%s, count=%d",pEntityName,m_modRunInfo[pEntityName].count);
  546. }
  547. CSmartPointer<IAsynWaitSp> spWait;
  548. ErrorCodeEnum eErrCode = Error_Succeed;
  549. eErrCode = pFuncPrivilege->TerminateEntity(pEntityName,spWait);
  550. if (spWait != NULL)
  551. eErrCode = spWait->WaitAnswer(10000);
  552. if (eErrCode != Error_Succeed)
  553. {
  554. DbgWithLink(LOG_LEVEL_INFO,LOG_TYPE_SYSTEM).setAPI("RestartModule")("kill %s %d",pEntityName,eErrCode);
  555. return eErrCode;
  556. }
  557. Sleep(3000);
  558. eErrCode = pFuncPrivilege->StartEntity(pEntityName,NULL,spWait);
  559. if (spWait != NULL)
  560. eErrCode = spWait->WaitAnswer(10000);
  561. if (eErrCode != Error_Succeed)
  562. {
  563. DbgWithLink(LOG_LEVEL_INFO,LOG_TYPE_SYSTEM).setAPI("RestartModule")("start %s %d",pEntityName,eErrCode);
  564. return eErrCode;
  565. }
  566. //m_modRestartCount++;
  567. //if (m_modRestartCount == 1)
  568. // m_MCStart = GetTickCount();
  569. DWORD dwMaxTimes,dwInternal;
  570. if (m_modCfgInfo.find(pEntityName) == m_modCfgInfo.end())
  571. {
  572. dwMaxTimes = m_restartMode[RESTART_MODE_DEFAULT].dwTimes;
  573. dwInternal = m_restartMode[RESTART_MODE_DEFAULT].dwInternal;
  574. }
  575. else
  576. {
  577. dwMaxTimes = m_restartMode[m_modCfgInfo[pEntityName]].dwTimes;
  578. dwInternal = m_restartMode[m_modCfgInfo[pEntityName]].dwInternal;
  579. }
  580. DbgWithLink(LOG_LEVEL_INFO,LOG_TYPE_SYSTEM).setAPI("RestartModule")("RestartModule %d,%d,%s restart %d times",dwMaxTimes,dwInternal,pEntityName,m_modRunInfo[pEntityName].count);
  581. if (m_modRunInfo[pEntityName].count > dwMaxTimes)
  582. {
  583. m_MCEnd = GetTickCountRVC();
  584. if (m_MCEnd-m_modRunInfo[pEntityName].dwStart < dwInternal)
  585. {
  586. DbgWithLink(LOG_LEVEL_INFO,LOG_TYPE_SYSTEM).setAPI("RestartModule")("wait chance to restart pc.");
  587. //if (_strnicmp(pEntityName, "FaceTracking", strlen("FaceTracking")) != 0)
  588. // m_bWaitRestartPC = true;
  589. }
  590. else
  591. {
  592. m_modRunInfo[pEntityName].dwStart = m_MCEnd;
  593. m_modRunInfo[pEntityName].count = 0;
  594. LogWarn(Severity_Low,Error_Unexpect,LOG_WARN_HEALTH_MODULE_RESTART_TIMES
  595. ,"restart x times in more than 10mins");
  596. }
  597. }
  598. return eErrCode;
  599. }
  600. void CHealthManagerEntity::AfterWaitRestartPC()
  601. {
  602. CSmartPointer<IEntityFunction> pFunc = GetFunction();
  603. CSmartPointer<IEntityFunctionPrivilege> pFuncPrivilege = pFunc.ConvertCase<IEntityFunctionPrivilege>();
  604. if (pFuncPrivilege == NULL)
  605. {
  606. DbgWithLink(LOG_LEVEL_INFO,LOG_TYPE_SYSTEM).setAPI("AfterWaitRestartPC")("restart pc NoPrivilege");
  607. return;
  608. }
  609. ErrorCodeEnum eErr;
  610. CSimpleStringA csCustomerHandle("");
  611. eErr = GetFunction()->GetSysVar("CustomerHandle",csCustomerHandle);
  612. DbgWithLink(LOG_LEVEL_INFO,LOG_TYPE_SYSTEM).setAPI("AfterWaitRestartPC")("cust handle %d,%s",eErr,(LPCTSTR)csCustomerHandle);
  613. if (eErr != Error_Succeed)
  614. {
  615. DbgWithLink(LOG_LEVEL_INFO,LOG_TYPE_SYSTEM).setAPI("AfterWaitRestartPC")("get CustomerHandle failed (%d).",eErr);
  616. }
  617. else if (csCustomerHandle[0] == 'N')
  618. {
  619. m_bWaitRestartPC = false;
  620. pFuncPrivilege->DisplayBlueScreen("暂停服务test");
  621. DbgWithLink(LOG_LEVEL_INFO,LOG_TYPE_SYSTEM).setAPI("AfterWaitRestartPC")("time comes,restart machine");
  622. m_eRebootTrigger = RebootTrigger_RunExcepition;
  623. m_eRebootWay = RebootWay_Power;
  624. SystemRestart(false, true);
  625. }
  626. }
  627. void CHealthManagerEntity::UpsSupplyLockScreen()
  628. {
  629. ErrorCodeEnum eErr;
  630. CSimpleStringA csCustomerHandle("");
  631. eErr = GetFunction()->GetSysVar("CustomerHandle",csCustomerHandle);
  632. DbgWithLink(LOG_LEVEL_INFO,LOG_TYPE_SYSTEM).setAPI("UpsSupplyLockScreen")("ups lock screen cust handle %d,%s",eErr,(LPCTSTR)csCustomerHandle);
  633. if (eErr != Error_Succeed)
  634. {
  635. DbgWithLink(LOG_LEVEL_INFO,LOG_TYPE_SYSTEM).setAPI("UpsSupplyLockScreen")("get CustomerHandle failed (%d).",eErr);
  636. }
  637. else// if (csCustomerHandle[0] == 'N')
  638. {
  639. CSmartPointer<IEntityFunction> pFunc = GetFunction();
  640. CSmartPointer<IEntityFunctionPrivilege> pFuncPrivilege = pFunc.ConvertCase<IEntityFunctionPrivilege>();
  641. if (pFuncPrivilege == NULL)
  642. {
  643. DbgWithLink(LOG_LEVEL_INFO,LOG_TYPE_SYSTEM).setAPI("UpsSupplyLockScreen")("display screen NoPrivilege");
  644. return;
  645. }
  646. pFuncPrivilege->DisplayBlueScreen("暂停服务");
  647. LogEvent(Severity_High,LOG_EVT_HEALTH_UPS_NO_ELECTOR,"ups no elector,to shutdown machine");
  648. DbgWithLink(LOG_LEVEL_INFO,LOG_TYPE_SYSTEM).setAPI("UpsSupplyLockScreen")("ups no elector,display screen.");
  649. //oiltmp eject card and sth else
  650. Sleep(30000);
  651. if (m_bUpsWaitLock)
  652. {
  653. m_bUpsWaitLock = false;
  654. m_bScreenLock = true;
  655. int ret = SystemShutdown();
  656. DbgWithLink(LOG_LEVEL_INFO,LOG_TYPE_SYSTEM).setAPI("UpsSupplyLockScreen")("SystemShutdown result %d",ret);
  657. }
  658. else
  659. {
  660. pFuncPrivilege->UndisplayBlueScreen();
  661. m_bUpsWaitLock = false;
  662. m_bScreenLock = false;
  663. }
  664. }
  665. }
  666. void CHealthManagerEntity::OnCheckTimeTimeout()
  667. {
  668. //oilyang@20220330 check if need restart framework by THE key CenterSetting updated.
  669. if (m_bToRestartByCenterSetting)
  670. {
  671. CSimpleStringA csTermStage("");
  672. ErrorCodeEnum eErrCode;
  673. eErrCode = GetFunction()->GetSysVar("TerminalStage", csTermStage);
  674. Dbg("OnCheckTimeTimeout::ToRestartByCenterSetting to get termstage %s", csTermStage.GetData());
  675. if (m_bInMainPage || csTermStage.Compare("A"))
  676. {
  677. DbgWithLink(LOG_LEVEL_INFO,LOG_TYPE_SYSTEM)("THE key CenterSetting updated,we must restart framework right now.");
  678. m_eRebootTrigger = RebootTrigger_Resource;
  679. m_eRebootWay = RebootWay_Framework;
  680. FrameworkShutdown();
  681. }
  682. }
  683. SYSTEMTIME localTime;
  684. GetLocalTimeRVC(localTime);
  685. ErrorCodeEnum eErr = Error_Unexpect;
  686. //oilyang@20211229 add for Initializer automaticly
  687. if (m_bInMainPage)
  688. {
  689. //not work time
  690. CSmartPointer<IConfigInfo> spCerConfig;
  691. eErr = GetFunction()->OpenConfig(Config_CenterSetting, spCerConfig);
  692. int xTmpWorktime = 0;
  693. spCerConfig->ReadConfigValueInt(GetEntityName(), "WorkTimeStart", xTmpWorktime);
  694. if (xTmpWorktime >= 0 && xTmpWorktime <= 24)
  695. m_worktimeStart = xTmpWorktime;
  696. spCerConfig->ReadConfigValueInt(GetEntityName(), "WorkTimeEnd", xTmpWorktime);
  697. if (xTmpWorktime >= 0 && xTmpWorktime <= 24)
  698. m_worktimeEnd = xTmpWorktime;
  699. //oilyang@20230815 no need to do the useless things "cost so much,get almont none"
  700. //if (!(m_worktimeStart <= localTime.wHour && localTime.wHour < m_worktimeEnd))
  701. // m_fsm.CheckIfNeedAutoInit();
  702. }
  703. if (m_bNeedToRestartIE)
  704. {
  705. //oilyang 20160704
  706. //to judge in main page & the phone is offline
  707. CSimpleStringA csCustHandle("");
  708. eErr = GetFunction()->GetSysVar("CustomerHandle", csCustHandle);
  709. if (eErr == Error_Succeed)
  710. {
  711. if (csCustHandle.Compare("C") != 0 && csCustHandle.Compare("T") != 0 && csCustHandle.Compare("G") != 0)
  712. {
  713. if (m_bInMainPage)
  714. {
  715. //Dbg("to restart iebrowser.");
  716. DbgWithLink(LOG_LEVEL_INFO,LOG_TYPE_SYSTEM).setAPI("OnCheckTimeTimeout")("to restart iebrowser.");
  717. RestartIE();
  718. }
  719. }
  720. }
  721. }
  722. //99 is initial value of m_preDay
  723. if (m_preDay != 99 && m_preDay != localTime.wDayOfWeek && m_bNeedToRestartPAD == false)
  724. m_bNeedToRestartPAD = true;
  725. m_preDay = localTime.wDayOfWeek;
  726. CSmartPointer<IConfigInfo> spConfigRun;
  727. eErr = GetFunction()->OpenConfig(Config_Run, spConfigRun);
  728. if (eErr != Error_Succeed)
  729. DbgWithLink(LOG_LEVEL_INFO,LOG_TYPE_SYSTEM).setAPI("OnCheckTimeTimeout")("timer open cfg file failed!");
  730. else
  731. {
  732. if (localTime.wHour != m_lastHour)
  733. {
  734. spConfigRun->WriteConfigValueInt("Run", "RestartTimes", 0);
  735. }
  736. }
  737. if (_strnicmp(m_sysStaticInfo.strMachineType.GetData(), "RVC.PAD", strlen("RVC.PAD")) == 0)
  738. {
  739. if (m_bNeedToRestartPAD)
  740. {
  741. ULONGLONG ull = 0;
  742. ull = GetTickCountRVC();
  743. int osRunHours = 0, osRunDays = 0;
  744. osRunHours = (ull / (1000 * 60 * 60));
  745. osRunDays = osRunHours / 24;
  746. CSmartPointer<IConfigInfo> spConfigRun;
  747. ErrorCodeEnum eErr = GetFunction()->OpenConfig(Config_Run, spConfigRun);
  748. if (m_maxRunDays <= 0)
  749. m_maxRunDays = 7;
  750. if (osRunDays >= m_maxRunDays)
  751. {
  752. DbgWithLink(LOG_LEVEL_INFO,LOG_TYPE_SYSTEM).setAPI("OnCheckTimeTimeout")("os has run %d hour,to restart os.", osRunHours);
  753. spConfigRun->WriteConfigValueInt("Restart", "DayNum", 0);
  754. m_eRebootTrigger = RebootTrigger_Period;
  755. m_eRebootWay = RebootWay_Power;
  756. SystemRestart(true,true);
  757. }
  758. else if (osRunDays >= 1)
  759. {
  760. if (osRunDays > m_dayNum)
  761. {
  762. DbgWithLink(LOG_LEVEL_INFO,LOG_TYPE_SYSTEM).setAPI("OnCheckTimeTimeout")("os has run %d hour,to restart framework.", osRunHours);
  763. spConfigRun->WriteConfigValueInt("Restart", "DayNum", osRunDays);
  764. m_fsm.QuitFrameworkAndSaveInfo(RebootTrigger_Period, RebootWay_Framework);
  765. }
  766. }
  767. }
  768. }
  769. else //not RVC.PAD
  770. {
  771. if (m_wDayOfWeek != localTime.wDayOfWeek)
  772. {
  773. if (localTime.wHour == m_restartHour && localTime.wMinute >= m_restartMinute
  774. && localTime.wMinute <= (m_restartMinute + HEALTHMANAGER_TIMER_INTERVAL_MINUTE))
  775. {
  776. m_wDayOfWeek = localTime.wDayOfWeek;
  777. m_eRebootTrigger = RebootTrigger_Period;
  778. m_eRebootWay = RebootWay_Power;
  779. BOOL bRet = SystemRestart(true,true);
  780. DbgWithLink(LOG_LEVEL_INFO,LOG_TYPE_SYSTEM).setAPI("OnCheckTimeTimeout")("restart machine[%d][%d] bRet=%d, LastError=%d", localTime.wHour, localTime.wMinute, bRet, GetLastError()); }
  781. }
  782. }
  783. if (m_pUpsClient == NULL)
  784. {
  785. CSimpleStringA csRunState("B");
  786. GetFunction()->GetSysVar("RunState",csRunState);
  787. if (csRunState[0] != 'B' || csRunState[0] != 'I')
  788. {
  789. if (_strnicmp(m_sysStaticInfo.strMachineType.GetData(), "RVC.Stand2S", strlen("RVC.Stand2S") == 0))
  790. {
  791. int ret = ConnectUps();
  792. DbgWithLink(LOG_LEVEL_INFO,LOG_TYPE_SYSTEM).setAPI("OnCheckTimeTimeout")("connect ups %d.", ret);
  793. }
  794. }
  795. }
  796. else
  797. {
  798. UpsService_GetStatus_Req req;
  799. UpsService_GetStatus_Ans ans;
  800. ErrorCodeEnum eErrState = m_pUpsClient->GetStatus(req,ans,3000);
  801. if (eErrState == Error_Succeed)
  802. {
  803. m_bGetUpsStateFlag = true;
  804. switch(ans.Status)
  805. {
  806. case UPS_STATUS_NORMAL:
  807. m_bUpsWaitLock = false;
  808. m_upsNoElectorCount = 0;
  809. break;
  810. case UPS_STATUS_ERROR_TO_GET_STATUS:
  811. m_upsStateCount++;
  812. if (m_upsStateCount > 3)
  813. {
  814. //logwarn oiltmp
  815. }
  816. break;
  817. case UPS_STATUS_NO_ELECTOR:
  818. m_bUpsWaitLock = true;
  819. m_upsNoElectorCount++;
  820. if (m_upsNoElectorCount > 2)
  821. {
  822. //logwarn oiltmp
  823. //notify front end
  824. //shutdown pc or not?
  825. }
  826. break;
  827. default:
  828. break;
  829. }
  830. //Dbg("current state %d",ans.Status);
  831. }
  832. else
  833. {
  834. DbgWithLink(LOG_LEVEL_INFO,LOG_TYPE_SYSTEM).setAPI("OnCheckTimeTimeout")("get ups state failed(%d).",eErrState);
  835. m_bGetUpsStateFlag = false;
  836. if (eErrState == Error_NetBroken)
  837. {
  838. m_pUpsClient->GetFunction()->CloseSession();
  839. m_pUpsClient = NULL;
  840. }
  841. }
  842. }
  843. int iCheckGuardian = 0;
  844. if (m_fsm.GetFSMState() == HM_FSM_STATE_IDLE || (m_fsm.GetFSMState() == HM_FSM_STATE_CMS))
  845. {
  846. //oilyang@20210922 add comment
  847. //1、AccessAuth ok
  848. //2、have ever enter main page OR
  849. if (m_fsm.GetAccessAuthFlag() && (m_bEnterMainPageEver || (!m_bEnterMainPageEver && m_fsm.IfIEBeforeHealth())))//oilyang 20161219 改成通过是否成功进入主页来判断IE情况
  850. {
  851. iCheckGuardian = CheckGuardianIsRun(true);
  852. if (!m_bSayIdle)
  853. {
  854. m_bSayIdle = true;
  855. if (iCheckGuardian > 0)
  856. {
  857. if (m_pfUpgradeRestart != NULL)
  858. {
  859. eErr = m_pfUpgradeRestart(3, 0);
  860. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI("OnCheckTimeTimeout")("healthmanager say idle,so tell the guardian.%d", eErr);
  861. }
  862. }
  863. CSimpleStringA csRunInfo,csStartTime;
  864. if ((GetFunction()->GetPath("RunInfo",csRunInfo)) != Error_Succeed)
  865. {
  866. DbgWithLink(LOG_LEVEL_INFO,LOG_TYPE_SYSTEM).setAPI("OnCheckTimeTimeout")("get runinfo path failed");
  867. #if defined(RVC_OS_WIN)//oiltmp@20230801 ???为什么在失败时候要删除?
  868. DeleteFileA("d:\\Run\\runinfo\\runcfg\\starttime.dat");
  869. DeleteFileA("c:\\Run\\runinfo\\runcfg\\starttime.dat");
  870. #endif
  871. }
  872. else
  873. {
  874. #if defined(RVC_OS_WIN)
  875. csStartTime = csRunInfo + "\\runcfg\\starttime.dat";
  876. int ret = DeleteFileA(csStartTime);
  877. #else
  878. csStartTime = csRunInfo + "/runcfg/starttime.dat";
  879. int ret = remove(csStartTime);
  880. #endif
  881. if (ret == 0){
  882. DbgWithLink(LOG_LEVEL_INFO,LOG_TYPE_SYSTEM).setAPI("OnCheckTimeTimeout")("delete time file [%s] error.[%d]", csStartTime.GetData(),GetLastError());
  883. }else{
  884. //清理前次记录的guardian版本记录
  885. spConfigRun->WriteConfigValue("Run", "VersionEx", "");
  886. }
  887. }
  888. }
  889. if (iCheckGuardian > 0)
  890. {
  891. if (m_pfShake != NULL)
  892. {
  893. WorkStateEnum eShake;
  894. ErrorCodeEnum eErrShake = m_pfShake(eShake);
  895. }
  896. if (!m_bHealthInit)
  897. {
  898. DbgWithLink(LOG_LEVEL_INFO,LOG_TYPE_SYSTEM).setAPI("OnCheckTimeTimeout")("准备重新启动guardian");
  899. bool bStop = StopGuardian();
  900. if (bStop)
  901. {
  902. m_bHealthInit = true;
  903. bool bGuardian = StartGuardian();
  904. DbgWithLink(LOG_LEVEL_INFO,LOG_TYPE_SYSTEM).setAPI("OnCheckTimeTimeout")("restart guardian %d", bGuardian);
  905. }
  906. }
  907. }
  908. else if (iCheckGuardian == -1)
  909. {
  910. DbgWithLink(LOG_LEVEL_INFO,LOG_TYPE_SYSTEM).setAPI("OnCheckTimeTimeout")("未启动guardian,准备启动guardian");
  911. bool bGuardian = StartGuardian();
  912. DbgWithLink(LOG_LEVEL_INFO,LOG_TYPE_SYSTEM).setAPI("OnCheckTimeTimeout")("start guardian %d",bGuardian);
  913. }
  914. }
  915. else
  916. {
  917. //oilyang@20190905 add if auth suc,tell guardian,for upgrade
  918. if (m_fsm.GetAccessAuthFlag())
  919. {
  920. if (CheckGuardianIsRun(true) > 0)
  921. {
  922. if (m_pfUpgradeRestart != NULL)
  923. {
  924. eErr = m_pfUpgradeRestart(5, 0);
  925. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI("OnCheckTimeTimeout")("auth suc,so tell the guardian.%d", eErr);
  926. }
  927. }
  928. }
  929. }
  930. }
  931. else
  932. {
  933. m_bSayIdle = false;
  934. }
  935. //oilyang@20210331 if accessauth told me not to restart framework,so that it can have time to retry
  936. if (!m_bNeedGuardianRestart)
  937. {
  938. if (CheckGuardianIsRun(true) > 0)
  939. {
  940. if (m_pfShake != NULL)
  941. {
  942. WorkStateEnum eShake;
  943. eErr = m_pfShake(eShake);
  944. DbgWithLink(LOG_LEVEL_INFO,LOG_TYPE_SYSTEM).setAPI("OnCheckTimeTimeout")("accessauth told me not to restart framework,so that it can have time to retry.%d", eErr);
  945. }
  946. }
  947. }
  948. if (m_fsm.GetFSMState() == HM_FSM_STATE_CMS)
  949. {
  950. GetFunction()->ResetTimer(HEALTHMANAGER_TIMER_ID, HEALTHMANAGER_TIMER_INTERVAL);
  951. return;
  952. }
  953. if (m_bWaitRestartPC)
  954. {
  955. DbgWithLink(LOG_LEVEL_INFO,LOG_TYPE_SYSTEM).setAPI("OnCheckTimeTimeout")("finally we the restart time come,no wait.");
  956. //m_bWaitRestartPC = false;
  957. AfterWaitRestartPC();
  958. }
  959. if (m_bUpsWaitLock)
  960. {
  961. UpsSupplyLockScreen();
  962. }
  963. else
  964. {
  965. //no need to un-display blue screen? oiltest 20140320
  966. //if (m_bScreenLock)
  967. //{
  968. // CSmartPointer<IEntityFunction> pFunc = GetFunction();
  969. // CSmartPointer<IEntityFunctionPrivilege> pFuncPrivilege = pFunc.ConvertCase<IEntityFunctionPrivilege>();
  970. // if (pFuncPrivilege == NULL)
  971. // {
  972. // Dbg("unlock screen NoPrivilege");
  973. // return;
  974. // }
  975. // pFuncPrivilege->UndisplayBlueScreen();
  976. // m_bScreenLock = false;
  977. //}
  978. }
  979. GetFunction()->ResetTimer(HEALTHMANAGER_TIMER_ID, HEALTHMANAGER_TIMER_INTERVAL);
  980. }
  981. #if defined(RVC_OS_LINUX)
  982. bool FindGuardianPid(pid_t &pid)
  983. {
  984. char* relate_processes[] = { "guardian" };
  985. int count = 1;
  986. alive_process_info processes[1];
  987. memset(processes, 0, sizeof(processes));
  988. osutil_detect_unique_app(relate_processes, array_size(relate_processes), &count, processes);
  989. if (count > 0) {
  990. pid = processes[0].pid;
  991. return true;
  992. }
  993. return false;
  994. }
  995. #endif //RVC_OS_LINUX
  996. int CHealthManagerEntity::CheckGuardianIsRun(bool bStart)
  997. {
  998. if (!m_bNeedGuardian)//no need guardian
  999. return 0;
  1000. #ifdef RVC_OS_WIN
  1001. HANDLE hSnapshot;
  1002. //find guardian.exe
  1003. hSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
  1004. if (hSnapshot)
  1005. {
  1006. PROCESSENTRY32 pe;
  1007. pe.dwSize = sizeof(pe);
  1008. if (Process32First(hSnapshot, &pe))
  1009. {
  1010. do {
  1011. if (_stricmp(&pe.szExeFile[0], "guardian.exe") == 0)
  1012. {
  1013. //Dbg("guardian is running.");
  1014. return true;
  1015. }
  1016. } while (Process32Next(hSnapshot, &pe));
  1017. }
  1018. CloseHandle(hSnapshot);
  1019. }
  1020. Sleep(1000);
  1021. DbgWithLink(LOG_LEVEL_INFO,LOG_TYPE_SYSTEM).setAPI("CheckGuardianIsRun")("cannot find guardian.");
  1022. if (bStart)
  1023. return StartGuardian();
  1024. else
  1025. return false;
  1026. #else
  1027. Dbg("to check guardian is online.");
  1028. pid_t pID;
  1029. bool bFind = false;
  1030. bFind = FindGuardianPid(pID);
  1031. if (bFind)
  1032. {
  1033. Dbg("find guardian");
  1034. int ret = kill(pID, 0);
  1035. Dbg("ret= %d ", ret);
  1036. if (0 == ret)
  1037. {
  1038. Dbg("process: guardian.exe exist!");
  1039. return true;
  1040. }
  1041. else
  1042. {
  1043. Dbg("process: guardian.exe not exist!");
  1044. if (bStart)
  1045. return StartGuardian();
  1046. else
  1047. return false;
  1048. }
  1049. }
  1050. if (bStart)
  1051. return StartGuardian();
  1052. else
  1053. return false;
  1054. #endif //RVC_OS_WIN
  1055. }
  1056. bool CHealthManagerEntity::StopGuardian()
  1057. {
  1058. #ifdef RVC_OS_WIN
  1059. DbgWithLink(LOG_LEVEL_INFO,LOG_TYPE_SYSTEM).setAPI("StopGuardian")("to stop guardian");
  1060. HANDLE hSnapshot;
  1061. int rc = TRUE;
  1062. int result;
  1063. HANDLE hProcess;
  1064. //find and kill guardian.exe
  1065. hSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
  1066. if (hSnapshot)
  1067. {
  1068. PROCESSENTRY32 pe;
  1069. pe.dwSize = sizeof(pe);
  1070. if (Process32First(hSnapshot, &pe))
  1071. {
  1072. do {
  1073. if (_stricmp(&pe.szExeFile[0], "guardian.exe") == 0)
  1074. {
  1075. hProcess = OpenProcess( PROCESS_ALL_ACCESS, FALSE, pe.th32ProcessID );
  1076. if( hProcess == NULL )
  1077. {
  1078. DbgWithLink(LOG_LEVEL_INFO,LOG_TYPE_SYSTEM).setAPI("StopGuardian")("Fail to open process(%d)!",GetLastError());
  1079. return false;
  1080. }
  1081. else
  1082. {
  1083. result = TerminateProcess(hProcess,-1);
  1084. if (result)
  1085. {
  1086. Sleep(3000);
  1087. DbgWithLink(LOG_LEVEL_INFO,LOG_TYPE_SYSTEM).setAPI("StopGuardian")("Terminate guardian suc.");
  1088. return true;
  1089. }
  1090. else
  1091. {
  1092. DbgWithLink(LOG_LEVEL_INFO,LOG_TYPE_SYSTEM).setAPI("StopGuardian")("Terminate guardian failed(%d).",GetLastError());
  1093. return false;
  1094. }
  1095. CloseHandle( hProcess );
  1096. }
  1097. Sleep(3000);
  1098. WaitForSingleObject(&pe.th32ProcessID, INFINITE );
  1099. break;
  1100. }
  1101. } while (Process32Next(hSnapshot, &pe));
  1102. }
  1103. CloseHandle(hSnapshot);
  1104. }
  1105. Sleep(3000);
  1106. return false;
  1107. #else
  1108. int ret = m_pfUpgradeRestart(6, 0);
  1109. Dbg("healthmanager tell the guardian to quit.%d", ret);
  1110. Sleep(5000);
  1111. pid_t pID;
  1112. bool bFind = false;
  1113. bFind = FindGuardianPid(pID);
  1114. if (bFind)
  1115. {
  1116. int ret = kill(pID, 9);
  1117. if (ret < 0)
  1118. {
  1119. Dbg("kill guardian failed:%d",errno);
  1120. return false;
  1121. }
  1122. else
  1123. {
  1124. Dbg("killed guardian.");
  1125. return true;
  1126. }
  1127. }
  1128. Dbg("can't find guardian pid.");
  1129. return true;
  1130. #endif //RVC_OS_WIN
  1131. }
  1132. bool CHealthManagerEntity::StartGuardian()
  1133. {
  1134. LOG_FUNCTION();
  1135. DbgWithLink(LOG_LEVEL_INFO,LOG_TYPE_SYSTEM).setAPI("StartGuardian")("启动 to start guardian");
  1136. // Start the child process.
  1137. CSimpleStringA csBinPath, csAll, csSep("\"");
  1138. ErrorCodeEnum Error = GetFunction()->GetPath("Bin", csBinPath);
  1139. #if defined(RVC_OS_WIN)
  1140. STARTUPINFO si;
  1141. PROCESS_INFORMATION pi;
  1142. ZeroMemory( &si, sizeof(si) );
  1143. si.cb = sizeof(si);
  1144. ZeroMemory( &pi, sizeof(pi) );
  1145. GetFunction()->FlushLogFile();
  1146. csBinPath +="\\guardian.exe";
  1147. if (m_fsm.IfInUpgradeProcess() && !m_versionEx.IsNullOrEmpty())
  1148. {
  1149. string xTmp = csBinPath;//路径值
  1150. xTmp = xTmp.replace(xTmp.find(m_currentVer), m_currentVer.GetLength(), m_versionEx);
  1151. if(ExistsFileA(xTmp.c_str())){
  1152. csBinPath = xTmp.c_str();
  1153. DbgWithLink(LOG_LEVEL_INFO,LOG_TYPE_SYSTEM).setAPI("StartGuardian")("curr:%s,ex:%s", m_currentVer.GetData(), m_versionEx.GetData());
  1154. }else{
  1155. DbgWithLink(LOG_LEVEL_INFO,LOG_TYPE_SYSTEM).setAPI("StartGuardian")("m_versionEx exe is not exist [%s],use current Version exe, curr:%s,ex:%s",xTmp.c_str(),m_currentVer.GetData(), m_versionEx.GetData());
  1156. }
  1157. }
  1158. DbgWithLink(LOG_LEVEL_INFO,LOG_TYPE_SYSTEM).setAPI("StartGuardian")("guardian path[%s]",(LPCTSTR)csBinPath);
  1159. csAll = csSep + csBinPath + csSep;
  1160. LPTSTR szCmdline = _strdup(csAll);
  1161. if( !CreateProcess( NULL,szCmdline,NULL,NULL,FALSE,0,NULL,NULL,&si,&pi))
  1162. {
  1163. DbgWithLink(LOG_LEVEL_INFO,LOG_TYPE_SYSTEM).setAPI("StartGuardian")("CreateProcess failed (%d).\n", GetLastError());
  1164. return false;
  1165. }
  1166. DWORD dwErr = GetLastError();
  1167. return true;
  1168. #else
  1169. char app[MAX_PATH];
  1170. memset(app, 0, sizeof(app));
  1171. tk_process_t* process = NULL;
  1172. tk_process_option_t option;
  1173. csBinPath += "/guardian";
  1174. Dbg("path:%s", (const char*)csBinPath);
  1175. sprintf(app, "%s %s %d", (const char*)csBinPath, "oiltest", 1);
  1176. option.exit_cb = NULL;
  1177. option.file = NULL;
  1178. option.flags = 0;
  1179. option.params = app;
  1180. if (0 == process_spawn(&option, &process)) {
  1181. Dbg("process_spawn guardian");
  1182. FREE(process);
  1183. return true;
  1184. }
  1185. Dbg("end of StartGuardian");
  1186. return false;
  1187. #endif //RVC_OS_WIN
  1188. }
  1189. bool CHealthManagerEntity::DoRestart()
  1190. {
  1191. LOG_FUNCTION();
  1192. CSmartPointer<IConfigInfo> spConfig;
  1193. ErrorCodeEnum err = GetFunction()->OpenConfig(Config_CenterSetting, spConfig);
  1194. if (err != Error_Succeed) {
  1195. DbgWithLink(LOG_LEVEL_INFO,LOG_TYPE_SYSTEM).setAPI("DoRestart")("open cfg file failed!");
  1196. return false;
  1197. }
  1198. m_restartHour = m_restartMinute = 1;
  1199. m_maxRestartTimes = 3;
  1200. int defaultTimesMax,defaultInternal,lowTimesMax,lowInternal;
  1201. do
  1202. {
  1203. int value(0);
  1204. spConfig->ReadConfigValueInt(GetEntityName(), "RestartHour", value);
  1205. if (value > 0) {
  1206. m_restartHour = value;
  1207. }
  1208. } while (false);
  1209. do {
  1210. int value(0);
  1211. spConfig->ReadConfigValueInt(GetEntityName(), "RestartMinute", value);
  1212. if (value > 0) {
  1213. m_restartMinute = value;
  1214. }
  1215. } while (false);
  1216. do {
  1217. int value(0);
  1218. spConfig->ReadConfigValueInt(GetEntityName(), "TestFlag", value);
  1219. m_testFlag = value;
  1220. } while (false);
  1221. do {
  1222. int value(0);
  1223. spConfig->ReadConfigValueInt(GetEntityName(), "MaxRestartTimes", value);
  1224. if (value > 0) {
  1225. m_maxRestartTimes = value;
  1226. }
  1227. } while (false);
  1228. DbgWithLink(LOG_LEVEL_INFO,LOG_TYPE_SYSTEM).setAPI("DoRestart")("m_maxRestartTimes(%d)",m_maxRestartTimes);
  1229. defaultTimesMax = 10;
  1230. do {
  1231. int value(0);
  1232. spConfig->ReadConfigValueInt(GetEntityName(), "DefaultTimesMax", value);
  1233. if (value > 0) {
  1234. defaultTimesMax = value;
  1235. }
  1236. } while (false);
  1237. defaultInternal = 600000;
  1238. do {
  1239. int value(0);
  1240. spConfig->ReadConfigValueInt(GetEntityName(), "DefaultInternal", value);
  1241. if (value > 0) {
  1242. defaultInternal = value;
  1243. }
  1244. } while (false);
  1245. lowTimesMax = 5;
  1246. do {
  1247. int value(0);
  1248. spConfig->ReadConfigValueInt(GetEntityName(), "LowTimesMax", value);
  1249. if (value > 0) {
  1250. lowTimesMax = value;
  1251. }
  1252. } while (false);
  1253. lowInternal = 600000;
  1254. do {
  1255. int value(0);
  1256. spConfig->ReadConfigValueInt(GetEntityName(), "LowInternal", value);
  1257. if (value > 0) {
  1258. lowInternal = value;
  1259. }
  1260. } while (false);
  1261. m_restartMode[RESTART_MODE_DEFAULT].dwTimes = defaultTimesMax;
  1262. m_restartMode[RESTART_MODE_DEFAULT].dwInternal = defaultInternal;
  1263. m_restartMode[RESTART_MODE_LOW].dwTimes = lowTimesMax;
  1264. m_restartMode[RESTART_MODE_LOW].dwInternal = lowInternal;
  1265. CSimpleStringA csDefaultModule("MediaController"), csLowModule(true);
  1266. do {
  1267. CSimpleStringA strValue(true);
  1268. spConfig->ReadConfigValue(GetEntityName(), "DefaultModule", strValue);
  1269. if (!strValue.IsNullOrEmpty()) {
  1270. csDefaultModule = strValue;
  1271. }
  1272. } while (false);
  1273. do {
  1274. CSimpleStringA strValue(true);
  1275. spConfig->ReadConfigValue(GetEntityName(), "LowModule", strValue);
  1276. if (!strValue.IsNullOrEmpty()) {
  1277. csLowModule = strValue;
  1278. }
  1279. } while (false);
  1280. SplitModuleNames(csDefaultModule,RESTART_MODE_DEFAULT);
  1281. SplitModuleNames(csLowModule,RESTART_MODE_LOW);
  1282. DbgWithLink(LOG_LEVEL_INFO,LOG_TYPE_SYSTEM).setAPI("DoRestart")("m_restartHour:m_restartMinute=%d:%d",m_restartHour,m_restartMinute);
  1283. CSmartPointer<IConfigInfo> spConfigRun;
  1284. ErrorCodeEnum eErr = GetFunction()->OpenConfig(Config_Run, spConfigRun);
  1285. spConfigRun->ReadConfigValueInt("Run", "LastHour", m_lastHour);
  1286. m_dayNum = 1;
  1287. spConfigRun->ReadConfigValueInt("Restart", "DayNum", m_dayNum);
  1288. if (m_dayNum == 0)
  1289. {
  1290. spConfigRun->WriteConfigValueInt("Restart", "DayNum", 0);
  1291. }
  1292. spConfigRun->ReadConfigValueInt("Run", "RestartTimes", m_restartTimes);
  1293. spConfigRun->ReadConfigValue("Run", "VersionEx", m_versionEx);
  1294. //判断上个版本号值是否为空
  1295. if(m_versionEx.IsNullOrEmpty()){
  1296. DbgWithLink(LOG_LEVEL_INFO,LOG_TYPE_SYSTEM).setAPI("DoRestart")("get VersionEx is null");
  1297. }
  1298. CSmartPointer<IConfigInfo> spCerConfig;
  1299. eErr = GetFunction()->OpenConfig(Config_CenterSetting, spCerConfig);
  1300. spCerConfig->ReadConfigValueInt(GetEntityName(), "MaxRunDays", m_maxRunDays);
  1301. spCerConfig->ReadConfigValueInt(GetEntityName(), "MaxTimeWaitMainPageMS", m_maxWaitMainpageTime);
  1302. if (m_maxWaitMainpageTime < 5000)
  1303. m_maxWaitMainpageTime = HEALTHMANAGER_WAIT_MAINPAGE_OPEN_TIMER_INTERVAL;
  1304. CSimpleStringA csimpleStrMachineTypeCfg;
  1305. auto rc = spCerConfig->ReadConfigValue("NonExclusive", "NonGuardian", csimpleStrMachineTypeCfg);
  1306. eErr = GetFunction()->GetSystemStaticInfo(m_sysStaticInfo);
  1307. if (eErr != Error_Succeed)
  1308. {
  1309. DbgWithLink(LOG_LEVEL_INFO,LOG_TYPE_SYSTEM).setAPI("DoRestart")("Get system static info failed(%s).", SpStrError(eErr));
  1310. m_sysStaticInfo.strMachineType = "";
  1311. m_sysStaticInfo.strSite = "";
  1312. m_sysStaticInfo.InstallVersion = CVersion();
  1313. }
  1314. m_currentVer = m_sysStaticInfo.InstallVersion.ToString();
  1315. DbgWithLink(LOG_LEVEL_INFO,LOG_TYPE_SYSTEM).setAPI("DoRestart")("get current version [%s]", (LPCTSTR)m_currentVer);
  1316. if(csimpleStrMachineTypeCfg.IndexOf(m_sysStaticInfo.strMachineType)>=0)
  1317. {
  1318. LogWarn(Severity_Low, Error_Unexpect, HealthManager_UserErrorCode_Need_No_Guardian, "terminal is not need start up guardian");
  1319. m_bNeedGuardian = false;
  1320. //设置一个系统变量给关门页面使用
  1321. //liuwt@20220104 N noguardian Y needguardian
  1322. eErr = GetFunction()->SetSysVar("NeedGuardian","N");
  1323. if (eErr != Error_Succeed)
  1324. {
  1325. DbgWithLink(LOG_LEVEL_INFO,LOG_TYPE_SYSTEM).setAPI("DoRestart")("set NeedGuardian N failed (%d).",(int)eErr);
  1326. }
  1327. }else{
  1328. LogWarn(Severity_Low, Error_Unexpect, HealthManager_UserErrorCode_Need_Guardian, "terminal is need start up guardian");
  1329. }
  1330. DbgWithLink(LOG_LEVEL_INFO,LOG_TYPE_SYSTEM).setAPI("DoRestart")("central setting:m_maxRunDays:%d,DayNum:%d,NonGuardian:%s", m_maxRunDays,m_dayNum,csimpleStrMachineTypeCfg.GetData());
  1331. SYSTEMTIME localTime;
  1332. GetLocalTimeRVC(localTime);
  1333. if (m_bInit)
  1334. {
  1335. m_bInit = false;
  1336. m_wDayOfWeek = localTime.wDayOfWeek;
  1337. }
  1338. ITimerListener *pListener = new TimerOutHelper<CHealthManagerEntity>(this, &CHealthManagerEntity::OnCheckTimeTimeout);
  1339. DbgWithLink(LOG_LEVEL_INFO,LOG_TYPE_SYSTEM).setAPI("DoRestart")("set timer");
  1340. GetFunction()->SetTimer(HEALTHMANAGER_TIMER_ID, pListener, HEALTHMANAGER_TIMER_INTERVAL);
  1341. CSimpleStringA deamonBasePath = "";
  1342. err = GetFunction()->GetPath("bin",deamonBasePath);
  1343. if (err != Error_Succeed)
  1344. {
  1345. DbgWithLink(LOG_LEVEL_INFO,LOG_TYPE_SYSTEM).setAPI("DoRestart")("for wait deamon get bin path failed(%d).",err);
  1346. return false;
  1347. }
  1348. DbgWithLink(LOG_LEVEL_INFO,LOG_TYPE_SYSTEM).setAPI("DoRestart")("加载guardian.dll");
  1349. #if defined(RVC_OS_WIN)
  1350. deamonBasePath += "\\GuardianBase.dll";
  1351. #else
  1352. deamonBasePath += "/libGuardianBase.so";
  1353. #endif
  1354. DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("to check if in upgrade process");
  1355. if (m_fsm.IfInUpgradeProcess() && !m_versionEx.IsNullOrEmpty())
  1356. {
  1357. string xTmp(deamonBasePath.GetData());
  1358. xTmp = xTmp.replace(xTmp.find(m_currentVer), m_currentVer.GetLength(), m_versionEx);
  1359. //判断文件是否存在,如果不存在,则启动当前版本guardian.
  1360. if(ExistsFileA(xTmp.c_str())){
  1361. deamonBasePath = xTmp.c_str();
  1362. DbgWithLink(LOG_LEVEL_INFO,LOG_TYPE_SYSTEM).setAPI("DoRestart")("curr:%s,ex:%s", m_currentVer.GetData(), m_versionEx.GetData());
  1363. }else{
  1364. DbgWithLink(LOG_LEVEL_INFO,LOG_TYPE_SYSTEM).setAPI("DoRestart")("m_versionEx dll is not exist ,use current Version gd, curr:%s,ex:%s", m_currentVer.GetData(), m_versionEx.GetData());
  1365. }
  1366. }
  1367. #if defined(RVC_OS_WIN)
  1368. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI("DoRestart")("gd path [%s]", deamonBasePath.GetData());
  1369. HMODULE hDll = LoadLibraryA(deamonBasePath);
  1370. if (hDll == NULL)
  1371. {
  1372. DbgWithLink(LOG_LEVEL_INFO,LOG_TYPE_SYSTEM).setAPI("DoRestart")("load guardianbase.dll failed(%d)",GetLastError());
  1373. return false;
  1374. }
  1375. m_pfShake = (pfShakeHands)GetProcAddress(hDll,"ShakeHands");
  1376. if (m_pfShake == NULL)
  1377. {
  1378. DbgWithLink(LOG_LEVEL_INFO,LOG_TYPE_SYSTEM).setAPI("DoRestart")("get shakehands failed(%d)",GetLastError());
  1379. return false;
  1380. }
  1381. m_pfUpgradeRestart = (pfUpgradeRestart)GetProcAddress(hDll,"UpgradeRestart");
  1382. if (m_pfUpgradeRestart == NULL)
  1383. {
  1384. DbgWithLink(LOG_LEVEL_INFO,LOG_TYPE_SYSTEM).setAPI("DoRestart")("get UpgradeRestart failed(%d)",GetLastError());
  1385. return false;
  1386. }
  1387. #else
  1388. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("gd path [%s]", (LPCTSTR)deamonBasePath);
  1389. void* handle = dlopen(deamonBasePath, RTLD_LAZY);
  1390. if (handle == NULL)
  1391. {
  1392. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("load libGuardianBase.so failed(%d)", errno);
  1393. return false;
  1394. }
  1395. m_pfShake = (pfShakeHands)dlsym(handle, "ShakeHands");
  1396. if (m_pfShake == NULL)
  1397. {
  1398. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("get ShakeHands failed(%d)", GetLastError());
  1399. return false;
  1400. }
  1401. m_pfUpgradeRestart = (pfUpgradeRestart)dlsym(handle, "UpgradeRestart");
  1402. if (m_pfUpgradeRestart == NULL)
  1403. {
  1404. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("get UpgradeRestart failed(%d)", GetLastError());
  1405. return false;
  1406. }
  1407. #endif
  1408. DbgWithLink(LOG_LEVEL_INFO,LOG_TYPE_SYSTEM).setAPI("DoRestart")("have load guardian.");
  1409. if (CheckGuardianIsRun(true) > 0)
  1410. {
  1411. Sleep(500);
  1412. if (m_bNeedGuardian)
  1413. {
  1414. DbgWithLink(LOG_LEVEL_INFO,LOG_TYPE_SYSTEM).setAPI("DoRestart")("to tell guardian framework is starting.");
  1415. eErr = m_pfUpgradeRestart(4, 0);//tell guardian framework is starting...oilyang 20150514
  1416. DbgWithLink(LOG_LEVEL_INFO,LOG_TYPE_SYSTEM).setAPI("DoRestart")("feedback of framework is starting.%d", eErr);
  1417. }
  1418. else
  1419. {
  1420. DbgWithLink(LOG_LEVEL_INFO,LOG_TYPE_SYSTEM).setAPI("DoRestart")("need Upgrade guardian only");
  1421. eErr = m_pfUpgradeRestart(6, 0);//tell guardian framework we need Upgrade !!!Only!!! oilyang@20211221
  1422. DbgWithLink(LOG_LEVEL_INFO,LOG_TYPE_SYSTEM).setAPI("DoRestart")("feedback of need Upgrade guardian only.%d", eErr);
  1423. }
  1424. }
  1425. UpdateSiteToRuncfg();
  1426. return true;
  1427. }
  1428. void CHealthManagerEntity::SplitModuleNames(CSimpleStringA csLine, ModuleReMode eMode)
  1429. {
  1430. string str((const char*)csLine);
  1431. size_t pos = 0,nameEnd = 0;
  1432. size_t len = str.length();
  1433. while(1)
  1434. {
  1435. nameEnd = str.find(',',pos);
  1436. if (nameEnd != string::npos)
  1437. {
  1438. m_modCfgInfo[str.substr(pos,nameEnd-pos).c_str()] = eMode;
  1439. pos = nameEnd + 1;
  1440. }
  1441. else
  1442. {
  1443. if (pos < len)
  1444. m_modCfgInfo[str.substr(pos,nameEnd-pos).c_str()] = eMode;
  1445. break;
  1446. }
  1447. }
  1448. }
  1449. int CHealthManagerEntity::ConnectUps()
  1450. {
  1451. if (m_pUpsClient == NULL)
  1452. {
  1453. m_pUpsClient = new UpsService_ClientBase(this);
  1454. ErrorCodeEnum eErrConn = m_pUpsClient->Connect();
  1455. if (eErrConn != Error_Succeed) {
  1456. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI("ConnectUps")("Ups connected failed(%d).", eErrConn);
  1457. m_pUpsClient->SafeDelete();
  1458. m_pUpsClient = NULL;
  1459. }
  1460. else
  1461. {
  1462. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI("ConnectUps")("ups entity connected.");
  1463. UpsService_GetStatus_Req req;
  1464. UpsService_GetStatus_Ans ans;
  1465. ErrorCodeEnum eErrState = m_pUpsClient->GetStatus(req, ans, 3000);
  1466. if (eErrState == Error_Succeed)
  1467. {
  1468. m_bGetUpsStateFlag = true;
  1469. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI("ConnectUps")("current state %d", ans.Status);
  1470. return 0;
  1471. }
  1472. else
  1473. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI("ConnectUps")("connect get ups state failed(%d).", eErrState);
  1474. }
  1475. }
  1476. return -1;
  1477. }
  1478. bool CHealthManagerEntity::SaveCurrentVersion()
  1479. {
  1480. CSimpleStringA csRootVer,csRunInfo,csBakFile,csVerFile;
  1481. ErrorCodeEnum eErr;
  1482. if ((eErr = GetFunction()->GetPath("RootVer",csRootVer)) != Error_Succeed)
  1483. {
  1484. DbgWithLink(LOG_LEVEL_INFO,LOG_TYPE_SYSTEM).setAPI("SaveCurrentVersion")("Get version path failed(%d).",eErr);
  1485. return false;
  1486. }
  1487. if ((eErr = GetFunction()->GetPath("RunInfo",csRunInfo)) != Error_Succeed)
  1488. {
  1489. DbgWithLink(LOG_LEVEL_INFO,LOG_TYPE_SYSTEM).setAPI("SaveCurrentVersion")("get runinfo path failed(%d)",eErr);
  1490. return false;
  1491. }
  1492. #if defined(RVC_OS_WIN)
  1493. csBakFile = csRunInfo + "\\runcfg\\version.dat";
  1494. #else
  1495. csBakFile = csRunInfo + "/runcfg/version.dat";
  1496. #endif
  1497. ofstream outfile (csBakFile,std::ofstream::binary);
  1498. CSmartPointer<IConfigInfo> spConfigRun;
  1499. eErr = GetFunction()->OpenConfig(Config_Run, spConfigRun);
  1500. if (eErr != Error_Succeed) {
  1501. DbgWithLink(LOG_LEVEL_INFO,LOG_TYPE_SYSTEM).setAPI("SaveCurrentVersion")("SaveCurrentVersion open run cfg file failed!");
  1502. return -1;
  1503. }
  1504. else
  1505. spConfigRun->WriteConfigValue("Run", "VersionEx", m_currentVer);
  1506. int size = m_currentVer.GetLength();
  1507. char* buffer = new char[size];
  1508. ZeroMemory(buffer,size);
  1509. //infile.read (buffer,size);
  1510. memcpy(buffer, m_currentVer,size);
  1511. outfile.write (buffer,size);
  1512. delete[] buffer;
  1513. outfile.close();
  1514. //infile.close();
  1515. return true;
  1516. }
  1517. bool CHealthManagerEntity::SaveFrameStartTimeForUpgrade()
  1518. {
  1519. CSimpleStringA csRunInfo,csBakFile;
  1520. ErrorCodeEnum eErr;
  1521. if ((eErr = GetFunction()->GetPath("RunInfo",csRunInfo)) != Error_Succeed)
  1522. {
  1523. DbgWithLink(LOG_LEVEL_INFO,LOG_TYPE_SYSTEM).setAPI("SaveFrameStartTimeForUpgrade")("get runinfo path failed(%d)",eErr);
  1524. return false;
  1525. }
  1526. #if defined(RVC_OS_WIN)
  1527. csBakFile = csRunInfo + "\\runcfg\\starttime.dat";
  1528. #else
  1529. csBakFile = csRunInfo + "/runcfg/starttime.dat";
  1530. #endif
  1531. ofstream outfile (csBakFile,std::ofstream::binary);
  1532. CSystemRunInfo sysRunInfo;
  1533. GetFunction()->GetSystemRunInfo(sysRunInfo);
  1534. if (eErr != Error_Succeed)
  1535. {
  1536. DbgWithLink(LOG_LEVEL_INFO,LOG_TYPE_SYSTEM).setAPI("SaveFrameStartTimeForUpgrade")("Get system run info failed(%d).",eErr);
  1537. return false;
  1538. }
  1539. CSimpleStringA csStartTime = sysRunInfo.tmStart.ToTimeString();
  1540. DbgWithLink(LOG_LEVEL_INFO,LOG_TYPE_SYSTEM).setAPI("SaveFrameStartTimeForUpgrade")("get current time start [%s]",(LPCTSTR)csStartTime);
  1541. int size = csStartTime.GetLength();
  1542. char* buffer = new char[size];
  1543. ZeroMemory(buffer,size);
  1544. //infile.read (buffer,size);
  1545. memcpy(buffer,csStartTime,size);
  1546. outfile.write (buffer,size);
  1547. delete[] buffer;
  1548. outfile.close();
  1549. //infile.close();
  1550. return true;
  1551. }
  1552. bool CHealthManagerEntity::VersionRollBack(const char *pVerion)
  1553. {
  1554. CSimpleStringA csCurrVer = m_sysStaticInfo.InstallVersion.ToString();
  1555. if (_stricmp(csCurrVer,pVerion) == 0)
  1556. {
  1557. DbgWithLink(LOG_LEVEL_INFO,LOG_TYPE_SYSTEM).setAPI("VersionRollBack")("destination version identified the current version.");
  1558. return false;
  1559. }
  1560. m_pUpgMgr = new UpgradeMgrService_ClientBase(this);
  1561. if (m_pUpgMgr == NULL)
  1562. {
  1563. DbgWithLink(LOG_LEVEL_INFO,LOG_TYPE_SYSTEM).setAPI("VersionRollBack")("create UpgradeMgr client failed.");
  1564. return false;
  1565. }
  1566. CSmartPointer<IAsynWaitSp> pAsyncWait;
  1567. ErrorCodeEnum eErr = m_pUpgMgr->Connect(pAsyncWait);
  1568. if (eErr != Error_Succeed)
  1569. {
  1570. DbgWithLink(LOG_LEVEL_INFO,LOG_TYPE_SYSTEM).setAPI("VersionRollBack")("connect to UpgradeMgr failed(%d)",eErr);
  1571. return false;
  1572. }
  1573. else
  1574. eErr = pAsyncWait->WaitAnswer(10000);
  1575. UpgradeMgrService_RollbackUpdate_Req req;
  1576. req.strVersion = pVerion;
  1577. UpgradeMgrService_RollbackUpdate_Ans ans;
  1578. eErr = m_pUpgMgr->RollbackUpdate(req,ans,10000);
  1579. if (eErr == Error_Succeed)
  1580. {
  1581. DbgWithLink(LOG_LEVEL_INFO,LOG_TYPE_SYSTEM).setAPI("VersionRollBack")("version rollback doing.");
  1582. m_bVerRollback = true;
  1583. return true;
  1584. }
  1585. else
  1586. {
  1587. DbgWithLink(LOG_LEVEL_INFO,LOG_TYPE_SYSTEM).setAPI("VersionRollBack")("UpgradeMgr rollback failed(%d)",eErr);
  1588. return false;
  1589. }
  1590. }
  1591. int CHealthManagerEntity::UpdateSiteChangeFlag()
  1592. {
  1593. CSmartPointer<IConfigInfo> spConfig;
  1594. ErrorCodeEnum eErr = GetFunction()->OpenConfig(Config_Run, spConfig);
  1595. if (eErr != Error_Succeed) {
  1596. DbgWithLink(LOG_LEVEL_INFO,LOG_TYPE_SYSTEM).setAPI("UpdateSiteChangeFlag")("UpdateSiteChangeFlag open run cfg file failed!");
  1597. return -1;
  1598. }
  1599. eErr = spConfig->WriteConfigValueInt("AboutSite", "SiteChanged", 1);
  1600. DbgWithLink(LOG_LEVEL_INFO,LOG_TYPE_SYSTEM).setAPI("UpdateSiteChangeFlag")("Write SiteChanged 1.err[%d]",eErr);
  1601. return 0;
  1602. }
  1603. int CHealthManagerEntity::UpdateSiteToRuncfg(bool bWriteSite,bool bClearSiteFlag)
  1604. {
  1605. DbgWithLink(LOG_LEVEL_INFO,LOG_TYPE_SYSTEM).setAPI("UpdateSiteToRuncfg")("bClearSiteFlag[%d]",bClearSiteFlag);
  1606. CSmartPointer<IConfigInfo> spConfig;
  1607. ErrorCodeEnum eErr = GetFunction()->OpenConfig(Config_Run, spConfig);
  1608. if (eErr != Error_Succeed) {
  1609. DbgWithLink(LOG_LEVEL_INFO,LOG_TYPE_SYSTEM).setAPI("UpdateSiteToRuncfg")("UpdateSiteToRuncfg open run cfg file failed!");
  1610. return -1;
  1611. }
  1612. if (!bClearSiteFlag)
  1613. {
  1614. int siteChangedFlag = 0;
  1615. eErr = spConfig->ReadConfigValueInt("AboutSite", "SiteChanged", siteChangedFlag);
  1616. if (eErr == Error_Succeed)
  1617. {
  1618. if (siteChangedFlag != 0)
  1619. {
  1620. bWriteSite = false;
  1621. }
  1622. }
  1623. }
  1624. else
  1625. {
  1626. eErr = spConfig->WriteConfigValueInt("AboutSite", "SiteChanged", 0);
  1627. DbgWithLink(LOG_LEVEL_INFO,LOG_TYPE_SYSTEM).setAPI("UpdateSiteToRuncfg")("UpdateSiteToRuncfg.Write Site (%d).", eErr);
  1628. }
  1629. if (bWriteSite)
  1630. {
  1631. spConfig->WriteConfigValue("AboutSite", "Site", m_sysStaticInfo.strSite);
  1632. }
  1633. return 0;
  1634. }
  1635. int CHealthManagerEntity::RestartIE()
  1636. {
  1637. CSimpleStringA csBrowserName = "Chromium";
  1638. m_bNeedToRestartIE = false;
  1639. CSmartPointer<IAsynWaitSp> spWait;
  1640. CSmartPointer<IEntityFunctionPrivilege> pFuncPrivilege = GetFunction().ConvertCase<IEntityFunctionPrivilege>();
  1641. ErrorCodeEnum eErr = pFuncPrivilege->TerminateEntity(csBrowserName.GetData(), spWait);
  1642. if (eErr == Error_Succeed)
  1643. {
  1644. if (spWait != NULL)
  1645. spWait->WaitAnswer(10000);
  1646. }
  1647. else
  1648. DbgWithLink(LOG_LEVEL_INFO,LOG_TYPE_SYSTEM).setAPI("RestartIE")("TerminateEntity browser failed.%d", eErr);
  1649. eErr = pFuncPrivilege->StartEntity(csBrowserName.GetData(), "", spWait);
  1650. if (eErr == Error_Succeed)
  1651. {
  1652. if (spWait != NULL)
  1653. eErr = spWait->WaitAnswer(15000);
  1654. }
  1655. else
  1656. {
  1657. DbgWithLink(LOG_LEVEL_INFO,LOG_TYPE_SYSTEM).setAPI("RestartIE")("Start browser failed(%d).", eErr);
  1658. }
  1659. return 0;
  1660. }
  1661. void CHealthManagerEntity::ReadCenterConfigStr(SpReqAnsContext<HealthManagerService_ReadCenterConfigStr_Req, HealthManagerService_ReadCenterConfigStr_Ans>::Pointer ctx)
  1662. {
  1663. ctx->Ans.value = __ReadCenterConfigStr(ctx->Req.key, ctx->Req.entity);
  1664. ctx->Answer(Error_Succeed);
  1665. }
  1666. void CHealthManagerEntity::ControlTerminalLife(
  1667. SpReqAnsContext<HealthManagerService_ControlTerminalLife_Req, HealthManagerService_ControlTerminalLife_Ans>::Pointer ctx)
  1668. {
  1669. //< !--1:restart app; 2: shutdown app; 3:shutdown app and guardian; 4: restart pc; 5: poweroff; 6:poweroff with ups-- >
  1670. int retCode = 0;
  1671. ErrorCodeEnum result = Error_Unexpect;
  1672. switch (ctx->Req.cmdType) {
  1673. case 1:
  1674. retCode = m_fsm.QuitFrameworkAndSaveInfo(RebootTrigger_ManualLocal, RebootWay_Framework);
  1675. result = Error_Succeed;
  1676. break;
  1677. case 2:
  1678. retCode = m_fsm.QuitFrameworkAndSaveInfo(RebootTrigger_Unknown, RebootWay_Framework);
  1679. result = Error_Succeed;
  1680. break;
  1681. case 3:
  1682. retCode = m_fsm.QuitFrameworkAndSaveInfo(RebootTrigger_DeadForever, RebootWay_Framework);
  1683. result = Error_Succeed;
  1684. break;
  1685. case 4:
  1686. retCode = m_fsm.QuitFrameworkAndSaveInfo(RebootTrigger_ManualLocal, RebootWay_OS);
  1687. result = Error_Succeed;
  1688. break;
  1689. case 5:
  1690. retCode = m_fsm.QuitFrameworkAndSaveInfo(RebootTrigger_DeadForever, RebootWay_OS);
  1691. result = Error_Succeed;
  1692. break;
  1693. case 6:
  1694. if(ctx->Req.reserved1 > 0 && ctx->Req.reserved2 > 0)
  1695. result = SystemShutdownThroughUPS(ctx->Req.reserved1, ctx->Req.reserved2);
  1696. else
  1697. result = SystemShutdownThroughUPS();
  1698. if (result == Error_Succeed) {
  1699. Sleep(300);
  1700. m_fsm.QuitFrameworkAndSaveInfo(RebootTrigger_DeadForever, RebootWay_OS);
  1701. }
  1702. break;
  1703. default:
  1704. result = Error_Param;
  1705. break;
  1706. }
  1707. ctx->Ans.retCode = retCode;
  1708. ctx->Answer(result);
  1709. }
  1710. CSimpleStringA CHealthManagerEntity::__ReadCenterConfigStr(CSimpleStringA key, CSimpleStringA entityName = "")
  1711. {
  1712. CSimpleStringA str = "";
  1713. CSmartPointer<IConfigInfo> spCerConfig;
  1714. ErrorCodeEnum err = GetFunction()->OpenConfig(Config_CenterSetting, spCerConfig);
  1715. if (entityName == "")
  1716. {
  1717. spCerConfig->ReadConfigValue("IEBrowser", key, str);
  1718. }
  1719. else
  1720. {
  1721. spCerConfig->ReadConfigValue(entityName, key, str);
  1722. }
  1723. return str;
  1724. }
  1725. void CHealthManagerEntity::GetAuthErrMsg(SpReqAnsContext<HealthManagerService_GetAuthErrMsg_Req, HealthManagerService_GetAuthErrMsg_Ans>::Pointer ctx)
  1726. {
  1727. CSimpleStringA tmp;
  1728. GetFunction()->GetSysVar("AuthErrMsg", tmp);//获取错误页信息
  1729. ctx->Ans.errMsg = tmp;
  1730. ctx->Answer(Error_Succeed);
  1731. }
  1732. void CHealthManagerEntity::OnLog(const CAutoArray<CUUID>& SubIDs, const CUUID nLogID, const LogTypeEnum eLogType, const SeverityLevelEnum eLevel,
  1733. const DWORD dwSysError, const DWORD dwUserCode, const DWORD dwEntityInstanceID, const WORD wEntityDevelID,
  1734. const CAutoArray<DWORD>& Param, const char* pszEntityName, const char* pszModuleName, const char* pszMessage, const linkContext& pLinkInfo)
  1735. {
  1736. DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("user code:%x,from entity:%s", dwUserCode, pszEntityName);
  1737. switch (dwUserCode) {
  1738. case EVENT_RESTART_SHELL:
  1739. case Event_Req_Framework_Restart: //case framework restart after upgrade
  1740. case EVENT_CONSOLE_REQ_RESTART_SHELL:
  1741. case Event_Req_Framework_Rollback://case after rollback
  1742. //according to zl commented the following line 20150828
  1743. //case EVENT_UKEY_CUSTOMER_MANANAGER_SYS_EXIT:
  1744. case LOG_EVT_IEBROWSER_RESET_SITE_RESTART: //重设root.ini的site,重启框架
  1745. case Event_Req_Framework_No_Upgrade_Restart://升级请求重启框架(体系外升级等等)
  1746. {
  1747. //TODO oilyang@20230613 all of the Privilege CMD need to been collated
  1748. LogWarn(Severity_Low, Error_Unexpect, HealthManager_UserErrorCode_PrivilegeCMD, CSimpleStringA::Format("%x", dwUserCode));
  1749. int iCheckGuardian = CheckGuardianIsRun();
  1750. if (iCheckGuardian < 0)
  1751. {
  1752. bool bStartGuardian = StartGuardian();
  1753. if (!bStartGuardian)
  1754. {
  1755. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("Before restart frame,start guardian failed.");
  1756. break;
  1757. }
  1758. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("Before restart frame,start guardian suc.");
  1759. Sleep(2000);
  1760. }
  1761. if (dwUserCode == Event_Req_Framework_Restart)
  1762. {
  1763. FrameworkRestartTask* task = new FrameworkRestartTask(this); //通过工作线程弹窗并重启
  1764. GetFunction()->PostThreadPoolTask(task);
  1765. break;
  1766. }
  1767. else if (dwUserCode == Event_Req_Framework_Rollback)
  1768. {
  1769. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("version rollback succeed.to restart framework");
  1770. m_bVerRollback = false;
  1771. m_eRebootTrigger = RebootTrigger_RollBack;
  1772. }
  1773. else if (dwUserCode == LOG_EVT_IEBROWSER_RESET_SITE_RESTART)
  1774. {
  1775. //oilyang@20211021 comment the following line
  1776. //can't see why update this ,as browser haven't changed site
  1777. //UpdateSiteChangeFlag();
  1778. m_eRebootTrigger = RebootTrigger_Resource;
  1779. }
  1780. else if (dwUserCode == Event_Req_Framework_No_Upgrade_Restart)
  1781. {
  1782. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("Event_Req_Framework_No_Upgrade_Restart.!!!!");
  1783. FrameworkRestartTask* task = new FrameworkRestartTask(this); //通过工作线程弹窗并重启
  1784. GetFunction()->PostThreadPoolTask(task);
  1785. break;
  1786. }
  1787. m_eRebootWay = RebootWay_Framework;
  1788. BOOL bRet = FrameworkShutdown();
  1789. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("framework shutdown [%d]", bRet);
  1790. }
  1791. break;
  1792. case EVENT_CONSOLE_REQ_SHUTDOWN_SHELL:
  1793. {
  1794. LogWarn(Severity_Low, Error_Unexpect, HealthManager_UserErrorCode_PrivilegeCMD, CSimpleStringA::Format("%x", dwUserCode));
  1795. BOOL bRet = FrameworkShutdown(false);
  1796. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("framework shutdown from console [%d]", bRet);
  1797. }
  1798. break;
  1799. case EVENT_RESTART_MACHINE:
  1800. case Event_Req_OS_Restart://case os restart after outside update
  1801. case EVENT_CONSOLE_REQ_RESTART_POWER:
  1802. {
  1803. LogWarn(Severity_Low, Error_Unexpect, HealthManager_UserErrorCode_PrivilegeCMD, CSimpleStringA::Format("%x", dwUserCode));
  1804. if (dwUserCode == Event_Req_OS_Restart)
  1805. m_eRebootTrigger = RebootTrigger_OSUpgrade;
  1806. else
  1807. m_eRebootTrigger = RebootTrigger_Unknown;
  1808. m_eRebootWay = RebootWay_Power;
  1809. BOOL bRet = SystemRestart(false, true);
  1810. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("os restart [%d]", bRet);
  1811. }
  1812. break;
  1813. case LOG_EVT_IEBROWSER_RESTART_MACHINE:
  1814. {
  1815. m_eRebootTrigger = RebootTrigger_Unknown;
  1816. m_eRebootWay = RebootWay_Power;
  1817. LogWarn(Severity_Low, Error_Unexpect, LOG_EVT_IEBROWSER_RESTART_MACHINE, "ClosePage/UserDeskTop to call restart machine.");
  1818. BOOL bRet = SystemRestart(false, true, true);
  1819. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("machine restart now [%d]", bRet);
  1820. break;
  1821. }
  1822. case LOG_EVT_IEBROWSER_SHUTDOWN_MACHINE:
  1823. {
  1824. LogWarn(Severity_Low, Error_Unexpect, LOG_EVT_IEBROWSER_SHUTDOWN_MACHINE, "ClosePage/UserDeskTop to call shutdown machine.");
  1825. SystemShutdown();
  1826. break;
  1827. }
  1828. case LOG_EVT_IEBROWSER_SHUTDOWN_MACHINE_THROUGH_UPS:
  1829. {
  1830. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("User descktop said to shutdown machine now through UPS");
  1831. if (Error_Succeed == SystemShutdownThroughUPS()) {
  1832. ///**TODO(Gifur@7/16/2021): 主动跟监护进程做一次握手,避免在关机过程中提前重启了框架 */
  1833. Sleep(300);
  1834. m_fsm.QuitFrameworkAndSaveInfo(RebootTrigger_DeadForever, RebootWay_Framework);
  1835. }
  1836. break;
  1837. }
  1838. case LOG_EVT_SELFCHECK_OS_RESTART:
  1839. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("selfcheck to wait chance to restart(os) pc.");
  1840. m_eRebootTrigger = RebootTrigger_RunExcepition;
  1841. m_eRebootWay = RebootWay_Power;
  1842. m_bWaitRestartPC = true;
  1843. break;
  1844. case LOG_EVT_SELFCHECK_POWER_RESTART:
  1845. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("selfcheck to wait chance to restart(power) pc.");
  1846. m_eRebootTrigger = RebootTrigger_RunExcepition;
  1847. m_eRebootWay = RebootWay_Power;
  1848. m_bWaitRestartPC = true;
  1849. break;
  1850. case EVENT_MOD_SIP_RESART:
  1851. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("SIPPhone said to wait chance to restart(power) pc.");
  1852. m_eRebootTrigger = RebootTrigger_RunExcepition;
  1853. m_eRebootWay = RebootWay_Power;
  1854. m_bWaitRestartPC = true;
  1855. break;
  1856. case EVENT_ACCESSAUTH_SUCCEED:
  1857. {
  1858. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_USER).setLogCode("QLR0402501Z10302")("access auth succeed.");
  1859. m_fsm.SetAccessAuth(AccessAuth_Suc);
  1860. m_bNeedAuthRetry = false;
  1861. m_bNeedGuardianRestart = true;
  1862. m_dwTimeOfAuthSuc = GetTickCount64() / 1000;
  1863. GetFunction()->SetTimer(HEALTHMANAGER_WAIT_MAINPAGE_OPEN_TIMER_ID, this, m_maxWaitMainpageTime);
  1864. CSimpleStringA msg(true);
  1865. GetFunction()->GetSysVar("AuthErrMsg", msg);
  1866. if (msg.GetLength() != 0)
  1867. {
  1868. StartManagerDesktopPage("warnPrompt.html");
  1869. }
  1870. break;
  1871. } //oilyang@20210331 distinguish reasons of accessauth failed to decide what to do next
  1872. //case EVENT_ACCESSAUTH_FAILED:
  1873. //case EVENT_ACCESSAUTH_TIMEOUT:
  1874. case CONTROL_ACCESSAUTH_NORETRY_NORESTART:
  1875. case CONTROL_ACCESSAUTH_RETRY_NORESTART:
  1876. case CONTROL_ACCESSAUTH_RETRY_RESTART:
  1877. case CONTROL_ACCESSAUTH_UNKNOWN:
  1878. {
  1879. if (dwUserCode == CONTROL_ACCESSAUTH_NORETRY_NORESTART) {
  1880. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("no retry,no restart.");
  1881. m_bNeedAuthRetry = false;
  1882. m_bNeedGuardianRestart = false;
  1883. }
  1884. else if (dwUserCode == CONTROL_ACCESSAUTH_RETRY_NORESTART) {
  1885. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("retry,no restart.");
  1886. m_bNeedAuthRetry = true;
  1887. m_bNeedGuardianRestart = false;
  1888. }
  1889. else if (dwUserCode == CONTROL_ACCESSAUTH_RETRY_RESTART) {
  1890. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("retry,restart.");
  1891. m_bNeedAuthRetry = true;
  1892. m_bNeedGuardianRestart = true;
  1893. }
  1894. else if (dwUserCode == CONTROL_ACCESSAUTH_UNKNOWN) {
  1895. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("unkown access failed.no retry,restart.");
  1896. m_bNeedAuthRetry = false;
  1897. m_bNeedGuardianRestart = true;
  1898. }
  1899. m_fsm.SetAccessAuth(AccessAuth_Fail);
  1900. DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_USER).setLogCode("QLR0402501Z10302").setResultCode("RTA5103")("receive accessauth failed result:%d", dwUserCode);
  1901. if (m_bNeedAuthRetry)
  1902. {
  1903. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("retry AccessAuth");
  1904. m_fsm.ToReAccessAuth();
  1905. }
  1906. }
  1907. break;
  1908. case ERR_ACCESSAUTH_SERVICE_FAILED: //准入服务返回失败
  1909. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("unkown access failed.no retry, no restart.");
  1910. m_bNeedAuthRetry = false;
  1911. m_bNeedGuardianRestart = false; //服务端准入失败无需重启
  1912. m_fsm.SetAccessAuth(AccessAuth_servFail);
  1913. DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_USER)("access auth failed %d. TerminalStage = S", dwUserCode);
  1914. DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_USER).setLogCode("QLR0402501Z10302").setResultCode("RTA5103")("receive accessauth failed result:%d", dwUserCode);
  1915. if (m_bNeedAuthRetry)
  1916. {
  1917. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("retry AccessAuth");
  1918. m_fsm.ToReAccessAuth();
  1919. }
  1920. break;
  1921. case EVENT_MOD_INITIALIZER_MK_LOADED:
  1922. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("init succeed.");
  1923. m_fsm.SetInitSucFlag();
  1924. break;
  1925. case EVENT_MOD_INITIALIZER_MK_FAILED:
  1926. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("init failed.");
  1927. m_fsm.SetInitFailFlag();
  1928. break;
  1929. case EVENT_MOD_FACE_OPENCV_ERROR:
  1930. RestartModule("FaceTracking");
  1931. break;
  1932. case LOG_EVT_INC_VERSION_ROLLBACK:
  1933. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("version to be rollback to %s", pszMessage);
  1934. if (!m_bVerRollback)
  1935. {
  1936. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("rollbacking");
  1937. VersionRollBack(pszMessage);
  1938. }
  1939. break;
  1940. case LOG_EVT_SELFCHECK_TOKEN_KEEPER_LOST:
  1941. {
  1942. ErrorCodeEnum eErr = RestartModule("TokenKeeper");
  1943. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("to re accessauth");
  1944. m_fsm.ToReAccessAuth();
  1945. }
  1946. break;
  1947. case LOG_EVT_HEARTBEAT_CONNECTED:
  1948. UpdateSiteToRuncfg(true, true);
  1949. break;
  1950. case EVENT_MOD_CENTERSETTING_RVCWEBVER_CHANGE:
  1951. m_bNeedToRestartIE = true;
  1952. break;
  1953. case EVENT_MOD_RELEASESIP_TIMEOUT:
  1954. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("RELEASESIP_TIMEOUT.");
  1955. RestartModule("SIPPhone");
  1956. break;
  1957. case LOG_EVT_SELFCHECK_IEBROWSER_IDLE:
  1958. //IE重启之后,重置是否进入主页变量
  1959. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("Browser(Chromuim) to idle.");
  1960. LogWarn(Severity_Low, Error_Unexpect, HealthManager_UserErrorCode_Receive_Browser_Idle
  1961. , "Browser(Chromuim) to idle.");
  1962. m_bBrowserIdleFirst = true;
  1963. break;
  1964. case LOG_EVT_INC_TRADE_MANAGER_NORMAL:
  1965. case LOG_EVT_INC_TRADE_MANAGER_ON:
  1966. case LOG_EVT_INC_TRADE_MANAGER_OFF:
  1967. {
  1968. TradeManage tm;
  1969. if (dwUserCode == LOG_EVT_INC_TRADE_MANAGER_NORMAL)
  1970. tm.op = 0;
  1971. else if (dwUserCode == LOG_EVT_INC_TRADE_MANAGER_ON)
  1972. tm.op = 1;
  1973. else if (dwUserCode == LOG_EVT_INC_TRADE_MANAGER_OFF)
  1974. tm.op = 2;
  1975. tm.time = pszMessage;
  1976. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("trademanager:%d,%s", tm.op, (const char*)tm.time);
  1977. SpSendBroadcast(GetFunction(), SP_MSG_OF(TradeManage), SP_MSG_SIG_OF(TradeManage), tm);
  1978. }
  1979. case LOG_EVT_INC_DEVICE_LOCK_ON:
  1980. case LOG_EVT_INC_DEVICE_UNLOCK:
  1981. case LOG_EVT_INC_DEVICE_KICK_OFF:
  1982. {
  1983. TerminalManager tm;
  1984. if (dwUserCode == LOG_EVT_INC_DEVICE_LOCK_ON)
  1985. tm.op = 0;
  1986. else if (dwUserCode == LOG_EVT_INC_DEVICE_UNLOCK)
  1987. {
  1988. if (m_fsm.GetAccessAuthFlag())
  1989. tm.op = 1;
  1990. else
  1991. tm.op = 99;//oilyang@20170818 according to xingzichen
  1992. }
  1993. else if (dwUserCode == LOG_EVT_INC_DEVICE_KICK_OFF)
  1994. tm.op = 2;
  1995. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("terminal manager:%d", tm.op);
  1996. SpSendBroadcast(GetFunction(), SP_MSG_OF(TerminalManager), SP_MSG_SIG_OF(TerminalManager), tm);
  1997. }
  1998. break;
  1999. case LOG_EVT_PINPAD_OPEN_SUC:
  2000. m_fsm.JudgeIfNeedInitFWB();
  2001. break;
  2002. case EVENT_MOD_CENTERSETTING_CRITICAL_UPDATE:
  2003. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("CenterSetting update some critical item,we need to restart framework.");
  2004. m_bToRestartByCenterSetting = true;
  2005. break;
  2006. default:
  2007. //Dbg("unknown event(%d)...", dwUserCode);
  2008. return;
  2009. }
  2010. }
  2011. void CHealthManagerEntity::OnSysVarEvent(const char *pszKey, const char *pszValue, const char *pszOldValue, const char *pszEntityName)
  2012. {
  2013. if ((_strnicmp(pszKey, "UIState", strlen("UIState")) == 0))
  2014. {
  2015. if (_strnicmp(pszValue, "M", strlen("M")) == 0)
  2016. {
  2017. CSmartPointer<IConfigInfo> spConfigRun;
  2018. ErrorCodeEnum eErr = GetFunction()->OpenConfig(Config_Run, spConfigRun);
  2019. m_bInMainPage = true;
  2020. if (!m_bHaveThrowMainPage)
  2021. {
  2022. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_USER).setLogCode("QLR0402501Z10401")("first enter main page from HealthManager started.");
  2023. m_bHaveThrowMainPage = true;
  2024. //the following lines from linux version
  2025. CSmartPointer<IConfigInfo> spConfigShell;
  2026. GetFunction()->OpenConfig(Config_Shell, spConfigShell);
  2027. CSimpleStringA shellVersion(true);
  2028. spConfigShell->ReadConfigValue("Main", "SoftwareVersion", shellVersion);
  2029. ULONGLONG dwElapse = GetTickCount64();//使用机器启动时间秒数
  2030. DWORD elapseTimeTemp = dwElapse / 1000;
  2031. DWORD dwToMainPageCostTime = elapseTimeTemp - m_dwTimeOfAuthSuc;//从准入通过到首次收到进入首页事件
  2032. CSimpleStringA xMsg = CSimpleStringA::Format("{\"Decripstion\":\"the first enter main page from HealthManger started.\",\"version\":\"%s\",\"elapseTime\":\"%d\",\"enterMainPageTime\":\"%d\"}"
  2033. , m_sysStaticInfo.InstallVersion.ToString().GetData(), elapseTimeTemp, dwToMainPageCostTime);
  2034. LogWarn(Severity_Low, Error_Unexpect, LOG_EVT_HEALTH_FIRST_ENTER_MAINPADE_FROM_HEALTH_START, xMsg.GetData());
  2035. //oilyang@20230518 最大设置时间的3倍、2倍、1倍还没进入首页
  2036. if (dwToMainPageCostTime > m_maxWaitMainpageTime / 1000 * 3)
  2037. DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_USER).setLogCode("QLR0402501Z10401").setResultCode("RTA5106")
  2038. ("After receive accessauth success event, havn't receive enter main page in %d seconds.", m_maxWaitMainpageTime / 1000 * 3);
  2039. else if (dwToMainPageCostTime > m_maxWaitMainpageTime / 1000 * 2)
  2040. DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_USER).setLogCode("QLR0402501Z10401").setResultCode("RTA5105")
  2041. ("After receive accessauth success event, havn't receive enter main page in %d seconds.", m_maxWaitMainpageTime / 1000 *2);
  2042. else if (dwToMainPageCostTime > m_maxWaitMainpageTime / 1000)
  2043. DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_USER).setLogCode("QLR0402501Z10401").setResultCode("RTA5104")
  2044. ("After receive accessauth success event, havn't receive enter main page in %d seconds.", m_maxWaitMainpageTime / 1000);
  2045. }
  2046. if (m_bBrowserIdleFirst)
  2047. {
  2048. DbgWithLink(LOG_LEVEL_INFO,LOG_TYPE_SYSTEM)("the first enter main page from browser started.");
  2049. m_bBrowserIdleFirst = false;
  2050. m_bEnterMainPageEver = true;
  2051. LogEvent(Severity_Middle, LOG_EVT_HEALTH_FIRST_ENTER_MAINPADE, "enter main page");
  2052. ULONGLONG dwElapse = GetTickCount64();//使用机器启动时间秒数
  2053. DWORD elapseTimeTemp = dwElapse / 1000;
  2054. CSimpleStringA xMsg = CSimpleStringA::Format("{\"Decripstion\":\"the first enter main page from browser started.\",\"version\":\"%s\",\"elapseTime\":\"%d\"}"
  2055. , m_sysStaticInfo.InstallVersion.ToString().GetData(), elapseTimeTemp);
  2056. LogWarn(Severity_Low, Error_Unexpect, LOG_EVT_HEALTH_FIRST_ENTER_MAINPADE, xMsg.GetData());
  2057. spConfigRun->WriteConfigValueInt("Run", "UpgradeRestartTimes", 0);
  2058. spConfigRun->WriteConfigValueInt("Run", "UpgradeRestartOSTimes", 0);
  2059. DbgWithLink(LOG_LEVEL_INFO,LOG_TYPE_SYSTEM)("As have been in main page,reset UpgradeRestartTimes.");
  2060. }
  2061. }
  2062. else
  2063. m_bInMainPage = false;
  2064. }
  2065. }
  2066. void CHealthManagerEntity::OnBroadcastEvent(CUUID SubID, const char *pszEntityName, DWORD dwMessageId, DWORD dwMessageSignature, CAutoBuffer Buffer)
  2067. {
  2068. }
  2069. void CHealthManagerEntity::OnTimeout(DWORD dwTimeID)
  2070. {
  2071. switch (dwTimeID)
  2072. {
  2073. case HEALTHMANAGER_WAIT_MAINPAGE_OPEN_TIMER_ID:
  2074. if (!m_bHaveThrowMainPage)
  2075. DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_USER).setLogCode("QLR0402501Z10401").setResultCode("RTA5104")
  2076. ("After receive accessauth success event, havn't receive enter main page in %d seconds.", m_maxWaitMainpageTime / 1000);
  2077. break;
  2078. default:
  2079. break;
  2080. }
  2081. }
  2082. bool CHealthManagerEntity::StartManagerDesktopPage(CSimpleStringA pageName)
  2083. {
  2084. #if defined(RVC_OS_WIN)
  2085. //升级重启弹窗提示
  2086. ChromiumSrv_ClientBase* chromiumClient = new ChromiumSrv_ClientBase(this);
  2087. ErrorCodeEnum error = chromiumClient->Connect();
  2088. if (error == Error_Succeed)
  2089. {
  2090. ChromiumSrv_OpenBrowser_Req req;
  2091. ChromiumSrv_OpenBrowser_Ans ans;
  2092. int width = GetSystemMetrics(SM_CXSCREEN);
  2093. int height = GetSystemMetrics(SM_CYSCREEN);
  2094. auto pFunc = GetFunction();
  2095. CSimpleStringA strPath, statusPagePath, fileStart;
  2096. fileStart = "file:///";
  2097. pFunc->GetPath("Bin", strPath);
  2098. strPath += "\\Chromium\\cefclient.exe";
  2099. pFunc->GetPath("Bin", statusPagePath);
  2100. statusPagePath = statusPagePath + CSimpleStringA("\\..\\res\\ManagerDesktop\\") + pageName;
  2101. statusPagePath = fileStart + statusPagePath;
  2102. req.mainUrl = statusPagePath;
  2103. req.type = "SpecialPageFromOtherEntity";
  2104. req.name = "tempMessage";
  2105. req.param1 = CSimpleStringA::Format("%d*%d", width, height);
  2106. req.param2 = CSimpleStringA::Format("0*0");
  2107. req.top = -1;
  2108. error = chromiumClient->OpenBrowser(req, ans, 10000);
  2109. chromiumClient->GetFunction()->CloseSession();
  2110. if (error != Error_Succeed)
  2111. {
  2112. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("Start chromium page [%s] failed.", statusPagePath.GetData());
  2113. return false;
  2114. }
  2115. else
  2116. {
  2117. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("Start chromium page [%s] success.", statusPagePath.GetData());
  2118. return true;
  2119. }
  2120. }
  2121. return false;
  2122. #else
  2123. return false;
  2124. #endif
  2125. }
  2126. void CHealthManagerEntity::WarnAndRestartFramwork()
  2127. {
  2128. StartManagerDesktopPage("upgradeRestart.html");
  2129. Sleep(5000);
  2130. SaveCurrentVersion();
  2131. SaveFrameStartTimeForUpgrade();
  2132. if (CheckGuardianIsRun(true) > 0)
  2133. {
  2134. ErrorCodeEnum eErr = Error_Unexpect;
  2135. eErr = m_pfUpgradeRestart(1, 0);
  2136. //Dbg("to tell guardian framework is restarting.%d",eErr);
  2137. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("to tell guardian framework is restarting.%d", eErr);
  2138. }
  2139. m_eRebootTrigger = RebootTrigger_FrameUpgrade;
  2140. m_eRebootWay = RebootWay_Framework;
  2141. BOOL bRet = FrameworkShutdown();
  2142. //Dbg("framework shutdown [%d]", bRet);
  2143. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("framework shutdown in restart task [%d]", bRet);
  2144. }
  2145. void CHealthManagerEntity::ControlEntityLife(SpReqAnsContext<HealthManagerService_ControlEntityLife_Req, HealthManagerService_ControlEntityLife_Ans>::Pointer ctx)
  2146. {
  2147. ErrorCodeEnum result(Error_Succeed);
  2148. ErrorCodeEnum tmpResult(Error_Succeed);
  2149. CSimpleStringA tmpMsg(true);
  2150. if (ctx->Req.devId == 0 && ctx->Req.entityName.IsNullOrEmpty()) {
  2151. result = Error_Param;
  2152. }
  2153. else {
  2154. if (ctx->Req.entityName.IsNullOrEmpty()) {
  2155. ///**TODO(Gifur@10/22/2021): */
  2156. result = Error_NotImpl;
  2157. }
  2158. else {
  2159. tmpResult = DealSpecifiedEntity((DealType)ctx->Req.option, ctx->Req.entityName, ctx->Req.param, ctx->Req.force, tmpMsg);
  2160. }
  2161. }
  2162. ctx->Ans.result = tmpResult;
  2163. ctx->Ans.msg = tmpMsg;
  2164. ctx->Answer(result);
  2165. }
  2166. void CHealthManagerEntity::Gateway(SpReqAnsContext<HealthManagerService_Gateway_Req, HealthManagerService_Gateway_Ans>::Pointer ctx)
  2167. {
  2168. ErrorCodeEnum result(Error_Succeed);
  2169. ErrorCodeEnum tmpResult(Error_Succeed);
  2170. CSimpleStringA tmpMsg(true);
  2171. if (ctx->Req.type != 1) {
  2172. result = Error_NotSupport;
  2173. } else {
  2174. result = Error_Deprecated;
  2175. }
  2176. ctx->Ans.result = tmpResult;
  2177. ctx->Ans.msg = tmpMsg;
  2178. ctx->Answer(result);
  2179. }
  2180. ErrorCodeEnum CHealthManagerEntity::GetTmpRootFilePath(CSimpleStringA& rootPath, CSimpleStringA& rootTmpPath, CSimpleStringA& rootBackPath)
  2181. {
  2182. CSimpleStringA strRootCfgPath;
  2183. ErrorCodeEnum ec = GetFunction()->GetPath("HardwareCfg", strRootCfgPath);
  2184. rootPath = strRootCfgPath;
  2185. rootPath += SPLIT_SLASH_STR;
  2186. rootPath += "root.ini";
  2187. rootTmpPath = rootPath + ".tmp";
  2188. SYSTEMTIME curTime = CSmallDateTime::GetNow().ToSystemTime();
  2189. CSimpleStringA strBackupFileSuffix = CSimpleStringA::Format(".bak%04d%02d%02d%02d%02d%02d%03d",
  2190. curTime.wYear, curTime.wMonth, curTime.wDay, curTime.wHour, curTime.wMinute, curTime.wSecond, curTime.wMilliseconds);
  2191. rootBackPath = rootPath + strBackupFileSuffix;
  2192. return ec;
  2193. }
  2194. void CHealthManagerEntity::RecordInstallBeginTimeStamp(const CSimpleString& strTimeStamp, BOOL forceReset)
  2195. {
  2196. if (!forceReset) {
  2197. CSimpleStringA strReserved(true);
  2198. const ErrorCodeEnum rc = GetInstallBeginTimeStamp(strReserved);
  2199. if (!strReserved.IsNullOrEmpty()) {
  2200. return;
  2201. }
  2202. }
  2203. CSmartPointer<IConfigInfo> pConfig;
  2204. GetFunction()->OpenConfig(Config_Cache, pConfig);
  2205. if (strTimeStamp.IsNullOrEmpty()) {
  2206. pConfig->WriteConfigValue("TerminalDeploy", "StartTimeStamp", CSimpleStringA::Format("0x%08X", (DWORD)CSmallDateTime::GetNow()));
  2207. }
  2208. else {
  2209. pConfig->WriteConfigValue("TerminalDeploy", "StartTimeStamp", strTimeStamp);
  2210. }
  2211. }
  2212. ErrorCodeEnum CHealthManagerEntity::GetInstallBeginTimeStamp(CSimpleString& strTimeStamp)
  2213. {
  2214. CSmartPointer<IConfigInfo> pConfig;
  2215. GetFunction()->OpenConfig(Config_Cache, pConfig);
  2216. CSimpleStringA strValue(true);
  2217. pConfig->ReadConfigValue("TerminalDeploy", "StartTimeStamp", strValue);
  2218. if (strValue.IsNullOrEmpty()) {
  2219. return Error_DataCheck;
  2220. }
  2221. strTimeStamp = strValue;
  2222. return Error_Succeed;
  2223. }
  2224. ErrorCodeEnum CHealthManagerEntity::GetGuidePageUrlWithStep(int whichStep, CSimpleStringA& strUrl)
  2225. {
  2226. strUrl.Clear();
  2227. CSimpleStringA pagePath;
  2228. ErrorCodeEnum ec = GetFunction()->GetPath("Base", pagePath);
  2229. pagePath.Append(SPLIT_SLASH_STR "res" SPLIT_SLASH_STR "ManagerDesktop" SPLIT_SLASH_STR "guide.html");
  2230. if (whichStep > 0) {
  2231. CSimpleStringA terminalNo;
  2232. CSimpleStringA vendorType;
  2233. CSimpleStringA serverIP;
  2234. do {
  2235. CSmartPointer<IConfigInfo> pConfig;
  2236. GetFunction()->OpenConfig(Config_Cache, pConfig);
  2237. const ErrorCodeEnum ec0 = pConfig->ReadConfigValue("TerminalDeploy", "TerminalNo", terminalNo);
  2238. const ErrorCodeEnum ec1 = pConfig->ReadConfigValue("TerminalDeploy", "Manufacturer", vendorType);
  2239. const ErrorCodeEnum ec2 = pConfig->ReadConfigValue("TerminalDeploy", "ServerIP", serverIP);
  2240. Dbg("read step: %s, %s, %s", SpStrError(ec0), SpStrError(ec1), SpStrError(ec2));
  2241. } while (false);
  2242. pagePath = CSimpleStringA::Format("%s?page=%d", pagePath.GetData(), whichStep);
  2243. bool prefix(true);
  2244. if (!terminalNo.IsNullOrEmpty() || !vendorType.IsNullOrEmpty() || !serverIP.IsNullOrEmpty()) {
  2245. CSimpleStringA strSearch(true);
  2246. if (!terminalNo.IsNullOrEmpty()) {
  2247. if (prefix) strSearch += "&";
  2248. strSearch += CSimpleStringA("terminalno=") + terminalNo;
  2249. prefix = true;
  2250. }
  2251. if (!vendorType.IsNullOrEmpty()) {
  2252. if (prefix) strSearch += "&";
  2253. strSearch += CSimpleStringA("vendor=") + vendorType;
  2254. prefix = true;
  2255. }
  2256. if (!serverIP.IsNullOrEmpty()) {
  2257. if (prefix) strSearch += "&";
  2258. strSearch += CSimpleStringA("ip=") + serverIP;
  2259. prefix = true;
  2260. }
  2261. pagePath += strSearch;
  2262. }
  2263. }
  2264. strUrl = CSimpleStringA("file:///") + pagePath + CSimpleStringA("");
  2265. return ec;
  2266. }
  2267. namespace
  2268. {
  2269. ErrorCodeEnum SplitAdapterFileName(CSimpleStringA strFileName, CAutoArray<CSimpleStringA>& values)
  2270. {
  2271. #ifdef RVC_OS_WIN
  2272. CSimpleStringA strPrefix("");
  2273. CSimpleStringA strSuffix(".dll");
  2274. #else
  2275. CSimpleStringA strPrefix("lib");
  2276. CSimpleStringA strSuffix(".so");
  2277. #endif //RVC_OS_WIN
  2278. if (strFileName.GetLength() < strPrefix.GetLength() + strSuffix.GetLength()) {
  2279. return Error_Param;
  2280. }
  2281. CSimpleStringA pureAdapterName = strFileName.SubString(
  2282. strPrefix.GetLength(), strFileName.GetLength() - strPrefix.GetLength() - strSuffix.GetLength());
  2283. values = pureAdapterName.Split('.');
  2284. if (values.GetCount() != 4) {
  2285. return Error_DataCheck;
  2286. }
  2287. return Error_Succeed;
  2288. }
  2289. }
  2290. ErrorCodeEnum CHealthManagerEntity::TellChromiumOpenGuidePage(const CSimpleStringA& pageUrl)
  2291. {
  2292. ErrorCodeEnum result(Error_Succeed);
  2293. auto pClient = new ChromiumSrv_ClientBase(this);
  2294. result = pClient->Connect();
  2295. if (result == Error_Succeed) {
  2296. ChromiumSrv_OpenBrowser_Req req;
  2297. ChromiumSrv_OpenBrowser_Ans ans;
  2298. req.mainUrl = pageUrl;
  2299. req.viceUrl = "";
  2300. req.type = "OutsideRequest";
  2301. req.name = "GuidePage";
  2302. req.exclusiveMode = true;
  2303. req.top = -1;
  2304. result = pClient->OpenBrowser(req, ans, 10000);
  2305. if (result == Error_Succeed) {
  2306. Dbg("Request Chromium::OpenBrowser succ!");
  2307. }
  2308. else {
  2309. Dbg("Request Chromium::OpenBrowser failed: %s", SpStrError(result));
  2310. }
  2311. pClient->GetFunction()->CloseSession();
  2312. }
  2313. else {
  2314. pClient->SafeDelete();
  2315. Dbg("Connect to Chromium entity failed: %s", SpStrError(result));
  2316. }
  2317. return result;
  2318. }
  2319. ErrorCodeEnum CHealthManagerEntity::DealSpecifiedEntity(DealType type, LPCTSTR lpcszEntityName, LPCTSTR lpcszCmdline, bool bForce, CSimpleStringA& strErrMsg)
  2320. {
  2321. ErrorCodeEnum result(Error_Succeed);
  2322. strErrMsg.Clear();
  2323. switch (type) {
  2324. case Deal_Start:
  2325. {
  2326. CSmartPointer<IEntityFunction> pFunc = GetFunction();
  2327. CSmartPointer<IEntityFunctionPrivilege> pFuncPrivilege = pFunc.ConvertCase<IEntityFunctionPrivilege>();
  2328. CSimpleStringA strEntityName(lpcszEntityName);
  2329. CEntityRunInfo info = {};
  2330. result = GetFunction()->GetEntityRunInfo(strEntityName, info);
  2331. bool toStart(true);
  2332. Dbg("entity: %s, %s,%s", strEntityName.GetData(), SpStrError(result), SpStrEntityState(info.eState));
  2333. if ((info.eState != EntityState_NoStart && info.eState == EntityState_Lost
  2334. && info.eState == EntityState_Close && info.eState == EntityState_UnLoading)
  2335. && (bForce)) {
  2336. }
  2337. if (info.eState != EntityState_NoStart && bForce) {
  2338. Dbg("to terminal entity..");
  2339. CSmartPointer<IAsynWaitSp> spWait;
  2340. result = pFuncPrivilege->StopEntity(strEntityName, spWait);
  2341. Dbg("stop entity return %s", SpStrError(result));
  2342. if (result == Error_Succeed && spWait != NULL) {
  2343. Dbg("to wait after stop...");
  2344. result = spWait->WaitAnswer(60 * 1000);
  2345. Dbg("wait result: %s", SpStrError(result));
  2346. if (result != Error_Succeed) {
  2347. CSmartPointer<IAsynWaitSp> spWait2;
  2348. result = pFuncPrivilege->TerminateEntity(strEntityName, spWait2);
  2349. Dbg("terminal entity return %s", SpStrError(result));
  2350. if (result == Error_Succeed && spWait2 != NULL) {
  2351. Dbg("to wait after terminal...");
  2352. result = spWait2->WaitAnswer(60 * 1000);
  2353. Dbg("wait result: %s", SpStrError(result));
  2354. }
  2355. }
  2356. }
  2357. if (result != Error_Succeed) {
  2358. strErrMsg = CSimpleStringA::Format("重启前停止实体失败 %s, %s", SpStrEntityState(info.eState), SpStrError(result));
  2359. toStart = false;
  2360. }
  2361. }
  2362. else if (info.eState != EntityState_NoStart) {
  2363. result = Error_InvalidState;
  2364. strErrMsg = CSimpleStringA::Format("实体[%s]当前状态(%s)不支持该操作", strEntityName.GetData(), SpStrEntityState(info.eState));
  2365. toStart = false;
  2366. }
  2367. if (toStart) {
  2368. Dbg("to start entity..");
  2369. CSmartPointer<IAsynWaitSp> spWait;
  2370. result = pFuncPrivilege->StartEntity(strEntityName, lpcszCmdline, spWait);
  2371. Dbg("start entity return %s", SpStrError(result));
  2372. if (result == Error_Succeed && spWait != NULL) {
  2373. Dbg("to wait...");
  2374. result = spWait->WaitAnswer(60 * 1000);
  2375. Dbg("wait result: %s", SpStrError(result));
  2376. }
  2377. if (result != Error_Succeed) {
  2378. strErrMsg = CSimpleStringA::Format("启动实体失败 %s", SpStrError(result));
  2379. }
  2380. }
  2381. }
  2382. break;
  2383. case Deal_Close:
  2384. result = Error_NotImpl;
  2385. break;
  2386. case Deal_Pause:
  2387. result = Error_NotImpl;
  2388. break;
  2389. case Deal_Continue:
  2390. result = Error_NotImpl;
  2391. break;
  2392. case Deal_Kill:
  2393. result = Error_NotImpl;
  2394. break;
  2395. case Deal_Test:
  2396. result = Error_NotImpl;
  2397. break;
  2398. case Deal_Restart:
  2399. result = Error_NotImpl;
  2400. break;
  2401. default:
  2402. result = Error_NotSupport;
  2403. break;
  2404. }
  2405. return result;
  2406. }
  2407. void CHealthManagerEntity::DeployTerminal(SpReqAnsContext<HealthManagerService_DeployTerminal_Req, HealthManagerService_DeployTerminal_Ans>::Pointer ctx)
  2408. {
  2409. #if defined(RVC_OS_LINUX)
  2410. LOG_FUNCTION();
  2411. ErrorCodeEnum result(Error_Succeed);
  2412. int tmpResult = 0;
  2413. CSimpleStringA tmpMsg(true);
  2414. Dbg("Cmd: %d", ctx->Req.currStep);
  2415. switch (ctx->Req.currStep) {
  2416. case DeployStep_Begin:
  2417. {
  2418. if (ctx->Req.options == 1) { //重置配置
  2419. CSmartPointer<IConfigInfo> pConfig;
  2420. GetFunction()->OpenConfig(Config_Cache, pConfig);
  2421. int lastStep(0), stepStatus(0);
  2422. pConfig->ReadConfigValueInt("TerminalDeploy", "CurrStep", lastStep);
  2423. pConfig->ReadConfigValueInt("TerminalDeploy", "CurrState", stepStatus);
  2424. if (lastStep > 0 && (stepStatus == DEPLOYSTATE_NOTINIT)) {
  2425. lastStep--;
  2426. Dbg("draw back to %d", lastStep);
  2427. }
  2428. else if (lastStep != 0) {
  2429. Dbg("current step: %d", lastStep);
  2430. }
  2431. else if (!m_fConfigMode) {
  2432. lastStep = DeployStep_Finished;
  2433. Dbg("reset to finished step");
  2434. }
  2435. for (int cur = lastStep; cur > 0; --cur) {
  2436. switch (cur) {
  2437. case DeployStep_GetTerminalInfo:
  2438. {
  2439. Dbg("clear terminalno etc at cache file...");
  2440. pConfig->WriteConfigValue("TerminalDeploy", "TerminalNo", NULL);
  2441. pConfig->WriteConfigValue("TerminalDeploy", "Manufacturer", NULL);
  2442. pConfig->WriteConfigValue("TerminalDeploy", "ServerIP", NULL);
  2443. pConfig->WriteConfigValue("TerminalDeploy", "HeadOfficeMode", NULL);
  2444. pConfig->WriteConfigValue("TerminalDeploy", "InstallVersion", NULL);
  2445. pConfig->WriteConfigValue("TerminalDeploy", "LastInfo", NULL);
  2446. }
  2447. break;
  2448. case DeployStep_FetchCenterSettings:
  2449. {
  2450. //清理集中配置文件
  2451. Dbg("clear centersetting files...");
  2452. CSimpleStringA strEntityCfgPath;
  2453. tmpResult = GetFunction()->GetPath("Cfg", strEntityCfgPath);
  2454. array_header_t* subs = fileutil_get_sub_files_a(strEntityCfgPath);
  2455. if (subs) {
  2456. regex_t reg;
  2457. CSimpleStringA pattern = "CenterSetting\.[a-zA-Z0-9_\\(\\)\\-]*\.ini";
  2458. int ret = regcomp(&reg, pattern, REG_EXTENDED | REG_NOSUB);
  2459. if (ret) {
  2460. char ebuff[256];
  2461. regerror(ret, &reg, ebuff, 256);
  2462. Dbg("regex failed: %s", ebuff);
  2463. tmpResult = Error_Unexpect;
  2464. tmpMsg = CSimpleStringA::Format("内部错误:REGEX %s", ebuff);
  2465. toolkit_array_free2(subs);
  2466. break;
  2467. }
  2468. Dbg("pattern: %s", pattern.GetData());
  2469. for (int i = 0; i < subs->nelts; ++i) {
  2470. char* filenamePath = ARRAY_IDX(subs, i, char*);
  2471. char* filename = &filenamePath[strEntityCfgPath.GetLength() + 1];
  2472. ret = regexec(&reg, filename, 0, NULL, 0);
  2473. if (0 == ret) {
  2474. Dbg("filename %s matched and remove it.", filename);
  2475. fileutil_delete_file(filenamePath);
  2476. }
  2477. }
  2478. toolkit_array_free2(subs);
  2479. }
  2480. }
  2481. break;
  2482. case DeployStep_AccessAuthorize:
  2483. break;
  2484. case DeployStep_MediaConfig:
  2485. break;
  2486. default:
  2487. break;
  2488. }
  2489. }
  2490. /*读取第一启动的时间戳,有用*/
  2491. CSimpleStringA strBeginTimeReserved(true);
  2492. GetInstallBeginTimeStamp(strBeginTimeReserved);
  2493. CSimpleStringA strCachePath;
  2494. CSimpleStringA strRootTmpFile;
  2495. CSimpleStringA strRootIniFullPath;
  2496. CSimpleStringA strRunInfoDirPath;
  2497. CSimpleStringA strRunCfgDirPath;
  2498. ///**TODO(Gifur@4/21/2022): 既然删除了,前面就没必要清空字段内容了 */
  2499. GetFunction()->GetPath("RunInfo", strRunInfoDirPath);
  2500. strCachePath = strRunInfoDirPath + SPLIT_SLASH_STR + "Global.ini";
  2501. if (ExistsFileA(strCachePath)) {
  2502. Dbg("delete cache file");
  2503. fileutil_delete_file(strCachePath);
  2504. }
  2505. GetFunction()->GetPath("RunCfg", strRunCfgDirPath);
  2506. if (strRunCfgDirPath.IsNullOrEmpty()) {
  2507. strRunCfgDirPath = strRunInfoDirPath + SPLIT_SLASH_STR + "runcfg";
  2508. }
  2509. else {
  2510. Dbg("Get RunCfg from GetPath directly:%s", strRunCfgDirPath.GetData());
  2511. }
  2512. if (ExistsDirA(strRunCfgDirPath)) {
  2513. Dbg("remove runinfo dir");
  2514. RemoveDirRecursiveA(strRunCfgDirPath);
  2515. }
  2516. CSimpleStringA strBackupFile;
  2517. GetTmpRootFilePath(strRootIniFullPath, strRootTmpFile, strBackupFile);
  2518. if (ExistsFileA(strRootIniFullPath)) {
  2519. Dbg("delete root.ini");
  2520. fileutil_copy_file(strBackupFile, strRootIniFullPath);
  2521. fileutil_delete_file(strRootIniFullPath);
  2522. }
  2523. LogWarn(Severity_High, Error_Debug, LOG_WARN_HEALTH_INSTALL_RESET, "user requires installation reset!");
  2524. /** 将首次安装的时间写进去*/
  2525. if (!strBeginTimeReserved.IsNullOrEmpty()) {
  2526. RecordInstallBeginTimeStamp(strBeginTimeReserved);
  2527. }
  2528. }
  2529. else {
  2530. result = Error_NotImpl;
  2531. }
  2532. }
  2533. break;
  2534. case DeployStep_GetTerminalInfo:
  2535. {
  2536. if (ctx->Req.options == 0) {
  2537. CAutoArray<CSimpleStringA> arrs = ctx->Req.param4.Split('|');
  2538. const CSimpleStringA& terminalNo = arrs[0];
  2539. //终端类型(行内定义)
  2540. const CSimpleStringA& strTerminalType = arrs[1];
  2541. const CSimpleStringA& serverIP = ctx->Req.param3;
  2542. Dbg("server ip: %s, terminal no: %s, type: %s", serverIP.GetData(), (LPCTSTR)terminalNo, (LPCTSTR)strTerminalType);
  2543. CSimpleStringA strVendorName(true);
  2544. CSimpleStringA strZhCNVendorName(true);
  2545. CSimpleStringA strDeviceModel(true);
  2546. CSimpleStringA strDeviceSN(true);
  2547. if (ctx->Req.array2.GetCount() > 0) {
  2548. //硬件厂商
  2549. strVendorName = ctx->Req.array2[0];
  2550. //硬件设备型号(厂商)
  2551. strDeviceModel = ctx->Req.array2[1];
  2552. //设备序列号
  2553. strDeviceSN = ctx->Req.array2[2];
  2554. Dbg("vendor: %s, model:%s, sn: %s", strVendorName.GetData(), strDeviceModel.GetData(), strDeviceSN.GetData());
  2555. }
  2556. bool toRecord(false);
  2557. bool fHeadOfficeMode(false);
  2558. CSimpleStringA matchInfo(true);
  2559. ///**TODO(Gifur@4/21/2022): 走分行的逻辑后续要移除 */
  2560. if (ctx->Req.param1 == 0) { //走分行服务
  2561. CTerminalInfoQuery* pCnn = new CTerminalInfoQuery(this);
  2562. /** 1050 是固定的服务端实体端口 [Gifur@20211013]*/
  2563. const bool ret = pCnn->ConnectServer(serverIP.GetData(), 1050);
  2564. Dbg("Connect finished: %d", ret);
  2565. if (pCnn->IsConnectionOK()) {
  2566. Dbg("Connect OK!");
  2567. TerminalRegistRet info;
  2568. result = pCnn->GetTerminalInfo(terminalNo.GetData(), &info);
  2569. pCnn->Close();
  2570. PrintTerminalRegistInfo(&info);
  2571. if (strlen(info.TerminalNo) == 0) {
  2572. tmpResult = Error_NotExist;
  2573. tmpMsg = "查询终端信息不存在,请检测输入的终端号是否正确";
  2574. }
  2575. else if (terminalNo.Compare(info.TerminalNo) != 0) {
  2576. tmpResult = Error_MisMatched;
  2577. tmpMsg = CSimpleStringA::Format("查询返回的终端信息不匹配,输入:%s,返回:%s", terminalNo.GetData(), info.TerminalNo);
  2578. }
  2579. else {
  2580. toRecord = true;
  2581. }
  2582. }
  2583. else {
  2584. Dbg("Connect Failed!");
  2585. result = Error_ConnectFailed;
  2586. }
  2587. pCnn->DecRefCount();
  2588. pCnn = NULL;
  2589. }
  2590. else if (ctx->Req.param1 == 1) { //走总行服务
  2591. fHeadOfficeMode = true;
  2592. HttpClientRequestConfig config(serverIP.GetData());
  2593. HttpClientResponseResult result;
  2594. config.SetChildUri(URLPATH_REGISTER_FULL_LIST);
  2595. config.AppendQuery("terminalNo", terminalNo.GetData());
  2596. RestfulClient client = RestfulClient::getInstance();
  2597. config.PreDo();
  2598. client.Do(&config, &result);
  2599. if (result.ResponseOK()) {
  2600. struct CommResponseJson : public MicroServices::API::CommResponse {
  2601. JSONCONVERT2OBJECT_MEMEBER_REGISTER(success, errorCode, returnCode, errorMsg, message)
  2602. };
  2603. CommResponseJson reponseStatus;
  2604. struct RegistInfoJson : public MicroServices::API::Manage::RegistDetailInfo {
  2605. JSONCONVERT2OBJECT_MEMEBER_REGISTER(branchNo, deviceNo, initIP, machineNo, machineType, machineVersion, sites, terminalNo, manufactureID, manufacturerName, deviceTye)
  2606. } terminalRegistInfo;
  2607. Json::Value rawRoot;
  2608. bool testSucc(false);
  2609. do
  2610. {
  2611. if (!GetJsonRootObject(rawRoot, result.content)) {
  2612. Dbg("%d", __LINE__);
  2613. break;
  2614. }
  2615. if (!Json2Object(reponseStatus, rawRoot)) {
  2616. Dbg("%d", __LINE__);
  2617. break;
  2618. }
  2619. if (!reponseStatus.IsOperatedOK()) {
  2620. Dbg("%d", __LINE__);
  2621. break;
  2622. }
  2623. if (!(rawRoot["data"].size() > 0)) {
  2624. Dbg("%d", __LINE__);
  2625. break;
  2626. }
  2627. if (!Json2Object(terminalRegistInfo, rawRoot["data"][0])) {
  2628. Dbg("%d", __LINE__);
  2629. break;
  2630. }
  2631. testSucc = true;
  2632. } while (false);
  2633. if (testSucc) {
  2634. auto printFunc = [&terminalRegistInfo]() {
  2635. Dbg("TerminalNo: %s", terminalRegistInfo.terminalNo.c_str());
  2636. Dbg("BranchNo: %s", terminalRegistInfo.branchNo.c_str());
  2637. Dbg("DeviceNo: %s", terminalRegistInfo.deviceNo.c_str());
  2638. Dbg("IP: %s", terminalRegistInfo.initIP.c_str());
  2639. Dbg("MachineNo: %s", terminalRegistInfo.machineNo.c_str());
  2640. Dbg("MachineType: %s", terminalRegistInfo.machineType.c_str());
  2641. Dbg("MachineVersion: %s", terminalRegistInfo.machineVersion.c_str());
  2642. Dbg("Sites: %s", terminalRegistInfo.sites.c_str());
  2643. Dbg("manufactureID: %s", terminalRegistInfo.manufactureID.c_str());
  2644. Dbg("manufacturerName: %s", terminalRegistInfo.manufacturerName.c_str());
  2645. /** Agent: 终端设备型号*/
  2646. Dbg("deviceTye: %s", terminalRegistInfo.deviceTye.c_str());
  2647. };
  2648. printFunc();
  2649. if (!terminalRegistInfo.manufactureID.empty() && terminalRegistInfo.manufacturerName.empty()) {
  2650. CommResponseJson reponseStatus2;
  2651. HttpClientResponseResult result2;
  2652. Json::Value rawRoot2;
  2653. config.SetChildUri(URLPATH_MANUFACTURE_GET_ALL);
  2654. config.ResetQuery();
  2655. config.PreDo();
  2656. client.Do(&config, &result2);
  2657. bool fetchManufactureDone(false);
  2658. if (result2.ResponseOK() && GetJsonRootObject(rawRoot2, result2.content)
  2659. && Json2Object(reponseStatus2, rawRoot2) && reponseStatus2.IsOperatedOK()) {
  2660. struct ManufactureInfoJson : public MicroServices::API::Manufacture::ManufactureInfo {
  2661. JSONCONVERT2OBJECT_MEMEBER_REGISTER(manufacturerId, manufacturerName)
  2662. };
  2663. struct ManufactureList {
  2664. std::vector<ManufactureInfoJson> data;
  2665. JSONCONVERT2OBJECT_MEMEBER_REGISTER(data)
  2666. } manufactureList;
  2667. if (Json2Object(manufactureList, rawRoot2)) {
  2668. for (auto it = manufactureList.data.begin(); it != manufactureList.data.end(); ++it) {
  2669. if (it->manufacturerId.compare(terminalRegistInfo.manufactureID) == 0) {
  2670. terminalRegistInfo.manufacturerName = it->manufacturerName;
  2671. Dbg("get manufacturer name: %s", terminalRegistInfo.manufacturerName.c_str());
  2672. fetchManufactureDone = true;
  2673. break;
  2674. }
  2675. }
  2676. }
  2677. }
  2678. if (!fetchManufactureDone) {
  2679. if (reponseStatus2.IsNotEmpty() && !reponseStatus2.IsOperatedOK()) {
  2680. Dbg("请求失败:%s", reponseStatus2.WhatError().c_str());
  2681. }
  2682. else {
  2683. Dbg("解析返回内容失败:%s", result2.content.c_str());
  2684. }
  2685. }
  2686. }
  2687. printFunc();
  2688. if (terminalRegistInfo.terminalNo.empty()) {
  2689. tmpResult = Error_NotExist;
  2690. tmpMsg = "查询终端信息不存在,请检测输入的终端号是否正确";
  2691. }
  2692. else if (terminalRegistInfo.terminalNo != terminalNo.GetData()) {
  2693. tmpResult = Error_MisMatched;
  2694. tmpMsg = CSimpleStringA::Format("查询返回的终端信息不匹配,输入:%s,返回:%s"
  2695. , terminalNo.GetData(), terminalRegistInfo.terminalNo.c_str());
  2696. }
  2697. else {
  2698. bool bMatched(true);
  2699. /** 考虑到测试环境数据不准确,这里加一个开关跳过 [Gifur@2023421]*/
  2700. bool criticialCheck(true);
  2701. #ifndef DEVOPS_ON_PRD
  2702. CSmartPointer<IConfigInfo> spConfigShell;
  2703. GetFunction()->OpenConfig(Config_Shell, spConfigShell);
  2704. int nValue(0);
  2705. spConfigShell->ReadConfigValueInt("InstallProc", "SkipTerminalInfoCheck", nValue);
  2706. if (!!nValue) {
  2707. criticialCheck = false;
  2708. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("Skip terminal info check task!!");
  2709. }
  2710. #endif // !DEVOPS_ON_PRD
  2711. if (criticialCheck) {
  2712. if (strTerminalType.Compare(terminalRegistInfo.machineType.c_str()) != 0) {
  2713. if (!matchInfo.IsNullOrEmpty()) { matchInfo += ";"; }
  2714. matchInfo += CSimpleStringA::Format("终端类型不匹配:[%s]vs[%s]", strTerminalType.GetData(), terminalRegistInfo.machineType.c_str());
  2715. bMatched = false;
  2716. }
  2717. //terminalRegistInfo.manufacturerName = "中钞科堡现金处理";
  2718. if (strVendorName.Compare(terminalRegistInfo.manufacturerName.c_str(), true) != 0) {
  2719. do {
  2720. CSmartPointer<IConfigInfo> spCfgConfig;
  2721. GetFunction()->OpenConfig(Config_Software, spCfgConfig);
  2722. spCfgConfig->ReadConfigValue("VendorZhCN", strVendorName, strZhCNVendorName);
  2723. } while (false);
  2724. if (!strZhCNVendorName.IsNullOrEmpty()
  2725. && terminalRegistInfo.manufacturerName.find(strZhCNVendorName.GetData()) != std::string::npos) {
  2726. //let it empty.
  2727. }
  2728. else {
  2729. if (!matchInfo.IsNullOrEmpty()) { matchInfo += ";"; }
  2730. if (strZhCNVendorName.IsNullOrEmpty()) {
  2731. matchInfo += CSimpleStringA::Format("设备厂商不匹配:[%s]vs[%s]", strVendorName.GetData(), terminalRegistInfo.manufacturerName.c_str());
  2732. }
  2733. else {
  2734. matchInfo += CSimpleStringA::Format("设备厂商不匹配:[%s]vs[%s]", strZhCNVendorName.GetData(), terminalRegistInfo.manufacturerName.c_str());
  2735. }
  2736. bMatched = false;
  2737. }
  2738. }
  2739. if (strDeviceModel.Compare(terminalRegistInfo.deviceTye.c_str()) != 0) {
  2740. if (!matchInfo.IsNullOrEmpty()) { matchInfo += ";"; }
  2741. matchInfo += CSimpleStringA::Format("设备型号不匹配:[%s]vs[%s]", strDeviceModel.GetData(), terminalRegistInfo.deviceTye.c_str());
  2742. bMatched = false;
  2743. }
  2744. /** Agent: 设备编号*/
  2745. if (strDeviceSN.Compare(terminalRegistInfo.machineNo.c_str()) != 0) {
  2746. if (!matchInfo.IsNullOrEmpty()) { matchInfo += ";"; }
  2747. matchInfo += CSimpleStringA::Format("设备序列号(编号)不匹配:[%s]vs[%s]", strDeviceSN.GetData(), terminalRegistInfo.machineNo.c_str());
  2748. bMatched = false;
  2749. }
  2750. /** 其他信息的校验和应用 [Gifur@2022123]*/
  2751. }
  2752. if (!bMatched) {
  2753. tmpResult = Error_DataCheck;
  2754. if (!matchInfo.IsNullOrEmpty()) { matchInfo += "。请核验录入信息是否准确!"; }
  2755. tmpMsg = matchInfo;
  2756. }
  2757. else {
  2758. toRecord = true;
  2759. }
  2760. }
  2761. }
  2762. else {
  2763. if (reponseStatus.IsNotEmpty() && !reponseStatus.IsOperatedOK()) {
  2764. tmpResult = Error_DataCheck;
  2765. tmpMsg = CSimpleStringA::Format("请求失败:%s", reponseStatus.WhatError().c_str());
  2766. Dbg(tmpMsg);
  2767. }
  2768. else {
  2769. tmpResult = Error_DataCheck;
  2770. tmpMsg = CSimpleStringA::Format("解析返回内容失败:%s", result.content.c_str());
  2771. Dbg(tmpMsg);
  2772. Dbg("rawRoot[data].size(): %d", rawRoot["data"].size());
  2773. }
  2774. }
  2775. }
  2776. else {
  2777. tmpResult = Error_ServerNotAvailable;
  2778. if (!result.content.empty()) {
  2779. tmpMsg = CSimpleStringA::Format("访问 %s 失败:%d,%s", config.GetRequestUri().c_str(), result.statusCode, result.content.c_str());
  2780. }
  2781. else {
  2782. tmpMsg = CSimpleStringA::Format("访问 %s 失败:%d", config.GetRequestUri().c_str(), result.statusCode);
  2783. }
  2784. }
  2785. }
  2786. if (toRecord) {
  2787. ErrorCodeEnum ec(Error_Succeed);
  2788. do {
  2789. Dbg("record to cache...");
  2790. CSmartPointer<IConfigInfo> pConfig;
  2791. GetFunction()->OpenConfig(Config_Cache, pConfig);
  2792. const ErrorCodeEnum ec0 = pConfig->WriteConfigValue("TerminalDeploy", "TerminalNo", terminalNo);
  2793. const ErrorCodeEnum ec1 = pConfig->WriteConfigValue("TerminalDeploy", "Manufacturer", strVendorName);
  2794. const ErrorCodeEnum ec2 = pConfig->WriteConfigValue("TerminalDeploy", "ServerIP", serverIP);
  2795. const ErrorCodeEnum ec3 = pConfig->WriteConfigValueInt("TerminalDeploy", "HeadOfficeMode", fHeadOfficeMode ? 1 : 0);
  2796. if (!matchInfo.IsNullOrEmpty()) {
  2797. pConfig->WriteConfigValue("TerminalDeploy", "LastInfo", matchInfo);
  2798. }
  2799. Dbg("record step: %s, %s, %s", SpStrError(ec0), SpStrError(ec1), SpStrError(ec2), SpStrError(ec3));
  2800. } while (false);
  2801. do {
  2802. CSimpleStringA strRootCfgPath;
  2803. CSimpleStringA strRootTmpFile;
  2804. CSimpleStringA strRootIniFullPath;
  2805. CSimpleStringA strRootChosenFile(true);
  2806. CSimpleStringA strNousedPath;
  2807. ec = GetTmpRootFilePath(strRootIniFullPath, strRootTmpFile, strNousedPath);
  2808. ///**TODO(Gifur@10/16/2021): ASSERT 在这个步骤root.ini 文件不应该出现的,可能是字段的缺失才识别为未配置模式 */
  2809. if (ExistsFileA(strRootIniFullPath)) {
  2810. fileutil_copy_file(strNousedPath, strRootIniFullPath);
  2811. fileutil_delete_file(strRootIniFullPath);
  2812. Dbg("root.ini exists!");
  2813. }
  2814. const CSimpleStringA machineType(strTerminalType);
  2815. const CSimpleStringA rootPattern("root");
  2816. const CSimpleStringA pattern = rootPattern + "\\-" + machineType + "\\-" + strVendorName + "\\-[a-zA-Z0-9_\\(\\)\\-]*" + ".ini";
  2817. ec = GetFunction()->GetPath("HardwareCfg", strRootCfgPath);
  2818. array_header_t* subs = fileutil_get_sub_files_a(strRootCfgPath);
  2819. if (subs) {
  2820. regex_t reg;
  2821. int ret = regcomp(&reg, pattern, REG_EXTENDED | REG_NOSUB);
  2822. if (ret) {
  2823. char ebuff[256];
  2824. regerror(ret, &reg, ebuff, 256);
  2825. Dbg("regex failed: %s", ebuff);
  2826. tmpResult = Error_Unexpect;
  2827. tmpMsg = CSimpleStringA::Format("内部错误:REGEX %s", ebuff);
  2828. toolkit_array_free2(subs);
  2829. break;
  2830. }
  2831. Dbg("pattern: %s", pattern.GetData());
  2832. for (int i = 0; i < subs->nelts; ++i) {
  2833. char* filenamePath = ARRAY_IDX(subs, i, char*);
  2834. char* filename = &filenamePath[strRootCfgPath.GetLength() + 1];
  2835. Dbg("filename: %s", filename);
  2836. ret = regexec(&reg, filename, 0, NULL, 0);
  2837. if (0 == ret) {
  2838. Dbg("matched!");
  2839. strRootChosenFile = filenamePath;
  2840. break;
  2841. }
  2842. Dbg("not matched.");
  2843. }
  2844. toolkit_array_free2(subs);
  2845. }
  2846. if (!strRootChosenFile.IsNullOrEmpty()) {
  2847. ///**TODO(Gifur@1/23/2022): 根据服务器返回的信息填充其他字段内容 */
  2848. fileutil_copy_file(strRootTmpFile, strRootChosenFile);
  2849. inifile_write_str(strRootTmpFile, "Terminal", "TerminalNo", terminalNo);
  2850. //inifile_write_str(strRootTmpFile, "Terminal", "Manufacturer", vendorType);
  2851. if (!strDeviceSN.IsNullOrEmpty()) {
  2852. inifile_write_str(strRootTmpFile, "Terminal", "SN", strDeviceSN);
  2853. }
  2854. }
  2855. else {
  2856. CSimpleStringA::Format("%s", pattern.GetData());
  2857. tmpMsg = "harewarecfg下匹配不到相应的配置文件,请确认选择的机型和设备厂商是否正确";
  2858. tmpResult = Error_InvalidState;
  2859. }
  2860. } while (false);
  2861. ctx->Ans.param2 = serverIP;
  2862. }
  2863. }
  2864. else if (ctx->Req.options == 1) {
  2865. //从缓存文件中获取,避免出现依赖
  2866. CSimpleStringA terminalNo;
  2867. CSimpleStringA vendorType;
  2868. CSimpleStringA serverIP;
  2869. bool fHeadOfficeMode(false);
  2870. do {
  2871. Dbg("read from cache...");
  2872. CSmartPointer<IConfigInfo> pConfig;
  2873. GetFunction()->OpenConfig(Config_Cache, pConfig);
  2874. int nTemp(0);
  2875. const ErrorCodeEnum ec0 = pConfig->ReadConfigValue("TerminalDeploy", "TerminalNo", terminalNo);
  2876. const ErrorCodeEnum ec1 = pConfig->ReadConfigValue("TerminalDeploy", "Manufacturer", vendorType);
  2877. const ErrorCodeEnum ec2 = pConfig->ReadConfigValue("TerminalDeploy", "ServerIP", serverIP);
  2878. const ErrorCodeEnum ec3 = pConfig->ReadConfigValueInt("TerminalDeploy", "HeadOfficeMode", nTemp);
  2879. fHeadOfficeMode = (nTemp > 0);
  2880. Dbg("read step: %s, %s, %s", SpStrError(ec0), SpStrError(ec1), SpStrError(ec2));
  2881. } while (false);
  2882. int checkFlag = 0;
  2883. if (terminalNo.IsNullOrEmpty()) checkFlag |= 1;
  2884. if (vendorType.IsNullOrEmpty()) checkFlag |= 2;
  2885. if (serverIP.IsNullOrEmpty()) checkFlag |= 4;
  2886. if (checkFlag != 0) {
  2887. tmpResult = Error_Null;
  2888. tmpMsg = CSimpleStringA::Format("获取终端缓存信息失败 Mask=0x%X", checkFlag);
  2889. }
  2890. else {
  2891. ctx->Ans.array1.Init(3);
  2892. ctx->Ans.array1[0] = ctx->Ans.array1[1] = ctx->Ans.array1[2] = 0;
  2893. ctx->Ans.array1[0] = fHeadOfficeMode ? 1 : 0;
  2894. ctx->Ans.array2.Init(3);
  2895. ctx->Ans.array2[0] = terminalNo;
  2896. ctx->Ans.array2[1] = vendorType;
  2897. ctx->Ans.array2[2] = serverIP;
  2898. }
  2899. }
  2900. else {
  2901. tmpResult = Error_NotSupport;
  2902. }
  2903. }
  2904. break;
  2905. case DeployStep_FetchCenterSettings:
  2906. {
  2907. const CSimpleStringA& serverIP = ctx->Req.param3;
  2908. const int nPort = ctx->Req.param1;
  2909. const bool headOfficeMode = (ctx->Req.param2 == 1);
  2910. if (serverIP.IsNullOrEmpty() || (!headOfficeMode && nPort <= 0)) {
  2911. result = Error_Param;
  2912. break;
  2913. }
  2914. ErrorCodeEnum ec(Error_Succeed);
  2915. Dbg("to connect centersetting...%s::%d", serverIP.GetData(), nPort);
  2916. auto pCenterSettingClient = new CenterSettingService_ClientBase(this);
  2917. ec = pCenterSettingClient->Connect();
  2918. if (ec != Error_Succeed) {
  2919. tmpMsg = CSimpleStringA::Format("连接集中配置模块失败: %s", SpStrError(ec));
  2920. pCenterSettingClient->SafeDelete();
  2921. Dbg("connect to centersetting failed: %s", SpStrError(ec));
  2922. }
  2923. else {
  2924. CenterSettingService_Download_Req req = {};
  2925. req.strAddr = serverIP;
  2926. req.nPort = nPort;
  2927. CenterSettingService_Download_Ans ans = {};
  2928. /**TODO(Gifur@10/14/2021): 未知行内还是行外的情况 */
  2929. Dbg("to download...");
  2930. ec = pCenterSettingClient->Download(req, ans, 60000);
  2931. if (ec != Error_Succeed) {
  2932. tmpMsg = CSimpleStringA::Format("下载集中配置文件请求失败: %s", SpStrError(ec));
  2933. Dbg("to download failed: %s", SpStrError(ec));
  2934. }
  2935. pCenterSettingClient->GetFunction()->CloseSession();
  2936. }
  2937. tmpResult = ec;
  2938. ctx->Ans.param2 = serverIP;
  2939. }
  2940. break;
  2941. case DeployStep_AccessAuthorize:
  2942. {
  2943. const CSimpleStringA& serverIP = ctx->Req.param3;
  2944. const int nPort = ctx->Req.param1;
  2945. CSimpleStringA strUsername("admin");
  2946. CSimpleStringA strPassword("88888888");
  2947. if (ctx->Req.array2.GetCount() == 2) {
  2948. strUsername = ctx->Req.array2[0];
  2949. strPassword = ctx->Req.array2[1];
  2950. }
  2951. if (serverIP.IsNullOrEmpty()) {
  2952. result = Error_Param;
  2953. break;
  2954. }
  2955. ErrorCodeEnum ec(Error_Succeed);
  2956. CSmartPointer<IConfigInfo> pConfig;
  2957. GetFunction()->OpenConfig(Config_Cache, pConfig);
  2958. Dbg("to connect initializer...%s::%d", serverIP.GetData(), nPort);
  2959. auto pClient = new AccessAuthService_ClientBase(this);
  2960. ec = pClient->Connect();
  2961. if (ec != Error_Succeed) {
  2962. tmpMsg = CSimpleStringA::Format("连接准入模块失败: %s", SpStrError(ec));
  2963. pClient->SafeDelete();
  2964. DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_USER)("connect to accessauth module failed: %s", SpStrError(ec));
  2965. tmpResult = ec;
  2966. }
  2967. else {
  2968. AccessAuthService_InitializeNew_Req req = {};
  2969. req.strAuthServer = serverIP;
  2970. req.strUserID = strUsername;
  2971. req.strPassword = strPassword;
  2972. AccessAuthService_InitializeNew_Ans ans = {};
  2973. Dbg("to initializer new...");
  2974. ec = pClient->InitializeNew(req, ans, 60000);
  2975. if (ec != Error_Succeed) {
  2976. tmpMsg = CSimpleStringA::Format("初始化请求失败: %s", SpStrError(ec));
  2977. tmpResult = ec;
  2978. DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_USER)("to initializenew failed: %s", SpStrError(ec));
  2979. }
  2980. else {
  2981. const int errUserCode = (int)(ans.Errcode);
  2982. if (errUserCode != 0) {
  2983. if (ans.ErrMsg.IsNullOrEmpty()) {
  2984. tmpMsg = CSimpleStringA::Format("%d", errUserCode);
  2985. }
  2986. else {
  2987. tmpMsg = CSimpleStringA::Format("%s", ans.ErrMsg.GetData());
  2988. }
  2989. tmpResult = errUserCode;
  2990. DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_USER)("initialize failed: %s", (LPCTSTR)tmpMsg);
  2991. }
  2992. else {
  2993. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_USER)("initialize succ.");
  2994. }
  2995. }
  2996. pClient->GetFunction()->CloseSession();
  2997. }
  2998. ctx->Ans.param2 = serverIP;
  2999. }
  3000. break;
  3001. case DeployStep_MediaConfig:
  3002. {
  3003. CSimpleStringA strRootTmpFile;
  3004. CSimpleStringA strRootIniFullPath;
  3005. CSimpleStringA strNousedPath;
  3006. tmpResult = GetTmpRootFilePath(strRootIniFullPath, strRootTmpFile, strNousedPath);
  3007. CSimpleStringA strRecordFilePath = (ctx->Req.options == 1) ? strRootIniFullPath : strRootTmpFile;
  3008. if (!ExistsFileA(strRecordFilePath)) {
  3009. Dbg("%s not exists!", strRecordFilePath.GetData());
  3010. tmpMsg = CSimpleStringA::Format("%文件不存在,请重置后重新进行配置!", strRecordFilePath.GetData());
  3011. tmpResult = Error_NotExist;
  3012. }
  3013. else {
  3014. for (int i = 0; i < ctx->Req.array1.GetCount() && tmpResult == Error_Succeed; ++i) {
  3015. CSimpleStringA key(true), value(ctx->Req.array2[i]);
  3016. const int type = ctx->Req.array1[i];
  3017. Dbg("%d: %s - %d", i, value.GetData(), type);
  3018. switch (type) {
  3019. case MediaDev_OutSpeaker:
  3020. key = "handfree_out_dev";
  3021. break;
  3022. case MediaDev_InSpeaker:
  3023. key = "pickup_out_dev";
  3024. break;
  3025. case MediaDev_OutMicrophone:
  3026. key = "handfree_in_dev";
  3027. break;
  3028. case MediaDev_InMicrophone:
  3029. key = "pickup_in_dev";
  3030. break;
  3031. default:
  3032. tmpResult = Error_Param;
  3033. break;
  3034. }
  3035. if (!key.IsNullOrEmpty()) {
  3036. tmpResult = inifile_write_str(strRecordFilePath, "Audio", key, value);
  3037. Dbg("write %s=%s into root.ini tmp file: %s", key.GetData(), value.GetData(), SpStrError((ErrorCodeEnum)tmpResult));
  3038. }
  3039. else {
  3040. Dbg("unrecognize: %d, %s", type, value.GetData());
  3041. tmpResult = Error_Unexpect;
  3042. }
  3043. }
  3044. }
  3045. }
  3046. break;
  3047. case DeployStep_AdapterConfig:
  3048. {
  3049. if ((ctx->Req.options & 0x2) || (ctx->Req.options & 0x1)) {
  3050. CSimpleStringA& strAdapterFileName = ctx->Req.param3;
  3051. CAutoArray<CSimpleStringA> adapterInfo;
  3052. tmpResult = SplitAdapterFileName(strAdapterFileName, adapterInfo);
  3053. Dbg("%s, %s", strAdapterFileName.GetData(), SpStrError((ErrorCodeEnum)tmpResult));
  3054. if (tmpResult == 0) {
  3055. CSimpleStringA strDevice(adapterInfo[0]);
  3056. CSimpleStringA strDeviceSection("Device.");
  3057. strDeviceSection += strDevice;
  3058. CSimpleStringA strVendor(adapterInfo[1]);
  3059. CSimpleStringA strVersion(adapterInfo[2]);
  3060. CSimpleStringA strBatch(adapterInfo[3]);
  3061. const int port = ctx->Req.param1;
  3062. const int baudrate = ctx->Req.param2;
  3063. if ((ctx->Req.options & 0x1)) { //更新到缓存
  3064. CSimpleStringA strRootTmpFile;
  3065. CSimpleStringA strRootIniFullPath;
  3066. CSimpleStringA strNousedPath;
  3067. tmpResult = GetTmpRootFilePath(strRootIniFullPath, strRootTmpFile, strNousedPath);
  3068. if (!ExistsFileA(strRootTmpFile)) {
  3069. Dbg("%s not exists!", strRootTmpFile.GetData());
  3070. tmpMsg = "临时配置文件不存在,请重置后重新进行配置!";
  3071. tmpResult = Error_NotExist;
  3072. }
  3073. else {
  3074. tmpResult = inifile_write_str(strRootTmpFile, strDeviceSection, "Vendor", strVendor);
  3075. tmpResult = inifile_write_str(strRootTmpFile, strDeviceSection, "Version", strVersion);
  3076. tmpResult = inifile_write_str(strRootTmpFile, strDeviceSection, "Batch", strBatch);
  3077. tmpResult = inifile_write_int(strRootTmpFile, strDeviceSection, "Port", port);
  3078. tmpResult = inifile_write_int(strRootTmpFile, strDeviceSection, "Baudrate", baudrate);
  3079. }
  3080. }
  3081. else { //更新到root.ini
  3082. CSmartPointer<IConfigInfo> pRootConfig;
  3083. GetFunction()->OpenConfig(Config_Root, pRootConfig);
  3084. tmpResult = pRootConfig->WriteConfigValue(strDeviceSection, "Vendor", strVendor);
  3085. Dbg("%s,%s,%s,%s,%s", strDeviceSection.GetData(), strVendor.GetData(), strVersion.GetData(), strBatch.GetData(), SpStrError((ErrorCodeEnum)tmpResult));
  3086. if (tmpResult == 0) {
  3087. pRootConfig->WriteConfigValue(strDeviceSection, "Version", strVersion);
  3088. pRootConfig->WriteConfigValue(strDeviceSection, "Batch", strBatch);
  3089. pRootConfig->WriteConfigValueInt(strDeviceSection, "Port", port);
  3090. pRootConfig->WriteConfigValueInt(strDeviceSection, "Baudrate", baudrate);
  3091. }
  3092. else {
  3093. tmpMsg = CSimpleStringA::Format("写入ROOT配置文件失败:%s", SpStrError((ErrorCodeEnum)tmpResult));
  3094. }
  3095. }
  3096. }
  3097. else {
  3098. tmpMsg = CSimpleStringA::Format("适配器文件名称不符合规范:%s", strAdapterFileName.GetData());
  3099. }
  3100. }
  3101. else if ((ctx->Req.options & 0x4)) { //启动实体
  3102. CSimpleStringA& strEntityName = ctx->Req.param3;
  3103. tmpResult = DealSpecifiedEntity((DealType)ctx->Req.param1, strEntityName, ctx->Req.param4, (ctx->Req.param2 != 0), tmpMsg);
  3104. }
  3105. }
  3106. break;
  3107. case DeployStep_3rdParty_SogouInstall:
  3108. {
  3109. if ((ctx->Req.options == 1)) { //检测输入法的安装状态
  3110. auto pClient = new ResourceWatcherService_ClientBase(this);
  3111. tmpResult = pClient->Connect();
  3112. if (tmpResult != 0) {
  3113. tmpMsg = CSimpleStringA::Format("连接资源管理模块失败: %s", SpStrError((ErrorCodeEnum)tmpResult));
  3114. pClient->SafeDelete();
  3115. Dbg(tmpMsg);
  3116. }
  3117. else {
  3118. ResourceWatcherService_GetThirdPartyInstallState_Req req = {};
  3119. ResourceWatcherService_GetThirdPartyInstallState_Ans ans = {};
  3120. req.mode = 1;
  3121. Dbg("to invoke...");
  3122. tmpResult = pClient->GetThirdPartyInstallState(req, ans, 30000);
  3123. if (tmpResult != 0) {
  3124. tmpMsg = CSimpleStringA::Format("获取安装状态请求失败: %s", SpStrError((ErrorCodeEnum)tmpResult));
  3125. Dbg(tmpMsg);
  3126. }
  3127. else {
  3128. ctx->Ans.param1 = 0;
  3129. if (ans.status == 1) {
  3130. ctx->Ans.param1 = 1;
  3131. ctx->Ans.array1.Init(3);
  3132. ctx->Ans.array2.Init(3);
  3133. ctx->Ans.array2[0] = ans.version;
  3134. ctx->Ans.array2[1] = ans.path;
  3135. ctx->Ans.array2[2] = ans.reserverd1; //安装时间
  3136. ctx->Ans.array1[0] = ctx->Ans.array1[1] = ctx->Ans.array1[2] = 0;
  3137. /** 传递是否已经是新版输入法 [Gifur@2023822]*/
  3138. ctx->Ans.array1[0] = ans.reserverd3;
  3139. }
  3140. }
  3141. pClient->GetFunction()->CloseSession();
  3142. }
  3143. }
  3144. else if (ctx->Req.options == 2) { //安装搜狗输入法
  3145. auto pClient = new ResourceWatcherService_ClientBase(this);
  3146. tmpResult = pClient->Connect();
  3147. if (tmpResult != 0) {
  3148. tmpMsg = CSimpleStringA::Format("连接资源管理模块失败: %s", SpStrError((ErrorCodeEnum)tmpResult));
  3149. pClient->SafeDelete();
  3150. DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)(tmpMsg);
  3151. }
  3152. else {
  3153. ResourceWatcherService_InstallThirdPartyProgram_Req req = {};
  3154. ResourceWatcherService_InstallThirdPartyProgram_Ans ans = {};
  3155. req.type = 1;
  3156. req.reserved1 = req.reserved2 = 0;
  3157. /** 健康实体过来的调用,1表示不直接重启机器 [Gifur@202275]*/
  3158. req.reserved1 = 1;
  3159. DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("to install...");
  3160. tmpResult = pClient->InstallThirdPartyProgram(req, ans, 120000);
  3161. if (tmpResult != 0) {
  3162. tmpMsg = CSimpleStringA::Format("调用安装请求返回错误:%s", SpStrError((ErrorCodeEnum)tmpResult));
  3163. Dbg(tmpMsg);
  3164. } else {
  3165. tmpResult = ans.result;
  3166. tmpMsg = ans.msg;
  3167. if (tmpResult == 0) {
  3168. ctx->Ans.array1.Init(3);
  3169. ctx->Ans.array2.Init(3);
  3170. ctx->Ans.array2[0] = ans.reserverd1; //版本号
  3171. ctx->Ans.array2[1] = ans.path;
  3172. ctx->Ans.array2[2] = ans.reserverd2; //安装时间
  3173. ctx->Ans.array1[0] = ctx->Ans.array1[1] = ctx->Ans.array1[2] = 0;
  3174. if(!ans.reserverd1.IsNullOrEmpty())
  3175. { /** 缺少字段,只能再查一次输入法状态,以获取新旧版输入法信息 [Gifur@2023825]*/
  3176. ResourceWatcherService_GetThirdPartyInstallState_Req req1 = {};
  3177. ResourceWatcherService_GetThirdPartyInstallState_Ans ans1 = {};
  3178. req1.mode = 1;
  3179. ErrorCodeEnum tmp1 = pClient->GetThirdPartyInstallState(req1, ans1, 30000);
  3180. if (tmp1 == Error_Succeed && ans1.status == 1) {
  3181. ctx->Ans.array1[0] = ans1.reserverd3;
  3182. }
  3183. }
  3184. }
  3185. }
  3186. pClient->GetFunction()->CloseSession();
  3187. }
  3188. }
  3189. else {
  3190. result = Error_NotSupport;
  3191. }
  3192. }
  3193. break;
  3194. case DeployStep_3rdParty_FontInstall:
  3195. {
  3196. if ((ctx->Req.options == 1)) { //检测字体的安装状态
  3197. auto pClient = new ResourceWatcherService_ClientBase(this);
  3198. tmpResult = pClient->Connect();
  3199. if (tmpResult != 0) {
  3200. tmpMsg = CSimpleStringA::Format("连接资源管理模块失败: %s", SpStrError((ErrorCodeEnum)tmpResult));
  3201. pClient->SafeDelete();
  3202. DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)(tmpMsg);
  3203. }
  3204. else {
  3205. ResourceWatcherService_GetThirdPartyInstallState_Req req = {};
  3206. ResourceWatcherService_GetThirdPartyInstallState_Ans ans = {};
  3207. req.mode = 2;
  3208. Dbg("to invoke...");
  3209. tmpResult = pClient->GetThirdPartyInstallState(req, ans, 30000);
  3210. if (tmpResult != 0) {
  3211. tmpMsg = CSimpleStringA::Format("获取安装状态请求失败: %s", SpStrError((ErrorCodeEnum)tmpResult));
  3212. DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)(tmpMsg);
  3213. }
  3214. else {
  3215. ctx->Ans.param1 = 0;
  3216. if (ans.status == 1) {
  3217. ctx->Ans.param1 = 1;
  3218. ctx->Ans.array1.Init(3);
  3219. ctx->Ans.array2.Init(3);
  3220. ctx->Ans.array2[0] = ans.version;
  3221. ctx->Ans.array2[1] = ans.path;
  3222. ctx->Ans.array2[2] = ans.reserverd1; //安装时间
  3223. }
  3224. }
  3225. pClient->GetFunction()->CloseSession();
  3226. }
  3227. }
  3228. else if ((ctx->Req.options == 2)) { //字体的安装
  3229. auto pClient = new ResourceWatcherService_ClientBase(this);
  3230. tmpResult = pClient->Connect();
  3231. if (tmpResult != 0) {
  3232. tmpMsg = CSimpleStringA::Format("连接资源管理模块失败: %s", SpStrError((ErrorCodeEnum)tmpResult));
  3233. pClient->SafeDelete();
  3234. DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)(tmpMsg);
  3235. }
  3236. else {
  3237. ResourceWatcherService_InstallThirdPartyProgram_Req req = {};
  3238. ResourceWatcherService_InstallThirdPartyProgram_Ans ans = {};
  3239. req.type = 2; //
  3240. req.reserved1 = req.reserved2 = 0;
  3241. DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("to install font....");
  3242. tmpResult = pClient->InstallThirdPartyProgram(req, ans, 60000);
  3243. if (tmpResult != 0) {
  3244. tmpMsg = CSimpleStringA::Format("调用安装请求返回错误:%s", SpStrError((ErrorCodeEnum)tmpResult));
  3245. Dbg(tmpMsg);
  3246. }
  3247. else {
  3248. tmpResult = ans.result;
  3249. tmpMsg = ans.msg;
  3250. }
  3251. pClient->GetFunction()->CloseSession();
  3252. }
  3253. }
  3254. else {
  3255. result = Error_NotSupport;
  3256. }
  3257. }
  3258. break;
  3259. case DeployStep_Finished:
  3260. {
  3261. CSimpleStringA strRootTmpFile;
  3262. CSimpleStringA strRootIniFullPath;
  3263. CSimpleStringA strRootChosenFile(true);
  3264. CSimpleStringA strNousedPath;
  3265. GetTmpRootFilePath(strRootIniFullPath, strRootTmpFile, strNousedPath);
  3266. strRootChosenFile = strRootIniFullPath + ".bak";
  3267. if (ExistsFileA(strRootChosenFile)) {
  3268. fileutil_delete_file(strRootChosenFile);
  3269. DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("to clear root.ini backup file.");
  3270. }
  3271. CSystemStaticInfo info;
  3272. GetFunction()->GetSystemStaticInfo(info);
  3273. CSmartPointer<IConfigInfo> pConfig;
  3274. GetFunction()->OpenConfig(Config_Cache, pConfig);
  3275. pConfig->WriteConfigValue("TerminalDeploy", "InstallVersion", info.InstallVersion.ToString());
  3276. DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("received finish install cmd!");
  3277. LogWarn(Severity_High, Error_Debug, LOG_WARN_HEALTH_INSTALL_FINISHED, "install finished");
  3278. result = Error_Succeed;
  3279. }
  3280. break;
  3281. default:
  3282. result = Error_MisMatched;
  3283. break;
  3284. }
  3285. //////////////////////////////////////////////////////////////////////////
  3286. bool restartApp(false), restartPC(false);
  3287. if (result == Error_Succeed) {
  3288. CSmartPointer<IConfigInfo> pConfig;
  3289. GetFunction()->OpenConfig(Config_Cache, pConfig);
  3290. if (tmpResult == 0) {
  3291. if ((ctx->Req.additional & 0x1)) //重命名 root.ini
  3292. {
  3293. CSimpleStringA strRootTmpFile;
  3294. CSimpleStringA strRootIniFullPath;
  3295. CSimpleStringA strNousedPath;
  3296. tmpResult = GetTmpRootFilePath(strRootIniFullPath, strRootTmpFile, strNousedPath);
  3297. if (!ExistsFileA(strRootTmpFile)) {
  3298. tmpMsg = "临时配置文件不存在,无法加载配置文件,请重置后重新进行配置";
  3299. tmpResult = Error_NotExist;
  3300. }
  3301. else {
  3302. Dbg("rename tmp file to root.ini..");
  3303. fileutil_copy_file(strRootIniFullPath, strRootTmpFile);
  3304. fileutil_delete_file(strRootTmpFile);
  3305. if (!ExistsFileA(strRootIniFullPath)) {
  3306. tmpResult = Error_IO;
  3307. }
  3308. else {
  3309. Dbg("root.ini has been renamed!");
  3310. }
  3311. }
  3312. }
  3313. pConfig->WriteConfigValueInt("TerminalDeploy", "CurrStep", ctx->Req.nextStep);
  3314. pConfig->WriteConfigValueInt("TerminalDeploy", "CurrState", DEPLOYSTATE_NOTINIT);
  3315. pConfig->WriteConfigValue("TerminalDeploy", "TimeStamp", CSimpleStringA::Format("0x%08X", (DWORD)CSmallDateTime::GetNow()));
  3316. restartApp = ctx->Req.restartApp;
  3317. restartPC = ctx->Req.restartPC;
  3318. }
  3319. else {
  3320. pConfig->WriteConfigValueInt("TerminalDeploy", "CurrStep", ctx->Req.currStep);
  3321. pConfig->WriteConfigValueInt("TerminalDeploy", "CurrState", DEPLOYSTATE_FAILED);
  3322. pConfig->WriteConfigValue("TerminalDeploy", "TimeStamp", CSimpleStringA::Format("0x%08X", (DWORD)CSmallDateTime::GetNow()));
  3323. }
  3324. }
  3325. if (restartPC || restartApp) {
  3326. /** 无奈,有时处理太快,导致界面上看不到提示,所以只能选择战略性延迟,剩下的靠前端自己了 [Gifur@20211022]*/
  3327. Dbg("sleep suitable second for providing time for fontside to tell user to wait while restarting pc or app");
  3328. Sleep(3000);
  3329. }
  3330. if (restartPC) {
  3331. tmpResult = m_fsm.QuitFrameworkAndSaveInfo(RebootTrigger_ManualLocal, RebootWay_OS);
  3332. if (tmpResult != 0) {
  3333. tmpMsg = CSimpleStringA::Format("重启设备失败(%s),请手动重启", SpStrError((ErrorCodeEnum)tmpResult));
  3334. Dbg(tmpMsg);
  3335. }
  3336. }
  3337. else if (restartApp) {
  3338. tmpResult = m_fsm.QuitFrameworkAndSaveInfo(RebootTrigger_ManualLocal, RebootWay_Framework);
  3339. if (tmpResult != 0) {
  3340. tmpMsg = CSimpleStringA::Format("重启应用失败(%s),请手动重启", SpStrError((ErrorCodeEnum)tmpResult));
  3341. Dbg(tmpMsg);
  3342. }
  3343. }
  3344. ctx->Ans.result = tmpResult;
  3345. ctx->Ans.additionalMsg = tmpMsg;
  3346. ctx->Ans.nextStep = ctx->Req.nextStep;
  3347. ctx->Answer(result);
  3348. #endif
  3349. }
  3350. bool CHealthManagerEntity::IsTestMode()
  3351. {
  3352. static int flag = -1;
  3353. if (flag == -1) {
  3354. CSystemRunInfo runInfo;
  3355. bool result = (GetFunction()->GetSystemRunInfo(runInfo) == Error_Succeed
  3356. && !!(runInfo.dwBootOption & SystemBootOptionEnum::BootOption_Test));
  3357. flag = result ? 1 : 0;
  3358. }
  3359. return !!flag;
  3360. }
  3361. bool CHealthManagerEntity::IsNotConfigMode(int& stepMode)
  3362. {
  3363. stepMode = 0;
  3364. int lastRecordTime = 0;
  3365. CSystemRunInfo runInfo;
  3366. ErrorCodeEnum ec = GetFunction()->GetSystemRunInfo(runInfo);
  3367. if (ec != Error_Succeed) {
  3368. stepMode = ec;
  3369. Dbg("get framework info failed: %s", SpStrError(ec));
  3370. return false;
  3371. }
  3372. if (runInfo.eState == FrameworkState_NotConfig) {
  3373. Dbg("not config from framework");
  3374. stepMode = -1;
  3375. return true;
  3376. }
  3377. else {
  3378. CSmartPointer<IConfigInfo> pConfig;
  3379. GetFunction()->OpenConfig(Config_Cache, pConfig);
  3380. int stepStatus(0);
  3381. pConfig->ReadConfigValueInt("TerminalDeploy", "CurrStep", stepMode);
  3382. pConfig->ReadConfigValueInt("TerminalDeploy", "CurrState", stepStatus);
  3383. pConfig->ReadConfigValueInt("TerminalDeploy", "TimeStamp", lastRecordTime);
  3384. if (stepMode != 0 && DeployStep_Finished != stepMode) {
  3385. Dbg("not config from cache: step=%d, status=%d", stepMode, stepStatus);
  3386. return true;
  3387. }
  3388. }
  3389. return false;
  3390. }
  3391. SP_BEGIN_ENTITY_MAP()
  3392. SP_ENTITY(CHealthManagerEntity)
  3393. SP_END_ENTITY_MAP()