summaryrefslogtreecommitdiffstats
path: root/control
diff options
context:
space:
mode:
authorMatthew Barth <msbarth@us.ibm.com>2017-09-11 16:07:58 -0500
committerMatthew Barth <msbarth@us.ibm.com>2017-09-18 10:35:10 -0500
commitf9201abb8ca5a30220b05f3bbaa2db9343699a80 (patch)
tree35643a2081fc4be8f9d9c1f1576b4211294b04f4 /control
parent6ad28430764b7d16ee7abcb9965b76ea5583008f (diff)
downloadphosphor-fan-presence-f9201abb8ca5a30220b05f3bbaa2db9343699a80.tar.gz
phosphor-fan-presence-f9201abb8ca5a30220b05f3bbaa2db9343699a80.zip
Support a list of actions for a set speed event
Each set speed event will contain a list of one-to-many actions to perform for the given event group's property. This reduces the amount of code generated and properly handles property changed events against the group. Change-Id: If2b8c0d0b8ecf6e1c974c43d96e1c6e9e952022b Signed-off-by: Matthew Barth <msbarth@us.ibm.com>
Diffstat (limited to 'control')
-rw-r--r--control/preconditions.hpp22
-rw-r--r--control/types.hpp8
-rw-r--r--control/zone.cpp72
-rw-r--r--control/zone.hpp8
4 files changed, 78 insertions, 32 deletions
diff --git a/control/preconditions.hpp b/control/preconditions.hpp
index 65eb0e2..f989f0d 100644
--- a/control/preconditions.hpp
+++ b/control/preconditions.hpp
@@ -28,7 +28,7 @@ namespace precondition
* and either subscribe or unsubscribe a set speed event group.
*/
auto property_states_match(std::vector<PrecondGroup>&& pg,
- SetSpeedEvent&& sse)
+ std::vector<SetSpeedEvent>&& sse)
{
return [pg = std::move(pg),
sse = std::move(sse)](auto& zone, auto& group)
@@ -56,13 +56,25 @@ auto property_states_match(std::vector<PrecondGroup>&& pg,
if (precondState == pg.size())
{
- // Init the event when all the precondition(s) are true
- zone.initEvent(sse);
+ // Init the events when all the precondition(s) are true
+ std::for_each(
+ sse.begin(),
+ sse.end(),
+ [&zone](auto const& entry)
+ {
+ zone.initEvent(entry);
+ });
}
else
{
- // Unsubscribe the event signals when any precondition is false
- zone.removeEvent(sse);
+ // Unsubscribe the events' signals when any precondition is false
+ std::for_each(
+ sse.begin(),
+ sse.end(),
+ [&zone](auto const& entry)
+ {
+ zone.removeEvent(entry);
+ });
zone.setFullSpeed();
}
// Update group's fan control active allowed
diff --git a/control/types.hpp b/control/types.hpp
index b788ac5..a670810 100644
--- a/control/types.hpp
+++ b/control/types.hpp
@@ -61,18 +61,18 @@ constexpr auto handlerObjPos = 1;
using PropertyChange = std::tuple<std::string, Handler>;
constexpr auto groupPos = 0;
-constexpr auto actionPos = 1;
+constexpr auto actionsPos = 1;
constexpr auto timerPos = 2;
constexpr auto propChangeListPos = 3;
using SetSpeedEvent = std::tuple<Group,
- Action,
+ std::vector<Action>,
Timer,
std::vector<PropertyChange>>;
constexpr auto eventGroupPos = 0;
constexpr auto eventHandlerPos = 1;
-constexpr auto eventActionPos = 2;
-using EventData = std::tuple<Group, Handler, Action>;
+constexpr auto eventActionsPos = 2;
+using EventData = std::tuple<Group, Handler, std::vector<Action>>;
constexpr auto timerTimerPos = 0;
using TimerEvent = std::tuple<phosphor::fan::util::Timer>;
diff --git a/control/zone.cpp b/control/zone.cpp
index 4d31ecf..3eab42f 100644
--- a/control/zone.cpp
+++ b/control/zone.cpp
@@ -222,7 +222,7 @@ void Zone::initEvent(const SetSpeedEvent& event)
{
std::get<groupPos>(event),
std::get<handlerObjPos>(prop),
- std::get<actionPos>(event)
+ std::get<actionsPos>(event)
}
);
std::unique_ptr<sdbusplus::server::match::match> match =
@@ -244,7 +244,7 @@ void Zone::initEvent(const SetSpeedEvent& event)
std::make_unique<util::Timer>(
_sdEvents,
[this,
- action = &(std::get<actionPos>(event)),
+ action = &(std::get<actionsPos>(event)),
group = &(std::get<groupPos>(event))]()
{
this->timerExpired(*group, *action);
@@ -256,9 +256,15 @@ void Zone::initEvent(const SetSpeedEvent& event)
}
_timerEvents.emplace_back(std::move(timer));
}
- // Run action function for initial event state
- std::get<actionPos>(event)(*this,
- std::get<groupPos>(event));
+ // Run action functions for initial event state
+ std::for_each(
+ std::get<actionsPos>(event).begin(),
+ std::get<actionsPos>(event).end(),
+ [this, &event](auto const& action)
+ {
+ action(*this,
+ std::get<groupPos>(event));
+ });
}
void Zone::removeEvent(const SetSpeedEvent& event)
@@ -270,14 +276,31 @@ void Zone::removeEvent(const SetSpeedEvent& event)
[&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 (std::get<eventActionsPos>(seEventData).size() !=
+ std::get<actionsPos>(event).size())
+ {
+ return false;
+ }
+ else
+ {
+ // TODO openbmc/openbmc#2328 - Use the action function target
+ // for comparison
+ auto actsEqual = [](auto const& a1,
+ auto const& a2)
+ {
+ return a1.target_type().name() ==
+ a2.target_type().name();
+ };
+ return
+ (
+ std::get<eventGroupPos>(seEventData) ==
+ std::get<groupPos>(event) &&
+ std::equal(std::get<actionsPos>(event).begin(),
+ std::get<actionsPos>(event).end(),
+ std::get<eventActionsPos>(seEventData).begin(),
+ actsEqual)
+ );
+ }
});
if (it != std::end(_signalEvents))
{
@@ -319,10 +342,15 @@ void Zone::getProperty(sdbusplus::bus::bus& bus,
hostResponseMsg.read(value);
}
-void Zone::timerExpired(Group eventGroup, Action eventAction)
+void Zone::timerExpired(Group eventGroup, std::vector<Action> eventActions)
{
- // Perform the action
- eventAction(*this, eventGroup);
+ // Perform the actions
+ std::for_each(eventActions.begin(),
+ eventActions.end(),
+ [this, &eventGroup](auto const& action)
+ {
+ action(*this, eventGroup);
+ });
}
void Zone::handleEvent(sdbusplus::message::message& msg,
@@ -330,9 +358,15 @@ void Zone::handleEvent(sdbusplus::message::message& msg,
{
// Handle the callback
std::get<eventHandlerPos>(*eventData)(_bus, msg, *this);
- // Perform the action
- std::get<eventActionPos>(*eventData)(*this,
- std::get<eventGroupPos>(*eventData));
+ // Perform the actions
+ std::for_each(
+ std::get<eventActionsPos>(*eventData).begin(),
+ std::get<eventActionsPos>(*eventData).end(),
+ [this, &eventData](auto const& action)
+ {
+ action(*this,
+ std::get<eventGroupPos>(*eventData));
+ });
}
}
diff --git a/control/zone.hpp b/control/zone.hpp
index cb1ce69..bc21b9f 100644
--- a/control/zone.hpp
+++ b/control/zone.hpp
@@ -243,12 +243,12 @@ class Zone
/**
* @brief Callback function for event timers that processes the given
- * action for a group
+ * actions for a group
*
- * @param[in] eventGroup - Group to process action on
- * @param[in] eventAction - Event action to run
+ * @param[in] eventGroup - Group to process actions on
+ * @param[in] eventActions - List of event actions to run
*/
- void timerExpired(Group eventGroup, Action eventAction);
+ void timerExpired(Group eventGroup, std::vector<Action> eventActions);
private:
OpenPOWER on IntegriCloud