Update Naming and Tests
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
#include "Device.h"
|
||||
#include "Driver.h"
|
||||
#include "Functions.h"
|
||||
#include <json.hpp>
|
||||
#include <Logging.h>
|
||||
@@ -9,7 +9,7 @@
|
||||
namespace PresenceDetection {
|
||||
namespace Bluetooth {
|
||||
|
||||
Device::Device(int timeout, const std::string& inventoryURL, const std::string& target, const std::vector<Util::StaticDevice>& staticDevices) :
|
||||
Driver::Driver(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),
|
||||
@@ -22,33 +22,33 @@ Device::Device(int timeout, const std::string& inventoryURL, const std::string&
|
||||
Start();
|
||||
}
|
||||
|
||||
Device::~Device()
|
||||
Driver::~Driver()
|
||||
{
|
||||
}
|
||||
|
||||
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(600000, static_cast<std::function<void()>>(std::bind(&Device::UpdateDevicesFromInventory, this)));
|
||||
m_inventoryTimer.StartContinuous(600000, 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.Wait();
|
||||
}
|
||||
|
||||
void Device::ClearDevices()
|
||||
void Driver::ClearDevices()
|
||||
{
|
||||
for (std::vector<Util::DynamicDevice>::iterator it = m_dynamicDevices.begin(); it != m_dynamicDevices.end(); ++it)
|
||||
{
|
||||
@@ -59,7 +59,7 @@ void Device::ClearDevices()
|
||||
catch (const std::exception& e)
|
||||
{
|
||||
std::stringstream ss;
|
||||
ss << "Bluetooth::Device::ClearDevices() - Error: " << e.what() << std::endl;
|
||||
ss << "Bluetooth::Driver::ClearDevices() - Error: " << e.what() << std::endl;
|
||||
Logging::Log(Logging::Severity::Error, ss.str());
|
||||
}
|
||||
}
|
||||
@@ -75,14 +75,14 @@ void Device::ClearDevices()
|
||||
catch (const std::exception& e)
|
||||
{
|
||||
std::stringstream ss;
|
||||
ss << "Bluetooth::Device::ClearDevices() - Error: " << e.what() << std::endl;
|
||||
ss << "Bluetooth::Driver::ClearDevices() - Error: " << e.what() << std::endl;
|
||||
Logging::Log(Logging::Severity::Error, ss.str());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Device::UpdateDevicesFromInventory()
|
||||
void Driver::UpdateDevicesFromInventory()
|
||||
{
|
||||
try
|
||||
{
|
||||
@@ -102,12 +102,12 @@ void Device::UpdateDevicesFromInventory()
|
||||
catch (const std::exception& e)
|
||||
{
|
||||
std::stringstream ss;
|
||||
ss << "Bluetooth::Device::GetDevicesFromInventory() - Error: " << e.what() << std::endl;
|
||||
ss << "Bluetooth::Driver::GetDevicesFromInventory() - Error: " << e.what() << std::endl;
|
||||
Logging::Log(Logging::Severity::Error, ss.str());
|
||||
}
|
||||
}
|
||||
|
||||
void Device::UpdatePresentDevices()
|
||||
void Driver::UpdatePresentDevices()
|
||||
{
|
||||
std::vector<std::string> presentDevices;
|
||||
std::vector<std::string> ignoredDevices;
|
||||
@@ -149,7 +149,7 @@ void Device::UpdatePresentDevices()
|
||||
catch (const std::exception& e)
|
||||
{
|
||||
std::stringstream ss;
|
||||
ss << "Bluetooth::Device::UpdatePresentDevices() - Error: " << e.what() << std::endl;
|
||||
ss << "Bluetooth::Driver::UpdatePresentDevices() - Error: " << e.what() << std::endl;
|
||||
Logging::Log(Logging::Severity::Error, ss.str());
|
||||
}
|
||||
}
|
||||
@@ -193,7 +193,7 @@ void Device::UpdatePresentDevices()
|
||||
catch (const std::exception& e)
|
||||
{
|
||||
std::stringstream ss;
|
||||
ss << "Bluetooth::Device::UpdatePresentDevices() - Error: " << e.what() << std::endl;
|
||||
ss << "Bluetooth::Driver::UpdatePresentDevices() - Error: " << e.what() << std::endl;
|
||||
Logging::Log(Logging::Severity::Error, ss.str());
|
||||
}
|
||||
}
|
||||
@@ -211,7 +211,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)
|
||||
@@ -237,7 +237,7 @@ void Device::SendStateChange(bool present, const std::string& macAddress)
|
||||
catch (const std::exception& e)
|
||||
{
|
||||
std::stringstream ss;
|
||||
ss << "Bluetooth::Device::SendStateChange() - Error: " << e.what() << std::endl;
|
||||
ss << "Bluetooth::Driver::SendStateChange() - Error: " << e.what() << std::endl;
|
||||
Logging::Log(Logging::Severity::Error, ss.str());
|
||||
}
|
||||
}
|
||||
@@ -276,7 +276,7 @@ void Device::SendStateChange(bool present, const std::string& macAddress)
|
||||
catch (const std::exception& e)
|
||||
{
|
||||
std::stringstream ss;
|
||||
ss << "Bluetooth::Device::SendStateChange() - Error: " << e.what() << std::endl;
|
||||
ss << "Bluetooth::Driver::SendStateChange() - Error: " << e.what() << std::endl;
|
||||
Logging::Log(Logging::Severity::Error, ss.str());
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
#ifndef BLUETOOTH_DEVICE_H
|
||||
#define BLUETOOTH_DEVICE_H
|
||||
#ifndef BLUETOOTH_DRIVER_H
|
||||
#define BLUETOOTH_DRIVER_H
|
||||
|
||||
#include "Util/DynamicDevice.h"
|
||||
#include "Util/StaticDevice.h"
|
||||
@@ -12,11 +12,11 @@
|
||||
namespace PresenceDetection {
|
||||
namespace Bluetooth {
|
||||
|
||||
class Device
|
||||
class Driver
|
||||
{
|
||||
public:
|
||||
Device(int timeout, const std::string& inventoryURL, const std::string& target, const std::vector<Util::StaticDevice>& staticDevices);
|
||||
~Device();
|
||||
Driver(int timeout, const std::string& inventoryURL, const std::string& target, const std::vector<Util::StaticDevice>& staticDevices);
|
||||
~Driver();
|
||||
|
||||
void Start();
|
||||
void Stop();
|
||||
@@ -47,4 +47,4 @@ private:
|
||||
} // namespace Bluetooth
|
||||
} // namespace PresenceDetection
|
||||
|
||||
#endif // BLUETOOTH_DEVICE_H
|
||||
#endif // BLUETOOTH_DRIVER_H
|
||||
@@ -43,8 +43,8 @@ bool Functions::Ping(const std::string& macAddress)
|
||||
str2ba(macAddress.c_str(), &socketAddress.l2_bdaddr);
|
||||
|
||||
struct timeval timeoutStruct;
|
||||
timeoutStruct.tv_sec = 3;
|
||||
timeoutStruct.tv_usec = 0;
|
||||
timeoutStruct.tv_sec = 1;
|
||||
timeoutStruct.tv_usec = 0; //500000;
|
||||
|
||||
fd_set writeDescriptor, errorDescriptor;
|
||||
FD_ZERO(&writeDescriptor);
|
||||
@@ -68,7 +68,7 @@ bool Functions::Ping(const std::string& macAddress)
|
||||
|
||||
if (ret != 0)
|
||||
{
|
||||
if (select(socketDescriptor + 1, &errorDescriptor, &writeDescriptor, NULL, &timeoutStruct) < 0)
|
||||
if (select(socketDescriptor + 1, &errorDescriptor, &writeDescriptor, NULL, &timeoutStruct) <= 0)
|
||||
return false;
|
||||
|
||||
int error = 0;
|
||||
@@ -125,7 +125,7 @@ bool Functions::Ping(const std::string& macAddress)
|
||||
pf[0].events = POLLIN;
|
||||
|
||||
int err;
|
||||
int timeout = 500;
|
||||
int timeout = 200;
|
||||
if ((err = poll(pf, 1, timeout)) < 0)
|
||||
throw std::runtime_error("Poll failed");
|
||||
|
||||
|
||||
Reference in New Issue
Block a user