From 79b1b57045e86d9845e352c3f2aa0efbab6111a9 Mon Sep 17 00:00:00 2001
From: gcontini <1121667+gcontini@users.noreply.github.com>
Date: 周六, 14 3月 2020 10:19:09 +0800
Subject: [PATCH] tests and improvements

---
 src/library/os/linux/execution_environment.cpp |   44 +++++++++++++++++++++++++++-----------------
 1 files changed, 27 insertions(+), 17 deletions(-)

diff --git a/src/library/os/linux/execution_environment.cpp b/src/library/os/linux/execution_environment.cpp
index 9744e27..1f14d62 100644
--- a/src/library/os/linux/execution_environment.cpp
+++ b/src/library/os/linux/execution_environment.cpp
@@ -17,8 +17,11 @@
 #include "../../base/base.h"
 #include "../cpu_info.hpp"
 #include "../execution_environment.hpp"
+#include "../../base/file_utils.hpp"
+#include "../../base/StringUtils.h"
 
 namespace license {
+namespace os {
 using namespace std;
 
 // 0=NO 1=Docker/2=Lxc
@@ -80,26 +83,33 @@
 	return result;
 }
 
-VIRTUALIZATION ExecutionEnvironment::getVirtualization() {
-	VIRTUALIZATION result;
-	CpuInfo cpuInfo;
-	bool isContainer = checkContainerProc() != 0 || checkSystemdContainer() != 0;
-	if (isContainer) {
-		result = CONTAINER;
-	} else if (cpuInfo.cpu_virtual() || is_cloud()) {
-		result = VM;
-	} else {
-		result = NONE;
+ExecutionEnvironment::ExecutionEnvironment() {
+	try {
+		m_bios_vendor = toupper_copy(trim_copy(get_file_contents("/sys/class/dmi/id/sys_vendor", 256)));
+
+	} catch (...) {
 	}
-	return result;
+	try {
+		m_bios_description = toupper_copy(trim_copy(get_file_contents("/sys/class/dmi/id/modalias", 256)));
+		char last_char = m_bios_description[m_bios_description.length() - 1];
+		if (last_char == '\r' || last_char == '\n') {
+			m_bios_description = m_bios_description.erase(m_bios_description.length() - 1);
+		}
+	} catch (...) {
+	}
+	try {
+		m_sys_vendor = get_file_contents("/sys/class/dmi/id/sys_vendor", 256);
+		char last_char = m_sys_vendor[m_sys_vendor.length() - 2];
+		if (last_char == '\r' || last_char == '\n') {
+			m_sys_vendor = m_sys_vendor.erase(m_sys_vendor.length() - 1);
+		}
+	} catch (...) {
+	}
 }
 
-bool ExecutionEnvironment::is_cloud() { return getCloudProvider() == NONE; }
+bool ExecutionEnvironment::is_container() const { return (checkContainerProc() != 0 || checkSystemdContainer() != 0); }
 
-bool ExecutionEnvironment::is_docker() { return (checkContainerProc() == 1 || checkSystemdContainer() == 1); }
+bool ExecutionEnvironment::is_docker() const { return (checkContainerProc() == 1 || checkSystemdContainer() == 1); }
 
-CLOUD_PROVIDER ExecutionEnvironment::getCloudProvider() {
-	// TODO
-}
-
+}  // namespace os
 }  // namespace license

--
Gitblit v1.9.1