Generate sensor to trust association
Each sensor listed to be associated with a trust group is defined to
either be part of the trust group or just affected by the results of the
trust group. This is denoted by defining an "in_trust" boolean attribute
that will include the sensor in the trust group for determination of
trust when true, otherwise only be included in the resulting trust
affect when defined as false.
When no "in_trust" attribute is given, the sensor is defaulted to be
included in the trust group determining trust.
Tested: Current trust group associations & reactions are unchanged
Change-Id: I717074bc1a32a07dc59f172a4c823c7e2bb84f8c
Signed-off-by: Matthew Barth <msbarth@us.ibm.com>
diff --git a/monitor/gen-fan-monitor-defs.py b/monitor/gen-fan-monitor-defs.py
index 965625b..7a1b874 100755
--- a/monitor/gen-fan-monitor-defs.py
+++ b/monitor/gen-fan-monitor-defs.py
@@ -57,12 +57,15 @@
##If a group were to ever need a different constructor,
##it could be handled here.
<%def name="get_lambda_contents(group)">
- std::vector<std::string> names{
- %for sensor in group['sensors']:
- "${sensor['name']}",
+ std::vector<GroupDefinition> group{
+ %for member in group['group']:
+ <%
+ in_trust = str(member.get('in_trust', "true")).lower()
+ %>
+ GroupDefinition{"${member['name']}", ${in_trust}},
%endfor
};
- return std::make_unique<${group['class']}>(names);
+ return std::make_unique<${group['class']}>(group);
</%def>
const std::vector<CreateGroupFunction> trustGroups
{
diff --git a/monitor/nonzero_speed_trust.hpp b/monitor/nonzero_speed_trust.hpp
index 93fce7d..e1f787f 100644
--- a/monitor/nonzero_speed_trust.hpp
+++ b/monitor/nonzero_speed_trust.hpp
@@ -30,9 +30,10 @@
/**
* Constructor
*
- * @param[in] names - the names of the sensors in the group
+ * @param[in] names - the names of the sensors and its inclusion in
+ * determining trust for the group
*/
- explicit NonzeroSpeed(const std::vector<std::string>& names) :
+ explicit NonzeroSpeed(const std::vector<GroupDefinition>& names) :
Group(names)
{
}
@@ -53,7 +54,7 @@
_sensors.end(),
[](const auto& s)
{
- return s->getInput() != 0;
+ return std::get<0>(s)->getInput() != 0;
});
}
};
diff --git a/monitor/trust_group.hpp b/monitor/trust_group.hpp
index ff60508..7f28f6c 100644
--- a/monitor/trust_group.hpp
+++ b/monitor/trust_group.hpp
@@ -9,6 +9,11 @@
namespace trust
{
+constexpr auto sensorName = 0;
+constexpr auto inTrust = 1;
+using GroupDefinition = std::tuple<std::string,
+ bool>;
+
/**
* @class Group
*
@@ -43,9 +48,9 @@
/**
* Constructor
*
- * @param[in] names - the names of the sensors in the group
+ * @param[in] names - the names and inclusion of sensors in the group
*/
- explicit Group(const std::vector<std::string>& names) :
+ explicit Group(const std::vector<GroupDefinition>& names) :
_names(names)
{
}
@@ -65,12 +70,13 @@
[&sensor](const auto& name)
{
return monitor::FAN_SENSOR_PATH +
- name == sensor->name();
+ std::get<sensorName>(name) == sensor->name();
});
if (found != _names.end())
{
- _sensors.push_back(sensor);
+ auto gs = std::make_tuple(sensor, std::get<inTrust>(*found));
+ _sensors.push_back(gs);
}
}
@@ -89,7 +95,7 @@
_sensors.end(),
[&sensor](const auto& s)
{
- return sensor.name() == s->name();
+ return sensor.name() == std::get<0>(s)->name();
}) != _sensors.end());
}
@@ -107,7 +113,7 @@
_sensors.end(),
[](const auto& s)
{
- s->stopTimer();
+ std::get<0>(s)->stopTimer();
});
}
@@ -126,11 +132,11 @@
{
//If a sensor isn't functional, then its timer
//already expired so don't bother starting it again
- if (s->functional() &&
- static_cast<uint64_t>(s->getInput()) !=
- s->getTarget())
+ if (std::get<0>(s)->functional() &&
+ static_cast<uint64_t>(std::get<0>(s)->getInput()) !=
+ std::get<0>(s)->getTarget())
{
- s->startTimer();
+ std::get<0>(s)->startTimer();
}
});
}
@@ -190,11 +196,13 @@
protected:
/**
- * The sensor objects in the group.
+ * The sensor objects and their trust inclusion in the group.
*
* Added by registerSensor().
*/
- std::vector<std::shared_ptr<monitor::TachSensor>> _sensors;
+ std::vector<std::tuple<
+ std::shared_ptr<monitor::TachSensor>,
+ bool>> _sensors;
private:
@@ -230,9 +238,10 @@
bool _stateChange = false;
/**
- * The names of the sensors that should be added to this group
+ * The names of the sensors and whether it is included in
+ * determining trust for this group
*/
- const std::vector<std::string> _names;
+ const std::vector<GroupDefinition> _names;
};
}