|
|
@@ -1,4 +1,4 @@
|
|
|
-#include "Device.h"
|
|
|
+#include "Driver.h"
|
|
|
#include <json.hpp>
|
|
|
#include <Logging.h>
|
|
|
#include <algorithm>
|
|
|
@@ -6,9 +6,9 @@
|
|
|
|
|
|
|
|
|
namespace PresenceDetection {
|
|
|
-namespace UniFi {
|
|
|
+namespace WiFi {
|
|
|
|
|
|
-Device::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::StaticDevice>& staticDevices) :
|
|
|
+Driver::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) :
|
|
|
m_loggedIn(false),
|
|
|
m_hostname(hostname),
|
|
|
m_port(port),
|
|
|
@@ -27,34 +27,34 @@ Device::Device(const std::string& hostname, int port, const std::string& usernam
|
|
|
Start();
|
|
|
}
|
|
|
|
|
|
-Device::~Device()
|
|
|
+Driver::~Driver()
|
|
|
{
|
|
|
Logout();
|
|
|
}
|
|
|
|
|
|
-void Device::Start()
|
|
|
+void Driver::Start()
|
|
|
{
|
|
|
int checkInterval = m_checkInterval * 1000;
|
|
|
- m_deviceTimer.StartContinuous(checkInterval, static_cast<std::function<void()>>(std::bind(&Device::UpdatePresentDevices, this)));
|
|
|
+ m_deviceTimer.StartContinuous(checkInterval, static_cast<std::function<void()>>(std::bind(&Driver::UpdatePresentDevices, this)));
|
|
|
if (!m_inventoryURL.empty())
|
|
|
- m_inventoryTimer.StartContinuous(300000, static_cast<std::function<void()>>(std::bind(&Device::UpdateDevicesFromInventory, this)));
|
|
|
+ m_inventoryTimer.StartContinuous(300000, static_cast<std::function<void()>>(std::bind(&Driver::UpdateDevicesFromInventory, this)));
|
|
|
}
|
|
|
|
|
|
-void Device::Stop()
|
|
|
+void Driver::Stop()
|
|
|
{
|
|
|
m_deviceTimer.Stop();
|
|
|
if (!m_inventoryURL.empty())
|
|
|
m_inventoryTimer.Stop();
|
|
|
}
|
|
|
|
|
|
-void Device::Wait()
|
|
|
+void Driver::Wait()
|
|
|
{
|
|
|
m_deviceTimer.Wait();
|
|
|
if (!m_inventoryURL.empty())
|
|
|
m_inventoryTimer.Stop();
|
|
|
}
|
|
|
|
|
|
-bool Device::Login()
|
|
|
+bool Driver::Login()
|
|
|
{
|
|
|
std::stringstream url;
|
|
|
url << "https://" << m_hostname << ":" << m_port << "/api/login";
|
|
|
@@ -88,7 +88,7 @@ bool Device::Login()
|
|
|
catch (const std::exception& e)
|
|
|
{
|
|
|
std::stringstream ss;
|
|
|
- ss << "UniFi::Device::Login() - Error: " << e.what() << std::endl;
|
|
|
+ ss << "WiFi::Driver::Login() - Error: " << e.what() << std::endl;
|
|
|
Logging::Log(Logging::Severity::Error, ss.str());
|
|
|
std::lock_guard<std::mutex> lock(m_mutex);
|
|
|
m_loggedIn = false;
|
|
|
@@ -100,7 +100,7 @@ bool Device::Login()
|
|
|
return m_loggedIn;
|
|
|
}
|
|
|
|
|
|
-void Device::Logout()
|
|
|
+void Driver::Logout()
|
|
|
{
|
|
|
std::stringstream url;
|
|
|
url << "https://" << m_hostname << ":" << m_port << "/logout";
|
|
|
@@ -118,12 +118,12 @@ void Device::Logout()
|
|
|
catch (const std::exception& e)
|
|
|
{
|
|
|
std::stringstream ss;
|
|
|
- ss << "UniFi::Device::Logout() - Error: " << e.what() << std::endl;
|
|
|
+ ss << "WiFi::Driver::Logout() - Error: " << e.what() << std::endl;
|
|
|
Logging::Log(Logging::Severity::Error, ss.str());
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-void Device::ClearDevices()
|
|
|
+void Driver::ClearDevices()
|
|
|
{
|
|
|
for (std::vector<std::string>::iterator it = m_devices.begin(); it != m_devices.end(); ++it)
|
|
|
{
|
|
|
@@ -134,7 +134,7 @@ void Device::ClearDevices()
|
|
|
catch (const std::exception& e)
|
|
|
{
|
|
|
std::stringstream ss;
|
|
|
- ss << "UniFi::Device::ClearDevices() - Error: " << e.what() << std::endl;
|
|
|
+ ss << "WiFi::Driver::ClearDevices() - Error: " << e.what() << std::endl;
|
|
|
Logging::Log(Logging::Severity::Error, ss.str());
|
|
|
}
|
|
|
}
|
|
|
@@ -150,14 +150,14 @@ void Device::ClearDevices()
|
|
|
catch (const std::exception& e)
|
|
|
{
|
|
|
std::stringstream ss;
|
|
|
- ss << "UniFi::Device::ClearDevices() - Error: " << e.what() << std::endl;
|
|
|
+ ss << "WiFi::Driver::ClearDevices() - Error: " << e.what() << std::endl;
|
|
|
Logging::Log(Logging::Severity::Error, ss.str());
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-void Device::UpdateDevicesFromInventory()
|
|
|
+void Driver::UpdateDevicesFromInventory()
|
|
|
{
|
|
|
try
|
|
|
{
|
|
|
@@ -177,12 +177,12 @@ void Device::UpdateDevicesFromInventory()
|
|
|
catch (const std::exception& e)
|
|
|
{
|
|
|
std::stringstream ss;
|
|
|
- ss << "UniFi::Device::GetDevicesFromInventory() - Error: " << e.what() << std::endl;
|
|
|
+ ss << "WiFi::Driver::GetDevicesFromInventory() - Error: " << e.what() << std::endl;
|
|
|
Logging::Log(Logging::Severity::Error, ss.str());
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-void Device::UpdatePresentDevices()
|
|
|
+void Driver::UpdatePresentDevices()
|
|
|
{
|
|
|
bool loggedIn;
|
|
|
{
|
|
|
@@ -229,7 +229,12 @@ void Device::UpdatePresentDevices()
|
|
|
if ((timeStamp - lastSeen) < m_timeout)
|
|
|
{
|
|
|
if (std::find(m_presentDevices.begin(), m_presentDevices.end(), macAddress) == m_presentDevices.end())
|
|
|
+ {
|
|
|
addedDevices.push_back(macAddress);
|
|
|
+ std::stringstream ss;
|
|
|
+ ss << "Device Added: " << device.dump() << std::endl;
|
|
|
+ Logging::Log(Logging::Severity::Info, ss.str());
|
|
|
+ }
|
|
|
presentDevices.push_back(macAddress);
|
|
|
}
|
|
|
else
|
|
|
@@ -238,7 +243,7 @@ void Device::UpdatePresentDevices()
|
|
|
{
|
|
|
std::stringstream ss;
|
|
|
ss << "TimeOut (" << m_timeout << "): " << macAddress << std::endl;
|
|
|
- Logging::Log(Logging::Severity::Debug, ss.str());
|
|
|
+ Logging::Log(Logging::Severity::Info, ss.str());
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
@@ -260,7 +265,7 @@ void Device::UpdatePresentDevices()
|
|
|
{
|
|
|
std::stringstream ss;
|
|
|
ss << "TimeOut (" << m_timeout << "): " << macAddress << std::endl;
|
|
|
- Logging::Log(Logging::Severity::Debug, ss.str());
|
|
|
+ Logging::Log(Logging::Severity::Info, ss.str());
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
@@ -269,7 +274,7 @@ void Device::UpdatePresentDevices()
|
|
|
catch (const std::exception& e)
|
|
|
{
|
|
|
std::stringstream ss;
|
|
|
- ss << "UniFi::Device::IsDevicePresent() - Error: " << e.what() << std::endl;
|
|
|
+ ss << "WiFi::Driver::IsDevicePresent() - Error: " << e.what() << std::endl;
|
|
|
Logging::Log(Logging::Severity::Error, ss.str());
|
|
|
Logout();
|
|
|
return;
|
|
|
@@ -288,7 +293,7 @@ void Device::UpdatePresentDevices()
|
|
|
m_presentDevices.assign(presentDevices.begin(), presentDevices.end());
|
|
|
}
|
|
|
|
|
|
-void Device::SendStateChange(bool present, const std::string& macAddress)
|
|
|
+void Driver::SendStateChange(bool present, const std::string& macAddress)
|
|
|
{
|
|
|
char sign;
|
|
|
if (present)
|
|
|
@@ -297,13 +302,13 @@ void Device::SendStateChange(bool present, const std::string& macAddress)
|
|
|
sign = '-';
|
|
|
|
|
|
std::stringstream ss;
|
|
|
- ss << "UniFi: " << sign << " " << macAddress;
|
|
|
+ ss << "WiFi: " << sign << " " << macAddress;
|
|
|
Logging::Log(Logging::Severity::Info, ss.str());
|
|
|
|
|
|
if (!m_target.empty())
|
|
|
{
|
|
|
std::stringstream url;
|
|
|
- url << m_target << "/UniFi/" << sign << "/" << macAddress;
|
|
|
+ url << m_target << "/WiFi/" << sign << "/" << macAddress;
|
|
|
|
|
|
try
|
|
|
{
|
|
|
@@ -314,7 +319,7 @@ void Device::SendStateChange(bool present, const std::string& macAddress)
|
|
|
catch (const std::exception& e)
|
|
|
{
|
|
|
std::stringstream ss;
|
|
|
- ss << "UniFi::Device::SendStateChange() - Error: " << e.what() << std::endl;
|
|
|
+ ss << "WiFi::Driver::SendStateChange() - Error: " << e.what() << std::endl;
|
|
|
Logging::Log(Logging::Severity::Error, ss.str());
|
|
|
}
|
|
|
}
|
|
|
@@ -353,7 +358,7 @@ void Device::SendStateChange(bool present, const std::string& macAddress)
|
|
|
catch (const std::exception& e)
|
|
|
{
|
|
|
std::stringstream ss;
|
|
|
- ss << "UniFi::Device::SendStateChange() - Error: " << e.what() << std::endl;
|
|
|
+ ss << "WiFi::Driver::SendStateChange() - Error: " << e.what() << std::endl;
|
|
|
Logging::Log(Logging::Severity::Error, ss.str());
|
|
|
}
|
|
|
}
|
|
|
@@ -361,5 +366,5 @@ void Device::SendStateChange(bool present, const std::string& macAddress)
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-} // namespace UniFi
|
|
|
+} // namespace WiFi
|
|
|
} // namespace PresenceDetection
|