From 55dea64300f44adc5146da3764ab52d39b546518 Mon Sep 17 00:00:00 2001 From: Matthew Barth Date: Mon, 6 Nov 2017 13:34:32 -0600 Subject: Remove empty service name Before refreshing the service names and states for a group, the empty service name should be removed if it exists. An empty service name may exist where upon startup, a particular service was not found for a member or members of a group. Change-Id: I15d224231bb9db0823866393ec1776f793a3c126 Signed-off-by: Matthew Barth --- control/zone.cpp | 29 ++++++++++++++++++++++++++++- control/zone.hpp | 9 +++++++++ 2 files changed, 37 insertions(+), 1 deletion(-) (limited to 'control') diff --git a/control/zone.cpp b/control/zone.cpp index 5fe9b01..784004e 100644 --- a/control/zone.cpp +++ b/control/zone.cpp @@ -120,6 +120,32 @@ void Zone::setActiveAllow(const Group* group, bool isActiveAllow) } } +void Zone::removeService(const Group* group, + const std::string& name) +{ + try + { + auto& sNames = _services.at(*group); + auto it = std::find_if( + sNames.begin(), + sNames.end(), + [&name](auto const& entry) + { + return name == std::get(entry); + } + ); + if (it != std::end(sNames)) + { + // Remove service name from group + sNames.erase(it); + } + } + catch (const std::out_of_range& oore) + { + // No services for group found + } +} + void Zone::setServiceOwner(const Group* group, const std::string& name, const bool hasOwner) @@ -152,7 +178,8 @@ void Zone::setServiceOwner(const Group* group, void Zone::setServices(const Group* group) { - // TODO Remove empty service name if exists + // Remove the empty service name if exists + removeService(group, ""); for (auto it = group->begin(); it != group->end(); ++it) { std::string name; diff --git a/control/zone.hpp b/control/zone.hpp index 9565933..dbf4378 100644 --- a/control/zone.hpp +++ b/control/zone.hpp @@ -139,6 +139,15 @@ class Zone return _properties.at(object).at(interface).at(property); }; + /** + * @brief Remove a service associated to a group + * + * @param[in] group - Group associated with service + * @param[in] name - Service name to remove + */ + void removeService(const Group* group, + const std::string& name); + /** * @brief Set or update a service name owner in use * -- cgit v1.2.1