From e59fdf707514ed00fa1ab432a052de1fac07b56c Mon Sep 17 00:00:00 2001 From: Matthew Barth Date: Wed, 27 Sep 2017 09:33:42 -0500 Subject: Set/update a service name owner for a group Adds a service name associated with a group when the group or given service name is not found within the map of services otherwise updates the service name owner associated with the group. Change-Id: I602ddaa7e06e354e01ea70d6c5c0a45e74a14e99 Signed-off-by: Matthew Barth --- control/types.hpp | 4 ++++ control/zone.cpp | 30 ++++++++++++++++++++++++++++++ control/zone.hpp | 16 ++++++++++++++++ 3 files changed, 50 insertions(+) (limited to 'control') diff --git a/control/types.hpp b/control/types.hpp index d3ddb16..915b8b4 100644 --- a/control/types.hpp +++ b/control/types.hpp @@ -53,6 +53,10 @@ using PrecondGroup = std::tuple; +constexpr auto namePos = 0; +constexpr auto hasOwnerPos = 1; +using Service = std::tuple; + constexpr auto intervalPos = 0; using Timer = std::tuple; diff --git a/control/zone.cpp b/control/zone.cpp index 3d7852e..b9a7583 100644 --- a/control/zone.cpp +++ b/control/zone.cpp @@ -115,6 +115,36 @@ void Zone::setActiveAllow(const Group* group, bool isActiveAllow) } } +void Zone::setServiceOwner(const Group* group, + const std::string& name, + const bool hasOwner) +{ + 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)) + { + std::get(*it) = hasOwner; + } + else + { + _services[*group].emplace_back(name, hasOwner); + } + } + catch (const std::out_of_range& oore) + { + _services[*group].emplace_back(name, hasOwner); + } +} + void Zone::setFloor(uint64_t speed) { _floorSpeed = speed; diff --git a/control/zone.hpp b/control/zone.hpp index 8869f91..9c08032 100644 --- a/control/zone.hpp +++ b/control/zone.hpp @@ -127,6 +127,17 @@ class Zone return _properties.at(object).at(interface).at(property); }; + /** + * @brief Set or update a service name owner in use + * + * @param[in] group - Group associated with service + * @param[in] name - Service name + * @param[in] hasOwner - Whether the service is owned or not + */ + void setServiceOwner(const Group* group, + const std::string& name, + const bool hasOwner); + /** * @brief Initialize a set speed event properties and actions * @@ -371,6 +382,11 @@ class Zone */ std::map _active; + /** + * @brief Map of group service names + */ + std::map> _services; + /** * @brief List of signal event arguments and Dbus matches for callbacks */ -- cgit v1.2.1