presence: Clang format updates
Used `format-code.sh` build script to make changes to conform to clang
format.
Tested: Compiled
Change-Id: I2fc795938e85a752ee56b54212d389c2ff296828
Signed-off-by: Matthew Barth <msbarth@us.ibm.com>
diff --git a/presence/anyof.cpp b/presence/anyof.cpp
index 4dbf356..b77d6d7 100644
--- a/presence/anyof.cpp
+++ b/presence/anyof.cpp
@@ -13,25 +13,27 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-#include <algorithm>
-#include <phosphor-logging/log.hpp>
#include "anyof.hpp"
+
#include "fan.hpp"
#include "psensor.hpp"
+#include <phosphor-logging/log.hpp>
+
+#include <algorithm>
+
namespace phosphor
{
namespace fan
{
namespace presence
{
-AnyOf::AnyOf(
- const Fan& fan,
- const std::vector<std::reference_wrapper<PresenceSensor>>& s)
- : RedundancyPolicy(fan),
- state()
+AnyOf::AnyOf(const Fan& fan,
+ const std::vector<std::reference_wrapper<PresenceSensor>>& s) :
+ RedundancyPolicy(fan),
+ state()
{
- for (auto& sensor: s)
+ for (auto& sensor : s)
{
state.emplace_back(sensor, false);
}
@@ -40,18 +42,17 @@
void AnyOf::stateChanged(bool present, PresenceSensor& sensor)
{
// Find the sensor that changed state.
- auto sit = std::find_if(
- state.begin(),
- state.end(),
- [&sensor](const auto& s){ return std::get<0>(s).get() == sensor; });
+ auto sit =
+ std::find_if(state.begin(), state.end(), [&sensor](const auto& s) {
+ return std::get<0>(s).get() == sensor;
+ });
if (sit != state.end())
{
// Update our cache of the sensors state and re-evaluate.
std::get<bool>(*sit) = present;
- auto newState = std::any_of(
- state.begin(),
- state.end(),
- [](const auto& s){ return std::get<bool>(s); });
+ auto newState =
+ std::any_of(state.begin(), state.end(),
+ [](const auto& s) { return std::get<bool>(s); });
setPresence(fan, newState);
}
}
@@ -60,16 +61,14 @@
{
// Start all sensors in the anyof redundancy set.
- for (auto& s: state)
+ for (auto& s : state)
{
- auto &sensor = std::get<0>(s);
+ auto& sensor = std::get<0>(s);
std::get<bool>(s) = sensor.get().start();
}
- auto present = std::any_of(
- state.begin(),
- state.end(),
- [](const auto& s){ return std::get<bool>(s); });
+ auto present = std::any_of(state.begin(), state.end(),
+ [](const auto& s) { return std::get<bool>(s); });
setPresence(fan, present);
}
diff --git a/presence/anyof.hpp b/presence/anyof.hpp
index 70ddb43..efe3c79 100644
--- a/presence/anyof.hpp
+++ b/presence/anyof.hpp
@@ -1,10 +1,11 @@
#pragma once
-#include <functional>
-#include <vector>
#include "fan.hpp"
#include "rpolicy.hpp"
+#include <functional>
+#include <vector>
+
namespace phosphor
{
namespace fan
@@ -24,50 +25,45 @@
*/
class AnyOf : public RedundancyPolicy
{
- public:
- AnyOf() = delete;
- AnyOf(const AnyOf&) = default;
- AnyOf& operator=(const AnyOf&) = default;
- AnyOf(AnyOf&&) = default;
- AnyOf& operator=(AnyOf&&) = default;
- ~AnyOf() = default;
+ public:
+ AnyOf() = delete;
+ AnyOf(const AnyOf&) = default;
+ AnyOf& operator=(const AnyOf&) = default;
+ AnyOf(AnyOf&&) = default;
+ AnyOf& operator=(AnyOf&&) = default;
+ ~AnyOf() = default;
- /**
- * @brief Construct an any of bitwise policy.
- *
- * @param[in] fan - The fan associated with the policy.
- * @param[in] s - The set of sensors associated with the policy.
- */
- AnyOf(
- const Fan& fan,
- const std::vector<std::reference_wrapper<PresenceSensor>>& s);
+ /**
+ * @brief Construct an any of bitwise policy.
+ *
+ * @param[in] fan - The fan associated with the policy.
+ * @param[in] s - The set of sensors associated with the policy.
+ */
+ AnyOf(const Fan& fan,
+ const std::vector<std::reference_wrapper<PresenceSensor>>& s);
- /**
- * @brief stateChanged
- *
- * Update the inventory and execute the fallback
- * policy.
- *
- * @param[in] present - The new presence state according
- * to the specified sensor.
- * @param[in] sensor - The sensor reporting the new state.
- */
- void stateChanged(bool present, PresenceSensor& sensor) override;
+ /**
+ * @brief stateChanged
+ *
+ * Update the inventory and execute the fallback
+ * policy.
+ *
+ * @param[in] present - The new presence state according
+ * to the specified sensor.
+ * @param[in] sensor - The sensor reporting the new state.
+ */
+ void stateChanged(bool present, PresenceSensor& sensor) override;
- /**
- * @brief monitor
- *
- * Start monitoring the fan.
- */
- void monitor() override;
+ /**
+ * @brief monitor
+ *
+ * Start monitoring the fan.
+ */
+ void monitor() override;
- private:
-
- /** @brief All presence sensors in the redundancy set. */
- std::vector<
- std::tuple<
- std::reference_wrapper<PresenceSensor>,
- bool>> state;
+ private:
+ /** @brief All presence sensors in the redundancy set. */
+ std::vector<std::tuple<std::reference_wrapper<PresenceSensor>, bool>> state;
};
} // namespace presence
diff --git a/presence/fallback.cpp b/presence/fallback.cpp
index f6a0116..726c988 100644
--- a/presence/fallback.cpp
+++ b/presence/fallback.cpp
@@ -13,12 +13,15 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-#include <algorithm>
-#include <phosphor-logging/log.hpp>
-#include "fan.hpp"
#include "fallback.hpp"
+
+#include "fan.hpp"
#include "psensor.hpp"
+#include <phosphor-logging/log.hpp>
+
+#include <algorithm>
+
namespace phosphor
{
namespace fan
@@ -32,10 +35,8 @@
{
// Starting with the first backup, find the first
// sensor that reports the fan as present, if any.
- auto it = std::find_if(
- std::next(activeSensor),
- sensors.end(),
- [](auto& s){return s.get().present();});
+ auto it = std::find_if(std::next(activeSensor), sensors.end(),
+ [](auto& s) { return s.get().present(); });
if (it != sensors.end())
{
@@ -51,9 +52,8 @@
++activeSensor;
}
phosphor::logging::log<phosphor::logging::level::INFO>(
- "Using backup presence sensor.",
- phosphor::logging::entry(
- "FAN=%s", std::get<1>(fan).c_str()));
+ "Using backup presence sensor.",
+ phosphor::logging::entry("FAN=%s", std::get<1>(fan).c_str()));
activeSensor = it;
}
}
@@ -65,10 +65,8 @@
{
// Find the first sensor that says the fan is present
// and set it as the active sensor.
- activeSensor = std::find_if(
- sensors.begin(),
- sensors.end(),
- [](auto& s){return s.get().present();});
+ activeSensor = std::find_if(sensors.begin(), sensors.end(),
+ [](auto& s) { return s.get().present(); });
if (activeSensor == sensors.end())
{
// The first sensor is working or all sensors
@@ -79,9 +77,8 @@
if (activeSensor != sensors.begin())
{
phosphor::logging::log<phosphor::logging::level::INFO>(
- "Using backup presence sensor.",
- phosphor::logging::entry(
- "FAN=%s", std::get<1>(fan).c_str()));
+ "Using backup presence sensor.",
+ phosphor::logging::entry("FAN=%s", std::get<1>(fan).c_str()));
}
// Callout the broken sensors.
diff --git a/presence/fallback.hpp b/presence/fallback.hpp
index 280ef1c..bd9d1a5 100644
--- a/presence/fallback.hpp
+++ b/presence/fallback.hpp
@@ -1,10 +1,11 @@
#pragma once
-#include <functional>
-#include <vector>
#include "fan.hpp"
#include "rpolicy.hpp"
+#include <functional>
+#include <vector>
+
namespace phosphor
{
namespace fan
@@ -25,54 +26,53 @@
*/
class Fallback : public RedundancyPolicy
{
- public:
- Fallback() = delete;
- Fallback(const Fallback&) = default;
- Fallback& operator=(const Fallback&) = default;
- Fallback(Fallback&&) = default;
- Fallback& operator=(Fallback&&) = default;
- ~Fallback() = default;
+ public:
+ Fallback() = delete;
+ Fallback(const Fallback&) = default;
+ Fallback& operator=(const Fallback&) = default;
+ Fallback(Fallback&&) = default;
+ Fallback& operator=(Fallback&&) = default;
+ ~Fallback() = default;
- /**
- * @brief Construct a fallback policy.
- *
- * @param[in] fan - The fan associated with the policy.
- * @param[in] s - The set of sensors associated with the policy.
- */
- Fallback(
- const Fan& fan,
- const std::vector<std::reference_wrapper<PresenceSensor>>& s) :
- RedundancyPolicy(fan), sensors(s)
- {
- activeSensor = sensors.begin();
- }
+ /**
+ * @brief Construct a fallback policy.
+ *
+ * @param[in] fan - The fan associated with the policy.
+ * @param[in] s - The set of sensors associated with the policy.
+ */
+ Fallback(const Fan& fan,
+ const std::vector<std::reference_wrapper<PresenceSensor>>& s) :
+ RedundancyPolicy(fan),
+ sensors(s)
+ {
+ activeSensor = sensors.begin();
+ }
- /**
- * @brief stateChanged
- *
- * Update the inventory and execute the fallback
- * policy.
- *
- * @param[in] present - The new presence state according
- * to the active sensor.
- * @param[in] sensor - The sensor that changed state.
- */
- void stateChanged(bool present, PresenceSensor& sensor) override;
+ /**
+ * @brief stateChanged
+ *
+ * Update the inventory and execute the fallback
+ * policy.
+ *
+ * @param[in] present - The new presence state according
+ * to the active sensor.
+ * @param[in] sensor - The sensor that changed state.
+ */
+ void stateChanged(bool present, PresenceSensor& sensor) override;
- /**
- * @brief monitor
- *
- * Start monitoring the fan.
- */
- void monitor() override;
+ /**
+ * @brief monitor
+ *
+ * Start monitoring the fan.
+ */
+ void monitor() override;
- private:
+ private:
+ /** @brief All presence sensors in the redundancy set. */
+ std::vector<std::reference_wrapper<PresenceSensor>> sensors;
- /** @brief All presence sensors in the redundancy set. */
- std::vector<std::reference_wrapper<PresenceSensor>> sensors;
-
- /** @brief The active presence sensor. */
- decltype(sensors)::iterator activeSensor;
+ /** @brief The active presence sensor. */
+ decltype(sensors)::iterator activeSensor;
};
} // namespace presence
diff --git a/presence/fan.cpp b/presence/fan.cpp
index 823de29..9d300c3 100644
--- a/presence/fan.cpp
+++ b/presence/fan.cpp
@@ -13,12 +13,15 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-#include <map>
-#include <sdbusplus/message.hpp>
-#include <string>
#include "fan.hpp"
+
#include "sdbusplus.hpp"
+#include <sdbusplus/message.hpp>
+
+#include <map>
+#include <string>
+
namespace phosphor
{
namespace fan
@@ -40,34 +43,24 @@
using Properties = std::map<std::string, variant<std::string, bool>>;
using Interfaces = std::map<std::string, Properties>;
- std::map<object_path, Interfaces> obj =
- {{
+ std::map<object_path, Interfaces> obj = {{
std::get<1>(fan),
- {{
- itemIface,
- {
- {"Present"s, newState},
- {"PrettyName"s, std::get<0>(fan)},
- }
- },
- {
- fanIface, {}
- }},
+ {{itemIface,
+ {
+ {"Present"s, newState},
+ {"PrettyName"s, std::get<0>(fan)},
+ }},
+ {fanIface, {}}},
}};
- util::SDBusPlus::lookupAndCallMethod(
- invNamespace,
- invMgrIface,
- "Notify"s,
- obj);
+ util::SDBusPlus::lookupAndCallMethod(invNamespace, invMgrIface, "Notify"s,
+ obj);
}
bool getPresence(const Fan& fan)
{
- return util::SDBusPlus::getProperty<bool>(
- std::get<1>(fan),
- itemIface,
- "Present"s);
+ return util::SDBusPlus::getProperty<bool>(std::get<1>(fan), itemIface,
+ "Present"s);
}
} // namespace presence
diff --git a/presence/gpio.cpp b/presence/gpio.cpp
index 19593c2..1aa63a4 100644
--- a/presence/gpio.cpp
+++ b/presence/gpio.cpp
@@ -13,14 +13,17 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-#include <functional>
+#include "gpio.hpp"
+
+#include "rpolicy.hpp"
+
#include <phosphor-logging/elog-errors.hpp>
#include <phosphor-logging/elog.hpp>
#include <sdeventplus/event.hpp>
-#include <tuple>
#include <xyz/openbmc_project/Common/Callout/error.hpp>
-#include "gpio.hpp"
-#include "rpolicy.hpp"
+
+#include <functional>
+#include <tuple>
namespace phosphor
{
@@ -29,24 +32,17 @@
namespace presence
{
-Gpio::Gpio(
- const std::string& physDevice,
- const std::string& device,
- unsigned int physPin) :
+Gpio::Gpio(const std::string& physDevice, const std::string& device,
+ unsigned int physPin) :
currentState(false),
evdevfd(open(device.c_str(), O_RDONLY | O_NONBLOCK)),
- evdev(evdevpp::evdev::newFromFD(evdevfd())),
- phys(physDevice),
- pin(physPin)
-{
-
-}
+ evdev(evdevpp::evdev::newFromFD(evdevfd())), phys(physDevice), pin(physPin)
+{}
bool Gpio::start()
{
- source.emplace(sdeventplus::Event::get_default(),
- evdevfd(), EPOLLIN,
- std::bind(&Gpio::ioCallback, this));
+ source.emplace(sdeventplus::Event::get_default(), evdevfd(), EPOLLIN,
+ std::bind(&Gpio::ioCallback, this));
currentState = present();
return currentState;
}
@@ -68,9 +64,8 @@
using namespace xyz::openbmc_project::Common::Callout;
report<sdbusplus::xyz::openbmc_project::Common::Callout::Error::GPIO>(
- GPIO::CALLOUT_GPIO_NUM(pin),
- GPIO::CALLOUT_ERRNO(0),
- GPIO::CALLOUT_DEVICE_PATH(phys.c_str()));
+ GPIO::CALLOUT_GPIO_NUM(pin), GPIO::CALLOUT_ERRNO(0),
+ GPIO::CALLOUT_DEVICE_PATH(phys.c_str()));
}
void Gpio::ioCallback()
diff --git a/presence/gpio.hpp b/presence/gpio.hpp
index 2829bea..5f9e28b 100644
--- a/presence/gpio.hpp
+++ b/presence/gpio.hpp
@@ -1,11 +1,13 @@
#pragma once
-#include <sdeventplus/source/io.hpp>
-#include <optional>
#include "evdevpp/evdev.hpp"
#include "psensor.hpp"
#include "utility.hpp"
+#include <sdeventplus/source/io.hpp>
+
+#include <optional>
+
namespace phosphor
{
namespace fan
@@ -22,87 +24,85 @@
*/
class Gpio : public PresenceSensor
{
- public:
- /**
- * @brief
- *
- * Cannot move or copy due to this ptr as context
- * for sdevent callbacks.
- */
- Gpio() = delete;
- Gpio(const Gpio&) = delete;
- Gpio& operator=(const Gpio&) = delete;
- Gpio(Gpio&&) = delete;
- Gpio& operator=(Gpio&&) = delete;
- ~Gpio() = default;
+ public:
+ /**
+ * @brief
+ *
+ * Cannot move or copy due to this ptr as context
+ * for sdevent callbacks.
+ */
+ Gpio() = delete;
+ Gpio(const Gpio&) = delete;
+ Gpio& operator=(const Gpio&) = delete;
+ Gpio(Gpio&&) = delete;
+ Gpio& operator=(Gpio&&) = delete;
+ ~Gpio() = default;
- /**
- * @brief Construct a gpio sensor.
- *
- * @param[in] physDevice - The physical gpio device path.
- * @param[in] device - The gpio-keys input device.
- * @param[in] physPin - The physical gpio pin number.
- */
- Gpio(
- const std::string& physDevice,
- const std::string& device,
- unsigned int physPin);
+ /**
+ * @brief Construct a gpio sensor.
+ *
+ * @param[in] physDevice - The physical gpio device path.
+ * @param[in] device - The gpio-keys input device.
+ * @param[in] physPin - The physical gpio pin number.
+ */
+ Gpio(const std::string& physDevice, const std::string& device,
+ unsigned int physPin);
- /**
- * @brief start
- *
- * Register for an sdevent io callback on the gpio.
- * Query the initial state of the gpio.
- *
- * @return The current sensor state.
- */
- bool start() override;
+ /**
+ * @brief start
+ *
+ * Register for an sdevent io callback on the gpio.
+ * Query the initial state of the gpio.
+ *
+ * @return The current sensor state.
+ */
+ bool start() override;
- /**
- * @brief stop
- *
- * De-register sdevent io callback.
- */
- void stop() override;
+ /**
+ * @brief stop
+ *
+ * De-register sdevent io callback.
+ */
+ void stop() override;
- /**
- * @brief fail
- *
- * Call the gpio out.
- */
- void fail() override;
+ /**
+ * @brief fail
+ *
+ * Call the gpio out.
+ */
+ void fail() override;
- /**
- * @brief Check the sensor.
- *
- * Query the gpio.
- */
- bool present() override;
+ /**
+ * @brief Check the sensor.
+ *
+ * Query the gpio.
+ */
+ bool present() override;
- private :
- /** @brief Get the policy associated with this sensor. */
- virtual RedundancyPolicy& getPolicy() = 0;
+ private:
+ /** @brief Get the policy associated with this sensor. */
+ virtual RedundancyPolicy& getPolicy() = 0;
- /** @brief sdevent io callback. */
- void ioCallback();
+ /** @brief sdevent io callback. */
+ void ioCallback();
- /** The current state of the sensor. */
- bool currentState;
+ /** The current state of the sensor. */
+ bool currentState;
- /** Gpio event device file descriptor. */
- util::FileDescriptor evdevfd;
+ /** Gpio event device file descriptor. */
+ util::FileDescriptor evdevfd;
- /** Gpio event device. */
- evdevpp::evdev::EvDev evdev;
+ /** Gpio event device. */
+ evdevpp::evdev::EvDev evdev;
- /** Physical gpio device. */
- std::string phys;
+ /** Physical gpio device. */
+ std::string phys;
- /** Gpio pin number. */
- unsigned int pin;
+ /** Gpio pin number. */
+ unsigned int pin;
- /** sdevent io handle. */
- std::optional<sdeventplus::source::IO> source;
+ /** sdevent io handle. */
+ std::optional<sdeventplus::source::IO> source;
};
} // namespace presence
diff --git a/presence/json_config.cpp b/presence/json_config.cpp
index d09139c..1974c76 100644
--- a/presence/json_config.cpp
+++ b/presence/json_config.cpp
@@ -13,19 +13,21 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-#include <string>
-#include <filesystem>
-#include <fstream>
+#include "json_config.hpp"
+
+#include "anyof.hpp"
+#include "fallback.hpp"
+#include "gpio.hpp"
+#include "sdbusplus.hpp"
+#include "tach.hpp"
+
#include <nlohmann/json.hpp>
#include <phosphor-logging/log.hpp>
#include <sdbusplus/bus.hpp>
-#include "json_config.hpp"
-#include "tach.hpp"
-#include "gpio.hpp"
-#include "anyof.hpp"
-#include "fallback.hpp"
-#include "sdbusplus.hpp"
+#include <filesystem>
+#include <fstream>
+#include <string>
namespace phosphor
{
@@ -39,19 +41,12 @@
using namespace phosphor::logging;
policies JsonConfig::_policies;
-const std::map<std::string, methodHandler> JsonConfig::_methods =
-{
- {"tach", method::getTach},
- {"gpio", method::getGpio}
-};
-const std::map<std::string, rpolicyHandler> JsonConfig::_rpolicies =
-{
- {"anyof", rpolicy::getAnyof},
- {"fallback", rpolicy::getFallback}
-};
+const std::map<std::string, methodHandler> JsonConfig::_methods = {
+ {"tach", method::getTach}, {"gpio", method::getGpio}};
+const std::map<std::string, rpolicyHandler> JsonConfig::_rpolicies = {
+ {"anyof", rpolicy::getAnyof}, {"fallback", rpolicy::getFallback}};
-JsonConfig::JsonConfig(sdbusplus::bus::bus& bus) :
- _bus(bus)
+JsonConfig::JsonConfig(sdbusplus::bus::bus& bus) : _bus(bus)
{
// Determine the configuration file to use
_confFile = getConfFile();
@@ -75,7 +70,7 @@
entry("JSON_FILE=%s", _confFile.c_str()));
// Load and process the json configuration
load();
- for (auto& p: _policies)
+ for (auto& p : _policies)
{
p->monitor();
}
@@ -116,8 +111,7 @@
{
// Retrieve json config relative path location from dbus
auto relPathLoc = util::SDBusPlus::getProperty<std::string>(
- _bus, itServ->first, itObj->first,
- confDbusIntf, confDbusProp);
+ _bus, itServ->first, itObj->first, confDbusIntf, confDbusProp);
confFile = fs::path{confBasePath} / relPathLoc / confFileName;
if (!fs::exists(confFile))
{
@@ -186,10 +180,9 @@
if (!member.contains("name") || !member.contains("path") ||
!member.contains("methods") || !member.contains("rpolicy"))
{
- log<level::ERR>(
- "Missing required fan presence properties",
- entry("REQUIRED_PROPERTIES=%s",
- "{name, path, methods, rpolicy}"));
+ log<level::ERR>("Missing required fan presence properties",
+ entry("REQUIRED_PROPERTIES=%s",
+ "{name, path, methods, rpolicy}"));
throw std::runtime_error(
"Missing required fan presence properties");
}
@@ -203,7 +196,7 @@
log<level::ERR>(
"Missing required fan presence method type",
entry("FAN_NAME=%s",
- member["name"].get<std::string>().c_str()));
+ member["name"].get<std::string>().c_str()));
throw std::runtime_error(
"Missing required fan presence method type");
}
@@ -223,10 +216,11 @@
}
else
{
- log<level::ERR>("Invalid fan presence method type",
- entry("FAN_NAME=%s",
- member["name"].get<std::string>().c_str()),
- entry("METHOD_TYPE=%s", type.c_str()));
+ log<level::ERR>(
+ "Invalid fan presence method type",
+ entry("FAN_NAME=%s",
+ member["name"].get<std::string>().c_str()),
+ entry("METHOD_TYPE=%s", type.c_str()));
throw std::runtime_error("Invalid fan presence method type");
}
}
@@ -250,17 +244,16 @@
_policies.swap(policies);
}
-std::unique_ptr<RedundancyPolicy> JsonConfig::getPolicy(
- const json& rpolicy,
- const fanPolicy& fpolicy)
+std::unique_ptr<RedundancyPolicy>
+ JsonConfig::getPolicy(const json& rpolicy, const fanPolicy& fpolicy)
{
if (!rpolicy.contains("type"))
{
- log<level::ERR>("Missing required fan presence policy type",
- entry("FAN_NAME=%s",
- std::get<fanPolicyFanPos>(
- std::get<Fan>(fpolicy)).c_str()),
- entry("REQUIRED_PROPERTIES=%s", "{type}"));
+ log<level::ERR>(
+ "Missing required fan presence policy type",
+ entry("FAN_NAME=%s",
+ std::get<fanPolicyFanPos>(std::get<Fan>(fpolicy)).c_str()),
+ entry("REQUIRED_PROPERTIES=%s", "{type}"));
throw std::runtime_error("Missing required fan presence policy type");
}
@@ -276,9 +269,10 @@
}
else
{
- log<level::ERR>("Invalid fan presence policy type",
+ log<level::ERR>(
+ "Invalid fan presence policy type",
entry("FAN_NAME=%s",
- std::get<fanPolicyFanPos>(std::get<Fan>(fpolicy)).c_str()),
+ std::get<fanPolicyFanPos>(std::get<Fan>(fpolicy)).c_str()),
entry("RPOLICY_TYPE=%s", type.c_str()));
throw std::runtime_error("Invalid fan presence methods policy type");
}
@@ -289,51 +283,48 @@
*/
namespace method
{
- // Get a constructed presence sensor for fan presence detection by tach
- std::unique_ptr<PresenceSensor> getTach(size_t fanIndex, const json& method)
+// Get a constructed presence sensor for fan presence detection by tach
+std::unique_ptr<PresenceSensor> getTach(size_t fanIndex, const json& method)
+{
+ if (!method.contains("sensors") || method["sensors"].size() == 0)
{
- if (!method.contains("sensors") ||
- method["sensors"].size() == 0)
- {
- log<level::ERR>(
- "Missing required tach method properties",
- entry("FAN_ENTRY=%d", fanIndex),
- entry("REQUIRED_PROPERTIES=%s", "{sensors}"));
- throw std::runtime_error("Missing required tach method properties");
- }
-
- std::vector<std::string> sensors;
- for (auto& sensor : method["sensors"])
- {
- sensors.emplace_back(sensor.get<std::string>());
- }
-
- return std::make_unique<PolicyAccess<Tach, JsonConfig>>(
- fanIndex, std::move(sensors));
+ log<level::ERR>("Missing required tach method properties",
+ entry("FAN_ENTRY=%d", fanIndex),
+ entry("REQUIRED_PROPERTIES=%s", "{sensors}"));
+ throw std::runtime_error("Missing required tach method properties");
}
- // Get a constructed presence sensor for fan presence detection by gpio
- std::unique_ptr<PresenceSensor> getGpio(size_t fanIndex, const json& method)
+ std::vector<std::string> sensors;
+ for (auto& sensor : method["sensors"])
{
- if (!method.contains("physpath") ||
- !method.contains("devpath") ||
- !method.contains("key"))
- {
- log<level::ERR>(
- "Missing required gpio method properties",
- entry("FAN_ENTRY=%d", fanIndex),
- entry("REQUIRED_PROPERTIES=%s", "{physpath, devpath, key}"));
- throw std::runtime_error("Missing required gpio method properties");
- }
-
- auto physpath = method["physpath"].get<std::string>();
- auto devpath = method["devpath"].get<std::string>();
- auto key = method["key"].get<unsigned int>();
-
- return std::make_unique<PolicyAccess<Gpio, JsonConfig>>(
- fanIndex, physpath, devpath, key);
+ sensors.emplace_back(sensor.get<std::string>());
}
+ return std::make_unique<PolicyAccess<Tach, JsonConfig>>(fanIndex,
+ std::move(sensors));
+}
+
+// Get a constructed presence sensor for fan presence detection by gpio
+std::unique_ptr<PresenceSensor> getGpio(size_t fanIndex, const json& method)
+{
+ if (!method.contains("physpath") || !method.contains("devpath") ||
+ !method.contains("key"))
+ {
+ log<level::ERR>(
+ "Missing required gpio method properties",
+ entry("FAN_ENTRY=%d", fanIndex),
+ entry("REQUIRED_PROPERTIES=%s", "{physpath, devpath, key}"));
+ throw std::runtime_error("Missing required gpio method properties");
+ }
+
+ auto physpath = method["physpath"].get<std::string>();
+ auto devpath = method["devpath"].get<std::string>();
+ auto key = method["key"].get<unsigned int>();
+
+ return std::make_unique<PolicyAccess<Gpio, JsonConfig>>(fanIndex, physpath,
+ devpath, key);
+}
+
} // namespace method
/**
@@ -341,34 +332,32 @@
*/
namespace rpolicy
{
- // Get an `Anyof` redundancy policy for the fan
- std::unique_ptr<RedundancyPolicy> getAnyof(const fanPolicy& fan)
+// Get an `Anyof` redundancy policy for the fan
+std::unique_ptr<RedundancyPolicy> getAnyof(const fanPolicy& fan)
+{
+ std::vector<std::reference_wrapper<PresenceSensor>> pSensors;
+ for (auto& fanSensor : std::get<fanPolicySensorListPos>(fan))
{
- std::vector<std::reference_wrapper<PresenceSensor>> pSensors;
- for (auto& fanSensor : std::get<fanPolicySensorListPos>(fan))
- {
- pSensors.emplace_back(*fanSensor);
- }
-
- return std::make_unique<AnyOf>(
- std::get<fanPolicyFanPos>(fan), pSensors);
+ pSensors.emplace_back(*fanSensor);
}
- // Get a `Fallback` redundancy policy for the fan
- std::unique_ptr<RedundancyPolicy> getFallback(const fanPolicy& fan)
- {
- std::vector<std::reference_wrapper<PresenceSensor>> pSensors;
- for (auto& fanSensor : std::get<fanPolicySensorListPos>(fan))
- {
- // Place in the order given to fallback correctly
- pSensors.emplace_back(*fanSensor);
- }
+ return std::make_unique<AnyOf>(std::get<fanPolicyFanPos>(fan), pSensors);
+}
- return std::make_unique<Fallback>(
- std::get<fanPolicyFanPos>(fan), pSensors);
+// Get a `Fallback` redundancy policy for the fan
+std::unique_ptr<RedundancyPolicy> getFallback(const fanPolicy& fan)
+{
+ std::vector<std::reference_wrapper<PresenceSensor>> pSensors;
+ for (auto& fanSensor : std::get<fanPolicySensorListPos>(fan))
+ {
+ // Place in the order given to fallback correctly
+ pSensors.emplace_back(*fanSensor);
}
-} // namespace policy
+ return std::make_unique<Fallback>(std::get<fanPolicyFanPos>(fan), pSensors);
+}
+
+} // namespace rpolicy
} // namespace presence
} // namespace fan
diff --git a/presence/json_config.hpp b/presence/json_config.hpp
index 7a3f7b8..6045e90 100644
--- a/presence/json_config.hpp
+++ b/presence/json_config.hpp
@@ -1,16 +1,17 @@
#pragma once
-#include <string>
-#include <vector>
-#include <memory>
-#include <nlohmann/json.hpp>
-#include <filesystem>
-#include <sdeventplus/source/signal.hpp>
-#include <sdbusplus/bus.hpp>
-
-#include "rpolicy.hpp"
#include "fan.hpp"
#include "psensor.hpp"
+#include "rpolicy.hpp"
+
+#include <nlohmann/json.hpp>
+#include <sdbusplus/bus.hpp>
+#include <sdeventplus/source/signal.hpp>
+
+#include <filesystem>
+#include <memory>
+#include <string>
+#include <vector>
namespace phosphor
{
@@ -35,105 +36,103 @@
using fanPolicy = std::tuple<Fan, std::vector<std::unique_ptr<PresenceSensor>>>;
// Presence method handler function
-using methodHandler = std::function<
- std::unique_ptr<PresenceSensor>(size_t, const json&)>;
+using methodHandler =
+ std::function<std::unique_ptr<PresenceSensor>(size_t, const json&)>;
// Presence redundancy policy handler function
-using rpolicyHandler = std::function<
- std::unique_ptr<RedundancyPolicy>(const fanPolicy&)>;
+using rpolicyHandler =
+ std::function<std::unique_ptr<RedundancyPolicy>(const fanPolicy&)>;
class JsonConfig
{
- public:
+ public:
+ JsonConfig() = delete;
+ JsonConfig(const JsonConfig&) = delete;
+ JsonConfig(JsonConfig&&) = delete;
+ JsonConfig& operator=(const JsonConfig&) = delete;
+ JsonConfig& operator=(JsonConfig&&) = delete;
+ ~JsonConfig() = default;
- JsonConfig() = delete;
- JsonConfig(const JsonConfig&) = delete;
- JsonConfig(JsonConfig&&) = delete;
- JsonConfig& operator=(const JsonConfig&) = delete;
- JsonConfig& operator=(JsonConfig&&) = delete;
- ~JsonConfig() = default;
+ /**
+ * Constructor
+ * Parses and populates the fan presence policies from a json file
+ *
+ * @param[in] bus - sdbusplus bus object
+ */
+ explicit JsonConfig(sdbusplus::bus::bus& bus);
- /**
- * Constructor
- * Parses and populates the fan presence policies from a json file
- *
- * @param[in] bus - sdbusplus bus object
- */
- explicit JsonConfig(sdbusplus::bus::bus& bus);
+ /**
+ * @brief Get the json config based fan presence policies
+ *
+ * @return - The fan presence policies
+ */
+ static const policies& get();
- /**
- * @brief Get the json config based fan presence policies
- *
- * @return - The fan presence policies
- */
- static const policies& get();
+ /**
+ * @brief Callback function to handle receiving a HUP signal to
+ * reload the json configuration.
+ *
+ * @param[in] sigSrc - sd_event_source signal wrapper
+ * @param[in] sigInfo - signal info on signal fd
+ */
+ void sighupHandler(sdeventplus::source::Signal& sigSrc,
+ const struct signalfd_siginfo* sigInfo);
- /**
- * @brief Callback function to handle receiving a HUP signal to
- * reload the json configuration.
- *
- * @param[in] sigSrc - sd_event_source signal wrapper
- * @param[in] sigInfo - signal info on signal fd
- */
- void sighupHandler(sdeventplus::source::Signal& sigSrc,
- const struct signalfd_siginfo* sigInfo);
+ private:
+ /* Fan presence policies */
+ static policies _policies;
- private:
+ /* The sdbusplus bus object */
+ sdbusplus::bus::bus& _bus;
- /* Fan presence policies */
- static policies _policies;
+ /* Config file to be used */
+ fs::path _confFile;
- /* The sdbusplus bus object */
- sdbusplus::bus::bus& _bus;
+ /* List of Fan objects to have presence policies */
+ std::vector<fanPolicy> _fans;
- /* Config file to be used */
- fs::path _confFile;
+ /* Presence methods mapping to their associated handler function */
+ static const std::map<std::string, methodHandler> _methods;
- /* List of Fan objects to have presence policies */
- std::vector<fanPolicy> _fans;
+ /**
+ * Presence redundancy policy mapping to their associated handler
+ * function
+ */
+ static const std::map<std::string, rpolicyHandler> _rpolicies;
- /* Presence methods mapping to their associated handler function */
- static const std::map<std::string, methodHandler> _methods;
+ /**
+ * Get the json configuration file. The first location found to contain
+ * the json config file is used from the following locations in order.
+ * 1.) confOverridePath ("/etc/phosphor-fan-presence/presence")
+ * 2.) confBasePath ("/usr/share/phosphor-fan-presence/presence")
+ * 3.) From first dbus object found hosting
+ * interface = Interface set in confDbusIntf
+ * property = Property set in confDbusProp
+ */
+ const fs::path getConfFile();
- /**
- * Presence redundancy policy mapping to their associated handler
- * function
- */
- static const std::map<std::string, rpolicyHandler> _rpolicies;
+ /**
+ * @brief Load the json config file
+ */
+ void load();
- /**
- * Get the json configuration file. The first location found to contain
- * the json config file is used from the following locations in order.
- * 1.) confOverridePath ("/etc/phosphor-fan-presence/presence")
- * 2.) confBasePath ("/usr/share/phosphor-fan-presence/presence")
- * 3.) From first dbus object found hosting
- * interface = Interface set in confDbusIntf
- * property = Property set in confDbusProp
- */
- const fs::path getConfFile();
+ /**
+ * @brief Process the json config to extract the defined fan presence
+ * policies.
+ *
+ * @param[in] jsonConf - parsed json configuration data
+ */
+ void process(const json& jsonConf);
- /**
- * @brief Load the json config file
- */
- void load();
-
- /**
- * @brief Process the json config to extract the defined fan presence
- * policies.
- *
- * @param[in] jsonConf - parsed json configuration data
- */
- void process(const json& jsonConf);
-
- /**
- * @brief Get the redundancy policy of presence detection for a fan
- *
- * @param[in] rpolicy - policy type to construct
- * @param[in] fpolicy - fan policy object
- *
- * @return - The constructed redundancy policy type for the fan
- */
- std::unique_ptr<RedundancyPolicy> getPolicy(const json& rpolicy,
- const fanPolicy& fpolicy);
+ /**
+ * @brief Get the redundancy policy of presence detection for a fan
+ *
+ * @param[in] rpolicy - policy type to construct
+ * @param[in] fpolicy - fan policy object
+ *
+ * @return - The constructed redundancy policy type for the fan
+ */
+ std::unique_ptr<RedundancyPolicy> getPolicy(const json& rpolicy,
+ const fanPolicy& fpolicy);
};
/**
@@ -141,27 +140,25 @@
*/
namespace method
{
- /**
- * @brief Fan presence detection method by tach feedback
- *
- * @param[in] fanIndex - fan object index to add tach method
- * @param[in] method - json properties for a tach method
- *
- * @return - A presence sensor to detect fan presence by tach feedback
- */
- std::unique_ptr<PresenceSensor> getTach(size_t fanIndex,
- const json& method);
+/**
+ * @brief Fan presence detection method by tach feedback
+ *
+ * @param[in] fanIndex - fan object index to add tach method
+ * @param[in] method - json properties for a tach method
+ *
+ * @return - A presence sensor to detect fan presence by tach feedback
+ */
+std::unique_ptr<PresenceSensor> getTach(size_t fanIndex, const json& method);
- /**
- * @brief Fan presence detection method by gpio
- *
- * @param[in] fanIndex - fan object index to add gpio method
- * @param[in] method - json properties for a gpio method
- *
- * @return - A presence sensor to detect fan presence by gpio
- */
- std::unique_ptr<PresenceSensor> getGpio(size_t fanIndex,
- const json& method);
+/**
+ * @brief Fan presence detection method by gpio
+ *
+ * @param[in] fanIndex - fan object index to add gpio method
+ * @param[in] method - json properties for a gpio method
+ *
+ * @return - A presence sensor to detect fan presence by gpio
+ */
+std::unique_ptr<PresenceSensor> getGpio(size_t fanIndex, const json& method);
} // namespace method
@@ -170,27 +167,27 @@
*/
namespace rpolicy
{
- /**
- * @brief Create an `Anyof` redundancy policy on the created presence
- * sensors for a fan
- *
- * @param[in] fan - fan policy object with the presence sensors for the fan
- *
- * @return - An `Anyof` redundancy policy
- */
- std::unique_ptr<RedundancyPolicy> getAnyof(const fanPolicy& fan);
+/**
+ * @brief Create an `Anyof` redundancy policy on the created presence
+ * sensors for a fan
+ *
+ * @param[in] fan - fan policy object with the presence sensors for the fan
+ *
+ * @return - An `Anyof` redundancy policy
+ */
+std::unique_ptr<RedundancyPolicy> getAnyof(const fanPolicy& fan);
- /**
- * @brief Create a `Fallback` redundancy policy on the created presence
- * sensors for a fan
- *
- * @param[in] fan - fan policy object with the presence sensors for the fan
- *
- * @return - A `Fallback` redundancy policy
- */
- std::unique_ptr<RedundancyPolicy> getFallback(const fanPolicy& fan);
+/**
+ * @brief Create a `Fallback` redundancy policy on the created presence
+ * sensors for a fan
+ *
+ * @param[in] fan - fan policy object with the presence sensors for the fan
+ *
+ * @return - A `Fallback` redundancy policy
+ */
+std::unique_ptr<RedundancyPolicy> getFallback(const fanPolicy& fan);
-} // namespace policy
+} // namespace rpolicy
} // namespace presence
} // namespace fan
diff --git a/presence/psensor.hpp b/presence/psensor.hpp
index 7afbd75..8ce2d7e 100644
--- a/presence/psensor.hpp
+++ b/presence/psensor.hpp
@@ -21,71 +21,72 @@
*/
class PresenceSensor
{
- public:
- PresenceSensor(const PresenceSensor&) = default;
- PresenceSensor& operator=(const PresenceSensor&) = default;
- PresenceSensor(PresenceSensor&&) = default;
- PresenceSensor& operator=(PresenceSensor&&) = default;
- virtual ~PresenceSensor() = default;
- PresenceSensor() : id(nextId)
- {
- nextId++;
- }
+ public:
+ PresenceSensor(const PresenceSensor&) = default;
+ PresenceSensor& operator=(const PresenceSensor&) = default;
+ PresenceSensor(PresenceSensor&&) = default;
+ PresenceSensor& operator=(PresenceSensor&&) = default;
+ virtual ~PresenceSensor() = default;
+ PresenceSensor() : id(nextId)
+ {
+ nextId++;
+ }
- /**
- * @brief start
- *
- * Implementations should peform any preparation
- * for detecting presence. Typical implementations
- * might register signal callbacks or start
- * a polling loop.
- *
- * @return The state of the sensor.
- */
- virtual bool start() = 0;
+ /**
+ * @brief start
+ *
+ * Implementations should peform any preparation
+ * for detecting presence. Typical implementations
+ * might register signal callbacks or start
+ * a polling loop.
+ *
+ * @return The state of the sensor.
+ */
+ virtual bool start() = 0;
- /**
- * @brief stop
- *
- * Implementations should stop issuing presence
- * state change notifications. Typical implementations
- * might de-register signal callbacks or terminate
- * polling loops.
- */
- virtual void stop() = 0;
+ /**
+ * @brief stop
+ *
+ * Implementations should stop issuing presence
+ * state change notifications. Typical implementations
+ * might de-register signal callbacks or terminate
+ * polling loops.
+ */
+ virtual void stop() = 0;
- /**
- * @brief Check the sensor.
- *
- * Implementations should perform an offline (the start
- * method has not been invoked) query of the presence
- * state.
- *
- * @return The state of the sensor.
- */
- virtual bool present() = 0;
+ /**
+ * @brief Check the sensor.
+ *
+ * Implementations should perform an offline (the start
+ * method has not been invoked) query of the presence
+ * state.
+ *
+ * @return The state of the sensor.
+ */
+ virtual bool present() = 0;
- /**
- * @brief Mark the sensor as failed.
- *
- * Implementations should log an an event if the
- * system policy requires it.
- *
- * Provide a default noop implementation.
- */
- virtual void fail() {}
+ /**
+ * @brief Mark the sensor as failed.
+ *
+ * Implementations should log an an event if the
+ * system policy requires it.
+ *
+ * Provide a default noop implementation.
+ */
+ virtual void fail()
+ {}
- friend bool operator==(const PresenceSensor& l, const PresenceSensor& r);
+ friend bool operator==(const PresenceSensor& l, const PresenceSensor& r);
- private:
- /** @brief Unique sensor ID. */
- std::size_t id;
+ private:
+ /** @brief Unique sensor ID. */
+ std::size_t id;
- /** @brief The next unique sensor ID. */
- static std::size_t nextId;
+ /** @brief The next unique sensor ID. */
+ static std::size_t nextId;
};
-inline bool operator==(const PresenceSensor& l, const PresenceSensor &r)
+inline bool operator==(const PresenceSensor& l, const PresenceSensor& r)
{
return l.id == r.id;
}
diff --git a/presence/rpolicy.hpp b/presence/rpolicy.hpp
index 8f7db3e..d596dfa 100644
--- a/presence/rpolicy.hpp
+++ b/presence/rpolicy.hpp
@@ -24,43 +24,44 @@
*/
class RedundancyPolicy
{
- public:
- RedundancyPolicy(const RedundancyPolicy&) = default;
- RedundancyPolicy& operator=(const RedundancyPolicy&) = default;
- RedundancyPolicy(RedundancyPolicy&&) = default;
- RedundancyPolicy& operator=(RedundancyPolicy&&) = default;
- virtual ~RedundancyPolicy() = default;
+ public:
+ RedundancyPolicy(const RedundancyPolicy&) = default;
+ RedundancyPolicy& operator=(const RedundancyPolicy&) = default;
+ RedundancyPolicy(RedundancyPolicy&&) = default;
+ RedundancyPolicy& operator=(RedundancyPolicy&&) = default;
+ virtual ~RedundancyPolicy() = default;
- /**
- * @brief Construct a new Redundancy Policy.
- *
- * @param[in] fan - The fan associated with this policy.
- */
- explicit RedundancyPolicy(const Fan& f) : fan(f) {}
+ /**
+ * @brief Construct a new Redundancy Policy.
+ *
+ * @param[in] fan - The fan associated with this policy.
+ */
+ explicit RedundancyPolicy(const Fan& f) : fan(f)
+ {}
- /**
- * @brief stateChanged
- *
- * Typically invoked by presence sensors to signify
- * a change of presence. Implementations should update
- * the inventory and execute their policy logic.
- *
- * @param[in] present - The new state of the sensor.
- * @param[in] sensor - The sensor that changed state.
- */
- virtual void stateChanged(bool present, PresenceSensor& sensor) = 0;
+ /**
+ * @brief stateChanged
+ *
+ * Typically invoked by presence sensors to signify
+ * a change of presence. Implementations should update
+ * the inventory and execute their policy logic.
+ *
+ * @param[in] present - The new state of the sensor.
+ * @param[in] sensor - The sensor that changed state.
+ */
+ virtual void stateChanged(bool present, PresenceSensor& sensor) = 0;
- /**
- * @brief monitor
- *
- * Implementations should start monitoring the sensors
- * associated with the fan.
- */
- virtual void monitor() = 0;
+ /**
+ * @brief monitor
+ *
+ * Implementations should start monitoring the sensors
+ * associated with the fan.
+ */
+ virtual void monitor() = 0;
- protected:
- /** @brief Fan name and inventory path. */
- const Fan& fan;
+ protected:
+ /** @brief Fan name and inventory path. */
+ const Fan& fan;
};
/**
@@ -78,35 +79,36 @@
template <typename T, typename Policy>
class PolicyAccess : public T
{
- public:
- PolicyAccess() = default;
- PolicyAccess(const PolicyAccess&) = default;
- PolicyAccess& operator=(const PolicyAccess&) = default;
- PolicyAccess(PolicyAccess&&) = default;
- PolicyAccess& operator=(PolicyAccess&&) = default;
- ~PolicyAccess() = default;
+ public:
+ PolicyAccess() = default;
+ PolicyAccess(const PolicyAccess&) = default;
+ PolicyAccess& operator=(const PolicyAccess&) = default;
+ PolicyAccess(PolicyAccess&&) = default;
+ PolicyAccess& operator=(PolicyAccess&&) = default;
+ ~PolicyAccess() = default;
- /**
- * @brief Construct a new PolicyAccess wrapped object.
- *
- * @param[in] index - The array index in Policy.
- * @tparam Args - Forwarded to wrapped type constructor.
- */
- template <typename...Args>
- PolicyAccess(size_t index, Args&&...args) :
- T(std::forward<Args>(args)...), policy(index) {}
+ /**
+ * @brief Construct a new PolicyAccess wrapped object.
+ *
+ * @param[in] index - The array index in Policy.
+ * @tparam Args - Forwarded to wrapped type constructor.
+ */
+ template <typename... Args>
+ PolicyAccess(size_t index, Args&&... args) :
+ T(std::forward<Args>(args)...), policy(index)
+ {}
- private:
- /**
- * @brief Get the associated policy.
- */
- RedundancyPolicy& getPolicy() override
- {
- return *Policy::get()[policy];
- }
+ private:
+ /**
+ * @brief Get the associated policy.
+ */
+ RedundancyPolicy& getPolicy() override
+ {
+ return *Policy::get()[policy];
+ }
- /** The associated policy index. */
- size_t policy;
+ /** The associated policy index. */
+ size_t policy;
};
} // namespace presence
} // namespace fan
diff --git a/presence/tach.cpp b/presence/tach.cpp
index d8b6395..ee35878 100644
--- a/presence/tach.cpp
+++ b/presence/tach.cpp
@@ -13,12 +13,15 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+#include "tach.hpp"
+
+#include "rpolicy.hpp"
+
#include <phosphor-logging/log.hpp>
+
#include <string>
#include <tuple>
#include <vector>
-#include "tach.hpp"
-#include "rpolicy.hpp"
namespace phosphor
{
@@ -34,8 +37,7 @@
static const auto tachIface = "xyz.openbmc_project.Sensor.Value"s;
static const auto tachProperty = "Value"s;
-Tach::Tach(
- const std::vector<std::string>& sensors) : currentState(false)
+Tach::Tach(const std::vector<std::string>& sensors) : currentState(false)
{
// Initialize state.
for (const auto& s : sensors)
@@ -53,39 +55,31 @@
// Register for signal callbacks.
std::get<1>(s) = std::make_unique<sdbusplus::bus::match::match>(
- util::SDBusPlus::getBus(),
- sdbusplus::bus::match::rules::propertiesChanged(
- tachPath, tachIface),
- [this, i](auto& msg){ this->propertiesChanged(i, msg);});
+ util::SDBusPlus::getBus(),
+ sdbusplus::bus::match::rules::propertiesChanged(tachPath,
+ tachIface),
+ [this, i](auto& msg) { this->propertiesChanged(i, msg); });
// Get an initial tach speed.
try
{
std::get<int64_t>(s) = util::SDBusPlus::getProperty<int64_t>(
- tachPath,
- tachIface,
- tachProperty);
+ tachPath, tachIface, tachProperty);
}
catch (std::exception&)
{
// Assume not spinning.
std::get<int64_t>(s) = 0;
- log<level::INFO>(
- "Unable to read fan tach sensor.",
- entry("SENSOR=%s", tachPath.c_str()));
-
+ log<level::INFO>("Unable to read fan tach sensor.",
+ entry("SENSOR=%s", tachPath.c_str()));
}
}
// Set the initial state of the sensor.
- currentState = std::any_of(
- state.begin(),
- state.end(),
- [](const auto & s)
- {
- return std::get<int64_t>(s) != 0;
- });
+ currentState = std::any_of(state.begin(), state.end(), [](const auto& s) {
+ return std::get<int64_t>(s) != 0;
+ });
return currentState;
}
@@ -105,22 +99,15 @@
std::vector<int64_t> values;
for (const auto& s : state)
{
- values.push_back(
- util::SDBusPlus::getProperty<int64_t>(
- tachNamespace + std::get<std::string>(s),
- tachIface,
- tachProperty));
+ values.push_back(util::SDBusPlus::getProperty<int64_t>(
+ tachNamespace + std::get<std::string>(s), tachIface, tachProperty));
}
- return std::any_of(
- values.begin(),
- values.end(),
- [](const auto & v) {return v != 0;});
+ return std::any_of(values.begin(), values.end(),
+ [](const auto& v) { return v != 0; });
}
-void Tach::propertiesChanged(
- size_t sensor,
- sdbusplus::message::message& msg)
+void Tach::propertiesChanged(size_t sensor, sdbusplus::message::message& msg)
{
std::string iface;
util::Properties<int64_t> properties;
@@ -129,9 +116,8 @@
propertiesChanged(sensor, properties);
}
-void Tach::propertiesChanged(
- size_t sensor,
- const util::Properties<int64_t>& props)
+void Tach::propertiesChanged(size_t sensor,
+ const util::Properties<int64_t>& props)
{
auto& s = state[sensor];
@@ -141,13 +127,10 @@
{
std::get<int64_t>(s) = std::get<int64_t>(it->second);
- auto newState = std::any_of(
- state.begin(),
- state.end(),
- [](const auto & s)
- {
- return std::get<int64_t>(s) != 0;
- });
+ auto newState =
+ std::any_of(state.begin(), state.end(), [](const auto& s) {
+ return std::get<int64_t>(s) != 0;
+ });
if (currentState != newState)
{
diff --git a/presence/tach.hpp b/presence/tach.hpp
index 4f02521..9f2654d 100644
--- a/presence/tach.hpp
+++ b/presence/tach.hpp
@@ -1,12 +1,14 @@
#pragma once
-#include <sdbusplus/message.hpp>
-#include <sdbusplus/bus/match.hpp>
-#include <string>
-#include <vector>
#include "psensor.hpp"
#include "sdbusplus.hpp"
+#include <sdbusplus/bus/match.hpp>
+#include <sdbusplus/message.hpp>
+
+#include <string>
+#include <vector>
+
namespace phosphor
{
namespace fan
@@ -24,85 +26,81 @@
*/
class Tach : public PresenceSensor
{
- public:
- /**
- * @brief
- *
- * Cannot move or copy due to this ptr as context
- * for sdbus callbacks.
- */
- Tach() = delete;
- Tach(const Tach&) = delete;
- Tach& operator=(const Tach&) = delete;
- Tach(Tach&&) = delete;
- Tach& operator=(Tach&&) = delete;
- ~Tach() = default;
+ public:
+ /**
+ * @brief
+ *
+ * Cannot move or copy due to this ptr as context
+ * for sdbus callbacks.
+ */
+ Tach() = delete;
+ Tach(const Tach&) = delete;
+ Tach& operator=(const Tach&) = delete;
+ Tach(Tach&&) = delete;
+ Tach& operator=(Tach&&) = delete;
+ ~Tach() = default;
- /**
- * @brief ctor
- *
- * @param[in] sensors - Fan tach sensors for this psensor.
- */
- Tach(const std::vector<std::string>& sensors);
+ /**
+ * @brief ctor
+ *
+ * @param[in] sensors - Fan tach sensors for this psensor.
+ */
+ Tach(const std::vector<std::string>& sensors);
- /**
- * @brief start
- *
- * Register for dbus signal callbacks on fan
- * tach sensor change. Query initial tach speeds.
- *
- * @return The current sensor state.
- */
- bool start() override;
+ /**
+ * @brief start
+ *
+ * Register for dbus signal callbacks on fan
+ * tach sensor change. Query initial tach speeds.
+ *
+ * @return The current sensor state.
+ */
+ bool start() override;
- /**
- * @brief stop
- *
- * De-register dbus signal callbacks.
- */
- void stop() override;
+ /**
+ * @brief stop
+ *
+ * De-register dbus signal callbacks.
+ */
+ void stop() override;
- /**
- * @brief Check the sensor.
- *
- * Query the tach speeds.
- */
- bool present() override;
+ /**
+ * @brief Check the sensor.
+ *
+ * Query the tach speeds.
+ */
+ bool present() override;
- private :
- /**
- * @brief Get the policy associated with this sensor.
- */
- virtual RedundancyPolicy& getPolicy() = 0;
+ private:
+ /**
+ * @brief Get the policy associated with this sensor.
+ */
+ virtual RedundancyPolicy& getPolicy() = 0;
- /**
- * @brief Properties changed handler for tach sensor updates.
- *
- * @param[in] sensor - The sensor that changed.
- * @param[in] props - The properties that changed.
- */
- void propertiesChanged(
- size_t sensor,
- const phosphor::fan::util::Properties<int64_t>& props);
+ /**
+ * @brief Properties changed handler for tach sensor updates.
+ *
+ * @param[in] sensor - The sensor that changed.
+ * @param[in] props - The properties that changed.
+ */
+ void propertiesChanged(
+ size_t sensor, const phosphor::fan::util::Properties<int64_t>& props);
- /**
- * @brief Properties changed handler for tach sensor updates.
- *
- * @param[in] sensor - The sensor that changed.
- * @param[in] msg - The sdbusplus signal message.
- */
- void propertiesChanged(
- size_t sensor,
- sdbusplus::message::message& msg);
+ /**
+ * @brief Properties changed handler for tach sensor updates.
+ *
+ * @param[in] sensor - The sensor that changed.
+ * @param[in] msg - The sdbusplus signal message.
+ */
+ void propertiesChanged(size_t sensor, sdbusplus::message::message& msg);
- /** @brief array of tach sensors dbus matches, and tach values. */
- std::vector<std::tuple<
- std::string,
- std::unique_ptr<sdbusplus::bus::match::match>,
- int64_t>> state;
+ /** @brief array of tach sensors dbus matches, and tach values. */
+ std::vector<std::tuple<
+ std::string, std::unique_ptr<sdbusplus::bus::match::match>, int64_t>>
+ state;
- /** The current state of the sensor. */
- bool currentState;
+ /** The current state of the sensor. */
+ bool currentState;
};
} // namespace presence
diff --git a/presence/tach_detect.cpp b/presence/tach_detect.cpp
index e374c12..1c1dcf9 100644
--- a/presence/tach_detect.cpp
+++ b/presence/tach_detect.cpp
@@ -20,9 +20,10 @@
#include "generated.hpp"
#endif
#include <sdeventplus/event.hpp>
-#include <functional>
-#include <stdplus/signal.hpp>
#include <sdeventplus/source/signal.hpp>
+#include <stdplus/signal.hpp>
+
+#include <functional>
int main(void)
{
@@ -35,17 +36,18 @@
#ifdef PRESENCE_USE_JSON
// Use json file for presence config
presence::JsonConfig config(bus);
- for (auto& p: presence::JsonConfig::get())
+ for (auto& p : presence::JsonConfig::get())
{
p->monitor();
}
stdplus::signal::block(SIGHUP);
- sdeventplus::source::Signal signal(event, SIGHUP,
- std::bind(&presence::JsonConfig::sighupHandler,
- &config, std::placeholders::_1, std::placeholders::_2));
+ sdeventplus::source::Signal signal(
+ event, SIGHUP,
+ std::bind(&presence::JsonConfig::sighupHandler, &config,
+ std::placeholders::_1, std::placeholders::_2));
#else
- for (auto& p: presence::ConfigPolicy::get())
+ for (auto& p : presence::ConfigPolicy::get())
{
p->monitor();
}
diff --git a/presence/test/fallbacktest.cpp b/presence/test/fallbacktest.cpp
index a9f989c..daa0b50 100644
--- a/presence/test/fallbacktest.cpp
+++ b/presence/test/fallbacktest.cpp
@@ -1,8 +1,11 @@
+#include "../fallback.hpp"
+
+#include "../psensor.hpp"
+
#include <iostream>
#include <string>
+
#include <gtest/gtest.h>
-#include "../fallback.hpp"
-#include "../psensor.hpp"
int pstate = -1;
@@ -26,32 +29,32 @@
class TestSensor : public PresenceSensor
{
- public:
- bool start() override
- {
- ++started;
- return _present;
- }
+ public:
+ bool start() override
+ {
+ ++started;
+ return _present;
+ }
- void stop() override
- {
- ++stopped;
- }
+ void stop() override
+ {
+ ++stopped;
+ }
- bool present() override
- {
- return _present;
- }
+ bool present() override
+ {
+ return _present;
+ }
- void fail() override
- {
- ++failed;
- }
+ void fail() override
+ {
+ ++failed;
+ }
- bool _present = false;
- size_t started = 0;
- size_t stopped = 0;
- size_t failed = 0;
+ bool _present = false;
+ size_t started = 0;
+ size_t stopped = 0;
+ size_t failed = 0;
};
} // namespace presence
@@ -136,7 +139,6 @@
ASSERT_EQ(ts2.started, 0);
}
-
TEST(FallbackTest, TestTwoB)
{
// Validate two sensors.