common_api.h 3.8 KB

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