common_api.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  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. bool MergeDevicePath(vector<string>& nodes, string& Devpath);
  50. string GetProcessDirectory();
  51. string GetFileTitle(string& fullpath);
  52. string GetFileName(string& fullpath);
  53. string& makeLowerStr(string& src);
  54. string GetFileDirectory(string& fullpath);
  55. bool FindSubVersionDirs(string rootDir, map<string, vector<string>>& dirlist);
  56. bool FindSortedSubFiles(string rootFile, vector<string>& filelist);
  57. void RawToHex(const char* pRaw, DWORD RawLen, string& Hex);
  58. string ReplaceSubString(string org, string& keystr, string& replacestr);
  59. string ReplaceFileTitle(string FilePath, string NewTitle);
  60. bool FindSubFiles(string rootDir, vector<string>& filelist, bool Recursive = true, string strWildcard = "*");
  61. template <class Type>
  62. bool StrToIntT(const char* str, Type* result)
  63. {
  64. Type value = 0;
  65. Type sign = 1;
  66. Type radix;
  67. if (str == NULL)
  68. {
  69. return false;
  70. }
  71. if (strlen(str) == 0)
  72. {
  73. return false;
  74. }
  75. if (*str == '-')
  76. {
  77. sign = -1;
  78. str++;
  79. }
  80. if (*str == '0' && (*(str + 1) == 'x' || *(str + 1) == 'X'))
  81. {
  82. radix = 16;
  83. str += 2;
  84. }
  85. //else if(*str == '0')
  86. //{
  87. // radix = 8;
  88. // str++;
  89. //}
  90. else
  91. {
  92. bool HitF = false;
  93. size_t Len = strlen(str);
  94. for (size_t i = 0; i < Len; i++)
  95. {
  96. if (str[i] >= '0' && str[i] <= '9')
  97. {
  98. continue;
  99. }
  100. HitF = true;
  101. break;
  102. }
  103. if (HitF)
  104. {
  105. radix = 16;
  106. }
  107. else
  108. {
  109. radix = 10;
  110. }
  111. }
  112. while (*str)
  113. {
  114. if (radix == 16)
  115. {
  116. if (*str >= '0' && *str <= '9')
  117. {
  118. value = value * radix + *str - '0';
  119. }
  120. else
  121. {
  122. if ((*str | 0x20) >= 'a' && (*str | 0x20) <= 'f')
  123. {
  124. value = value * radix + (*str | 0x20) - 'a' + 10;
  125. }
  126. else
  127. {
  128. return false;
  129. }
  130. }
  131. }
  132. else
  133. {
  134. value = value * radix + *str - '0';
  135. }
  136. str++;
  137. }
  138. *result = sign * value;
  139. return true;
  140. };
  141. class common_api {
  142. public:
  143. common_api(void);
  144. virtual ~common_api(void);
  145. pthread_mutex_t m_NotifyMutex;
  146. };
  147. using export_functions = std::tuple<string, DWORD, DWORD>;
  148. std::vector<export_functions> GetDllFunctionInfo(const char* moduleName);