Remove set speed event
Allows the complete removal of a set speed event from the zone. This is
done when any precondition defined for the event to be active is not
met any longer.
Change-Id: Idbec357f76f0fd7db9107e8c9d3e00461872c528
Signed-off-by: Matthew Barth <msbarth@us.ibm.com>
diff --git a/control/zone.cpp b/control/zone.cpp
index 55aae9d..cef375c 100644
--- a/control/zone.cpp
+++ b/control/zone.cpp
@@ -196,27 +196,57 @@
// Setup signal matches for property change events
for (auto& prop : std::get<propChangeListPos>(event))
{
- _signalEvents.emplace_back(
- std::make_unique<EventData>(
- EventData
- {
- std::get<groupPos>(event),
- std::get<handlerObjPos>(prop),
- std::get<actionPos>(event)
- }));
- _matches.emplace_back(
+ std::unique_ptr<EventData> eventData =
+ std::make_unique<EventData>(
+ EventData
+ {
+ std::get<groupPos>(event),
+ std::get<handlerObjPos>(prop),
+ std::get<actionPos>(event)
+ }
+ );
+ std::unique_ptr<sdbusplus::server::match::match> match =
+ std::make_unique<sdbusplus::server::match::match>(
_bus,
std::get<signaturePos>(prop).c_str(),
std::bind(std::mem_fn(&Zone::handleEvent),
this,
std::placeholders::_1,
- _signalEvents.back().get()));
+ eventData.get())
+ );
+ _signalEvents.emplace_back(std::move(eventData), std::move(match));
}
// Run action function for initial event state
std::get<actionPos>(event)(*this,
std::get<groupPos>(event));
}
+void Zone::removeEvent(const SetSpeedEvent& event)
+{
+ // Find the signal event to be removed
+ auto it = std::find_if(
+ _signalEvents.begin(),
+ _signalEvents.end(),
+ [&event](auto const& se)
+ {
+ auto seEventData = *std::get<signalEventDataPos>(se);
+ // TODO Use the action function target for comparison
+ return
+ (
+ std::get<eventGroupPos>(seEventData) ==
+ std::get<groupPos>(event) &&
+ std::get<eventActionPos>(seEventData).target_type().name() ==
+ std::get<actionPos>(event).target_type().name()
+ );
+ });
+ if (it != std::end(_signalEvents))
+ {
+ std::get<signalEventDataPos>(*it).reset();
+ std::get<signalMatchPos>(*it).reset();
+ _signalEvents.erase(it);
+ }
+}
+
void Zone::refreshProperty(sdbusplus::bus::bus& bus,
const std::string& path,
const std::string& iface,