|
|
@@ -71,7 +71,7 @@ bool Device::Login()
|
|
|
catch (const std::exception& e)
|
|
|
{
|
|
|
std::stringstream ss;
|
|
|
- ss << "UniFiDevice::Login() - Error: " << e.what() << std::endl;
|
|
|
+ ss << "UniFi::Device::Login() - Error: " << e.what() << std::endl;
|
|
|
syslog(LOG_ERR, "%s", ss.str().c_str());
|
|
|
std::lock_guard<std::mutex> lock(m_mutex);
|
|
|
m_loggedIn = false;
|
|
|
@@ -98,7 +98,7 @@ void Device::Logout()
|
|
|
catch (const std::exception& e)
|
|
|
{
|
|
|
std::stringstream ss;
|
|
|
- ss << "UniFiDevice::Logout() - Error: " << e.what() << std::endl;
|
|
|
+ ss << "UniFi::Device::Logout() - Error: " << e.what() << std::endl;
|
|
|
syslog(LOG_ERR, "%s", ss.str().c_str());
|
|
|
}
|
|
|
}
|
|
|
@@ -156,7 +156,7 @@ void Device::UpdatePresentDevices()
|
|
|
catch (const std::exception& e)
|
|
|
{
|
|
|
std::stringstream ss;
|
|
|
- ss << "UniFiDevice::IsDevicePresent() - Error: " << e.what() << std::endl;
|
|
|
+ ss << "UniFi::Device::IsDevicePresent() - Error: " << e.what() << std::endl;
|
|
|
syslog(LOG_ERR, "%s", ss.str().c_str());
|
|
|
Logout();
|
|
|
return;
|
|
|
@@ -167,48 +167,39 @@ void Device::UpdatePresentDevices()
|
|
|
removedDevices.push_back(*it);
|
|
|
|
|
|
for (std::vector<std::string>::iterator it = addedDevices.begin(); it != addedDevices.end(); ++it)
|
|
|
- {
|
|
|
- std::stringstream ss;
|
|
|
- ss << "UniFi: + " << *it;
|
|
|
- syslog(LOG_INFO, "%s", ss.str().c_str());
|
|
|
+ SendStateChange(true, *it);
|
|
|
|
|
|
- std::stringstream url;
|
|
|
- url << m_target << "/UniFi/+/" << *it;
|
|
|
+ for (std::vector<std::string>::iterator it = removedDevices.begin(); it != removedDevices.end(); ++it)
|
|
|
+ SendStateChange(false, *it);
|
|
|
|
|
|
- try
|
|
|
- {
|
|
|
- m_httpClient.GetUrlSilent(url.str());
|
|
|
- }
|
|
|
- catch (const std::exception& e)
|
|
|
- {
|
|
|
- std::stringstream ss;
|
|
|
- ss << "UniFiDevice::UpdatePresentDevices() - Error: " << e.what() << std::endl;
|
|
|
- syslog(LOG_ERR, "%s", ss.str().c_str());
|
|
|
- }
|
|
|
- }
|
|
|
+ m_presentDevices.assign(presentDevices.begin(), presentDevices.end());
|
|
|
+}
|
|
|
|
|
|
- for (std::vector<std::string>::iterator it = removedDevices.begin(); it != removedDevices.end(); ++it)
|
|
|
- {
|
|
|
- std::stringstream ss;
|
|
|
- ss << "UniFi: - " << *it;
|
|
|
- syslog(LOG_INFO, "%s", ss.str().c_str());
|
|
|
+void Device::SendStateChange(bool present, const std::string& macAddress)
|
|
|
+{
|
|
|
+ char sign;
|
|
|
+ if (present)
|
|
|
+ sign = '+';
|
|
|
+ else
|
|
|
+ sign = '-';
|
|
|
|
|
|
- std::stringstream url;
|
|
|
- url << m_target << "/UniFi/-/" << *it;
|
|
|
+ std::stringstream ss;
|
|
|
+ ss << "UniFi: " << sign << " " << macAddress;
|
|
|
+ syslog(LOG_INFO, "%s", ss.str().c_str());
|
|
|
|
|
|
- try
|
|
|
- {
|
|
|
- m_httpClient.GetUrlSilent(url.str());
|
|
|
- }
|
|
|
- catch (const std::exception& e)
|
|
|
- {
|
|
|
- std::stringstream ss;
|
|
|
- ss << "UniFiDevice::UpdatePresentDevices() - Error: " << e.what() << std::endl;
|
|
|
- syslog(LOG_ERR, "%s", ss.str().c_str());
|
|
|
- }
|
|
|
- }
|
|
|
+ std::stringstream url;
|
|
|
+ url << m_target << "/UniFi/" << sign << "/" << macAddress;
|
|
|
|
|
|
- m_presentDevices.assign(presentDevices.begin(), presentDevices.end());
|
|
|
+ try
|
|
|
+ {
|
|
|
+ m_httpClient.GetUrlSilent(url.str());
|
|
|
+ }
|
|
|
+ catch (const std::exception& e)
|
|
|
+ {
|
|
|
+ std::stringstream ss;
|
|
|
+ ss << "UniFi::Device::SendStateChange() - Error: " << e.what() << std::endl;
|
|
|
+ syslog(LOG_ERR, "%s", ss.str().c_str());
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
} // namespace UniFi
|