Browse Source

Z991239-1017 #comment fea 迁移remotecontroller编译通过

陈良瑜80374463 4 years ago
parent
commit
1e499c668f

+ 86 - 0
Module/mod_RomoteController/CMakeLists.txt

@@ -0,0 +1,86 @@
+define_module("RomoteController")
+
+file(GLOB RomoteControl_CPP_SRCS *.cpp)
+file(GLOB RomoteControl_H_SRCS *.h)
+if (MSVC)
+	set(ZIP_SRCS
+	${ThirdPartyHeadRoot}/XZip/XZip.h
+	${ThirdPartyHeadRoot}/XZip/XZip.cpp
+	)
+else()
+	set(ZIP_SRCS
+	../mod_upload/XZipZilb.h
+	../mod_upload/XZipZilb.cpp
+	)
+endif()
+
+MESSAGE( STATUS "RomoteControl_CPP_SRCS = ${RomoteControl_CPP_SRCS}")
+MESSAGE( STATUS "RomoteControl_H_SRCS = ${RomoteControl_H_SRCS}")
+MESSAGE( STATUS "ZIP_SRCS = ${ZIP_SRCS}")
+
+	#need boost
+conan_cmake_run(REQUIRES boost/1.69.0@LR04.02_ThirdParty/testing
+BASIC_SETUP CMAKE_TARGETS
+BUILD missing)
+
+MESSAGE( STATUS "BOOST_ROOT = ${CONAN_BOOST_ROOT}")
+#set(BOOST_ROOT /home/pcacc/Desktop/boost_1_69_0)
+set(BOOST_ROOT ${CONAN_BOOST_ROOT})
+
+set(Boost_DEBUG ON)
+set(Boost_USE_STATIC_LIBS   ON)
+if (MSVC)
+else()
+	set(Boost_NO_SYSTEM_PATHS ON)
+	set(Boost_USE_MULTITHREADED      ON)
+	set(Boost_USE_STATIC_RUNTIME    ON)
+	add_definitions(-DBOOST_ERROR_CODE_HEADER_ONLY)
+endif()
+
+find_package(Boost COMPONENTS atomic chrono date_time filesystem regex system thread REQUIRED)
+
+if(Boost_FOUND)
+	include_directories(${Boost_INCLUDE_DIRS})
+	MESSAGE( STATUS "Boost_INCLUDE_DIRS = ${Boost_INCLUDE_DIRS}")
+	MESSAGE( STATUS "Boost_LIBRARIES = ${Boost_LIBRARIES}")
+	MESSAGE( STATUS "Boost_LIB_VERSION = ${Boost_LIB_VERSION}")
+endif()
+
+#boost end
+
+conan_cmake_run(REQUIRES zlib/1.2.11@LR04.02_ThirdParty/stable
+BASIC_SETUP CMAKE_TARGETS
+BUILD missing)
+
+MESSAGE( STATUS "CONAN_INCLUDE_DIRS_ZLIB = ${CONAN_INCLUDE_DIRS_ZLIB}")
+MESSAGE( STATUS "CONAN_PKG_LIBS_ZLIB = ${CONAN_PKG_LIBS_ZLIB}")
+
+set(${MODULE_PREFIX}_SRCS
+	${RomoteControl_CPP_SRCS}
+	${RomoteControl_H_SRCS}
+	${ThirdPartyHeadRoot}/CJson/cJSON.c
+	${Boost_INCLUDE_DIRS}
+	${ZIP_SRCS}
+	)
+
+set(MOD_VERSION_STRING "0.0.1-dev1")
+add_module_libraries(${MODULE_PREFIX} ${MODULE_NAME} ${MOD_VERSION_STRING})
+
+target_include_directories(${MODULE_NAME} PRIVATE
+	${RVC_FRAMEWORK_INCLUDES_DIR}
+	${CONAN_INCLUDE_DIRS_OPENSSL}
+	${ThirdPartyHeadRoot}/CJson
+	${CONAN_LIB_DIRS_BOOST}
+	${CONAN_INCLUDE_DIRS_ZLIB}
+	${ThirdPartyHeadRoot}/XZip
+)
+
+target_link_directories(${MODULE_NAME} PRIVATE
+	${CONAN_LIB_DIRS_ZLIB}
+)
+
+# 添加实体需要依赖的其他共享库(包括系统库)
+set(${MODULE_PREFIX}_LIBS ${MODULE_BASE_LIBS} ${RVCCOMM_LIB} ${CONAN_PKG_LIBS_ZLIB})
+target_link_libraries(${MODULE_NAME} ${${MODULE_PREFIX}_LIBS} CONAN_PKG::OpenSSL ${Boost_LIBRARIES})
+
+deploy_module(${MODULE_PREFIX} ${MODULE_NAME})

+ 167 - 0
Module/mod_RomoteController/remoteBase.cpp

