Driver.h 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. #ifndef WIFI_DRIVER_H
  2. #define WIFI_DRIVER_H
  3. #include "Util/StaticDevice.h"
  4. #include <HttpClient.h>
  5. #include <Timer.h>
  6. #include <mutex>
  7. #include <string>
  8. #include <vector>
  9. namespace PresenceDetection {
  10. namespace WiFi {
  11. class Driver
  12. {
  13. public:
  14. Driver(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::StaticDevice>& staticDevices);
  15. ~Driver();
  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. void ClearCookiesFile();
  27. private:
  28. struct PresentDevice
  29. {
  30. PresentDevice(const std::string& macAddress);
  31. PresentDevice(const std::string& macAddress, int lastSeen);
  32. std::string MacAddress;
  33. int LastSeen;
  34. bool operator==(const PresentDevice& other) const;
  35. bool operator!=(const PresentDevice& other) const;
  36. bool operator==(const std::string& other) const;
  37. bool operator!=(const std::string& other) const;
  38. };
  39. private:
  40. Timer::Timer m_deviceTimer;
  41. Timer::Timer m_inventoryTimer;
  42. Http::HttpClient m_httpClient;
  43. std::mutex m_mutex;
  44. bool m_loggedIn;
  45. std::string m_hostname;
  46. int m_port;
  47. std::string m_username;
  48. std::string m_password;
  49. std::string m_cookieFile;
  50. std::vector<std::string> m_devices;
  51. int m_timeout;
  52. int m_checkInterval;
  53. std::string m_inventoryURL;
  54. std::string m_target;
  55. std::vector<Util::StaticDevice> m_staticDevices;
  56. std::vector<PresentDevice> m_presentDevices;
  57. };
  58. } // namespace WiFi
  59. } // namespace PresenceDetection
  60. #endif // WIFI_DRIVER_H