common_api.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. // common_api.h
  2. #pragma once
  3. #include <map>
  4. #include <string>
  5. #include <vector>
  6. #include <cstdint>
  7. #include <sys/types.h>
  8. #include <sys/stat.h>
  9. #include <unistd.h>
  10. #include <dirent.h>
  11. #include <dlfcn.h>
  12. #include <cstring>
  13. #include <ctime>
  14. #include <cstdarg>
  15. #include <algorithm>
  16. using namespace std;
  17. // 定义Linux兼容类型
  18. #ifndef DWORD_DEFINED
  19. #define DWORD_DEFINED
  20. typedef unsigned long DWORD; // 定义DWORD
  21. #endif // 结束条件编译
  22. typedef int64_t __time64_t;
  23. typedef uint64_t UINT64;
  24. typedef unsigned char BYTE;
  25. typedef void* HANDLE;
  26. // 添加 GUID 类型定义(如果未定义)
  27. #ifndef GUID_DEFINED
  28. #define GUID_DEFINED
  29. typedef struct _GUID {
  30. unsigned long Data1;
  31. unsigned short Data2;
  32. unsigned short Data3;
  33. unsigned char Data4[8];
  34. } GUID;
  35. #endif
  36. bool AddEnvPath(const char* pPath);
  37. bool DelEnvPath(const char* pPath);
  38. UINT64 GetDay(UINT64 TheTime);
  39. __time64_t GetCurrentRealTimeOfStk();
  40. int CompareTimeByDay(UINT64 Prev, UINT64 Cur);
  41. bool string_2_guid(const char* pstr, GUID& stGuid);
  42. bool guid_2_string(GUID& stGuid, string& str);
  43. bool SplitString(const char* pString, string args, vector<string>& nodes);
  44. bool SplitTo84422222222String(const char* pString, vector<string>& nodes);
  45. bool CreateFileDirectory(string& FullFilePath);
  46. string FormatstdString(const char* pcFormat, ...);
  47. bool getBusIdFromFilePath(const char* pFilePath, string& BusId);
  48. bool SplitDevicePath(const char* pDevicePath, vector<string>& nodes);
  49. void SplitDeviceList(const char* deviceList, std::vector<std::string>& result);
  50. bool MergeDevicePath(vector<string>& nodes, string& Devpath);
  51. string GetProcessDirectory();
  52. string GetFileTitle(string& fullpath);
  53. string GetFileName(string& fullpath);
  54. string& makeLowerStr(string& src);
  55. string GetFileDirectory(string& fullpath);
  56. bool FindSubVersionDirs(string rootDir, map<string, vector<string>>& dirlist);
  57. bool FindSortedSubFiles(string rootFile, vector<string>& filelist);
  58. void RawToHex(const char* pRaw, DWORD RawLen, string& Hex);
  59. string ReplaceSubString(string org, string& keystr, string& replacestr);
  60. string ReplaceFileTitle(string FilePath, string NewTitle);
  61. bool FindSubFiles(string rootDir, vector<string>& filelist, bool Recursive = true, string strWildcard = "*");
  62. template <class Type>
  63. bool StrToIntT(const char* str, Type* result)
  64. {
  65. Type value = 0;
  66. Type sign = 1;
  67. Type radix;
  68. if (str == NULL)
  69. {
  70. return false;
  71. }
  72. if (strlen(str) == 0)
  73. {
  74. return false;
  75. }
  76. if (*str == '-')
  77. {
  78. sign = -1;
  79. str++;
  80. }
  81. if (*str == '0' && (*(str + 1) == 'x' || *(str + 1) == 'X'))
  82. {
  83. radix = 16;
  84. str += 2;
  85. }
  86. //else if(*str == '0')
  87. //{
  88. // radix = 8;
  89. // str++;
  90. //}
  91. else
  92. {
  93. bool HitF = false;
  94. size_t Len = strlen(str);
  95. for (size_t i = 0; i < Len; i++)
  96. {
  97. if (str[i] >= '0' && str[i] <= '9')
  98. {
  99. continue;
  100. }
  101. HitF = true;
  102. break;
  103. }
  104. if (HitF)
  105. {
  106. radix = 16;
  107. }
  108. else
  109. {
  110. radix = 10;
  111. }
  112. }
  113. while (*str)
  114. {
  115. if (radix == 16)
  116. {
  117. if (*str >= '0' && *str <= '9')
  118. {
  119. value = value * radix + *str - '0';
  120. }
  121. else
  122. {
  123. if ((*str | 0x20) >= 'a' && (*str | 0x20) <= 'f')
  124. {
  125. value = value * radix + (*str | 0x20) - 'a' + 10;
  126. }
  127. else
  128. {
  129. return false;
  130. }
  131. }
  132. }
  133. else
  134. {
  135. value = value * radix + *str - '0';
  136. }
  137. str++;
  138. }
  139. *result = sign * value;
  140. return true;
  141. };
  142. class common_api {
  143. public:
  144. common_api(void);
  145. virtual ~common_api(void);
  146. pthread_mutex_t m_NotifyMutex;
  147. };
  148. using export_functions = std::tuple<string, DWORD, DWORD>;
  149. std::vector<export_functions> GetDllFunctionInfo(const char* moduleName);