123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174 |
- // 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>
- using namespace std;
- // 定义Linux兼容类型
- #ifndef DWORD_DEFINED
- #define DWORD_DEFINED
- typedef unsigned long DWORD; // 定义DWORD
- #endif // 结束条件编译
- 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
- 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);
- 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 = "*");
- 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);
|