summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthew Barth <msbarth@us.ibm.com>2017-08-04 11:18:28 -0500
committerMatthew Barth <msbarth@us.ibm.com>2017-08-07 15:30:10 -0500
commit604329ef36d8ba2cd324f7132427d7e5724c074e (patch)
tree20b319dc2ff32e408ef0cb6bad272d2ea749c299
parenteb639c575a7964b849117cc70b6102f17a2dc32a (diff)
downloadphosphor-fan-presence-604329ef36d8ba2cd324f7132427d7e5724c074e.tar.gz
phosphor-fan-presence-604329ef36d8ba2cd324f7132427d7e5724c074e.zip
Add precondition that checks property states
The property state check precondition validates that each given property matches the defined value. When all the precondition groups' property states match, the given set speed event is initialized and activated allowing the zone speeds to be active controlled. Change-Id: Ic16a0e1fc584c6fa695e354fa80fb1993002ffc7 Signed-off-by: Matthew Barth <msbarth@us.ibm.com>
-rw-r--r--control/preconditions.hpp38
-rw-r--r--control/zone.cpp21
-rw-r--r--control/zone.hpp30
3 files changed, 74 insertions, 15 deletions
diff --git a/control/preconditions.hpp b/control/preconditions.hpp
index 61a2f50..3bceb19 100644
--- a/control/preconditions.hpp
+++ b/control/preconditions.hpp
@@ -1,5 +1,7 @@
#pragma once
+#include <algorithm>
+
namespace phosphor
{
namespace fan
@@ -31,9 +33,39 @@ auto property_states_match(std::vector<PrecondGroup>&& pg,
return [pg = std::move(pg),
sse = std::move(sse)](auto& zone, auto& group)
{
- // TODO Read/Compare given precondition entries
- // TODO Only init the event when the precondition(s) are true
- // TODO Remove the event properties when the precondition(s) are false
+ // Compare given precondition entries
+ size_t precondState = std::count_if(
+ pg.begin(),
+ pg.end(),
+ [&zone](auto const& entry)
+ {
+ try
+ {
+ return zone.getPropValueVariant(
+ std::get<pcPathPos>(entry),
+ std::get<pcIntfPos>(entry),
+ std::get<pcPropPos>(entry)) ==
+ std::get<pcValuePos>(entry);
+ }
+ catch (const std::out_of_range& oore)
+ {
+ // Default to property variants not equal when not found
+ return false;
+ }
+ });
+
+ // Update group's fan control active allowed
+ zone.setActiveAllow(&group, (precondState == pg.size()));
+ if (precondState == pg.size())
+ {
+ // Init the event when all the precondition(s) are true
+ zone.initEvent(sse);
+ }
+ else
+ {
+ zone.setFullSpeed();
+ // TODO Unsubscribe the event signals when any precondition is false
+ }
};
}
diff --git a/control/zone.cpp b/control/zone.cpp
index 4fb60cd..55aae9d 100644
--- a/control/zone.cpp
+++ b/control/zone.cpp
@@ -175,12 +175,23 @@ void Zone::decTimerExpired()
void Zone::initEvent(const SetSpeedEvent& event)
{
// Get the current value for each property
- for (auto& entry : std::get<groupPos>(event))
+ for (auto& group : std::get<groupPos>(event))
{
- refreshProperty(_bus,
- entry.first,
- std::get<intfPos>(entry.second),
- std::get<propPos>(entry.second));
+ try
+ {
+ refreshProperty(_bus,
+ group.first,
+ std::get<intfPos>(group.second),
+ std::get<propPos>(group.second));
+ }
+ catch (const InternalFailure& ife)
+ {
+ log<level::ERR>(
+ "Unable to find property: ",
+ entry("PATH=%s", group.first.c_str()),
+ entry("INTERFACE=%s", std::get<intfPos>(group.second).c_str()),
+ entry("PROPERTY=%s", std::get<propPos>(group.second).c_str()));
+ }
}
// Setup signal matches for property change events
for (auto& prop : std::get<propChangeListPos>(event))
diff --git a/control/zone.hpp b/control/zone.hpp
index 077bfcf..f618c10 100644
--- a/control/zone.hpp
+++ b/control/zone.hpp
@@ -119,6 +119,29 @@ class Zone
};
/**
+ * @brief Get the object's property variant
+ *
+ * @param[in] object - Name of the object containing the property
+ * @param[in] interface - Interface name containing the property
+ * @param[in] property - Property name
+ *
+ * @return - The property variant
+ */
+ inline auto getPropValueVariant(const std::string& object,
+ const std::string& interface,
+ const std::string& property)
+ {
+ return _properties.at(object).at(interface).at(property);
+ };
+
+ /**
+ * @brief Initialize a set speed event properties and actions
+ *
+ * @param[in] event - Set speed event
+ */
+ void initEvent(const SetSpeedEvent& event);
+
+ /**
* @brief Get the default floor speed
*
* @return - The defined default floor speed
@@ -329,13 +352,6 @@ class Zone
std::vector<sdbusplus::server::match::match> _matches;
/**
- * @brief Initialize a set speed event properties and actions
- *
- * @param[in] event - Set speed event
- */
- void initEvent(const SetSpeedEvent& event);
-
- /**
* @brief Refresh the given property's cached value
*
* @param[in] bus - the bus to use
OpenPOWER on IntegriCloud