Device.h 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. #ifndef UNIFI_DEVICE_H
  2. #define UNIFI_DEVICE_H
  3. #include <mutex>
  4. #include <string>
  5. #include <vector>
  6. #include "Util/Device.h"
  7. #include "Util/Timer.h"
  8. #include "Util/HttpClient.h"
  9. namespace PresenceDetection {
  10. namespace UniFi {
  11. class Device
  12. {
  13. public:
  14. Device(const std::string& hostname, int port, const std::string& username, const std::string& password, const std::string& cookieFile, int timeout, const std::string& inventoryURL, const std::string& target, const std::vector<Util::Device>& devices);
  15. ~Device();
  16. void Start();
  17. void Stop();
  18. void Wait();
  19. private:
  20. bool Login();
  21. void Logout();
  22. void ClearDevices();
  23. void UpdateDevicesFromInventory();
  24. void UpdatePresentDevices();
  25. void SendStateChange(bool present, const std::string& macAddress);
  26. private:
  27. Util::Timer m_deviceTimer;
  28. Util::Timer m_inventoryTimer;
  29. Util::HttpClient m_httpClient;
  30. std::mutex m_mutex;
  31. bool m_loggedIn;
  32. std::string m_hostname;
  33. int m_port;
  34. std::string m_username;
  35. std::string m_password;
  36. std::string m_cookieFile;
  37. std::vector<std::string> m_devices;
  38. int m_timeout;
  39. std::string m_inventoryURL;
  40. std::string m_target;
  41. std::vector<Util::Device> m_staticDevices;
  42. std::vector<std::string> m_presentDevices;
  43. };
  44. } // namespace UniFi
  45. } // namespace PresenceDetection
  46. #endif // UNIFI_DEVICE_H