123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628 |
- // mod_DeviceControl.cpp : Defines the exported functions for the DLL application.
- //
- #include "stdafx.h"
- #include "mod_DeviceControl.h"
- #include "DeviceControl_msg_g.h"
- #include "toolkit.h"
- #include "CommEntityUtil.hpp"
- #include <string>
- #include <map>
- #include <regex.h>
- #include "array.h"
- #include "fileutil.h"
- #include <vector>
- #include <sys/utsname.h>
- #include "RestfulFunc.h"
- #include "DeviceAdaptChecker.h"
- #include "EventCode.h"
- void CDeviceControlServerSession::Handle_USB(SpReqAnsContext<DeviceControlService_USB_Req, DeviceControlService_USB_Ans>::Pointer ctx)
- {
- LOG_FUNCTION();
- m_pEntity->USB(ctx);
- }
- void CDeviceControlServerSession::Handle_GetUkeyID(SpReqAnsContext<DeviceControlService_GetUkeyID_Req, DeviceControlService_GetUkeyID_Ans>::Pointer ctx)
- {
- LOG_FUNCTION();
- m_pEntity->GetUkeyID(ctx);
- }
- void CDeviceControlServerSession::Handle_InitToken(SpReqAnsContext<DeviceControlService_InitToken_Req, DeviceControlService_InitToken_Ans>::Pointer ctx)
- {
- LOG_FUNCTION();
- m_pEntity->InitToken(ctx);
- }
- void CDeviceControlServerSession::Handle_QueryUSBStatus(SpReqAnsContext<DeviceControlService_QueryUSBStatus_Req, DeviceControlService_QueryUSBStatus_Ans>::Pointer ctx)
- {
- LOG_FUNCTION();
- m_pEntity->QueryUSBStatus(ctx);
- }
- void CDeviceControlServerSession::Handle_QueryHardwareInfo(SpReqAnsContext<DeviceControlService_QueryHardwareInfo_Req, DeviceControlService_QueryHardwareInfo_Ans>::Pointer ctx)
- {
- LOG_FUNCTION();
- m_pEntity->QueryHardwareInfo(ctx);
- }
- void CDeviceControlServerSession::Handle_ReadCenterConfigStr(SpReqAnsContext<DeviceControlService_ReadCenterConfigStr_Req, DeviceControlService_ReadCenterConfigStr_Ans>::Pointer ctx)
- {
- LOG_FUNCTION();
- m_pEntity->ReadCenterConfigStr(ctx);
- }
- void CDeviceControlServerSession::Handle_ReadConfigValue(SpReqAnsContext<DeviceControlService_ReadConfigValue_Req, DeviceControlService_ReadConfigValue_Ans>::Pointer ctx)
- {
- m_pEntity->ReadConfigValue(ctx);
- }
- void CDeviceControlServerSession::Handle_GetDevInfo(SpReqAnsContext<DeviceControlService_GetDevInfo_Req, DeviceControlService_GetDevInfo_Ans>::Pointer ctx)
- {
- LOG_FUNCTION();
- m_pEntity->GetDevInfo(ctx);
- }
- void CDeviceControlServerSession::Handle_TestConnectivity(SpReqAnsContext<DeviceControlService_TestConnectivity_Req, DeviceControlService_TestConnectivity_Ans>::Pointer ctx)
- {
- LOG_FUNCTION();
- m_pEntity->TestConnectivity(ctx);
- }
- void CDeviceControlServerSession::Handle_GetVendorFileList(SpReqAnsContext<DeviceControlService_GetVendorFileList_Req, DeviceControlService_GetVendorFileList_Ans>::Pointer ctx)
- {
- LOG_FUNCTION();
- m_pEntity->GetVendorFileList(ctx);
- }
- void CDeviceControlServerSession::Handle_TestAdapterFileAvailable(SpReqAnsContext<DeviceControlService_TestAdapterFileAvailable_Req, DeviceControlService_TestAdapterFileAvailable_Ans>::Pointer ctx)
- {
- LOG_FUNCTION();
- m_pEntity->TestAdapterFileAvailable(ctx);
- }
- void CDeviceControlEntity::QueryHardwareInfo(SpReqAnsContext<DeviceControlService_QueryHardwareInfo_Req, DeviceControlService_QueryHardwareInfo_Ans>::Pointer ctx)
- {
- CSystemStaticInfo info;
- GetFunction()->GetSystemStaticInfo(info);
- CSimpleStringA deviceFct("");
- NetworkAddressesList macAddrs;
- NetworkAddressesList ipAddrs;
- SP::Module::Net::GetINETMacAddresses(macAddrs, ipAddrs);
- //根据设备类型获取厂商信息
- if (info.strMachineType == "RVC.PAD")
- {
- DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("This is PAD device.");
- //国产化目前没有pad设备,后续按需修改
- }
- else
- {
- CSmartPointer<IConfigInfo> spConfig;
- GetFunction()->OpenConfig(Config_Root, spConfig);
- spConfig->ReadConfigValue("Device.PinPad", "Vendor", deviceFct);
- }
- //获取操作系统版本信息
- utsname sysInfo;
- uname(&sysInfo);
- CSimpleStringA sysVer("UOS ");
- sysVer.Append(sysInfo.release);
- if (ctx != NULL) {
- ctx->Ans.ip = ipAddrs;
- ctx->Ans.mac = macAddrs;
- ctx->Ans.machineType = info.strMachineType;
- ctx->Ans.site = info.strSite;
- ctx->Ans.terminalNo = info.strTerminalID;
- ctx->Ans.termLimit = __ReadCenterConfigStr("TermLimitSwitch", "IEBrowser").second;
- ctx->Ans.termVersion = info.InstallVersion.ToString();
- ctx->Ans.reserved3 = sysVer;
- ctx->Ans.reserved4 = deviceFct;
- ctx->Answer(Error_Succeed);
- }
- }
- void CDeviceControlEntity::ReadCenterConfigStr(SpReqAnsContext<DeviceControlService_ReadCenterConfigStr_Req, DeviceControlService_ReadCenterConfigStr_Ans>::Pointer ctx)
- {
- auto ret = __ReadCenterConfigStr(ctx->Req.key, ctx->Req.entityName);
- ctx->Ans.value = ret.second;
- ctx->Ans.reserved1 = ctx->Ans.reserved2 = 0;
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("%s: ReadCenterConfigStr key:%s, entityName:%s: %s",
- SpStrError(ret.first),
- ctx->Req.key.GetData(), ctx->Req.entityName.GetData(), ctx->Ans.value.GetData());
- ctx->Answer(ret.first);
- }
- void CDeviceControlEntity::ReadConfigValue(SpReqAnsContext<DeviceControlService_ReadConfigValue_Req, DeviceControlService_ReadConfigValue_Ans>::Pointer ctx)
- {
- LOG_FUNCTION();
- if (ctx->Req.configType < 0 || ctx->Req.configType > Config_Cache + 1) {
- ctx->Answer(Error_Param);
- return;
- }
- if (ctx->Req.configType == 0) {
- if (ctx->Req.section.Compare("SougouInput") == 0) {
- if (ctx->Req.key.Compare("Snapshot") == 0) {
- CSimpleStringA shellScriptPath;
- GetFunction()->GetPath("Base", shellScriptPath);
- shellScriptPath += SPLIT_SLASH_STR;
- shellScriptPath += "res" SPLIT_SLASH_STR "RunScript" SPLIT_SLASH_STR;
- std::string fetch_scripts(shellScriptPath.GetData());
- fetch_scripts += "sogouime-info-cmb.sh";
- if (!ExistsFileA(fetch_scripts.c_str())) {
- ctx->Answer(Error_NotExist);
- return;
- } else {
- 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", fetch_scripts.c_str());
- option.params = app;
- const int res = process_spawn(&option, &process);
- if (0 == res) {
- FREE(process);
- LogWarn(Severity_Middle, Error_Debug, LOG_DEVICECONTROL_SOGOU_SCRIPTS_EXECUTE_SUCC,
- CSimpleStringA::Format("%s", fetch_scripts.c_str()));
- } else {
- LogWarn(Severity_Middle, Error_Unexpect, LOG_DEVICECONTROL_SOGOU_SCRIPTS_EXECUTE_FAILED,
- CSimpleStringA::Format("%s: %d", fetch_scripts.c_str(), res));
- ctx->Answer(Error_NotExist);
- return;
- }
- } while (false);
- Sleep(5000);
- do {
- std::string succStr, errStr;
- SYSTEMTIME curTime = CSmallDateTime::GetNow().ToSystemTime();
- CSimpleStringA logFileName = CSimpleStringA::Format("/opt/rvc/dbg/sogouinfo/%04d%02d%02d.log", curTime.wYear, curTime.wMonth, curTime.wDay);
- std::string runStr("cat ");
- if (ExistsFileA(logFileName)) {
- runStr += logFileName.GetData();
- if (SP::Module::Util::ShellExecute(runStr, succStr, errStr)) {
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("execute {%s} suc: %s", runStr.c_str(), succStr.c_str());
- ctx->Ans.reserved3 = succStr.c_str();
- }
- }
- } while (false);
- ctx->Answer(Error_Succeed);
- return;
- }
-
- } else if (ctx->Req.key.Compare("SogouRestart") == 0) {
- ctx->Answer(m_fsm.RestartSogouServices());
- return;
- }
- else {
- ctx->Answer(Error_NotImpl);
- return;
- }
- } else {
- ctx->Answer(Error_NotImpl);
- return;
- }
- }
- ConfigTypeEnum type = static_cast<ConfigTypeEnum>(ctx->Req.configType - 1);
- CSmartPointer<IConfigInfo> spConfig;
- ErrorCodeEnum err = GetFunction()->OpenConfig(type, spConfig);
- if (err == Error_Succeed) {
- CSimpleStringA str(true);
- CSimpleStringA section(ctx->Req.section);
- CSimpleStringA key(ctx->Req.key);
- #ifndef DEVOPS_ON_PRD
- /** 被逼的,方便测试环境验证,并且在只读的情况下 [Gifur@2022127]*/
- if (ctx->Req.reserved1 == 1 && !ctx->Req.option) {
- #ifdef DEVOPS_ON_ST
- section.Append("_ST");
- #else defined(DEVOPS_ON_UAT)
- section.Append("_UAT");
- #endif // DEVOPS_ON_ST
- }
- #endif
- err = spConfig->ReadConfigValue(section, key, str);
- if (err == Error_Succeed) ctx->Ans.value = str;
- if (ctx->Req.option && ctx->Req.reserved3.Compare(str) != 0) {
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("save value: %s", ctx->Req.reserved3.GetData());
- err = spConfig->WriteConfigValue(section, key, ctx->Req.reserved3);
- } else if (ctx->Req.option) {
- DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM)("stored value is the same as the coming one: %s", str.GetData());
- }
- }
- ctx->Answer(err);
- return;
- }
- void CDeviceControlEntity::TestConnectivity(SpReqAnsContext<DeviceControlService_TestConnectivity_Req, DeviceControlService_TestConnectivity_Ans>::Pointer ctx)
- {
- LOG_FUNCTION();
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("%d: %s:%d", ctx->Req.protocol, ctx->Req.ip.GetData(), ctx->Req.port);
- ErrorCodeEnum result(Error_NotInit);
- if (ctx->Req.protocol == 0) {
- result = Error_Param;
- } else if (ctx->Req.protocol == 1) { //Ping
- if (ctx->Req.ip.IsNullOrEmpty()) {
- result = Error_Param;
- } else {
- const int res = PingTest(std::string(ctx->Req.ip));
- if (res == 0) {
- ctx->Ans.result = 0;
- ctx->Ans.additionalMsg.Clear();
- } else {
- ctx->Ans.result = -1;
- ctx->Ans.additionalMsg = CSimpleStringA::Format("Ping %s failed: %d", ctx->Req.ip.GetData(), res);
- }
- result = Error_Succeed;
- }
- } else if (ctx->Req.protocol == 2) { //Normal socket connect Test
- if (ctx->Req.ip.IsNullOrEmpty() || ctx->Req.port <= 0) {
- result = Error_Param;
- } else {
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("Test socket connect available: %s:%d", ctx->Req.ip.GetData(), ctx->Req.port);
- std::string errMsg("");
- const int ret = SocketConnectTest(ctx->Req.ip.GetData(), ctx->Req.port, errMsg);
- ctx->Ans.result = ret;
- ctx->Ans.additionalMsg = errMsg.c_str();
- result = Error_Succeed;
- }
- }
- else if (ctx->Req.protocol == 4) { //Http Test
- if (ctx->Req.ip.IsNullOrEmpty()) {
- result = Error_Param;
- } else {
- std::string msg;
- const int res = HttpProbe(std::string(ctx->Req.ip), msg);
- ctx->Ans.result = res;
- ctx->Ans.additionalMsg = msg.c_str();
- result = Error_Succeed;
- }
- } else {
- result = Error_NotSupport;
- }
- ctx->Answer(result);
- }
- static CSimpleStringA GetRegexPatternString(const DeviceControlService_GetVendorFileList_Req& req, const CSimpleStringA& strMachineType)
- {
- const char* prefix = "^lib";
- const char* suffix = "\\.so$";
- CSimpleStringA strRegexPattern(prefix);
- //^lib(Gpio|PinPad)\.[a-zA-Z]*\.[0-9]*\.[0-9]*\.so$
- if (req.adapter.IsNullOrEmpty() || req.adapter.Compare("*") == 0) {
- CSimpleStringA tmp("(");
- if (strMachineType.Compare("RVC.Stand2S") == 0) {
- for (int i = 0; i < array_size(adapterList_4_stand2s); ++i) {
- if (i != 0) tmp += "|";
- tmp += adapterList_4_stand2s[i];
- }
- } else if (strMachineType.Compare("RVC.Stand1SPlus") == 0) {
- for (int i = 0; i < array_size(adapterList_4_stand1s); ++i) {
- if (i != 0) tmp += "|";
- tmp += adapterList_4_stand1s[i];
- }
- } else {
- tmp += ".*";
- }
- tmp += (")");
- strRegexPattern += tmp;
- } else {
- strRegexPattern += "(";
- strRegexPattern += req.adapter;
- strRegexPattern += ")";
- }
- strRegexPattern += "\\.";
- if (req.vendor.IsNullOrEmpty() || req.vendor.Compare("*") == 0) {
- strRegexPattern += "[a-zA-Z]*";
- } else {
- strRegexPattern += "(";
- strRegexPattern += req.vendor;
- strRegexPattern += ")";
- }
- strRegexPattern += "\\.";
- if (req.version.IsNullOrEmpty() || req.version.Compare("*") == 0) {
- strRegexPattern += "[0-9]*";
- } else {
- strRegexPattern += "(";
- strRegexPattern += req.version;
- strRegexPattern += ")";
- }
- strRegexPattern += "\\.";
- if (req.batch.IsNullOrEmpty() || req.batch.Compare("*") == 0) {
- strRegexPattern += "[0-9]*";
- } else {
- strRegexPattern += "(";
- strRegexPattern += req.batch;
- strRegexPattern += ")";
- }
- strRegexPattern += suffix;
- return strRegexPattern;
- }
- void CDeviceControlEntity::GetVendorFileList(SpReqAnsContext<DeviceControlService_GetVendorFileList_Req, DeviceControlService_GetVendorFileList_Ans>::Pointer ctx)
- {
- LOG_FUNCTION();
- ErrorCodeEnum result(Error_Succeed);
- int tmpResult = 0;
- CSimpleStringA tmpMsg(true);
- CSimpleStringA strDepDirPath;
- result = GetFunction()->GetPath("Dep", strDepDirPath);
- if (ctx->Req.root) {
- CAdapterLoadChecker* checker = new CAdapterLoadChecker();
- checker->Init(this);
- CAutoArray<AdapterRootConfigInfo> tmp;
- if (ctx->Req.adapter.IsNullOrEmpty() || ctx->Req.adapter.Compare("*") == 0) {
- tmp = checker->GetConfigedAdapterInfo();
- } else {
- tmp = checker->GetConfigedAdapterInfo(ctx->Req.adapter);
- }
- delete checker;
- checker = NULL;
- const int curSize = tmp.GetCount();
- ctx->Ans.filenames.Init(curSize);
- ctx->Ans.status.Init(curSize);
- ctx->Ans.port.Init(curSize);
- ctx->Ans.baudrate.Init(curSize);
- CSimpleStringA strDepDirPath2 = strDepDirPath + SPLIT_SLASH_STR;
- for (int i = 0; i < curSize; ++i) {
- ctx->Ans.filenames[i] = tmp[i].strDepDirWithSlashOrFileName;
- ctx->Ans.port[i] = tmp[i].dwPort;
- ctx->Ans.baudrate[i] = tmp[i].dwBaudRate;
- CSimpleStringA fullPath = strDepDirPath2 + ctx->Ans.filenames[i];
- ctx->Ans.status[i] = 0x2;
- if (ExistsFileA(fullPath)) {
- ctx->Ans.status[i] |= 0x1;
- }
- }
-
- } else {
- std::vector<std::string> adapterFiles;
- array_header_t* subs = fileutil_get_sub_files_a(strDepDirPath);
- if (subs) {
- regex_t reg;
- CSystemStaticInfo info;
- GetFunction()->GetSystemStaticInfo(info);
- CSimpleStringA pattern = GetRegexPatternString(ctx->Req, info.strMachineType);
- int ret = regcomp(®, pattern, REG_EXTENDED | REG_NOSUB);
- if (ret) {
- char ebuff[256];
- regerror(ret, ®, ebuff, 256);
- DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM)("regex failed: %s", ebuff);
- tmpResult = Error_Unexpect;
- tmpMsg = CSimpleStringA::Format("内部错误:REGEX %s", ebuff);
- } else {
- DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("pattern: %s", pattern.GetData());
- for (int i = 0; i < subs->nelts; ++i) {
- char* filenamePath = ARRAY_IDX(subs, i, char*);
- char* filename = &filenamePath[strDepDirPath.GetLength() + 1];
- ret = regexec(®, filename, 0, NULL, 0);
- if (0 == ret) {
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("filename %s matched!", filename);
- adapterFiles.push_back(std::string(filename));
- }
- }
- }
- const int curSize = adapterFiles.size();
- ctx->Ans.filenames.Init(curSize);
- ctx->Ans.status.Init(curSize);
- ctx->Ans.port.Init(curSize);
- ctx->Ans.baudrate.Init(curSize);
- for (int i = 0; i < curSize; ++i) {
- ctx->Ans.status[i] = 0;
- ctx->Ans.port[i] = 0;
- ctx->Ans.baudrate[i] = 0;
- }
- if (curSize > 0) {
- CAdapterLoadChecker* checker = new CAdapterLoadChecker();
- checker->Init(this);
- int cnt = 0;
- for (auto iter = adapterFiles.cbegin(); iter != adapterFiles.cend(); ++iter, ++cnt) {
- ctx->Ans.filenames[cnt] = iter->c_str();
- ctx->Ans.status[cnt] = 0x1;
- AdapterRootConfigInfo info;
- if (checker->IsThisFileConfigure(iter->c_str(), &info)) {
- ctx->Ans.status[cnt] |= 0x2;
- ctx->Ans.port[cnt] = info.dwPort;
- ctx->Ans.baudrate[cnt] = info.dwBaudRate;
- }
- }
- delete checker;
- }
- toolkit_array_free2(subs);
- }
- }
- ctx->Ans.result = tmpResult;
- ctx->Ans.msg = tmpMsg;
- ctx->Answer(result);
- return;
- }
- void CDeviceControlEntity::TestAdapterFileAvailable(
- SpReqAnsContext<DeviceControlService_TestAdapterFileAvailable_Req, DeviceControlService_TestAdapterFileAvailable_Ans>::Pointer ctx)
- {
- LOG_FUNCTION();
- ErrorCodeEnum result(Error_Succeed);
- int tmpResult = 0;
- CSimpleStringA tmpMsg(true);
- if (ctx->Req.type == 1) /*循环验证配置适配器的有效性*/ {
- CAdapterLoadChecker* checker = new CAdapterLoadChecker();
- checker->Init(this);
- CAutoArray<CAdapterLoader*>& tmp = checker->AdapterCoinfigList();
- const int curSize = tmp.GetCount();
- std::vector<std::string> errlibNames;
- std::vector<std::string> errMsgs;
- for (int i = 0; i < curSize; ++i) {
- ErrorCodeEnum ec(Error_Succeed);
- CSimpleStringA strLastErrMsg(true);
- VendorLibInfoEx& libInfo = tmp[i]->vendorLibInfo;
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("to check %s", libInfo.toLibNameString().GetData());
- ec = CAdapterLoadChecker::CheckDeviceAndAdapterAvailable(libInfo, strLastErrMsg);
- if (ec != Error_Succeed) {
- errlibNames.push_back(std::string(libInfo.toLibNameString().GetData()));
- errMsgs.push_back(std::string(strLastErrMsg.GetData()));
- strLastErrMsg = CSimpleStringA::Format("%s: %s", libInfo.toLibNameString().GetData(), strLastErrMsg.GetData());
- if (!tmpMsg.IsNullOrEmpty()) tmpMsg += "\n";
- tmpMsg += strLastErrMsg;
- if (!!(ctx->Req.options & 0x1)) {
- DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM)("detect critical error limit, break it.");
- tmpResult = ec;
- break;
- }
- }
- BroadcastAdapterTestResult(libInfo.toLibNameString(), ec, strLastErrMsg);
- }
- delete checker;
- checker = NULL;
- if (!(ctx->Req.options & 0x1) && !tmpMsg.IsNullOrEmpty()) {
- tmpResult = Error_Failed;
- }
- if (!errlibNames.empty()) {
- const int curErrSize = errlibNames.size();
- ctx->Ans.reserved1.Init(curErrSize);
- ctx->Ans.reserved2.Init(curErrSize);
- ctx->Ans.reserved3.Init(curErrSize);
- int cnt(0);
- for (auto iter = errlibNames.cbegin(); iter != errlibNames.cend(); ++iter) {
- ctx->Ans.reserved1[cnt] = 0;
- ctx->Ans.reserved2[cnt] = iter->c_str();
- ctx->Ans.reserved3[cnt] = errMsgs[cnt].c_str();
- cnt++;
- }
- }
- } else {
- if (ctx->Req.filename.IsNullOrEmpty()) {
- ctx->Answer(Error_Param);
- return;
- }
- VendorLibInfoEx libInfo;
- if (libInfo.Load(ctx->Req.filename)) {
- libInfo.optCfg.dwPort = ctx->Req.port;
- libInfo.optCfg.dwBaudRate = ctx->Req.baudrate;
- libInfo.optCfg.dwParam1 = ctx->Req.param1;
- libInfo.optCfg.dwParam2 = ctx->Req.param2;
- GetFunction()->GetPath("Dep", libInfo.optCfg.strDepDirWithSlashOrFileName);
- libInfo.optCfg.strDepDirWithSlashOrFileName += SPLIT_SLASH_STR;
- } else if (ctx->Req.filename.IndexOf(".") == -1) { //pure adapter name
- CAdapterLoader loader(ctx->Req.filename, this);
- tmpResult = loader.LoadConfigFromRootIni();
- libInfo = loader.vendorLibInfo;
- } else {
- DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM)("invalid adapter file name: %s", ctx->Req.filename.GetData());
- ctx->Answer(Error_MisMatched);
- return;
- }
- if (tmpResult == 0) {
- tmpResult = CAdapterLoadChecker::CheckDeviceAndAdapterAvailable(libInfo, tmpMsg);
- }
-
- }
- ctx->Ans.status = tmpResult;
- ctx->Ans.msg = tmpMsg;
- ctx->Answer(result);
- return;
- }
- std::pair<ErrorCodeEnum, CSimpleStringA> CDeviceControlEntity::__ReadCenterConfigStr(CSimpleStringA key, CSimpleStringA entityName = "")
- {
- CSimpleStringA str = "";
- CSmartPointer<IConfigInfo> spCerConfig;
- ErrorCodeEnum err = GetFunction()->OpenConfig(Config_CenterSetting, spCerConfig);
- if (err != Error_Succeed)
- DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM)("OpenConfig failed: %s", SpStrError(err));
- else
- err = spCerConfig->ReadConfigValue(
- entityName == CSimpleStringA("") ? "IEBrowser" : (const char*)entityName.GetData()
- , (const char*)key.GetData(), str);
- if (str.IsNullOrEmpty() && key.Compare("CenterConfigUrl") == 0 && entityName.Compare("CenterSetting") == 0) {
- DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM)("Try to read CenterSettings download url from shell.ini again");
- CSmartPointer<IConfigInfo> pConfigShell;
- GetFunction()->OpenConfig(Config_Shell, pConfigShell);
- CSimpleStringA section("CenterSettingsDownloadUrl");
- pConfigShell->ReadConfigValue(section, "LAN", str);
- if (Error_Succeed != err && !str.IsNullOrEmpty()) {
- err = Error_Succeed;
- }
- }
- return std::make_pair(err, str);
- }
- void CDeviceControlEntity::BroadcastAdapterTestResult(const CSimpleStringA& adapterName, ErrorCodeEnum result, const CSimpleStringA& strErrMsg)
- {
- LOG_FUNCTION();
- DeviceControl::AdapterTestResult evt;
- evt.result = result;
- evt.adapterInfo = adapterName;
- evt.errMsg = strErrMsg;
- SpSendBroadcast(GetFunction(), SP_MSG_OF(AdapterTestResult), SP_MSG_SIG_OF(AdapterTestResult), evt);
- }
- SP_BEGIN_ENTITY_MAP()
- SP_ENTITY(CDeviceControlEntity)
- SP_END_ENTITY_MAP()
|