device.h 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. #ifndef HM_DEVICE_H
  2. #define HM_DEVICE_H
  3. #include <string>
  4. #include <mutex>
  5. #include <memory>
  6. #include "items.h"
  7. #include "dhnetsdk.h"
  8. namespace hm {
  9. class Device {
  10. private:
  11. std::mutex uMtx, cwMtx, cbMtx;
  12. bool inited, running;
  13. int port, reset;
  14. std::string mac, ip, local;
  15. std::vector<User> faceUserList;
  16. std::vector<Plate> carWhiteList, carBlackList;
  17. void init();
  18. bool login();
  19. void logout();
  20. bool subscribe();
  21. void unsubscribe();
  22. void varUserInsert(const User &user);
  23. void varUserDelete(const std::string &uid);
  24. bool varUserExists(const std::string &uid);
  25. bool addUserFace(const std::string &uid, const std::string &face, std::string &msg);
  26. bool removeUserOnly(const std::string &uid, std::string &msg);
  27. bool removeUserFace(const std::string &uid, std::string &msg);
  28. void varCarWoBInsert(const bool &isBlack, const Plate &plate);
  29. void varCarWoBDelete(const bool &isBlack, const int &cid);
  30. bool varCarWoBExists(const bool &isBlack, const int &cid);
  31. bool varCarWoBExists(const bool &isBlack, const std::string &plate);
  32. bool insertOneCarWoBList(const bool &isBlack, Plate &plateInfo, std::string &msg);
  33. bool removeOneCarWoBList(const bool &isBlack, const int &cid, std::string &msg);
  34. Plate *getPlateByCNo(const std::string &cno);
  35. public:
  36. LLONG loginId, subId;
  37. bool online, isFaceDevice;
  38. std::string seq;
  39. explicit Device(DEVICE_NET_INFO_EX2 *info);
  40. Device(const Device &) = delete;
  41. Device(Device &&) = delete;
  42. ~Device();
  43. void queryFaceUsers();
  44. void queryCarWoBList(const bool &isBlack);
  45. void Start();
  46. void onAccessCtlEvent(DEV_EVENT_ACCESS_CTL_INFO *info, BYTE *imgBuf, DWORD bufSize);
  47. void onTrafficJunctionEvent(DEV_EVENT_TRAFFICJUNCTION_INFO *info, BYTE *imgBuf, DWORD bufSize);
  48. std::string getJsonStr();
  49. bool getFaceUsers(std::vector<std::string> &users, std::string &msg);
  50. bool insertFaceUser(const User &user, std::string &msg);
  51. bool removeFaceUser(const std::string &uid, std::string &msg);
  52. bool getCarWoBList(const bool &isBlack, std::vector<std::string> &list, std::string &msg);
  53. bool insertCarWoBList(const bool &isBlack, std::vector<Plate> &list, std::string &msg);
  54. bool removeCarWoBList(const bool &isBlack, const std::vector<int> &cids, std::string &msg);
  55. };
  56. // global vars
  57. extern std::mutex gDeviceMtx;
  58. extern std::vector<std::unique_ptr<Device>> gDevicesVec;
  59. }
  60. #endif //HM_DEVICE_H