|
@@ -3,6 +3,8 @@
|
|
|
#include "GetDevInfoHelper.h"
|
|
|
#include "EventCode.h"
|
|
|
#include "fileutil.h"
|
|
|
+#include "toolkit.h"
|
|
|
+#include "CommEntityUtil.hpp"
|
|
|
|
|
|
#if defined(RVC_OS_WIN)
|
|
|
static const char DEFAULT_ADAPTER_LIBRARY_NAME[] = "DeviceControl.cmbsz.1.1.dll";
|
|
@@ -123,6 +125,7 @@ ErrorCodeEnum CDeviceControlFSM::OnInit()
|
|
|
}
|
|
|
|
|
|
DoBrowserCacheClearJob();
|
|
|
+ DoRestartSogouServicesJob();
|
|
|
|
|
|
return Error_Succeed;
|
|
|
}
|
|
@@ -189,6 +192,104 @@ void CDeviceControlFSM::DoBrowserCacheClearJob()
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+void CDeviceControlFSM::DoRestartSogouServicesJob()
|
|
|
+{
|
|
|
+ LOG_FUNCTION();
|
|
|
+
|
|
|
+ CSmartPointer<IConfigInfo> spConfig;
|
|
|
+ ErrorCodeEnum err = GetEntityBase()->GetFunction()->OpenConfig(Config_Run, spConfig);
|
|
|
+ CSimpleStringA str(true);
|
|
|
+ err = spConfig->ReadConfigValue("Browser", "SogouRestart", str);
|
|
|
+ if (str.Compare("true", true) == 0) {
|
|
|
+ spConfig->WriteConfigValue("Browser", "SogouRestart", NULL);
|
|
|
+ RestartSogouServices();
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+ErrorCodeEnum CDeviceControlFSM::RestartSogouServices()
|
|
|
+{
|
|
|
+ LOG_FUNCTION();
|
|
|
+
|
|
|
+ ErrorCodeEnum result(Error_Succeed);
|
|
|
+
|
|
|
+ CSimpleStringA shellScriptPath;
|
|
|
+ GetEntityBase()->GetFunction()->GetPath("Base", shellScriptPath);
|
|
|
+ shellScriptPath += SPLIT_SLASH_STR;
|
|
|
+ shellScriptPath += "res" SPLIT_SLASH_STR "RunScript" SPLIT_SLASH_STR;
|
|
|
+
|
|
|
+ std::string startup_service(shellScriptPath.GetData());
|
|
|
+ startup_service += "startup_sogouservice.sh";
|
|
|
+ std::string shutdown_service(shellScriptPath.GetData());
|
|
|
+ shutdown_service += "shutdown_sogouservice.sh";
|
|
|
+
|
|
|
+ const BOOL s1 = ExistsFileA(startup_service.c_str());
|
|
|
+ const BOOL s2 = ExistsFileA(shutdown_service.c_str());
|
|
|
+
|
|
|
+ if (s1 && s2) {
|
|
|
+
|
|
|
+ do {
|
|
|
+ std::string succStr, errStr;
|
|
|
+ std::string runStr("bash ");
|
|
|
+ runStr += shutdown_service;
|
|
|
+ if (!SP::Module::Util::ShelllExecute(runStr, succStr, errStr)) {
|
|
|
+ LogWarn(Severity_Middle, Error_Unexpect, LOG_DEVICECONTROL_SOGOU_SCRIPTS_EXECUTE_FAILED,
|
|
|
+ CSimpleStringA::Format("%s: %s, %s", shutdown_service.c_str(), succStr.c_str(), errStr.c_str()));
|
|
|
+ return Error_Unexpect;
|
|
|
+ } else {
|
|
|
+ Dbg("execute {%s} suc: %s", shutdown_service.c_str(), succStr.c_str());
|
|
|
+ }
|
|
|
+ } while (false);
|
|
|
+
|
|
|
+ Sleep(3000);
|
|
|
+
|
|
|
+ do {
|
|
|
+ char app[MAX_PATH] = { '\0' };
|
|
|
+ tk_process_t* process = NULL;
|
|
|
+ tk_process_option_t option;
|
|
|
+ option.exit_cb = NULL;
|
|
|
+ option.file = NULL;
|
|
|
+ option.flags = 0;
|
|
|
+
|
|
|
+ sprintf(app, "bash %s", startup_service.c_str());
|
|
|
+ option.params = app;
|
|
|
+
|
|
|
+ const int res = process_spawn(&option, &process);
|
|
|
+ if (0 == res) {
|
|
|
+ FREE(process);
|
|
|
+ Dbg("execute {%s} suc", startup_service.c_str());
|
|
|
+ } else {
|
|
|
+ LogWarn(Severity_Middle, Error_Unexpect, LOG_DEVICECONTROL_SOGOU_SCRIPTS_EXECUTE_FAILED,
|
|
|
+ CSimpleStringA::Format("%s: %d", startup_service.c_str(), res));
|
|
|
+ return Error_Unexpect;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ // std::string succStr, errStr;
|
|
|
+ // std::string runStr("bash ");
|
|
|
+ // runStr += startup_service;
|
|
|
+
|
|
|
+ // if (!SP::Module::Util::ShelllExecute(runStr, succStr, errStr)) {
|
|
|
+ // LogWarn(Severity_Middle, Error_Unexpect, LOG_DEVICECONTROL_SOGOU_SCRIPTS_EXECUTE_FAILED,
|
|
|
+ // CSimpleStringA::Format("%s: %s, %s", startup_service.c_str(), succStr.c_str(), errStr.c_str()));
|
|
|
+ // return Error_Unexpect;
|
|
|
+ //} else {
|
|
|
+ // Dbg("execute {%s} suc: %s", startup_service.c_str(), succStr.c_str());
|
|
|
+ //}
|
|
|
+
|
|
|
+ } while (false);
|
|
|
+
|
|
|
+ LogWarn(Severity_Middle, Error_Unexpect, LOG_DEVICECONTROL_SOGOU_SCRIPTS_EXECUTE_SUCC, "sogou restart succ.");
|
|
|
+
|
|
|
+ } else {
|
|
|
+
|
|
|
+ LogWarn(Severity_Middle, Error_NotExist, LOG_DEVICECONTROL_SOGOU_SCRIPTS_NOT_EXISTS,
|
|
|
+ CSimpleStringA::Format("%s=%d, %s=%d", startup_service.c_str(), s1, shutdown_service.c_str(), s2));
|
|
|
+ result = Error_NotExist;
|
|
|
+ }
|
|
|
+
|
|
|
+ return result;
|
|
|
+}
|
|
|
+
|
|
|
ErrorCodeEnum CDeviceControlFSM::OnExit()
|
|
|
{
|
|
|
return Error_Succeed;
|