|
@@ -3,8 +3,14 @@
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
+#include "SpBase.h"
|
|
|
#include "SpHelper.h"
|
|
|
#include "DeviceBaseClass.h"
|
|
|
+#include "SimpleString.h"
|
|
|
+#include "path.h"
|
|
|
+#include <regex>
|
|
|
+#include <winpr/file.h>
|
|
|
+#include <winpr/environment.h>
|
|
|
|
|
|
#define SAFE_FREE_LIBRARY(hModule) \
|
|
|
do { \
|
|
@@ -15,11 +21,11 @@
|
|
|
}while(0)
|
|
|
|
|
|
#if DEVICE_BASE_INTERFACE_FILE_VERSION == 2
|
|
|
-using DevAdaptObjCreateFunc = ErrorCodeEnum(*)(DWORD dwDevClassID, DeviceBaseClass * &pOutDevAptObj);
|
|
|
-using DevAdaptObjReleaseFunc = ErrorCodeEnum(*)(DWORD dwDevClassID, DeviceBaseClass * &pInDevAptObj);
|
|
|
+ using DevAdaptObjCreateFunc = ErrorCodeEnum(*)(DWORD dwDevClassID, DeviceBaseClass * &pOutDevAptObj);
|
|
|
+ using DevAdaptObjReleaseFunc = ErrorCodeEnum(*)(DWORD dwDevClassID, DeviceBaseClass * &pInDevAptObj);
|
|
|
#else
|
|
|
-using DevAdaptObjCreateFunc = ErrorCodeEnum(*)(DeviceBaseClass * &pOutDevAptObj);
|
|
|
-using DevAdaptObjReleaseFunc = ErrorCodeEnum(*)(DeviceBaseClass * &pInDevAptObj);
|
|
|
+ using DevAdaptObjCreateFunc = ErrorCodeEnum(*)(DeviceBaseClass * &pOutDevAptObj);
|
|
|
+ using DevAdaptObjReleaseFunc = ErrorCodeEnum(*)(DeviceBaseClass * &pInDevAptObj);
|
|
|
#endif
|
|
|
|
|
|
|
|
@@ -101,10 +107,10 @@ struct DevAdptLibHelper
|
|
|
{
|
|
|
if (m_AdptObjPtr != nullptr) {
|
|
|
m_AdptObjPtr->DevClose();
|
|
|
- }
|
|
|
- if (m_AdptObjPtr != nullptr && nullptr != pFuncReleaseAdapt) {
|
|
|
- pFuncReleaseAdapt(0, m_AdptObjPtr);
|
|
|
- m_AdptObjPtr = nullptr;
|
|
|
+ if (nullptr != pFuncReleaseAdapt) {
|
|
|
+ pFuncReleaseAdapt(0, m_AdptObjPtr);
|
|
|
+ m_AdptObjPtr = nullptr;
|
|
|
+ }
|
|
|
}
|
|
|
SAFE_FREE_LIBRARY(hModule);
|
|
|
}
|
|
@@ -118,6 +124,10 @@ struct DevAdptLibHelper
|
|
|
{
|
|
|
|
|
|
}
|
|
|
+ ~DevAdptLibHelper()
|
|
|
+ {
|
|
|
+ TearDown();
|
|
|
+ }
|
|
|
|
|
|
private:
|
|
|
|
|
@@ -128,74 +138,116 @@ private:
|
|
|
TSubAdpt* m_AdptObjPtr;
|
|
|
};
|
|
|
|
|
|
+struct VendorLibInfo
|
|
|
+{
|
|
|
+ CSimpleStringA strDevice;
|
|
|
+ CSimpleStringA strVendor;
|
|
|
+ CSimpleStringA strVersion;
|
|
|
+ CSimpleStringA strBatch;
|
|
|
+
|
|
|
+ VendorLibInfo() :strDevice(true), strVendor(true), strVersion(true), strBatch(true) {}
|
|
|
+
|
|
|
+ bool IsValid() const {
|
|
|
+ return (!strDevice.IsNullOrEmpty()
|
|
|
+ && !strVendor.IsNullOrEmpty()
|
|
|
+ && !strVersion.IsNullOrEmpty()
|
|
|
+ && !strBatch.IsNullOrEmpty());
|
|
|
+ }
|
|
|
+
|
|
|
+ int GetVersion()
|
|
|
+ {
|
|
|
+ int result = 0;
|
|
|
+ if (!strVersion.IsNullOrEmpty()) {
|
|
|
+ result = atoi(strVersion.GetData());
|
|
|
+ }
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+ int GetBatch()
|
|
|
+ {
|
|
|
+ int result = 0;
|
|
|
+ if (!strBatch.IsNullOrEmpty()) {
|
|
|
+ result = atoi(strBatch.GetData());
|
|
|
+ }
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+ CSimpleStringA toLibNameString()
|
|
|
+ {
|
|
|
+ CSimpleStringA strFullLibName(true);
|
|
|
+ if (!strDevice.IsNullOrEmpty()) {
|
|
|
+ strFullLibName = strDevice;
|
|
|
+ if (strVendor.IsNullOrEmpty()) {
|
|
|
+ strFullLibName += ".";
|
|
|
+ strFullLibName += strVendor;
|
|
|
+ }
|
|
|
+ if (strVersion.IsNullOrEmpty()) {
|
|
|
+ strFullLibName += ".";
|
|
|
+ strFullLibName += strVersion;
|
|
|
+ }
|
|
|
+ if (strBatch.IsNullOrEmpty()) {
|
|
|
+ strFullLibName += ".";
|
|
|
+ strFullLibName += strBatch;
|
|
|
+ }
|
|
|
+
|
|
|
+#ifdef _WIN32
|
|
|
+ strFullLibName += ".dll";
|
|
|
+#else
|
|
|
+ CSimpleStringA strPrefix("lib");
|
|
|
+ strPrefix += strFullLibName;
|
|
|
+ strPrefix += ".so";
|
|
|
+ strFullLibName = strPrefix;
|
|
|
+#endif //_WIN32
|
|
|
+ }
|
|
|
+
|
|
|
+ return strFullLibName;
|
|
|
+ }
|
|
|
+};
|
|
|
+
|
|
|
|
|
|
class CDevAdptEntityBase : public CEntityBase
|
|
|
{
|
|
|
|
|
|
public:
|
|
|
|
|
|
- CDevAdptEntityBase() :m_strLibName(true) {}
|
|
|
+ CDevAdptEntityBase(){}
|
|
|
|
|
|
CSimpleStringA GetVendorLibName()
|
|
|
{
|
|
|
- if (m_strLibName.IsNullOrEmpty()) {
|
|
|
- ExtractVendorLibName(m_strLibName);
|
|
|
+ if (m_libInfo.IsValid()) {
|
|
|
+ ExtractVendorLibName();
|
|
|
}
|
|
|
- return m_strLibName;
|
|
|
+ return m_libInfo.toLibNameString();
|
|
|
}
|
|
|
|
|
|
ErrorCodeEnum ExtractVendorLibFullPath(CSimpleStringA& csLibFullPath);
|
|
|
-
|
|
|
+ ErrorCodeEnum InitializeVendorLogSwitch();
|
|
|
private:
|
|
|
|
|
|
- ErrorCodeEnum ExtractVendorLibName(CSimpleStringA& csLibName);
|
|
|
+ ErrorCodeEnum ExtractVendorLibName();
|
|
|
|
|
|
-private:
|
|
|
-
|
|
|
- CSimpleStringA m_strLibName;
|
|
|
+protected:
|
|
|
+ VendorLibInfo m_libInfo;
|
|
|
};
|
|
|
|
|
|
-ErrorCodeEnum CDevAdptEntityBase::ExtractVendorLibName(CSimpleStringA& csLibName)
|
|
|
+inline ErrorCodeEnum CDevAdptEntityBase::ExtractVendorLibName()
|
|
|
{
|
|
|
CSmartPointer<IConfigInfo> spRootConfig;
|
|
|
ErrorCodeEnum erroCode = GetFunction()->OpenConfig(Config_Root, spRootConfig);
|
|
|
-
|
|
|
if (IS_SUCCEED(erroCode)) {
|
|
|
CSimpleStringA strSection = CSimpleStringA("Device.") + GetEntityName();
|
|
|
- csLibName = GetEntityBase()->GetEntityName();
|
|
|
- CSimpleStringA str;
|
|
|
- spRootConfig->ReadConfigValue(strSection, "Vendor", str);
|
|
|
- if (!str.IsNullOrEmpty()) {
|
|
|
- csLibName += ".";
|
|
|
- csLibName += str;
|
|
|
- } else {
|
|
|
- erroCode = Error_NotConfig;
|
|
|
- }
|
|
|
-
|
|
|
- str.Clear();
|
|
|
- spRootConfig->ReadConfigValue(strSection, "Version", str);
|
|
|
- if (!str.IsNullOrEmpty()) {
|
|
|
- csLibName += ".";
|
|
|
- csLibName += str;
|
|
|
- }
|
|
|
+ m_libInfo.strDevice = GetEntityName();
|
|
|
+ spRootConfig->ReadConfigValue(strSection, "Vendor", m_libInfo.strVendor);
|
|
|
+ spRootConfig->ReadConfigValue(strSection, "Version", m_libInfo.strVersion);
|
|
|
+ spRootConfig->ReadConfigValue(strSection, "Batch", m_libInfo.strBatch);
|
|
|
|
|
|
- str.Clear();
|
|
|
- spRootConfig->ReadConfigValue(strSection, "Batch", str);
|
|
|
- if (!str.IsNullOrEmpty()) {
|
|
|
- csLibName += ".";
|
|
|
- csLibName += str;
|
|
|
- }
|
|
|
-
|
|
|
- str = csLibName + ".dll";
|
|
|
- csLibName = str;
|
|
|
- }
|
|
|
- else {
|
|
|
- //TODO: SetCustLastErrorCode();
|
|
|
+ if (!m_libInfo.IsValid())
|
|
|
+ erroCode = Error_NotConfig;
|
|
|
}
|
|
|
return erroCode;
|
|
|
}
|
|
|
|
|
|
-ErrorCodeEnum CDevAdptEntityBase::ExtractVendorLibFullPath(CSimpleStringA& csLibFullPath)
|
|
|
+inline ErrorCodeEnum CDevAdptEntityBase::ExtractVendorLibFullPath(CSimpleStringA& csLibFullPath)
|
|
|
{
|
|
|
CSimpleStringA strLibName = GetVendorLibName();
|
|
|
if (strLibName.IsNullOrEmpty()) {
|
|
@@ -204,9 +256,78 @@ ErrorCodeEnum CDevAdptEntityBase::ExtractVendorLibFullPath(CSimpleStringA& csLib
|
|
|
|
|
|
CSimpleStringA strDepPath;
|
|
|
GetFunction()->GetPath("Dep", strDepPath);
|
|
|
- csLibFullPath = CSimpleStringA::Format("%s\\%s", (LPCTSTR)strDepPath, (LPCTSTR)strLibName);
|
|
|
+ csLibFullPath = CSimpleStringA::Format("%s" SPLIT_SLASH_STR "%s", (LPCTSTR)strDepPath, (LPCTSTR)strLibName);
|
|
|
|
|
|
return Error_Succeed;
|
|
|
}
|
|
|
|
|
|
+inline ErrorCodeEnum CDevAdptEntityBase::InitializeVendorLogSwitch()
|
|
|
+{
|
|
|
+ CSystemStaticInfo sysInfo;
|
|
|
+ GetFunction()->GetSystemStaticInfo(sysInfo);
|
|
|
+ if (!m_libInfo.IsValid())
|
|
|
+ ExtractVendorLibName();
|
|
|
+
|
|
|
+ struct VendorLogConfig {
|
|
|
+ CSimpleStringA strLevel;
|
|
|
+ CSimpleStringA strType;
|
|
|
+ CSimpleStringA strDllName;
|
|
|
+ CSimpleStringA strLogPath;
|
|
|
+
|
|
|
+ void Settle() {
|
|
|
+ SetEnvironmentVariableA("VENDOR_RECODE_LEVEL", strLevel);
|
|
|
+ SetEnvironmentVariableA("VENDOR_RECODE_TYPE", strType);
|
|
|
+ SetEnvironmentVariableA("VENDOR_DLL_NAME", strDllName);
|
|
|
+ SetEnvironmentVariableA("VENDOR_LOG_PATH", strLogPath);
|
|
|
+ }
|
|
|
+
|
|
|
+ } stLogConfig = { "OFF" "FILE", m_libInfo.toLibNameString(), ""};
|
|
|
+
|
|
|
+ CSmartPointer<IConfigInfo> centerConfig;
|
|
|
+ GetFunction()->OpenConfig(Config_CenterSetting, centerConfig);
|
|
|
+
|
|
|
+ CSimpleStringA str;
|
|
|
+ centerConfig->ReadConfigValue(GetEntityName(), m_libInfo.strVendor, str);
|
|
|
+ if (str.IsNullOrEmpty()) {
|
|
|
+ centerConfig->ReadConfigValue(GetEntityName(), "All", str);
|
|
|
+ }
|
|
|
+ if (!str.IsNullOrEmpty())
|
|
|
+ stLogConfig.strLevel = str;
|
|
|
+
|
|
|
+ if (stLogConfig.strLevel.Compare("OFF", true) != 0) {
|
|
|
+ CSimpleStringA strWhiteNameSheet;
|
|
|
+ centerConfig->ReadConfigValue(GetEntityName(), "AllowTerminals", strWhiteNameSheet);
|
|
|
+ if (!strWhiteNameSheet.IsNullOrEmpty()) {
|
|
|
+ bool bWhiteNameSheet = false;
|
|
|
+ CAutoArray<CSimpleStringA> arrayWhiteNameSheet = strWhiteNameSheet.Split(',');
|
|
|
+ for (int i = 0; i < arrayWhiteNameSheet.GetCount(); i++) {
|
|
|
+ std::regex pattern(arrayWhiteNameSheet[i]);
|
|
|
+ if (std::regex_match(sysInfo.strTerminalID.GetData(), pattern)) {
|
|
|
+ bWhiteNameSheet = true;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //if this terminal is not at WhiteNameSheet,set level with "OFF".
|
|
|
+ if (!bWhiteNameSheet)
|
|
|
+ stLogConfig.strLevel = "OFF";
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (stLogConfig.strLevel.Compare("OFF", true) != 0) {
|
|
|
+ str.Clear();
|
|
|
+ centerConfig->ReadConfigValue(GetEntityName(), "Type", str);
|
|
|
+ if (!str.IsNullOrEmpty())
|
|
|
+ stLogConfig.strType = str;
|
|
|
+
|
|
|
+ TCHAR szPath[MAX_PATH] = { 0 };
|
|
|
+ GetModuleFileNameA(NULL, szPath, MAX_PATH);
|
|
|
+ CSimpleStringA strDir = szPath;
|
|
|
+ str = strDir.SubString(0, 1);
|
|
|
+ str += ":/rvc/dbg";
|
|
|
+ stLogConfig.strLogPath = str;
|
|
|
+
|
|
|
+ stLogConfig.Settle();
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
#endif /*_RVC_DEVICE_ADAPTER_ENTITY_BASE_H__*/
|