From df3e8d67fd8afb78105f516eac360d0a7d44326f Mon Sep 17 00:00:00 2001 From: Matthew Barth Date: Wed, 31 May 2017 11:07:24 -0500 Subject: Check initial event's group members' properties On start of fan control, check the current event's group members' property states and envoke the defined action function on the results. Change-Id: I12509403328d90f85d67b393dbdd97d8710c83ef Signed-off-by: Matthew Barth --- control/zone.cpp | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++ control/zone.hpp | 16 ++++++++++++++++ 2 files changed, 68 insertions(+) diff --git a/control/zone.cpp b/control/zone.cpp index 35c7d2b..13ee977 100644 --- a/control/zone.cpp +++ b/control/zone.cpp @@ -13,7 +13,9 @@ * See the License for the specific language governing permissions and * limitations under the License. */ +#include #include "zone.hpp" +#include "utility.hpp" namespace phosphor { @@ -22,6 +24,7 @@ namespace fan namespace control { +using namespace phosphor::logging; Zone::Zone(Mode mode, sdbusplus::bus::bus& bus, @@ -43,6 +46,27 @@ Zone::Zone(Mode mode, // Setup signal trigger for set speed events for (auto& event : std::get(def)) { + // Get the current value for each property + for (auto& entry : std::get(event)) + { + try + { + bool value = false; + getProperty(_bus, + entry.first, + std::get(entry.second), + std::get(entry.second), + value); + setPropertyValue(entry.first.c_str(), + std::get(entry.second).c_str(), + value); + } + catch (const std::exception& e) + { + log(e.what()); + } + } + // Setup signal matches for property change events for (auto& prop : std::get(event)) { _signalEvents.emplace_back( @@ -60,6 +84,9 @@ Zone::Zone(Mode mode, signalHandler, _signalEvents.back().get()); } + // Run action function for initial event state + std::get(event)(*this, + std::get(event)); } } } @@ -90,6 +117,31 @@ void Zone::setActiveAllow(const Group* group, bool isActiveAllow) } } +template +void Zone::getProperty(sdbusplus::bus::bus& bus, + const std::string& path, + const std::string& iface, + const std::string& prop, + T& value) +{ + sdbusplus::message::variant property; + auto serv = phosphor::fan::util::getService(path, iface, bus); + 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()) + { + throw std::runtime_error( + "Error in host call response for retrieving property"); + } + hostResponseMsg.read(property); + value = sdbusplus::message::variant_ns::get(property); +} + int Zone::signalHandler(sd_bus_message* msg, void* data, sd_bus_error* err) diff --git a/control/zone.hpp b/control/zone.hpp index b727567..c6e0594 100644 --- a/control/zone.hpp +++ b/control/zone.hpp @@ -153,6 +153,22 @@ class Zone */ std::vector _matches; + /** + * @brief Get a property value from the path/interface given + * + * @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 + * @param[out] value - the value of the property + */ + template + static void getProperty(sdbusplus::bus::bus& bus, + const std::string& path, + const std::string& iface, + const std::string& prop, + T& value); + /** * @brief Dbus signal change handler * -- cgit v1.2.1