diff options
author | Patrick Venture <venture@google.com> | 2018-08-31 10:10:53 -0700 |
---|---|---|
committer | Patrick Venture <venture@google.com> | 2018-08-31 12:42:31 -0700 |
commit | 043d32306e00484afc446a44789b61869ea14f84 (patch) | |
tree | 786a28de89a2a916ba5c2e4b73411516a10dc8af | |
parent | 901f117733c828aa7519610eb23ce112b9d068a8 (diff) | |
download | phosphor-hwmon-043d32306e00484afc446a44789b61869ea14f84.tar.gz phosphor-hwmon-043d32306e00484afc446a44789b61869ea14f84.zip |
add .clang-format
Change-Id: I94ce26d595367e08d6fb3734535bcd855f1b1473
Signed-off-by: Patrick Venture <venture@google.com>
-rw-r--r-- | .clang-format | 99 | ||||
-rw-r--r-- | argument.cpp | 20 | ||||
-rw-r--r-- | argument.hpp | 25 | ||||
-rw-r--r-- | env.cpp | 34 | ||||
-rw-r--r-- | env.hpp | 24 | ||||
-rw-r--r-- | fan_pwm.cpp | 37 | ||||
-rw-r--r-- | fan_pwm.hpp | 82 | ||||
-rw-r--r-- | fan_speed.cpp | 78 | ||||
-rw-r--r-- | fan_speed.hpp | 92 | ||||
-rw-r--r-- | hwmon.cpp | 15 | ||||
-rw-r--r-- | hwmon.hpp | 60 | ||||
-rw-r--r-- | hwmonio.cpp | 82 | ||||
-rw-r--r-- | hwmonio.hpp | 157 | ||||
-rw-r--r-- | interface.hpp | 16 | ||||
-rw-r--r-- | mainloop.cpp | 213 | ||||
-rw-r--r-- | mainloop.hpp | 240 | ||||
-rw-r--r-- | readd.cpp | 17 | ||||
-rw-r--r-- | sensor.cpp | 94 | ||||
-rw-r--r-- | sensor.hpp | 187 | ||||
-rw-r--r-- | sensorset.cpp | 13 | ||||
-rw-r--r-- | sensorset.hpp | 94 | ||||
-rw-r--r-- | sysfs.cpp | 39 | ||||
-rw-r--r-- | sysfs.hpp | 11 | ||||
-rw-r--r-- | targets.hpp | 64 | ||||
-rw-r--r-- | test/fanpwm_unittest.cpp | 134 | ||||
-rw-r--r-- | test/hwmon_unittest.cpp | 9 | ||||
-rw-r--r-- | test/hwmonio_mock.hpp | 36 | ||||
-rw-r--r-- | thresholds.hpp | 9 | ||||
-rw-r--r-- | timer.cpp | 30 | ||||
-rw-r--r-- | timer.hpp | 138 | ||||
-rw-r--r-- | tools/find_callout_path.cpp | 6 | ||||
-rw-r--r-- | tools/find_hwmon.cpp | 6 | ||||
-rw-r--r-- | types.hpp | 3 |
33 files changed, 1023 insertions, 1141 deletions
diff --git a/.clang-format b/.clang-format new file mode 100644 index 0000000..42a2307 --- /dev/null +++ b/.clang-format @@ -0,0 +1,99 @@ +--- +Language: Cpp +# BasedOnStyle: LLVM +AccessModifierOffset: -2 +AlignAfterOpenBracket: Align +AlignConsecutiveAssignments: false +AlignConsecutiveDeclarations: false +AlignEscapedNewlinesLeft: false +AlignOperands: true +AlignTrailingComments: true +AllowAllParametersOfDeclarationOnNextLine: true +AllowShortBlocksOnASingleLine: false +AllowShortCaseLabelsOnASingleLine: false +AllowShortFunctionsOnASingleLine: None +AllowShortIfStatementsOnASingleLine: false +AllowShortLoopsOnASingleLine: false +AlwaysBreakAfterDefinitionReturnType: None +AlwaysBreakAfterReturnType: None +AlwaysBreakBeforeMultilineStrings: false +AlwaysBreakTemplateDeclarations: true +BinPackArguments: true +BinPackParameters: true +BraceWrapping: + AfterClass: true + AfterControlStatement: true + AfterEnum: true + AfterFunction: true + AfterNamespace: true + AfterObjCDeclaration: true + AfterStruct: true + AfterUnion: true + BeforeCatch: true + BeforeElse: true + IndentBraces: false +BreakBeforeBinaryOperators: None +BreakBeforeBraces: Custom +BreakBeforeTernaryOperators: true +BreakConstructorInitializers: AfterColon +ColumnLimit: 80 +CommentPragmas: '^ IWYU pragma:' +ConstructorInitializerAllOnOneLineOrOnePerLine: false +ConstructorInitializerIndentWidth: 4 +ContinuationIndentWidth: 4 +Cpp11BracedListStyle: true +DerivePointerAlignment: true +PointerAlignment: Left +DisableFormat: false +ExperimentalAutoDetectBinPacking: false +FixNamespaceComments: true +ForEachMacros: [ foreach, Q_FOREACH, BOOST_FOREACH ] +IncludeBlocks: Regroup +IncludeCategories: + - Regex: '^[<"](gtest|gmock)' + Priority: 5 + - Regex: '^"config.h"' + Priority: -1 + - Regex: '^".*\.hpp"' + Priority: 1 + - Regex: '^<.*\.h>' + Priority: 2 + - Regex: '^<.*' + Priority: 3 + - Regex: '.*' + Priority: 4 +IndentCaseLabels: true +IndentWidth: 4 +IndentWrappedFunctionNames: true +KeepEmptyLinesAtTheStartOfBlocks: true +MacroBlockBegin: '' +MacroBlockEnd: '' +MaxEmptyLinesToKeep: 1 +NamespaceIndentation: None +ObjCBlockIndentWidth: 2 +ObjCSpaceAfterProperty: false +ObjCSpaceBeforeProtocolList: true +PenaltyBreakBeforeFirstCallParameter: 19 +PenaltyBreakComment: 300 +PenaltyBreakFirstLessLess: 120 +PenaltyBreakString: 1000 +PenaltyExcessCharacter: 1000000 +PenaltyReturnTypeOnItsOwnLine: 60 +PointerAlignment: Right +ReflowComments: true +SortIncludes: true +SpaceAfterCStyleCast: false +SpaceBeforeAssignmentOperators: true +SpaceBeforeParens: ControlStatements +SpaceInEmptyParentheses: false +SpacesBeforeTrailingComments: 1 +SpacesInAngles: false +SpacesInContainerLiterals: true +SpacesInCStyleCastParentheses: false +SpacesInParentheses: false +SpacesInSquareBrackets: false +Standard: Cpp11 +TabWidth: 4 +UseTab: Never +... + diff --git a/argument.cpp b/argument.cpp index 3849cae..99ee710 100644 --- a/argument.cpp +++ b/argument.cpp @@ -13,11 +13,12 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -#include <iostream> -#include <iterator> +#include "argument.hpp" + #include <algorithm> #include <cassert> -#include "argument.hpp" +#include <iostream> +#include <iterator> ArgumentParser::ArgumentParser(int argc, char** argv) { @@ -66,13 +67,14 @@ void ArgumentParser::usage(char** argv) std::cerr << std::flush; } -const option ArgumentParser::options[] = -{ - { "path", required_argument, NULL, 'p' }, - { "dev-path", required_argument, NULL, 'o' }, - { "help", no_argument, NULL, 'h' }, - { 0, 0, 0, 0}, +// clang-format off +const option ArgumentParser::options[] = { + {"path", required_argument, NULL, 'p'}, + {"dev-path", required_argument, NULL, 'o'}, + {"help", no_argument, NULL, 'h'}, + {0, 0, 0, 0}, }; +// clang-format on const char* ArgumentParser::optionstr = "o:p:?h"; diff --git a/argument.hpp b/argument.hpp index ed2399a..e6acaf3 100644 --- a/argument.hpp +++ b/argument.hpp @@ -1,28 +1,29 @@ #pragma once #include <getopt.h> + #include <map> #include <string> class ArgumentParser { - public: - ArgumentParser(int argc, char** argv); - const std::string& operator[](const std::string& opt); + public: + ArgumentParser(int argc, char** argv); + const std::string& operator[](const std::string& opt); - static void usage(char** argv); + static void usage(char** argv); - static const std::string true_string; - static const std::string empty_string; + static const std::string true_string; + static const std::string empty_string; - private: - std::map<const std::string, std::string> arguments; + private: + std::map<const std::string, std::string> arguments; - static const option options[]; - static const char* optionstr; + static const option options[]; + static const char* optionstr; - private: - ArgumentParser() {}; + private: + ArgumentParser(){}; }; // vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4 @@ -14,13 +14,15 @@ * limitations under the License. */ -#include <cstdlib> -#include <fstream> - #include "env.hpp" + #include "hwmon.hpp" -namespace env { +#include <cstdlib> +#include <fstream> + +namespace env +{ std::string getEnv(const char* key) { @@ -28,8 +30,7 @@ std::string getEnv(const char* key) return (value) ? std::string(value) : std::string(); } -std::string getEnv( - const char* prefix, const SensorSet::key_type& sensor) +std::string getEnv(const char* prefix, const SensorSet::key_type& sensor) { std::string key; @@ -41,19 +42,15 @@ std::string getEnv( return getEnv(key.c_str()); } -std::string getEnv( - const char* prefix, - const std::string& type, - const std::string& id) +std::string getEnv(const char* prefix, const std::string& type, + const std::string& id) { SensorSet::key_type sensor{type, id}; return getEnv(prefix, sensor); } -std::string getIndirectID( - std::string path, - const std::string& fileSuffix, - const SensorSet::key_type& sensor) +std::string getIndirectID(std::string path, const std::string& fileSuffix, + const SensorSet::key_type& sensor) { std::string content; @@ -65,13 +62,12 @@ std::string getIndirectID( std::ifstream handle(path.c_str()); if (!handle.fail()) { - content.assign( - (std::istreambuf_iterator<char>(handle)), - (std::istreambuf_iterator<char>())); + content.assign((std::istreambuf_iterator<char>(handle)), + (std::istreambuf_iterator<char>())); if (!content.empty()) { - //remove the newline + // remove the newline content.pop_back(); } } @@ -79,6 +75,6 @@ std::string getIndirectID( return content; } -} // namespace env +} // namespace env // vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4 @@ -1,10 +1,11 @@ #pragma once -#include <string> - #include "sensorset.hpp" -namespace env { +#include <string> + +namespace env +{ /** @brief Reads an environment variable * @@ -25,8 +26,7 @@ std::string getEnv(const char* key); * * @return string - the env var value */ -std::string getEnv( - const char* prefix, const SensorSet::key_type& sensor); +std::string getEnv(const char* prefix, const SensorSet::key_type& sensor); /** @brief Reads an environment variable, and takes type and id separately * @@ -36,10 +36,8 @@ std::string getEnv( * * @return string - the env var value */ -std::string getEnv( - const char* prefix, - const std::string& type, - const std::string& id); +std::string getEnv(const char* prefix, const std::string& type, + const std::string& id); /** @brief Gets the ID for the sensor with a level of indirection * @@ -50,9 +48,7 @@ std::string getEnv( * @param[in] fileSuffix - The file suffix * @param[in] sensor - Sensor details */ -std::string getIndirectID( - std::string path, - const std::string& fileSuffix, - const SensorSet::key_type& sensor); +std::string getIndirectID(std::string path, const std::string& fileSuffix, + const SensorSet::key_type& sensor); -} // namespace env +} // namespace env diff --git a/fan_pwm.cpp b/fan_pwm.cpp index 1808f5d..f814c0a 100644 --- a/fan_pwm.cpp +++ b/fan_pwm.cpp @@ -1,15 +1,15 @@ -#include "env.hpp" #include "fan_pwm.hpp" + +#include "env.hpp" #include "hwmon.hpp" #include "hwmonio.hpp" #include "sensorset.hpp" #include "sysfs.hpp" -#include <phosphor-logging/elog-errors.hpp> -#include <xyz/openbmc_project/Control/Device/error.hpp> - #include <experimental/filesystem> +#include <phosphor-logging/elog-errors.hpp> #include <string> +#include <xyz/openbmc_project/Control/Device/error.hpp> using namespace phosphor::logging; @@ -21,32 +21,22 @@ uint64_t FanPwm::target(uint64_t value) using namespace std::literals; std::string empty; - //Write target out to sysfs + // Write target out to sysfs try { - ioAccess->write( - value, - type, - id, - empty, - hwmonio::retries, - hwmonio::delay); + ioAccess->write(value, type, id, empty, hwmonio::retries, + hwmonio::delay); } catch (const std::system_error& e) { - using namespace sdbusplus::xyz::openbmc_project::Control:: - Device::Error; + using namespace sdbusplus::xyz::openbmc_project::Control::Device::Error; report<WriteFailure>( - xyz::openbmc_project::Control::Device:: - WriteFailure::CALLOUT_ERRNO(e.code().value()), - xyz::openbmc_project::Control::Device:: - WriteFailure::CALLOUT_DEVICE_PATH(devPath.c_str())); + xyz::openbmc_project::Control::Device::WriteFailure::CALLOUT_ERRNO( + e.code().value()), + xyz::openbmc_project::Control::Device::WriteFailure:: + CALLOUT_DEVICE_PATH(devPath.c_str())); - auto file = sysfs::make_sysfs_path( - ioAccess->path(), - type, - id, - empty); + auto file = sysfs::make_sysfs_path(ioAccess->path(), type, id, empty); log<level::INFO>("Logging failing sysfs file", phosphor::logging::entry("FILE=%s", file.c_str())); @@ -58,4 +48,3 @@ uint64_t FanPwm::target(uint64_t value) } } // namespace hwmon - diff --git a/fan_pwm.hpp b/fan_pwm.hpp index 61c0bf6..e80dde0 100644 --- a/fan_pwm.hpp +++ b/fan_pwm.hpp @@ -1,11 +1,11 @@ #pragma once -#include <memory> - #include "hwmonio.hpp" #include "interface.hpp" #include "sysfs.hpp" +#include <memory> + namespace hwmon { @@ -17,49 +17,43 @@ namespace hwmon */ class FanPwm : public FanPwmObject { - public: - - /** - * @brief Constructs FanPwm Object - * - * @param[in] io - HwmonIO - * @param[in] devPath - The /sys/devices sysfs path - * @param[in] id - The hwmon id - * @param[in] bus - Dbus bus object - * @param[in] objPath - Dbus object path - * @param[in] defer - Dbus object registration defer - */ + public: + /** + * @brief Constructs FanPwm Object + * + * @param[in] io - HwmonIO + * @param[in] devPath - The /sys/devices sysfs path + * @param[in] id - The hwmon id + * @param[in] bus - Dbus bus object + * @param[in] objPath - Dbus object path + * @param[in] defer - Dbus object registration defer + */ FanPwm(std::unique_ptr<hwmonio::HwmonIOInterface> io, - const std::string& devPath, - const std::string& id, - sdbusplus::bus::bus& bus, - const char* objPath, - bool defer, - uint64_t target) : FanPwmObject(bus, objPath, defer), - id(id), - ioAccess(std::move(io)), - devPath(devPath) - { - FanPwmObject::target(target); - } - - /** - * @brief Set the value of target - * - * @return Value of target - */ - uint64_t target(uint64_t value) override; - - private: - /** @brief hwmon type */ - static constexpr auto type = "pwm"; - /** @brief hwmon id */ - std::string id; - /** @brief Hwmon sysfs access. */ - std::unique_ptr<hwmonio::HwmonIOInterface> ioAccess; - /** @brief Physical device path. */ - std::string devPath; + const std::string& devPath, const std::string& id, + sdbusplus::bus::bus& bus, const char* objPath, bool defer, + uint64_t target) : + FanPwmObject(bus, objPath, defer), + id(id), ioAccess(std::move(io)), devPath(devPath) + { + FanPwmObject::target(target); + } + + /** + * @brief Set the value of target + * + * @return Value of target + */ + uint64_t target(uint64_t value) override; + + private: + /** @brief hwmon type */ + static constexpr auto type = "pwm"; + /** @brief hwmon id */ + std::string id; + /** @brief Hwmon sysfs access. */ + std::unique_ptr<hwmonio::HwmonIOInterface> ioAccess; + /** @brief Physical device path. */ + std::string devPath; }; } // namespace hwmon - diff --git a/fan_speed.cpp b/fan_speed.cpp index 9e297bc..db683a2 100644 --- a/fan_speed.cpp +++ b/fan_speed.cpp @@ -1,12 +1,14 @@ -#include <phosphor-logging/elog-errors.hpp> -#include <xyz/openbmc_project/Control/Device/error.hpp> -#include "sensorset.hpp" -#include "env.hpp" #include "fan_speed.hpp" + +#include "env.hpp" #include "hwmon.hpp" #include "hwmonio.hpp" +#include "sensorset.hpp" #include "sysfs.hpp" +#include <phosphor-logging/elog-errors.hpp> +#include <xyz/openbmc_project/Control/Device/error.hpp> + using namespace phosphor::logging; namespace hwmon @@ -18,36 +20,27 @@ uint64_t FanSpeed::target(uint64_t value) if (curValue != value) { - //Write target out to sysfs + // Write target out to sysfs try { - ioAccess->write( - value, - type, - id, - entry::target, - hwmonio::retries, - hwmonio::delay); - + ioAccess->write(value, type, id, entry::target, hwmonio::retries, + hwmonio::delay); } catch (const std::system_error& e) { - using namespace sdbusplus::xyz::openbmc_project::Control:: - Device::Error; + using namespace sdbusplus::xyz::openbmc_project::Control::Device:: + Error; report<WriteFailure>( - xyz::openbmc_project::Control::Device:: - WriteFailure::CALLOUT_ERRNO(e.code().value()), - xyz::openbmc_project::Control::Device:: - WriteFailure::CALLOUT_DEVICE_PATH(devPath.c_str())); + xyz::openbmc_project::Control::Device::WriteFailure:: + CALLOUT_ERRNO(e.code().value()), + xyz::openbmc_project::Control::Device::WriteFailure:: + CALLOUT_DEVICE_PATH(devPath.c_str())); - auto file = sysfs::make_sysfs_path( - ioAccess->path(), - type, - id, - entry::target); + auto file = sysfs::make_sysfs_path(ioAccess->path(), type, id, + entry::target); log<level::INFO>("Logging failing sysfs file", - phosphor::logging::entry("FILE=%s", file.c_str())); + phosphor::logging::entry("FILE=%s", file.c_str())); exit(EXIT_FAILURE); } @@ -56,7 +49,6 @@ uint64_t FanSpeed::target(uint64_t value) return FanSpeedObject::target(value); } - void FanSpeed::enable() { auto enable = env::getEnv("ENABLE", type, id); @@ -66,37 +58,29 @@ void FanSpeed::enable() try { - ioAccess->write( - val, - type::pwm, - id, - entry::enable, - hwmonio::retries, - hwmonio::delay); + ioAccess->write(val, type::pwm, id, entry::enable, hwmonio::retries, + hwmonio::delay); } catch (const std::system_error& e) { - using namespace sdbusplus::xyz::openbmc_project::Control:: - Device::Error; + using namespace sdbusplus::xyz::openbmc_project::Control::Device:: + Error; phosphor::logging::report<WriteFailure>( - xyz::openbmc_project::Control::Device:: - WriteFailure::CALLOUT_ERRNO(e.code().value()), - xyz::openbmc_project::Control::Device:: - WriteFailure::CALLOUT_DEVICE_PATH(devPath.c_str())); + xyz::openbmc_project::Control::Device::WriteFailure:: + CALLOUT_ERRNO(e.code().value()), + xyz::openbmc_project::Control::Device::WriteFailure:: + CALLOUT_DEVICE_PATH(devPath.c_str())); - auto fullPath = sysfs::make_sysfs_path( - ioAccess->path(), - type::pwm, - id, - entry::enable); + auto fullPath = sysfs::make_sysfs_path(ioAccess->path(), type::pwm, + id, entry::enable); - log<level::INFO>("Logging failing sysfs file", - phosphor::logging::entry("FILE=%s", fullPath.c_str())); + log<level::INFO>( + "Logging failing sysfs file", + phosphor::logging::entry("FILE=%s", fullPath.c_str())); exit(EXIT_FAILURE); } } } - } // namespace hwmon diff --git a/fan_speed.hpp b/fan_speed.hpp index 9b4ad63..96d408e 100644 --- a/fan_speed.hpp +++ b/fan_speed.hpp @@ -1,11 +1,11 @@ #pragma once -#include <memory> - #include "hwmonio.hpp" #include "interface.hpp" #include "sysfs.hpp" +#include <memory> + namespace hwmon { @@ -17,56 +17,50 @@ namespace hwmon */ class FanSpeed : public FanSpeedObject { - public: - - /** - * @brief Constructs FanSpeed Object - * - * @param[in] io - HwmonIO(instance path) (ex /sys/class/hwmon/hwmon1) - * @param[in] devPath - The /sys/devices sysfs path - * @param[in] id - The hwmon id - * @param[in] bus - Dbus bus object - * @param[in] objPath - Dbus object path - * @param[in] defer - Dbus object registration defer - * @param[in] target - initial target speed value - */ - FanSpeed(std::unique_ptr<hwmonio::HwmonIOInterface> io, - const std::string& devPath, - const std::string& id, - sdbusplus::bus::bus& bus, - const char* objPath, - bool defer, - uint64_t target) : FanSpeedObject(bus, objPath, defer), - id(id), - ioAccess(std::move(io)), - devPath(devPath) - { - FanSpeedObject::target(target); - } - - /** - * @brief Set the value of target - * - * @return Value of target - */ - uint64_t target(uint64_t value) override; + public: + /** + * @brief Constructs FanSpeed Object + * + * @param[in] io - HwmonIO(instance path) (ex /sys/class/hwmon/hwmon1) + * @param[in] devPath - The /sys/devices sysfs path + * @param[in] id - The hwmon id + * @param[in] bus - Dbus bus object + * @param[in] objPath - Dbus object path + * @param[in] defer - Dbus object registration defer + * @param[in] target - initial target speed value + */ + FanSpeed(std::unique_ptr<hwmonio::HwmonIOInterface> io, + const std::string& devPath, const std::string& id, + sdbusplus::bus::bus& bus, const char* objPath, bool defer, + uint64_t target) : + FanSpeedObject(bus, objPath, defer), + id(id), ioAccess(std::move(io)), devPath(devPath) + { + FanSpeedObject::target(target); + } - /** - * @brief Writes the pwm_enable sysfs entry if the - * env var with the value to write is present - */ - void enable(); + /** + * @brief Set the value of target + * + * @return Value of target + */ + uint64_t target(uint64_t value) override; - private: - /** @brief hwmon type */ - static constexpr auto type = "fan"; - /** @brief hwmon id */ - std::string id; - /** @brief Hwmon sysfs access. */ - std::unique_ptr<hwmonio::HwmonIOInterface> ioAccess; - /** @brief Physical device path. */ - std::string devPath; + /** + * @brief Writes the pwm_enable sysfs entry if the + * env var with the value to write is present + */ + void enable(); + private: + /** @brief hwmon type */ + static constexpr auto type = "fan"; + /** @brief hwmon id */ + std::string id; + /** @brief Hwmon sysfs access. */ + std::unique_ptr<hwmonio::HwmonIOInterface> ioAccess; + /** @brief Physical device path. */ + std::string devPath; }; } // namespace hwmon @@ -1,17 +1,14 @@ #include "hwmon.hpp" -namespace hwmon { +namespace hwmon +{ bool getAttributes(const std::string& type, Attributes& attributes) { // *INDENT-OFF* - auto a = std::find_if( - typeAttrMap.begin(), - typeAttrMap.end(), - [&](const auto & e) - { - return type == getHwmonType(e); - }); + auto a = + std::find_if(typeAttrMap.begin(), typeAttrMap.end(), + [&](const auto& e) { return type == getHwmonType(e); }); // *INDENT-ON* if (a == typeAttrMap.end()) @@ -23,4 +20,4 @@ bool getAttributes(const std::string& type, Attributes& attributes) return true; } -} // namespace hwmon +} // namespace hwmon @@ -1,10 +1,10 @@ #pragma once +#include "interface.hpp" + #include <string> #include <tuple> -#include "interface.hpp" - namespace hwmon { namespace entry @@ -20,7 +20,7 @@ static const std::string label = clabel; static const std::string target = ctarget; static const std::string enable = cenable; static const std::string fault = cfault; -} +} // namespace entry namespace type { @@ -32,7 +32,6 @@ static constexpr auto cenergy = "energy"; static constexpr auto cpower = "power"; static constexpr auto cpwm = "pwm"; - static const std::string fan = cfan; static const std::string temp = ctemp; static const std::string volt = cvolt; @@ -40,44 +39,25 @@ static const std::string curr = ccurr; static const std::string energy = cenergy; static const std::string power = cpower; static const std::string pwm = cpwm; -} +} // namespace type -static constexpr auto typeAttrMap = -{ +static constexpr auto typeAttrMap = { // 1 - hwmon class // 2 - unit // 3 - sysfs scaling factor // 4 - namespace - std::make_tuple( - hwmon::type::ctemp, - ValueInterface::Unit::DegreesC, - -3, - "temperature"), - std::make_tuple( - hwmon::type::cfan, - ValueInterface::Unit::RPMS, - 0, - "fan_tach"), - std::make_tuple( - hwmon::type::cvolt, - ValueInterface::Unit::Volts, - -3, - "voltage"), - std::make_tuple( - hwmon::type::ccurr, - ValueInterface::Unit::Amperes, - -3, - "current"), - std::make_tuple( - hwmon::type::cenergy, - ValueInterface::Unit::Joules, - -6, - "energy"), - std::make_tuple( - hwmon::type::cpower, - ValueInterface::Unit::Watts, - -6, - "power"), + std::make_tuple(hwmon::type::ctemp, ValueInterface::Unit::DegreesC, -3, + "temperature"), + std::make_tuple(hwmon::type::cfan, ValueInterface::Unit::RPMS, 0, + "fan_tach"), + std::make_tuple(hwmon::type::cvolt, ValueInterface::Unit::Volts, -3, + "voltage"), + std::make_tuple(hwmon::type::ccurr, ValueInterface::Unit::Amperes, -3, + "current"), + std::make_tuple(hwmon::type::cenergy, ValueInterface::Unit::Joules, -6, + "energy"), + std::make_tuple(hwmon::type::cpower, ValueInterface::Unit::Watts, -6, + "power"), }; inline auto getHwmonType(decltype(typeAttrMap)::const_reference attrs) @@ -101,8 +81,8 @@ inline auto getNamespace(decltype(typeAttrMap)::const_reference attrs) } using AttributeIterator = decltype(*typeAttrMap.begin()); -using Attributes - = std::remove_cv<std::remove_reference<AttributeIterator>::type>::type; +using Attributes = + std::remove_cv<std::remove_reference<AttributeIterator>::type>::type; /** @brief Get Attribute tuple for the type * @@ -113,6 +93,6 @@ using Attributes */ bool getAttributes(const std::string& type, Attributes& attributes); -} // namespace hwmon +} // namespace hwmon // vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4 diff --git a/hwmonio.cpp b/hwmonio.cpp index 97990ce..6c461b3 100644 --- a/hwmonio.cpp +++ b/hwmonio.cpp @@ -11,16 +11,19 @@ * See the License for the specific language governing permissions and * limitations under the License. */ +#include "config.h" + +#include "hwmonio.hpp" + +#include "sysfs.hpp" + #include <algorithm> #include <exception> #include <fstream> #include <thread> -#include "config.h" -#include "hwmonio.hpp" -#include "sysfs.hpp" - -namespace hwmonio { +namespace hwmonio +{ static constexpr auto retryableErrors = { /* @@ -72,22 +75,16 @@ HwmonIO::HwmonIO(const std::string& path) : p(path) { } -int64_t HwmonIO::read( - const std::string& type, - const std::string& id, - const std::string& sensor, - size_t retries, - std::chrono::milliseconds delay) const +int64_t HwmonIO::read(const std::string& type, const std::string& id, + const std::string& sensor, size_t retries, + std::chrono::milliseconds delay) const { int64_t val; std::ifstream ifs; - auto fullPath = sysfs::make_sysfs_path( - p, type, id, sensor); + auto fullPath = sysfs::make_sysfs_path(p, type, id, sensor); - ifs.exceptions( - std::ifstream::failbit | - std::ifstream::badbit | - std::ifstream::eofbit); + ifs.exceptions(std::ifstream::failbit | std::ifstream::badbit | + std::ifstream::eofbit); while (true) { @@ -112,21 +109,19 @@ int64_t HwmonIO::read( if (rc == ENOENT || rc == ENODEV) { // If the directory or device disappeared then this application - // should gracefully exit. There are race conditions between the - // unloading of a hwmon driver and the stopping of this service - // by systemd. To prevent this application from falsely failing - // in these scenarios, it will simply exit if the directory or - // file can not be found. It is up to the user(s) of this - // provided hwmon object to log the appropriate errors if the - // object disappears when it should not. + // should gracefully exit. There are race conditions between + // the unloading of a hwmon driver and the stopping of this + // service by systemd. To prevent this application from falsely + // failing in these scenarios, it will simply exit if the + // directory or file can not be found. It is up to the user(s) + // of this provided hwmon object to log the appropriate errors + // if the object disappears when it should not. exit(0); } - if (0 == std::count( - retryableErrors.begin(), - retryableErrors.end(), - rc) || - !retries) + if (0 == std::count(retryableErrors.begin(), retryableErrors.end(), + rc) || + !retries) { // Not a retryable error or out of retries. #ifdef NEGATIVE_ERRNO_ON_FAIL @@ -148,23 +143,16 @@ int64_t HwmonIO::read( return val; } -void HwmonIO::write( - uint32_t val, - const std::string& type, - const std::string& id, - const std::string& sensor, - size_t retries, - std::chrono::milliseconds delay) const +void HwmonIO::write(uint32_t val, const std::string& type, + const std::string& id, const std::string& sensor, + size_t retries, std::chrono::milliseconds delay) const { std::ofstream ofs; - auto fullPath = sysfs::make_sysfs_path( - p, type, id, sensor); + auto fullPath = sysfs::make_sysfs_path(p, type, id, sensor); - ofs.exceptions( - std::ofstream::failbit | - std::ofstream::badbit | - std::ofstream::eofbit); + ofs.exceptions(std::ofstream::failbit | std::ofstream::badbit | + std::ofstream::eofbit); // See comments in the read method for an explanation of the odd exception // handling behavior here. @@ -195,11 +183,9 @@ void HwmonIO::write( exit(0); } - if (0 == std::count( - retryableErrors.begin(), - retryableErrors.end(), - rc) || - !retries) + if (0 == std::count(retryableErrors.begin(), retryableErrors.end(), + rc) || + !retries) { // Not a retryable error or out of retries. @@ -221,4 +207,4 @@ std::string HwmonIO::path() const return p; } -} // hwmonio +} // namespace hwmonio diff --git a/hwmonio.hpp b/hwmonio.hpp index d49f4db..902888f 100644 --- a/hwmonio.hpp +++ b/hwmonio.hpp @@ -3,7 +3,8 @@ #include <chrono> #include <string> -namespace hwmonio { +namespace hwmonio +{ static constexpr auto retries = 10; static constexpr auto delay = std::chrono::milliseconds{100}; @@ -16,25 +17,19 @@ static constexpr auto delay = std::chrono::milliseconds{100}; */ class HwmonIOInterface { - public: - virtual ~HwmonIOInterface() = default; + public: + virtual ~HwmonIOInterface() = default; - virtual int64_t read( - const std::string& type, - const std::string& id, - const std::string& sensor, - size_t retries, - std::chrono::milliseconds delay) const = 0; + virtual int64_t read(const std::string& type, const std::string& id, + const std::string& sensor, size_t retries, + std::chrono::milliseconds delay) const = 0; - virtual void write( - uint32_t val, - const std::string& type, - const std::string& id, - const std::string& sensor, - size_t retries, - std::chrono::milliseconds delay) const = 0; + virtual void write(uint32_t val, const std::string& type, + const std::string& id, const std::string& sensor, + size_t retries, + std::chrono::milliseconds delay) const = 0; - virtual std::string path() const = 0; + virtual std::string path() const = 0; }; /** @class HwmonIO @@ -48,79 +43,71 @@ class HwmonIOInterface */ class HwmonIO : public HwmonIOInterface { - public: - HwmonIO() = delete; - HwmonIO(const HwmonIO&) = default; - HwmonIO(HwmonIO&&) = default; - HwmonIO& operator=(const HwmonIO&) = default; - HwmonIO& operator=(HwmonIO&&) = default; - ~HwmonIO() = default; - - /** @brief Constructor - * - * @param[in] path - hwmon instance root - eg: - * /sys/class/hwmon/hwmon<N> - */ - explicit HwmonIO(const std::string& path); + public: + HwmonIO() = delete; + HwmonIO(const HwmonIO&) = default; + HwmonIO(HwmonIO&&) = default; + HwmonIO& operator=(const HwmonIO&) = default; + HwmonIO& operator=(HwmonIO&&) = default; + ~HwmonIO() = default; - /** @brief Perform formatted hwmon sysfs read. - * - * Propagates any exceptions other than ENOENT. - * ENOENT will result in a call to exit(0) in case - * the underlying hwmon driver is unbound and - * the program is inadvertently left running. - * - * For possibly transient errors will retry up to - * the specified number of times. - * - * @param[in] type - The hwmon type (ex. temp). - * @param[in] id - The hwmon id (ex. 1). - * @param[in] sensor - The hwmon sensor (ex. input). - * @param[in] retries - The number of times to retry. - * @param[in] delay - The time to sleep between retry attempts. - * - * @return val - The read value. - */ - int64_t read( - const std::string& type, - const std::string& id, - const std::string& sensor, - size_t retries, - std::chrono::milliseconds delay) const override; + /** @brief Constructor + * + * @param[in] path - hwmon instance root - eg: + * /sys/class/hwmon/hwmon<N> + */ + explicit HwmonIO(const std::string& path); - /** @brief Perform formatted hwmon sysfs write. - * - * Propagates any exceptions other than ENOENT. - * ENOENT will result in a call to exit(0) in case - * the underlying hwmon driver is unbound and - * the program is inadvertently left running. - * - * For possibly transient errors will retry up to - * the specified number of times. - * - * @param[in] val - The value to be written. - * @param[in] type - The hwmon type (ex. fan). - * @param[in] id - The hwmon id (ex. 1). - * @param[in] retries - The number of times to retry. - * @param[in] delay - The time to sleep between retry attempts. - */ - void write( - uint32_t val, - const std::string& type, - const std::string& id, - const std::string& sensor, - size_t retries, - std::chrono::milliseconds delay) const override; + /** @brief Perform formatted hwmon sysfs read. + * + * Propagates any exceptions other than ENOENT. + * ENOENT will result in a call to exit(0) in case + * the underlying hwmon driver is unbound and + * the program is inadvertently left running. + * + * For possibly transient errors will retry up to + * the specified number of times. + * + * @param[in] type - The hwmon type (ex. temp). + * @param[in] id - The hwmon id (ex. 1). + * @param[in] sensor - The hwmon sensor (ex. input). + * @param[in] retries - The number of times to retry. + * @param[in] delay - The time to sleep between retry attempts. + * + * @return val - The read value. + */ + int64_t read(const std::string& type, const std::string& id, + const std::string& sensor, size_t retries, + std::chrono::milliseconds delay) const override; + /** @brief Perform formatted hwmon sysfs write. + * + * Propagates any exceptions other than ENOENT. + * ENOENT will result in a call to exit(0) in case + * the underlying hwmon driver is unbound and + * the program is inadvertently left running. + * + * For possibly transient errors will retry up to + * the specified number of times. + * + * @param[in] val - The value to be written. + * @param[in] type - The hwmon type (ex. fan). + * @param[in] id - The hwmon id (ex. 1). + * @param[in] retries - The number of times to retry. + * @param[in] delay - The time to sleep between retry attempts. + */ + void write(uint32_t val, const std::string& type, const std::string& id, + const std::string& sensor, size_t retries, + std::chrono::milliseconds delay) const override; - /** @brief Hwmon instance path access. - * - * @return path - The hwmon instance path. - */ - std::string path() const override; + /** @brief Hwmon instance path access. + * + * @return path - The hwmon instance path. + */ + std::string path() const override; - private: - std::string p; + private: + std::string p; }; } // namespace hwmonio diff --git a/interface.hpp b/interface.hpp index a2fa21f..e8ec28e 100644 --- a/interface.hpp +++ b/interface.hpp @@ -1,12 +1,12 @@ #pragma once -#include "xyz/openbmc_project/Sensor/Value/server.hpp" -#include "xyz/openbmc_project/Sensor/Threshold/Warning/server.hpp" -#include "xyz/openbmc_project/Sensor/Threshold/Critical/server.hpp" -#include "xyz/openbmc_project/Control/FanSpeed/server.hpp" -#include "xyz/openbmc_project/Control/FanPwm/server.hpp" -#include "xyz/openbmc_project/State/Decorator/OperationalStatus/server.hpp" #include <sdbusplus/server.hpp> +#include <xyz/openbmc_project/Control/FanPwm/server.hpp> +#include <xyz/openbmc_project/Control/FanSpeed/server.hpp> +#include <xyz/openbmc_project/Sensor/Threshold/Critical/server.hpp> +#include <xyz/openbmc_project/Sensor/Threshold/Warning/server.hpp> +#include <xyz/openbmc_project/Sensor/Value/server.hpp> +#include <xyz/openbmc_project/State/Decorator/OperationalStatus/server.hpp> template <typename... T> using ServerObject = typename sdbusplus::server::object::object<T...>; @@ -25,8 +25,8 @@ using FanSpeedObject = ServerObject<FanSpeedInterface>; using FanPwmInterface = sdbusplus::xyz::openbmc_project::Control::server::FanPwm; using FanPwmObject = ServerObject<FanPwmInterface>; -using StatusInterface = - sdbusplus::xyz::openbmc_project::State::Decorator::server::OperationalStatus; +using StatusInterface = sdbusplus::xyz::openbmc_project::State::Decorator:: + server::OperationalStatus; using StatusObject = ServerObject<StatusInterface>; enum class InterfaceType diff --git a/mainloop.cpp b/mainloop.cpp index 02c3ebb..cf5baaf 100644 --- a/mainloop.cpp +++ b/mainloop.cpp @@ -13,28 +13,29 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -#include <functional> -#include <iostream> -#include <memory> -#include <cstdlib> -#include <string> -#include <unordered_set> -#include <sstream> - -#include <phosphor-logging/elog-errors.hpp> #include "config.h" + +#include "mainloop.hpp" + #include "env.hpp" #include "fan_pwm.hpp" #include "fan_speed.hpp" #include "hwmon.hpp" #include "hwmonio.hpp" +#include "sensor.hpp" #include "sensorset.hpp" #include "sysfs.hpp" -#include "mainloop.hpp" #include "targets.hpp" #include "thresholds.hpp" -#include "sensor.hpp" +#include <cstdlib> +#include <functional> +#include <iostream> +#include <memory> +#include <phosphor-logging/elog-errors.hpp> +#include <sstream> +#include <string> +#include <unordered_set> #include <xyz/openbmc_project/Sensor/Device/error.hpp> using namespace phosphor::logging; @@ -48,9 +49,11 @@ decltype(Thresholds<WarningObject>::getLo) Thresholds<WarningObject>::getLo = &WarningObject::warningLow; decltype(Thresholds<WarningObject>::getHi) Thresholds<WarningObject>::getHi = &WarningObject::warningHigh; -decltype(Thresholds<WarningObject>::alarmLo) Thresholds<WarningObject>::alarmLo = +decltype( + Thresholds<WarningObject>::alarmLo) Thresholds<WarningObject>::alarmLo = &WarningObject::warningAlarmLow; -decltype(Thresholds<WarningObject>::alarmHi) Thresholds<WarningObject>::alarmHi = +decltype( + Thresholds<WarningObject>::alarmHi) Thresholds<WarningObject>::alarmHi = &WarningObject::warningAlarmHigh; // Initialization for Critical Objects @@ -62,9 +65,11 @@ decltype(Thresholds<CriticalObject>::getLo) Thresholds<CriticalObject>::getLo = &CriticalObject::criticalLow; decltype(Thresholds<CriticalObject>::getHi) Thresholds<CriticalObject>::getHi = &CriticalObject::criticalHigh; -decltype(Thresholds<CriticalObject>::alarmLo) Thresholds<CriticalObject>::alarmLo = +decltype( + Thresholds<CriticalObject>::alarmLo) Thresholds<CriticalObject>::alarmLo = &CriticalObject::criticalAlarmLow; -decltype(Thresholds<CriticalObject>::alarmHi) Thresholds<CriticalObject>::alarmHi = +decltype( + Thresholds<CriticalObject>::alarmHi) Thresholds<CriticalObject>::alarmHi = &CriticalObject::criticalAlarmHigh; std::string MainLoop::getID(SensorSet::container_t::const_reference sensor) @@ -87,10 +92,8 @@ std::string MainLoop::getID(SensorSet::container_t::const_reference sensor) auto mode = env::getEnv("MODE", sensor.first); if (!mode.empty()) { - id = env::getIndirectID( - _hwmonRoot + '/' + _instance + '/', - mode, - sensor.first); + id = env::getIndirectID(_hwmonRoot + '/' + _instance + '/', mode, + sensor.first); if (id.empty()) { @@ -105,8 +108,8 @@ std::string MainLoop::getID(SensorSet::container_t::const_reference sensor) return id; } -SensorIdentifiers MainLoop::getIdentifiers( - SensorSet::container_t::const_reference sensor) +SensorIdentifiers + MainLoop::getIdentifiers(SensorSet::container_t::const_reference sensor) { std::string id = getID(sensor); std::string label; @@ -117,8 +120,7 @@ SensorIdentifiers MainLoop::getIdentifiers( label = env::getEnv("LABEL", sensor.first.first, id); } - return std::make_tuple(std::move(id), - std::move(label)); + return std::make_tuple(std::move(id), std::move(label)); } /** @@ -129,8 +131,8 @@ SensorIdentifiers MainLoop::getIdentifiers( * are created and the InterfacesAdded signal is emitted. The object's state * data is then returned for sensor state monitoring within the main loop. */ -optional_ns::optional<ObjectStateData> MainLoop::getObject( - SensorSet::container_t::const_reference sensor) +optional_ns::optional<ObjectStateData> + MainLoop::getObject(SensorSet::container_t::const_reference sensor) { auto properties = getIdentifiers(sensor); if (std::get<sensorID>(properties).empty() || @@ -145,9 +147,8 @@ optional_ns::optional<ObjectStateData> MainLoop::getObject( return {}; } - auto sensorObj = std::make_unique<sensor::Sensor>(sensor.first, - ioAccess, - _devPath); + auto sensorObj = + std::make_unique<sensor::Sensor>(sensor.first, ioAccess, _devPath); // Get list of return codes for removing sensors on device auto devRmRCs = env::getEnv("REMOVERCS"); @@ -168,8 +169,7 @@ optional_ns::optional<ObjectStateData> MainLoop::getObject( // don't retry on errors when reading its value std::get<size_t>(retryIO) = 0; } - auto valueInterface = static_cast< - std::shared_ptr<ValueObject>>(nullptr); + auto valueInterface = static_cast<std::shared_ptr<ValueObject>>(nullptr); try { // Add status interface based on _fault file being present @@ -178,11 +178,9 @@ optional_ns::optional<ObjectStateData> MainLoop::getObject( } catch (const std::system_error& e) { - auto file = sysfs::make_sysfs_path( - ioAccess.path(), - sensor.first.first, - sensor.first.second, - hwmon::entry::cinput); + auto file = + sysfs::make_sysfs_path(ioAccess.path(), sensor.first.first, + sensor.first.second, hwmon::entry::cinput); #ifndef REMOVE_ON_FAIL // Check sensorAdjusts for sensor removal RCs auto& sAdjusts = sensorObj->getAdjusts(); @@ -193,24 +191,22 @@ optional_ns::optional<ObjectStateData> MainLoop::getObject( { // Trace for sensor not already removed from dbus log<level::INFO>("Sensor not added to dbus for read fail", - entry("FILE=%s", file.c_str()), - entry("RC=%d", e.code().value())); - rmSensors[std::move(sensor.first)] = - std::move(sensor.second); + entry("FILE=%s", file.c_str()), + entry("RC=%d", e.code().value())); + rmSensors[std::move(sensor.first)] = std::move(sensor.second); } return {}; } #endif - using namespace sdbusplus::xyz::openbmc_project:: - Sensor::Device::Error; + using namespace sdbusplus::xyz::openbmc_project::Sensor::Device::Error; report<ReadFailure>( - xyz::openbmc_project::Sensor::Device:: - ReadFailure::CALLOUT_ERRNO(e.code().value()), - xyz::openbmc_project::Sensor::Device:: - ReadFailure::CALLOUT_DEVICE_PATH(_devPath.c_str())); + xyz::openbmc_project::Sensor::Device::ReadFailure::CALLOUT_ERRNO( + e.code().value()), + xyz::openbmc_project::Sensor::Device::ReadFailure:: + CALLOUT_DEVICE_PATH(_devPath.c_str())); log<level::INFO>("Logging failing sysfs file", - entry("FILE=%s", file.c_str())); + entry("FILE=%s", file.c_str())); #ifdef REMOVE_ON_FAIL return {}; /* skip adding this sensor for now. */ #else @@ -218,17 +214,13 @@ optional_ns::optional<ObjectStateData> MainLoop::getObject( #endif } auto sensorValue = valueInterface->value(); - addThreshold<WarningObject>(sensor.first.first, - std::get<sensorID>(properties), - sensorValue, - info); - addThreshold<CriticalObject>(sensor.first.first, - std::get<sensorID>(properties), - sensorValue, - info); - - auto target = addTarget<hwmon::FanSpeed>( - sensor.first, ioAccess, _devPath, info); + addThreshold<WarningObject>( + sensor.first.first, std::get<sensorID>(properties), sensorValue, info); + addThreshold<CriticalObject>( + sensor.first.first, std::get<sensorID>(properties), sensorValue, info); + + auto target = + addTarget<hwmon::FanSpeed>(sensor.first, ioAccess, _devPath, info); if (target) { target->enable(); @@ -246,23 +238,12 @@ optional_ns::optional<ObjectStateData> MainLoop::getObject( std::move(info)); } -MainLoop::MainLoop( - sdbusplus::bus::bus&& bus, - const std::string& param, - const std::string& path, - const std::string& devPath, - const char* prefix, - const char* root) - : _bus(std::move(bus)), - _manager(_bus, root), - _pathParam(param), - _hwmonRoot(), - _instance(), - _devPath(devPath), - _prefix(prefix), - _root(root), - state(), - ioAccess(path) +MainLoop::MainLoop(sdbusplus::bus::bus&& bus, const std::string& param, + const std::string& path, const std::string& devPath, + const char* prefix, const char* root) : + _bus(std::move(bus)), + _manager(_bus, root), _pathParam(param), _hwmonRoot(), _instance(), + _devPath(devPath), _prefix(prefix), _root(root), state(), ioAccess(path) { // Strip off any trailing slashes. std::string p = path; @@ -297,14 +278,12 @@ void MainLoop::run() sd_event_default(&loop); - std::function<void()> callback(std::bind( - &MainLoop::read, this)); + std::function<void()> callback(std::bind(&MainLoop::read, this)); try { timer = std::make_unique<phosphor::hwmon::Timer>( - loop, callback, - std::chrono::microseconds(_interval), - phosphor::hwmon::timer::ON); + loop, callback, std::chrono::microseconds(_interval), + phosphor::hwmon::timer::ON); // TODO: Issue#6 - Optionally look at polling interval sysfs entry. @@ -336,9 +315,9 @@ void MainLoop::init() // std::tuple<SensorSet::mapped_type, // std::string(Sensor Label), // ObjectInfo> - auto value = std::make_tuple(std::move(i.second), - std::move((*object).first), - std::move((*object).second)); + auto value = + std::make_tuple(std::move(i.second), std::move((*object).first), + std::move((*object).second)); state[std::move(i.first)] = std::move(value); } @@ -352,8 +331,7 @@ void MainLoop::init() { std::stringstream ss; - ss << _prefix - << "-" + ss << _prefix << "-" << std::to_string(std::hash<std::string>{}(_devPath + _pathParam)) << ".Hwmon1"; @@ -383,7 +361,8 @@ void MainLoop::read() // Read value from sensor. int64_t value; std::string input = hwmon::entry::cinput; - if (i.first.first == "pwm") { + if (i.first.first == "pwm") + { input = ""; } @@ -396,13 +375,10 @@ void MainLoop::read() if (it != obj.end()) { auto fault = ioAccess.read( - i.first.first, - i.first.second, - hwmon::entry::fault, - hwmonio::retries, - hwmonio::delay); + i.first.first, i.first.second, hwmon::entry::fault, + hwmonio::retries, hwmonio::delay); auto statusIface = std::experimental::any_cast< - std::shared_ptr<StatusObject>>(it->second); + std::shared_ptr<StatusObject>>(it->second); if (!statusIface->functional((fault == 0) ? true : false)) { continue; @@ -412,12 +388,8 @@ void MainLoop::read() // Retry for up to a second if device is busy // or has a transient error. - value = ioAccess.read( - i.first.first, - i.first.second, - input, - hwmonio::retries, - hwmonio::delay); + value = ioAccess.read(i.first.first, i.first.second, input, + hwmonio::retries, hwmonio::delay); value = sensorObjects[i.first]->adjustValue(value); @@ -430,15 +402,16 @@ void MainLoop::read() switch (iface.first) { case InterfaceType::VALUE: - valueIface = std::experimental::any_cast<std::shared_ptr<ValueObject>> - (iface.second); + valueIface = std::experimental::any_cast< + std::shared_ptr<ValueObject>>(iface.second); valueIface->value(value); break; case InterfaceType::WARN: checkThresholds<WarningObject>(iface.second, value); break; case InterfaceType::CRIT: - checkThresholds<CriticalObject>(iface.second, value); + checkThresholds<CriticalObject>(iface.second, + value); break; default: break; @@ -448,10 +421,8 @@ void MainLoop::read() catch (const std::system_error& e) { auto file = sysfs::make_sysfs_path( - ioAccess.path(), - i.first.first, - i.first.second, - hwmon::entry::cinput); + ioAccess.path(), i.first.first, i.first.second, + hwmon::entry::cinput); #ifndef REMOVE_ON_FAIL // Check sensorAdjusts for sensor removal RCs auto& sAdjusts = sensorObjects[i.first]->getAdjusts(); @@ -462,26 +433,25 @@ void MainLoop::read() { // Trace for sensor not already removed from dbus log<level::INFO>( - "Remove sensor from dbus for read fail", - entry("FILE=%s", file.c_str()), - entry("RC=%d", e.code().value())); + "Remove sensor from dbus for read fail", + entry("FILE=%s", file.c_str()), + entry("RC=%d", e.code().value())); // Mark this sensor to be removed from dbus rmSensors[i.first] = std::get<0>(i.second); } continue; } #endif - using namespace sdbusplus::xyz::openbmc_project:: - Sensor::Device::Error; + using namespace sdbusplus::xyz::openbmc_project::Sensor:: + Device::Error; report<ReadFailure>( - xyz::openbmc_project::Sensor::Device:: - ReadFailure::CALLOUT_ERRNO(e.code().value()), - xyz::openbmc_project::Sensor::Device:: - ReadFailure::CALLOUT_DEVICE_PATH( - _devPath.c_str())); + xyz::openbmc_project::Sensor::Device::ReadFailure:: + CALLOUT_ERRNO(e.code().value()), + xyz::openbmc_project::Sensor::Device::ReadFailure:: + CALLOUT_DEVICE_PATH(_devPath.c_str())); log<level::INFO>("Logging failing sysfs file", - entry("FILE=%s", file.c_str())); + entry("FILE=%s", file.c_str())); #ifdef REMOVE_ON_FAIL rmSensors[i.first] = std::get<0>(i.second); @@ -506,7 +476,7 @@ void MainLoop::read() if (state.find(it->first) == state.end()) { SensorSet::container_t::value_type ssValueType = - std::make_pair(it->first, it->second); + std::make_pair(it->first, it->second); auto object = getObject(ssValueType); if (object) { @@ -522,13 +492,10 @@ void MainLoop::read() // Sensor object added, erase entry from removal list auto file = sysfs::make_sysfs_path( - ioAccess.path(), - it->first.first, - it->first.second, - hwmon::entry::cinput); - log<level::INFO>( - "Added sensor to dbus after successful read", - entry("FILE=%s", file.c_str())); + ioAccess.path(), it->first.first, it->first.second, + hwmon::entry::cinput); + log<level::INFO>("Added sensor to dbus after successful read", + entry("FILE=%s", file.c_str())); it = rmSensors.erase(it); } else diff --git a/mainloop.hpp b/mainloop.hpp index c3ed161..77419e5 100644 --- a/mainloop.hpp +++ b/mainloop.hpp @@ -1,18 +1,19 @@ #pragma once -#include <string> -#include <vector> -#include <experimental/any> -#include <experimental/optional> -#include <memory> -#include <sdbusplus/server.hpp> -#include "types.hpp" #include "hwmonio.hpp" +#include "interface.hpp" +#include "sensor.hpp" #include "sensorset.hpp" #include "sysfs.hpp" -#include "interface.hpp" #include "timer.hpp" -#include "sensor.hpp" +#include "types.hpp" + +#include <experimental/any> +#include <experimental/optional> +#include <memory> +#include <sdbusplus/server.hpp> +#include <string> +#include <vector> static constexpr auto default_interval = 1000000; @@ -27,116 +28,113 @@ namespace optional_ns = std::experimental; */ class MainLoop { - public: - MainLoop() = delete; - MainLoop(const MainLoop&) = delete; - MainLoop& operator=(const MainLoop&) = delete; - MainLoop(MainLoop&&) = default; - MainLoop& operator=(MainLoop&&) = default; - ~MainLoop() = default; - - /** @brief Constructor - * - * @param[in] bus - sdbusplus bus client connection. - * @param[in] param - the path parameter provided - * @param[in] path - hwmon sysfs instance to manage - * @param[in] devPath - physical device sysfs path. - * @param[in] prefix - DBus busname prefix. - * @param[in] root - DBus sensors namespace root. - * - * Any DBus objects are created relative to the DBus - * sensors namespace root. - * - * At startup, the application will own a busname with - * the format <prefix>.hwmon<n>. - */ - MainLoop( - sdbusplus::bus::bus&& bus, - const std::string& param, - const std::string& path, - const std::string& devPath, - const char* prefix, - const char* root); - - /** @brief Setup polling timer in a sd event loop and attach to D-Bus - * event loop. - */ - void run(); - - /** @brief Stop polling timer event loop from another thread. - * - * Typically only used by testcases. - */ - void shutdown() noexcept; - - private: - using mapped_type = std::tuple<SensorSet::mapped_type, std::string, ObjectInfo>; - using SensorState = std::map<SensorSet::key_type, mapped_type>; - - /** @brief Read hwmon sysfs entries */ - void read(); - - /** @brief Set up D-Bus object state */ - void init(); - - /** @brief sdbusplus bus client connection. */ - sdbusplus::bus::bus _bus; - /** @brief sdbusplus freedesktop.ObjectManager storage. */ - sdbusplus::server::manager::manager _manager; - /** @brief the parameter path used. */ - std::string _pathParam; - /** @brief hwmon sysfs class path. */ - std::string _hwmonRoot; - /** @brief hwmon sysfs instance. */ - std::string _instance; - /** @brief physical device sysfs path. */ - std::string _devPath; - /** @brief DBus busname prefix. */ - const char* _prefix; - /** @brief DBus sensors namespace root. */ - const char* _root; - /** @brief DBus object state. */ - SensorState state; - /** @brief Sleep interval in microseconds. */ - uint64_t _interval = default_interval; - /** @brief Hwmon sysfs access. */ - hwmonio::HwmonIO ioAccess; - /** @brief Timer */ - std::unique_ptr<phosphor::hwmon::Timer> timer; - /** @brief the sd_event structure */ - sd_event* loop = nullptr; - /** @brief Store the specifications of sensor objects */ - std::map<SensorSet::key_type, - std::unique_ptr<sensor::Sensor>> sensorObjects; - - /** - * @brief Map of removed sensors - */ - std::map<SensorSet::key_type, SensorSet::mapped_type> rmSensors; - - /** - * @brief Get the ID of the sensor - * - * @param[in] sensor - Sensor to get the ID of - */ - std::string getID(SensorSet::container_t::const_reference sensor); - - /** - * @brief Get the sensor identifiers - * - * @param[in] sensor - Sensor to get the identifiers of - */ - SensorIdentifiers getIdentifiers( - SensorSet::container_t::const_reference sensor); - - /** - * @brief Used to create and add sensor objects - * - * @param[in] sensor - Sensor to create/add object for - * - * @return - Optional - * Object state data on success, nothing on failure - */ - optional_ns::optional<ObjectStateData> getObject( - SensorSet::container_t::const_reference sensor); + public: + MainLoop() = delete; + MainLoop(const MainLoop&) = delete; + MainLoop& operator=(const MainLoop&) = delete; + MainLoop(MainLoop&&) = default; + MainLoop& operator=(MainLoop&&) = default; + ~MainLoop() = default; + + /** @brief Constructor + * + * @param[in] bus - sdbusplus bus client connection. + * @param[in] param - the path parameter provided + * @param[in] path - hwmon sysfs instance to manage + * @param[in] devPath - physical device sysfs path. + * @param[in] prefix - DBus busname prefix. + * @param[in] root - DBus sensors namespace root. + * + * Any DBus objects are created relative to the DBus + * sensors namespace root. + * + * At startup, the application will own a busname with + * the format <prefix>.hwmon<n>. + */ + MainLoop(sdbusplus::bus::bus&& bus, const std::string& param, + const std::string& path, const std::string& devPath, + const char* prefix, const char* root); + + /** @brief Setup polling timer in a sd event loop and attach to D-Bus + * event loop. + */ + void run(); + + /** @brief Stop polling timer event loop from another thread. + * + * Typically only used by testcases. + */ + void shutdown() noexcept; + + private: + using mapped_type = + std::tuple<SensorSet::mapped_type, std::string, ObjectInfo>; + using SensorState = std::map<SensorSet::key_type, mapped_type>; + + /** @brief Read hwmon sysfs entries */ + void read(); + + /** @brief Set up D-Bus object state */ + void init(); + + /** @brief sdbusplus bus client connection. */ + sdbusplus::bus::bus _bus; + /** @brief sdbusplus freedesktop.ObjectManager storage. */ + sdbusplus::server::manager::manager _manager; + /** @brief the parameter path used. */ + std::string _pathParam; + /** @brief hwmon sysfs class path. */ + std::string _hwmonRoot; + /** @brief hwmon sysfs instance. */ + std::string _instance; + /** @brief physical device sysfs path. */ + std::string _devPath; + /** @brief DBus busname prefix. */ + const char* _prefix; + /** @brief DBus sensors namespace root. */ + const char* _root; + /** @brief DBus object state. */ + SensorState state; + /** @brief Sleep interval in microseconds. */ + uint64_t _interval = default_interval; + /** @brief Hwmon sysfs access. */ + hwmonio::HwmonIO ioAccess; + /** @brief Timer */ + std::unique_ptr<phosphor::hwmon::Timer> timer; + /** @brief the sd_event structure */ + sd_event* loop = nullptr; + /** @brief Store the specifications of sensor objects */ + std::map<SensorSet::key_type, std::unique_ptr<sensor::Sensor>> + sensorObjects; + + /** + * @brief Map of removed sensors + */ + std::map<SensorSet::key_type, SensorSet::mapped_type> rmSensors; + + /** + * @brief Get the ID of the sensor + * + * @param[in] sensor - Sensor to get the ID of + */ + std::string getID(SensorSet::container_t::const_reference sensor); + + /** + * @brief Get the sensor identifiers + * + * @param[in] sensor - Sensor to get the identifiers of + */ + SensorIdentifiers + getIdentifiers(SensorSet::container_t::const_reference sensor); + + /** + * @brief Used to create and add sensor objects + * + * @param[in] sensor - Sensor to create/add object for + * + * @return - Optional + * Object state data on success, nothing on failure + */ + optional_ns::optional<ObjectStateData> + getObject(SensorSet::container_t::const_reference sensor); }; @@ -13,13 +13,15 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -#include <iostream> -#include <memory> +#include "config.h" + #include "argument.hpp" #include "mainloop.hpp" -#include "config.h" #include "sysfs.hpp" +#include <iostream> +#include <memory> + static void exit_with_error(const char* err, char** argv) { ArgumentParser::usage(argv); @@ -71,13 +73,8 @@ int main(int argc, char** argv) exit_with_error("Unable to determine callout path.", argv); } - MainLoop loop( - sdbusplus::bus::new_default(), - param, - path, - calloutPath, - BUSNAME_PREFIX, - SENSOR_ROOT); + MainLoop loop(sdbusplus::bus::new_default(), param, path, calloutPath, + BUSNAME_PREFIX, SENSOR_ROOT); loop.run(); return 0; @@ -1,27 +1,26 @@ -#include <cstring> -#include <experimental/filesystem> - -#include <phosphor-logging/elog-errors.hpp> -#include <xyz/openbmc_project/Sensor/Device/error.hpp> - #include "config.h" + #include "sensor.hpp" -#include "sensorset.hpp" -#include "hwmon.hpp" + #include "env.hpp" +#include "hwmon.hpp" +#include "sensorset.hpp" #include "sysfs.hpp" +#include <cstring> +#include <experimental/filesystem> +#include <phosphor-logging/elog-errors.hpp> +#include <xyz/openbmc_project/Sensor/Device/error.hpp> + namespace sensor { using namespace phosphor::logging; Sensor::Sensor(const SensorSet::key_type& sensor, - const hwmonio::HwmonIO& ioAccess, - const std::string& devPath) : + const hwmonio::HwmonIO& ioAccess, const std::string& devPath) : sensor(sensor), - ioAccess(ioAccess), - devPath(devPath) + ioAccess(ioAccess), devPath(devPath) { auto gain = env::getEnv("GAIN", sensor); if (!gain.empty()) @@ -47,8 +46,7 @@ void Sensor::addRemoveRCs(const std::string& rcList) } // Convert to a char* for strtok - std::vector<char> rmRCs(rcList.c_str(), - rcList.c_str() + rcList.size() + 1); + std::vector<char> rmRCs(rcList.c_str(), rcList.c_str() + rcList.size() + 1); auto rmRC = std::strtok(&rmRCs[0], ", "); while (rmRC != nullptr) { @@ -83,15 +81,13 @@ int64_t Sensor::adjustValue(int64_t value) // Adjust based on gain and offset value = static_cast<decltype(value)>( - static_cast<double>(value) * sensorAdjusts.gain - + sensorAdjusts.offset); + static_cast<double>(value) * sensorAdjusts.gain + sensorAdjusts.offset); return value; } -std::shared_ptr<ValueObject> Sensor::addValue( - const RetryIO& retryIO, - ObjectInfo& info) +std::shared_ptr<ValueObject> Sensor::addValue(const RetryIO& retryIO, + ObjectInfo& info) { static constexpr bool deferSignals = true; @@ -105,8 +101,9 @@ std::shared_ptr<ValueObject> Sensor::addValue( auto it = obj.find(InterfaceType::STATUS); if (it != obj.end()) { - statusIface = std::experimental::any_cast< - std::shared_ptr<StatusObject>>(it->second); + statusIface = + std::experimental::any_cast<std::shared_ptr<StatusObject>>( + it->second); } // If there's no fault file or the sensor has a fault file and @@ -115,16 +112,14 @@ std::shared_ptr<ValueObject> Sensor::addValue( { // Retry for up to a second if device is busy // or has a transient error. - val = ioAccess.read( - sensor.first, - sensor.second, - hwmon::entry::cinput, - std::get<size_t>(retryIO), - std::get<std::chrono::milliseconds>(retryIO)); + val = ioAccess.read(sensor.first, sensor.second, hwmon::entry::cinput, + std::get<size_t>(retryIO), + std::get<std::chrono::milliseconds>(retryIO)); val = adjustValue(val); } - auto iface = std::make_shared<ValueObject>(bus, objPath.c_str(), deferSignals); + auto iface = + std::make_shared<ValueObject>(bus, objPath.c_str(), deferSignals); iface->value(val); hwmon::Attributes attrs; @@ -135,12 +130,12 @@ std::shared_ptr<ValueObject> Sensor::addValue( } auto maxValue = env::getEnv("MAXVALUE", sensor); - if(!maxValue.empty()) + if (!maxValue.empty()) { iface->maxValue(std::stoll(maxValue)); } auto minValue = env::getEnv("MINVALUE", sensor); - if(!minValue.empty()) + if (!minValue.empty()) { iface->minValue(std::stoll(minValue)); } @@ -164,20 +159,15 @@ std::shared_ptr<StatusObject> Sensor::addStatus(ObjectInfo& info) std::string faultID = sensor.second; std::string entry = hwmon::entry::fault; - auto sysfsFullPath = sysfs::make_sysfs_path(ioAccess.path(), - faultName, - faultID, - entry); + auto sysfsFullPath = + sysfs::make_sysfs_path(ioAccess.path(), faultName, faultID, entry); if (fs::exists(sysfsFullPath)) { bool functional = true; uint32_t fault = 0; try { - fault = ioAccess.read(faultName, - faultID, - entry, - hwmonio::retries, + fault = ioAccess.read(faultName, faultID, entry, hwmonio::retries, hwmonio::delay); if (fault != 0) { @@ -186,24 +176,20 @@ std::shared_ptr<StatusObject> Sensor::addStatus(ObjectInfo& info) } catch (const std::system_error& e) { - using namespace sdbusplus::xyz::openbmc_project:: - Sensor::Device::Error; - using metadata = xyz::openbmc_project::Sensor:: - Device::ReadFailure; - - report<ReadFailure>( - metadata::CALLOUT_ERRNO(e.code().value()), - metadata::CALLOUT_DEVICE_PATH(devPath.c_str())); - - log<level::INFO>("Logging failing sysfs file", - phosphor::logging::entry( - "FILE=%s", sysfsFullPath.c_str())); + using namespace sdbusplus::xyz::openbmc_project::Sensor::Device:: + Error; + using metadata = xyz::openbmc_project::Sensor::Device::ReadFailure; + + report<ReadFailure>(metadata::CALLOUT_ERRNO(e.code().value()), + metadata::CALLOUT_DEVICE_PATH(devPath.c_str())); + + log<level::INFO>( + "Logging failing sysfs file", + phosphor::logging::entry("FILE=%s", sysfsFullPath.c_str())); } - iface = std::make_shared<StatusObject>( - bus, - objPath.c_str(), - deferSignals); + iface = + std::make_shared<StatusObject>(bus, objPath.c_str(), deferSignals); // Set functional property iface->functional(functional); @@ -1,9 +1,10 @@ #pragma once -#include <unordered_set> -#include "types.hpp" -#include "sensorset.hpp" #include "hwmonio.hpp" +#include "sensorset.hpp" +#include "types.hpp" + +#include <unordered_set> namespace sensor { @@ -23,97 +24,95 @@ struct valueAdjust */ class Sensor { - public: - Sensor() = delete; - Sensor(const Sensor&) = delete; - Sensor(Sensor&&) = default; - Sensor& operator=(const Sensor&) = delete; - Sensor& operator=(Sensor&&) = default; - ~Sensor() = default; - - /** - * @brief Constructs Sensor object - * - * @param[in] sensor - A pair of sensor indentifiers - * @param[in] ioAccess - Hwmon sysfs access - * @param[in] devPath - Device sysfs path - */ - explicit Sensor(const SensorSet::key_type& sensor, - const hwmonio::HwmonIO& ioAccess, - const std::string& devPath); - - /** - * @brief Adds any sensor removal return codes for the sensor - * @details Add all return codes defined within a device's config file - * for the entire device or for the specific sensor. - * - * @param[in] rcList - List of return codes found for the sensor - */ - void addRemoveRCs(const std::string& rcList); - - /** - * @brief Get the adjustments struct for the sensor - * - * @return - Sensor adjustment struct - */ - inline const valueAdjust& getAdjusts() - { - return sensorAdjusts; - } - - /** - * @brief Adjusts a sensor value - * @details Adjusts the value given by any gain and/or offset defined - * for this sensor object and returns that adjusted value. - * - * @param[in] value - Value to be adjusted - * - * @return - Adjusted sensor value - */ - int64_t adjustValue(int64_t value); - - /** - * @brief Add value interface and value property for sensor - * @details When a sensor has an associated input file, the Sensor.Value - * interface is added along with setting the Value property to the - * corresponding value found in the input file. - * - * @param[in] retryIO - Hwmon sysfs file retry constraints - * (number of and delay between) - * @param[in] info - Sensor object information - * - * @return - Shared pointer to the value object - */ - std::shared_ptr<ValueObject> addValue( - const RetryIO& retryIO, - ObjectInfo& info); - - /** - * @brief Add status interface and functional property for sensor - * @details When a sensor has an associated fault file, the - * OperationalStatus interface is added along with setting the - * Functional property to the corresponding value found in the - * fault file. - * - * @param[in] info - Sensor object information - * - * @return - Shared pointer to the status object - */ - std::shared_ptr<StatusObject> addStatus( - ObjectInfo& info); - - private: - /** @brief Sensor object's identifiers */ - SensorSet::key_type sensor; - - /** @brief Hwmon sysfs access. */ - const hwmonio::HwmonIO& ioAccess; - - /** @brief Physical device sysfs path. */ - const std::string& devPath; - - /** @brief Structure for storing sensor adjustments */ - valueAdjust sensorAdjusts; + public: + Sensor() = delete; + Sensor(const Sensor&) = delete; + Sensor(Sensor&&) = default; + Sensor& operator=(const Sensor&) = delete; + Sensor& operator=(Sensor&&) = default; + ~Sensor() = default; + + /** + * @brief Constructs Sensor object + * + * @param[in] sensor - A pair of sensor indentifiers + * @param[in] ioAccess - Hwmon sysfs access + * @param[in] devPath - Device sysfs path + */ + explicit Sensor(const SensorSet::key_type& sensor, + const hwmonio::HwmonIO& ioAccess, + const std::string& devPath); + + /** + * @brief Adds any sensor removal return codes for the sensor + * @details Add all return codes defined within a device's config file + * for the entire device or for the specific sensor. + * + * @param[in] rcList - List of return codes found for the sensor + */ + void addRemoveRCs(const std::string& rcList); + + /** + * @brief Get the adjustments struct for the sensor + * + * @return - Sensor adjustment struct + */ + inline const valueAdjust& getAdjusts() + { + return sensorAdjusts; + } + + /** + * @brief Adjusts a sensor value + * @details Adjusts the value given by any gain and/or offset defined + * for this sensor object and returns that adjusted value. + * + * @param[in] value - Value to be adjusted + * + * @return - Adjusted sensor value + */ + int64_t adjustValue(int64_t value); + + /** + * @brief Add value interface and value property for sensor + * @details When a sensor has an associated input file, the Sensor.Value + * interface is added along with setting the Value property to the + * corresponding value found in the input file. + * + * @param[in] retryIO - Hwmon sysfs file retry constraints + * (number of and delay between) + * @param[in] info - Sensor object information + * + * @return - Shared pointer to the value object + */ + std::shared_ptr<ValueObject> addValue(const RetryIO& retryIO, + ObjectInfo& info); + + /** + * @brief Add status interface and functional property for sensor + * @details When a sensor has an associated fault file, the + * OperationalStatus interface is added along with setting the + * Functional property to the corresponding value found in the + * fault file. + * + * @param[in] info - Sensor object information + * + * @return - Shared pointer to the status object + */ + std::shared_ptr<StatusObject> addStatus(ObjectInfo& info); + + private: + /** @brief Sensor object's identifiers */ + SensorSet::key_type sensor; + + /** @brief Hwmon sysfs access. */ + const hwmonio::HwmonIO& ioAccess; + + /** @brief Physical device sysfs path. */ + const std::string& devPath; + + /** @brief Structure for storing sensor adjustments */ + valueAdjust sensorAdjusts; }; } // namespace sensor diff --git a/sensorset.cpp b/sensorset.cpp index 2952775..268ef3d 100644 --- a/sensorset.cpp +++ b/sensorset.cpp @@ -13,17 +13,18 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -#include <experimental/filesystem> -#include <regex> -#include <iostream> #include "sensorset.hpp" + #include "hwmon.hpp" +#include <experimental/filesystem> +#include <iostream> +#include <regex> + // TODO: Issue#2 - STL regex generates really bloated code. Use POSIX regex // interfaces instead. -static const std::regex sensors_regex = - std::regex("^(fan|in|temp|power|energy|curr)([0-9]+)_([a-z]*)", - std::regex::extended); +static const std::regex sensors_regex = std::regex( + "^(fan|in|temp|power|energy|curr)([0-9]+)_([a-z]*)", std::regex::extended); static const auto sensor_regex_match_count = 4; SensorSet::SensorSet(const std::string& path) diff --git a/sensorset.hpp b/sensorset.hpp index 420761f..8ad0d5a 100644 --- a/sensorset.hpp +++ b/sensorset.hpp @@ -19,58 +19,56 @@ */ class SensorSet { - public: - typedef std::map<std::pair<std::string, std::string>, - std::set<std::string>> container_t; - using mapped_type = container_t::mapped_type; - using key_type = container_t::key_type; + public: + typedef std::map<std::pair<std::string, std::string>, std::set<std::string>> + container_t; + using mapped_type = container_t::mapped_type; + using key_type = container_t::key_type; - /** - * @brief Constructor - * @details Builds a map of the hwmon sysfs files in the passed - * in directory. - * - * @param[in] path - path to the hwmon device directory - * - */ - explicit SensorSet(const std::string& path); - ~SensorSet() = default; - SensorSet() = delete; - SensorSet(const SensorSet&) = delete; - SensorSet& operator=(const SensorSet&) = delete; - SensorSet(SensorSet&&) = default; - SensorSet& operator=(SensorSet&&) = default; + /** + * @brief Constructor + * @details Builds a map of the hwmon sysfs files in the passed + * in directory. + * + * @param[in] path - path to the hwmon device directory + * + */ + explicit SensorSet(const std::string& path); + ~SensorSet() = default; + SensorSet() = delete; + SensorSet(const SensorSet&) = delete; + SensorSet& operator=(const SensorSet&) = delete; + SensorSet(SensorSet&&) = default; + SensorSet& operator=(SensorSet&&) = default; - /** - * @brief Returns an iterator to the beginning of the map - * - * @return const_iterator - */ - container_t::const_iterator begin() - { - return const_cast<const container_t&>(container).begin(); - } + /** + * @brief Returns an iterator to the beginning of the map + * + * @return const_iterator + */ + container_t::const_iterator begin() + { + return const_cast<const container_t&>(container).begin(); + } - /** - * @brief Returns an iterator to the end of the map - * - * @return const_iterator - */ - container_t::const_iterator end() - { - return const_cast<const container_t&>(container).end(); - } - - private: - - /** - * @brief The map of hwmon files in the directory - * @details For example: - * key = pair("temp", "1") - * value = "input" - */ - container_t container; + /** + * @brief Returns an iterator to the end of the map + * + * @return const_iterator + */ + container_t::const_iterator end() + { + return const_cast<const container_t&>(container).end(); + } + private: + /** + * @brief The map of hwmon files in the directory + * @details For example: + * key = pair("temp", "1") + * value = "input" + */ + container_t container; }; // vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4 @@ -13,6 +13,10 @@ * See the License for the specific language governing permissions and * limitations under the License. */ +#include "config.h" + +#include "sysfs.hpp" + #include <algorithm> #include <cerrno> #include <cstdlib> @@ -21,20 +25,18 @@ #include <memory> #include <phosphor-logging/log.hpp> #include <thread> -#include "config.h" -#include "sysfs.hpp" using namespace std::string_literals; namespace fs = std::experimental::filesystem; -namespace sysfs { +namespace sysfs +{ static const auto emptyString = ""s; static constexpr auto ofRoot = "/sys/firmware/devicetree/base"; -std::string findPhandleMatch( - const std::string& iochanneldir, - const std::string& phandledir) +std::string findPhandleMatch(const std::string& iochanneldir, + const std::string& phandledir) { // TODO: At the moment this method only supports device trees // with iio-hwmon nodes with a single sensor. Typically @@ -56,9 +58,8 @@ std::string findPhandleMatch( uint32_t ioChannelsValue; std::ifstream ioChannelsFile(ioChannelsPath); - ioChannelsFile.read( - reinterpret_cast<char*>(&ioChannelsValue), - sizeof(ioChannelsValue)); + ioChannelsFile.read(reinterpret_cast<char*>(&ioChannelsValue), + sizeof(ioChannelsValue)); for (const auto& ofInst : fs::recursive_directory_iterator(phandledir)) { @@ -70,9 +71,8 @@ std::string findPhandleMatch( std::ifstream pHandleFile(path); uint32_t pHandleValue; - pHandleFile.read( - reinterpret_cast<char*>(&pHandleValue), - sizeof(pHandleValue)); + pHandleFile.read(reinterpret_cast<char*>(&pHandleValue), + sizeof(pHandleValue)); if (ioChannelsValue == pHandleValue) { @@ -128,7 +128,7 @@ std::string findCalloutPath(const std::string& instancePath) // If a match is found, use the corresponding /sys/devices // iio device as the callout device. static constexpr auto iioDevices = "/sys/bus/iio/devices"; - for (const auto& iioDev: fs::recursive_directory_iterator(iioDevices)) + for (const auto& iioDev : fs::recursive_directory_iterator(iioDevices)) { p = iioDev.path(); p /= "of_node"; @@ -211,9 +211,9 @@ std::string findHwmonFromDevPath(const std::string& devPath) try { - //This path is also used as a filesystem path to an environment - //file, and that has issues with ':'s in the path so they've - //been converted to '--'s. Convert them back now. + // This path is also used as a filesystem path to an environment + // file, and that has issues with ':'s in the path so they've + // been converted to '--'s. Convert them back now. size_t pos = 0; std::string path = p; while ((pos = path.find("--")) != std::string::npos) @@ -224,7 +224,7 @@ std::string findHwmonFromDevPath(const std::string& devPath) for (const auto& hwmonInst : fs::directory_iterator(path)) { if ((hwmonInst.path().filename().string().find("hwmon") != - std::string::npos)) + std::string::npos)) { return hwmonInst.path(); } @@ -233,9 +233,8 @@ std::string findHwmonFromDevPath(const std::string& devPath) catch (const std::exception& e) { using namespace phosphor::logging; - log<level::ERR>( - "Unable to find hwmon directory from the dev path", - entry("PATH=%s", devPath.c_str())); + log<level::ERR>("Unable to find hwmon directory from the dev path", + entry("PATH=%s", devPath.c_str())); } return emptyString; } @@ -5,7 +5,8 @@ #include <fstream> #include <string> -namespace sysfs { +namespace sysfs +{ inline std::string make_sysfs_path(const std::string& path, const std::string& type, @@ -14,7 +15,8 @@ inline std::string make_sysfs_path(const std::string& path, { using namespace std::literals; - if (entry.empty()) { + if (entry.empty()) + { return path + "/"s + type + id; } @@ -35,9 +37,8 @@ inline std::string make_sysfs_path(const std::string& path, * * @return Path to phandle file with value matching that in io-channels */ -std::string findPhandleMatch( - const std::string& iochanneldir, - const std::string& phandledir); +std::string findPhandleMatch(const std::string& iochanneldir, + const std::string& phandledir); /** @brief Find hwmon instances from an open-firmware device tree path * diff --git a/targets.hpp b/targets.hpp index 9867ba9..317eec5 100644 --- a/targets.hpp +++ b/targets.hpp @@ -1,14 +1,15 @@ #pragma once +#include "env.hpp" +#include "fan_pwm.hpp" +#include "fan_speed.hpp" +#include "hwmonio.hpp" + #include <experimental/filesystem> #include <memory> #include <phosphor-logging/elog-errors.hpp> #include <phosphor-logging/log.hpp> #include <xyz/openbmc_project/Sensor/Device/error.hpp> -#include "env.hpp" -#include "fan_speed.hpp" -#include "fan_pwm.hpp" -#include "hwmonio.hpp" enum class targetType { @@ -64,8 +65,7 @@ struct Targets<hwmon::FanPwm> template <typename T> std::shared_ptr<T> addTarget(const SensorSet::key_type& sensor, const hwmonio::HwmonIO& ioAccess, - const std::string& devPath, - ObjectInfo& info) + const std::string& devPath, ObjectInfo& info) { std::shared_ptr<T> target; namespace fs = std::experimental::filesystem; @@ -98,10 +98,8 @@ std::shared_ptr<T> addTarget(const SensorSet::key_type& sensor, entry = empty; } - sysfsFullPath = sysfs::make_sysfs_path(ioAccess.path(), - targetName, - targetId, - entry); + sysfsFullPath = + sysfs::make_sysfs_path(ioAccess.path(), targetName, targetId, entry); if (fs::exists(sysfsFullPath)) { auto useTarget = true; @@ -128,11 +126,10 @@ std::shared_ptr<T> addTarget(const SensorSet::key_type& sensor, else { using namespace phosphor::logging; - log<level::ERR>("Invalid TARGET_MODE env var found", - phosphor::logging::entry( - "TARGET_MODE=%s", tmEnv.c_str()), - phosphor::logging::entry( - "DEVPATH=%s", devPath.c_str())); + log<level::ERR>( + "Invalid TARGET_MODE env var found", + phosphor::logging::entry("TARGET_MODE=%s", tmEnv.c_str()), + phosphor::logging::entry("DEVPATH=%s", devPath.c_str())); } } @@ -142,40 +139,31 @@ std::shared_ptr<T> addTarget(const SensorSet::key_type& sensor, try { - targetSpeed = ioAccess.read( - targetName, - targetId, - entry, - hwmonio::retries, - hwmonio::delay); + targetSpeed = ioAccess.read(targetName, targetId, entry, + hwmonio::retries, hwmonio::delay); } catch (const std::system_error& e) { using namespace phosphor::logging; - using namespace sdbusplus::xyz::openbmc_project:: - Sensor::Device::Error; - using metadata = xyz::openbmc_project::Sensor:: - Device::ReadFailure; + using namespace sdbusplus::xyz::openbmc_project::Sensor:: + Device::Error; + using metadata = + xyz::openbmc_project::Sensor::Device::ReadFailure; report<ReadFailure>( - metadata::CALLOUT_ERRNO(e.code().value()), - metadata::CALLOUT_DEVICE_PATH(devPath.c_str())); + metadata::CALLOUT_ERRNO(e.code().value()), + metadata::CALLOUT_DEVICE_PATH(devPath.c_str())); - log<level::INFO>("Logging failing sysfs file", - phosphor::logging::entry( - "FILE=%s", sysfsFullPath.c_str())); + log<level::INFO>( + "Logging failing sysfs file", + phosphor::logging::entry("FILE=%s", sysfsFullPath.c_str())); } // ioAccess.path() is a path like: /sys/class/hwmon/hwmon1 target = std::make_shared<T>( - std::move(std::make_unique<hwmonio::HwmonIO>( - ioAccess.path())), - devPath, - targetId, - bus, - objPath.c_str(), - deferSignals, - targetSpeed); + std::move(std::make_unique<hwmonio::HwmonIO>(ioAccess.path())), + devPath, targetId, bus, objPath.c_str(), deferSignals, + targetSpeed); obj[type] = target; } } diff --git a/test/fanpwm_unittest.cpp b/test/fanpwm_unittest.cpp index 63520d3..11dcee9 100644 --- a/test/fanpwm_unittest.cpp +++ b/test/fanpwm_unittest.cpp @@ -1,12 +1,12 @@ #include "fan_pwm.hpp" - #include "hwmonio_mock.hpp" -#include <gmock/gmock.h> -#include <gtest/gtest.h> #include <sdbusplus/test/sdbus_mock.hpp> #include <string> +#include <gmock/gmock.h> +#include <gtest/gtest.h> + using ::testing::_; using ::testing::Invoke; using ::testing::IsNull; @@ -19,55 +19,38 @@ static auto FanPwmProp = "Target"; // Handle basic expectations we'll need for all these tests, if it's found that // this is helpful for more tests, it can be promoted in scope. -void SetupDbusObject( - sdbusplus::SdBusMock *sdbus_mock, - const std::string& path, - const std::string& intf, - const std::string property = "") +void SetupDbusObject(sdbusplus::SdBusMock *sdbus_mock, const std::string &path, + const std::string &intf, const std::string property = "") { EXPECT_CALL(*sdbus_mock, - sd_bus_add_object_vtable( - IsNull(), - NotNull(), - StrEq(path), - StrEq(intf), - NotNull(), - NotNull())) - .WillOnce(Return(0)); + sd_bus_add_object_vtable(IsNull(), NotNull(), StrEq(path), + StrEq(intf), NotNull(), NotNull())) + .WillOnce(Return(0)); if (property.empty()) { EXPECT_CALL(*sdbus_mock, - sd_bus_emit_properties_changed_strv( - IsNull(), - StrEq(path), - StrEq(intf), - NotNull())) - .WillOnce(Return(0)); + sd_bus_emit_properties_changed_strv(IsNull(), StrEq(path), + StrEq(intf), NotNull())) + .WillOnce(Return(0)); } else { EXPECT_CALL(*sdbus_mock, - sd_bus_emit_properties_changed_strv( - IsNull(), - StrEq(path), - StrEq(intf), - NotNull())) - .WillOnce( - Invoke([=](sd_bus *bus, - const char *path, - const char *interface, - char **names) { + sd_bus_emit_properties_changed_strv(IsNull(), StrEq(path), + StrEq(intf), NotNull())) + .WillOnce(Invoke([=](sd_bus *bus, const char *path, + const char *interface, char **names) { EXPECT_STREQ(property.c_str(), names[0]); return 0; - }) - ); + })); } return; } -TEST(FanPwmTest, BasicConstructorDeferredTest) { +TEST(FanPwmTest, BasicConstructorDeferredTest) +{ // Attempt to just instantiate one. // NOTE: This test's goal is to figure out what's minimally required to @@ -87,16 +70,12 @@ TEST(FanPwmTest, BasicConstructorDeferredTest) { SetupDbusObject(&sdbus_mock, objPath, FanPwmIntf, FanPwmProp); - hwmon::FanPwm f(std::move(hwmonio_mock), - devPath, - id, - bus_mock, - objPath.c_str(), - defer, - target); + hwmon::FanPwm f(std::move(hwmonio_mock), devPath, id, bus_mock, + objPath.c_str(), defer, target); } -TEST(FanPwmTest, BasicConstructorNotDeferredTest) { +TEST(FanPwmTest, BasicConstructorNotDeferredTest) +{ // Attempt to just instantiate one. // NOTE: This test's goal is to figure out what's minimally required to @@ -116,24 +95,18 @@ TEST(FanPwmTest, BasicConstructorNotDeferredTest) { SetupDbusObject(&sdbus_mock, objPath, FanPwmIntf, FanPwmProp); - EXPECT_CALL(sdbus_mock, - sd_bus_emit_object_added(IsNull(), StrEq("asdf"))) - .WillOnce(Return(0)); + EXPECT_CALL(sdbus_mock, sd_bus_emit_object_added(IsNull(), StrEq("asdf"))) + .WillOnce(Return(0)); - EXPECT_CALL(sdbus_mock, - sd_bus_emit_object_removed(IsNull(), StrEq("asdf"))) - .WillOnce(Return(0)); - - hwmon::FanPwm f(std::move(hwmonio_mock), - devPath, - id, - bus_mock, - objPath.c_str(), - defer, - target); + EXPECT_CALL(sdbus_mock, sd_bus_emit_object_removed(IsNull(), StrEq("asdf"))) + .WillOnce(Return(0)); + + hwmon::FanPwm f(std::move(hwmonio_mock), devPath, id, bus_mock, + objPath.c_str(), defer, target); } -TEST(FanPwmTest, WriteTargetValue) { +TEST(FanPwmTest, WriteTargetValue) +{ // Create a FanPwm and write a value to the object. sdbusplus::SdBusMock sdbus_mock; @@ -154,43 +127,29 @@ TEST(FanPwmTest, WriteTargetValue) { hwmonio::HwmonIOMock *hwmonio = reinterpret_cast<hwmonio::HwmonIOMock *>(hwmonio_mock.get()); - hwmon::FanPwm f(std::move(hwmonio_mock), - devPath, - id, - bus_mock, - objPath.c_str(), - defer, - target); + hwmon::FanPwm f(std::move(hwmonio_mock), devPath, id, bus_mock, + objPath.c_str(), defer, target); target = 0x64; - EXPECT_CALL(*hwmonio, write(static_cast<uint32_t>(target), - StrEq("pwm"), - StrEq("the_id"), - _, - hwmonio::retries, - hwmonio::delay)); + EXPECT_CALL(*hwmonio, + write(static_cast<uint32_t>(target), StrEq("pwm"), + StrEq("the_id"), _, hwmonio::retries, hwmonio::delay)); EXPECT_CALL(sdbus_mock, sd_bus_emit_properties_changed_strv( - IsNull(), - StrEq("asdf"), - StrEq(FanPwmIntf), - NotNull())) - .WillOnce( - Invoke([&](sd_bus *bus, - const char *path, - const char *interface, - char **names) { + IsNull(), StrEq("asdf"), StrEq(FanPwmIntf), NotNull())) + .WillOnce(Invoke([&](sd_bus *bus, const char *path, + const char *interface, char **names) { EXPECT_EQ(0, strncmp("Target", names[0], 6)); return 0; - }) - ); + })); EXPECT_EQ(target, f.target(target)); } -TEST(FanPwmTest, WriteTargetValueNoUpdate) { +TEST(FanPwmTest, WriteTargetValueNoUpdate) +{ // Create a FanPwm and write a value to the object that was the previous // value. @@ -209,13 +168,8 @@ TEST(FanPwmTest, WriteTargetValueNoUpdate) { SetupDbusObject(&sdbus_mock, objPath, FanPwmIntf, FanPwmProp); - hwmon::FanPwm f(std::move(hwmonio_mock), - devPath, - id, - bus_mock, - objPath.c_str(), - defer, - target); + hwmon::FanPwm f(std::move(hwmonio_mock), devPath, id, bus_mock, + objPath.c_str(), defer, target); EXPECT_EQ(target, f.target(target)); } diff --git a/test/hwmon_unittest.cpp b/test/hwmon_unittest.cpp index 035d098..1c538c7 100644 --- a/test/hwmon_unittest.cpp +++ b/test/hwmon_unittest.cpp @@ -3,10 +3,9 @@ #include <gmock/gmock.h> #include <gtest/gtest.h> -TEST(HwmonTest, InvalidType) { - - hwmon::Attributes attrs; - EXPECT_FALSE(hwmon::getAttributes("invalid", attrs)); +TEST(HwmonTest, InvalidType) +{ + hwmon::Attributes attrs; + EXPECT_FALSE(hwmon::getAttributes("invalid", attrs)); } - diff --git a/test/hwmonio_mock.hpp b/test/hwmonio_mock.hpp index 4ad944c..6caa67e 100644 --- a/test/hwmonio_mock.hpp +++ b/test/hwmonio_mock.hpp @@ -1,30 +1,26 @@ #pragma once -#include <gmock/gmock.h> - #include "hwmonio.hpp" -namespace hwmonio { +#include <gmock/gmock.h> + +namespace hwmonio +{ class HwmonIOMock : public HwmonIOInterface { - public: - virtual ~HwmonIOMock(){}; - - MOCK_CONST_METHOD5(read, int64_t(const std::string&, - const std::string&, - const std::string&, - size_t, - std::chrono::milliseconds)); - - MOCK_CONST_METHOD6(write, void(uint32_t, - const std::string&, - const std::string&, - const std::string&, - size_t, - std::chrono::milliseconds)); - - MOCK_CONST_METHOD0(path, std::string()); + public: + virtual ~HwmonIOMock(){}; + + MOCK_CONST_METHOD5(read, int64_t(const std::string&, const std::string&, + const std::string&, size_t, + std::chrono::milliseconds)); + + MOCK_CONST_METHOD6(write, void(uint32_t, const std::string&, + const std::string&, const std::string&, + size_t, std::chrono::milliseconds)); + + MOCK_CONST_METHOD0(path, std::string()); }; } // namespace hwmonio diff --git a/thresholds.hpp b/thresholds.hpp index 684e712..c483665 100644 --- a/thresholds.hpp +++ b/thresholds.hpp @@ -59,8 +59,7 @@ struct Thresholds<CriticalObject> template <typename T> void checkThresholds(std::experimental::any& iface, int64_t value) { - auto realIface = std::experimental::any_cast<std::shared_ptr<T>> - (iface); + auto realIface = std::experimental::any_cast<std::shared_ptr<T>>(iface); auto lo = (*realIface.*Thresholds<T>::getLo)(); auto hi = (*realIface.*Thresholds<T>::getHi)(); (*realIface.*Thresholds<T>::alarmLo)(value <= lo); @@ -80,10 +79,8 @@ void checkThresholds(std::experimental::any& iface, int64_t value) * @param[in] info - The sdbusplus server connection and interfaces. */ template <typename T> -auto addThreshold(const std::string& sensorType, - const std::string& sensorID, - int64_t value, - ObjectInfo& info) +auto addThreshold(const std::string& sensorType, const std::string& sensorID, + int64_t value, ObjectInfo& info) { static constexpr bool deferSignals = true; @@ -1,7 +1,9 @@ +#include "timer.hpp" + +#include <string.h> + #include <chrono> #include <system_error> -#include <string.h> -#include "timer.hpp" namespace phosphor { @@ -15,36 +17,32 @@ static std::chrono::microseconds getTime() return duration_cast<microseconds>(usec); } -Timer::Timer(sd_event* event, - std::function<void()> callback, - std::chrono::microseconds usec, - timer::Action action): +Timer::Timer(sd_event* event, std::function<void()> callback, + std::chrono::microseconds usec, timer::Action action) : event(event), - callback(callback), - duration(usec), - action(action) + callback(callback), duration(usec), action(action) { auto r = sd_event_add_time(event, &eventSource, - CLOCK_MONOTONIC, // Time base + CLOCK_MONOTONIC, // Time base (getTime() + usec).count(), // When to fire - 0, // Use default event accuracy + 0, // Use default event accuracy timeoutHandler, // Callback handler on timeout - this); // User data + this); // User data if (r < 0) { throw std::system_error(r, std::generic_category(), strerror(-r)); } } -int Timer::timeoutHandler(sd_event_source* eventSource, - uint64_t usec, void* userData) +int Timer::timeoutHandler(sd_event_source* eventSource, uint64_t usec, + void* userData) { auto timer = static_cast<Timer*>(userData); if (timer->getAction() == timer::ON) { auto r = sd_event_source_set_time( - eventSource, (getTime() + timer->getDuration()).count()); + eventSource, (getTime() + timer->getDuration()).count()); if (r < 0) { throw std::system_error(r, std::generic_category(), strerror(-r)); @@ -56,7 +54,7 @@ int Timer::timeoutHandler(sd_event_source* eventSource, } } - if(timer->callback) + if (timer->callback) { timer->callback(); } @@ -1,8 +1,9 @@ #pragma once +#include <systemd/sd-event.h> + #include <chrono> #include <functional> -#include <systemd/sd-event.h> namespace phosphor { @@ -17,7 +18,6 @@ enum Action ON = SD_EVENT_ON, ONESHOT = SD_EVENT_ONESHOT }; - } /** @class Timer @@ -32,76 +32,74 @@ enum Action */ class Timer { - public: - Timer() = delete; - Timer(const Timer&) = delete; - Timer& operator=(const Timer&) = delete; - Timer(Timer&&) = delete; - Timer& operator=(Timer&&) = delete; - - /** @brief Constructs timer object - * - * @param[in] events - sd_event pointer - * @param[in] callback - function callback for timer expiry - * @param[in] usec - timer duration, in micro seconds - * @param[in] action - controls the timer's lifetime - */ - Timer(sd_event* event, - std::function<void()> userCallback, - std::chrono::microseconds usec, - timer::Action action); - - ~Timer() - { - if (eventSource) - { - eventSource = sd_event_source_unref(eventSource); - } - } - - /** @brief Timer expiry handler - invokes callback - * - * @param[in] eventSource - Source of the event - * @param[in] usec - time in micro seconds - * @param[in] userData - User data pointer - * - */ - static int timeoutHandler(sd_event_source* eventSource, - uint64_t usec, void* userData); - - /** @brief Enables / disables the timer - * @param[in] action - controls the timer's lifetime - */ - int state(timer::Action action) - { - return sd_event_source_set_enabled(eventSource, action); - } - - timer::Action getAction() const + public: + Timer() = delete; + Timer(const Timer&) = delete; + Timer& operator=(const Timer&) = delete; + Timer(Timer&&) = delete; + Timer& operator=(Timer&&) = delete; + + /** @brief Constructs timer object + * + * @param[in] events - sd_event pointer + * @param[in] callback - function callback for timer expiry + * @param[in] usec - timer duration, in micro seconds + * @param[in] action - controls the timer's lifetime + */ + Timer(sd_event* event, std::function<void()> userCallback, + std::chrono::microseconds usec, timer::Action action); + + ~Timer() + { + if (eventSource) { - return action; + eventSource = sd_event_source_unref(eventSource); } - - std::chrono::microseconds getDuration() const - { - return duration; - } - - private: - /** @brief the sd_event structure */ - sd_event* event = nullptr; - - /** @brief Source of events */ - sd_event_source* eventSource = nullptr; - - /** @brief Optional function to call on timer expiration */ - std::function<void()> callback{}; - - /** @brief Duration of the timer */ - std::chrono::microseconds duration{}; - - /** @brief whether the timer is enabled/disabled/one-shot */ - timer::Action action = timer::OFF; + } + + /** @brief Timer expiry handler - invokes callback + * + * @param[in] eventSource - Source of the event + * @param[in] usec - time in micro seconds + * @param[in] userData - User data pointer + * + */ + static int timeoutHandler(sd_event_source* eventSource, uint64_t usec, + void* userData); + + /** @brief Enables / disables the timer + * @param[in] action - controls the timer's lifetime + */ + int state(timer::Action action) + { + return sd_event_source_set_enabled(eventSource, action); + } + + timer::Action getAction() const + { + return action; + } + + std::chrono::microseconds getDuration() const + { + return duration; + } + + private: + /** @brief the sd_event structure */ + sd_event* event = nullptr; + + /** @brief Source of events */ + sd_event_source* eventSource = nullptr; + + /** @brief Optional function to call on timer expiration */ + std::function<void()> callback{}; + + /** @brief Duration of the timer */ + std::chrono::microseconds duration{}; + + /** @brief whether the timer is enabled/disabled/one-shot */ + timer::Action action = timer::OFF; }; } // namespace hwmon diff --git a/tools/find_callout_path.cpp b/tools/find_callout_path.cpp index 97280fc..f72673c 100644 --- a/tools/find_callout_path.cpp +++ b/tools/find_callout_path.cpp @@ -13,15 +13,15 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -#include <iostream> #include "../sysfs.hpp" +#include <iostream> + int main(int argc, char* argv[]) { if (argc < 2) { - std::cerr << "Usage: " << argv[0] - << " HWMON_INST_PATH" << std::endl; + std::cerr << "Usage: " << argv[0] << " HWMON_INST_PATH" << std::endl; return 1; } diff --git a/tools/find_hwmon.cpp b/tools/find_hwmon.cpp index 1142ad1..f155541 100644 --- a/tools/find_hwmon.cpp +++ b/tools/find_hwmon.cpp @@ -13,15 +13,15 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -#include <iostream> #include "../sysfs.hpp" +#include <iostream> + int main(int argc, char* argv[]) { if (argc < 2) { - std::cerr << "Usage: " << argv[0] - << " DT_REL_BASE_PATH" << std::endl; + std::cerr << "Usage: " << argv[0] << " DT_REL_BASE_PATH" << std::endl; return 1; } @@ -1,8 +1,9 @@ #pragma once -#include <experimental/any> #include "interface.hpp" +#include <experimental/any> + using Object = std::map<InterfaceType, std::experimental::any>; using ObjectInfo = std::tuple<sdbusplus::bus::bus*, std::string, Object>; using RetryIO = std::tuple<size_t, std::chrono::milliseconds>; |