control: Clang format updates
Used `format-code.sh` build script to make changes to conform to clang
format.
Tested: Compiled
Change-Id: Ic9d621d7c5647bde0a92c5f17938c99deeca0512
Signed-off-by: Matthew Barth <msbarth@us.ibm.com>
diff --git a/control/actions.cpp b/control/actions.cpp
index 97f4f34..00dc8f0 100644
--- a/control/actions.cpp
+++ b/control/actions.cpp
@@ -14,10 +14,8 @@
Action call_actions_based_on_timer(TimerConf&& tConf,
std::vector<Action>&& actions)
{
- return [tConf = std::move(tConf),
- actions = std::move(actions)](control::Zone& zone,
- const Group& group)
- {
+ return [tConf = std::move(tConf), actions = std::move(actions)](
+ control::Zone& zone, const Group& group) {
try
{
auto it = zone.getTimerEvents().find(__func__);
@@ -58,13 +56,9 @@
// Set/update the services of the group
zone.setServices(&group);
auto services = zone.getGroupServices(&group);
- auto defFloor = std::any_of(
- services.begin(),
- services.end(),
- [](const auto& s)
- {
- return !std::get<hasOwnerPos>(s);
- });
+ auto defFloor =
+ std::any_of(services.begin(), services.end(),
+ [](const auto& s) { return !std::get<hasOwnerPos>(s); });
if (defFloor)
{
zone.setFloor(zone.getDefFloor());
@@ -75,16 +69,12 @@
Action set_speed_on_missing_owner(uint64_t speed)
{
- return [speed](control::Zone& zone, const Group& group)
- {
+ return [speed](control::Zone& zone, const Group& group) {
// Set/update the services of the group
zone.setServices(&group);
auto services = zone.getGroupServices(&group);
- auto missingOwner = std::any_of(
- services.begin(),
- services.end(),
- [](const auto& s)
- {
+ auto missingOwner =
+ std::any_of(services.begin(), services.end(), [](const auto& s) {
return !std::get<hasOwnerPos>(s);
});
if (missingOwner)
@@ -96,21 +86,16 @@
};
}
-void set_request_speed_base_with_max(control::Zone& zone,
- const Group& group)
+void set_request_speed_base_with_max(control::Zone& zone, const Group& group)
{
int64_t base = 0;
std::for_each(
- group.begin(),
- group.end(),
- [&zone, &base](auto const& entry)
- {
+ group.begin(), group.end(), [&zone, &base](auto const& entry) {
try
{
auto value = zone.template getPropertyValue<int64_t>(
- std::get<pathPos>(entry),
- std::get<intfPos>(entry),
- std::get<propPos>(entry));
+ std::get<pathPos>(entry), std::get<intfPos>(entry),
+ std::get<propPos>(entry));
base = std::max(base, value);
}
catch (const std::out_of_range& oore)
diff --git a/control/actions.hpp b/control/actions.hpp
index d33c366..53e2efe 100644
--- a/control/actions.hpp
+++ b/control/actions.hpp
@@ -1,10 +1,11 @@
#pragma once
+#include "types.hpp"
+#include "utility.hpp"
+#include "zone.hpp"
+
#include <algorithm>
#include <numeric>
-#include "types.hpp"
-#include "zone.hpp"
-#include "utility.hpp"
namespace phosphor
{
@@ -26,9 +27,8 @@
* @return Action lambda function
* An Action function that creates a timer
*/
-Action call_actions_based_on_timer(
- TimerConf&& tConf,
- std::vector<Action>&& actions);
+Action call_actions_based_on_timer(TimerConf&& tConf,
+ std::vector<Action>&& actions);
/**
* @brief An action that sets the floor to the default fan floor speed
@@ -85,18 +85,15 @@
template <typename T>
auto count_state_before_speed(size_t count, T&& state, uint64_t speed)
{
- return [count,
- speed,
- state = std::forward<T>(state)](auto& zone, auto& group)
- {
+ return [count, speed, state = std::forward<T>(state)](auto& zone,
+ auto& group) {
size_t numAtState = 0;
for (auto& entry : group)
{
try
{
if (zone.template getPropertyValue<T>(
- std::get<pathPos>(entry),
- std::get<intfPos>(entry),
+ std::get<pathPos>(entry), std::get<intfPos>(entry),
std::get<propPos>(entry)) == state)
{
numAtState++;
@@ -130,48 +127,38 @@
* property values within the group is below the lowest sensor value given
*/
template <typename T>
-Action set_floor_from_average_sensor_value(
- std::map<T, uint64_t>&& val_to_speed)
+Action set_floor_from_average_sensor_value(std::map<T, uint64_t>&& val_to_speed)
{
return [val_to_speed = std::move(val_to_speed)](control::Zone& zone,
- const Group& group)
- {
+ const Group& group) {
auto speed = zone.getDefFloor();
if (group.size() != 0)
{
auto count = 0;
auto sumValue = std::accumulate(
- group.begin(),
- group.end(),
- 0,
- [&zone, &count](T sum, auto const& entry)
+ group.begin(), group.end(), 0,
+ [&zone, &count](T sum, auto const& entry) {
+ try
{
- try
- {
- return sum +
- zone.template getPropertyValue<T>(
- std::get<pathPos>(entry),
- std::get<intfPos>(entry),
- std::get<propPos>(entry));
- }
- catch (const std::out_of_range& oore)
- {
- count++;
- return sum;
- }
- });
+ return sum + zone.template getPropertyValue<T>(
+ std::get<pathPos>(entry),
+ std::get<intfPos>(entry),
+ std::get<propPos>(entry));
+ }
+ catch (const std::out_of_range& oore)
+ {
+ count++;
+ return sum;
+ }
+ });
if ((group.size() - count) > 0)
{
auto groupSize = static_cast<int64_t>(group.size());
auto avgValue = sumValue / (groupSize - count);
- auto it = std::find_if(
- val_to_speed.begin(),
- val_to_speed.end(),
- [&avgValue](auto const& entry)
- {
- return avgValue < entry.first;
- }
- );
+ auto it = std::find_if(val_to_speed.begin(), val_to_speed.end(),
+ [&avgValue](auto const& entry) {
+ return avgValue < entry.first;
+ });
if (it != std::end(val_to_speed))
{
speed = (*it).second;
@@ -197,48 +184,42 @@
* below(decreasing) the key transition point
*/
template <typename T>
-Action set_ceiling_from_average_sensor_value(
- std::map<T, uint64_t>&& val_to_speed)
+Action
+ set_ceiling_from_average_sensor_value(std::map<T, uint64_t>&& val_to_speed)
{
return [val_to_speed = std::move(val_to_speed)](Zone& zone,
- const Group& group)
- {
+ const Group& group) {
auto speed = zone.getCeiling();
if (group.size() != 0)
{
auto count = 0;
auto sumValue = std::accumulate(
- group.begin(),
- group.end(),
- 0,
- [&zone, &count](T sum, auto const& entry)
+ group.begin(), group.end(), 0,
+ [&zone, &count](T sum, auto const& entry) {
+ try
{
- try
- {
- return sum +
- zone.template getPropertyValue<T>(
- std::get<pathPos>(entry),
- std::get<intfPos>(entry),
- std::get<propPos>(entry));
- }
- catch (const std::out_of_range& oore)
- {
- count++;
- return sum;
- }
- });
+ return sum + zone.template getPropertyValue<T>(
+ std::get<pathPos>(entry),
+ std::get<intfPos>(entry),
+ std::get<propPos>(entry));
+ }
+ catch (const std::out_of_range& oore)
+ {
+ count++;
+ return sum;
+ }
+ });
if ((group.size() - count) > 0)
{
auto groupSize = static_cast<int64_t>(group.size());
auto avgValue = sumValue / (groupSize - count);
auto prevValue = zone.swapCeilingKeyValue(avgValue);
if (avgValue != prevValue)
- {// Only check if previous and new values differ
+ { // Only check if previous and new values differ
if (avgValue < prevValue)
- {// Value is decreasing from previous
+ { // Value is decreasing from previous
for (auto it = val_to_speed.rbegin();
- it != val_to_speed.rend();
- ++it)
+ it != val_to_speed.rend(); ++it)
{
if (it == val_to_speed.rbegin() &&
avgValue >= it->first)
@@ -256,8 +237,7 @@
speed = it->second;
break;
}
- if (avgValue < it->first &&
- it->first <= prevValue)
+ if (avgValue < it->first && it->first <= prevValue)
{
// Value decreased & transitioned across
// a map key, update ceiling speed to this
@@ -269,10 +249,9 @@
}
}
else
- {// Value is increasing from previous
+ { // Value is increasing from previous
for (auto it = val_to_speed.begin();
- it != val_to_speed.end();
- ++it)
+ it != val_to_speed.end(); ++it)
{
if (it == val_to_speed.begin() &&
avgValue <= it->first)
@@ -290,8 +269,7 @@
speed = it->second;
break;
}
- if (avgValue > it->first &&
- it->first >= prevValue)
+ if (avgValue > it->first && it->first >= prevValue)
{
// Value increased & transitioned across
// a map key, update ceiling speed to this
@@ -326,45 +304,37 @@
template <typename T>
auto set_net_increase_speed(T&& state, T&& factor, uint64_t speedDelta)
{
- return [speedDelta,
- factor = std::forward<T>(factor),
- state = std::forward<T>(state)](auto& zone, auto& group)
- {
+ return [speedDelta, factor = std::forward<T>(factor),
+ state = std::forward<T>(state)](auto& zone, auto& group) {
auto netDelta = zone.getIncSpeedDelta();
std::for_each(
- group.begin(),
- group.end(),
- [&zone, &state, &factor, &speedDelta, &netDelta](
- auto const& entry)
- {
+ group.begin(), group.end(),
+ [&zone, &state, &factor, &speedDelta,
+ &netDelta](auto const& entry) {
try
{
T value = zone.template getPropertyValue<T>(
- std::get<pathPos>(entry),
- std::get<intfPos>(entry),
- std::get<propPos>(entry));
+ std::get<pathPos>(entry), std::get<intfPos>(entry),
+ std::get<propPos>(entry));
// TODO openbmc/phosphor-fan-presence#7 - Support possible
// state types for comparison
if (value >= state)
{
// Increase by at least a single delta(factor)
// to attempt bringing under 'state'
- auto delta = std::max(
- (value - state),
- factor);
+ auto delta = std::max((value - state), factor);
// Increase is the factor applied to the
// difference times the given speed delta
- netDelta = std::max(
- netDelta,
- static_cast<uint64_t>((delta/factor) * speedDelta));
+ netDelta = std::max(netDelta,
+ static_cast<uint64_t>(
+ (delta / factor) * speedDelta));
}
}
catch (const std::out_of_range& oore)
{
// Property value not found, netDelta unchanged
}
- }
- );
+ });
// Request speed change for target speed update
zone.requestSpeedIncrease(netDelta);
};
@@ -387,26 +357,23 @@
template <typename T>
auto set_net_decrease_speed(T&& state, T&& factor, uint64_t speedDelta)
{
- return [speedDelta,
- factor = std::forward<T>(factor),
- state = std::forward<T>(state)](auto& zone, auto& group)
- {
+ return [speedDelta, factor = std::forward<T>(factor),
+ state = std::forward<T>(state)](auto& zone, auto& group) {
auto netDelta = zone.getDecSpeedDelta();
for (auto& entry : group)
{
try
{
T value = zone.template getPropertyValue<T>(
- std::get<pathPos>(entry),
- std::get<intfPos>(entry),
- std::get<propPos>(entry));
+ std::get<pathPos>(entry), std::get<intfPos>(entry),
+ std::get<propPos>(entry));
// TODO openbmc/phosphor-fan-presence#7 - Support possible
// state types for comparison
if (value < state)
{
if (netDelta == 0)
{
- netDelta = ((state - value)/factor) * speedDelta;
+ netDelta = ((state - value) / factor) * speedDelta;
}
else
{
@@ -414,8 +381,8 @@
// difference times the given speed delta
netDelta = std::min(
netDelta,
- static_cast<uint64_t>(
- ((state - value)/factor) * speedDelta));
+ static_cast<uint64_t>(((state - value) / factor) *
+ speedDelta));
}
}
else
@@ -457,22 +424,17 @@
std::vector<SetSpeedEvent>&& defEvents,
std::vector<SetSpeedEvent>&& altEvents)
{
- return [state = std::forward<T>(state),
- defEvents = std::move(defEvents),
- altEvents = std::move(altEvents)](auto& zone, auto& group)
- {
+ return [state = std::forward<T>(state), defEvents = std::move(defEvents),
+ altEvents = std::move(altEvents)](auto& zone, auto& group) {
// Compare all group entries to the state
auto useAlt = std::all_of(
- group.begin(),
- group.end(),
- [&zone, &state](auto const& entry)
- {
+ group.begin(), group.end(), [&zone, &state](auto const& entry) {
try
{
return zone.template getPropertyValue<T>(
- std::get<pathPos>(entry),
- std::get<intfPos>(entry),
- std::get<propPos>(entry)) == state;
+ std::get<pathPos>(entry),
+ std::get<intfPos>(entry),
+ std::get<propPos>(entry)) == state;
}
catch (const std::out_of_range& oore)
{
@@ -481,8 +443,8 @@
}
});
- const std::vector<SetSpeedEvent> *rmEvents = &altEvents;
- const std::vector<SetSpeedEvent> *initEvents = &defEvents;
+ const std::vector<SetSpeedEvent>* rmEvents = &altEvents;
+ const std::vector<SetSpeedEvent>* initEvents = &defEvents;
if (useAlt)
{
@@ -491,21 +453,11 @@
}
// Remove events
- std::for_each(
- rmEvents->begin(),
- rmEvents->end(),
- [&zone](auto const& entry)
- {
- zone.removeEvent(entry);
- });
+ std::for_each(rmEvents->begin(), rmEvents->end(),
+ [&zone](auto const& entry) { zone.removeEvent(entry); });
// Init events
- std::for_each(
- initEvents->begin(),
- initEvents->end(),
- [&zone](auto const& entry)
- {
- zone.initEvent(entry);
- });
+ std::for_each(initEvents->begin(), initEvents->end(),
+ [&zone](auto const& entry) { zone.initEvent(entry); });
};
}
@@ -527,16 +479,13 @@
* of valid sensor values based on their highest value or median.
*/
template <typename T>
-Action set_floor_from_median_sensor_value(
- T&& lowerBound,
- T&& upperBound,
- std::map<T, uint64_t>&& valueToSpeed)
+Action set_floor_from_median_sensor_value(T&& lowerBound, T&& upperBound,
+ std::map<T, uint64_t>&& valueToSpeed)
{
return [lowerBound = std::forward<T>(lowerBound),
upperBound = std::forward<T>(upperBound),
valueToSpeed = std::move(valueToSpeed)](control::Zone& zone,
- const Group& group)
- {
+ const Group& group) {
auto speed = zone.getDefFloor();
if (group.size() != 0)
{
@@ -546,9 +495,8 @@
try
{
auto value = zone.template getPropertyValue<T>(
- std::get<pathPos>(member),
- std::get<intfPos>(member),
- std::get<propPos>(member));
+ std::get<pathPos>(member), std::get<intfPos>(member),
+ std::get<propPos>(member));
if (value == std::clamp(value, lowerBound, upperBound))
{
// Sensor value is valid
@@ -578,14 +526,10 @@
}
// Use determined median sensor value to find floor speed
- auto it = std::find_if(
- valueToSpeed.begin(),
- valueToSpeed.end(),
- [&median](auto const& entry)
- {
- return median < entry.first;
- }
- );
+ auto it = std::find_if(valueToSpeed.begin(), valueToSpeed.end(),
+ [&median](auto const& entry) {
+ return median < entry.first;
+ });
if (it != std::end(valueToSpeed))
{
speed = (*it).second;
@@ -611,19 +555,15 @@
template <typename T>
auto update_default_floor(T&& state, uint64_t speed)
{
- return [speed, state = std::forward<T>(state)](auto& zone, auto& group)
- {
+ return [speed, state = std::forward<T>(state)](auto& zone, auto& group) {
auto updateDefFloor = std::all_of(
- group.begin(),
- group.end(),
- [&zone, &state](auto const& entry)
- {
+ group.begin(), group.end(), [&zone, &state](auto const& entry) {
try
{
return zone.template getPropertyValue<T>(
- std::get<pathPos>(entry),
- std::get<intfPos>(entry),
- std::get<propPos>(entry)) == state;
+ std::get<pathPos>(entry),
+ std::get<intfPos>(entry),
+ std::get<propPos>(entry)) == state;
}
catch (const std::out_of_range& oore)
{
@@ -657,24 +597,19 @@
* and initializes the set of events, otherwise removes them.
*/
template <typename T>
-auto use_events_on_state(T&& state,
- std::vector<SetSpeedEvent>&& events)
+auto use_events_on_state(T&& state, std::vector<SetSpeedEvent>&& events)
{
return [state = std::forward<T>(state),
- events = std::move(events)](auto& zone, auto& group)
- {
+ events = std::move(events)](auto& zone, auto& group) {
// Compare all group entries to the state
auto useEvents = std::all_of(
- group.begin(),
- group.end(),
- [&zone, &state](auto const& entry)
- {
+ group.begin(), group.end(), [&zone, &state](auto const& entry) {
try
{
return zone.template getPropertyValue<T>(
- std::get<pathPos>(entry),
- std::get<intfPos>(entry),
- std::get<propPos>(entry)) == state;
+ std::get<pathPos>(entry),
+ std::get<intfPos>(entry),
+ std::get<propPos>(entry)) == state;
}
catch (const std::out_of_range& oore)
{
@@ -687,23 +622,15 @@
{
// Init events
std::for_each(
- events.begin(),
- events.end(),
- [&zone](auto const& entry)
- {
- zone.initEvent(entry);
- });
+ events.begin(), events.end(),
+ [&zone](auto const& entry) { zone.initEvent(entry); });
}
else
{
// Remove events
std::for_each(
- events.begin(),
- events.end(),
- [&zone](auto const& entry)
- {
- zone.removeEvent(entry);
- });
+ events.begin(), events.end(),
+ [&zone](auto const& entry) { zone.removeEvent(entry); });
}
};
}
diff --git a/control/argument.cpp b/control/argument.cpp
index e014453..cd6e6da 100644
--- a/control/argument.cpp
+++ b/control/argument.cpp
@@ -13,10 +13,11 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+#include "argument.hpp"
+
+#include <algorithm>
#include <iostream>
#include <iterator>
-#include <algorithm>
-#include "argument.hpp"
namespace phosphor
{
@@ -67,17 +68,17 @@
std::cerr << "Usage: " << argv[0] << " [options]\n";
std::cerr << "Options:\n";
std::cerr << " --help Print this menu\n";
- std::cerr << " --init Sets fans to full speed, delays, exits\n";
+ std::cerr
+ << " --init Sets fans to full speed, delays, exits\n";
std::cerr << " --control Start fan control algorithm\n";
std::cerr << std::flush;
}
-const option ArgumentParser::options[] =
-{
- { "init", no_argument, NULL, 'i' },
- { "control", no_argument, NULL, 'c' },
- { "help", no_argument, NULL, 'h' },
- { 0, 0, 0, 0},
+const option ArgumentParser::options[] = {
+ {"init", no_argument, NULL, 'i'},
+ {"control", no_argument, NULL, 'c'},
+ {"help", no_argument, NULL, 'h'},
+ {0, 0, 0, 0},
};
const char* ArgumentParser::optionstr = "ich?";
@@ -85,7 +86,7 @@
const std::string ArgumentParser::true_string = "true";
const std::string ArgumentParser::empty_string = "";
-}
-}
-}
+} // namespace util
+} // namespace fan
+} // namespace phosphor
// vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4
diff --git a/control/fan.cpp b/control/fan.cpp
index c86186f..7f8f21f 100644
--- a/control/fan.cpp
+++ b/control/fan.cpp
@@ -13,10 +13,12 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-#include <string>
#include "fan.hpp"
+
#include "sdbusplus.hpp"
+#include <string>
+
namespace phosphor
{
namespace fan
@@ -30,9 +32,8 @@
constexpr auto FAN_SENSOR_PATH = "/xyz/openbmc_project/sensors/fan_tach/";
constexpr auto FAN_TARGET_PROPERTY = "Target";
-Fan::Fan(sdbusplus::bus::bus& bus, const FanDefinition& def):
- _bus(bus),
- _name(std::get<fanNamePos>(def)),
+Fan::Fan(sdbusplus::bus::bus& bus, const FanDefinition& def) :
+ _bus(bus), _name(std::get<fanNamePos>(def)),
_interface(std::get<targetInterfacePos>(def))
{
std::string path;
@@ -40,10 +41,7 @@
for (auto& s : sensors)
{
path = FAN_SENSOR_PATH + s;
- auto service = util::SDBusPlus::getService(
- bus,
- path,
- _interface);
+ auto service = util::SDBusPlus::getService(bus, path, _interface);
_sensors[path] = service;
}
// All sensors associated with this fan are set to the same target speed,
@@ -53,10 +51,7 @@
// Use getProperty with service lookup since each target sensor
// path given could have different services providing them
_targetSpeed = util::SDBusPlus::getProperty<uint64_t>(
- bus,
- path,
- _interface,
- FAN_TARGET_PROPERTY);
+ bus, path, _interface, FAN_TARGET_PROPERTY);
}
}
@@ -68,27 +63,20 @@
try
{
util::SDBusPlus::setProperty<uint64_t>(
- _bus,
- sensor.second,
- sensor.first,
- _interface,
- FAN_TARGET_PROPERTY,
- std::move(value));
+ _bus, sensor.second, sensor.first, _interface,
+ FAN_TARGET_PROPERTY, std::move(value));
}
catch (const sdbusplus::exception::SdBusError&)
{
- throw util::DBusPropertyError{
- "DBus set property failed",
- sensor.second,
- sensor.first,
- _interface,
- FAN_TARGET_PROPERTY};
+ throw util::DBusPropertyError{"DBus set property failed",
+ sensor.second, sensor.first,
+ _interface, FAN_TARGET_PROPERTY};
}
}
_targetSpeed = speed;
}
-}
-}
-}
+} // namespace control
+} // namespace fan
+} // namespace phosphor
diff --git a/control/fan.hpp b/control/fan.hpp
index 3e05e16..f686817 100644
--- a/control/fan.hpp
+++ b/control/fan.hpp
@@ -1,7 +1,8 @@
#pragma once
-#include <sdbusplus/bus.hpp>
#include "types.hpp"
+#include <sdbusplus/bus.hpp>
+
namespace phosphor
{
namespace fan
@@ -9,7 +10,6 @@
namespace control
{
-
/**
* @class Fan
*
@@ -21,70 +21,67 @@
*/
class Fan
{
- public:
+ public:
+ Fan() = delete;
+ Fan(const Fan&) = delete;
+ Fan(Fan&&) = default;
+ Fan& operator=(const Fan&) = delete;
+ Fan& operator=(Fan&&) = default;
+ ~Fan() = default;
- Fan() = delete;
- Fan(const Fan&) = delete;
- Fan(Fan&&) = default;
- Fan& operator=(const Fan&) = delete;
- Fan& operator=(Fan&&) = default;
- ~Fan() = default;
+ /**
+ * Creates a fan object with sensors specified by
+ * the fan definition data.
+ *
+ * @param[in] bus - the dbus object
+ * @param[in] def - the fan definition data
+ */
+ Fan(sdbusplus::bus::bus& bus, const FanDefinition& def);
- /**
- * Creates a fan object with sensors specified by
- * the fan definition data.
- *
- * @param[in] bus - the dbus object
- * @param[in] def - the fan definition data
- */
- Fan(sdbusplus::bus::bus& bus, const FanDefinition& def);
+ /**
+ * Sets the speed value on all contained sensors
+ *
+ * @param[in] speed - the value to set
+ */
+ void setSpeed(uint64_t speed);
- /**
- * Sets the speed value on all contained sensors
- *
- * @param[in] speed - the value to set
- */
- void setSpeed(uint64_t speed);
+ /**
+ * @brief Get the current fan target speed
+ *
+ * @return - The target speed of the fan
+ */
+ inline auto getTargetSpeed() const
+ {
+ return _targetSpeed;
+ }
- /**
- * @brief Get the current fan target speed
- *
- * @return - The target speed of the fan
- */
- inline auto getTargetSpeed() const
- {
- return _targetSpeed;
- }
+ private:
+ /**
+ * The dbus object
+ */
+ sdbusplus::bus::bus& _bus;
- private:
+ /**
+ * The inventory name of the fan
+ */
+ std::string _name;
- /**
- * The dbus object
- */
- sdbusplus::bus::bus& _bus;
+ /**
+ * Map of hwmon target sensors to the service providing them
+ */
+ std::map<std::string, std::string> _sensors;
- /**
- * The inventory name of the fan
- */
- std::string _name;
+ /**
+ * The interface of the fan target
+ */
+ const std::string _interface;
- /**
- * Map of hwmon target sensors to the service providing them
- */
- std::map<std::string, std::string> _sensors;
-
- /**
- * The interface of the fan target
- */
- const std::string _interface;
-
- /**
- * Target speed for this fan
- */
- uint64_t _targetSpeed;
+ /**
+ * Target speed for this fan
+ */
+ uint64_t _targetSpeed;
};
-
-}
-}
-}
+} // namespace control
+} // namespace fan
+} // namespace phosphor
diff --git a/control/functor.hpp b/control/functor.hpp
index 6251ce8..f631311 100644
--- a/control/functor.hpp
+++ b/control/functor.hpp
@@ -1,7 +1,8 @@
#pragma once
-#include "types.hpp"
#include "sdbusplus.hpp"
+#include "types.hpp"
+
#include <phosphor-logging/log.hpp>
namespace phosphor
@@ -39,7 +40,7 @@
template <typename T>
auto make_trigger(T&& trigger)
{
- return Trigger(std::forward<T>(trigger));
+ return Trigger(std::forward<T>(trigger));
}
/**
@@ -86,24 +87,20 @@
Properties& operator=(const Properties&) = default;
Properties(Properties&&) = default;
Properties& operator=(Properties&&) = default;
- explicit Properties(U&& handler) :
- _handler(std::forward<U>(handler)) { }
- Properties(const char* path,
- const char* intf,
- const char* prop,
+ explicit Properties(U&& handler) : _handler(std::forward<U>(handler))
+ {}
+ Properties(const char* path, const char* intf, const char* prop,
U&& handler) :
_path(path),
- _intf(intf),
- _prop(prop),
- _handler(std::forward<U>(handler)) { }
+ _intf(intf), _prop(prop), _handler(std::forward<U>(handler))
+ {}
/** @brief Run signal handler function
*
* Extract the property from the PropertiesChanged
* message and run the handler function.
*/
- void operator()(sdbusplus::bus::bus& bus,
- sdbusplus::message::message& msg,
+ void operator()(sdbusplus::bus::bus& bus, sdbusplus::message::message& msg,
Zone& zone) const
{
if (msg)
@@ -159,10 +156,8 @@
void operator()(Zone& zone, const Group& group) const
{
std::for_each(
- group.begin(),
- group.end(),
- [&zone, handler = std::move(_handler)](auto const& member)
- {
+ group.begin(), group.end(),
+ [&zone, handler = std::move(_handler)](auto const& member) {
auto path = std::get<pathPos>(member);
auto intf = std::get<intfPos>(member);
auto prop = std::get<propPos>(member);
@@ -179,11 +174,10 @@
{
// Property value not sent to handler
}
- }
- );
+ });
}
-private:
+ private:
const char* _path;
const char* _intf;
const char* _prop;
@@ -202,15 +196,10 @@
* @tparam U - The type of the handler
*/
template <typename T, typename U>
-auto propertiesChanged(const char* path,
- const char* intf,
- const char* prop,
+auto propertiesChanged(const char* path, const char* intf, const char* prop,
U&& handler)
{
- return Properties<T, U>(path,
- intf,
- prop,
- std::forward<U>(handler));
+ return Properties<T, U>(path, intf, prop, std::forward<U>(handler));
}
/**
@@ -243,22 +232,18 @@
InterfacesAdded& operator=(const InterfacesAdded&) = default;
InterfacesAdded(InterfacesAdded&&) = default;
InterfacesAdded& operator=(InterfacesAdded&&) = default;
- InterfacesAdded(const char* path,
- const char* intf,
- const char* prop,
+ InterfacesAdded(const char* path, const char* intf, const char* prop,
U&& handler) :
_path(path),
- _intf(intf),
- _prop(prop),
- _handler(std::forward<U>(handler)) { }
+ _intf(intf), _prop(prop), _handler(std::forward<U>(handler))
+ {}
/** @brief Run signal handler function
*
* Extract the property from the InterfacesAdded
* message and run the handler function.
*/
- void operator()(sdbusplus::bus::bus&,
- sdbusplus::message::message& msg,
+ void operator()(sdbusplus::bus::bus&, sdbusplus::message::message& msg,
Zone& zone) const
{
if (msg)
@@ -272,8 +257,8 @@
return;
}
- std::map<std::string, std::map<std::string,
- PropertyVariantType>> intfProp;
+ std::map<std::string, std::map<std::string, PropertyVariantType>>
+ intfProp;
msg.read(intfProp);
auto itIntf = intfProp.find(_intf);
if (itIntf == intfProp.cend())
@@ -296,7 +281,7 @@
}
}
-private:
+ private:
const char* _path;
const char* _intf;
const char* _prop;
@@ -315,15 +300,10 @@
* @tparam U - The type of the handler
*/
template <typename T, typename U>
-auto interfacesAdded(const char* path,
- const char* intf,
- const char* prop,
+auto interfacesAdded(const char* path, const char* intf, const char* prop,
U&& handler)
{
- return InterfacesAdded<T, U>(path,
- intf,
- prop,
- std::forward<U>(handler));
+ return InterfacesAdded<T, U>(path, intf, prop, std::forward<U>(handler));
}
/**
@@ -341,20 +321,16 @@
InterfacesRemoved& operator=(const InterfacesRemoved&) = default;
InterfacesRemoved(InterfacesRemoved&&) = default;
InterfacesRemoved& operator=(InterfacesRemoved&&) = default;
- InterfacesRemoved(const char* path,
- const char* intf,
- U&& handler) :
- _path(path),
- _intf(intf),
- _handler(std::forward<U>(handler)) { }
+ InterfacesRemoved(const char* path, const char* intf, U&& handler) :
+ _path(path), _intf(intf), _handler(std::forward<U>(handler))
+ {}
/** @brief Run signal handler function
*
* Extract the interfaces from the InterfacesRemoved
* message and run the handler function.
*/
- void operator()(sdbusplus::bus::bus&,
- sdbusplus::message::message& msg,
+ void operator()(sdbusplus::bus::bus&, sdbusplus::message::message& msg,
Zone& zone) const
{
if (msg)
@@ -381,7 +357,7 @@
}
}
-private:
+ private:
const char* _path;
const char* _intf;
U _handler;
@@ -397,13 +373,9 @@
* @tparam U - The type of the handler
*/
template <typename U>
-auto interfacesRemoved(const char* path,
- const char* intf,
- U&& handler)
+auto interfacesRemoved(const char* path, const char* intf, U&& handler)
{
- return InterfacesRemoved<U>(path,
- intf,
- std::forward<U>(handler));
+ return InterfacesRemoved<U>(path, intf, std::forward<U>(handler));
}
/**
@@ -421,16 +393,15 @@
NameOwner& operator=(const NameOwner&) = default;
NameOwner(NameOwner&&) = default;
NameOwner& operator=(NameOwner&&) = default;
- explicit NameOwner(U&& handler) :
- _handler(std::forward<U>(handler)) { }
+ explicit NameOwner(U&& handler) : _handler(std::forward<U>(handler))
+ {}
/** @brief Run signal handler function
*
* Extract the name owner from the NameOwnerChanged
* message and run the handler function.
*/
- void operator()(sdbusplus::bus::bus& bus,
- sdbusplus::message::message& msg,
+ void operator()(sdbusplus::bus::bus& bus, sdbusplus::message::message& msg,
Zone& zone) const
{
std::string name;
@@ -453,17 +424,14 @@
}
}
- void operator()(Zone& zone,
- const Group& group) const
+ void operator()(Zone& zone, const Group& group) const
{
std::string name = "";
bool hasOwner = false;
std::for_each(
- group.begin(),
- group.end(),
- [&zone, &group, &name, &hasOwner, handler = std::move(_handler)](
- auto const& member)
- {
+ group.begin(), group.end(),
+ [&zone, &group, &name, &hasOwner,
+ handler = std::move(_handler)](auto const& member) {
auto path = std::get<pathPos>(member);
auto intf = std::get<intfPos>(member);
try
@@ -473,12 +441,9 @@
{
name = servName;
hasOwner = util::SDBusPlus::callMethodAndRead<bool>(
- zone.getBus(),
- "org.freedesktop.DBus",
- "/org/freedesktop/DBus",
- "org.freedesktop.DBus",
- "NameHasOwner",
- name);
+ zone.getBus(), "org.freedesktop.DBus",
+ "/org/freedesktop/DBus", "org.freedesktop.DBus",
+ "NameHasOwner", name);
// Update service name owner state list of a group
handler(zone, name, hasOwner);
}
@@ -489,11 +454,10 @@
name = "";
hasOwner = false;
}
- }
- );
+ });
}
-private:
+ private:
U _handler;
};
diff --git a/control/handlers.hpp b/control/handlers.hpp
index d1f6a94..1e82b37 100644
--- a/control/handlers.hpp
+++ b/control/handlers.hpp
@@ -24,14 +24,10 @@
* A lambda function to set/update the zone property
*/
template <typename T>
-auto setZoneProperty(const char* intf,
- const char* prop,
- T (Zone::*func)(T),
- T&& value,
- bool persist)
+auto setZoneProperty(const char* intf, const char* prop, T (Zone::*func)(T),
+ T&& value, bool persist)
{
- return [=, value = std::forward<T>(value)](auto& zone)
- {
+ return [=, value = std::forward<T>(value)](auto& zone) {
(zone.*func)(value);
if (persist)
{
@@ -55,8 +51,7 @@
template <typename T>
auto setProperty()
{
- return [](auto& zone, auto& path, auto& intf, auto& prop, T&& arg)
- {
+ return [](auto& zone, auto& path, auto& intf, auto& prop, T&& arg) {
zone.setPropertyValue(path, intf, prop, std::forward<T>(arg));
};
}
@@ -73,8 +68,7 @@
*/
auto setService(Group&& group)
{
- return [group = std::move(group)](auto& zone, auto& name, bool hasOwner)
- {
+ return [group = std::move(group)](auto& zone, auto& name, bool hasOwner) {
// Update service name owner state list of a group
zone.setServiceOwner(&group, name, hasOwner);
};
@@ -93,10 +87,7 @@
*/
auto removeInterface(const char* path, const char* interface)
{
- return[=](auto& zone)
- {
- zone.removeObjectInterface(path, interface);
- };
+ return [=](auto& zone) { zone.removeObjectInterface(path, interface); };
}
} // namespace handler
diff --git a/control/main.cpp b/control/main.cpp
index 4420488..05dce98 100644
--- a/control/main.cpp
+++ b/control/main.cpp
@@ -13,13 +13,14 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-#include <sdbusplus/bus.hpp>
-#include <sdeventplus/event.hpp>
-#include <phosphor-logging/log.hpp>
#include "argument.hpp"
#include "manager.hpp"
#include "sdbusplus.hpp"
+#include <phosphor-logging/log.hpp>
+#include <sdbusplus/bus.hpp>
+#include <sdeventplus/event.hpp>
+
using namespace phosphor::fan::control;
using namespace phosphor::logging;
@@ -51,15 +52,15 @@
return 1;
}
- //Attach the event object to the bus object so we can
- //handle both sd_events (for the timers) and dbus signals.
+ // Attach the event object to the bus object so we can
+ // handle both sd_events (for the timers) and dbus signals.
bus.attach_event(event.get(), SD_EVENT_PRIORITY_NORMAL);
try
{
Manager manager(bus, event, mode);
- //Init mode will just set fans to max and delay
+ // Init mode will just set fans to max and delay
if (mode == Mode::init)
{
manager.doInit();
@@ -68,29 +69,29 @@
return event.loop();
}
- //Log the useful metadata on these exceptions and let the app
- //return 1 so it is restarted without a core dump.
+ // Log the useful metadata on these exceptions and let the app
+ // return 1 so it is restarted without a core dump.
catch (phosphor::fan::util::DBusServiceError& e)
{
log<level::ERR>("Uncaught DBus service lookup failure exception",
- entry("PATH=%s", e.path.c_str()),
- entry("INTERFACE=%s", e.interface.c_str()));
+ entry("PATH=%s", e.path.c_str()),
+ entry("INTERFACE=%s", e.interface.c_str()));
}
catch (phosphor::fan::util::DBusMethodError& e)
{
log<level::ERR>("Uncaught DBus method failure exception",
- entry("BUSNAME=%s", e.busName.c_str()),
- entry("PATH=%s", e.path.c_str()),
- entry("INTERFACE=%s", e.interface.c_str()),
- entry("METHOD=%s", e.method.c_str()));
+ entry("BUSNAME=%s", e.busName.c_str()),
+ entry("PATH=%s", e.path.c_str()),
+ entry("INTERFACE=%s", e.interface.c_str()),
+ entry("METHOD=%s", e.method.c_str()));
}
catch (phosphor::fan::util::DBusPropertyError& e)
{
log<level::ERR>("Uncaught DBus property access failure exception",
- entry("BUSNAME=%s", e.busName.c_str()),
- entry("PATH=%s", e.path.c_str()),
- entry("INTERFACE=%s", e.interface.c_str()),
- entry("PROPERTY=%s", e.property.c_str()));
+ entry("BUSNAME=%s", e.busName.c_str()),
+ entry("PATH=%s", e.path.c_str()),
+ entry("INTERFACE=%s", e.interface.c_str()),
+ entry("PROPERTY=%s", e.property.c_str()));
}
return 1;
diff --git a/control/manager.cpp b/control/manager.cpp
index 360239c..543d42f 100644
--- a/control/manager.cpp
+++ b/control/manager.cpp
@@ -13,18 +13,23 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+#include "config.h"
+
+#include "manager.hpp"
+
+#include "sdbusplus.hpp"
+#include "utility.hpp"
+
+#include <unistd.h>
+
+#include <phosphor-logging/elog-errors.hpp>
+#include <phosphor-logging/elog.hpp>
+#include <phosphor-logging/log.hpp>
+#include <sdbusplus/bus.hpp>
+#include <xyz/openbmc_project/Common/error.hpp>
+
#include <algorithm>
#include <experimental/filesystem>
-#include <sdbusplus/bus.hpp>
-#include <phosphor-logging/log.hpp>
-#include <phosphor-logging/elog.hpp>
-#include <phosphor-logging/elog-errors.hpp>
-#include <xyz/openbmc_project/Common/error.hpp>
-#include <unistd.h>
-#include "config.h"
-#include "manager.hpp"
-#include "utility.hpp"
-#include "sdbusplus.hpp"
namespace phosphor
{
@@ -36,8 +41,8 @@
using namespace phosphor::logging;
namespace fs = std::experimental::filesystem;
-constexpr auto SYSTEMD_SERVICE = "org.freedesktop.systemd1";
-constexpr auto SYSTEMD_OBJ_PATH = "/org/freedesktop/systemd1";
+constexpr auto SYSTEMD_SERVICE = "org.freedesktop.systemd1";
+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";
@@ -62,10 +67,9 @@
if (type.compare("getProperty") == 0)
{
auto propertyValue = util::SDBusPlus::getProperty<decltype(value)>(
- bus,
- std::get<propertyPathPos>(p),
- std::get<propertyInterfacePos>(p),
- std::get<propertyNamePos>(p));
+ bus, std::get<propertyPathPos>(p),
+ std::get<propertyInterfacePos>(p),
+ std::get<propertyNamePos>(p));
if (value != propertyValue)
{
@@ -76,29 +80,26 @@
return true;
}
-
-//Note: Future code will check 'mode' before starting control algorithm
-Manager::Manager(sdbusplus::bus::bus& bus,
- const sdeventplus::Event& event,
+// Note: Future code will check 'mode' before starting control algorithm
+Manager::Manager(sdbusplus::bus::bus& bus, const sdeventplus::Event& event,
Mode mode) :
_bus(bus),
_objMgr(bus, CONTROL_OBJPATH)
{
- //Create the appropriate Zone objects based on the
- //actual system configuration.
+ // Create the appropriate Zone objects based on the
+ // actual system configuration.
- //Find the 1 ZoneGroup that meets all of its conditions
+ // Find the 1 ZoneGroup that meets all of its conditions
for (auto& group : _zoneLayouts)
{
auto& conditions = std::get<conditionListPos>(group);
if (std::all_of(conditions.begin(), conditions.end(),
- [&bus](const auto& condition)
+ [&bus](const auto& condition) {
+ return checkCondition(bus, condition);
+ }))
{
- return checkCondition(bus, condition);
- }))
- {
- //Create a Zone object for each zone in this group
+ // Create a Zone object for each zone in this group
auto& zones = std::get<zoneListPos>(group);
for (auto& z : zones)
@@ -106,11 +107,8 @@
fs::path path{CONTROL_OBJPATH};
path /= std::to_string(std::get<zoneNumPos>(z));
_zones.emplace(std::get<zoneNumPos>(z),
- std::make_unique<Zone>(mode,
- _bus,
- path.string(),
- event,
- z));
+ std::make_unique<Zone>(mode, _bus, path.string(),
+ event, z));
}
break;
@@ -123,7 +121,6 @@
}
}
-
void Manager::doInit()
{
for (auto& z : _zones)
@@ -137,14 +134,9 @@
delay = sleep(delay);
}
- util::SDBusPlus::callMethod(
- _bus,
- SYSTEMD_SERVICE,
- SYSTEMD_OBJ_PATH,
- SYSTEMD_INTERFACE,
- "StartUnit",
- FAN_CONTROL_READY_TARGET,
- "replace");
+ util::SDBusPlus::callMethod(_bus, SYSTEMD_SERVICE, SYSTEMD_OBJ_PATH,
+ SYSTEMD_INTERFACE, "StartUnit",
+ FAN_CONTROL_READY_TARGET, "replace");
}
} // namespace control
diff --git a/control/manager.hpp b/control/manager.hpp
index c87d0d8..34ae0b9 100644
--- a/control/manager.hpp
+++ b/control/manager.hpp
@@ -1,12 +1,14 @@
#pragma once
-#include <memory>
-#include <vector>
-#include <sdbusplus/bus.hpp>
-#include <sdeventplus/event.hpp>
#include "types.hpp"
#include "zone.hpp"
+#include <sdbusplus/bus.hpp>
+#include <sdeventplus/event.hpp>
+
+#include <memory>
+#include <vector>
+
namespace phosphor
{
namespace fan
@@ -14,75 +16,70 @@
namespace control
{
-using ZoneMap = std::map<unsigned int,
- std::unique_ptr<Zone>>;
+using ZoneMap = std::map<unsigned int, std::unique_ptr<Zone>>;
/**
* @class Fan control manager
*/
class Manager
{
- public:
+ public:
+ Manager() = delete;
+ Manager(const Manager&) = delete;
+ Manager(Manager&&) = default;
+ Manager& operator=(const Manager&) = delete;
+ Manager& operator=(Manager&&) = delete;
+ ~Manager() = default;
- Manager() = delete;
- Manager(const Manager&) = delete;
- Manager(Manager&&) = default;
- Manager& operator=(const Manager&) = delete;
- Manager& operator=(Manager&&) = delete;
- ~Manager() = default;
+ /**
+ * Constructor
+ * Creates the Zone objects based on the
+ * _zoneLayouts data.
+ *
+ * @param[in] bus - The dbus object
+ * @param[in] event - The event loop
+ * @param[in] mode - The control mode
+ */
+ Manager(sdbusplus::bus::bus& bus, const sdeventplus::Event& event,
+ Mode mode);
- /**
- * Constructor
- * Creates the Zone objects based on the
- * _zoneLayouts data.
- *
- * @param[in] bus - The dbus object
- * @param[in] event - The event loop
- * @param[in] mode - The control mode
- */
- Manager(sdbusplus::bus::bus& bus,
- const sdeventplus::Event& event,
- Mode mode);
+ /**
+ * Does the fan control inititialization, which is
+ * setting fans to full, delaying so they
+ * can get there, and starting a target.
+ */
+ void doInit();
- /**
- * Does the fan control inititialization, which is
- * setting fans to full, delaying so they
- * can get there, and starting a target.
- */
- void doInit();
+ private:
+ /**
+ * The dbus object
+ */
+ sdbusplus::bus::bus& _bus;
- private:
+ /**
+ * The sdbusplus object manager
+ */
+ sdbusplus::server::manager::manager _objMgr;
- /**
- * The dbus object
- */
- sdbusplus::bus::bus& _bus;
+ /**
+ * The fan zones in the system
+ */
+ ZoneMap _zones;
- /**
- * The sdbusplus object manager
- */
- sdbusplus::server::manager::manager _objMgr;
+ /**
+ * The fan zone layout for the system.
+ * This is generated data.
+ */
+ static const std::vector<ZoneGroup> _zoneLayouts;
- /**
- * The fan zones in the system
- */
- ZoneMap _zones;
-
- /**
- * The fan zone layout for the system.
- * This is generated data.
- */
- static const std::vector<ZoneGroup> _zoneLayouts;
-
- /**
- * The number of seconds to delay after
- * fans get set to high speed on a power on
- * to give them a chance to get there.
- */
- static const unsigned int _powerOnDelay;
+ /**
+ * The number of seconds to delay after
+ * fans get set to high speed on a power on
+ * to give them a chance to get there.
+ */
+ static const unsigned int _powerOnDelay;
};
-
-}
-}
-}
+} // namespace control
+} // namespace fan
+} // namespace phosphor
diff --git a/control/matches.hpp b/control/matches.hpp
index c3b4006..b4cbd65 100644
--- a/control/matches.hpp
+++ b/control/matches.hpp
@@ -1,8 +1,9 @@
#pragma once
-#include <sdbusplus/bus.hpp>
#include "sdbusplus.hpp"
+#include <sdbusplus/bus.hpp>
+
namespace phosphor
{
namespace fan
diff --git a/control/preconditions.cpp b/control/preconditions.cpp
index cd404d1..09284a8 100644
--- a/control/preconditions.cpp
+++ b/control/preconditions.cpp
@@ -1,8 +1,11 @@
-#include <algorithm>
-#include <phosphor-logging/log.hpp>
#include "preconditions.hpp"
+
#include "zone.hpp"
+#include <phosphor-logging/log.hpp>
+
+#include <algorithm>
+
namespace phosphor
{
namespace fan
@@ -13,26 +16,22 @@
{
using namespace phosphor::fan;
+using namespace phosphor::logging;
Action property_states_match(std::vector<PrecondGroup>&& pg,
std::vector<SetSpeedEvent>&& sse)
{
- return [pg = std::move(pg),
- sse = std::move(sse)](auto& zone, auto& group)
- {
+ return [pg = std::move(pg), sse = std::move(sse)](auto& zone, auto& group) {
// Compare given precondition entries
- auto precondState = std::all_of(
- pg.begin(),
- pg.end(),
- [&zone](auto const& entry)
- {
+ auto precondState =
+ std::all_of(pg.begin(), pg.end(), [&zone](auto const& entry) {
try
{
return zone.getPropValueVariant(
- std::get<pcPathPos>(entry),
- std::get<pcIntfPos>(entry),
- std::get<pcPropPos>(entry)) ==
- std::get<pcValuePos>(entry);
+ std::get<pcPathPos>(entry),
+ std::get<pcIntfPos>(entry),
+ std::get<pcPropPos>(entry)) ==
+ std::get<pcValuePos>(entry);
}
catch (const std::out_of_range& oore)
{
@@ -47,13 +46,9 @@
"Preconditions passed, init the associated events",
entry("EVENT_COUNT=%u", sse.size()));
// Init the events when all the precondition(s) are true
- std::for_each(
- sse.begin(),
- sse.end(),
- [&zone](auto const& entry)
- {
- zone.initEvent(entry);
- });
+ std::for_each(sse.begin(), sse.end(), [&zone](auto const& entry) {
+ zone.initEvent(entry);
+ });
}
else
{
@@ -61,13 +56,9 @@
"Preconditions not met for events, events removed if present",
entry("EVENT_COUNT=%u", sse.size()));
// Unsubscribe the events' signals when any precondition is false
- std::for_each(
- sse.begin(),
- sse.end(),
- [&zone](auto const& entry)
- {
- zone.removeEvent(entry);
- });
+ std::for_each(sse.begin(), sse.end(), [&zone](auto const& entry) {
+ zone.removeEvent(entry);
+ });
zone.setFullSpeed();
}
// Update group's fan control active allowed
@@ -77,40 +68,28 @@
Action services_missing_owner(std::vector<SetSpeedEvent>&& sse)
{
- return [sse = std::move(sse)](auto& zone, auto& group)
- {
+ return [sse = std::move(sse)](auto& zone, auto& group) {
// Set/update the services of the group
zone.setServices(&group);
const auto& services = zone.getGroupServices(&group);
- auto precondState = std::any_of(
- services.begin(),
- services.end(),
- [](const auto& s)
- {
+ auto precondState =
+ std::any_of(services.begin(), services.end(), [](const auto& s) {
return !std::get<hasOwnerPos>(s);
});
if (precondState)
{
// Init the events when all the precondition(s) are true
- std::for_each(
- sse.begin(),
- sse.end(),
- [&zone](auto const& entry)
- {
- zone.initEvent(entry);
- });
+ std::for_each(sse.begin(), sse.end(), [&zone](auto const& entry) {
+ zone.initEvent(entry);
+ });
}
else
{
// Unsubscribe the events' signals when any precondition is false
- std::for_each(
- sse.begin(),
- sse.end(),
- [&zone](auto const& entry)
- {
- zone.removeEvent(entry);
- });
+ std::for_each(sse.begin(), sse.end(), [&zone](auto const& entry) {
+ zone.removeEvent(entry);
+ });
}
};
}
diff --git a/control/preconditions.hpp b/control/preconditions.hpp
index c756047..f360886 100644
--- a/control/preconditions.hpp
+++ b/control/preconditions.hpp
@@ -11,8 +11,6 @@
namespace precondition
{
-using namespace phosphor::logging;
-
/**
* @brief A precondition to compare a group of property values and
* subscribe/unsubscribe a set speed event group
diff --git a/control/triggers.cpp b/control/triggers.cpp
index 0df2a4a..cb7281c 100644
--- a/control/triggers.cpp
+++ b/control/triggers.cpp
@@ -13,46 +13,29 @@
Trigger timer(TimerConf&& tConf)
{
- return [tConf = std::move(tConf)](control::Zone& zone,
- const std::string& name,
- const Group& group,
- const std::vector<Action>& actions)
- {
- zone.addTimer(name,
- group,
- actions,
- tConf);
+ return [tConf = std::move(tConf)](
+ control::Zone& zone, const std::string& name, const Group& group,
+ const std::vector<Action>& actions) {
+ zone.addTimer(name, group, actions, tConf);
};
}
Trigger signal(const std::string& match, SignalHandler&& handler)
{
- return [match = std::move(match),
- handler = std::move(handler)](control::Zone& zone,
- const std::string& name,
- const Group& group,
- const std::vector<Action>& actions)
- {
+ return [match = std::move(match), handler = std::move(handler)](
+ control::Zone& zone, const std::string& name, const Group& group,
+ const std::vector<Action>& actions) {
// Setup signal matches of the property for event
std::unique_ptr<EventData> eventData =
- std::make_unique<EventData>(
- group,
- match,
- handler,
- actions
- );
+ std::make_unique<EventData>(group, match, handler, actions);
std::unique_ptr<sdbusplus::server::match::match> mPtr = nullptr;
if (!match.empty())
{
// Subscribe to signal match
mPtr = std::make_unique<sdbusplus::server::match::match>(
- zone.getBus(),
- match.c_str(),
- std::bind(std::mem_fn(&Zone::handleEvent),
- &zone,
- std::placeholders::_1,
- eventData.get())
- );
+ zone.getBus(), match.c_str(),
+ std::bind(std::mem_fn(&Zone::handleEvent), &zone,
+ std::placeholders::_1, eventData.get()));
}
else
{
@@ -65,13 +48,12 @@
auto ifaces = zone.getIfaces();
// Group member interface in list owned by zone
if (std::find(ifaces.begin(), ifaces.end(),
- std::get<intfPos>(entry)) != ifaces.end())
+ std::get<intfPos>(entry)) != ifaces.end())
{
// Store path,interface,property as a managed object
- zone.setObjectData(std::get<pathPos>(entry),
- std::get<intfPos>(entry),
- std::get<propPos>(entry),
- eventData.get());
+ zone.setObjectData(
+ std::get<pathPos>(entry), std::get<intfPos>(entry),
+ std::get<propPos>(entry), eventData.get());
}
}
}
@@ -82,11 +64,9 @@
Trigger init(MethodHandler&& handler)
{
- return [handler = std::move(handler)](control::Zone& zone,
- const std::string& name,
- const Group& group,
- const std::vector<Action>& actions)
- {
+ return [handler = std::move(handler)](
+ control::Zone& zone, const std::string& name, const Group& group,
+ const std::vector<Action>& actions) {
// A handler function is optional
if (handler)
{
@@ -95,13 +75,8 @@
// Run action functions for initial event state
std::for_each(
- actions.begin(),
- actions.end(),
- [&zone, &group](auto const& action)
- {
- action(zone, group);
- }
- );
+ actions.begin(), actions.end(),
+ [&zone, &group](auto const& action) { action(zone, group); });
};
}
diff --git a/control/types.hpp b/control/types.hpp
index cb9f743..0207b36 100644
--- a/control/types.hpp
+++ b/control/types.hpp
@@ -1,11 +1,12 @@
#pragma once
-#include <string>
-#include <tuple>
-#include <vector>
#include <sdbusplus/server.hpp>
#include <sdeventplus/clock.hpp>
#include <sdeventplus/utility/timer.hpp>
+#include <string>
+#include <tuple>
+#include <vector>
+
namespace phosphor
{
namespace fan
@@ -21,44 +22,32 @@
constexpr auto propertyValuePos = 3;
// TODO openbmc/openbmc#1769: Support more property types.
-using ConditionProperty = std::tuple<std::string,
- std::string,
- std::string,
- bool>;
+using ConditionProperty =
+ std::tuple<std::string, std::string, std::string, bool>;
constexpr auto conditionTypePos = 0;
constexpr auto conditionPropertyListPos = 1;
-using Condition = std::tuple<std::string,
- std::vector<ConditionProperty>>;
+using Condition = std::tuple<std::string, std::vector<ConditionProperty>>;
-using PropertyVariantType = std::variant<bool,
- int32_t,
- int64_t,
- double,
- std::string>;
+using PropertyVariantType =
+ std::variant<bool, int32_t, int64_t, double, std::string>;
constexpr auto fanNamePos = 0;
constexpr auto sensorListPos = 1;
constexpr auto targetInterfacePos = 2;
-using FanDefinition = std::tuple<std::string,
- std::vector<std::string>,
- std::string>;
+using FanDefinition =
+ std::tuple<std::string, std::vector<std::string>, std::string>;
constexpr auto pathPos = 0;
constexpr auto intfPos = 1;
constexpr auto propPos = 2;
-using Group = std::vector<std::tuple<std::string,
- std::string,
- std::string>>;
+using Group = std::vector<std::tuple<std::string, std::string, std::string>>;
using ZoneHandler = std::function<void(Zone&)>;
using SignalHandler = std::function<void(sdbusplus::bus::bus&,
- sdbusplus::message::message&,
- Zone&)>;
+ sdbusplus::message::message&, Zone&)>;
using MethodHandler = std::function<void(Zone&, const Group&)>;
using Action = std::function<void(Zone&, const Group&)>;
-using Trigger = std::function<void(Zone&,
- const std::string&,
- const Group&,
+using Trigger = std::function<void(Zone&, const std::string&, const Group&,
const std::vector<Action>&)>;
constexpr auto adGroupPos = 0;
@@ -69,10 +58,8 @@
constexpr auto pcIntfPos = 1;
constexpr auto pcPropPos = 2;
constexpr auto pcValuePos = 3;
-using PrecondGroup = std::tuple<std::string,
- std::string,
- std::string,
- PropertyVariantType>;
+using PrecondGroup =
+ std::tuple<std::string, std::string, std::string, PropertyVariantType>;
constexpr auto namePos = 0;
constexpr auto hasOwnerPos = 1;
@@ -85,8 +72,7 @@
oneshot,
repeating,
};
-using TimerConf = std::tuple<std::chrono::microseconds,
- TimerType>;
+using TimerConf = std::tuple<std::chrono::microseconds, TimerType>;
// TODO Remove event group (groupPos)
// Bind groups directly to list of actions after optimized code generated
@@ -94,19 +80,15 @@
constexpr auto groupPos = 1;
constexpr auto actionsPos = 2;
constexpr auto triggerPos = 3;
-using SetSpeedEvent = std::tuple<std::string,
- Group,
- ActionData,
- std::vector<Trigger>>;
+using SetSpeedEvent =
+ std::tuple<std::string, Group, ActionData, std::vector<Trigger>>;
constexpr auto eventGroupPos = 0;
constexpr auto eventMatchPos = 1;
constexpr auto eventHandlerPos = 2;
constexpr auto eventActionsPos = 3;
-using EventData = std::tuple<Group,
- std::string,
- SignalHandler,
- std::vector<Action>>;
+using EventData =
+ std::tuple<Group, std::string, SignalHandler, std::vector<Action>>;
constexpr auto timerEventDataPos = 0;
constexpr auto timerTimerPos = 1;
@@ -127,20 +109,16 @@
constexpr auto handlerPos = 5;
constexpr auto fanListPos = 6;
constexpr auto setSpeedEventsPos = 7;
-using ZoneDefinition = std::tuple<size_t,
- uint64_t,
- uint64_t,
- size_t,
- size_t,
- std::vector<ZoneHandler>,
- std::vector<FanDefinition>,
- std::vector<SetSpeedEvent>>;
+using ZoneDefinition =
+ std::tuple<size_t, uint64_t, uint64_t, size_t, size_t,
+ std::vector<ZoneHandler>, std::vector<FanDefinition>,
+ std::vector<SetSpeedEvent>>;
constexpr auto conditionListPos = 0;
constexpr auto zoneListPos = 1;
-using ZoneGroup = std::tuple<std::vector<Condition>,
- std::vector<ZoneDefinition>>;
+using ZoneGroup =
+ std::tuple<std::vector<Condition>, std::vector<ZoneDefinition>>;
-}
-}
-}
+} // namespace control
+} // namespace fan
+} // namespace phosphor
diff --git a/control/utility.cpp b/control/utility.cpp
index 49a8a13..8c8dadd 100644
--- a/control/utility.cpp
+++ b/control/utility.cpp
@@ -1,8 +1,8 @@
+#include "utility.hpp"
+
#include <algorithm>
#include <stdexcept>
-#include "utility.hpp"
-
namespace phosphor
{
namespace fan
diff --git a/control/utility.hpp b/control/utility.hpp
index 3458180..ba626b3 100644
--- a/control/utility.hpp
+++ b/control/utility.hpp
@@ -1,8 +1,9 @@
#pragma once
-#include <vector>
#include "types.hpp"
+#include <vector>
+
namespace phosphor
{
namespace fan
diff --git a/control/zone.cpp b/control/zone.cpp
index 82c3b70..3c87654 100644
--- a/control/zone.cpp
+++ b/control/zone.cpp
@@ -13,21 +13,25 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-#include <chrono>
-#include <functional>
-#include <fstream>
-#include <cereal/cereal.hpp>
-#include <cereal/archives/json.hpp>
-#include <experimental/filesystem>
-#include <phosphor-logging/log.hpp>
-#include <phosphor-logging/elog.hpp>
-#include <phosphor-logging/elog-errors.hpp>
-#include <stdexcept>
-#include <xyz/openbmc_project/Common/error.hpp>
#include "config.h"
+
#include "zone.hpp"
-#include "utility.hpp"
+
#include "sdbusplus.hpp"
+#include "utility.hpp"
+
+#include <cereal/archives/json.hpp>
+#include <cereal/cereal.hpp>
+#include <phosphor-logging/elog-errors.hpp>
+#include <phosphor-logging/elog.hpp>
+#include <phosphor-logging/log.hpp>
+#include <xyz/openbmc_project/Common/error.hpp>
+
+#include <chrono>
+#include <experimental/filesystem>
+#include <fstream>
+#include <functional>
+#include <stdexcept>
namespace phosphor
{
@@ -40,17 +44,13 @@
using namespace phosphor::fan;
using namespace phosphor::logging;
namespace fs = std::experimental::filesystem;
-using InternalFailure = sdbusplus::xyz::openbmc_project::Common::
- Error::InternalFailure;
+using InternalFailure =
+ sdbusplus::xyz::openbmc_project::Common::Error::InternalFailure;
-Zone::Zone(Mode mode,
- sdbusplus::bus::bus& bus,
- const std::string& path,
- const sdeventplus::Event& event,
- const ZoneDefinition& def) :
+Zone::Zone(Mode mode, sdbusplus::bus::bus& bus, const std::string& path,
+ const sdeventplus::Event& event, const ZoneDefinition& def) :
ThermalObject(bus, path.c_str(), true),
- _bus(bus),
- _path(path),
+ _bus(bus), _path(path),
_ifaces({"xyz.openbmc_project.Control.ThermalMode"}),
_fullSpeed(std::get<fullSpeedPos>(def)),
_zoneNum(std::get<zoneNumPos>(def)),
@@ -59,8 +59,7 @@
_incDelay(std::get<incDelayPos>(def)),
_decInterval(std::get<decIntervalPos>(def)),
_incTimer(event, std::bind(&Zone::incTimerExpired, this)),
- _decTimer(event, std::bind(&Zone::decTimerExpired, this)),
- _eventLoop(event)
+ _decTimer(event, std::bind(&Zone::decTimerExpired, this)), _eventLoop(event)
{
auto& fanDefs = std::get<fanListPos>(def);
@@ -133,27 +132,20 @@
else
{
// Check all entries are set to allow control active
- auto actPred = [](auto const& entry) {return entry.second;};
- _isActive = std::all_of(_active.begin(),
- _active.end(),
- actPred);
+ auto actPred = [](auto const& entry) { return entry.second; };
+ _isActive = std::all_of(_active.begin(), _active.end(), actPred);
}
}
-void Zone::removeService(const Group* group,
- const std::string& name)
+void Zone::removeService(const Group* group, const std::string& name)
{
try
{
auto& sNames = _services.at(*group);
- auto it = std::find_if(
- sNames.begin(),
- sNames.end(),
- [&name](auto const& entry)
- {
- return name == std::get<namePos>(entry);
- }
- );
+ auto it = std::find_if(sNames.begin(), sNames.end(),
+ [&name](auto const& entry) {
+ return name == std::get<namePos>(entry);
+ });
if (it != std::end(sNames))
{
// Remove service name from group
@@ -166,21 +158,16 @@
}
}
-void Zone::setServiceOwner(const Group* group,
- const std::string& name,
+void Zone::setServiceOwner(const Group* group, const std::string& name,
const bool hasOwner)
{
try
{
auto& sNames = _services.at(*group);
- auto it = std::find_if(
- sNames.begin(),
- sNames.end(),
- [&name](auto const& entry)
- {
- return name == std::get<namePos>(entry);
- }
- );
+ auto it = std::find_if(sNames.begin(), sNames.end(),
+ [&name](auto const& entry) {
+ return name == std::get<namePos>(entry);
+ });
if (it != std::end(sNames))
{
std::get<hasOwnerPos>(*it) = hasOwner;
@@ -206,15 +193,10 @@
bool hasOwner = false;
try
{
- name = getService(std::get<pathPos>(*it),
- std::get<intfPos>(*it));
+ name = getService(std::get<pathPos>(*it), std::get<intfPos>(*it));
hasOwner = util::SDBusPlus::callMethodAndRead<bool>(
- _bus,
- "org.freedesktop.DBus",
- "/org/freedesktop/DBus",
- "org.freedesktop.DBus",
- "NameHasOwner",
- name);
+ _bus, "org.freedesktop.DBus", "/org/freedesktop/DBus",
+ "org.freedesktop.DBus", "NameHasOwner", name);
}
catch (const util::DBusMethodError& e)
{
@@ -228,10 +210,8 @@
void Zone::setFloor(uint64_t speed)
{
// Check all entries are set to allow floor to be set
- auto pred = [](auto const& entry) {return entry.second;};
- auto setFloor = std::all_of(_floorChange.begin(),
- _floorChange.end(),
- pred);
+ auto pred = [](auto const& entry) { return entry.second; };
+ auto setFloor = std::all_of(_floorChange.begin(), _floorChange.end(), pred);
if (setFloor)
{
_floorSpeed = speed;
@@ -247,8 +227,7 @@
{
// Only increase speed when delta is higher than
// the current increase delta for the zone and currently under ceiling
- if (targetDelta > _incSpeedDelta &&
- _targetSpeed < _ceilingSpeed)
+ if (targetDelta > _incSpeedDelta && _targetSpeed < _ceilingSpeed)
{
auto requestTarget = getRequestSpeedBase();
requestTarget = (targetDelta - _incSpeedDelta) + requestTarget;
@@ -283,18 +262,16 @@
void Zone::decTimerExpired()
{
// Check all entries are set to allow a decrease
- auto pred = [](auto const& entry) {return entry.second;};
- auto decAllowed = std::all_of(_decAllowed.begin(),
- _decAllowed.end(),
- pred);
+ auto pred = [](auto const& entry) { return entry.second; };
+ auto decAllowed = std::all_of(_decAllowed.begin(), _decAllowed.end(), pred);
// Only decrease speeds when allowed,
// a requested decrease speed delta exists,
// where no requested increases exist and
// the increase timer is not running
// (i.e. not in the middle of increasing)
- if (decAllowed && _decSpeedDelta != 0 &&
- _incSpeedDelta == 0 && !_incTimer.isEnabled())
+ if (decAllowed && _decSpeedDelta != 0 && _incSpeedDelta == 0 &&
+ !_incTimer.isEnabled())
{
auto requestTarget = getRequestSpeedBase();
// Request target speed should not start above ceiling
@@ -323,44 +300,35 @@
{
// Enable event triggers
std::for_each(
- std::get<triggerPos>(event).begin(),
- std::get<triggerPos>(event).end(),
- [this, &event](auto const& trigger)
- {
+ std::get<triggerPos>(event).begin(), std::get<triggerPos>(event).end(),
+ [this, &event](auto const& trigger) {
if (!std::get<actionsPos>(event).empty())
{
std::for_each(
std::get<actionsPos>(event).begin(),
std::get<actionsPos>(event).end(),
- [this, &trigger, &event](auto const& action)
- {
+ [this, &trigger, &event](auto const& action) {
// Default to use group defined with action if exists
if (!std::get<adGroupPos>(action).empty())
{
- trigger(*this,
- std::get<sseNamePos>(event),
+ trigger(*this, std::get<sseNamePos>(event),
std::get<adGroupPos>(action),
std::get<adActionsPos>(action));
}
else
{
- trigger(*this,
- std::get<sseNamePos>(event),
+ trigger(*this, std::get<sseNamePos>(event),
std::get<groupPos>(event),
std::get<adActionsPos>(action));
}
- }
- );
+ });
}
else
{
- trigger(*this,
- std::get<sseNamePos>(event),
- std::get<groupPos>(event),
- {});
+ trigger(*this, std::get<sseNamePos>(event),
+ std::get<groupPos>(event), {});
}
- }
- );
+ });
}
void Zone::removeEvent(const SetSpeedEvent& event)
@@ -385,28 +353,24 @@
}
}
-std::vector<TimerEvent>::iterator Zone::findTimer(
- const Group& eventGroup,
- const std::vector<Action>& eventActions,
- std::vector<TimerEvent>& eventTimers)
+std::vector<TimerEvent>::iterator
+ Zone::findTimer(const Group& eventGroup,
+ const std::vector<Action>& eventActions,
+ std::vector<TimerEvent>& eventTimers)
{
for (auto it = eventTimers.begin(); it != eventTimers.end(); ++it)
{
const auto& teEventData = *std::get<timerEventDataPos>(*it);
if (std::get<eventGroupPos>(teEventData) == eventGroup &&
std::get<eventActionsPos>(teEventData).size() ==
- eventActions.size())
+ eventActions.size())
{
// TODO openbmc/openbmc#2328 - Use the action function target
// for comparison
- auto actsEqual = [](auto const& a1,
- auto const& a2)
- {
- return a1.target_type().name() ==
- a2.target_type().name();
- };
- if (std::equal(eventActions.begin(),
- eventActions.end(),
+ auto actsEqual = [](auto const& a1, auto const& a2) {
+ return a1.target_type().name() == a2.target_type().name();
+ };
+ if (std::equal(eventActions.begin(), eventActions.end(),
std::get<eventActionsPos>(teEventData).begin(),
actsEqual))
{
@@ -418,21 +382,13 @@
return eventTimers.end();
}
-void Zone::addTimer(const std::string& name,
- const Group& group,
- const std::vector<Action>& actions,
- const TimerConf& tConf)
+void Zone::addTimer(const std::string& name, const Group& group,
+ const std::vector<Action>& actions, const TimerConf& tConf)
{
- auto eventData = std::make_unique<EventData>(
- group,
- "",
- nullptr,
- actions
- );
+ auto eventData = std::make_unique<EventData>(group, "", nullptr, actions);
Timer timer(
_eventLoop,
- std::bind(&Zone::timerExpired,
- this,
+ std::bind(&Zone::timerExpired, this,
std::cref(std::get<Group>(*eventData)),
std::cref(std::get<std::vector<Action>>(*eventData))));
if (std::get<TimerType>(tConf) == TimerType::repeating)
@@ -454,28 +410,22 @@
const std::vector<Action>& eventActions)
{
// Perform the actions
- std::for_each(eventActions.begin(),
- eventActions.end(),
- [this, &eventGroup](auto const& action)
- {
- action(*this, eventGroup);
- });
+ std::for_each(
+ eventActions.begin(), eventActions.end(),
+ [this, &eventGroup](auto const& action) { action(*this, eventGroup); });
}
void Zone::handleEvent(sdbusplus::message::message& msg,
const EventData* eventData)
{
// Handle the callback
- std::get<eventHandlerPos>(*eventData)(_bus, msg, *this);
+ std::get<eventHandlerPos> (*eventData)(_bus, msg, *this);
// Perform the actions
- std::for_each(
- std::get<eventActionsPos>(*eventData).begin(),
- std::get<eventActionsPos>(*eventData).end(),
- [this, &eventData](auto const& action)
- {
- action(*this,
- std::get<eventGroupPos>(*eventData));
- });
+ std::for_each(std::get<eventActionsPos>(*eventData).begin(),
+ std::get<eventActionsPos>(*eventData).end(),
+ [this, &eventData](auto const& action) {
+ action(*this, std::get<eventGroupPos>(*eventData));
+ });
}
const std::string& Zone::getService(const std::string& path,
@@ -488,12 +438,8 @@
for (auto& serv : srvIter->second)
{
auto it = std::find_if(
- serv.second.begin(),
- serv.second.end(),
- [&intf](auto const& interface)
- {
- return intf == interface;
- });
+ serv.second.begin(), serv.second.end(),
+ [&intf](auto const& interface) { return intf == interface; });
if (it != std::end(serv.second))
{
// Service found
@@ -511,8 +457,7 @@
}
const std::string& Zone::addServices(const std::string& path,
- const std::string& intf,
- int32_t depth)
+ const std::string& intf, int32_t depth)
{
static const std::string empty = "";
auto it = _servTree.end();
@@ -570,20 +515,15 @@
return empty;
}
-auto Zone::getPersisted(const std::string& intf,
- const std::string& prop)
+auto Zone::getPersisted(const std::string& intf, const std::string& prop)
{
auto persisted = false;
auto it = _persisted.find(intf);
if (it != _persisted.end())
{
- return std::any_of(it->second.begin(),
- it->second.end(),
- [&prop](auto& p)
- {
- return prop == p;
- });
+ return std::any_of(it->second.begin(), it->second.end(),
+ [&prop](auto& p) { return prop == p; });
}
return persisted;
@@ -595,11 +535,8 @@
std::transform(value.begin(), value.end(), value.begin(), toupper);
auto supported = ThermalObject::supported();
- auto isSupported = std::any_of(
- supported.begin(),
- supported.end(),
- [&value](auto& s)
- {
+ auto isSupported =
+ std::any_of(supported.begin(), supported.end(), [&value](auto& s) {
std::transform(s.begin(), s.end(), s.begin(), toupper);
return value == s;
});
@@ -612,8 +549,7 @@
saveCurrentMode();
}
// Trigger event(s) for current mode property change
- auto eData = _objects[_path]
- ["xyz.openbmc_project.Control.ThermalMode"]
+ auto eData = _objects[_path]["xyz.openbmc_project.Control.ThermalMode"]
["Current"];
if (eData != nullptr)
{
@@ -663,6 +599,6 @@
this->current(current);
}
-}
-}
-}
+} // namespace control
+} // namespace fan
+} // namespace phosphor
diff --git a/control/zone.hpp b/control/zone.hpp
index 71fba32..e7c01f3 100644
--- a/control/zone.hpp
+++ b/control/zone.hpp
@@ -1,16 +1,18 @@
#pragma once
+#include "fan.hpp"
+#include "sdbusplus.hpp"
+#include "types.hpp"
+#include "xyz/openbmc_project/Control/ThermalMode/server.hpp"
+
+#include <sdbusplus/bus.hpp>
+#include <sdeventplus/event.hpp>
+
#include <algorithm>
#include <cassert>
#include <chrono>
#include <cmath>
-#include <sdbusplus/bus.hpp>
-#include <sdeventplus/event.hpp>
-#include <vector>
#include <optional>
-#include "fan.hpp"
-#include "types.hpp"
-#include "sdbusplus.hpp"
-#include "xyz/openbmc_project/Control/ThermalMode/server.hpp"
+#include <vector>
namespace phosphor
{
@@ -39,223 +41,212 @@
*/
class Zone : public ThermalObject
{
- public:
+ public:
+ Zone() = delete;
+ Zone(const Zone&) = delete;
+ Zone(Zone&&) = delete;
+ Zone& operator=(const Zone&) = delete;
+ Zone& operator=(Zone&&) = delete;
+ ~Zone() = default;
- Zone() = delete;
- Zone(const Zone&) = delete;
- Zone(Zone&&) = delete;
- Zone& operator=(const Zone&) = delete;
- Zone& operator=(Zone&&) = delete;
- ~Zone() = default;
+ /**
+ * Constructor
+ * Creates the appropriate fan objects based on
+ * the zone definition data passed in.
+ *
+ * @param[in] mode - mode of fan control
+ * @param[in] bus - the dbus object
+ * @param[in] path - object instance path
+ * @param[in] event - Event loop reference
+ * @param[in] def - the fan zone definition data
+ */
+ Zone(Mode mode, sdbusplus::bus::bus& bus, const std::string& path,
+ const sdeventplus::Event& event, const ZoneDefinition& def);
- /**
- * Constructor
- * Creates the appropriate fan objects based on
- * the zone definition data passed in.
- *
- * @param[in] mode - mode of fan control
- * @param[in] bus - the dbus object
- * @param[in] path - object instance path
- * @param[in] event - Event loop reference
- * @param[in] def - the fan zone definition data
- */
- Zone(Mode mode,
- sdbusplus::bus::bus& bus,
- const std::string& path,
- const sdeventplus::Event& event,
- const ZoneDefinition& def);
+ /**
+ * @brief Get the zone's bus
+ *
+ * @return The bus used by the zone
+ */
+ inline auto& getBus()
+ {
+ return _bus;
+ }
- /**
- * @brief Get the zone's bus
- *
- * @return The bus used by the zone
- */
- inline auto& getBus()
- {
- return _bus;
- }
+ /**
+ * @brief Get the zone's path
+ *
+ * @return The path of this zone
+ */
+ inline auto& getPath()
+ {
+ return _path;
+ }
- /**
- * @brief Get the zone's path
- *
- * @return The path of this zone
- */
- inline auto& getPath()
- {
- return _path;
- }
+ /**
+ * @brief Get the zone's hosted interfaces
+ *
+ * @return The interfaces hosted by this zone
+ */
+ inline auto& getIfaces()
+ {
+ return _ifaces;
+ }
- /**
- * @brief Get the zone's hosted interfaces
- *
- * @return The interfaces hosted by this zone
- */
- inline auto& getIfaces()
- {
- return _ifaces;
- }
+ /**
+ * Sets all fans in the zone to the speed
+ * passed in when the zone is active
+ *
+ * @param[in] speed - the fan speed
+ */
+ void setSpeed(uint64_t speed);
- /**
- * Sets all fans in the zone to the speed
- * passed in when the zone is active
- *
- * @param[in] speed - the fan speed
- */
- void setSpeed(uint64_t speed);
+ /**
+ * Sets the zone to full speed regardless of zone's active state
+ */
+ void setFullSpeed();
- /**
- * Sets the zone to full speed regardless of zone's active state
- */
- void setFullSpeed();
+ /**
+ * @brief Sets the automatic fan control allowed active state
+ *
+ * @param[in] group - A group that affects the active state
+ * @param[in] isActiveAllow - Active state according to group
+ */
+ void setActiveAllow(const Group* group, bool isActiveAllow);
- /**
- * @brief Sets the automatic fan control allowed active state
- *
- * @param[in] group - A group that affects the active state
- * @param[in] isActiveAllow - Active state according to group
- */
- void setActiveAllow(const Group* group, bool isActiveAllow);
+ /**
+ * @brief Sets the floor change allowed state
+ *
+ * @param[in] group - A group that affects floor changes
+ * @param[in] isAllow - Allow state according to group
+ */
+ inline void setFloorChangeAllow(const Group* group, bool isAllow)
+ {
+ _floorChange[*(group)] = isAllow;
+ }
- /**
- * @brief Sets the floor change allowed state
- *
- * @param[in] group - A group that affects floor changes
- * @param[in] isAllow - Allow state according to group
- */
- inline void setFloorChangeAllow(const Group* group, bool isAllow)
- {
- _floorChange[*(group)] = isAllow;
- }
+ /**
+ * @brief Sets the decrease allowed state of a group
+ *
+ * @param[in] group - A group that affects speed decreases
+ * @param[in] isAllow - Allow state according to group
+ */
+ inline void setDecreaseAllow(const Group* group, bool isAllow)
+ {
+ _decAllowed[*(group)] = isAllow;
+ }
- /**
- * @brief Sets the decrease allowed state of a group
- *
- * @param[in] group - A group that affects speed decreases
- * @param[in] isAllow - Allow state according to group
- */
- inline void setDecreaseAllow(const Group* group, bool isAllow)
- {
- _decAllowed[*(group)] = isAllow;
- }
-
- /**
- * @brief Sets a given object's event data for a property on this zone
- *
- * @param[in] object - Name of the object containing the property
- * @param[in] interface - Interface name containing the property
- * @param[in] property - Property name
- * @param[in] data - Property value
- */
- inline void setObjectData(const std::string& object,
- const std::string& interface,
- const std::string& property,
- EventData* data)
- {
- _objects[object][interface][property] = data;
- }
-
- /**
- * @brief Sets a given object's property value
- *
- * @param[in] object - Name of the object containing the property
- * @param[in] interface - Interface name containing the property
- * @param[in] property - Property name
- * @param[in] value - Property value
- */
- template <typename T>
- void setPropertyValue(const char* object,
- const char* interface,
- const char* property,
- T value)
- {
- _properties[object][interface][property] = value;
- };
-
- /**
- * @brief Sets a given object's property value
- *
- * @param[in] object - Name of the object containing the property
- * @param[in] interface - Interface name containing the property
- * @param[in] property - Property name
- * @param[in] value - Property value
- */
- template <typename T>
- void setPropertyValue(const std::string& object,
+ /**
+ * @brief Sets a given object's event data for a property on this zone
+ *
+ * @param[in] object - Name of the object containing the property
+ * @param[in] interface - Interface name containing the property
+ * @param[in] property - Property name
+ * @param[in] data - Property value
+ */
+ inline void setObjectData(const std::string& object,
const std::string& interface,
- const std::string& property,
- T value)
- {
- _properties[object][interface][property] = value;
- };
+ const std::string& property, EventData* data)
+ {
+ _objects[object][interface][property] = data;
+ }
- /**
- * @brief Get the value of an object's property
- *
- * @param[in] object - Name of the object containing the property
- * @param[in] interface - Interface name containing the property
- * @param[in] property - Property name
- *
- * @return - The property value
- */
- template <typename T>
- inline auto getPropertyValue(const std::string& object,
- const std::string& interface,
- const std::string& property)
- {
- return std::get<T>(
- _properties.at(object).at(interface).at(property));
- };
+ /**
+ * @brief Sets a given object's property value
+ *
+ * @param[in] object - Name of the object containing the property
+ * @param[in] interface - Interface name containing the property
+ * @param[in] property - Property name
+ * @param[in] value - Property value
+ */
+ template <typename T>
+ void setPropertyValue(const char* object, const char* interface,
+ const char* property, T value)
+ {
+ _properties[object][interface][property] = value;
+ };
- /**
- * @brief Get the object's property variant
- *
- * @param[in] object - Name of the object containing the property
- * @param[in] interface - Interface name containing the property
- * @param[in] property - Property name
- *
- * @return - The property variant
- */
- inline auto getPropValueVariant(const std::string& object,
- const std::string& interface,
- const std::string& property)
- {
- return _properties.at(object).at(interface).at(property);
- };
+ /**
+ * @brief Sets a given object's property value
+ *
+ * @param[in] object - Name of the object containing the property
+ * @param[in] interface - Interface name containing the property
+ * @param[in] property - Property name
+ * @param[in] value - Property value
+ */
+ template <typename T>
+ void setPropertyValue(const std::string& object,
+ const std::string& interface,
+ const std::string& property, T value)
+ {
+ _properties[object][interface][property] = value;
+ };
- /**
- * @brief Get a property's value after applying a set of visitors
- * to translate the property value's type change to keep from
- * affecting the configured use of the property.
- *
- * @param[in] intf = Interface name containing the property
- * @param[in] prop = Property name
- * @param[in] variant = Variant containing the property's value from
- * the supported property types.
- */
- template <typename T>
- inline auto getPropertyValueVisitor(
- const char* intf,
- const char* prop,
- PropertyVariantType& variant)
+ /**
+ * @brief Get the value of an object's property
+ *
+ * @param[in] object - Name of the object containing the property
+ * @param[in] interface - Interface name containing the property
+ * @param[in] property - Property name
+ *
+ * @return - The property value
+ */
+ template <typename T>
+ inline auto getPropertyValue(const std::string& object,
+ const std::string& interface,
+ const std::string& property)
+ {
+ return std::get<T>(_properties.at(object).at(interface).at(property));
+ };
+
+ /**
+ * @brief Get the object's property variant
+ *
+ * @param[in] object - Name of the object containing the property
+ * @param[in] interface - Interface name containing the property
+ * @param[in] property - Property name
+ *
+ * @return - The property variant
+ */
+ inline auto getPropValueVariant(const std::string& object,
+ const std::string& interface,
+ const std::string& property)
+ {
+ return _properties.at(object).at(interface).at(property);
+ };
+
+ /**
+ * @brief Get a property's value after applying a set of visitors
+ * to translate the property value's type change to keep from
+ * affecting the configured use of the property.
+ *
+ * @param[in] intf = Interface name containing the property
+ * @param[in] prop = Property name
+ * @param[in] variant = Variant containing the property's value from
+ * the supported property types.
+ */
+ template <typename T>
+ inline auto getPropertyValueVisitor(const char* intf, const char* prop,
+ PropertyVariantType& variant)
+ {
+ // Handle the transition of the dbus sensor value type from
+ // int64 to double which also removed the scale property.
+ // https://gerrit.openbmc-project.xyz/11739
+ if (strcmp(intf, "xyz.openbmc_project.Sensor.Value") == 0 &&
+ strcmp(prop, "Value") == 0)
{
- // Handle the transition of the dbus sensor value type from
- // int64 to double which also removed the scale property.
- // https://gerrit.openbmc-project.xyz/11739
- if (strcmp(intf, "xyz.openbmc_project.Sensor.Value") == 0 &&
- strcmp(prop, "Value") == 0)
- {
- // Use 'optional' variable to determine if the sensor value
- // is set within the visitor based on the supported types.
- // A non-supported type configured will assert.
- std::optional<T> value;
- std::visit([&value](auto&& val)
- {
+ // Use 'optional' variable to determine if the sensor value
+ // is set within the visitor based on the supported types.
+ // A non-supported type configured will assert.
+ std::optional<T> value;
+ std::visit(
+ [&value](auto&& val) {
// If the type configured is int64, but the sensor value
// property's type is double, scale it by 1000 and return
// the value as an int64 as configured.
using V = std::decay_t<decltype(val)>;
- if constexpr(std::is_same_v<T, int64_t> &&
- std::is_same_v<V, double>)
+ if constexpr (std::is_same_v<T, int64_t> &&
+ std::is_same_v<V, double>)
{
val = val * 1000;
value = std::lround(val);
@@ -263,612 +254,598 @@
// If the type configured matches the sensor value
// property's type, just return the value as its
// given type.
- else if constexpr(std::is_same_v<T, V>)
+ else if constexpr (std::is_same_v<T, V>)
{
value = val;
}
- }, variant);
+ },
+ variant);
- // Unable to return Sensor Value property
- // as given type configured.
- assert(value);
+ // Unable to return Sensor Value property
+ // as given type configured.
+ assert(value);
- return value.value();
- }
+ return value.value();
+ }
- // Default to return the property's value by the data type
- // configured, applying no visitors to the variant.
- return std::get<T>(variant);
- };
+ // Default to return the property's value by the data type
+ // configured, applying no visitors to the variant.
+ return std::get<T>(variant);
+ };
- /**
- * @brief Remove an object's interface
- *
- * @param[in] object - Name of the object with the interface
- * @param[in] interface - Interface name to remove
- */
- inline void removeObjectInterface(const char* object,
- const char* interface)
+ /**
+ * @brief Remove an object's interface
+ *
+ * @param[in] object - Name of the object with the interface
+ * @param[in] interface - Interface name to remove
+ */
+ inline void removeObjectInterface(const char* object, const char* interface)
+ {
+ auto it = _properties.find(object);
+ if (it != std::end(_properties))
{
- auto it = _properties.find(object);
- if (it != std::end(_properties))
+ _properties[object].erase(interface);
+ }
+ }
+
+ /**
+ * @brief Remove a service associated to a group
+ *
+ * @param[in] group - Group associated with service
+ * @param[in] name - Service name to remove
+ */
+ void removeService(const Group* group, const std::string& name);
+
+ /**
+ * @brief Set or update a service name owner in use
+ *
+ * @param[in] group - Group associated with service
+ * @param[in] name - Service name
+ * @param[in] hasOwner - Whether the service is owned or not
+ */
+ void setServiceOwner(const Group* group, const std::string& name,
+ const bool hasOwner);
+
+ /**
+ * @brief Set or update all services for a group
+ *
+ * @param[in] group - Group to get service names for
+ */
+ void setServices(const Group* group);
+
+ /**
+ * @brief Get the group's list of service names
+ *
+ * @param[in] group - Group to get service names for
+ *
+ * @return - The list of service names
+ */
+ inline auto getGroupServices(const Group* group)
+ {
+ return _services.at(*group);
+ }
+
+ /**
+ * @brief Initialize a set speed event properties and actions
+ *
+ * @param[in] event - Set speed event
+ */
+ void initEvent(const SetSpeedEvent& event);
+
+ /**
+ * @brief Removes all the set speed event properties and actions
+ *
+ * @param[in] event - Set speed event
+ */
+ void removeEvent(const SetSpeedEvent& event);
+
+ /**
+ * @brief Get the default floor speed
+ *
+ * @return - The defined default floor speed
+ */
+ inline auto getDefFloor()
+ {
+ return _defFloorSpeed;
+ };
+
+ /**
+ * @brief Set the default floor
+ *
+ * @param[in] speed - Speed to set the default floor to
+ */
+ inline void setDefFloor(uint64_t speed)
+ {
+ _defFloorSpeed = speed;
+ };
+
+ /**
+ * @brief Get the ceiling speed
+ *
+ * @return - The current ceiling speed
+ */
+ inline auto& getCeiling() const
+ {
+ return _ceilingSpeed;
+ };
+
+ /**
+ * @brief Set the ceiling speed to the given speed
+ *
+ * @param[in] speed - Speed to set the ceiling to
+ */
+ inline void setCeiling(uint64_t speed)
+ {
+ _ceilingSpeed = speed;
+ };
+
+ /**
+ * @brief Swaps the ceiling key value with what's given and
+ * returns the value that was swapped.
+ *
+ * @param[in] keyValue - New ceiling key value
+ *
+ * @return - Ceiling key value prior to swapping
+ */
+ inline auto swapCeilingKeyValue(int64_t keyValue)
+ {
+ std::swap(_ceilingKeyValue, keyValue);
+ return keyValue;
+ };
+
+ /**
+ * @brief Get the increase speed delta
+ *
+ * @return - The current increase speed delta
+ */
+ inline auto& getIncSpeedDelta() const
+ {
+ return _incSpeedDelta;
+ };
+
+ /**
+ * @brief Get the decrease speed delta
+ *
+ * @return - The current decrease speed delta
+ */
+ inline auto& getDecSpeedDelta() const
+ {
+ return _decSpeedDelta;
+ };
+
+ /**
+ * @brief Set the floor speed to the given speed and increase target
+ * speed to the floor when target is below floor where floor changes
+ * are allowed.
+ *
+ * @param[in] speed - Speed to set the floor to
+ */
+ void setFloor(uint64_t speed);
+
+ /**
+ * @brief Set the requested speed base to be used as the speed to
+ * base a new requested speed target from
+ *
+ * @param[in] speedBase - Base speed value to use
+ */
+ inline void setRequestSpeedBase(uint64_t speedBase)
+ {
+ _requestSpeedBase = speedBase;
+ };
+
+ /**
+ * @brief Calculate the requested target speed from the given delta
+ * and increase the fan speeds, not going above the ceiling.
+ *
+ * @param[in] targetDelta - The delta to increase the target speed by
+ */
+ void requestSpeedIncrease(uint64_t targetDelta);
+
+ /**
+ * @brief Calculate the requested target speed from the given delta
+ * and increase the fan speeds, not going above the ceiling.
+ *
+ * @param[in] targetDelta - The delta to increase the target speed by
+ */
+ void requestSpeedDecrease(uint64_t targetDelta);
+
+ /**
+ * @brief Callback function for the increase timer that delays
+ * processing of requested speed increases while fans are increasing
+ */
+ void incTimerExpired();
+
+ /**
+ * @brief Callback function for the decrease timer that processes any
+ * requested speed decreases if allowed
+ */
+ void decTimerExpired();
+
+ /**
+ * @brief Get the event loop used with this zone's timers
+ *
+ * @return - The event loop for timers
+ */
+ inline auto& getEventLoop()
+ {
+ return _eventLoop;
+ }
+
+ /**
+ * @brief Remove the given signal event
+ *
+ * @param[in] seIter - Iterator pointing to the signal event to remove
+ */
+ inline void removeSignal(std::vector<SignalEvent>::iterator& seIter)
+ {
+ std::get<signalEventDataPos>(*seIter).reset();
+ if (std::get<signalMatchPos>(*seIter) != nullptr)
+ {
+ std::get<signalMatchPos>(*seIter).reset();
+ }
+ }
+
+ /**
+ * @brief Get the list of timer events
+ *
+ * @return - List of timer events
+ */
+ inline auto& getTimerEvents()
+ {
+ return _timerEvents;
+ }
+
+ /**
+ * @brief Find the first instance of a timer event
+ *
+ * @param[in] eventGroup - Group associated with a timer
+ * @param[in] eventActions - List of actions associated with a timer
+ * @param[in] eventTimers - List of timers to find the timer in
+ *
+ * @return - Iterator to the timer event
+ */
+ std::vector<TimerEvent>::iterator
+ findTimer(const Group& eventGroup,
+ const std::vector<Action>& eventActions,
+ std::vector<TimerEvent>& eventTimers);
+
+ /**
+ * @brief Add a timer to the list of timer based events
+ *
+ * @param[in] name - Event name associated with timer
+ * @param[in] group - Group associated with a timer
+ * @param[in] actions - List of actions associated with a timer
+ * @param[in] tConf - Configuration for the new timer
+ */
+ void addTimer(const std::string& name, const Group& group,
+ const std::vector<Action>& actions, const TimerConf& tConf);
+
+ /**
+ * @brief Callback function for event timers that processes the given
+ * actions for a group
+ *
+ * @param[in] eventGroup - Group to process actions on
+ * @param[in] eventActions - List of event actions to run
+ */
+ void timerExpired(const Group& eventGroup,
+ const std::vector<Action>& eventActions);
+
+ /**
+ * @brief Get the service for a given path and interface from cached
+ * dataset and add a service that's not found
+ *
+ * @param[in] path - Path to get service for
+ * @param[in] intf - Interface to get service for
+ *
+ * @return - The service name
+ */
+ const std::string& getService(const std::string& path,
+ const std::string& intf);
+
+ /**
+ * @brief Add a set of services for a path and interface
+ * by retrieving all the path subtrees to the given depth
+ * from root for the interface
+ *
+ * @param[in] path - Path to add services for
+ * @param[in] intf - Interface to add services for
+ * @param[in] depth - Depth of tree traversal from root path
+ *
+ * @return - The associated service to the given path and interface
+ * or empty string for no service found
+ */
+ const std::string& addServices(const std::string& path,
+ const std::string& intf, int32_t depth);
+
+ /**
+ * @brief Dbus signal change callback handler
+ *
+ * @param[in] msg - Expanded sdbusplus message data
+ * @param[in] eventData - The single event's data
+ */
+ void handleEvent(sdbusplus::message::message& msg,
+ const EventData* eventData);
+
+ /**
+ * @brief Add a signal to the list of signal based events
+ *
+ * @param[in] name - Event name
+ * @param[in] data - Event data for signal
+ * @param[in] match - Subscribed signal match
+ */
+ inline void
+ addSignal(const std::string& name, std::unique_ptr<EventData>&& data,
+ std::unique_ptr<sdbusplus::server::match::match>&& match)
+ {
+ _signalEvents[name].emplace_back(std::move(data), std::move(match));
+ }
+
+ /**
+ * @brief Set a property to be persisted
+ *
+ * @param[in] intf - Interface containing property
+ * @param[in] prop - Property to be persisted
+ */
+ inline void setPersisted(const std::string& intf, const std::string& prop)
+ {
+ _persisted[intf].emplace_back(prop);
+ }
+
+ /**
+ * @brief Get persisted property
+ *
+ * @param[in] intf - Interface containing property
+ * @param[in] prop - Property persisted
+ *
+ * @return - True if property is to be persisted, false otherwise
+ */
+ auto getPersisted(const std::string& intf, const std::string& prop);
+
+ /**
+ * @brief Get a property value from the zone object or the bus when
+ * the property requested is not on the zone object
+ *
+ * @param[in] path - Path of object
+ * @param[in] intf - Object interface
+ * @param[in] prop - Object property
+ *
+ * @return - Property's value
+ */
+ template <typename T>
+ auto getPropertyByName(const std::string& path, const std::string& intf,
+ const std::string& prop)
+ {
+ T value;
+ auto pathIter = _objects.find(path);
+ if (pathIter != _objects.end())
+ {
+ auto intfIter = pathIter->second.find(intf);
+ if (intfIter != pathIter->second.end())
{
- _properties[object].erase(interface);
- }
- }
-
- /**
- * @brief Remove a service associated to a group
- *
- * @param[in] group - Group associated with service
- * @param[in] name - Service name to remove
- */
- void removeService(const Group* group,
- const std::string& name);
-
- /**
- * @brief Set or update a service name owner in use
- *
- * @param[in] group - Group associated with service
- * @param[in] name - Service name
- * @param[in] hasOwner - Whether the service is owned or not
- */
- void setServiceOwner(const Group* group,
- const std::string& name,
- const bool hasOwner);
-
- /**
- * @brief Set or update all services for a group
- *
- * @param[in] group - Group to get service names for
- */
- void setServices(const Group* group);
-
- /**
- * @brief Get the group's list of service names
- *
- * @param[in] group - Group to get service names for
- *
- * @return - The list of service names
- */
- inline auto getGroupServices(const Group* group)
- {
- return _services.at(*group);
- }
-
- /**
- * @brief Initialize a set speed event properties and actions
- *
- * @param[in] event - Set speed event
- */
- void initEvent(const SetSpeedEvent& event);
-
- /**
- * @brief Removes all the set speed event properties and actions
- *
- * @param[in] event - Set speed event
- */
- void removeEvent(const SetSpeedEvent& event);
-
- /**
- * @brief Get the default floor speed
- *
- * @return - The defined default floor speed
- */
- inline auto getDefFloor()
- {
- return _defFloorSpeed;
- };
-
- /**
- * @brief Set the default floor
- *
- * @param[in] speed - Speed to set the default floor to
- */
- inline void setDefFloor(uint64_t speed)
- {
- _defFloorSpeed = speed;
- };
-
- /**
- * @brief Get the ceiling speed
- *
- * @return - The current ceiling speed
- */
- inline auto& getCeiling() const
- {
- return _ceilingSpeed;
- };
-
- /**
- * @brief Set the ceiling speed to the given speed
- *
- * @param[in] speed - Speed to set the ceiling to
- */
- inline void setCeiling(uint64_t speed)
- {
- _ceilingSpeed = speed;
- };
-
- /**
- * @brief Swaps the ceiling key value with what's given and
- * returns the value that was swapped.
- *
- * @param[in] keyValue - New ceiling key value
- *
- * @return - Ceiling key value prior to swapping
- */
- inline auto swapCeilingKeyValue(int64_t keyValue)
- {
- std::swap(_ceilingKeyValue, keyValue);
- return keyValue;
- };
-
- /**
- * @brief Get the increase speed delta
- *
- * @return - The current increase speed delta
- */
- inline auto& getIncSpeedDelta() const
- {
- return _incSpeedDelta;
- };
-
- /**
- * @brief Get the decrease speed delta
- *
- * @return - The current decrease speed delta
- */
- inline auto& getDecSpeedDelta() const
- {
- return _decSpeedDelta;
- };
-
- /**
- * @brief Set the floor speed to the given speed and increase target
- * speed to the floor when target is below floor where floor changes
- * are allowed.
- *
- * @param[in] speed - Speed to set the floor to
- */
- void setFloor(uint64_t speed);
-
- /**
- * @brief Set the requested speed base to be used as the speed to
- * base a new requested speed target from
- *
- * @param[in] speedBase - Base speed value to use
- */
- inline void setRequestSpeedBase(uint64_t speedBase)
- {
- _requestSpeedBase = speedBase;
- };
-
- /**
- * @brief Calculate the requested target speed from the given delta
- * and increase the fan speeds, not going above the ceiling.
- *
- * @param[in] targetDelta - The delta to increase the target speed by
- */
- void requestSpeedIncrease(uint64_t targetDelta);
-
- /**
- * @brief Calculate the requested target speed from the given delta
- * and increase the fan speeds, not going above the ceiling.
- *
- * @param[in] targetDelta - The delta to increase the target speed by
- */
- void requestSpeedDecrease(uint64_t targetDelta);
-
- /**
- * @brief Callback function for the increase timer that delays
- * processing of requested speed increases while fans are increasing
- */
- void incTimerExpired();
-
- /**
- * @brief Callback function for the decrease timer that processes any
- * requested speed decreases if allowed
- */
- void decTimerExpired();
-
- /**
- * @brief Get the event loop used with this zone's timers
- *
- * @return - The event loop for timers
- */
- inline auto& getEventLoop()
- {
- return _eventLoop;
- }
-
- /**
- * @brief Remove the given signal event
- *
- * @param[in] seIter - Iterator pointing to the signal event to remove
- */
- inline void removeSignal(std::vector<SignalEvent>::iterator& seIter)
- {
- std::get<signalEventDataPos>(*seIter).reset();
- if (std::get<signalMatchPos>(*seIter) != nullptr)
- {
- std::get<signalMatchPos>(*seIter).reset();
- }
- }
-
- /**
- * @brief Get the list of timer events
- *
- * @return - List of timer events
- */
- inline auto& getTimerEvents()
- {
- return _timerEvents;
- }
-
- /**
- * @brief Find the first instance of a timer event
- *
- * @param[in] eventGroup - Group associated with a timer
- * @param[in] eventActions - List of actions associated with a timer
- * @param[in] eventTimers - List of timers to find the timer in
- *
- * @return - Iterator to the timer event
- */
- std::vector<TimerEvent>::iterator findTimer(
- const Group& eventGroup,
- const std::vector<Action>& eventActions,
- std::vector<TimerEvent>& eventTimers);
-
- /**
- * @brief Add a timer to the list of timer based events
- *
- * @param[in] name - Event name associated with timer
- * @param[in] group - Group associated with a timer
- * @param[in] actions - List of actions associated with a timer
- * @param[in] tConf - Configuration for the new timer
- */
- void addTimer(const std::string& name,
- const Group& group,
- const std::vector<Action>& actions,
- const TimerConf& tConf);
-
- /**
- * @brief Callback function for event timers that processes the given
- * actions for a group
- *
- * @param[in] eventGroup - Group to process actions on
- * @param[in] eventActions - List of event actions to run
- */
- void timerExpired(const Group& eventGroup,
- const std::vector<Action>& eventActions);
-
- /**
- * @brief Get the service for a given path and interface from cached
- * dataset and add a service that's not found
- *
- * @param[in] path - Path to get service for
- * @param[in] intf - Interface to get service for
- *
- * @return - The service name
- */
- const std::string& getService(const std::string& path,
- const std::string& intf);
-
- /**
- * @brief Add a set of services for a path and interface
- * by retrieving all the path subtrees to the given depth
- * from root for the interface
- *
- * @param[in] path - Path to add services for
- * @param[in] intf - Interface to add services for
- * @param[in] depth - Depth of tree traversal from root path
- *
- * @return - The associated service to the given path and interface
- * or empty string for no service found
- */
- const std::string& addServices(const std::string& path,
- const std::string& intf,
- int32_t depth);
-
- /**
- * @brief Dbus signal change callback handler
- *
- * @param[in] msg - Expanded sdbusplus message data
- * @param[in] eventData - The single event's data
- */
- void handleEvent(sdbusplus::message::message& msg,
- const EventData* eventData);
-
- /**
- * @brief Add a signal to the list of signal based events
- *
- * @param[in] name - Event name
- * @param[in] data - Event data for signal
- * @param[in] match - Subscribed signal match
- */
- inline void addSignal(
- const std::string& name,
- std::unique_ptr<EventData>&& data,
- std::unique_ptr<sdbusplus::server::match::match>&& match)
- {
- _signalEvents[name].emplace_back(std::move(data), std::move(match));
- }
-
- /**
- * @brief Set a property to be persisted
- *
- * @param[in] intf - Interface containing property
- * @param[in] prop - Property to be persisted
- */
- inline void setPersisted(const std::string& intf,
- const std::string& prop)
- {
- _persisted[intf].emplace_back(prop);
- }
-
- /**
- * @brief Get persisted property
- *
- * @param[in] intf - Interface containing property
- * @param[in] prop - Property persisted
- *
- * @return - True if property is to be persisted, false otherwise
- */
- auto getPersisted(const std::string& intf,
- const std::string& prop);
-
- /**
- * @brief Get a property value from the zone object or the bus when
- * the property requested is not on the zone object
- *
- * @param[in] path - Path of object
- * @param[in] intf - Object interface
- * @param[in] prop - Object property
- *
- * @return - Property's value
- */
- template <typename T>
- auto getPropertyByName(const std::string& path,
- const std::string& intf,
- const std::string& prop)
- {
- T value;
- auto pathIter = _objects.find(path);
- if (pathIter != _objects.end())
- {
- auto intfIter = pathIter->second.find(intf);
- if (intfIter != pathIter->second.end())
+ if (intf == "xyz.openbmc_project.Control.ThermalMode")
{
- if (intf == "xyz.openbmc_project.Control.ThermalMode")
- {
- auto var = ThermalMode::getPropertyByName(prop);
- // Use visitor to determine if requested property
- // type(T) is available on this interface and read it
- std::visit([&value](auto&& val)
- {
+ auto var = ThermalMode::getPropertyByName(prop);
+ // Use visitor to determine if requested property
+ // type(T) is available on this interface and read it
+ std::visit(
+ [&value](auto&& val) {
using V = std::decay_t<decltype(val)>;
- if constexpr(std::is_same_v<T, V>)
+ if constexpr (std::is_same_v<T, V>)
{
value = val;
}
- }, var);
+ },
+ var);
- return value;
- }
+ return value;
}
}
+ }
- // Retrieve the property's value applying any visitors necessary
- auto service = getService(path, intf);
- auto variant =
- util::SDBusPlus::getPropertyVariant<PropertyVariantType>(
- _bus, service, path, intf, prop);
- value = getPropertyValueVisitor<T>(
- intf.c_str(), prop.c_str(), variant);
+ // Retrieve the property's value applying any visitors necessary
+ auto service = getService(path, intf);
+ auto variant = util::SDBusPlus::getPropertyVariant<PropertyVariantType>(
+ _bus, service, path, intf, prop);
+ value = getPropertyValueVisitor<T>(intf.c_str(), prop.c_str(), variant);
- return value;
- };
+ return value;
+ };
- /**
- * @brief Overridden thermal object's set 'Current' property function
- *
- * @param[in] value - Value to set 'Current' to
- *
- * @return - The updated value of the 'Current' property
- */
- virtual std::string current(std::string value);
+ /**
+ * @brief Overridden thermal object's set 'Current' property function
+ *
+ * @param[in] value - Value to set 'Current' to
+ *
+ * @return - The updated value of the 'Current' property
+ */
+ virtual std::string current(std::string value);
- private:
+ private:
+ /**
+ * The dbus object
+ */
+ sdbusplus::bus::bus& _bus;
- /**
- * The dbus object
- */
- sdbusplus::bus::bus& _bus;
+ /**
+ * Zone object path
+ */
+ const std::string _path;
- /**
- * Zone object path
- */
- const std::string _path;
+ /**
+ * Zone supported interfaces
+ */
+ const std::vector<std::string> _ifaces;
- /**
- * Zone supported interfaces
- */
- const std::vector<std::string> _ifaces;
+ /**
+ * Full speed for the zone
+ */
+ const uint64_t _fullSpeed;
- /**
- * Full speed for the zone
- */
- const uint64_t _fullSpeed;
+ /**
+ * The zone number
+ */
+ const size_t _zoneNum;
- /**
- * The zone number
- */
- const size_t _zoneNum;
+ /**
+ * The default floor speed for the zone
+ */
+ uint64_t _defFloorSpeed;
- /**
- * The default floor speed for the zone
- */
- uint64_t _defFloorSpeed;
+ /**
+ * The default ceiling speed for the zone
+ */
+ const uint64_t _defCeilingSpeed;
- /**
- * The default ceiling speed for the zone
- */
- const uint64_t _defCeilingSpeed;
+ /**
+ * The floor speed to not go below
+ */
+ uint64_t _floorSpeed = _defFloorSpeed;
- /**
- * The floor speed to not go below
- */
- uint64_t _floorSpeed = _defFloorSpeed;
+ /**
+ * The ceiling speed to not go above
+ */
+ uint64_t _ceilingSpeed = _defCeilingSpeed;
- /**
- * The ceiling speed to not go above
- */
- uint64_t _ceilingSpeed = _defCeilingSpeed;
+ /**
+ * The previous sensor value for calculating the ceiling
+ */
+ int64_t _ceilingKeyValue = 0;
- /**
- * The previous sensor value for calculating the ceiling
- */
- int64_t _ceilingKeyValue = 0;
+ /**
+ * Automatic fan control active state
+ */
+ bool _isActive = true;
- /**
- * Automatic fan control active state
- */
- bool _isActive = true;
+ /**
+ * Target speed for this zone
+ */
+ uint64_t _targetSpeed = _fullSpeed;
- /**
- * Target speed for this zone
- */
- uint64_t _targetSpeed = _fullSpeed;
+ /**
+ * Speed increase delta
+ */
+ uint64_t _incSpeedDelta = 0;
- /**
- * Speed increase delta
- */
- uint64_t _incSpeedDelta = 0;
+ /**
+ * Speed decrease delta
+ */
+ uint64_t _decSpeedDelta = 0;
- /**
- * Speed decrease delta
- */
- uint64_t _decSpeedDelta = 0;
+ /**
+ * Requested speed base
+ */
+ uint64_t _requestSpeedBase = 0;
- /**
- * Requested speed base
- */
- uint64_t _requestSpeedBase = 0;
+ /**
+ * Speed increase delay in seconds
+ */
+ std::chrono::seconds _incDelay;
- /**
- * Speed increase delay in seconds
- */
- std::chrono::seconds _incDelay;
+ /**
+ * Speed decrease interval in seconds
+ */
+ std::chrono::seconds _decInterval;
- /**
- * Speed decrease interval in seconds
- */
- std::chrono::seconds _decInterval;
+ /**
+ * The increase timer object
+ */
+ Timer _incTimer;
- /**
- * The increase timer object
- */
- Timer _incTimer;
+ /**
+ * The decrease timer object
+ */
+ Timer _decTimer;
- /**
- * The decrease timer object
- */
- Timer _decTimer;
+ /**
+ * Event loop used on set speed event timers
+ */
+ sdeventplus::Event _eventLoop;
- /**
- * Event loop used on set speed event timers
- */
- sdeventplus::Event _eventLoop;
+ /**
+ * The vector of fans in this zone
+ */
+ std::vector<std::unique_ptr<Fan>> _fans;
- /**
- * The vector of fans in this zone
- */
- std::vector<std::unique_ptr<Fan>> _fans;
+ /**
+ * @brief Map of object property values
+ */
+ std::map<std::string,
+ std::map<std::string, std::map<std::string, PropertyVariantType>>>
+ _properties;
- /**
- * @brief Map of object property values
- */
- std::map<std::string,
- std::map<std::string,
- std::map<std::string,
- PropertyVariantType>>> _properties;
+ /**
+ * @brief Map of zone objects
+ */
+ std::map<std::string,
+ std::map<std::string, std::map<std::string, EventData*>>>
+ _objects;
- /**
- * @brief Map of zone objects
- */
- std::map<std::string,
- std::map<std::string,
- std::map<std::string,
- EventData*>>> _objects;
+ /**
+ * @brief Map of interfaces to persisted properties
+ */
+ std::map<std::string, std::vector<std::string>> _persisted;
- /**
- * @brief Map of interfaces to persisted properties
- */
- std::map<std::string, std::vector<std::string>> _persisted;
+ /**
+ * @brief Map of active fan control allowed by groups
+ */
+ std::map<const Group, bool> _active;
- /**
- * @brief Map of active fan control allowed by groups
- */
- std::map<const Group, bool> _active;
+ /**
+ * @brief Map of floor change allowed by groups
+ */
+ std::map<const Group, bool> _floorChange;
- /**
- * @brief Map of floor change allowed by groups
- */
- std::map<const Group, bool> _floorChange;
+ /**
+ * @brief Map of groups controlling decreases allowed
+ */
+ std::map<const Group, bool> _decAllowed;
- /**
- * @brief Map of groups controlling decreases allowed
- */
- std::map<const Group, bool> _decAllowed;
+ /**
+ * @brief Map of group service names
+ */
+ std::map<const Group, std::vector<Service>> _services;
- /**
- * @brief Map of group service names
- */
- std::map<const Group, std::vector<Service>> _services;
+ /**
+ * @brief Map tree of paths to services of interfaces
+ */
+ std::map<std::string, std::map<std::string, std::vector<std::string>>>
+ _servTree;
- /**
- * @brief Map tree of paths to services of interfaces
- */
- std::map<std::string,
- std::map<std::string,
- std::vector<std::string>>> _servTree;
+ /**
+ * @brief List of signal event arguments and Dbus matches
+ * for callbacks per event name
+ */
+ std::map<std::string, std::vector<SignalEvent>> _signalEvents;
- /**
- * @brief List of signal event arguments and Dbus matches
- * for callbacks per event name
- */
- std::map<std::string, std::vector<SignalEvent>> _signalEvents;
+ /**
+ * @brief List of timers per event name
+ */
+ std::map<std::string, std::vector<TimerEvent>> _timerEvents;
- /**
- * @brief List of timers per event name
- */
- std::map<std::string, std::vector<TimerEvent>> _timerEvents;
+ /**
+ * @brief Save the thermal control current mode property
+ * to persisted storage
+ */
+ void saveCurrentMode();
- /**
- * @brief Save the thermal control current mode property
- * to persisted storage
- */
- void saveCurrentMode();
+ /**
+ * @brief Restore persisted thermal control current mode property
+ * value, setting the mode to "Default" otherwise
+ */
+ void restoreCurrentMode();
- /**
- * @brief Restore persisted thermal control current mode property
- * value, setting the mode to "Default" otherwise
- */
- void restoreCurrentMode();
-
- /**
- * @brief Get the request speed base if defined, otherwise the
- * the current target speed is returned
- *
- * @return - The request speed base or current target speed
- */
- inline auto getRequestSpeedBase() const
- {
- return (_requestSpeedBase != 0) ? _requestSpeedBase : _targetSpeed;
- };
+ /**
+ * @brief Get the request speed base if defined, otherwise the
+ * the current target speed is returned
+ *
+ * @return - The request speed base or current target speed
+ */
+ inline auto getRequestSpeedBase() const
+ {
+ return (_requestSpeedBase != 0) ? _requestSpeedBase : _targetSpeed;
+ };
};
-}
-}
-}
+} // namespace control
+} // namespace fan
+} // namespace phosphor