summaryrefslogtreecommitdiffstats
path: root/control/zone.cpp
diff options
context:
space:
mode:
authorMatthew Barth <msbarth@us.ibm.com>2017-09-26 09:15:56 -0500
committerBrad Bishop <bradleyb@fuzziesquirrel.com>2017-11-17 15:43:28 +0000
commit336f18a541e93e2cc1719180df73ef8b357c962f (patch)
treee0edf72beb42a9c7a7a6ce9e46b768d1b7fcfffd /control/zone.cpp
parent6088558429fbe5f723783b4220b6ac1c9096cde9 (diff)
downloadphosphor-fan-presence-336f18a541e93e2cc1719180df73ef8b357c962f.tar.gz
phosphor-fan-presence-336f18a541e93e2cc1719180df73ef8b357c962f.zip
Update event initialization
Using a null dbus message to the event signal will perform the necessary steps to initialize the event parameters using the given signal handler's function directly. i.e.) In the case for subscribing to PropertiesChanged signals, initially the given property must be read. When the PropertiesChanged signal struct is given a null message, it finds the property, reads the value, and then can perform the given signal handler function directly. This produces the same functional path as receiving a PropertiesChanged signal containing the property value within the message. Change-Id: I35575cfff66eb0305156be786cb1f5536d42bb1c Signed-off-by: Matthew Barth <msbarth@us.ibm.com>
Diffstat (limited to 'control/zone.cpp')
-rw-r--r--control/zone.cpp86
1 files changed, 23 insertions, 63 deletions
diff --git a/control/zone.cpp b/control/zone.cpp
index fa426e6..3d7852e 100644
--- a/control/zone.cpp
+++ b/control/zone.cpp
@@ -194,46 +194,35 @@ void Zone::decTimerExpired()
void Zone::initEvent(const SetSpeedEvent& event)
{
- // Get the current value for each property
- for (auto& group : std::get<groupPos>(event))
- {
- try
- {
- refreshProperty(_bus,
- group.first,
- std::get<intfPos>(group.second),
- std::get<propPos>(group.second));
- }
- catch (const InternalFailure& ife)
- {
- log<level::INFO>(
- "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 events
+ sdbusplus::message::message nullMsg{nullptr};
+
for (auto& sig : std::get<signalsPos>(event))
{
+ // Initialize the event signal using handler
+ std::get<sigHandlerPos>(sig)(_bus, nullMsg, *this);
+ // Setup signal matches of the property for event
std::unique_ptr<EventData> eventData =
std::make_unique<EventData>(
EventData
{
std::get<groupPos>(event),
- std::get<handlerObjPos>(sig),
+ std::get<sigMatchPos>(sig),
+ std::get<sigHandlerPos>(sig),
std::get<actionsPos>(event)
}
);
- std::unique_ptr<sdbusplus::server::match::match> match =
- std::make_unique<sdbusplus::server::match::match>(
- _bus,
- std::get<signaturePos>(sig).c_str(),
- std::bind(std::mem_fn(&Zone::handleEvent),
- this,
- std::placeholders::_1,
- eventData.get())
- );
+ std::unique_ptr<sdbusplus::server::match::match> match = nullptr;
+ if (!std::get<sigMatchPos>(sig).empty())
+ {
+ match = std::make_unique<sdbusplus::server::match::match>(
+ _bus,
+ std::get<sigMatchPos>(sig).c_str(),
+ std::bind(std::mem_fn(&Zone::handleEvent),
+ this,
+ std::placeholders::_1,
+ eventData.get())
+ );
+ }
_signalEvents.emplace_back(std::move(eventData), std::move(match));
}
// Attach a timer to run the action of an event
@@ -305,43 +294,14 @@ void Zone::removeEvent(const SetSpeedEvent& event)
if (it != std::end(_signalEvents))
{
std::get<signalEventDataPos>(*it).reset();
- std::get<signalMatchPos>(*it).reset();
+ if (std::get<signalMatchPos>(*it) != nullptr)
+ {
+ std::get<signalMatchPos>(*it).reset();
+ }
_signalEvents.erase(it);
}
}
-void Zone::refreshProperty(sdbusplus::bus::bus& bus,
- const std::string& path,
- const std::string& iface,
- const std::string& prop)
-{
- PropertyVariantType property;
- getProperty(_bus, path, iface, prop, property);
- setPropertyValue(path.c_str(), iface.c_str(), prop.c_str(), property);
-}
-
-void Zone::getProperty(sdbusplus::bus::bus& bus,
- const std::string& path,
- const std::string& iface,
- const std::string& prop,
- PropertyVariantType& value)
-{
- auto serv = util::SDBusPlus::getService(bus, path, iface);
- auto hostCall = bus.new_method_call(serv.c_str(),
- path.c_str(),
- "org.freedesktop.DBus.Properties",
- "Get");
- hostCall.append(iface);
- hostCall.append(prop);
- auto hostResponseMsg = bus.call(hostCall);
- if (hostResponseMsg.is_method_error())
- {
- log<level::INFO>("Host call response error for retrieving property");
- elog<InternalFailure>();
- }
- hostResponseMsg.read(value);
-}
-
void Zone::timerExpired(Group eventGroup, std::vector<Action> eventActions)
{
// Perform the actions
OpenPOWER on IntegriCloud