clang-format this repo
Use the proper-clang-format file on this repository as required by
the openbmc documentation.
Change-Id: I4f1e0d707388605f1e818dfdc647533a335e5f2d
Signed-off-by: Ed Tanous <ed.tanous@intel.com>
diff --git a/fail-monitor/argument.cpp b/fail-monitor/argument.cpp
index 4f9003c..daf0177 100644
--- a/fail-monitor/argument.cpp
+++ b/fail-monitor/argument.cpp
@@ -73,20 +73,18 @@
std::cerr << std::flush;
}
-const option ArgumentParser::options[] =
-{
- { "source", required_argument, NULL, 's' },
- { "action", required_argument, NULL, 'a' },
- { "target", required_argument, NULL, 't' },
- { "help", no_argument, NULL, 'h' },
- { 0, 0, 0, 0},
+const option ArgumentParser::options[] = {
+ {"source", required_argument, NULL, 's'},
+ {"action", required_argument, NULL, 'a'},
+ {"target", required_argument, NULL, 't'},
+ {"help", no_argument, NULL, 'h'},
+ {0, 0, 0, 0},
};
const char* ArgumentParser::optionStr = "s:a:t:h?";
const std::string ArgumentParser::trueString = "true";
const std::string ArgumentParser::emptyString = "";
-
}
}
}
diff --git a/fail-monitor/argument.hpp b/fail-monitor/argument.hpp
index 2d08a2f..00f3755 100644
--- a/fail-monitor/argument.hpp
+++ b/fail-monitor/argument.hpp
@@ -16,53 +16,52 @@
*/
class ArgumentParser
{
- public:
- ArgumentParser() = delete;
- ~ArgumentParser() = default;
- ArgumentParser(const ArgumentParser&) = delete;
- ArgumentParser& operator=(const ArgumentParser&) = delete;
- ArgumentParser(ArgumentParser&&) = default;
- ArgumentParser& operator=(ArgumentParser&&) = default;
+ public:
+ ArgumentParser() = delete;
+ ~ArgumentParser() = default;
+ ArgumentParser(const ArgumentParser&) = delete;
+ ArgumentParser& operator=(const ArgumentParser&) = delete;
+ ArgumentParser(ArgumentParser&&) = default;
+ ArgumentParser& operator=(ArgumentParser&&) = default;
- /** @brief Contructs Argument object
- *
- * @param argc - the main function's argc passed as is
- * @param argv - the main function's argv passed as is
- * @return Object constructed
- */
- ArgumentParser(int argc, char** argv);
+ /** @brief Contructs Argument object
+ *
+ * @param argc - the main function's argc passed as is
+ * @param argv - the main function's argv passed as is
+ * @return Object constructed
+ */
+ ArgumentParser(int argc, char** argv);
- /** @brief Given an option, returns its argument(optarg)
- *
- * @param opt - command line option string
- *
- * @return argument which is a standard optarg
- */
- const std::string& operator[](const std::string& opt);
+ /** @brief Given an option, returns its argument(optarg)
+ *
+ * @param opt - command line option string
+ *
+ * @return argument which is a standard optarg
+ */
+ const std::string& operator[](const std::string& opt);
- /** @brief Displays usage
- *
- * @param argv - the main function's argv passed as is
- */
- static void usage(char** argv);
+ /** @brief Displays usage
+ *
+ * @param argv - the main function's argv passed as is
+ */
+ static void usage(char** argv);
- /** @brief Set to 'true' when an option is passed */
- static const std::string trueString;
+ /** @brief Set to 'true' when an option is passed */
+ static const std::string trueString;
- /** @brief Set to '' when an option is not passed */
- static const std::string emptyString;
+ /** @brief Set to '' when an option is not passed */
+ static const std::string emptyString;
- private:
- /** @brief Option to argument mapping */
- std::map<const std::string, std::string> arguments;
+ private:
+ /** @brief Option to argument mapping */
+ std::map<const std::string, std::string> arguments;
- /** @brief Array of struct options as needed by getopt_long */
- static const option options[];
+ /** @brief Array of struct options as needed by getopt_long */
+ static const option options[];
- /** @brief optstring as needed by getopt_long */
- static const char* optionStr;
+ /** @brief optstring as needed by getopt_long */
+ static const char* optionStr;
};
-
}
}
}
diff --git a/fail-monitor/main.cpp b/fail-monitor/main.cpp
index 1c47b98..2c3bc59 100644
--- a/fail-monitor/main.cpp
+++ b/fail-monitor/main.cpp
@@ -40,11 +40,8 @@
exit(EXIT_FAILURE);
}
-static const std::map<std::string, Monitor::Action> actions =
-{
- {"start", Monitor::Action::start},
- {"stop", Monitor::Action::stop}
-};
+static const std::map<std::string, Monitor::Action> actions = {
+ {"start", Monitor::Action::start}, {"stop", Monitor::Action::stop}};
int main(int argc, char** argv)
{
diff --git a/fail-monitor/monitor.cpp b/fail-monitor/monitor.cpp
index 1936e27..9a0722a 100644
--- a/fail-monitor/monitor.cpp
+++ b/fail-monitor/monitor.cpp
@@ -29,13 +29,12 @@
constexpr auto START_METHOD = "StartUnit";
constexpr auto STOP_METHOD = "StopUnit";
-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_INTERFACE = "org.freedesktop.DBus.Properties";
constexpr auto SYSTEMD_UNIT_INTERFACE = "org.freedesktop.systemd1.Unit";
-
void Monitor::analyze()
{
if (inFailedState(std::move(getSourceUnitPath())))
@@ -44,15 +43,12 @@
}
}
-
bool Monitor::inFailedState(const std::string&& path)
{
sdbusplus::message::variant<std::string> property;
- auto method = bus.new_method_call(SYSTEMD_SERVICE,
- path.c_str(),
- SYSTEMD_PROPERTY_INTERFACE,
- "Get");
+ auto method = bus.new_method_call(SYSTEMD_SERVICE, path.c_str(),
+ SYSTEMD_PROPERTY_INTERFACE, "Get");
method.append(SYSTEMD_UNIT_INTERFACE, "ActiveState");
@@ -60,7 +56,7 @@
if (reply.is_method_error())
{
log<level::ERR>("Failed reading ActiveState DBus property",
- entry("UNIT=%s", source.c_str()));
+ entry("UNIT=%s", source.c_str()));
// TODO openbmc/openbmc#851 - Once available, throw returned error
throw std::runtime_error("Failed reading ActiveState DBus property");
}
@@ -71,22 +67,19 @@
return (value == FAILED_STATE);
}
-
std::string Monitor::getSourceUnitPath()
{
sdbusplus::message::object_path path;
- auto method = bus.new_method_call(SYSTEMD_SERVICE,
- SYSTEMD_OBJ_PATH,
- SYSTEMD_INTERFACE,
- "GetUnit");
+ auto method = bus.new_method_call(SYSTEMD_SERVICE, SYSTEMD_OBJ_PATH,
+ SYSTEMD_INTERFACE, "GetUnit");
method.append(source);
auto reply = bus.call(method);
if (reply.is_method_error())
{
log<level::ERR>("Failed GetUnit DBus method call",
- entry("UNIT=%s", source.c_str()));
+ entry("UNIT=%s", source.c_str()));
// TODO openbmc/openbmc#851 - Once available, throw returned error
throw std::runtime_error("Failed GetUnit DBus method call");
}
@@ -96,12 +89,10 @@
return static_cast<std::string>(path);
}
-
void Monitor::runTargetAction()
{
- //Start or stop the target unit
- auto methodCall = (action == Action::start) ?
- START_METHOD : STOP_METHOD;
+ // Start or stop the target unit
+ auto methodCall = (action == Action::start) ? START_METHOD : STOP_METHOD;
log<level::INFO>("The source unit is in failed state, "
"running target action",
@@ -109,10 +100,8 @@
entry("TARGET=%s", target.c_str()),
entry("ACTION=%s", methodCall));
- auto method = this->bus.new_method_call(SYSTEMD_SERVICE,
- SYSTEMD_OBJ_PATH,
- SYSTEMD_INTERFACE,
- methodCall);
+ auto method = this->bus.new_method_call(SYSTEMD_SERVICE, SYSTEMD_OBJ_PATH,
+ SYSTEMD_INTERFACE, methodCall);
method.append(target);
method.append("replace");
@@ -121,12 +110,11 @@
if (reply.is_method_error())
{
log<level::ERR>("Failed to run action on the target unit",
- entry("UNIT=%s", target.c_str()));
+ entry("UNIT=%s", target.c_str()));
// TODO openbmc/openbmc#851 - Once available, throw returned error
throw std::runtime_error("Failed to run action on the target unit");
}
}
-
}
}
}
diff --git a/fail-monitor/monitor.hpp b/fail-monitor/monitor.hpp
index 5aa2170..0c2b33a 100644
--- a/fail-monitor/monitor.hpp
+++ b/fail-monitor/monitor.hpp
@@ -23,91 +23,85 @@
*/
class Monitor
{
- public:
+ public:
+ /**
+ * The valid actions - either starting or stopping a unit
+ */
+ enum class Action
+ {
+ start,
+ stop
+ };
- /**
- * The valid actions - either starting or stopping a unit
- */
- enum class Action
- {
- start,
- stop
- };
+ Monitor() = delete;
+ Monitor(const Monitor&) = delete;
+ Monitor(Monitor&&) = default;
+ Monitor& operator=(const Monitor&) = delete;
+ Monitor& operator=(Monitor&&) = default;
+ ~Monitor() = default;
- Monitor() = delete;
- Monitor(const Monitor&) = delete;
- Monitor(Monitor&&) = default;
- Monitor& operator=(const Monitor&) = delete;
- Monitor& operator=(Monitor&&) = default;
- ~Monitor() = default;
+ /**
+ * Constructor
+ *
+ * @param[in] sourceUnit - the source unit
+ * @param[in] targetUnit - the target unit
+ * @param[in] action - the action to run on the target
+ */
+ Monitor(const std::string& sourceUnit, const std::string& targetUnit,
+ Action action) :
+ bus(std::move(sdbusplus::bus::new_default())),
+ source(sourceUnit), target(targetUnit), action(action)
+ {
+ }
- /**
- * Constructor
- *
- * @param[in] sourceUnit - the source unit
- * @param[in] targetUnit - the target unit
- * @param[in] action - the action to run on the target
- */
- Monitor(const std::string& sourceUnit,
- const std::string& targetUnit,
- Action action) :
- bus(std::move(sdbusplus::bus::new_default())),
- source(sourceUnit),
- target(targetUnit),
- action(action)
- {
- }
+ /**
+ * Analyzes the source unit to check if it is in a failed state.
+ * If it is, then it runs the action on the target unit.
+ */
+ void analyze();
- /**
- * Analyzes the source unit to check if it is in a failed state.
- * If it is, then it runs the action on the target unit.
- */
- void analyze();
+ private:
+ /**
+ * Returns the dbus object path of the source unit
+ */
+ std::string getSourceUnitPath();
- private:
+ /**
+ * Says if the unit object passed in has an
+ * ActiveState property equal to 'failed'.
+ *
+ * @param[in] path - the unit object path to check
+ *
+ * @return - true if this unit is in the failed state
+ */
+ bool inFailedState(const std::string&& path);
- /**
- * Returns the dbus object path of the source unit
- */
- std::string getSourceUnitPath();
+ /**
+ * Runs the action on the target unit.
+ */
+ void runTargetAction();
- /**
- * Says if the unit object passed in has an
- * ActiveState property equal to 'failed'.
- *
- * @param[in] path - the unit object path to check
- *
- * @return - true if this unit is in the failed state
- */
- bool inFailedState(const std::string&& path);
+ /**
+ * The dbus object
+ */
+ sdbusplus::bus::bus bus;
- /**
- * Runs the action on the target unit.
- */
- void runTargetAction();
+ /**
+ * The source unit
+ */
+ const std::string source;
- /**
- * The dbus object
- */
- sdbusplus::bus::bus bus;
+ /**
+ * The target unit
+ */
+ const std::string target;
- /**
- * The source unit
- */
- const std::string source;
-
- /**
- * The target unit
- */
- const std::string target;
-
- /**
- * The action to run on the target if the source
- * unit is in failed state.
- */
- const Action action;
+ /**
+ * The action to run on the target if the source
+ * unit is in failed state.
+ */
+ const Action action;
};
-
}
}
}