summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--.clang-format85
-rw-r--r--bmc_state_manager.cpp102
-rw-r--r--bmc_state_manager.hpp112
-rw-r--r--bmc_state_manager_main.cpp7
-rw-r--r--chassis_state_manager.cpp88
-rw-r--r--chassis_state_manager.hpp176
-rw-r--r--chassis_state_manager_main.cpp6
-rw-r--r--discover_system_state.cpp60
-rw-r--r--host_check_main.cpp48
-rw-r--r--host_state_manager.cpp145
-rw-r--r--host_state_manager.hpp431
-rw-r--r--host_state_manager_main.cpp5
-rw-r--r--settings.cpp16
-rw-r--r--settings.hpp65
14 files changed, 667 insertions, 679 deletions
diff --git a/.clang-format b/.clang-format
new file mode 100644
index 0000000..309a9d6
--- /dev/null
+++ b/.clang-format
@@ -0,0 +1,85 @@
+---
+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: false
+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 ]
+IndentCaseLabels: true
+IndentWidth: 4
+IndentWrappedFunctionNames: false
+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: false
+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/bmc_state_manager.cpp b/bmc_state_manager.cpp
index 3539a30..667e300 100644
--- a/bmc_state_manager.cpp
+++ b/bmc_state_manager.cpp
@@ -20,14 +20,12 @@ constexpr auto signalDone = "done";
constexpr auto activeState = "active";
/* Map a transition to it's systemd target */
-const std::map<server::BMC::Transition, const char*> SYSTEMD_TABLE =
-{
- {server::BMC::Transition::Reboot, "reboot.target"}
-};
+const std::map<server::BMC::Transition, const char*> SYSTEMD_TABLE = {
+ {server::BMC::Transition::Reboot, "reboot.target"}};
-constexpr auto SYSTEMD_SERVICE = "org.freedesktop.systemd1";
-constexpr auto SYSTEMD_OBJ_PATH = "/org/freedesktop/systemd1";
-constexpr auto SYSTEMD_INTERFACE = "org.freedesktop.systemd1.Manager";
+constexpr auto SYSTEMD_SERVICE = "org.freedesktop.systemd1";
+constexpr auto SYSTEMD_OBJ_PATH = "/org/freedesktop/systemd1";
+constexpr auto SYSTEMD_INTERFACE = "org.freedesktop.systemd1.Manager";
constexpr auto SYSTEMD_PRP_INTERFACE = "org.freedesktop.DBus.Properties";
void BMC::discoverInitialState()
@@ -35,17 +33,15 @@ void BMC::discoverInitialState()
sdbusplus::message::variant<std::string> currentState;
sdbusplus::message::object_path unitTargetPath;
- auto method = this->bus.new_method_call(SYSTEMD_SERVICE,
- SYSTEMD_OBJ_PATH,
- SYSTEMD_INTERFACE,
- "GetUnit");
+ auto method = this->bus.new_method_call(SYSTEMD_SERVICE, SYSTEMD_OBJ_PATH,
+ SYSTEMD_INTERFACE, "GetUnit");
method.append(obmcStandbyTarget);
auto result = this->bus.call(method);
- //Check that the bus call didn't result in an error
- if(result.is_method_error())
+ // Check that the bus call didn't result in an error
+ if (result.is_method_error())
{
log<level::ERR>("Error in bus call.");
return;
@@ -53,46 +49,41 @@ void BMC::discoverInitialState()
result.read(unitTargetPath);
- method = this->bus.new_method_call(SYSTEMD_SERVICE,
- static_cast<const std::string&>
- (unitTargetPath).c_str(),
- SYSTEMD_PRP_INTERFACE,
- "Get");
+ method = this->bus.new_method_call(
+ SYSTEMD_SERVICE,
+ static_cast<const std::string&>(unitTargetPath).c_str(),
+ SYSTEMD_PRP_INTERFACE, "Get");
method.append("org.freedesktop.systemd1.Unit", "ActiveState");
result = this->bus.call(method);
- //Check that the bus call didn't result in an error
- if(result.is_method_error())
+ // Check that the bus call didn't result in an error
+ if (result.is_method_error())
{
log<level::INFO>("Error in bus call.");
return;
}
- //Is obmc-standby.target active or inactive?
+ // Is obmc-standby.target active or inactive?
result.read(currentState);
- if(currentState == activeState)
+ if (currentState == activeState)
{
log<level::INFO>("Setting the BMCState field",
- entry("CURRENT_BMC_STATE=%s",
- "BMC_READY"));
+ entry("CURRENT_BMC_STATE=%s", "BMC_READY"));
this->currentBMCState(BMCState::Ready);
- //Unsubscribe so we stop processing all other signals
- method = this->bus.new_method_call(SYSTEMD_SERVICE,
- SYSTEMD_OBJ_PATH,
- SYSTEMD_INTERFACE,
- "Unsubscribe");
+ // Unsubscribe so we stop processing all other signals
+ method = this->bus.new_method_call(SYSTEMD_SERVICE, SYSTEMD_OBJ_PATH,
+ SYSTEMD_INTERFACE, "Unsubscribe");
this->bus.call(method);
this->stateSignal.release();
}
else
{
log<level::INFO>("Setting the BMCState field",
- entry("CURRENT_BMC_STATE=%s",
- "BMC_NOTREADY"));
+ entry("CURRENT_BMC_STATE=%s", "BMC_NOTREADY"));
this->currentBMCState(BMCState::NotReady);
}
@@ -101,10 +92,8 @@ void BMC::discoverInitialState()
void BMC::subscribeToSystemdSignals()
{
- auto method = this->bus.new_method_call(SYSTEMD_SERVICE,
- SYSTEMD_OBJ_PATH,
- SYSTEMD_INTERFACE,
- "Subscribe");
+ auto method = this->bus.new_method_call(SYSTEMD_SERVICE, SYSTEMD_OBJ_PATH,
+ SYSTEMD_INTERFACE, "Subscribe");
this->bus.call(method);
return;
@@ -112,16 +101,15 @@ void BMC::subscribeToSystemdSignals()
void BMC::executeTransition(const Transition tranReq)
{
- //Check to make sure it can be found
+ // Check to make sure it can be found
auto iter = SYSTEMD_TABLE.find(tranReq);
- if (iter == SYSTEMD_TABLE.end()) return;
+ if (iter == SYSTEMD_TABLE.end())
+ return;
const auto& sysdUnit = iter->second;
- auto method = this->bus.new_method_call(SYSTEMD_SERVICE,
- SYSTEMD_OBJ_PATH,
- SYSTEMD_INTERFACE,
- "StartUnit");
+ auto method = this->bus.new_method_call(SYSTEMD_SERVICE, SYSTEMD_OBJ_PATH,
+ SYSTEMD_INTERFACE, "StartUnit");
// The only valid transition is reboot and that
// needs to be irreversible once started
method.append(sysdUnit, "replace-irreversibly");
@@ -132,26 +120,24 @@ void BMC::executeTransition(const Transition tranReq)
int BMC::bmcStateChange(sdbusplus::message::message& msg)
{
- uint32_t newStateID {};
+ uint32_t newStateID{};
sdbusplus::message::object_path newStateObjPath;
std::string newStateUnit{};
std::string newStateResult{};
- //Read the msg and populate each variable
+ // Read the msg and populate each variable
msg.read(newStateID, newStateObjPath, newStateUnit, newStateResult);
- //Caught the signal that indicates the BMC is now BMC_READY
- if((newStateUnit == obmcStandbyTarget) &&
- (newStateResult == signalDone))
+ // Caught the signal that indicates the BMC is now BMC_READY
+ if ((newStateUnit == obmcStandbyTarget) && (newStateResult == signalDone))
{
log<level::INFO>("BMC_READY");
this->currentBMCState(BMCState::Ready);
- //Unsubscribe so we stop processing all other signals
- auto method = this->bus.new_method_call(SYSTEMD_SERVICE,
- SYSTEMD_OBJ_PATH,
- SYSTEMD_INTERFACE,
- "Unsubscribe");
+ // Unsubscribe so we stop processing all other signals
+ auto method =
+ this->bus.new_method_call(SYSTEMD_SERVICE, SYSTEMD_OBJ_PATH,
+ SYSTEMD_INTERFACE, "Unsubscribe");
this->bus.call(method);
this->stateSignal.release();
}
@@ -161,10 +147,9 @@ int BMC::bmcStateChange(sdbusplus::message::message& msg)
BMC::Transition BMC::requestedBMCTransition(Transition value)
{
- log<level::INFO>(
- "Setting the RequestedBMCTransition field",
- entry("REQUESTED_BMC_TRANSITION=0x%s",
- convertForMessage(value).c_str()));
+ log<level::INFO>("Setting the RequestedBMCTransition field",
+ entry("REQUESTED_BMC_TRANSITION=0x%s",
+ convertForMessage(value).c_str()));
executeTransition(value);
return server::BMC::requestedBMCTransition(value);
@@ -173,15 +158,12 @@ BMC::Transition BMC::requestedBMCTransition(Transition value)
BMC::BMCState BMC::currentBMCState(BMCState value)
{
log<level::INFO>(
- "Setting the BMCState field",
- entry("CURRENT_BMC_STATE=0x%s",
- convertForMessage(value).c_str()));
+ "Setting the BMCState field",
+ entry("CURRENT_BMC_STATE=0x%s", convertForMessage(value).c_str()));
return server::BMC::currentBMCState(value);
}
-
} // namespace manager
} // namespace state
} // namepsace phosphor
-
diff --git a/bmc_state_manager.hpp b/bmc_state_manager.hpp
index f6f7540..b060ccd 100644
--- a/bmc_state_manager.hpp
+++ b/bmc_state_manager.hpp
@@ -12,10 +12,9 @@ namespace manager
{
using BMCInherit = sdbusplus::server::object::object<
- sdbusplus::xyz::openbmc_project::State::server::BMC>;
+ sdbusplus::xyz::openbmc_project::State::server::BMC>;
namespace sdbusRule = sdbusplus::bus::match::rules;
-
/** @class BMC
* @brief OpenBMC BMC state management implementation.
* @details A concrete implementation for xyz.openbmc_project.State.BMC
@@ -23,71 +22,66 @@ namespace sdbusRule = sdbusplus::bus::match::rules;
*/
class BMC : public BMCInherit
{
- public:
- /** @brief Constructs BMC State Manager
- *
- * @param[in] bus - The Dbus bus object
- * @param[in] busName - The Dbus name to own
- * @param[in] objPath - The Dbus object path
- */
- BMC(sdbusplus::bus::bus& bus,
- const char* objPath) :
- BMCInherit(bus, objPath, true),
- bus(bus),
- stateSignal(
- std::make_unique<decltype(stateSignal)::element_type>(
- bus,
- sdbusRule::type::signal() +
- sdbusRule::member("JobRemoved") +
- sdbusRule::path("/org/freedesktop/systemd1") +
- sdbusRule::interface(
- "org.freedesktop.systemd1.Manager"),
- std::bind(std::mem_fn(&BMC::bmcStateChange),
- this, std::placeholders::_1)))
- {
- subscribeToSystemdSignals();
- discoverInitialState();
- this->emit_object_added();
- };
+ public:
+ /** @brief Constructs BMC State Manager
+ *
+ * @param[in] bus - The Dbus bus object
+ * @param[in] busName - The Dbus name to own
+ * @param[in] objPath - The Dbus object path
+ */
+ BMC(sdbusplus::bus::bus& bus, const char* objPath) :
+ BMCInherit(bus, objPath, true), bus(bus),
+ stateSignal(std::make_unique<decltype(stateSignal)::element_type>(
+ bus,
+ sdbusRule::type::signal() + sdbusRule::member("JobRemoved") +
+ sdbusRule::path("/org/freedesktop/systemd1") +
+ sdbusRule::interface("org.freedesktop.systemd1.Manager"),
+ std::bind(std::mem_fn(&BMC::bmcStateChange), this,
+ std::placeholders::_1)))
+ {
+ subscribeToSystemdSignals();
+ discoverInitialState();
+ this->emit_object_added();
+ };
- /** @brief Set value of BMCTransition **/
- Transition requestedBMCTransition(Transition value) override;
+ /** @brief Set value of BMCTransition **/
+ Transition requestedBMCTransition(Transition value) override;
- /** @brief Set value of CurrentBMCState **/
- BMCState currentBMCState(BMCState value) override;
+ /** @brief Set value of CurrentBMCState **/
+ BMCState currentBMCState(BMCState value) override;
- private:
- /**
- * @brief discover the state of the bmc
- **/
- void discoverInitialState();
+ private:
+ /**
+ * @brief discover the state of the bmc
+ **/
+ void discoverInitialState();
- /**
- * @brief subscribe to the systemd signals
- **/
- void subscribeToSystemdSignals();
+ /**
+ * @brief subscribe to the systemd signals
+ **/
+ void subscribeToSystemdSignals();
- /** @brief Execute the transition request
- *
- * @param[in] tranReq - Transition requested
- */
- void executeTransition(Transition tranReq);
+ /** @brief Execute the transition request
+ *
+ * @param[in] tranReq - Transition requested
+ */
+ void executeTransition(Transition tranReq);
- /** @brief Callback function on bmc state change
- *
- * Check if the state is relevant to the BMC and if so, update
- * corresponding BMC object's state
- *
- * @param[in] msg - Data associated with subscribed signal
- *
- */
- int bmcStateChange(sdbusplus::message::message& msg);
+ /** @brief Callback function on bmc state change
+ *
+ * Check if the state is relevant to the BMC and if so, update
+ * corresponding BMC object's state
+ *
+ * @param[in] msg - Data associated with subscribed signal
+ *
+ */
+ int bmcStateChange(sdbusplus::message::message& msg);
- /** @brief Persistent sdbusplus DBus bus connection. **/
- sdbusplus::bus::bus& bus;
+ /** @brief Persistent sdbusplus DBus bus connection. **/
+ sdbusplus::bus::bus& bus;
- /** @brief Used to subscribe to dbus system state changes **/
- std::unique_ptr<sdbusplus::bus::match_t> stateSignal;
+ /** @brief Used to subscribe to dbus system state changes **/
+ std::unique_ptr<sdbusplus::bus::match_t> stateSignal;
};
} // namespace manager
diff --git a/bmc_state_manager_main.cpp b/bmc_state_manager_main.cpp
index 196522e..d11d952 100644
--- a/bmc_state_manager_main.cpp
+++ b/bmc_state_manager_main.cpp
@@ -2,7 +2,6 @@
#include "config.h"
#include "bmc_state_manager.hpp"
-
int main(int argc, char**)
{
auto bus = sdbusplus::bus::new_default();
@@ -14,17 +13,15 @@ int main(int argc, char**)
// Add sdbusplus ObjectManager.
sdbusplus::server::manager::manager objManager(bus, objPathInst.c_str());
- phosphor::state::manager::BMC manager(bus,
- objPathInst.c_str());
+ phosphor::state::manager::BMC manager(bus, objPathInst.c_str());
bus.request_name(BMC_BUSNAME);
- while(true)
+ while (true)
{
bus.process_discard();
bus.wait();
}
exit(EXIT_SUCCESS);
-
}
diff --git a/chassis_state_manager.cpp b/chassis_state_manager.cpp
index 9c771bd..ece0b1c 100644
--- a/chassis_state_manager.cpp
+++ b/chassis_state_manager.cpp
@@ -15,22 +15,22 @@ namespace server = sdbusplus::xyz::openbmc_project::State::server;
using namespace phosphor::logging;
constexpr auto CHASSIS_STATE_POWEROFF_TGT = "obmc-chassis-poweroff@0.target";
-constexpr auto CHASSIS_STATE_HARD_POWEROFF_TGT = "obmc-chassis-hard-poweroff@0.target";
+constexpr auto CHASSIS_STATE_HARD_POWEROFF_TGT =
+ "obmc-chassis-hard-poweroff@0.target";
constexpr auto CHASSIS_STATE_POWERON_TGT = "obmc-chassis-poweron@0.target";
constexpr auto ACTIVE_STATE = "active";
constexpr auto ACTIVATING_STATE = "activating";
/* Map a transition to it's systemd target */
-const std::map<server::Chassis::Transition,std::string> SYSTEMD_TARGET_TABLE =
-{
+const std::map<server::Chassis::Transition, std::string> SYSTEMD_TARGET_TABLE =
+ {
// Use the hard off target to ensure we shutdown immediately
{server::Chassis::Transition::Off, CHASSIS_STATE_HARD_POWEROFF_TGT},
- {server::Chassis::Transition::On, CHASSIS_STATE_POWERON_TGT}
-};
+ {server::Chassis::Transition::On, CHASSIS_STATE_POWERON_TGT}};
-constexpr auto SYSTEMD_SERVICE = "org.freedesktop.systemd1";
-constexpr auto SYSTEMD_OBJ_PATH = "/org/freedesktop/systemd1";
+constexpr auto SYSTEMD_SERVICE = "org.freedesktop.systemd1";
+constexpr auto SYSTEMD_OBJ_PATH = "/org/freedesktop/systemd1";
constexpr auto SYSTEMD_INTERFACE = "org.freedesktop.systemd1.Manager";
constexpr auto SYSTEMD_PROPERTY_IFACE = "org.freedesktop.DBus.Properties";
@@ -38,10 +38,8 @@ constexpr auto SYSTEMD_INTERFACE_UNIT = "org.freedesktop.systemd1.Unit";
void Chassis::subscribeToSystemdSignals()
{
- auto method = this->bus.new_method_call(SYSTEMD_SERVICE,
- SYSTEMD_OBJ_PATH,
- SYSTEMD_INTERFACE,
- "Subscribe");
+ auto method = this->bus.new_method_call(SYSTEMD_SERVICE, SYSTEMD_OBJ_PATH,
+ SYSTEMD_INTERFACE, "Subscribe");
this->bus.call_noreply(method);
return;
@@ -53,16 +51,15 @@ void Chassis::subscribeToSystemdSignals()
void Chassis::determineInitialState()
{
sdbusplus::message::variant<int> pgood = -1;
- auto method = this->bus.new_method_call("org.openbmc.control.Power",
- "/org/openbmc/control/power0",
- "org.freedesktop.DBus.Properties",
- "Get");
+ auto method = this->bus.new_method_call(
+ "org.openbmc.control.Power", "/org/openbmc/control/power0",
+ "org.freedesktop.DBus.Properties", "Get");
method.append("org.openbmc.control.Power", "pgood");
auto reply = this->bus.call(method);
reply.read(pgood);
- if(pgood == 1)
+ if (pgood == 1)
{
log<level::INFO>("Initial Chassis State will be On",
entry("CHASSIS_CURRENT_POWER_STATE=%s",
@@ -86,10 +83,8 @@ void Chassis::executeTransition(Transition tranReq)
{
auto sysdTarget = SYSTEMD_TARGET_TABLE.find(tranReq)->second;
- auto method = this->bus.new_method_call(SYSTEMD_SERVICE,
- SYSTEMD_OBJ_PATH,
- SYSTEMD_INTERFACE,
- "StartUnit");
+ auto method = this->bus.new_method_call(SYSTEMD_SERVICE, SYSTEMD_OBJ_PATH,
+ SYSTEMD_INTERFACE, "StartUnit");
method.append(sysdTarget);
method.append("replace");
@@ -104,16 +99,14 @@ bool Chassis::stateActive(const std::string& target)
sdbusplus::message::variant<std::string> currentState;
sdbusplus::message::object_path unitTargetPath;
- auto method = this->bus.new_method_call(SYSTEMD_SERVICE,
- SYSTEMD_OBJ_PATH,
- SYSTEMD_INTERFACE,
- "GetUnit");
+ auto method = this->bus.new_method_call(SYSTEMD_SERVICE, SYSTEMD_OBJ_PATH,
+ SYSTEMD_INTERFACE, "GetUnit");
method.append(target);
auto result = this->bus.call(method);
- //Check that the bus call didn't result in an error
- if(result.is_method_error())
+ // Check that the bus call didn't result in an error
+ if (result.is_method_error())
{
log<level::ERR>("Error in bus call - could not resolve GetUnit for:",
entry(" %s", SYSTEMD_INTERFACE));
@@ -122,17 +115,16 @@ bool Chassis::stateActive(const std::string& target)
result.read(unitTargetPath);
- method = this->bus.new_method_call(SYSTEMD_SERVICE,
- static_cast<const std::string&>
- (unitTargetPath).c_str(),
- SYSTEMD_PROPERTY_IFACE,
- "Get");
+ method = this->bus.new_method_call(
+ SYSTEMD_SERVICE,
+ static_cast<const std::string&>(unitTargetPath).c_str(),
+ SYSTEMD_PROPERTY_IFACE, "Get");
method.append(SYSTEMD_INTERFACE_UNIT, "ActiveState");
result = this->bus.call(method);
- //Check that the bus call didn't result in an error
- if(result.is_method_error())
+ // Check that the bus call didn't result in an error
+ if (result.is_method_error())
{
log<level::ERR>("Error in bus call - could not resolve Get for:",
entry(" %s", SYSTEMD_PROPERTY_IFACE));
@@ -141,40 +133,38 @@ bool Chassis::stateActive(const std::string& target)
result.read(currentState);
- if(currentState != ACTIVE_STATE && currentState != ACTIVATING_STATE)
+ if (currentState != ACTIVE_STATE && currentState != ACTIVATING_STATE)
{
- //False - not active
+ // False - not active
return false;
}
- //True - active
+ // True - active
return true;
-
}
int Chassis::sysStateChange(sdbusplus::message::message& msg)
{
- uint32_t newStateID {};
+ uint32_t newStateID{};
sdbusplus::message::object_path newStateObjPath;
std::string newStateUnit{};
std::string newStateResult{};
- //Read the msg and populate each variable
+ // Read the msg and populate each variable
msg.read(newStateID, newStateObjPath, newStateUnit, newStateResult);
- if((newStateUnit == CHASSIS_STATE_POWEROFF_TGT) &&
- (newStateResult == "done") &&
- (!stateActive(CHASSIS_STATE_POWERON_TGT)))
+ if ((newStateUnit == CHASSIS_STATE_POWEROFF_TGT) &&
+ (newStateResult == "done") && (!stateActive(CHASSIS_STATE_POWERON_TGT)))
{
log<level::INFO>("Received signal that power OFF is complete");
this->currentPowerState(server::Chassis::PowerState::Off);
}
- else if((newStateUnit == CHASSIS_STATE_POWERON_TGT) &&
- (newStateResult == "done") &&
- (stateActive(CHASSIS_STATE_POWERON_TGT)))
- {
- log<level::INFO>("Received signal that power ON is complete");
- this->currentPowerState(server::Chassis::PowerState::On);
- }
+ else if ((newStateUnit == CHASSIS_STATE_POWERON_TGT) &&
+ (newStateResult == "done") &&
+ (stateActive(CHASSIS_STATE_POWERON_TGT)))
+ {
+ log<level::INFO>("Received signal that power ON is complete");
+ this->currentPowerState(server::Chassis::PowerState::On);
+ }
return 0;
}
diff --git a/chassis_state_manager.hpp b/chassis_state_manager.hpp
index 132e30e..54f0afd 100644
--- a/chassis_state_manager.hpp
+++ b/chassis_state_manager.hpp
@@ -12,7 +12,7 @@ namespace manager
{
using ChassisInherit = sdbusplus::server::object::object<
- sdbusplus::xyz::openbmc_project::State::server::Chassis>;
+ sdbusplus::xyz::openbmc_project::State::server::Chassis>;
namespace sdbusRule = sdbusplus::bus::match::rules;
/** @class Chassis
@@ -22,94 +22,92 @@ namespace sdbusRule = sdbusplus::bus::match::rules;
*/
class Chassis : public ChassisInherit
{
- public:
- /** @brief Constructs Chassis State Manager
- *
- * @note This constructor passes 'true' to the base class in order to
- * defer dbus object registration until we can run
- * determineInitialState() and set our properties
- *
- * @param[in] bus - The Dbus bus object
- * @param[in] instance - The instance of this object
- * @param[in] objPath - The Dbus object path
- */
- Chassis(sdbusplus::bus::bus& bus,
- const char* busName,
- const char* objPath) :
- ChassisInherit(bus, objPath, true),
- bus(bus),
- systemdSignals(bus,
- sdbusRule::type::signal() +
- sdbusRule::member("JobRemoved") +
- sdbusRule::path("/org/freedesktop/systemd1") +
- sdbusRule::interface(
- "org.freedesktop.systemd1.Manager"),
- std::bind(std::mem_fn(&Chassis::sysStateChange),
- this, std::placeholders::_1))
- {
- subscribeToSystemdSignals();
-
- determineInitialState();
-
- // We deferred this until we could get our property correct
- this->emit_object_added();
- }
-
- /** @brief Set value of RequestedPowerTransition */
- Transition requestedPowerTransition(Transition value) override;
-
- /** @brief Set value of CurrentPowerState */
- PowerState currentPowerState(PowerState value) override;
-
- private:
- /** @brief Determine initial chassis state and set internally */
- void determineInitialState();
-
- /**
- * @brief subscribe to the systemd signals
- *
- * This object needs to capture when it's systemd targets complete
- * so it can keep it's state updated
- *
- **/
- void subscribeToSystemdSignals();
-
- /** @brief Execute the transition request
- *
- * This function calls the appropriate systemd target for the input
- * transition.
- *
- * @param[in] tranReq - Transition requested
- */
- void executeTransition(Transition tranReq);
-
- /**
- * @brief Determine if target is active
- *
- * This function determines if the target is active and
- * helps prevent misleading log recorded states.
- *
- * @param[in] target - Target string to check on
- *
- * @return boolean corresponding to state active
- **/
- bool stateActive(const std::string& target);
-
- /** @brief Check if systemd state change is relevant to this object
- *
- * Instance specific interface to handle the detected systemd state
- * change
- *
- * @param[in] msg - Data associated with subscribed signal
- *
- */
- int sysStateChange(sdbusplus::message::message& msg);
-
- /** @brief Persistent sdbusplus DBus connection. */
- sdbusplus::bus::bus& bus;
-
- /** @brief Used to subscribe to dbus systemd signals **/
- sdbusplus::bus::match_t systemdSignals;
+ public:
+ /** @brief Constructs Chassis State Manager
+ *
+ * @note This constructor passes 'true' to the base class in order to
+ * defer dbus object registration until we can run
+ * determineInitialState() and set our properties
+ *
+ * @param[in] bus - The Dbus bus object
+ * @param[in] instance - The instance of this object
+ * @param[in] objPath - The Dbus object path
+ */
+ Chassis(sdbusplus::bus::bus& bus, const char* busName,
+ const char* objPath) :
+ ChassisInherit(bus, objPath, true),
+ bus(bus),
+ systemdSignals(
+ bus,
+ sdbusRule::type::signal() + sdbusRule::member("JobRemoved") +
+ sdbusRule::path("/org/freedesktop/systemd1") +
+ sdbusRule::interface("org.freedesktop.systemd1.Manager"),
+ std::bind(std::mem_fn(&Chassis::sysStateChange), this,
+ std::placeholders::_1))
+ {
+ subscribeToSystemdSignals();
+
+ determineInitialState();
+
+ // We deferred this until we could get our property correct
+ this->emit_object_added();
+ }
+
+ /** @brief Set value of RequestedPowerTransition */
+ Transition requestedPowerTransition(Transition value) override;
+
+ /** @brief Set value of CurrentPowerState */
+ PowerState currentPowerState(PowerState value) override;
+
+ private:
+ /** @brief Determine initial chassis state and set internally */
+ void determineInitialState();
+
+ /**
+ * @brief subscribe to the systemd signals
+ *
+ * This object needs to capture when it's systemd targets complete
+ * so it can keep it's state updated
+ *
+ **/
+ void subscribeToSystemdSignals();
+
+ /** @brief Execute the transition request
+ *
+ * This function calls the appropriate systemd target for the input
+ * transition.
+ *
+ * @param[in] tranReq - Transition requested
+ */
+ void executeTransition(Transition tranReq);
+
+ /**
+ * @brief Determine if target is active
+ *
+ * This function determines if the target is active and
+ * helps prevent misleading log recorded states.
+ *
+ * @param[in] target - Target string to check on
+ *
+ * @return boolean corresponding to state active
+ **/
+ bool stateActive(const std::string& target);
+
+ /** @brief Check if systemd state change is relevant to this object
+ *
+ * Instance specific interface to handle the detected systemd state
+ * change
+ *
+ * @param[in] msg - Data associated with subscribed signal
+ *
+ */
+ int sysStateChange(sdbusplus::message::message& msg);
+
+ /** @brief Persistent sdbusplus DBus connection. */
+ sdbusplus::bus::bus& bus;
+
+ /** @brief Used to subscribe to dbus systemd signals **/
+ sdbusplus::bus::match_t systemdSignals;
};
} // namespace manager
diff --git a/chassis_state_manager_main.cpp b/chassis_state_manager_main.cpp
index 27965e0..ce3a0d8 100644
--- a/chassis_state_manager_main.cpp
+++ b/chassis_state_manager_main.cpp
@@ -5,7 +5,6 @@
#include "config.h"
#include "chassis_state_manager.hpp"
-
int main(int argc, char *argv[])
{
auto bus = sdbusplus::bus::new_default();
@@ -16,13 +15,12 @@ int main(int argc, char *argv[])
// Add sdbusplus ObjectManager.
sdbusplus::server::manager::manager objManager(bus, objPathInst.c_str());
- phosphor::state::manager::Chassis manager(bus,
- CHASSIS_BUSNAME,
+ phosphor::state::manager::Chassis manager(bus, CHASSIS_BUSNAME,
objPathInst.c_str());
bus.request_name(CHASSIS_BUSNAME);
- while(true)
+ while (true)
{
bus.process_discard();
bus.wait();
diff --git a/discover_system_state.cpp b/discover_system_state.cpp
index d403671..2790c58 100644
--- a/discover_system_state.cpp
+++ b/discover_system_state.cpp
@@ -32,18 +32,15 @@ constexpr auto PROPERTY_INTERFACE = "org.freedesktop.DBus.Properties";
std::string getService(sdbusplus::bus::bus& bus, std::string path,
std::string interface)
{
- auto mapper = bus.new_method_call(MAPPER_BUSNAME,
- MAPPER_PATH,
- MAPPER_INTERFACE,
- "GetObject");
+ auto mapper = bus.new_method_call(MAPPER_BUSNAME, MAPPER_PATH,
+ MAPPER_INTERFACE, "GetObject");
mapper.append(path, std::vector<std::string>({interface}));
auto mapperResponseMsg = bus.call(mapper);
if (mapperResponseMsg.is_method_error())
{
- log<level::ERR>("Error in mapper call",
- entry("PATH=%s", path.c_str()),
+ log<level::ERR>("Error in mapper call", entry("PATH=%s", path.c_str()),
entry("INTERFACE=%s", interface.c_str()));
throw std::runtime_error("Error in mapper call");
}
@@ -67,10 +64,8 @@ std::string getProperty(sdbusplus::bus::bus& bus, std::string path,
sdbusplus::message::variant<std::string> property;
std::string service = getService(bus, path, interface);
- auto method = bus.new_method_call(service.c_str(),
- path.c_str(),
- PROPERTY_INTERFACE,
- "Get");
+ auto method = bus.new_method_call(service.c_str(), path.c_str(),
+ PROPERTY_INTERFACE, "Get");
method.append(interface, propertyName);
auto reply = bus.call(method);
@@ -100,10 +95,8 @@ void setProperty(sdbusplus::bus::bus& bus, std::string path,
sdbusplus::message::variant<std::string> variantValue = value;
std::string service = getService(bus, path, interface);
- auto method = bus.new_method_call(service.c_str(),
- path.c_str(),
- PROPERTY_INTERFACE,
- "Set");
+ auto method = bus.new_method_call(service.c_str(), path.c_str(),
+ PROPERTY_INTERFACE, "Set");
method.append(interface, property, variantValue);
bus.call_noreply(method);
@@ -123,19 +116,16 @@ int main(int argc, char** argv)
int arg;
int optIndex = 0;
- static struct option longOpts[] =
- {
- {"host", required_argument, 0, 'h'},
- {0, 0, 0, 0}
- };
+ static struct option longOpts[] = {{"host", required_argument, 0, 'h'},
+ {0, 0, 0, 0}};
- while((arg = getopt_long(argc, argv, "h:", longOpts, &optIndex)) != -1)
+ while ((arg = getopt_long(argc, argv, "h:", longOpts, &optIndex)) != -1)
{
switch (arg)
{
case 'h':
- hostPath = std::string("/xyz/openbmc_project/state/host") +
- optarg;
+ hostPath =
+ std::string("/xyz/openbmc_project/state/host") + optarg;
break;
default:
break;
@@ -152,13 +142,10 @@ int main(int argc, char** argv)
// This application is only run if chassis power is off
- auto method =
- bus.new_method_call(
- settings.service(settings.powerRestorePolicy,
- powerRestoreIntf).c_str(),
- settings.powerRestorePolicy.c_str(),
- "org.freedesktop.DBus.Properties",
- "Get");
+ auto method = bus.new_method_call(
+ settings.service(settings.powerRestorePolicy, powerRestoreIntf).c_str(),
+ settings.powerRestorePolicy.c_str(), "org.freedesktop.DBus.Properties",
+ "Get");
method.append(powerRestoreIntf, "PowerRestorePolicy");
auto reply = bus.call(method);
if (reply.is_method_error())
@@ -178,21 +165,18 @@ int main(int argc, char** argv)
RestorePolicy::convertPolicyFromString(powerPolicy))
{
log<level::INFO>("power_policy=ALWAYS_POWER_ON, powering host on");
- setProperty(bus, hostPath, HOST_BUSNAME,
- "RequestedHostTransition",
+ setProperty(bus, hostPath, HOST_BUSNAME, "RequestedHostTransition",
convertForMessage(server::Host::Transition::On));
}
- else if(RestorePolicy::Policy::Restore ==
- RestorePolicy::convertPolicyFromString(powerPolicy))
+ else if (RestorePolicy::Policy::Restore ==
+ RestorePolicy::convertPolicyFromString(powerPolicy))
{
log<level::INFO>("power_policy=RESTORE, restoring last state");
// Read last requested state and re-request it to execute it
- auto hostReqState = getProperty(bus, hostPath,
- HOST_BUSNAME,
- "RequestedHostTransition");
- setProperty(bus, hostPath, HOST_BUSNAME,
- "RequestedHostTransition",
+ auto hostReqState =
+ getProperty(bus, hostPath, HOST_BUSNAME, "RequestedHostTransition");
+ setProperty(bus, hostPath, HOST_BUSNAME, "RequestedHostTransition",
hostReqState);
}
diff --git a/host_check_main.cpp b/host_check_main.cpp
index eec4acc..54a182a 100644
--- a/host_check_main.cpp
+++ b/host_check_main.cpp
@@ -19,12 +19,11 @@ constexpr auto MAPPER_INTERFACE = "xyz.openbmc_project.ObjectMapper";
constexpr auto CONTROL_HOST_PATH = "/xyz/openbmc_project/control/host0";
constexpr auto CONTROL_HOST_INTERFACE = "xyz.openbmc_project.Control.Host";
-bool cmdDone = false;
+bool cmdDone = false;
bool hostRunning = false;
// Function called on host control signals
-static int hostControlSignal(sd_bus_message* msg,
- void* userData,
+static int hostControlSignal(sd_bus_message* msg, void* userData,
sd_bus_error* retError)
{
std::string cmdCompleted{};
@@ -34,15 +33,16 @@ static int hostControlSignal(sd_bus_message* msg,
sdPlusMsg.read(cmdCompleted, cmdStatus);
log<level::DEBUG>("Host control signal values",
- entry("COMMAND=%s",cmdCompleted.c_str()),
- entry("STATUS=%s",cmdStatus.c_str()));
+ entry("COMMAND=%s", cmdCompleted.c_str()),
+ entry("STATUS=%s", cmdStatus.c_str()));
// Verify it's the command this code is interested in and then check status
- if(Host::convertCommandFromString(cmdCompleted) == Host::Command::Heartbeat)
+ if (Host::convertCommandFromString(cmdCompleted) ==
+ Host::Command::Heartbeat)
{
cmdDone = true;
- if(Host::convertResultFromString(cmdStatus) == Host::Result::Success)
+ if (Host::convertResultFromString(cmdStatus) == Host::Result::Success)
{
hostRunning = true;
}
@@ -54,10 +54,8 @@ static int hostControlSignal(sd_bus_message* msg,
// Send hearbeat to host to determine if it's running
void sendHeartbeat(sdbusplus::bus::bus& bus)
{
- auto mapper = bus.new_method_call(MAPPER_BUSNAME,
- MAPPER_PATH,
- MAPPER_INTERFACE,
- "GetObject");
+ auto mapper = bus.new_method_call(MAPPER_BUSNAME, MAPPER_PATH,
+ MAPPER_INTERFACE, "GetObject");
mapper.append(CONTROL_HOST_PATH,
std::vector<std::string>({CONTROL_HOST_INTERFACE}));
@@ -81,10 +79,8 @@ void sendHeartbeat(sdbusplus::bus::bus& bus)
const auto& host = mapperResponse.begin()->first;
- auto method = bus.new_method_call(host.c_str(),
- CONTROL_HOST_PATH,
- CONTROL_HOST_INTERFACE,
- "Execute");
+ auto method = bus.new_method_call(host.c_str(), CONTROL_HOST_PATH,
+ CONTROL_HOST_INTERFACE, "Execute");
method.append(convertForMessage(Host::Command::Heartbeat).c_str());
auto reply = bus.call(method);
@@ -97,42 +93,40 @@ void sendHeartbeat(sdbusplus::bus::bus& bus)
return;
}
-int main(int argc, char *argv[])
+int main(int argc, char* argv[])
{
log<level::INFO>("Check if host is running");
auto bus = sdbusplus::bus::new_default();
auto s = "type='signal',member='CommandComplete',path='"s +
- CONTROL_HOST_PATH + "',interface='" +
- CONTROL_HOST_INTERFACE + "'";
+ CONTROL_HOST_PATH + "',interface='" + CONTROL_HOST_INTERFACE + "'";
// Setup Signal Handler
- sdbusplus::bus::match::match hostControlSignals(bus,
- s.c_str(),
- hostControlSignal,
- nullptr);
+ sdbusplus::bus::match::match hostControlSignals(bus, s.c_str(),
+ hostControlSignal, nullptr);
sendHeartbeat(bus);
// Wait for signal
- while(!cmdDone)
+ while (!cmdDone)
{
bus.process_discard();
- if (cmdDone) break;
+ if (cmdDone)
+ break;
bus.wait();
}
// If host running then create file
- if(hostRunning)
+ if (hostRunning)
{
log<level::INFO>("Host is running!");
// Create file for host instance and create in filesystem to indicate
// to services that host is running
- auto size = std::snprintf(nullptr,0,HOST_RUNNING_FILE,0);
+ auto size = std::snprintf(nullptr, 0, HOST_RUNNING_FILE, 0);
size++; // null
std::unique_ptr<char[]> buf(new char[size]);
- std::snprintf(buf.get(),size,HOST_RUNNING_FILE,0);
+ std::snprintf(buf.get(), size, HOST_RUNNING_FILE, 0);
std::ofstream outfile(buf.get());
outfile.close();
}
diff --git a/host_state_manager.cpp b/host_state_manager.cpp
index 884372d..1ddd150 100644
--- a/host_state_manager.cpp
+++ b/host_state_manager.cpp
@@ -48,15 +48,13 @@ constexpr auto ACTIVE_STATE = "active";
constexpr auto ACTIVATING_STATE = "activating";
/* Map a transition to it's systemd target */
-const std::map<server::Host::Transition,std::string> SYSTEMD_TARGET_TABLE =
-{
- {server::Host::Transition::Off, HOST_STATE_SOFT_POWEROFF_TGT},
- {server::Host::Transition::On, HOST_STATE_POWERON_TGT},
- {server::Host::Transition::Reboot, HOST_STATE_REBOOT_TGT}
-};
+const std::map<server::Host::Transition, std::string> SYSTEMD_TARGET_TABLE = {
+ {server::Host::Transition::Off, HOST_STATE_SOFT_POWEROFF_TGT},
+ {server::Host::Transition::On, HOST_STATE_POWERON_TGT},
+ {server::Host::Transition::Reboot, HOST_STATE_REBOOT_TGT}};
-constexpr auto SYSTEMD_SERVICE = "org.freedesktop.systemd1";
-constexpr auto SYSTEMD_OBJ_PATH = "/org/freedesktop/systemd1";
+constexpr auto SYSTEMD_SERVICE = "org.freedesktop.systemd1";
+constexpr auto SYSTEMD_OBJ_PATH = "/org/freedesktop/systemd1";
constexpr auto SYSTEMD_INTERFACE = "org.freedesktop.systemd1.Manager";
constexpr auto MAPPER_BUSNAME = "xyz.openbmc_project.ObjectMapper";
@@ -68,17 +66,14 @@ constexpr auto SYSTEMD_INTERFACE_UNIT = "org.freedesktop.systemd1.Unit";
/* Map a system state to the HostState */
const std::map<std::string, server::Host::HostState> SYS_HOST_STATE_TABLE = {
- {"HOST_BOOTING", server::Host::HostState::Running},
- {"HOST_POWERED_OFF", server::Host::HostState::Off},
- {"HOST_QUIESCED", server::Host::HostState::Quiesced}
-};
+ {"HOST_BOOTING", server::Host::HostState::Running},
+ {"HOST_POWERED_OFF", server::Host::HostState::Off},
+ {"HOST_QUIESCED", server::Host::HostState::Quiesced}};
void Host::subscribeToSystemdSignals()
{
- auto method = this->bus.new_method_call(SYSTEMD_SERVICE,
- SYSTEMD_OBJ_PATH,
- SYSTEMD_INTERFACE,
- "Subscribe");
+ auto method = this->bus.new_method_call(SYSTEMD_SERVICE, SYSTEMD_OBJ_PATH,
+ SYSTEMD_INTERFACE, "Subscribe");
this->bus.call_noreply(method);
return;
@@ -87,7 +82,7 @@ void Host::subscribeToSystemdSignals()
void Host::determineInitialState()
{
- if(stateActive(HOST_STATE_POWERON_TGT))
+ if (stateActive(HOST_STATE_POWERON_TGT))
{
log<level::INFO>("Initial Host State will be Running",
entry("CURRENT_HOST_STATE=%s",
@@ -106,7 +101,7 @@ void Host::determineInitialState()
if (!deserialize(HOST_STATE_PERSIST_PATH))
{
- //set to default value.
+ // set to default value.
server::Host::requestedHostTransition(Transition::Off);
}
@@ -117,10 +112,8 @@ void Host::executeTransition(Transition tranReq)
{
auto sysdUnit = SYSTEMD_TARGET_TABLE.find(tranReq)->second;
- auto method = this->bus.new_method_call(SYSTEMD_SERVICE,
- SYSTEMD_OBJ_PATH,
- SYSTEMD_INTERFACE,
- "StartUnit");
+ auto method = this->bus.new_method_call(SYSTEMD_SERVICE, SYSTEMD_OBJ_PATH,
+ SYSTEMD_INTERFACE, "StartUnit");
method.append(sysdUnit);
method.append("replace");
@@ -135,15 +128,13 @@ bool Host::stateActive(const std::string& target)
sdbusplus::message::variant<std::string> currentState;
sdbusplus::message::object_path unitTargetPath;
- auto method = this->bus.new_method_call(SYSTEMD_SERVICE,
- SYSTEMD_OBJ_PATH,
- SYSTEMD_INTERFACE,
- "GetUnit");
+ auto method = this->bus.new_method_call(SYSTEMD_SERVICE, SYSTEMD_OBJ_PATH,
+ SYSTEMD_INTERFACE, "GetUnit");
method.append(target);
auto result = this->bus.call(method);
- //Check that the bus call didn't result in an error
+ // Check that the bus call didn't result in an error
if (result.is_method_error())
{
log<level::ERR>("Error in bus call - could not resolve GetUnit for:",
@@ -153,16 +144,15 @@ bool Host::stateActive(const std::string& target)
result.read(unitTargetPath);
- method = this->bus.new_method_call(SYSTEMD_SERVICE,
- static_cast<const std::string&>
- (unitTargetPath).c_str(),
- SYSTEMD_PROPERTY_IFACE,
- "Get");
+ method = this->bus.new_method_call(
+ SYSTEMD_SERVICE,
+ static_cast<const std::string&>(unitTargetPath).c_str(),
+ SYSTEMD_PROPERTY_IFACE, "Get");
method.append(SYSTEMD_INTERFACE_UNIT, "ActiveState");
result = this->bus.call(method);
- //Check that the bus call didn't result in an error
+ // Check that the bus call didn't result in an error
if (result.is_method_error())
{
log<level::ERR>("Error in bus call - could not resolve Get for:",
@@ -174,10 +164,10 @@ bool Host::stateActive(const std::string& target)
if (currentState != ACTIVE_STATE && currentState != ACTIVATING_STATE)
{
- //False - not active
+ // False - not active
return false;
}
- //True - active
+ // True - active
return true;
}
@@ -185,12 +175,9 @@ bool Host::isAutoReboot()
{
using namespace settings;
- auto method =
- bus.new_method_call(
- settings.service(settings.autoReboot, autoRebootIntf).c_str(),
- settings.autoReboot.c_str(),
- "org.freedesktop.DBus.Properties",
- "Get");
+ auto method = bus.new_method_call(
+ settings.service(settings.autoReboot, autoRebootIntf).c_str(),
+ settings.autoReboot.c_str(), "org.freedesktop.DBus.Properties", "Get");
method.append(autoRebootIntf, "AutoReboot");
auto reply = bus.call(method);
if (reply.is_method_error())
@@ -212,7 +199,7 @@ bool Host::isAutoReboot()
log<level::INFO>("Auto reboot enabled, rebooting");
return true;
}
- else if(rebootCounterParam == 0)
+ else if (rebootCounterParam == 0)
{
// Reset reboot counter and go to quiesce state
log<level::INFO>("Auto reboot enabled. "
@@ -236,55 +223,52 @@ bool Host::isAutoReboot()
void Host::sysStateChange(sdbusplus::message::message& msg)
{
- uint32_t newStateID {};
+ uint32_t newStateID{};
sdbusplus::message::object_path newStateObjPath;
std::string newStateUnit{};
std::string newStateResult{};
- //Read the msg and populate each variable
+ // Read the msg and populate each variable
msg.read(newStateID, newStateObjPath, newStateUnit, newStateResult);
- if((newStateUnit == HOST_STATE_POWEROFF_TGT) &&
- (newStateResult == "done") &&
- (!stateActive(HOST_STATE_POWERON_TGT)))
+ if ((newStateUnit == HOST_STATE_POWEROFF_TGT) &&
+ (newStateResult == "done") && (!stateActive(HOST_STATE_POWERON_TGT)))
{
log<level::INFO>("Received signal that host is off");
this->currentHostState(server::Host::HostState::Off);
this->bootProgress(bootprogress::Progress::ProgressStages::Unspecified);
this->operatingSystemState(osstatus::Status::OSStatus::Inactive);
-
}
- else if((newStateUnit == HOST_STATE_POWERON_TGT) &&
- (newStateResult == "done") &&
- (stateActive(HOST_STATE_POWERON_TGT)))
- {
- log<level::INFO>("Received signal that host is running");
- this->currentHostState(server::Host::HostState::Running);
- }
- else if((newStateUnit == HOST_STATE_QUIESCE_TGT) &&
+ else if ((newStateUnit == HOST_STATE_POWERON_TGT) &&
+ (newStateResult == "done") &&
+ (stateActive(HOST_STATE_POWERON_TGT)))
+ {
+ log<level::INFO>("Received signal that host is running");
+ this->currentHostState(server::Host::HostState::Running);
+ }
+ else if ((newStateUnit == HOST_STATE_QUIESCE_TGT) &&
(newStateResult == "done") &&
(stateActive(HOST_STATE_QUIESCE_TGT)))
- {
- if (Host::isAutoReboot())
- {
- log<level::INFO>("Beginning reboot...");
- Host::requestedHostTransition(server::Host::Transition::Reboot);
- }
- else
- {
- log<level::INFO>("Maintaining quiesce");
- this->currentHostState(server::Host::HostState::Quiesced);
- }
-
- }
+ {
+ if (Host::isAutoReboot())
+ {
+ log<level::INFO>("Beginning reboot...");
+ Host::requestedHostTransition(server::Host::Transition::Reboot);
+ }
+ else
+ {
+ log<level::INFO>("Maintaining quiesce");
+ this->currentHostState(server::Host::HostState::Quiesced);
+ }
+ }
}
uint32_t Host::decrementRebootCount()
{
auto rebootCount = reboot::RebootAttempts::attemptsLeft();
- if(rebootCount > 0)
+ if (rebootCount > 0)
{
- return(reboot::RebootAttempts::attemptsLeft(rebootCount - 1));
+ return (reboot::RebootAttempts::attemptsLeft(rebootCount - 1));
}
return rebootCount;
}
@@ -310,7 +294,7 @@ bool Host::deserialize(const fs::path& path)
}
return false;
}
- catch(cereal::Exception& e)
+ catch (cereal::Exception& e)
{
log<level::ERR>(e.what());
fs::remove(path);
@@ -320,24 +304,23 @@ bool Host::deserialize(const fs::path& path)
Host::Transition Host::requestedHostTransition(Transition value)
{
- log<level::INFO>(
- "Host State transaction request",
- entry("REQUESTED_HOST_TRANSITION=%s",
- convertForMessage(value).c_str()));
+ log<level::INFO>("Host State transaction request",
+ entry("REQUESTED_HOST_TRANSITION=%s",
+ convertForMessage(value).c_str()));
// If this is not a power off request then we need to
// decrement the reboot counter. This code should
// never prevent a power on, it should just decrement
// the count to 0. The quiesce handling is where the
// check of this count will occur
- if(value != server::Host::Transition::Off)
+ if (value != server::Host::Transition::Off)
{
decrementRebootCount();
}
executeTransition(value);
- auto retVal = server::Host::requestedHostTransition(value);
+ auto retVal = server::Host::requestedHostTransition(value);
serialize();
return retVal;
}
@@ -358,9 +341,9 @@ Host::OSStatus Host::operatingSystemState(OSStatus value)
Host::HostState Host::currentHostState(HostState value)
{
- log<level::INFO>("Change to Host State",
- entry("CURRENT_HOST_STATE=%s",
- convertForMessage(value).c_str()));
+ log<level::INFO>(
+ "Change to Host State",
+ entry("CURRENT_HOST_STATE=%s", convertForMessage(value).c_str()));
return server::Host::currentHostState(value);
}
diff --git a/host_state_manager.hpp b/host_state_manager.hpp
index 6b5e97e..2b00777 100644
--- a/host_state_manager.hpp
+++ b/host_state_manager.hpp
@@ -22,10 +22,10 @@ namespace manager
{
using HostInherit = sdbusplus::server::object::object<
- sdbusplus::xyz::openbmc_project::State::server::Host,
- sdbusplus::xyz::openbmc_project::State::Boot::server::Progress,
- sdbusplus::xyz::openbmc_project::Control::Boot::server::RebootAttempts,
- sdbusplus::xyz::openbmc_project::State::OperatingSystem::server::Status>;
+ sdbusplus::xyz::openbmc_project::State::server::Host,
+ sdbusplus::xyz::openbmc_project::State::Boot::server::Progress,
+ sdbusplus::xyz::openbmc_project::Control::Boot::server::RebootAttempts,
+ sdbusplus::xyz::openbmc_project::State::OperatingSystem::server::Status>;
using namespace phosphor::logging;
@@ -39,223 +39,214 @@ namespace fs = std::experimental::filesystem;
*/
class Host : public HostInherit
{
- public:
- /** @brief Constructs Host State Manager
- *
- * @note This constructor passes 'true' to the base class in order to
- * defer dbus object registration until we can run
- * determineInitialState() and set our properties
- *
- * @param[in] bus - The Dbus bus object
- * @param[in] busName - The Dbus name to own
- * @param[in] objPath - The Dbus object path
- */
- Host(sdbusplus::bus::bus& bus,
- const char* busName,
- const char* objPath) :
- HostInherit(bus, objPath, true),
- bus(bus),
- systemdSignals(
- bus,
- sdbusRule::type::signal() +
- sdbusRule::member("JobRemoved") +
- sdbusRule::path("/org/freedesktop/systemd1") +
- sdbusRule::interface(
- "org.freedesktop.systemd1.Manager"),
- std::bind(std::mem_fn(&Host::sysStateChange),
- this, std::placeholders::_1)),
- settings(bus)
- {
- // Enable systemd signals
- subscribeToSystemdSignals();
-
- // Will throw exception on fail
- determineInitialState();
-
- attemptsLeft(BOOT_COUNT_MAX_ALLOWED);
-
- // We deferred this until we could get our property correct
- this->emit_object_added();
- }
-
- /** @brief Set value of HostTransition */
- Transition requestedHostTransition(Transition value) override;
-
- /** @brief Set Value for boot progress */
- ProgressStages bootProgress(ProgressStages value) override;
-
- /** @brief Set Value for Operating System Status */
- OSStatus operatingSystemState(OSStatus value) override;
-
- /** @brief Set value of CurrentHostState */
- HostState currentHostState(HostState value) override;
-
- /**
- * @brief Set host reboot count to default
- *
- * OpenBMC software controls the number of allowed reboot attempts so
- * any external set request of this property will be overridden by
- * this function and set to the default.
- *
- * The only code responsible for decrementing the boot count resides
- * within this process and that will use the sub class interface
- * directly
- *
- * @param[in] value - Reboot count value, will be ignored
- *
- * @return Default number of reboot attempts left
- */
- uint32_t attemptsLeft(uint32_t value) override
- {
- log<level::DEBUG>("External request to reset reboot count");
- return (sdbusplus::xyz::openbmc_project::Control::Boot::server::
+ public:
+ /** @brief Constructs Host State Manager
+ *
+ * @note This constructor passes 'true' to the base class in order to
+ * defer dbus object registration until we can run
+ * determineInitialState() and set our properties
+ *
+ * @param[in] bus - The Dbus bus object
+ * @param[in] busName - The Dbus name to own
+ * @param[in] objPath - The Dbus object path
+ */
+ Host(sdbusplus::bus::bus& bus, const char* busName, const char* objPath) :
+ HostInherit(bus, objPath, true), bus(bus),
+ systemdSignals(
+ bus,
+ sdbusRule::type::signal() + sdbusRule::member("JobRemoved") +
+ sdbusRule::path("/org/freedesktop/systemd1") +
+ sdbusRule::interface("org.freedesktop.systemd1.Manager"),
+ std::bind(std::mem_fn(&Host::sysStateChange), this,
+ std::placeholders::_1)),
+ settings(bus)
+ {
+ // Enable systemd signals
+ subscribeToSystemdSignals();
+
+ // Will throw exception on fail
+ determineInitialState();
+
+ attemptsLeft(BOOT_COUNT_MAX_ALLOWED);
+
+ // We deferred this until we could get our property correct
+ this->emit_object_added();
+ }
+
+ /** @brief Set value of HostTransition */
+ Transition requestedHostTransition(Transition value) override;
+
+ /** @brief Set Value for boot progress */
+ ProgressStages bootProgress(ProgressStages value) override;
+
+ /** @brief Set Value for Operating System Status */
+ OSStatus operatingSystemState(OSStatus value) override;
+
+ /** @brief Set value of CurrentHostState */
+ HostState currentHostState(HostState value) override;
+
+ /**
+ * @brief Set host reboot count to default
+ *
+ * OpenBMC software controls the number of allowed reboot attempts so
+ * any external set request of this property will be overridden by
+ * this function and set to the default.
+ *
+ * The only code responsible for decrementing the boot count resides
+ * within this process and that will use the sub class interface
+ * directly
+ *
+ * @param[in] value - Reboot count value, will be ignored
+ *
+ * @return Default number of reboot attempts left
+ */
+ uint32_t attemptsLeft(uint32_t value) override
+ {
+ log<level::DEBUG>("External request to reset reboot count");
+ return (sdbusplus::xyz::openbmc_project::Control::Boot::server::
RebootAttempts::attemptsLeft(BOOT_COUNT_MAX_ALLOWED));
- }
-
- private:
- /**
- * @brief subscribe to the systemd signals
- *
- * This object needs to capture when it's systemd targets complete
- * so it can keep it's state updated
- *
- **/
- void subscribeToSystemdSignals();
-
- /**
- * @brief Determine initial host state and set internally
- *
- * @return Will throw exceptions on failure
- **/
- void determineInitialState();
-
- /** @brief Execute the transition request
- *
- * This function assumes the state has been validated and the host
- * is in an appropriate state for the transition to be started.
- *
- * @param[in] tranReq - Transition requested
- */
- void executeTransition(Transition tranReq);
-
- /**
- * @brief Determine if target is active
- *
- * This function determines if the target is active and
- * helps prevent misleading log recorded states.
- *
- * @param[in] target - Target string to check on
- *
- * @return boolean corresponding to state active
- **/
- bool stateActive(const std::string& target);
-
- /**
- * @brief Determine if auto reboot flag is set
- *
- * @return boolean corresponding to current auto_reboot setting
- **/
- bool isAutoReboot();
-
- /** @brief Check if systemd state change is relevant to this object
- *
- * Instance specific interface to handle the detected systemd state
- * change
- *
- * @param[in] msg - Data associated with subscribed signal
- *
- */
- void sysStateChange(sdbusplus::message::message& msg);
-
- /** @brief Decrement reboot count
- *
- * This is used internally to this application to decrement the boot
- * count on each boot attempt. The host will use the external
- * attemptsLeft() interface to reset the count when a boot is successful
- *
- * @return number of reboot count attempts left
- */
- uint32_t decrementRebootCount();
-
- // Allow cereal class access to allow these next two function to be
- // private
- friend class cereal::access;
-
- /** @brief Function required by Cereal to perform serialization.
- *
- * @tparam Archive - Cereal archive type (binary in our case).
- * @param[in] archive - reference to Cereal archive.
- * @param[in] version - Class version that enables handling
- * a serialized data across code levels
- */
- template<class Archive>
- void save(Archive& archive, const std::uint32_t version) const
- {
- archive(convertForMessage(sdbusplus::xyz::openbmc_project::
- State::server::Host::
- requestedHostTransition()),
- convertForMessage(sdbusplus::xyz::openbmc_project::
- State::Boot::server::Progress::
- bootProgress()),
- convertForMessage(sdbusplus::xyz::openbmc_project::
- State::OperatingSystem::server::Status::
- operatingSystemState()));
- }
-
- /** @brief Function required by Cereal to perform deserialization.
- *
- * @tparam Archive - Cereal archive type (binary in our case).
- * @param[in] archive - reference to Cereal archive.
- * @param[in] version - Class version that enables handling
- * a serialized data across code levels
- */
- template<class Archive>
- void load(Archive& archive, const std::uint32_t version)
- {
- std::string reqTranState;
- std::string bootProgress;
- std::string osState;
- archive(reqTranState, bootProgress, osState);
- auto reqTran = Host::convertTransitionFromString(reqTranState);
- // When restoring, set the requested state with persistent value
- // but don't call the override which would execute it
- sdbusplus::xyz::openbmc_project::State::server::Host::
- requestedHostTransition(reqTran);
- sdbusplus::xyz::openbmc_project::State::Boot::server::Progress::
- bootProgress(
- Host::convertProgressStagesFromString(bootProgress));
- sdbusplus::xyz::openbmc_project::State::OperatingSystem::server::
- Status::operatingSystemState(
- Host::convertOSStatusFromString(osState));
- }
-
- /** @brief Serialize and persist requested host state
- *
- * @param[in] dir - pathname of file where the serialized host state will
- * be placed.
- *
- * @return fs::path - pathname of persisted requested host state.
- */
- fs::path serialize(const fs::path& dir =
- fs::path(HOST_STATE_PERSIST_PATH));
-
- /** @brief Deserialze a persisted requested host state.
- *
- * @param[in] path - pathname of persisted host state file
- *
- * @return bool - true if the deserialization was successful, false
- * otherwise.
- */
- bool deserialize(const fs::path& path);
-
- /** @brief Persistent sdbusplus DBus bus connection. */
- sdbusplus::bus::bus& bus;
-
- /** @brief Used to subscribe to dbus systemd signals **/
- sdbusplus::bus::match_t systemdSignals;
-
- // Settings objects of interest
- settings::Objects settings;
+ }
+
+ private:
+ /**
+ * @brief subscribe to the systemd signals
+ *
+ * This object needs to capture when it's systemd targets complete
+ * so it can keep it's state updated
+ *
+ **/
+ void subscribeToSystemdSignals();
+
+ /**
+ * @brief Determine initial host state and set internally
+ *
+ * @return Will throw exceptions on failure
+ **/
+ void determineInitialState();
+
+ /** @brief Execute the transition request
+ *
+ * This function assumes the state has been validated and the host
+ * is in an appropriate state for the transition to be started.
+ *
+ * @param[in] tranReq - Transition requested
+ */
+ void executeTransition(Transition tranReq);
+
+ /**
+ * @brief Determine if target is active
+ *
+ * This function determines if the target is active and
+ * helps prevent misleading log recorded states.
+ *
+ * @param[in] target - Target string to check on
+ *
+ * @return boolean corresponding to state active
+ **/
+ bool stateActive(const std::string& target);
+
+ /**
+ * @brief Determine if auto reboot flag is set
+ *
+ * @return boolean corresponding to current auto_reboot setting
+ **/
+ bool isAutoReboot();
+
+ /** @brief Check if systemd state change is relevant to this object
+ *
+ * Instance specific interface to handle the detected systemd state
+ * change
+ *
+ * @param[in] msg - Data associated with subscribed signal
+ *
+ */
+ void sysStateChange(sdbusplus::message::message& msg);
+
+ /** @brief Decrement reboot count
+ *
+ * This is used internally to this application to decrement the boot
+ * count on each boot attempt. The host will use the external
+ * attemptsLeft() interface to reset the count when a boot is successful
+ *
+ * @return number of reboot count attempts left
+ */
+ uint32_t decrementRebootCount();
+
+ // Allow cereal class access to allow these next two function to be
+ // private
+ friend class cereal::access;
+
+ /** @brief Function required by Cereal to perform serialization.
+ *
+ * @tparam Archive - Cereal archive type (binary in our case).
+ * @param[in] archive - reference to Cereal archive.
+ * @param[in] version - Class version that enables handling
+ * a serialized data across code levels
+ */
+ template <class Archive>
+ void save(Archive& archive, const std::uint32_t version) const
+ {
+ archive(convertForMessage(sdbusplus::xyz::openbmc_project::State::
+ server::Host::requestedHostTransition()),
+ convertForMessage(sdbusplus::xyz::openbmc_project::State::Boot::
+ server::Progress::bootProgress()),
+ convertForMessage(
+ sdbusplus::xyz::openbmc_project::State::OperatingSystem::
+ server::Status::operatingSystemState()));
+ }
+
+ /** @brief Function required by Cereal to perform deserialization.
+ *
+ * @tparam Archive - Cereal archive type (binary in our case).
+ * @param[in] archive - reference to Cereal archive.
+ * @param[in] version - Class version that enables handling
+ * a serialized data across code levels
+ */
+ template <class Archive>
+ void load(Archive& archive, const std::uint32_t version)
+ {
+ std::string reqTranState;
+ std::string bootProgress;
+ std::string osState;
+ archive(reqTranState, bootProgress, osState);
+ auto reqTran = Host::convertTransitionFromString(reqTranState);
+ // When restoring, set the requested state with persistent value
+ // but don't call the override which would execute it
+ sdbusplus::xyz::openbmc_project::State::server::Host::
+ requestedHostTransition(reqTran);
+ sdbusplus::xyz::openbmc_project::State::Boot::server::Progress::
+ bootProgress(Host::convertProgressStagesFromString(bootProgress));
+ sdbusplus::xyz::openbmc_project::State::OperatingSystem::server::
+ Status::operatingSystemState(
+ Host::convertOSStatusFromString(osState));
+ }
+
+ /** @brief Serialize and persist requested host state
+ *
+ * @param[in] dir - pathname of file where the serialized host state will
+ * be placed.
+ *
+ * @return fs::path - pathname of persisted requested host state.
+ */
+ fs::path serialize(const fs::path& dir = fs::path(HOST_STATE_PERSIST_PATH));
+
+ /** @brief Deserialze a persisted requested host state.
+ *
+ * @param[in] path - pathname of persisted host state file
+ *
+ * @return bool - true if the deserialization was successful, false
+ * otherwise.
+ */
+ bool deserialize(const fs::path& path);
+
+ /** @brief Persistent sdbusplus DBus bus connection. */
+ sdbusplus::bus::bus& bus;
+
+ /** @brief Used to subscribe to dbus systemd signals **/
+ sdbusplus::bus::match_t systemdSignals;
+
+ // Settings objects of interest
+ settings::Objects settings;
};
} // namespace manager
diff --git a/host_state_manager_main.cpp b/host_state_manager_main.cpp
index 12d5e9a..4844a02 100644
--- a/host_state_manager_main.cpp
+++ b/host_state_manager_main.cpp
@@ -18,8 +18,7 @@ int main(int argc, char *argv[])
// Add sdbusplus ObjectManager.
sdbusplus::server::manager::manager objManager(bus, objPathInst.c_str());
- phosphor::state::manager::Host manager(bus,
- HOST_BUSNAME,
+ phosphor::state::manager::Host manager(bus, HOST_BUSNAME,
objPathInst.c_str());
auto dir = fs::path(HOST_STATE_PERSIST_PATH).parent_path();
@@ -27,7 +26,7 @@ int main(int argc, char *argv[])
bus.request_name(HOST_BUSNAME);
- while(true)
+ while (true)
{
bus.process_discard();
bus.wait();
diff --git a/settings.cpp b/settings.cpp
index 98254dd..e0600dc 100644
--- a/settings.cpp
+++ b/settings.cpp
@@ -13,16 +13,12 @@ constexpr auto mapperService = "xyz.openbmc_project.ObjectMapper";
constexpr auto mapperPath = "/xyz/openbmc_project/object_mapper";
constexpr auto mapperIntf = "xyz.openbmc_project.ObjectMapper";
-Objects::Objects(sdbusplus::bus::bus& bus):
- bus(bus)
+Objects::Objects(sdbusplus::bus::bus& bus) : bus(bus)
{
- std::vector<std::string> settingsIntfs =
- {autoRebootIntf, powerRestoreIntf};
+ std::vector<std::string> settingsIntfs = {autoRebootIntf, powerRestoreIntf};
auto depth = 0;
- auto mapperCall = bus.new_method_call(mapperService,
- mapperPath,
- mapperIntf,
+ auto mapperCall = bus.new_method_call(mapperService, mapperPath, mapperIntf,
"GetSubTree");
mapperCall.append(root);
mapperCall.append(depth);
@@ -63,10 +59,8 @@ Objects::Objects(sdbusplus::bus::bus& bus):
Service Objects::service(const Path& path, const Interface& interface) const
{
using Interfaces = std::vector<Interface>;
- auto mapperCall = bus.new_method_call(mapperService,
- mapperPath,
- mapperIntf,
- "GetObject");
+ auto mapperCall =
+ bus.new_method_call(mapperService, mapperPath, mapperIntf, "GetObject");
mapperCall.append(path);
mapperCall.append(Interfaces({interface}));
diff --git a/settings.hpp b/settings.hpp
index 088628a..a1a9a6e 100644
--- a/settings.hpp
+++ b/settings.hpp
@@ -11,8 +11,7 @@ using Service = std::string;
using Interface = std::string;
constexpr auto root = "/";
-constexpr auto autoRebootIntf =
- "xyz.openbmc_project.Control.Boot.RebootPolicy";
+constexpr auto autoRebootIntf = "xyz.openbmc_project.Control.Boot.RebootPolicy";
constexpr auto powerRestoreIntf =
"xyz.openbmc_project.Control.Power.RestorePolicy";
@@ -21,37 +20,37 @@ constexpr auto powerRestoreIntf =
*/
struct Objects
{
- public:
- /** @brief Constructor - fetch settings objects
- *
- * @param[in] bus - The Dbus bus object
- */
- Objects(sdbusplus::bus::bus& bus);
- Objects(const Objects&) = delete;
- Objects& operator=(const Objects&) = delete;
- Objects(Objects&&) = delete;
- Objects& operator=(Objects&&) = delete;
- ~Objects() = default;
-
- /** @brief Fetch d-bus service, given a path and an interface. The
- * service can't be cached because mapper returns unique
- * service names.
- *
- * @param[in] path - The Dbus object
- * @param[in] interface - The Dbus interface
- *
- * @return std::string - the dbus service name
- */
- Service service(const Path& path, const Interface& interface) const;
-
- /** @brief host auto_reboot settings object */
- Path autoReboot;
-
- /** @brief host power_restore_policy settings object */
- Path powerRestorePolicy;
-
- /** @brief The Dbus bus object */
- sdbusplus::bus::bus& bus;
+ public:
+ /** @brief Constructor - fetch settings objects
+ *
+ * @param[in] bus - The Dbus bus object
+ */
+ Objects(sdbusplus::bus::bus& bus);
+ Objects(const Objects&) = delete;
+ Objects& operator=(const Objects&) = delete;
+ Objects(Objects&&) = delete;
+ Objects& operator=(Objects&&) = delete;
+ ~Objects() = default;
+
+ /** @brief Fetch d-bus service, given a path and an interface. The
+ * service can't be cached because mapper returns unique
+ * service names.
+ *
+ * @param[in] path - The Dbus object
+ * @param[in] interface - The Dbus interface
+ *
+ * @return std::string - the dbus service name
+ */
+ Service service(const Path& path, const Interface& interface) const;
+
+ /** @brief host auto_reboot settings object */
+ Path autoReboot;
+
+ /** @brief host power_restore_policy settings object */
+ Path powerRestorePolicy;
+
+ /** @brief The Dbus bus object */
+ sdbusplus::bus::bus& bus;
};
} // namespace settings
OpenPOWER on IntegriCloud