diff options
author | Matthew Barth <msbarth@us.ibm.com> | 2017-06-23 16:16:30 -0500 |
---|---|---|
committer | Matthew Barth <msbarth@us.ibm.com> | 2017-07-06 17:25:12 -0500 |
commit | 1bf0ce4bef11cf2ff24b82257625f6288823377e (patch) | |
tree | 7f17f35efc2006755ff06cbf8d52f25db7908a44 /control | |
parent | 8600d9a0058071951e0881037deff77fc03d1601 (diff) | |
download | phosphor-fan-presence-1bf0ce4bef11cf2ff24b82257625f6288823377e.tar.gz phosphor-fan-presence-1bf0ce4bef11cf2ff24b82257625f6288823377e.zip |
Move event init steps at startup to functions
Change-Id: I8a281935368cd705658d489c7c7af59b8dde7e4d
Signed-off-by: Matthew Barth <msbarth@us.ibm.com>
Diffstat (limited to 'control')
-rw-r--r-- | control/zone.cpp | 96 | ||||
-rw-r--r-- | control/zone.hpp | 20 |
2 files changed, 69 insertions, 47 deletions
diff --git a/control/zone.cpp b/control/zone.cpp index 17e0089..f5099c1 100644 --- a/control/zone.cpp +++ b/control/zone.cpp @@ -54,53 +54,7 @@ Zone::Zone(Mode mode, // Do not enable set speed events when in init mode if (mode != Mode::init) { - // Setup signal trigger for set speed events - for (auto& event : std::get<setSpeedEventsPos>(def)) - { - // Get the current value for each property - for (auto& entry : std::get<groupPos>(event)) - { - try - { - PropertyVariantType property; - getProperty(_bus, - entry.first, - std::get<intfPos>(entry.second), - std::get<propPos>(entry.second), - property); - setPropertyValue(entry.first.c_str(), - std::get<intfPos>(entry.second).c_str(), - std::get<propPos>(entry.second).c_str(), - property); - } - catch (const std::exception& e) - { - log<level::ERR>(e.what()); - } - } - // Setup signal matches for property change events - for (auto& prop : std::get<propChangeListPos>(event)) - { - _signalEvents.emplace_back( - std::make_unique<EventData>( - EventData - { - std::get<groupPos>(event), - std::get<handlerObjPos>(prop), - std::get<actionPos>(event) - })); - _matches.emplace_back( - bus, - std::get<signaturePos>(prop).c_str(), - std::bind(std::mem_fn(&Zone::handleEvent), - this, - std::placeholders::_1, - _signalEvents.back().get())); - } - // Run action function for initial event state - std::get<actionPos>(event)(*this, - std::get<groupPos>(event)); - } + initEvents(def); // Start timer for fan speed decreases if (!_decTimer.running()) { @@ -197,6 +151,54 @@ void Zone::decTimerExpired() // Decrease timer is restarted since its repeating } +void Zone::initEvents(const ZoneDefinition& def) +{ + // Setup signal trigger for set speed events + for (auto& event : std::get<setSpeedEventsPos>(def)) + { + // Get the current value for each property + for (auto& entry : std::get<groupPos>(event)) + { + refreshProperty(_bus, + entry.first, + std::get<intfPos>(entry.second), + std::get<propPos>(entry.second)); + } + // Setup signal matches for property change events + for (auto& prop : std::get<propChangeListPos>(event)) + { + _signalEvents.emplace_back( + std::make_unique<EventData>( + EventData + { + std::get<groupPos>(event), + std::get<handlerObjPos>(prop), + std::get<actionPos>(event) + })); + _matches.emplace_back( + _bus, + std::get<signaturePos>(prop).c_str(), + std::bind(std::mem_fn(&Zone::handleEvent), + this, + std::placeholders::_1, + _signalEvents.back().get())); + } + // Run action function for initial event state + std::get<actionPos>(event)(*this, + std::get<groupPos>(event)); + } +} + +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, diff --git a/control/zone.hpp b/control/zone.hpp index 30de150..bdde64a 100644 --- a/control/zone.hpp +++ b/control/zone.hpp @@ -309,6 +309,26 @@ class Zone std::vector<sdbusplus::server::match::match> _matches; /** + * @brief Initialize all the set speed event properties and actions + * + * @param[in] def - zone definition containing set speed events + */ + void initEvents(const ZoneDefinition& def); + + /** + * @brief Refresh the given property's cached value + * + * @param[in] bus - the bus to use + * @param[in] path - the dbus path name + * @param[in] iface - the dbus interface name + * @param[in] prop - the property name + */ + void refreshProperty(sdbusplus::bus::bus& bus, + const std::string& path, + const std::string& iface, + const std::string& prop); + + /** * @brief Get a property value from the path/interface given * * @param[in] bus - the bus to use |