|
@@ -182,6 +182,18 @@ void ResourceWatcherServiceSession::Handle_UninstallThirdPartyProgram(SpReqAnsCo
|
|
|
m_pEntity->UninstallThirdPartyProgram(ctx);
|
|
|
}
|
|
|
|
|
|
+void ResourceWatcherServiceSession::Handle_RestartThirdPartyProgram(SpReqAnsContext<ResourceWatcherService_RestartThirdPartyProgram_Req, ResourceWatcherService_RestartThirdPartyProgram_Ans>::Pointer ctx)
|
|
|
+{
|
|
|
+ LOG_FUNCTION();
|
|
|
+ m_pEntity->RestartThirdPartyProgram(ctx);
|
|
|
+}
|
|
|
+
|
|
|
+void ResourceWatcherServiceSession::Handle_ProcessDetectThirdPartyProgram(SpReqAnsContext<ResourceWatcherService_ProcessDetectThirdPartyProgram_Req, ResourceWatcherService_ProcessDetectThirdPartyProgram_Ans>::Pointer ctx)
|
|
|
+{
|
|
|
+ LOG_FUNCTION();
|
|
|
+ m_pEntity->ProcessDetectThirdPartyProgram(ctx);
|
|
|
+}
|
|
|
+
|
|
|
void ResourceWatcherEntity::UpdateDNS(SpReqAnsContext<ResourceWatcherService_UpdateDNS_Req, ResourceWatcherService_UpdateDNS_Ans>::Pointer ctx)
|
|
|
{
|
|
|
ctx->Answer(Error_NotImpl);
|
|
@@ -837,6 +849,83 @@ void ResourceWatcherEntity::UninstallThirdPartyProgram(SpReqAnsContext<ResourceW
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
+void ResourceWatcherEntity::RestartThirdPartyProgram(SpReqAnsContext<ResourceWatcherService_RestartThirdPartyProgram_Req, ResourceWatcherService_RestartThirdPartyProgram_Ans>::Pointer ctx)
|
|
|
+{
|
|
|
+ ErrorCodeEnum result(Error_Succeed);
|
|
|
+ ErrorCodeEnum tmpResult(Error_Succeed);
|
|
|
+
|
|
|
+ int restartRe = false;
|
|
|
+ CSimpleStringA tmpMsg(true);
|
|
|
+ std::string res("");
|
|
|
+
|
|
|
+ if (ctx->Req.type == 1) {//重启搜狗输入法
|
|
|
+ //CSimpleStringA csBinPath;
|
|
|
+ //ErrorCodeEnum eErrPath = GetFunction()->GetPath("Bin", csBinPath);
|
|
|
+ //if (eErrPath != Error_Succeed)
|
|
|
+ //{
|
|
|
+ // //Dbg("GetBasePath failed (%d).", eErrPath));
|
|
|
+ // tmpMsg = "GetBasePath failed.";
|
|
|
+ //}
|
|
|
+ //else
|
|
|
+ //{
|
|
|
+ // CSimpleStringA startPath = CSimpleStringA::Format("%s\\spScript\\SogouServStarter.bat", csBinPath.GetData());
|
|
|
+ // int startFlag = WinExec(startPath.GetData(), SW_SHOWNORMAL);
|
|
|
+ // if (startFlag > 31)
|
|
|
+ // {
|
|
|
+ // tmpMsg = CSimpleStringA::Format("已执行搜狗启动脚本!路径:%s。", startPath.GetData());
|
|
|
+ // restartRe = 1;
|
|
|
+ // }
|
|
|
+ // else
|
|
|
+ // {
|
|
|
+ // tmpMsg = CSimpleStringA::Format("执行启动脚本异常!路径:%s。", startPath.GetData());
|
|
|
+ // restartRe = 0;
|
|
|
+ // }
|
|
|
+ //}
|
|
|
+ }
|
|
|
+
|
|
|
+ ctx->Ans.result = restartRe;
|
|
|
+ ctx->Ans.msg = tmpMsg;
|
|
|
+
|
|
|
+ ctx->Answer(result);
|
|
|
+ return;
|
|
|
+}
|
|
|
+
|
|
|
+void ResourceWatcherEntity::ProcessDetectThirdPartyProgram(SpReqAnsContext<ResourceWatcherService_ProcessDetectThirdPartyProgram_Req, ResourceWatcherService_ProcessDetectThirdPartyProgram_Ans>::Pointer ctx)
|
|
|
+{
|
|
|
+ ErrorCodeEnum result(Error_Succeed);
|
|
|
+ ErrorCodeEnum tmpResult(Error_Succeed);
|
|
|
+
|
|
|
+ int procDetectRe = false;
|
|
|
+ CSimpleStringA tmpMsg(true);
|
|
|
+ std::string res("");
|
|
|
+
|
|
|
+ if (ctx->Req.type == 1) {//检测搜狗输入法进程
|
|
|
+ CAutoArray<CSimpleStringA> pName(2);
|
|
|
+ pName[0] = "SogouImeMon.exe";
|
|
|
+ pName[1] = "SogouImeWebSrv.exe";
|
|
|
+ res = DoCheckCertainProcessStatus(pName);
|
|
|
+
|
|
|
+ if (res.length() == 0)
|
|
|
+ {
|
|
|
+ procDetectRe = false;
|
|
|
+ tmpMsg = "Can't find Sogou Process.";
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ procDetectRe = true;
|
|
|
+ tmpMsg = CSimpleStringA::Format("%s", res.c_str());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ ctx->Ans.result = procDetectRe;
|
|
|
+ ctx->Ans.msg = tmpMsg;
|
|
|
+ result = tmpResult;
|
|
|
+
|
|
|
+ ctx->Answer(result);
|
|
|
+ return;
|
|
|
+}
|
|
|
+
|
|
|
#if defined(RVC_OS_WIN)
|
|
|
//1: 32bit process running at 64bit platform
|
|
|
//0:
|
|
@@ -1286,6 +1375,78 @@ void ResourceWatcherEntity::OnSysVarEvent(const char* pszKey, const char* pszVal
|
|
|
|
|
|
}
|
|
|
|
|
|
+std::string ResourceWatcherEntity::DoCheckCertainProcessStatus(const CAutoArray<CSimpleStringA>& pName)
|
|
|
+{
|
|
|
+ int pSize = pName.GetCount();
|
|
|
+ /*static int old_process_id[pSize];
|
|
|
+ memset(old_process_id, -1, sizeof(old_process_id));*/
|
|
|
+ vector<int> old_process_id;
|
|
|
+ CAutoArray<CSimpleStringA> msgs;
|
|
|
+ alive_process_info* processes = new alive_process_info[pSize];
|
|
|
+ char** relate_processes = new char* [pSize];
|
|
|
+ int count = pSize;
|
|
|
+
|
|
|
+ for (int i = 0; i < pSize; ++i)
|
|
|
+ {
|
|
|
+ old_process_id.push_back(-1);
|
|
|
+
|
|
|
+ CSimpleStringA temp("");
|
|
|
+ msgs.Append(&temp, 0, 1);
|
|
|
+ relate_processes[i] = const_cast<char*>(pName[i].GetData());
|
|
|
+ Dbg("relate_process name: %s.", relate_processes[i]);
|
|
|
+ }
|
|
|
+ Dbg("COUNT = %d!", count);
|
|
|
+ osutil_detect_unique_app(relate_processes, pSize, &count, processes);
|
|
|
+
|
|
|
+ int cnt(0);
|
|
|
+ for (int i = 0; i < pSize; ++i) {
|
|
|
+ int k = -1;
|
|
|
+ for (int j = 0; j < count; ++j) {
|
|
|
+ if (strcmp(processes[j].name, relate_processes[i]) == 0) {
|
|
|
+ k = j;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (k != -1 && old_process_id[i] == -1) {
|
|
|
+ msgs[cnt++] = CSimpleStringA::Format("{\"name\":\"%s\", \"pid\":%d}"
|
|
|
+ , relate_processes[i], processes[k].pid);
|
|
|
+ old_process_id[i] = processes[k].pid;
|
|
|
+
|
|
|
+ }
|
|
|
+ else if (k != -1 && (processes[k].pid != old_process_id[i])) {
|
|
|
+ msgs[cnt++] = CSimpleStringA::Format("{\"name\":\"%s\", \"prev\":%d, \"pid\":%d}"
|
|
|
+ , relate_processes[i], old_process_id[i], processes[k].pid);
|
|
|
+ old_process_id[i] = processes[k].pid;
|
|
|
+
|
|
|
+ }
|
|
|
+ else if (k == -1 && old_process_id[i] != 0) {
|
|
|
+ msgs[cnt++] = CSimpleStringA::Format("{\"name\":\"%s\", \"prev\":%d, \"pid\":%d}"
|
|
|
+ , relate_processes[i], old_process_id[i], 0);
|
|
|
+ old_process_id[i] = 0;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ std::string uploadInfo("");
|
|
|
+ if (cnt > 0) {
|
|
|
+ if (cnt > 1) {
|
|
|
+ uploadInfo = "{";
|
|
|
+ }
|
|
|
+ for (int i = 0; i < cnt; ++i) {
|
|
|
+ if (i != 0) {
|
|
|
+ uploadInfo += ",";
|
|
|
+ }
|
|
|
+ uploadInfo += msgs[i].GetData();
|
|
|
+ }
|
|
|
+ if (cnt > 1) {
|
|
|
+ uploadInfo += "}";
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return uploadInfo;
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
SP_BEGIN_ENTITY_MAP()
|
|
|
SP_ENTITY(ResourceWatcherEntity)
|
|
|
SP_END_ENTITY_MAP()
|