Browse Source

Add Static Devices

JDierkse 5 years ago
parent
commit
21dbdd41d9

+ 19 - 14
Application/PresenceDetection.cc

@@ -1,6 +1,6 @@
 #include "Bluetooth/Device.h"
 #include "UniFi/Device.h"
-#include "Util/Device.h"
+#include "Util/StaticDevice.h"
 #include "Util/INIh.h"
 #include <clipp.h>
 #include <Logging.h>
@@ -41,7 +41,7 @@ int main(int argc, char** argv)
 
 		if (daemon)
 		{
-			Logging::Log(Logging::Severity::Info, "Starting Daemon");
+			Logging::Log(Logging::Severity::Info, "Starting PresenceDetection Daemon");
 			pid_t pid, sid;
 			pid = fork();
 
@@ -62,6 +62,11 @@ int main(int argc, char** argv)
 			close(STDOUT_FILENO);
 			close(STDERR_FILENO);
 		}
+		else
+		{
+			Logging::Log(Logging::Severity::Info, "Starting PresenceDetection");
+		}
+
 
 		std::string target = iniReader.Get("PresenceDetection", "Target", "");
 
@@ -69,7 +74,7 @@ int main(int argc, char** argv)
 
 		bool bluetooth = iniReader.GetBoolean("PresenceDetection", "Bluetooth", false);
 
-		std::vector<PresenceDetection::Util::Device> devices;
+		std::vector<PresenceDetection::Util::StaticDevice> staticDevices;
 
 		auto sections = iniReader.Sections();
 		for (auto section : sections)
@@ -88,33 +93,33 @@ int main(int argc, char** argv)
 					throw std::runtime_error(ss.str());
 				}
 
-				auto device = PresenceDetection::Util::Device(WifiMac, BluetoothMac);
+				auto staticDevice = PresenceDetection::Util::StaticDevice(WifiMac, BluetoothMac);
 
 				std::string OnlineURL = iniReader.Get(section, "OnlineURL", "");
 				if (!OnlineURL.empty())
-					device.SetOnlineURL(OnlineURL);
+					staticDevice.SetOnlineURL(OnlineURL);
 
 				std::string WifiOnlineURL = iniReader.Get(section, "WifiOnlineURL", "");
 				if (!WifiOnlineURL.empty())
-					device.SetWifiOnlineURL(WifiOnlineURL);
+					staticDevice.SetWifiOnlineURL(WifiOnlineURL);
 
 				std::string BluetoothOnlineURL = iniReader.Get(section, "BluetoothOnlineURL", "");
 				if (!BluetoothOnlineURL.empty())
-					device.SetBluetoothOnlineURL(BluetoothOnlineURL);
+					staticDevice.SetBluetoothOnlineURL(BluetoothOnlineURL);
 
 				std::string OfflineURL = iniReader.Get(section, "OfflineURL", "");
 				if (!OfflineURL.empty())
-					device.SetOfflineURL(OfflineURL);
+					staticDevice.SetOfflineURL(OfflineURL);
 
 				std::string WifiOfflineURL = iniReader.Get(section, "WifiOfflineURL", "");
 				if (!WifiOfflineURL.empty())
-					device.SetWifiOfflineURL(WifiOfflineURL);
+					staticDevice.SetWifiOfflineURL(WifiOfflineURL);
 
 				std::string BluetoothOfflineURL = iniReader.Get(section, "BluetoothOfflineURL", "");
 				if (!BluetoothOfflineURL.empty())
-					device.SetBluetoothOfflineURL(BluetoothOfflineURL);
+					staticDevice.SetBluetoothOfflineURL(BluetoothOfflineURL);
 
-				devices.push_back(device);
+				staticDevices.push_back(staticDevice);
 			}
 		}
 
@@ -143,7 +148,7 @@ int main(int argc, char** argv)
 
 			std::string inventoryURL = iniReader.Get("UniFi", "Inventory", "");
 
-			pUniFiDevice = std::make_shared<PresenceDetection::UniFi::Device>(hostname, port, username, password, cookiefile, timeout, inventoryURL, target, devices);
+			pUniFiDevice = std::make_shared<PresenceDetection::UniFi::Device>(hostname, port, username, password, cookiefile, timeout, inventoryURL, target, staticDevices);
 		}
 
 		std::shared_ptr<PresenceDetection::Bluetooth::Device> pBluetoothDevice;
