From f96b01e28462a78d253c0917cd201a7f094026c8 Mon Sep 17 00:00:00 2001 From: Gunnar Mills Date: Fri, 2 Jun 2017 16:32:19 -0500 Subject: Evaluate conditions to determine zone Change-Id: Idb825b27ecf98503ddc2405a0cafc30c644efc71 Signed-off-by: Gunnar Mills --- control/manager.cpp | 106 +++++++++++++++++++++++++++++++++++++++++++++------- control/types.hpp | 17 ++++++++- 2 files changed, 108 insertions(+), 15 deletions(-) (limited to 'control') diff --git a/control/manager.cpp b/control/manager.cpp index de9074c..c3c1226 100644 --- a/control/manager.cpp +++ b/control/manager.cpp @@ -17,6 +17,7 @@ #include #include #include "manager.hpp" +#include "utility.hpp" namespace phosphor { @@ -32,6 +33,87 @@ constexpr auto SYSTEMD_OBJ_PATH = "/org/freedesktop/systemd1"; constexpr auto SYSTEMD_INTERFACE = "org.freedesktop.systemd1.Manager"; constexpr auto FAN_CONTROL_READY_TARGET = "obmc-fan-control-ready@0.target"; +constexpr auto PROPERTY_INTERFACE = "org.freedesktop.DBus.Properties"; +constexpr auto MAPPER_BUSNAME = "xyz.openbmc_project.ObjectMapper"; +constexpr auto MAPPER_PATH = "/xyz/openbmc_project/object_mapper"; +constexpr auto MAPPER_INTERFACE = "xyz.openbmc_project.ObjectMapper"; + + +/** + * Get the current value of the D-Bus property under the specified path + * and interface. + * + * @param[in] bus - The D-Bus bus object + * @param[in] path - The D-Bus path + * @param[in] interface - The D-Bus interface + * @param[in] propertyName - The D-Bus property + * @param[out] value - The D-Bus property's value + */ +template +void getProperty(sdbusplus::bus::bus& bus, + const std::string& path, + const std::string& interface, + const std::string& propertyName, + T& value) +{ + sdbusplus::message::variant property; + std::string service = phosphor::fan::util::getService(path, interface, bus); + + auto method = bus.new_method_call(service.c_str(), + path.c_str(), + PROPERTY_INTERFACE, + "Get"); + + method.append(interface, propertyName); + auto reply = bus.call(method); + + if (reply.is_method_error()) + { + throw std::runtime_error( + "Error in call response for retrieving property"); + } + reply.read(property); + value = sdbusplus::message::variant_ns::get(property); +} + + +/** + * Check if a condition is true. Conditions are used to determine + * which fan zone to use. + * + * @param[in] bus - The D-Bus bus object + * @param[in] condition - The condition to check if true + * @return result - True if the condition is true + */ +bool checkCondition(sdbusplus::bus::bus& bus, const auto& c) +{ + auto& type = std::get(c); + auto& properties = std::get(c); + + for (auto& p : properties) + { + bool value = std::get(p); + bool propertyValue; + + // TODO openbmc/openbmc#1769: Support more types than just getProperty. + if (type.compare("getProperty") == 0) + { + getProperty(bus, + std::get(p), + std::get(p), + std::get(p), + propertyValue); + + if (value != propertyValue) + { + return false; + } + } + } + return true; +} + + //Note: Future code will check 'mode' before starting control algorithm Manager::Manager(sdbusplus::bus::bus& bus, Mode mode) : @@ -46,12 +128,10 @@ Manager::Manager(sdbusplus::bus::bus& bus, auto& conditions = std::get(group); if (std::all_of(conditions.begin(), conditions.end(), - [](const auto& c) - { - //TODO: openbmc/openbmc#1500 - //Still need to actually evaluate the conditions - return true; - })) + [&bus](const auto& condition) + { + return checkCondition(bus, condition); + })) { //Create a Zone object for each zone in this group auto& zones = std::get(group); @@ -71,7 +151,7 @@ Manager::Manager(sdbusplus::bus::bus& bus, void Manager::doInit() { - for (auto& z: _zones) + for (auto& z : _zones) { z.second->setFullSpeed(); } @@ -89,9 +169,9 @@ void Manager::doInit() void Manager::startFanControlReadyTarget() { auto method = _bus.new_method_call(SYSTEMD_SERVICE, - SYSTEMD_OBJ_PATH, - SYSTEMD_INTERFACE, - "StartUnit"); + SYSTEMD_OBJ_PATH, + SYSTEMD_INTERFACE, + "StartUnit"); method.append(FAN_CONTROL_READY_TARGET); method.append("replace"); @@ -105,6 +185,6 @@ void Manager::startFanControlReadyTarget() } } -} -} -} +} // namespace control +} // namespace fan +} // namespace phosphor diff --git a/control/types.hpp b/control/types.hpp index a9508eb..2b7509c 100644 --- a/control/types.hpp +++ b/control/types.hpp @@ -12,8 +12,21 @@ namespace control class Zone; -//Placeholder. Conditions are completely TBD. -using Condition = bool; +constexpr auto propertyNamePos = 0; +constexpr auto propertyInterfacePos = 1; +constexpr auto propertyPathPos = 2; +constexpr auto propertyValuePos = 3; + +// TODO openbmc/openbmc#1769: Support more property types. +using ConditionProperty = std::tuple; + +constexpr auto conditionTypePos = 0; +constexpr auto conditionPropertyListPos = 1; +using Condition = std::tuple>; constexpr auto fanNamePos = 0; constexpr auto sensorListPos = 1; -- cgit v1.2.1