summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthew Barth <msbarth@us.ibm.com>2017-06-02 11:31:06 -0500
committerPatrick Williams <patrick@stwcx.xyz>2017-06-26 01:39:41 +0000
commitf85dddcbd9882069e523fb86ecc18587d1cf52e3 (patch)
tree92e3e844895ada95603ad62c861a1045c0cc0a0c
parenta5763ff8f08dd9e3e52cf37d684fbe512658f87e (diff)
downloadphosphor-fan-presence-f85dddcbd9882069e523fb86ecc18587d1cf52e3.tar.gz
phosphor-fan-presence-f85dddcbd9882069e523fb86ecc18587d1cf52e3.zip
Update to use match methods for signal callbacks
Attach the tach change handler function to the match along with using the new match methods on the match string. Add 'argN' sensor value interface to reduce dbus traffic Resolves openbmc/phosphor-fan-presence#5 Change-Id: I9c809e42a384ea751d2f3a51b14ad304ce61cd2c Signed-off-by: Matthew Barth <msbarth@us.ibm.com>
-rw-r--r--presence/tach_sensor.cpp29
-rw-r--r--presence/tach_sensor.hpp37
2 files changed, 20 insertions, 46 deletions
diff --git a/presence/tach_sensor.cpp b/presence/tach_sensor.cpp
index c21478b..60da441 100644
--- a/presence/tach_sensor.cpp
+++ b/presence/tach_sensor.cpp
@@ -30,35 +30,18 @@ bool TachSensor::isPresent()
return (tach != 0);
}
-// Tach signal callback handler
-int TachSensor::handleTachChangeSignal(sd_bus_message* msg,
- void* usrData,
- sd_bus_error* err)
-{
- auto sdbpMsg = sdbusplus::message::message(msg);
- static_cast<TachSensor*>(usrData)->handleTachChange(sdbpMsg, err);
- return 0;
-}
-
-void TachSensor::handleTachChange(sdbusplus::message::message& sdbpMsg,
- sd_bus_error* err)
+void TachSensor::handleTachChange(sdbusplus::message::message& sdbpMsg)
{
std::string msgSensor;
std::map<std::string, sdbusplus::message::variant<int64_t>> msgData;
sdbpMsg.read(msgSensor, msgData);
- // TODO openbmc/phosphor-fan-presence#5
- // Update to use 'arg0namespace' match option to reduce dbus traffic
- // Find interface with value property
- if (msgSensor.compare("xyz.openbmc_project.Sensor.Value") == 0)
+ // Find the 'Value' property containing tach
+ auto valPropMap = msgData.find("Value");
+ if (valPropMap != msgData.end())
{
- // Find the 'Value' property containing tach
- auto valPropMap = msgData.find("Value");
- if (valPropMap != msgData.end())
- {
- tach = sdbusplus::message::variant_ns::get<int64_t>(
- valPropMap->second);
- }
+ tach = sdbusplus::message::variant_ns::get<int64_t>(
+ valPropMap->second);
}
// Update inventory according to latest tach reported
fanEnc.updInventory();
diff --git a/presence/tach_sensor.hpp b/presence/tach_sensor.hpp
index 90d955b..3de5d69 100644
--- a/presence/tach_sensor.hpp
+++ b/presence/tach_sensor.hpp
@@ -12,6 +12,8 @@ namespace fan
namespace presence
{
+using namespace sdbusplus::bus::match::rules;
+
/**
* @class TachSensor
* @brief OpenBMC Tach feedback sensor presence implementation
@@ -43,8 +45,10 @@ class TachSensor : public Sensor
bus(bus),
tachSignal(bus,
match(id).c_str(),
- handleTachChangeSignal,
- this)
+ std::bind(
+ std::mem_fn(&TachSensor::handleTachChange),
+ this,
+ std::placeholders::_1))
{
// Nothing to do here
}
@@ -73,32 +77,19 @@ class TachSensor : public Sensor
*/
static std::string match(const std::string& id)
{
- return std::string("type='signal',"
- "interface='org.freedesktop.DBus.Properties',"
- "member='PropertiesChanged',"
- "path='/xyz/openbmc_project/sensors/fan_tach/" +
- id + "'");
+ return std::string(
+ interface("org.freedesktop.DBus.Properties") +
+ member("PropertiesChanged") +
+ type::signal() +
+ path("/xyz/openbmc_project/sensors/fan_tach/" + id) +
+ argN(0, "xyz.openbmc_project.Sensor.Value"));
}
/**
- * @brief Callback function on tach change signals
- *
- * @param[out] msg - Data associated with the subscribed signal
- * @param[out] data - Pointer to this tach sensor object instance
- * @param[out] err - Contains any sdbus error reference if occurred
- *
- * @return 0
- */
- static int handleTachChangeSignal(sd_bus_message* msg,
- void* data,
- sd_bus_error* err);
- /**
- * @brief Determine & handle when the signal was a tach change
+ * @brief Handle when the signal was a tach change
*
* @param[in] msg - Expanded sdbusplus message data
- * @param[in] err - Contains any sdbus error reference if occurred
*/
- void handleTachChange(sdbusplus::message::message& msg,
- sd_bus_error* err);
+ void handleTachChange(sdbusplus::message::message& msg);
};
OpenPOWER on IntegriCloud