@@ -153,7 +158,7 @@ int main(int argc, char** argv)
 
 			std::string inventoryURL = iniReader.Get("Bluetooth", "Inventory", "");
 
-			pBluetoothDevice = std::make_shared<PresenceDetection::Bluetooth::Device>(timeout, inventoryURL, target, devices);
+			pBluetoothDevice = std::make_shared<PresenceDetection::Bluetooth::Device>(timeout, inventoryURL, target, staticDevices);
 		}
 
 		sigset_t wset;
@@ -164,7 +169,7 @@ int main(int argc, char** argv)
 		int sig;
 		sigwait(&wset,&sig);
 
-		Logging::Log(Logging::Severity::Info, "Stopping...");
+		Logging::Log(Logging::Severity::Info, "Stopping PresenceDetection...");
 
 		if (pUniFiDevice)
 			pUniFiDevice->Stop();

+ 0 - 79
Application/Test.cc

@@ -14,85 +14,6 @@ void print()
 	std::cout << "Print" << std::endl;
 }
 
-void TestTimerAbort()
-{
-	Timer::Timer timer;
-	std::function<void()> f_print = print;
-
-	std::cout << "---" << std::endl;
-	auto start = std::chrono::steady_clock::now();
-	std::clock_t begin = std::clock();
-	timer.StartContinuous(1000, f_print);
-	timer.Stop();
-	timer.Wait();
-	auto elapsed = std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::steady_clock::now() - start);
-	std::cout << "Elapsed: " << elapsed.count() << std::endl;
-	std::cout << "---" << std::endl << std::endl;
-
-	std::cout << "---" << std::endl;
-	start = std::chrono::steady_clock::now();
-	timer.StartContinuous(3000, f_print);
-	timer.Abort();
-	timer.Wait();
-	elapsed = std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::steady_clock::now() - start);
-	std::cout << "Elapsed: " << elapsed.count() << std::endl;
-	std::cout << "---" << std::endl << std::endl;
-
-	std::cout << "---" << std::endl;
-	start = std::chrono::steady_clock::now();
-	timer.StartContinuous(3000, f_print);
-	sleep(1);
-	timer.Abort();
-	timer.Wait();
-	elapsed = std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::steady_clock::now() - start);
-	std::cout << "Elapsed: " << elapsed.count() << std::endl;
-	std::cout << "---" << std::endl << std::endl;
-}
-
-typedef std::unique_ptr<Timer::Timer> Pointer;
-
-template<typename T, typename... Args>
-std::unique_ptr<T> make_unique(Args&&... args) {
-	return std::unique_ptr<T>(new T(std::forward<Args>(args)...));
-}
-
-void OnTimerEnd(const std::string& type, int id)
-{
-	std::cout << "OnTimerEnd() " << type << " " << id <<std::endl;
-}
-
-void StartNewTimer(std::deque<Pointer>& timers)
-{
-	int delay(2000);
-	std::string identifier("Blabla");
-	int id(10);
-
-	// Protect!
-	auto timer = make_unique<Timer::Timer>();
-	timer->StartSingle(delay, static_cast<std::function<void(const std::string&, int)>>(std::bind(&OnTimerEnd, std::placeholders::_1, std::placeholders::_2)), identifier, id);
-	timers.push_back(std::move(timer));
-}
-
-void Cleanup(std::deque<Pointer>& timers)
-{
-	timers.erase(std::remove_if(timers.begin(), timers.end(), [](Pointer& t){return !t->IsRunning();}), timers.end());
-}
-
-void TestTimerDeque()
-{
-	std::deque<Pointer> timers;
-	StartNewTimer(timers);
-	std::cout << "Count: " << timers.size() << std::endl;
-	StartNewTimer(timers);
-	std::cout << "Count: " << timers.size() << std::endl;
-
-	sleep(5);
-
-	std::cout << "Count: " << timers.size() << std::endl;
-	Cleanup(timers);
-	std::cout << "Count: " << timers.size() << std::endl;
-}
-
 void TestINIReader()
 {
 	PresenceDetection::Util::INIReader reader("PresenceDetection.ini");

+ 56 - 40
Bluetooth/Device.cpp

@@ -9,11 +9,12 @@
 namespace PresenceDetection {
 namespace Bluetooth {
 
-Device::Device(int timeout, const std::string& inventoryURL, const std::string& target, const std::vector<Util::Device>& devices) :
+Device::Device(int timeout, const std::string& inventoryURL, const std::string& target, const std::vector<Util::StaticDevice>& staticDevices) :
 	m_timeout(timeout),
+	m_checkInterval(3),
 	m_inventoryURL(inventoryURL),
 	m_target(target),
-	m_staticDevices(devices)
+	m_staticDevices(staticDevices)
 {
 	if (!m_inventoryURL.empty())
 		UpdateDevicesFromInventory();
@@ -27,36 +28,33 @@ Device::~Device()
 
 void Device::Start()
 {
-	int timeout = m_timeout * 1000;
-	m_onlineDeviceTimer.StartContinuous(timeout, static_cast<std::function<void()>>(std::bind(&Device::UpdateOnlineDevices, this)));
-	m_offlineDeviceTimer.StartContinuous(3000, static_cast<std::function<void()>>(std::bind(&Device::UpdateOfflineDevices, 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(600000, static_cast<std::function<void()>>(std::bind(&Device::UpdateDevicesFromInventory, this)));
 }
 
 void Device::Stop()
 {
-	m_onlineDeviceTimer.Stop();
-	m_offlineDeviceTimer.Stop();
+	m_deviceTimer.Stop();
 	if (!m_inventoryURL.empty())
 		m_inventoryTimer.Stop();
 }
 
 void Device::Wait()
 {
-	m_onlineDeviceTimer.Wait();
-	m_offlineDeviceTimer.Wait();
+	m_deviceTimer.Wait();
 	if (!m_inventoryURL.empty())
 		m_inventoryTimer.Wait();
 }
 
 void Device::ClearDevices()
 {
-	for (std::vector<std::string>::iterator it = m_devices.begin(); it != m_devices.end(); ++it)
+	for (std::vector<Util::DynamicDevice>::iterator it = m_dynamicDevices.begin(); it != m_dynamicDevices.end(); ++it)
 	{
 		try
 		{
-			SendStateChange(false, *it);
+			SendStateChange(false, it->MacAddress());
 		}
 		catch (const std::exception& e)
 		{
@@ -66,7 +64,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->HasBluetoothMac())
 		{
@@ -91,13 +89,13 @@ void Device::UpdateDevicesFromInventory()
 		std::string devices = m_httpClient.GetUrlContents(m_inventoryURL);
 		Util::JSON json = Util::JSON::parse(devices);
 
-		m_devices.clear();
+		m_dynamicDevices.clear();
 		for (auto& element : json)
 			if (element["bluetooth"] != "")
 			{
 				std::string bluetooth = element["bluetooth"];
 				std::transform(bluetooth.begin(), bluetooth.end(), bluetooth.begin(), ::tolower);
-				m_devices.push_back(bluetooth);
+				m_dynamicDevices.push_back(Util::DynamicDevice(bluetooth));
 			}
 	}
 	catch (const std::exception& e)
@@ -108,40 +106,44 @@ void Device::UpdateDevicesFromInventory()
 	}
 }
 
-void Device::UpdateOnlineDevices()
-{
-	UpdatePresentDevices(true);
-}
-
-void Device::UpdateOfflineDevices()
-{
-	UpdatePresentDevices(false);
-}
-
-void Device::UpdatePresentDevices(bool updateOnlineDevices)
+void Device::UpdatePresentDevices()
 {
 	std::vector<std::string> presentDevices;
 	std::vector<std::string> ignoredDevices;
 
-	for (std::vector<std::string>::iterator it = m_devices.begin(); it != m_devices.end(); ++it)
+	for (std::vector<Util::DynamicDevice>::iterator it = m_dynamicDevices.begin(); it != m_dynamicDevices.end(); ++it)
 	{
 		try
 		{
 			bool pollDevice = false;
-			if (std::find(m_presentDevices.begin(), m_presentDevices.end(), *it) == m_presentDevices.end())
+			if (std::find(m_presentDevices.begin(), m_presentDevices.end(), it->MacAddress()) == m_presentDevices.end())
+			{
 				pollDevice = true;
+			}
 			else
-				pollDevice = updateOnlineDevices;
-
-			if (pollDevice && Functions::Ping(*it))
 			{
-				if (std::find(m_presentDevices.begin(), m_presentDevices.end(), *it) == m_presentDevices.end())
-					SendStateChange(true, *it);
-				presentDevices.push_back(*it);
+				it->IncrementProbeCounter();
+				if (it->ProbeCounter() * m_checkInterval >= m_timeout)
+				{
+					pollDevice = true;
+					it->ResetProbeCounter();
+				}
 			}
 
-			if (!pollDevice)
-				ignoredDevices.push_back(*it);
+			if (pollDevice && Functions::Ping(it->MacAddress()))
+			{
+				if (std::find(m_presentDevices.begin(), m_presentDevices.end(), it->MacAddress()) == m_presentDevices.end())
+					SendStateChange(true, it->MacAddress());
+				presentDevices.push_back(it->MacAddress());
+			}
+			else if (pollDevice)
+			{
+				it->ResetProbeCounter();
+			}
+			else
+			{
+				ignoredDevices.push_back(it->MacAddress());
+			}
 		}
 		catch (const std::exception& e)
 		{
@@ -151,7 +153,7 @@ void Device::UpdatePresentDevices(bool updateOnlineDevices)
 		}
 	}
 
-	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->HasBluetoothMac())
 		{
@@ -159,9 +161,18 @@ void Device::UpdatePresentDevices(bool updateOnlineDevices)
 			{
 				bool pollDevice = false;
 				if (std::find(m_presentDevices.begin(), m_presentDevices.end(), it->BluetoothMac()) == m_presentDevices.end())
+				{
 					pollDevice = true;
+				}
 				else
-					pollDevice = updateOnlineDevices;
+				{
+					it->IncrementProbeCounter();
+					if (it->ProbeCounter() * m_checkInterval >= m_timeout)
+					{
+						pollDevice = true;
+						it->ResetProbeCounter();
+					}
+				}
 
 				if (pollDevice && Functions::Ping(it->BluetoothMac()))
 				{
@@ -169,9 +180,14 @@ void Device::UpdatePresentDevices(bool updateOnlineDevices)
 						SendStateChange(true, it->BluetoothMac());
 					presentDevices.push_back(it->BluetoothMac());
 				}
-
-				if (!pollDevice)
+				else if (pollDevice)
+				{
+					it->ResetProbeCounter();
+				}
+				else
+				{
 					ignoredDevices.push_back(it->BluetoothMac());
+				}
 			}
 			catch (const std::exception& e)
 			{
@@ -223,7 +239,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->HasBluetoothMac() && it->BluetoothMac() == macAddress)
 		{

+ 8 - 9
Bluetooth/Device.h

@@ -1,7 +1,8 @@
 #ifndef BLUETOOTH_DEVICE_H
 #define BLUETOOTH_DEVICE_H
 
-#include "Util/Device.h"
+#include "Util/DynamicDevice.h"
+#include "Util/StaticDevice.h"
 #include <HttpClient.h>
 #include <Timer.h>
 #include <string>
@@ -14,7 +15,7 @@ namespace Bluetooth {
 class Device
 {
 public:
-	Device(int timeout, const std::string& inventoryURL, const std::string& target, const std::vector<Util::Device>& devices);
+	Device(int timeout, const std::string& inventoryURL, const std::string& target, const std::vector<Util::StaticDevice>& staticDevices);
 	~Device();
 
 	void Start();
@@ -24,23 +25,21 @@ public:
 private:
 	void ClearDevices();
 	void UpdateDevicesFromInventory();
-	void UpdateOnlineDevices();
-	void UpdateOfflineDevices();
-	void UpdatePresentDevices(bool updateOnlineDevices);
+	void UpdatePresentDevices();
 	void SendStateChange(bool present, const std::string& macAddress);
 
 private:
-	Timer::Timer m_onlineDeviceTimer;
-	Timer::Timer m_offlineDeviceTimer;
+	Timer::Timer m_deviceTimer;
 	Timer::Timer m_inventoryTimer;
 	Http::HttpClient m_httpClient;
 
-	std::vector<std::string> m_devices;
+	std::vector<Util::DynamicDevice> m_dynamicDevices;
 
 	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;
 };

+ 26 - 6
UniFi/Device.cpp

@@ -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
UniFi/Device.h

@@ -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;
 };

+ 0 - 167
Util/Device.cpp

@@ -1,167 +0,0 @@
-#include "Device.h"
-#include <algorithm>
-
-
-namespace PresenceDetection {
-namespace Util {
-
-Device::Device(const std::string& wifiMac, const std::string& bluetoothMac) :
-	m_wifiMac(wifiMac),
-	m_wifiState(false),
-	m_bluetoothMac(bluetoothMac),
-	m_bluetoothState(false)
-{
-	std::transform(m_wifiMac.begin(), m_wifiMac.end(), m_wifiMac.begin(), ::tolower);
-	std::transform(m_bluetoothMac.begin(), m_bluetoothMac.end(), m_bluetoothMac.begin(), ::tolower);
-}
-
-Device::Device(const Device &other) :
-	m_wifiMac(other.m_wifiMac),
-	m_wifiState(other.m_wifiState),
-	m_bluetoothMac(other.m_bluetoothMac),
-	m_bluetoothState(other.m_bluetoothState),
-	m_onlineURL(other.m_onlineURL),
-	m_wifiOnlineURL(other.m_wifiOnlineURL),
-	m_bluetoothOnlineURL(other.m_bluetoothOnlineURL),
-	m_offlineURL(other.m_offlineURL),
-	m_wifiOfflineURL(other.m_wifiOfflineURL),
-	m_bluetoothOfflineURL(other.m_bluetoothOfflineURL)
-{
-}
-
-Device::~Device()
-{
-}
-
-bool Device::HasWifiMac() const
-{
-	return !m_wifiMac.empty();
-}
-
-std::string Device::WifiMac() const
-{
-	return m_wifiMac;
-}
-
-void Device::SetWifiState(bool present)
-{
-	m_wifiState = present;
-}
-
-bool Device::GetWifiState() const
-{
-	return m_wifiState;
-}
-
-bool Device::HasBluetoothMac() const
-{
-	return !m_bluetoothMac.empty();
-}
-
-std::string Device::BluetoothMac() const
-{
-	return m_bluetoothMac;
-}
-
-void Device::SetBluetoothState(bool present)
-{
-	m_bluetoothState = present;
-}
-
-bool Device::GetBluetoothState() const
-{
-	return m_bluetoothState;
-}
-
-bool Device::HasOnlineURL() const
-{
-	return !m_onlineURL.empty();
-}
-
-void Device::SetOnlineURL(const std::string& url)
-{
-	m_onlineURL = url;
-}
-
-std::string Device::OnlineURL() const
-{
-	return m_onlineURL;
-}
-
-bool Device::HasWifiOnlineURL() const
-{
-	return !m_wifiOnlineURL.empty();
-}
-
-void Device::SetWifiOnlineURL(const std::string& url)
-{
-	m_wifiOnlineURL = url;
-}
-
-std::string Device::WifiOnlineURL() const
-{
-	return m_wifiOnlineURL;
-}
-
-bool Device::HasBluetoothOnlineURL() const
-{
-	return !m_bluetoothOnlineURL.empty();
-}
-
-void Device::SetBluetoothOnlineURL(const std::string& url)
-{
-	m_bluetoothOnlineURL = url;
-}
-
-std::string Device::BluetoothOnlineURL() const
-{
-	return m_bluetoothOnlineURL;
-}
-
-bool Device::HasOfflineURL() const
-{
-	return !m_offlineURL.empty();
-}
-
-void Device::SetOfflineURL(const std::string& url)
-{
-	m_offlineURL = url;
-}
-
-std::string Device::OfflineURL() const
-{
-	return m_offlineURL;
-}
-
-bool Device::HasWifiOfflineURL() const
-{
-	return !m_wifiOfflineURL.empty();
-}
-
-void Device::SetWifiOfflineURL(const std::string& url)
-{
-	m_wifiOfflineURL = url;
-}
-
-std::string Device::WifiOfflineURL() const
-{
-	return m_wifiOfflineURL;
-}
-
-bool Device::HasBluetoothOfflineURL() const
-{
-	return !m_bluetoothOfflineURL.empty();
-}
-
-void Device::SetBluetoothOfflineURL(const std::string& url)
-{
-	m_bluetoothOfflineURL = url;
-}
-
-std::string Device::BluetoothOfflineURL() const
-{
-	return m_bluetoothOfflineURL;
-}
-
-} // namespace Util
-} // namespace PresenceDetection

+ 35 - 0
Util/DynamicDevice.cpp

@@ -0,0 +1,35 @@
+#include "DynamicDevice.h"
+#include <StringAlgorithm.h>
+
+
+namespace PresenceDetection {
+namespace Util {
+
+DynamicDevice::DynamicDevice(const std::string& macAddress) :
+	m_probeCounter(0),
+	m_macAddress(macAddress)
+{
+}
+
+std::string DynamicDevice::MacAddress()
+{
+	return m_macAddress;
+}
+
+int DynamicDevice::ProbeCounter() const
+{
+	return m_probeCounter;
+}
+
+void DynamicDevice::IncrementProbeCounter()
+{
+	++m_probeCounter;
+}
+
+void DynamicDevice::ResetProbeCounter()
+{
+	m_probeCounter = 0;
+}
+
+} // namespace Util
+} // namespace PresenceDetection

+ 31 - 0
Util/DynamicDevice.h

@@ -0,0 +1,31 @@
+#ifndef UTIL_DYNAMICDEVICE_H
+#define UTIL_DYNAMICDEVICE_H
+
+#include "ProbeableDevice.h"
+#include <string>
+
+
+namespace PresenceDetection {
+namespace Util {
+
+class DynamicDevice : public ProbeableDevice
+{
+public:
+	DynamicDevice(const std::string& macAddress);
+
+	virtual int ProbeCounter() const override;
+	virtual void IncrementProbeCounter() override;
+	virtual void ResetProbeCounter() override;
+
+	std::string MacAddress();
+
+private:
+	int m_probeCounter;
+
+	std::string m_macAddress;
+};
+
+} // namespace Util
+} // namespace PresenceDetection
+
+#endif // UTIL_DYNAMICDEVICE_H

+ 21 - 0
Util/ProbeableDevice.h

@@ -0,0 +1,21 @@
+#ifndef UTIL_PROBEABLEDEVICE_H
+#define UTIL_PROBEABLEDEVICE_H
+
+#include <string>
+
+
+namespace PresenceDetection {
+namespace Util {
+
+class ProbeableDevice
+{
+public:
+	virtual int ProbeCounter() const = 0;
+	virtual void IncrementProbeCounter() = 0;
+	virtual void ResetProbeCounter() = 0;
+};
+
+} // namespace Util
+} // namespace PresenceDetection
+
+#endif // UTIL_PROBEABLEDEVICE_H

+ 184 - 0
Util/StaticDevice.cpp

@@ -0,0 +1,184 @@
+#include "StaticDevice.h"
+#include <algorithm>
+
+
+namespace PresenceDetection {
+namespace Util {
+
+StaticDevice::StaticDevice(const std::string& wifiMac, const std::string& bluetoothMac) :
+	m_probeCounter(0),
+	m_wifiMac(wifiMac),
+	m_wifiState(false),
+	m_bluetoothMac(bluetoothMac),
+	m_bluetoothState(false)
+{
+	std::transform(m_wifiMac.begin(), m_wifiMac.end(), m_wifiMac.begin(), ::tolower);
+	std::transform(m_bluetoothMac.begin(), m_bluetoothMac.end(), m_bluetoothMac.begin(), ::tolower);
+}
+
+StaticDevice::StaticDevice(const StaticDevice &other) :
+	m_probeCounter(other.m_probeCounter),
+	m_wifiMac(other.m_wifiMac),
+	m_wifiState(other.m_wifiState),
+	m_bluetoothMac(other.m_bluetoothMac),
+	m_bluetoothState(other.m_bluetoothState),
+	m_onlineURL(other.m_onlineURL),
+	m_wifiOnlineURL(other.m_wifiOnlineURL),
+	m_bluetoothOnlineURL(other.m_bluetoothOnlineURL),
+	m_offlineURL(other.m_offlineURL),
+	m_wifiOfflineURL(other.m_wifiOfflineURL),
+	m_bluetoothOfflineURL(other.m_bluetoothOfflineURL)
+{
+}
+
+StaticDevice::~StaticDevice()
+{
+}
+
+int StaticDevice::ProbeCounter() const
+{
+	return m_probeCounter;
+}
+
+void StaticDevice::IncrementProbeCounter()
+{
+	++m_probeCounter;
+}
+
+void StaticDevice::ResetProbeCounter()
+{
+	m_probeCounter = 0;
+}
+
+bool StaticDevice::HasWifiMac() const
+{
+	return !m_wifiMac.empty();
+}
+
+std::string StaticDevice::WifiMac() const
+{
+	return m_wifiMac;
+}
+
+void StaticDevice::SetWifiState(bool present)
+{
+	m_wifiState = present;
+}
+
+bool StaticDevice::GetWifiState() const
+{
+	return m_wifiState;
+}
+
+bool StaticDevice::HasBluetoothMac() const
+{
+	return !m_bluetoothMac.empty();
+}
+
+std::string StaticDevice::BluetoothMac() const
+{
+	return m_bluetoothMac;
+}
+
+void StaticDevice::SetBluetoothState(bool present)
+{
+	m_bluetoothState = present;
+}
+
+bool StaticDevice::GetBluetoothState() const
+{
+	return m_bluetoothState;
+}
+
+bool StaticDevice::HasOnlineURL() const
+{
+	return !m_onlineURL.empty();
+}
+
+void StaticDevice::SetOnlineURL(const std::string& url)
+{
+	m_onlineURL = url;
+}
+
+std::string StaticDevice::OnlineURL() const
+{
+	return m_onlineURL;
+}
+
+bool StaticDevice::HasWifiOnlineURL() const
+{
+	return !m_wifiOnlineURL.empty();
+}
+
+void StaticDevice::SetWifiOnlineURL(const std::string& url)
+{
+	m_wifiOnlineURL = url;
+}
+
+std::string StaticDevice::WifiOnlineURL() const
+{
+	return m_wifiOnlineURL;
+}
+
+bool StaticDevice::HasBluetoothOnlineURL() const
+{
+	return !m_bluetoothOnlineURL.empty();
+}
+
+void StaticDevice::SetBluetoothOnlineURL(const std::string& url)
+{
+	m_bluetoothOnlineURL = url;
+}
+
+std::string StaticDevice::BluetoothOnlineURL() const
+{
+	return m_bluetoothOnlineURL;
+}
+
+bool StaticDevice::HasOfflineURL() const
+{
+	return !m_offlineURL.empty();
+}
+
+void StaticDevice::SetOfflineURL(const std::string& url)
+{
+	m_offlineURL = url;
+}
+
+std::string StaticDevice::OfflineURL() const
+{
+	return m_offlineURL;
+}
+
+bool StaticDevice::HasWifiOfflineURL() const
+{
+	return !m_wifiOfflineURL.empty();
+}
+
+void StaticDevice::SetWifiOfflineURL(const std::string& url)
+{
+	m_wifiOfflineURL = url;
+}
+
+std::string StaticDevice::WifiOfflineURL() const
+{
+	return m_wifiOfflineURL;
+}
+
+bool StaticDevice::HasBluetoothOfflineURL() const
+{
+	return !m_bluetoothOfflineURL.empty();
+}
+
+void StaticDevice::SetBluetoothOfflineURL(const std::string& url)
+{
+	m_bluetoothOfflineURL = url;
+}
+
+std::string StaticDevice::BluetoothOfflineURL() const
+{
+	return m_bluetoothOfflineURL;
+}
+
+} // namespace Util
+} // namespace PresenceDetection

+ 14 - 7
Util/Device.h → Util/StaticDevice.h

@@ -1,18 +1,23 @@
-#ifndef UTIL_DEVICE_H
-#define UTIL_DEVICE_H
+#ifndef UTIL_STATICDEVICE_H
+#define UTIL_STATICDEVICE_H
 
+#include "ProbeableDevice.h"
 #include <string>
 
 
 namespace PresenceDetection {
 namespace Util {
 
-class Device
+class StaticDevice : public ProbeableDevice
 {
 public:
-	Device(const std::string& wifiMac, const std::string& bluetoothMac);
-	Device(const Device &other);
-	~Device();
+	StaticDevice(const std::string& wifiMac, const std::string& bluetoothMac);
+	StaticDevice(const StaticDevice &other);
+	~StaticDevice();
+
+	virtual int ProbeCounter() const override;
+	virtual void IncrementProbeCounter() override;
+	virtual void ResetProbeCounter() override;
 
 	bool HasWifiMac() const;
 	std::string WifiMac() const;
@@ -45,6 +50,8 @@ public:
 	std::string BluetoothOfflineURL() const;
 
 private:
+	int m_probeCounter;
+
 	std::string m_wifiMac;
 	bool m_wifiState;
 
@@ -62,4 +69,4 @@ private:
 } // namespace Util
 } // namespace PresenceDetection
 
-#endif // UTIL_DEVICE_H
+#endif // UTIL_STATICDEVICE_H