|
@@ -13,6 +13,17 @@
|
|
|
#include "fileutil.h"
|
|
|
#include "iniutil.h"
|
|
|
|
|
|
+#include "CenterSetting_client_g.h"
|
|
|
+using namespace CenterSetting;
|
|
|
+
|
|
|
+#include "Initializer_client_g.h"
|
|
|
+using namespace Initializer;
|
|
|
+
|
|
|
+#define DEPLOYSTATE_NOTINIT 0
|
|
|
+#define DEPLOYSTATE_DONE 1
|
|
|
+#define DEPLOYSTATE_FAILED 2
|
|
|
+
|
|
|
+
|
|
|
void CDeviceControlServerSession::Handle_USB(SpReqAnsContext<DeviceControlService_USB_Req, DeviceControlService_USB_Ans>::Pointer ctx)
|
|
|
{
|
|
|
LOG_FUNCTION();
|
|
@@ -164,7 +175,14 @@ void CDeviceControlEntity::TestConnectivity(SpReqAnsContext<DeviceControlService
|
|
|
|
|
|
void CDeviceControlEntity::DeployTerminal(SpReqAnsContext<DeviceControlService_DeployTerminal_Req, DeviceControlService_DeployTerminal_Ans>::Pointer ctx)
|
|
|
{
|
|
|
- ErrorCodeEnum result(Error_Unexpect);
|
|
|
+
|
|
|
+ LOG_FUNCTION();
|
|
|
+
|
|
|
+ ErrorCodeEnum result(Error_Succeed);
|
|
|
+ int tmpResult = 0;
|
|
|
+ CSimpleStringA tmpMsg(true);
|
|
|
+
|
|
|
+ Dbg("%d", ctx->Req.currStep);
|
|
|
|
|
|
switch (ctx->Req.currStep) {
|
|
|
case DeployStep_Begin:
|
|
@@ -194,9 +212,6 @@ void CDeviceControlEntity::DeployTerminal(SpReqAnsContext<DeviceControlService_D
|
|
|
result = Error_MisMatched;
|
|
|
} else {
|
|
|
ctx->Ans.nextStep = DeployStep_FetchCenterSettings;
|
|
|
- int tmpResult = 0;
|
|
|
- CSimpleStringA tmpMsg(true);
|
|
|
-
|
|
|
|
|
|
ErrorCodeEnum ec(Error_Succeed);
|
|
|
CSmartPointer<IConfigInfo> pConfig;
|
|
@@ -209,7 +224,7 @@ void CDeviceControlEntity::DeployTerminal(SpReqAnsContext<DeviceControlService_D
|
|
|
const ErrorCodeEnum ec2 = pConfig->WriteConfigValue("TerminalDeploy", "ServerIP", serverIP);
|
|
|
const ErrorCodeEnum ec3 = pConfig->WriteConfigValueInt("TerminalDeploy", "CurrStep", ctx->Req.currStep);
|
|
|
if (!ec0 && !ec1 && !ec2 && !ec3) {
|
|
|
- ec = pConfig->WriteConfigValueInt("TerminalDeploy", "CurrState", 1);
|
|
|
+ ec = pConfig->WriteConfigValueInt("TerminalDeploy", "CurrState", DEPLOYSTATE_DONE);
|
|
|
Dbg("record step: %s", SpStrError(ec));
|
|
|
} else {
|
|
|
Dbg("record failed: %s, %s, %s, %s", SpStrError(ec), SpStrError(ec1), SpStrError(ec2), SpStrError(ec3));
|
|
@@ -273,7 +288,7 @@ void CDeviceControlEntity::DeployTerminal(SpReqAnsContext<DeviceControlService_D
|
|
|
fileutil_delete_file(strRootTmpFile);
|
|
|
|
|
|
pConfig->WriteConfigValueInt("TerminalDeploy", "CurrStep", DeployStep_FetchCenterSettings);
|
|
|
- pConfig->WriteConfigValueInt("TerminalDeploy", "CurrState", 0);
|
|
|
+ pConfig->WriteConfigValueInt("TerminalDeploy", "CurrState", DEPLOYSTATE_NOTINIT);
|
|
|
|
|
|
} else {
|
|
|
tmpMsg = "找不到匹配的备选文件,请确认安装包完整性并尝试重新安装";
|
|
@@ -284,6 +299,8 @@ void CDeviceControlEntity::DeployTerminal(SpReqAnsContext<DeviceControlService_D
|
|
|
|
|
|
} while (false);
|
|
|
|
|
|
+ ctx->Ans.param2 = serverIP;
|
|
|
+
|
|
|
ctx->Ans.result = tmpResult;
|
|
|
ctx->Ans.message = tmpMsg;
|
|
|
}
|
|
@@ -297,10 +314,100 @@ void CDeviceControlEntity::DeployTerminal(SpReqAnsContext<DeviceControlService_D
|
|
|
}
|
|
|
break;
|
|
|
case DeployStep_FetchCenterSettings:
|
|
|
- result = Error_NotImpl;
|
|
|
+ {
|
|
|
+ const CSimpleStringA& serverIP = ctx->Req.param3;
|
|
|
+ const int nPort = ctx->Req.param1;
|
|
|
+
|
|
|
+ if (serverIP.IsNullOrEmpty() || nPort <= 0) {
|
|
|
+ result = Error_Param;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+
|
|
|
+ ErrorCodeEnum ec(Error_Succeed);
|
|
|
+ CSmartPointer<IConfigInfo> pConfig;
|
|
|
+ GetFunction()->OpenConfig(Config_Cache, pConfig);
|
|
|
+
|
|
|
+ Dbg("to connect centersetting...%s::%d", serverIP.GetData(), nPort);
|
|
|
+ auto pCenterSettingClient = new CenterSettingService_ClientBase(this);
|
|
|
+ ec = pCenterSettingClient->Connect();
|
|
|
+ if (ec != Error_Succeed) {
|
|
|
+ tmpMsg = CSimpleStringA::Format("连接集中配置模块失败: %s", SpStrError(ec));
|
|
|
+ pCenterSettingClient->SafeDelete();
|
|
|
+ Dbg("connect to centersetting failed: %s", SpStrError(ec));
|
|
|
+ tmpResult = ec;
|
|
|
+ } else {
|
|
|
+ CenterSettingService_Download_Req req = {};
|
|
|
+ req.strAddr = serverIP;
|
|
|
+ req.nPort = nPort;
|
|
|
+ CenterSettingService_Download_Ans ans = {};
|
|
|
+ /**TODO(Gifur@10/14/2021): 未知行内还是行外的情况 */
|
|
|
+ Dbg("to download...");
|
|
|
+ ec = pCenterSettingClient->Download(req, ans, 10000);
|
|
|
+ if (ec != Error_Succeed) {
|
|
|
+ tmpMsg = CSimpleStringA::Format("集中配置模块调用失败: %s", SpStrError(ec));
|
|
|
+ tmpResult = ec;
|
|
|
+ Dbg("to download failed: %s", SpStrError(ec));
|
|
|
+ } else {
|
|
|
+ pConfig->WriteConfigValueInt("TerminalDeploy", "CurrStep", DeployStep_AccessAuthorize);
|
|
|
+ pConfig->WriteConfigValueInt("TerminalDeploy", "CurrState", DEPLOYSTATE_NOTINIT);
|
|
|
+ }
|
|
|
+ pCenterSettingClient->GetFunction()->CloseSession();
|
|
|
+ }
|
|
|
+
|
|
|
+ ctx->Ans.param2 = serverIP;
|
|
|
+
|
|
|
+ ctx->Ans.result = tmpResult;
|
|
|
+ ctx->Ans.message = tmpMsg;
|
|
|
+ }
|
|
|
break;
|
|
|
case DeployStep_AccessAuthorize:
|
|
|
- result = Error_NotImpl;
|
|
|
+ {
|
|
|
+ const CSimpleStringA& serverIP = ctx->Req.param3;
|
|
|
+ const int nPort = ctx->Req.param1;
|
|
|
+
|
|
|
+ if (serverIP.IsNullOrEmpty() || nPort <= 0) {
|
|
|
+ result = Error_Param;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+
|
|
|
+ ErrorCodeEnum ec(Error_Succeed);
|
|
|
+ CSmartPointer<IConfigInfo> pConfig;
|
|
|
+ GetFunction()->OpenConfig(Config_Cache, pConfig);
|
|
|
+
|
|
|
+ Dbg("to connect initializer...%s::%d", serverIP.GetData(), nPort);
|
|
|
+ auto pClient = new InitializerService_ClientBase(this);
|
|
|
+ ec = pClient->Connect();
|
|
|
+ if (ec != Error_Succeed) {
|
|
|
+ tmpMsg = CSimpleStringA::Format("连接初始化模块失败: %s", SpStrError(ec));
|
|
|
+ pClient->SafeDelete();
|
|
|
+ Dbg("connect to initializer module failed: %s", SpStrError(ec));
|
|
|
+ tmpResult = ec;
|
|
|
+ } else {
|
|
|
+ InitializerService_InitializeNew_Req req = {};
|
|
|
+ req.strAuthServer = serverIP;
|
|
|
+ req.nAuthPort = nPort;
|
|
|
+ req.strUserID = "admin";
|
|
|
+ req.strPassword = "88888888";
|
|
|
+
|
|
|
+ InitializerService_InitializeNew_Ans ans = {};
|
|
|
+ Dbg("to initializer...");
|
|
|
+ ec = pClient->InitializeNew(req, ans, 30000);
|
|
|
+ if (ec != Error_Succeed) {
|
|
|
+ tmpMsg = CSimpleStringA::Format("初始化调用失败: %s", SpStrError(ec));
|
|
|
+ tmpResult = ec;
|
|
|
+ Dbg("to initialize failed: %s", SpStrError(ec));
|
|
|
+ } else {
|
|
|
+ pConfig->WriteConfigValueInt("TerminalDeploy", "CurrStep", DeployStep_MediaConfig);
|
|
|
+ pConfig->WriteConfigValueInt("TerminalDeploy", "CurrState", DEPLOYSTATE_NOTINIT);
|
|
|
+ }
|
|
|
+ pClient->GetFunction()->CloseSession();
|
|
|
+ }
|
|
|
+
|
|
|
+ ctx->Ans.param2 = serverIP;
|
|
|
+
|
|
|
+ ctx->Ans.result = tmpResult;
|
|
|
+ ctx->Ans.message = tmpMsg;
|
|
|
+ }
|
|
|
break;
|
|
|
case DeployStep_MediaConfig:
|
|
|
result = Error_NotImpl;
|
|
@@ -309,7 +416,7 @@ void CDeviceControlEntity::DeployTerminal(SpReqAnsContext<DeviceControlService_D
|
|
|
result = Error_NotImpl;
|
|
|
break;
|
|
|
default:
|
|
|
- result = Error_NotSupport;
|
|
|
+ result = Error_MisMatched;
|
|
|
break;
|
|
|
}
|
|
|
ctx->Answer(result);
|