Add Static Devices

This commit is contained in:
2020-05-01 11:39:46 +02:00
parent 157b1ceb51
commit 21dbdd41d9
12 changed files with 400 additions and 327 deletions
+19 -14
View File
@@ -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();