浏览代码

将common_api提取为单独的库解决common_api修改后库之前不统一的问题

lwk 1 月之前
父节点
当前提交
e2a0503a32
共有 3 个文件被更改,包括 864 次插入0 次删除
  1. 150 0
      common_api/CMakeLists.txt
  2. 531 0
      common_api/common_api.cpp
  3. 183 0
      common_api/common_api.h

+ 150 - 0
common_api/CMakeLists.txt

@@ -0,0 +1,150 @@
+cmake_minimum_required(VERSION 3.12)
+project(common_api VERSION 1.0.0 LANGUAGES CXX)
+
+# === 基础配置 ===
+set(CMAKE_CXX_STANDARD 17)
+set(CMAKE_CXX_STANDARD_REQUIRED ON)
+set(CMAKE_CXX_EXTENSIONS OFF)
+set(CMAKE_POSITION_INDEPENDENT_CODE ON)
+
+# 添加编译选项: -g 生成调试信息, -fPIC 位置无关代码
+add_compile_options(-g -fPIC)
+
+# 添加地址 sanitizer 选项(用于检测内存错误)
+# 仅在 Debug 模式下启用,避免影响 Release 性能
+set(SANITIZE_OPTIONS -fsanitize=address)
+add_compile_options($<$<CONFIG:Debug>:${SANITIZE_OPTIONS}>)
+link_libraries($<$<CONFIG:Debug>:${SANITIZE_OPTIONS}>)
+
+# === 输出目录配置 ===
+set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
+set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
+set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
+
+# === 路径配置 ===
+set(SRC_DIR ${CMAKE_CURRENT_SOURCE_DIR})
+set(INCLUDE_DIR ${SRC_DIR})
+
+# 配置ResDataObject相关路径(明确指定位置)
+set(RES_DATA_INCLUDE_DIR "${CMAKE_BINARY_DIR}/../../Deliver/include")
+set(RES_DATA_LIB_DIR "${CMAKE_BINARY_DIR}/../../Deliver/lib")  # 明确设置ResDataObject库所在目录
+get_filename_component(RES_DATA_INCLUDE_DIR ${RES_DATA_INCLUDE_DIR} ABSOLUTE)
+get_filename_component(RES_DATA_LIB_DIR ${RES_DATA_LIB_DIR} ABSOLUTE)
+message(STATUS "ResDataObject 头文件目录: ${RES_DATA_INCLUDE_DIR}")
+message(STATUS "ResDataObject 库文件目录: ${RES_DATA_LIB_DIR}")
+
+set(DELIVER_DIR "${CMAKE_BINARY_DIR}/../../Deliver" CACHE PATH "交付目录路径")
+get_filename_component(DELIVER_DIR ${DELIVER_DIR} ABSOLUTE)
+message(STATUS "交付目录: ${DELIVER_DIR}")
+
+# === 源文件与头文件 ===
+set(SRC_FILES
+    ${SRC_DIR}/common_api.cpp
+)
+
+set(HEADER_FILES
+    ${INCLUDE_DIR}/common_api.h
+)
+
+# 验证头文件是否存在
+foreach(header ${HEADER_FILES})
+    if(NOT EXISTS ${header})
+        message(FATAL_ERROR "头文件不存在: ${header}")
+    endif()
+endforeach()
+
+# 验证ResDataObject相关文件是否存在
+if(NOT EXISTS "${RES_DATA_INCLUDE_DIR}/ResDataObject.h")
+    message(FATAL_ERROR "ResDataObject.h 不存在于 ${RES_DATA_INCLUDE_DIR}")
+endif()
+
+# 查找ResDataObject库(精确匹配指定目录)
+find_library(RES_DATA_LIB
+    NAMES ResDataObject libResDataObject  # 同时检查带lib前缀和不带前缀的库名
+    PATHS ${RES_DATA_LIB_DIR}
+    NO_DEFAULT_PATH  # 只在指定目录查找,不搜索系统默认路径
+)
+
+if(NOT RES_DATA_LIB)
+    # 找不到库时列出目录内容帮助调试
+    message(FATAL_ERROR "找不到ResDataObject库,路径: ${RES_DATA_LIB_DIR}\n目录内容: $(ls ${RES_DATA_LIB_DIR})")
+else()
+    message(STATUS "找到ResDataObject库: ${RES_DATA_LIB}")
+endif()
+
+# === 构建共享库 ===
+add_library(common_api SHARED ${SRC_FILES} ${HEADER_FILES})
+
+# === 目标属性配置 ===
+set_target_properties(common_api PROPERTIES
+    VERSION ${PROJECT_VERSION}
+    SOVERSION 1
+    OUTPUT_NAME "common_api"
+    PUBLIC_HEADER "${HEADER_FILES}"
+)
+
+# === 编译选项 ===
+if(CMAKE_CXX_COMPILER_ID MATCHES "GNU")
+    target_compile_options(common_api PRIVATE -Wall -Wextra -Wpedantic -Werror=return-type)
+elseif(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
+    target_compile_options(common_api PRIVATE -Wall -Wextra -Wpedantic -Werror=return-type)
+endif()
+
+# === 依赖配置 ===
+target_include_directories(common_api
+    PUBLIC
+        $<BUILD_INTERFACE:${INCLUDE_DIR}>
+        $<BUILD_INTERFACE:${RES_DATA_INCLUDE_DIR}>
+        $<INSTALL_INTERFACE:include>
+)
+
+# 链接ResDataObject库和系统库
+target_link_libraries(common_api
+    PUBLIC
+        ${RES_DATA_LIB}  # 链接ResDataObject库
+    PRIVATE
+        pthread
+        dl
+)
+
+# === 交付与安装 ===
+file(MAKE_DIRECTORY
+    ${DELIVER_DIR}/lib
+    ${DELIVER_DIR}/include
+)
+
+add_custom_command(TARGET common_api POST_BUILD
+    COMMENT "复制构建产物到交付目录: ${DELIVER_DIR}"
+    COMMAND ${CMAKE_COMMAND} -E copy_if_different
+        $<TARGET_FILE:common_api>
+        ${DELIVER_DIR}/lib/
+    COMMAND ${CMAKE_COMMAND} -E copy_if_different
+        $<TARGET_LINKER_FILE:common_api>
+        ${DELIVER_DIR}/lib/
+    COMMAND ${CMAKE_COMMAND} -E copy_if_different
+        $<TARGET_SONAME_FILE:common_api>
+        ${DELIVER_DIR}/lib/
+    COMMAND ${CMAKE_COMMAND} -E copy_if_different
+        ${HEADER_FILES}
+        ${DELIVER_DIR}/include/
+)
+
+# 安装配置
+install(TARGETS common_api
+    EXPORT common_apiTargets
+    LIBRARY DESTINATION lib
+    ARCHIVE DESTINATION lib
+    PUBLIC_HEADER DESTINATION include
+)
+
+install(EXPORT common_apiTargets
+    FILE common_apiConfig.cmake
+    DESTINATION lib/cmake/common_api
+    EXPORT_LINK_INTERFACE_LIBRARIES
+)
+
+# === 调试辅助 ===
+message(STATUS "common_api 源文件: ${SRC_FILES}")
+message(STATUS "common_api 头文件: ${HEADER_FILES}")
+message(STATUS "common_api 链接库: ${RES_DATA_LIB} pthread dl")
+    

+ 531 - 0
common_api/common_api.cpp

@@ -0,0 +1,531 @@
+// common_api.cpp
+#include <time.h>
+#include <sys/time.h>
+#include <pthread.h>
+#include <dlfcn.h>
+#include <unistd.h>
+#include <limits.h>
+#include "common_api.h"
+#include <iostream>
+
+// 全局互斥锁初始化
+common_api::common_api(void) {
+    pthread_mutex_init(&m_NotifyMutex, NULL);
+}
+
+common_api::~common_api(void) {
+    pthread_mutex_destroy(&m_NotifyMutex);
+}
+
+common_api g_common1_for_init;
+
+//=== 时间相关函数 ===//
+__time64_t GetCurrentRealTimeOfStk() {
+    return time(NULL);
+}
+
+UINT64 GetDay(UINT64 TheTime) {
+    struct tm tCur;
+    gmtime_r((time_t*)&TheTime, &tCur);
+    tCur.tm_sec = 0;
+    tCur.tm_min = 0;
+    tCur.tm_hour = 0;
+    return mktime(&tCur);
+}
+
+int CompareTimeByDay(UINT64 Prev, UINT64 Cur) {
+    return (Cur / (24 * 3600)) - (Prev / (24 * 3600));
+}
+
+//=== GUID转换 ===//
+bool string_2_guid(const char* pstr, GUID& stGuid) {
+    return sscanf(pstr, "{%8lx-%4hx-%4hx-%2hhx%2hhx-%2hhx%2hhx%2hhx%2hhx%2hhx%2hhx}",
+        &stGuid.Data1, &stGuid.Data2, &stGuid.Data3,
+        &stGuid.Data4[0], &stGuid.Data4[1], &stGuid.Data4[2], &stGuid.Data4[3],
+        &stGuid.Data4[4], &stGuid.Data4[5], &stGuid.Data4[6], &stGuid.Data4[7]) == 11;
+}
+
+bool guid_2_string(GUID& stGuid, string& str) {
+    char szBuff[128];
+    snprintf(szBuff, sizeof(szBuff), "{%08lX-%04X-%04X-%02X%02X-%02X%02X%02X%02X%02X%02X}",
+        stGuid.Data1, stGuid.Data2, stGuid.Data3,
+        stGuid.Data4[0], stGuid.Data4[1], stGuid.Data4[2], stGuid.Data4[3],
+        stGuid.Data4[4], stGuid.Data4[5], stGuid.Data4[6], stGuid.Data4[7]);
+    str = szBuff;
+    return true;
+}
+
+const char* secure_getenv_n(const char* name)
+{
+    static char buffer[4096];
+    if (name == nullptr) return nullptr;
+
+    // 使用文件流读取/proc/self/environ
+    FILE* f = fopen("/proc/self/environ", "r");
+    if (!f) return nullptr;
+
+    size_t name_len = strlen(name);
+    while (fgets(buffer, sizeof(buffer), f)) {
+        if (strncmp(buffer, name, name_len) == 0 && buffer[name_len] == '=') {
+            fclose(f);
+            return buffer + name_len + 1;
+        }
+    }
+
+    fclose(f);
+    return nullptr;
+}
+
+//=== 环境变量操作 ===//
+bool AddEnvPath(const char* pPath) {
+    UNUSED(pPath);
+    //// 1. 输入验证
+    //if (!pPath || *pPath == '\0') {
+    //    std::cerr << "AddEnvPath: Invalid path" << std::endl;
+    //    return false;
+    //}
+
+    //// 2. 获取绝对路径
+    //char absPath[PATH_MAX];
+    //if (realpath(pPath, absPath) == nullptr) {
+    //    // 如果路径不存在,仍然使用原始路径(但警告)
+    //    std::cerr << "AddEnvPath: Warning - Path may not exist: " << pPath
+    //        << " (" << strerror(errno) << ")" << std::endl;
+    //    strncpy(absPath, pPath, PATH_MAX - 1);
+    //    absPath[PATH_MAX - 1] = '\0';
+    //}
+
+    //// 3. 获取当前环境变量值
+    //const char* currentEnv = getenv("LD_LIBRARY_PATH");
+    //std::vector<std::string> pathList;
+
+    //// 4. 解析现有路径并去重
+    //if (currentEnv && *currentEnv != '\0') {
+    //    std::istringstream iss(currentEnv);
+    //    std::string item;
+
+    //    while (std::getline(iss, item, ':')) {
+    //        if (!item.empty()) {
+    //            // 标准化现有路径
+    //            char resolved[PATH_MAX];
+    //            if (realpath(item.c_str(), resolved)) {
+    //                // 去重检查
+    //                if (strcmp(resolved, absPath) != 0) {
+    //                    pathList.push_back(resolved);
+    //                }
+    //            }
+    //            else {
+    //                // 无法解析的路径保留原样
+    //                pathList.push_back(item);
+    //            }
+    //        }
+    //    }
+    //}
+
+    //// 5. 添加新路径到最前面(优先搜索)
+    //pathList.insert(pathList.begin(), absPath);
+
+    //// 6. 构建新环境变量字符串
+    //std::ostringstream newEnvStream;
+    //for (size_t i = 0; i < pathList.size(); ++i) {
+    //    if (i > 0) newEnvStream << ':';
+    //    newEnvStream << pathList[i];
+    //}
+    //std::string newEnv = newEnvStream.str();
+
+    //// 7. 更新环境变量
+    //if (setenv("LD_LIBRARY_PATH", newEnv.c_str(), 1) != 0) {
+    //    std::cerr << "AddEnvPath: Failed to set LD_LIBRARY_PATH ("
+    //        << strerror(errno) << ")" << std::endl;
+    //    return false;
+    //}
+
+    //// 8. 验证设置
+    //const char* verify = getenv("LD_LIBRARY_PATH");
+    //if (verify && std::string(verify).find(absPath) != std::string::npos) {
+    //    std::cout << "AddEnvPath: Successfully updated LD_LIBRARY_PATH to: "
+    //        << newEnv << std::endl;
+    //    return true;
+    //}
+    //else {
+    //    std::cerr << "AddEnvPath: Verification failed - path not found in LD_LIBRARY_PATH"
+    //        << std::endl;
+    //    return false;
+    //}
+    return true;
+}
+
+bool DelEnvPath(const char* pPath) {
+    UNUSED(pPath);
+    return false; 
+}
+
+static bool SplitStringSub(string& Path, char key, vector<string>& nodes) {
+    string node;
+
+    string::size_type firstHit = Path.find_first_of(key);
+    if (firstHit == string::npos) {
+        if (Path.size() > 0) {
+            nodes.push_back(Path);
+        }
+        return true;
+    }
+
+    if (firstHit > 0) {
+        node = Path.substr(0, firstHit);
+        if (node.size() > 0) {
+            nodes.push_back(node);
+        }
+    }
+
+    while (firstHit < Path.size()) {
+        firstHit += 1;
+        if (firstHit >= Path.size()) break;
+
+        string::size_type SecondHit = Path.find_first_of(key, firstHit);
+        if (SecondHit == string::npos) {
+            node = Path.substr(firstHit, Path.size() - firstHit);
+            if (node.size() > 0) {
+                nodes.push_back(node);
+            }
+            break;
+        }
+
+        node = Path.substr(firstHit, SecondHit - firstHit);
+        if (node.size() > 0) {
+            nodes.push_back(node);
+        }
+        firstHit = SecondHit;
+    }
+
+    return (nodes.size() > 0);
+}
+
+//=== 字符串处理 ===//
+bool SplitString(const char* pString, string args, vector<string>& nodes) {
+    vector<string> req;
+    vector<string> res;
+    req.push_back(string(pString));
+
+    for (size_t i = 0; i < args.size(); i++)
+    {
+        //cut all req by key
+        for (size_t j = 0; j < req.size(); j++)
+        {
+            SplitStringSub(req[j], args[i], res);
+        }
+        //clear and reset
+        req.clear();
+        req = res;
+        res.clear();
+    }
+
+    nodes = req;
+
+    return true;
+}
+
+bool SplitTo84422222222String(const char* pString, vector<string>& nodes) {
+    string total;
+    vector<string> thelist;
+    SplitString(pString, string("{}-"), thelist);
+    for (size_t i = 0; i < thelist.size(); i++)
+    {
+        total += thelist[i];
+    }
+
+    if (total.size() != 32)
+    {
+        return false;
+    }
+
+    string temp;
+
+    temp = total.substr(0, 8);//8
+    nodes.push_back(temp);
+    temp = total.substr(8, 4);//4
+    nodes.push_back(temp);
+    temp = total.substr(12, 4);//4
+    nodes.push_back(temp);
+    temp = total.substr(16, 2);//2
+    nodes.push_back(temp);
+    temp = total.substr(18, 2);//2
+    nodes.push_back(temp);
+    temp = total.substr(20, 2);//2
+    nodes.push_back(temp);
+    temp = total.substr(22, 2);//2
+    nodes.push_back(temp);
+    temp = total.substr(24, 2);//2
+    nodes.push_back(temp);
+    temp = total.substr(26, 2);//2
+    nodes.push_back(temp);
+    temp = total.substr(28, 2);//2
+    nodes.push_back(temp);
+    temp = total.substr(30, 2);//2
+    nodes.push_back(temp);
+    return true;
+}
+
+string FormatstdString(const char* fmt, ...) {
+    va_list args;
+    va_start(args, fmt);
+    char buffer[1024];
+    vsnprintf(buffer, sizeof(buffer), fmt, args);
+    va_end(args);
+    return string(buffer);
+}
+
+bool getBusIdFromFilePath(const char* pFilePath, string& BusId)
+{
+    string Path = pFilePath;
+
+    size_t firstHit = Path.find_first_of('/');
+    if (firstHit == string::npos || firstHit != 0)
+    {
+        return false;
+    }
+
+    size_t SecondHit = Path.find_first_of('/', 1);
+    if (SecondHit == string::npos)
+    {
+        BusId = Path.substr(1, Path.size() - 1);
+    }
+    else
+    {
+        BusId = Path.substr(1, SecondHit - 1);
+    }
+
+    if (BusId.size() == 0)
+    {
+        return false;
+    }
+
+    return true;
+}
+
+bool SplitDevicePath(const char* pDevicePath, vector<string>& nodes)
+{
+    string node;
+    string Path = pDevicePath;
+
+    nodes.clear();
+
+    string::size_type firstHit = Path.find_first_of('/');
+    if (firstHit == string::npos || firstHit != 0)
+    {
+        return false;
+    }
+
+
+    while (firstHit < Path.size())
+    {
+        firstHit += 1;
+        string::size_type SecondHit = Path.find_first_of('/', firstHit);
+        if (SecondHit == string::npos)
+        {
+            node = Path.substr(firstHit, Path.size() - firstHit);
+            if (node.size() > 0)
+            {
+                nodes.push_back(node);
+            }
+            return true;
+        }
+        node = Path.substr(firstHit, SecondHit - (firstHit));
+        if (node.size() > 0)
+        {
+            nodes.push_back(node);
+        }
+        firstHit = SecondHit;
+
+    }
+
+    return (nodes.size() > 0);
+}
+
+void SplitDeviceList(const char* deviceList, std::vector<std::string>& result)
+{
+    result.clear();
+
+    // 处理空输入情况
+    if (deviceList == nullptr || *deviceList == '\0') return;
+
+    // 创建可修改副本(strtok会破坏原字符串)
+    char* buffer = new char[strlen(deviceList) + 1];
+    strcpy(buffer, deviceList);
+
+    // 使用strtok分割字符串
+    const char* delimiter = ";";
+    char* token = strtok(buffer, delimiter);
+
+    while (token != nullptr) {
+        // 过滤空字符串(避免连续分号产生空项)
+        if (strlen(token) > 0) {
+            result.push_back(token);
+        }
+        token = strtok(nullptr, delimiter);
+    }
+
+    delete[] buffer;  // 释放临时内存
+}
+
+//=== 文件路径操作 ===//
+std::string GetProcessDirectory() {
+    char path[PATH_MAX];
+    ssize_t len = readlink("/proc/self/exe", path, sizeof(path) - 1);
+
+    if (len == -1) {
+        std::cerr << "[ERROR] GetProcessDirectory failed to read /proc/self/exe" << std::endl;
+        return "";
+    }
+
+    // 确保字符串正确终止
+    path[len] = '\0';
+
+    // 现在可以安全地打印
+    std::cout << "[DEBUG] GetProcessDirectory() len: " << len << " path: " << path << std::endl;
+
+    // 找到最后一个斜杠并截断路径
+    char* last_slash = strrchr(path, '/');
+    if (last_slash) {
+        *last_slash = '\0';
+    }
+    else {
+        std::cerr << "[WARNING] GetProcessDirectory: No directory separator found" << std::endl;
+    }
+
+    // 返回一个新的字符串副本,而不是局部数组的指针
+    return std::string(path);
+}
+
+string GetFileDirectory(string& fullpath) {
+    size_t pos = fullpath.find_last_of('/');
+    return (pos != string::npos) ? fullpath.substr(0, pos) : "";
+}
+
+bool FindSubVersionDirs(string rootDir, map<string, vector<string>>& dirlist)
+{
+    UNUSED(rootDir);
+    UNUSED(dirlist);
+    return false;
+}
+
+string GetFileName(string& fullpath) {
+    size_t pos = fullpath.find_last_of('/');
+    return (pos != string::npos) ? fullpath.substr(pos + 1) : fullpath;
+}
+
+string GetFileTitle(string& fullpath) {
+    string filename = GetFileName(fullpath);
+    size_t dot = filename.find_last_of('.');
+    return (dot != string::npos) ? filename.substr(0, dot) : filename;
+}
+
+bool CreateFileDirectory(string& FullFilePath) {
+    string dir = GetFileDirectory(FullFilePath);
+    if (dir.empty()) return false;
+
+    string command = "mkdir -p " + dir;
+    return system(command.c_str()) == 0;
+}
+
+//=== 文件系统遍历 ===//
+bool FindSubFiles(string rootDir, vector<string>& filelist, bool Recursive, string strWildcard) {
+    DIR* dir = opendir(rootDir.c_str());
+    if (!dir) return false;
+
+    struct dirent* entry;
+    while ((entry = readdir(dir)) != nullptr) {
+        string name = entry->d_name;
+        if (name == "." || name == "..") continue;
+
+        string fullpath = rootDir + "/" + name;
+
+        if (entry->d_type == DT_DIR && Recursive) {
+            FindSubFiles(fullpath, filelist, Recursive, strWildcard);
+        }
+        else if (entry->d_type == DT_REG) {
+            filelist.push_back(fullpath);
+        }
+    }
+    closedir(dir);
+    return !filelist.empty();
+}
+
+//=== 其他辅助函数 ===//
+void RawToHex(const char* pRaw, DWORD RawLen, string& Hex) {
+    Hex.reserve(RawLen * 3);
+    for (DWORD i = 0; i < RawLen; i++) {
+        char buf[4];
+        snprintf(buf, sizeof(buf), "%02X ", pRaw[i] & 0xFF);
+        Hex.append(buf);
+    }
+}
+
+string ReplaceSubString(string org, string& keystr, string& replacestr) {
+    size_t pos = 0;
+    while ((pos = org.find(keystr, pos)) != string::npos) {
+        org.replace(pos, keystr.length(), replacestr);
+        pos += replacestr.length();
+    }
+    return org;
+}
+
+//=== 动态库函数信息 ===//
+std::vector<export_functions> GetDllFunctionInfo(const char* moduleName) {
+    void* handle = dlopen(moduleName, RTLD_LAZY);
+    if (!handle) return {};
+
+    // 获取动态库信息
+    Dl_info info;
+    if (dladdr(handle, &info) == 0) {
+        dlclose(handle);
+        return {};
+    }
+
+    // 简化实现:仅获取动态库路径
+    std::vector<export_functions> result;
+    result.push_back(make_tuple(info.dli_fname, 0, 0));
+    dlclose(handle);
+    return result;
+}
+
+void TransferModuleJosnConfig2DriverConfig(ResDataObject& config)
+{
+    for (size_t x = 0; x < config.size(); x++)
+    {
+        if (config[x].GetKeyCount("Value") > 0)
+        {
+            if (config[x]["Value"].size() <= 0)
+            {
+                string va = (const char*)config[x]["Value"];
+                config[x] = va.c_str();
+            }
+            else
+            {
+                ResDataObject rest = config[x]["Value"];
+                config[x] = rest;
+            }
+        }
+    }
+}
+// 将time_t类型时间转换为"YYYY-MM-DD HH:MM:SS"格式的字符串
+std::string DatetimeToString(time_t timeVal)
+{
+    // 将time_t转换为本地时间的tm结构体
+    struct tm* localTime = localtime(&timeVal);
+    if (localTime == nullptr)
+    {
+        // 处理转换失败的情况,返回空字符串或错误标识
+        return "";
+    }
+    
+    // 缓冲区,足够容纳格式化后的时间字符串(包含终止符)
+    char timeStr[32] = {0};
+    
+    // 格式化时间字符串:年-月-日 时:分:秒
+    // %Y:四位年份,%m:两位月份,%d:两位日期
+    // %H:24小时制小时,%M:分钟,%S:秒
+    strftime(timeStr, sizeof(timeStr), "%Y-%m-%d %H:%M:%S", localTime);
+    
+    return std::string(timeStr);
+}

+ 183 - 0
common_api/common_api.h

@@ -0,0 +1,183 @@
+// common_api.h
+#pragma once
+#include <map>
+#include <string>
+#include <vector>
+#include <cstdint>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <unistd.h>
+#include <dirent.h>
+#include <dlfcn.h>
+#include <cstring>
+#include <ctime>
+#include <cstdarg>
+#include <algorithm>
+#include "ResDataObject.h"
+
+using namespace std;
+
+// 定义Linux兼容类型
+#ifndef DWORD_DEFINED 
+#define DWORD_DEFINED 
+
+typedef unsigned long DWORD;  // 定义DWORD
+
+#endif  // 结束条件编译
+#define UNUSED(x) (void)(x)
+extern string LogHost;
+extern string TOPIC_PREFIX;
+extern std::string DEVICE_ID;
+
+typedef int64_t __time64_t;
+typedef uint64_t UINT64;
+typedef unsigned char BYTE;
+typedef void* HANDLE;
+
+// 添加 GUID 类型定义(如果未定义)
+#ifndef GUID_DEFINED
+#define GUID_DEFINED
+typedef struct _GUID {
+    unsigned long  Data1;
+    unsigned short Data2;
+    unsigned short Data3;
+    unsigned char  Data4[8];
+} GUID;
+#endif
+const char* secure_getenv_n(const char* name);
+bool AddEnvPath(const char* pPath);
+bool DelEnvPath(const char* pPath);
+
+UINT64 GetDay(UINT64 TheTime);
+__time64_t GetCurrentRealTimeOfStk();
+int CompareTimeByDay(UINT64 Prev, UINT64 Cur);
+
+bool string_2_guid(const char* pstr, GUID& stGuid);
+bool guid_2_string(GUID& stGuid, string& str);
+
+bool SplitString(const char* pString, string args, vector<string>& nodes);
+bool SplitTo84422222222String(const char* pString, vector<string>& nodes);
+
+bool CreateFileDirectory(string& FullFilePath);
+string FormatstdString(const char* pcFormat, ...);
+
+bool getBusIdFromFilePath(const char* pFilePath, string& BusId);
+bool SplitDevicePath(const char* pDevicePath, vector<string>& nodes);
+void SplitDeviceList(const char* deviceList, std::vector<std::string>& result);
+bool MergeDevicePath(vector<string>& nodes, string& Devpath);
+
+string GetProcessDirectory();
+string GetFileTitle(string& fullpath);
+string GetFileName(string& fullpath);
+string& makeLowerStr(string& src);
+string GetFileDirectory(string& fullpath);
+
+bool FindSubVersionDirs(string rootDir, map<string, vector<string>>& dirlist);
+bool FindSortedSubFiles(string rootFile, vector<string>& filelist);
+
+void RawToHex(const char* pRaw, DWORD RawLen, string& Hex);
+string ReplaceSubString(string org, string& keystr, string& replacestr);
+string ReplaceFileTitle(string FilePath, string NewTitle);
+bool FindSubFiles(string rootDir, vector<string>& filelist, bool Recursive = true, string strWildcard = "*");
+void TransferModuleJosnConfig2DriverConfig(ResDataObject& config);
+std::string DatetimeToString(time_t timeVal);
+
+template <class Type>
+bool StrToIntT(const char* str, Type* result) 
+{
+	Type value = 0;
+	Type sign = 1;
+	Type radix;
+	if (str == NULL)
+	{
+		return false;
+	}
+
+	if (strlen(str) == 0)
+	{
+		return false;
+	}
+
+	if (*str == '-')
+	{
+		sign = -1;
+		str++;
+	}
+
+	if (*str == '0' && (*(str + 1) == 'x' || *(str + 1) == 'X'))
+	{
+		radix = 16;
+		str += 2;
+	}
+	//else if(*str == '0')
+	//{      
+	//	radix = 8;      
+	//	str++;   
+	//}  
+	else
+	{
+		bool HitF = false;
+		size_t Len = strlen(str);
+		for (size_t i = 0; i < Len; i++)
+		{
+			if (str[i] >= '0' && str[i] <= '9')
+			{
+				continue;
+			}
+
+			HitF = true;
+			break;
+		}
+
+		if (HitF)
+		{
+			radix = 16;
+		}
+		else
+		{
+			radix = 10;
+		}
+
+	}
+	while (*str)
+	{
+		if (radix == 16)
+		{
+			if (*str >= '0' && *str <= '9')
+			{
+				value = value * radix + *str - '0';
+			}
+			else
+			{
+				if ((*str | 0x20) >= 'a' && (*str | 0x20) <= 'f')
+				{
+					value = value * radix + (*str | 0x20) - 'a' + 10;
+				}
+				else
+				{
+					return false;
+				}
+			}
+
+		}
+		else
+		{
+			value = value * radix + *str - '0';
+		}
+		str++;
+	}
+
+	*result = sign * value;
+
+	return true;
+};
+
+class common_api {
+public:
+    common_api(void);
+    virtual ~common_api(void);
+    pthread_mutex_t m_NotifyMutex;
+};
+
+using export_functions = std::tuple<string, DWORD, DWORD>;
+std::vector<export_functions> GetDllFunctionInfo(const char* moduleName);