Add Static Devices
This commit is contained in:
+26
-6
@@ -8,7 +8,7 @@
|
||||
namespace PresenceDetection {
|
||||
namespace UniFi {
|
||||
|
||||
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::Device>& devices) :
|
||||
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) :
|
||||
m_loggedIn(false),
|
||||
m_hostname(hostname),
|
||||
m_port(port),
|
||||
@@ -16,9 +16,10 @@ Device::Device(const std::string& hostname, int port, const std::string& usernam
|
||||
m_password(password),
|
||||
m_cookieFile(cookieFile),
|
||||
m_timeout(timeout),
|
||||
m_checkInterval(5),
|
||||
m_inventoryURL(inventoryURL),
|
||||
m_target(target),
|
||||
m_staticDevices(devices)
|
||||
m_staticDevices(staticDevices)
|
||||
{
|
||||
if (!m_inventoryURL.empty())
|
||||
UpdateDevicesFromInventory();
|
||||
@@ -33,7 +34,8 @@ Device::~Device()
|
||||
|
||||
void Device::Start()
|
||||
{
|
||||
m_deviceTimer.StartContinuous(5000, static_cast<std::function<void()>>(std::bind(&Device::UpdatePresentDevices, this)));
|
||||
int checkInterval = m_checkInterval * 1000;
|
||||
m_deviceTimer.StartContinuous(checkInterval, static_cast<std::function<void()>>(std::bind(&Device::UpdatePresentDevices, this)));
|
||||
if (!m_inventoryURL.empty())
|
||||
m_inventoryTimer.StartContinuous(300000, static_cast<std::function<void()>>(std::bind(&Device::UpdateDevicesFromInventory, this)));
|
||||
}
|
||||
@@ -129,7 +131,7 @@ void Device::ClearDevices()
|
||||
}
|
||||
}
|
||||
|
||||
for (std::vector<Util::Device>::iterator it = m_staticDevices.begin(); it != m_staticDevices.end(); ++it)
|
||||
for (std::vector<Util::StaticDevice>::iterator it = m_staticDevices.begin(); it != m_staticDevices.end(); ++it)
|
||||
{
|
||||
if (it->HasWifiMac())
|
||||
{
|
||||
@@ -219,9 +221,18 @@ void Device::UpdatePresentDevices()
|
||||
addedDevices.push_back(macAddress);
|
||||
presentDevices.push_back(macAddress);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (std::find(m_presentDevices.begin(), m_presentDevices.end(), macAddress) != m_presentDevices.end())
|
||||
{
|
||||
std::stringstream ss;
|
||||
ss << "TimeOut (" << m_timeout << "): " << macAddress << std::endl;
|
||||
Logging::Log(Logging::Severity::Debug, ss.str());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (std::vector<Util::Device>::iterator it = m_staticDevices.begin(); it != m_staticDevices.end(); ++it)
|
||||
for (std::vector<Util::StaticDevice>::iterator it = m_staticDevices.begin(); it != m_staticDevices.end(); ++it)
|
||||
{
|
||||
if ((timeStamp - lastSeen) < m_timeout)
|
||||
{
|
||||
@@ -232,6 +243,15 @@ void Device::UpdatePresentDevices()
|
||||
presentDevices.push_back(macAddress);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (std::find(m_presentDevices.begin(), m_presentDevices.end(), macAddress) != m_presentDevices.end())
|
||||
{
|
||||
std::stringstream ss;
|
||||
ss << "TimeOut (" << m_timeout << "): " << macAddress << std::endl;
|
||||
Logging::Log(Logging::Severity::Debug, ss.str());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -286,7 +306,7 @@ void Device::SendStateChange(bool present, const std::string& macAddress)
|
||||
}
|
||||
}
|
||||
|
||||
for (std::vector<Util::Device>::iterator it = m_staticDevices.begin(); it != m_staticDevices.end(); ++it)
|
||||
for (std::vector<Util::StaticDevice>::iterator it = m_staticDevices.begin(); it != m_staticDevices.end(); ++it)
|
||||
{
|
||||
if (it->HasWifiMac() && it->WifiMac() == macAddress)
|
||||
{
|
||||
|
||||
+4
-3
@@ -1,7 +1,7 @@
|
||||
#ifndef UNIFI_DEVICE_H
|
||||
#define UNIFI_DEVICE_H
|
||||
|
||||
#include "Util/Device.h"
|
||||
#include "Util/StaticDevice.h"
|
||||
#include <HttpClient.h>
|
||||
#include <Timer.h>
|
||||
#include <mutex>
|
||||
@@ -15,7 +15,7 @@ namespace UniFi {
|
||||
class Device
|
||||
{
|
||||
public:
|
||||
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);
|
||||
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);
|
||||
~Device();
|
||||
|
||||
void Start();
|
||||
@@ -47,9 +47,10 @@ private:
|
||||
std::vector<std::string> m_devices;
|
||||
|
||||
int m_timeout;
|
||||
int m_checkInterval;
|
||||
std::string m_inventoryURL;
|
||||
std::string m_target;
|
||||
std::vector<Util::Device> m_staticDevices;
|
||||
std::vector<Util::StaticDevice> m_staticDevices;
|
||||
|
||||
std::vector<std::string> m_presentDevices;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user