utils.h 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. #ifndef HM_UTILS_H
  2. #define HM_UTILS_H
  3. #include <cstdio>
  4. #include <string>
  5. #include <vector>
  6. #include <map>
  7. #define LogM(l, x...) printf("[HmGate|%5s] %16s : ",logLevelName(l),__FUNCTION__),printf(x),printf("\n")
  8. #define Log(l, x...) if (getLogStatus(l)) LogM(l, x)
  9. namespace hm {
  10. enum Level {
  11. Closed, Trace, Info, Warn, Error
  12. };
  13. extern Level gConfLogLevel;
  14. extern std::string gConfFaceRemote, gConfCarRemote, gConfLoginUser, gConfLoginPass;
  15. extern unsigned int gConfSearchGap, gConfSearchDuration, gConfServerPort;
  16. void ReadConfig(const char *path);
  17. const char *logLevelName(const Level &level);
  18. bool getLogStatus(const Level &level);
  19. bool startsWith(const std::string &str, const std::string &start);
  20. bool endsWith(const std::string &str, const std::string &end);
  21. std::string trim(const std::string &str);
  22. bool splitKeyValue(const std::string &src, std::string &key, std::string &value);
  23. std::vector<std::string> getIpList();
  24. int imageRead(const std::string &path, char *&buffer);
  25. int imgcpy(char *&dest, const std::string &src);
  26. void imageSave(const std::string &path, char *&start, const int &size);
  27. void imageSave(const std::string &path, unsigned char *&start, const unsigned int &size);
  28. time_t toTimestamp(
  29. const unsigned int &year, const unsigned int &mon, const unsigned int &day,
  30. const unsigned int &hour, const unsigned int &min, const unsigned int &sec
  31. );
  32. size_t onPostResponse(void *contents, size_t size, size_t nMem, std::string *output);
  33. void dataUpload(
  34. const std::string &url, const std::map<std::string, std::string> &data,
  35. unsigned char *&imgBuf, const unsigned int &bufSize
  36. );
  37. }
  38. #endif //HM_UTILS_H