summaryrefslogtreecommitdiffstats
path: root/presence
diff options
context:
space:
mode:
authorBrad Bishop <bradleyb@fuzziesquirrel.com>2017-06-08 11:52:34 -0400
committerBrad Bishop <bradleyb@fuzziesquirrel.com>2017-07-08 16:52:38 -0400
commit1fd8f74126c14b72493e4e7bec2262999b85fdbe (patch)
treeb6db8faf5209ca1e091cd6cfe47e7fdaa84232d1 /presence
parent0dea38e52ba8c6e7ebda591d10ca910a8b65a0dc (diff)
downloadphosphor-fan-presence-1fd8f74126c14b72493e4e7bec2262999b85fdbe.tar.gz
phosphor-fan-presence-1fd8f74126c14b72493e4e7bec2262999b85fdbe.zip
presence: Add initialstate ctor arguments
Allow class users to set the initial state of enclosures and tach sensors. Signed-off-by: Brad Bishop <bradleyb@fuzziesquirrel.com> Change-Id: If5199361ab051ca46096f66ba925aeb1a874801f
Diffstat (limited to 'presence')
-rw-r--r--presence/fan_enclosure.hpp9
-rw-r--r--presence/tach_sensor.cpp6
-rw-r--r--presence/tach_sensor.hpp8
3 files changed, 14 insertions, 9 deletions
diff --git a/presence/fan_enclosure.hpp b/presence/fan_enclosure.hpp
index 071b59c..30bd235 100644
--- a/presence/fan_enclosure.hpp
+++ b/presence/fan_enclosure.hpp
@@ -54,10 +54,13 @@ class FanEnclosure
* @brief Constructs Fan Enclosure Object
*
* @param[in] fanProp - Fan enclosure properties
+ * @param[in] initialState - The initial state of the enclosure.
*/
- explicit FanEnclosure(const phosphor::fan::Properties& fanProp) :
+ explicit FanEnclosure(const phosphor::fan::Properties& fanProp,
+ presenceState initialState = UNKNOWN) :
invPath(std::get<0>(fanProp)),
- fanDesc(std::get<1>(fanProp))
+ fanDesc(std::get<1>(fanProp)),
+ presState(initialState)
{
}
@@ -82,7 +85,7 @@ class FanEnclosure
/** @brief List of sensors associated with this fan enclosure */
std::vector<std::unique_ptr<Sensor>> sensors;
/** @brief Last known presence state of this fan enclosure */
- presenceState presState = UNKNOWN;
+ presenceState presState;
/**
* @brief Get the current presence state based on all sensors
diff --git a/presence/tach_sensor.cpp b/presence/tach_sensor.cpp
index 60da441..36d4bb1 100644
--- a/presence/tach_sensor.cpp
+++ b/presence/tach_sensor.cpp
@@ -27,7 +27,7 @@ namespace presence
bool TachSensor::isPresent()
{
- return (tach != 0);
+ return state;
}
void TachSensor::handleTachChange(sdbusplus::message::message& sdbpMsg)
@@ -40,8 +40,8 @@ void TachSensor::handleTachChange(sdbusplus::message::message& sdbpMsg)
auto valPropMap = msgData.find("Value");
if (valPropMap != msgData.end())
{
- tach = sdbusplus::message::variant_ns::get<int64_t>(
- valPropMap->second);
+ state = sdbusplus::message::variant_ns::get<int64_t>(
+ valPropMap->second) != 0;
}
// Update inventory according to latest tach reported
fanEnc.updInventory();
diff --git a/presence/tach_sensor.hpp b/presence/tach_sensor.hpp
index 47d2098..068a66f 100644
--- a/presence/tach_sensor.hpp
+++ b/presence/tach_sensor.hpp
@@ -38,14 +38,16 @@ class TachSensor : public Sensor
*/
TachSensor(
const std::string& id,
- FanEnclosure& fanEnc) :
+ FanEnclosure& fanEnc,
+ bool initialState = false) :
Sensor(id, fanEnc),
tachSignal(util::SDBusPlus::getBus(),
match(id).c_str(),
std::bind(
std::mem_fn(&TachSensor::handleTachChange),
this,
- std::placeholders::_1))
+ std::placeholders::_1)),
+ state(initialState)
{
// Nothing to do here
}
@@ -61,7 +63,7 @@ class TachSensor : public Sensor
/** @brief Used to subscribe to dbus signals */
sdbusplus::server::match::match tachSignal;
/** @brief Tach speed value given from the signal */
- int64_t tach = 0;
+ bool state;
/**
* @brief Appends the fan sensor id to construct a match string
OpenPOWER on IntegriCloud