Эх сурвалжийг харах

Z991239-968 #comment 提供获取终端信息的接口GetTerminalMachineInfo

gifur 5 жил өмнө
parent
commit
ed1e5da057

+ 165 - 0
Module/include/CommEntityUtil.hpp

@@ -0,0 +1,165 @@
+#ifndef RVC_MOD_COMM_ENTITY_UTIL_HPP_
+#define RVC_MOD_COMM_ENTITY_UTIL_HPP_
+
+#include "path.h"
+#include "SpBase.h"
+
+#if defined(RVC_OS_WIN)
+#define streq stricmp
+#else
+#define streq strcasecmp
+#endif //RVC_OS_WIN
+
+namespace SP
+{
+namespace Module
+{
+namespace Comm
+{
+inline
+CSimpleStringA GetCurrMachineType(CEntityBase* pEntity)
+{
+    CSystemStaticInfo sysInfo;
+    pEntity->GetFunction()->GetSystemStaticInfo(sysInfo);
+    return sysInfo.strMachineType;
+}
+
+inline
+CSimpleStringA GetCurrEntityConfigPath(CEntityBase* pEntity)
+{
+    CSimpleStringA strConfigDir(true);
+    pEntity->GetFunction()->GetPath("cfg", strConfigDir);
+    CSimpleStringA result(strConfigDir + SPLIT_SLASH_STR + pEntity->GetEntityName() + ".ini");
+    Dbg("config path: %s", result.GetData());
+    return result;
+}
+
+enum Site
+{
+	CMB_UNKNOWN,
+	CMB_LIB,       /** 行内大堂*/
+	CMB_SSB,      /** 自助网点*/
+	CMB_LSS,      /** 生活销售机*/
+	CMB_FLB,      /** 离行机器*/
+	CMB_OSB,     /** 外拓PAD*/
+	CMB_SMM     /** 商户终端*/
+};
+
+#define SITE_ENUM_TYPE(MACRO)	\
+		MACRO(LIB)\
+		MACRO(SSB)\
+		MACRO(LSS)\
+		MACRO(FLB)\
+		MACRO(OSB)\
+		MACRO(SMM)
+
+
+#define ENUM_MAP_CONVERT(elem) \
+	if (streq(lpcszSiteName, "CMB."#elem) == 0) return CMB_##elem;
+/*!
+ * convert cmb site name to enum type.
+ */
+static Site Str2Site(LPCSTR lpcszSiteName)
+{
+	if (lpcszSiteName == NULL || strlen(lpcszSiteName) == 0)
+		return CMB_UNKNOWN;
+	SITE_ENUM_TYPE(ENUM_MAP_CONVERT)
+		return CMB_UNKNOWN;
+}
+
+#undef ENUM_MAP_CONVERT
+#define ENUM_MAP_CONVERT(elem) case CMB_##elem: return "CMB."#elem;
+
+static LPCSTR Site2Str(Site site)
+{
+	switch (site) {
+		SITE_ENUM_TYPE(ENUM_MAP_CONVERT)
+	default:
+		break;
+	}
+	return "Unkown";
+}
+
+enum What
+{
+	RVC_UNKNOWN,
+	RVC_Stand2S,          /** 落地式大机*/
+	RVC_PAD,                /** PAD*/
+	RVC_Desk2S,           /** 低柜双屏*/
+	RVC_IL,                    /** 简版*/
+	RVC_Desk1S,          /** 低柜一体机*/
+	RPM_Stand1S         /** 扩展柜*/
+};
+
+#define MACHINE_ENUM_TYPE(MACRO)	\
+		MACRO(Stand2S)\
+		MACRO(PAD)\
+		MACRO(Desk2S)\
+		MACRO(IL)\
+		MACRO(Desk1S)
+
+#undef ENUM_MAP_CONVERT
+#define ENUM_MAP_CONVERT(elem) \
+	if (streq(lpcszTypeName, "RVC."#elem) == 0) return RVC_##elem;
+/*!
+ * convert cmb site name to enum type.
+ */
+static What Str2Type(LPCSTR lpcszTypeName)
+{
+	if (lpcszTypeName == NULL || strlen(lpcszTypeName) == 0)
+		return RVC_UNKNOWN;
+	MACHINE_ENUM_TYPE(ENUM_MAP_CONVERT)
+
+		if (streq(lpcszTypeName, "RPM.Stand1S") == 0)
+			return RPM_Stand1S;
+
+	return RVC_UNKNOWN;
+}
+
+#undef ENUM_MAP_CONVERT
+#define ENUM_MAP_CONVERT(elem) case RVC_##elem: return "RVC."#elem;
+
+static LPCSTR Type2Str(What what)
+{
+	switch (what) {
+		MACHINE_ENUM_TYPE(ENUM_MAP_CONVERT)
+	default:
+		break;
+	}
+
+	if (what == RPM_Stand1S)
+		return "RPM.Stand1S";
+
+	return "Unkown";
+}
+
+struct TerminalMachineInfo
+{
+	Site site;
+	What type;
+    struct {
+        WORD minor;
+        WORD major;
+    } gen;
+};
+
+inline
+TerminalMachineInfo GetTerminalMachineInfo(CEntityBase* pEntity)
+{
+    CSystemStaticInfo sysInfo;
+	TerminalMachineInfo termInfo;
+	pEntity->GetFunction()->GetSystemStaticInfo(sysInfo);
+	termInfo.site = Str2Site(sysInfo.strSite);
+	termInfo.type = Str2Type(sysInfo.strMachineType);
+	termInfo.gen.major = sysInfo.MachineVersion.GetMajor();
+	termInfo.gen.minor = sysInfo.MachineVersion.GetMinor();
+	return termInfo;
+}
+
+} // comm
+} // mod
+} // sp
+
+
+
+#endif //RVC_MOD_COMM_ENTITY_UTIL_HPP_

+ 22 - 0
Module/include/test/CMakeLists.txt

@@ -0,0 +1,22 @@
+set(MODULE_NAME "TestModuleComm")
+set(MODULE_PREFIX "TEST_MODULE_COMM")
+
+include_directories(${CMAKE_CURRENT_SOURCE_DIR}/..)
+file(GLOB ${MODULE_PREFIX}_TESTS "${CMAKE_CURRENT_SOURCE_DIR}/*.cpp")
+
+conan_cmake_run(REQUIRES Catch/2.13.0@LR04.02_ThirdParty/stable
+			BASIC_SETUP CMAKE_TARGETS
+			BUILD missing)
+
+foreach(test ${${MODULE_PREFIX}_TESTS})
+	get_filename_component(test_name ${test} NAME_WE)
+	add_executable(${test_name} ${test})
+	target_include_directories(${test_name} PRIVATE ${CONAN_INCLUDE_DIRS_CATCH})
+	target_include_directories(${test_name} PRIVATE ${MODULE_BASE_INCLUDES} ${RVC_FRAMEWORK_INCLUDES_DIR})
+	target_link_directories(${test_name} PRIVATE ${RVC_FRAMEWORK_LIBRARIES_DIR})
+	set_property(TARGET ${test_name} PROPERTY FOLDER "test/module")
+	set_target_properties(${test_name} PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${TESTING_OUTPUT_DIRECTORY}")
+	message(STATUS "add test case: ${test_name}...")
+	add_test(NAME ${test_name} COMMAND ${TESTING_OUTPUT_DIRECTORY}/${test_name})
+	set_tests_properties(${teset_name} PROPERTIES FAIL_REGULAR_EXPRESSION "FAILED;ERROR;Failed;error")
+endforeach()

+ 33 - 0
Module/include/test/TestCommEntityUtil.cpp

@@ -0,0 +1,33 @@
+#define CATCH_CONFIG_MAIN
+#include <catch2.hpp>
+#include <cstring>
+#include "CommEntityUtil.hpp"
+
+TEST_CASE("Test get machine type", "[machine]")
+{
+    REQUIRE(SP::Module::Comm::Str2Type("rvc.PAD") == SP::Module::Comm::RVC_PAD);
+    REQUIRE(SP::Module::Comm::Str2Type("RVC.Stand2S") == SP::Module::Comm::RVC_Stand2S);
+    REQUIRE(SP::Module::Comm::Str2Type("rvc.XXXX") == SP::Module::Comm::RVC_UNKNOWN);
+    REQUIRE(SP::Module::Comm::Str2Type("") == SP::Module::Comm::RVC_UNKNOWN);
+    REQUIRE(SP::Module::Comm::Str2Type(NULL) == SP::Module::Comm::RVC_UNKNOWN);
+    REQUIRE(SP::Module::Comm::Str2Type("RPM.Stand1S") == SP::Module::Comm::RPM_Stand1S);
+    REQUIRE(SP::Module::Comm::Str2Type("rpm.Stand1S") == SP::Module::Comm::RPM_Stand1S);
+
+    REQUIRE(std::strcmp(SP::Module::Comm::Type2Str(SP::Module::Comm::RVC_PAD), "RVC.PAD") == 0);
+    REQUIRE(std::strcmp(SP::Module::Comm::Type2Str(SP::Module::Comm::RVC_Desk2S), "RVC.Desk2S") == 0);
+    REQUIRE(std::strcmp(SP::Module::Comm::Type2Str(SP::Module::Comm::RVC_UNKNOWN), "Unkown") == 0);
+}
+
+TEST_CASE("Test get machine site", "[machine]")
+{
+    REQUIRE(SP::Module::Comm::Str2Site("cmb.lib") == SP::Module::Comm::CMB_LIB);
+    REQUIRE(SP::Module::Comm::Str2Site("CMB.SMM") == SP::Module::Comm::CMB_SMM);
+    REQUIRE(SP::Module::Comm::Str2Site("CMB.XXXX") == SP::Module::Comm::CMB_UNKNOWN);
+    REQUIRE(SP::Module::Comm::Str2Site("") == SP::Module::Comm::CMB_UNKNOWN);
+    REQUIRE(SP::Module::Comm::Str2Site(NULL) == SP::Module::Comm::CMB_UNKNOWN);
+
+    REQUIRE(std::strcmp("CMB.SMM", SP::Module::Comm::Site2Str(SP::Module::Comm::CMB_SMM)) == 0);
+    REQUIRE(std::strcmp("CMB.LSS", SP::Module::Comm::Site2Str(SP::Module::Comm::CMB_LSS)) == 0);
+    REQUIRE(std::strcmp("Unkown", SP::Module::Comm::Site2Str(SP::Module::Comm::CMB_UNKNOWN)) == 0);
+}
+

+ 0 - 35
Module/mod_BootManager/CommEntityUtil.hpp

@@ -1,35 +0,0 @@
-#ifndef RVC_MOD_COMM_ENTITY_UTIL_HPP_
-#define RVC_MOD_COMM_ENTITY_UTIL_HPP_
-
-#include "path.h"
-
-namespace SP
-{
-namespace Module
-{
-namespace Comm
-{
-inline
-CSimpleStringA GetCurrMachineType(CEntityBase* pEntity)
-{
-    CSystemStaticInfo sysInfo;
-    pEntity->GetFunction()->GetSystemStaticInfo(sysInfo);
-    return sysInfo.strMachineType;
-}
-
-inline
-CSimpleStringA GetCurrEntityConfigPath(CEntityBase* pEntity)
-{
-    CSimpleStringA strConfigDir(true);
-    pEntity->GetFunction()->GetPath("cfg", strConfigDir);
-    CSimpleStringA result(strConfigDir + SPLIT_SLASH_STR + pEntity->GetEntityName() + ".ini");
-    Dbg("config path: %s", result.GetData());
-    return result;
-}
-} // comm
-} // mod
-} // sp
-
-
-
-#endif //RVC_MOD_COMM_ENTITY_UTIL_HPP_

+ 10 - 0
Module/mod_BootManager/test/TestEntityLoadIniConfig.cpp

@@ -33,3 +33,13 @@ TEST_CASE_ENTITY_CLASS(BootManager, "StartupEntity")
     return result;
 }
 
+TEST_CASE_ENTITY_CLASS(BootManager, "Get terminal machine information")
+{
+    auto info = SP::Module::Comm::GetTerminalMachineInfo(this);
+    REQUIRE(info.site == SP::Module::Comm::CMB_LIB);
+    REQUIRE(info.type == SP::Module::Comm::RVC_Stand2S);
+    REQUIRE(info.gen.major == 2);
+    REQUIRE(info.gen.minor == 0);
+    return Error_Succeed;
+}
+