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 <msbarth@us.ibm.com>
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::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<namePos>(entry);
+ }
+ );
+ if (it != std::end(sNames))
+ {
+ std::get<hasOwnerPos>(*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;