@@ -0,0 +1,167 @@
+#include "remoteBase.h"
+//ip
+#include <vector>
+#include <string>
+#include <boost/asio.hpp> 
+#include <boost/algorithm/string.hpp>
+#include <boost/lexical_cast.hpp>
+#include <cstdio>
+using boost::asio::ip::tcp;
+
+#include <boost/format.hpp>
+#include <boost/date_time/gregorian/gregorian.hpp>
+
+//ini write
+#include <boost/property_tree/ptree.hpp>
+#include <boost/property_tree/ini_parser.hpp>
+
+
+namespace fs = boost::filesystem;
+
+bool Base_DeleteFile(std::string filePath)
+{
+	
+	if (fs::exists(filePath))
+		return fs::remove(filePath);
+	return false;
+}
+
+bool Base_Exist(std::string filePath)
+{
+	return fs::exists(filePath);
+}
+
+uintmax_t Base_filesize(std::string filePath)
+{
+	return fs::file_size(filePath);
+}
+
+
+std::pair<bool, int> Base_readFile(std::string filePath, uintmax_t start, char* readBuf, int readSize)
+{
+	auto cfgFile = fopen(filePath.c_str(), "r");
+	if (nullptr == cfgFile)
+		return std::make_pair(false, 0);
+	else
+	{
+		if (0 != fseek(cfgFile, start, SEEK_SET))
+			return std::make_pair(false, 0);
+
+		char* pBuf = new char[readSize];
+		memset(pBuf, 0, readSize);
+
+		int nHasRead = fread(readBuf, readSize, 1, cfgFile);
+
+		if (nHasRead <= 0)
+			return std::make_pair(false, 0);
+		delete[] pBuf;
+		fclose(cfgFile);
+		return std::make_pair(true, nHasRead);
+	}
+}
+
+
+bool Base_GetHostIPAddr(BYTE addr[4])
+{
+	boost::asio::io_service io_service;
+	tcp::resolver resolver(io_service);
+	tcp::resolver::query query(boost::asio::ip::host_name(), "");
+	tcp::resolver::iterator iter = resolver.resolve(query);
+	tcp::resolver::iterator end; // End marker. 
+	while (iter != end)
+	{
+		tcp::endpoint ep = *iter++;
+		if (ep.address().is_v4())
+		{
+			auto ipaddr = ep.address().to_string();
+			std::vector<std::string> vec;
+			boost::split(vec, ipaddr, boost::is_any_of("."));
+			if (4 == vec.size())
+			{
+				for (auto i = 0; i < vec.size(); i++)
+				{
+					int it = boost::lexical_cast<int>(vec[i].c_str());
+					addr[i] = it;
+				}
+				return true;
+			}
+		}
+	}
+	return false;
+}
+
+bool Base_CopyFile(std::string src, std::string dst)
+{
+	boost::system::error_code ec;
+	if (fs::exists(src))
+	{
+		fs::copy_file(src, dst, boost::filesystem::copy_option::overwrite_if_exists, ec);
+		if (!ec.failed())
+			return true;
+	}
+	else
+		return false;
+}
+
+//替换所有需要更换日期的地方
+std::string getCurData()
+{
+	boost::gregorian::date d(boost::gregorian::day_clock::local_day());
+	return (boost::format("%.4d%.2d%.2d") % d.year() % d.month().as_number() % d.day()).str();
+}
+
+//统一切换stricmp,Linux和windows部分都切换,因为很多使用了CSimpleString来比较
+bool iequals(const std::string& a, const std::string& b)
+{
+	unsigned int sz = a.size();
+	if (b.size() != sz)
+		return false;
+	for (unsigned int i = 0; i < sz; ++i)
+		if (tolower(a[i]) != tolower(b[i]))
+			return false;
+	return true;
+}
+
+unsigned int get_proc_mem(unsigned int pid) {//获取进程占用内存
+
+	auto VMRSS_LINE = 17;
+	char file_name[64] = { 0 };
+	FILE* fd;
+	char line_buff[512] = { 0 };
+	sprintf(file_name, "/proc/%d/status", pid);
+
+	fd = fopen(file_name, "r");
+	if (nullptr == fd) {
+		return 0;
+	}
+
+	char name[64];
+	int vmrss;
+	for (int i = 0; i < VMRSS_LINE - 1; i++) {
+		fgets(line_buff, sizeof(line_buff), fd);
+	}
+
+	fgets(line_buff, sizeof(line_buff), fd);
+	sscanf(line_buff, "%s %d", name, &vmrss);
+	fclose(fd);
+
+	return vmrss;
+}
+
+std::string getPathName(std::string filePath)
+{
+	return fs::path(filePath).filename().string();
+}
+
+template<typename T>
+void Base_writeIni(std::string section, std::string key, T value, std::string cfgPath)
+{
+	boost::property_tree::ptree lvptProperties;
+	boost::property_tree::ini_parser::read_ini(cfgPath, lvptProperties);
+	boost::property_tree::basic_ptree<std::string, std::string> lvbtItems = lvptProperties.get_child(section);
+
+
+		lvptProperties.add<T>(key, value);
+
+	boost::property_tree::ini_parser::write_ini(cfgPath, lvptProperties);
+}

+ 29 - 0
Module/mod_RomoteController/remoteBase.h

@@ -0,0 +1,29 @@
+#include "SpBase.h"
+#include <string>
+#include <vector>
+#include <boost/filesystem.hpp>
+#include <stdio.h>
+#include <utility>
+
+bool Base_GetHostIPAddr(BYTE addr[4]);
+
+std::string getCurData();
+
+bool Base_DeleteFile(std::string filePath);
+
+bool Base_Exist(std::string filePath);
+
+bool iequals(const std::string& a, const std::string& b);
+
+bool Base_CopyFile(std::string src, std::string dst);
+
+uintmax_t Base_filesize(std::string filePath);
+
+std::pair<bool, int> Base_readFile(std::string filePath, uintmax_t start, char* readBuf, int readSize);
+
+unsigned int get_proc_mem(unsigned int pid);
+
+std::string getPathName(std::string filePath);
+
+template<typename T>
+void Base_writeIni(std::string section, std::string key, T value, std::string cfgPath);