util::dbus: Make common the autorebootEnabled code
Move the code for checking autoreboot property from attention handler
specific code to common utility dbus code.
Signed-off-by: Ben Tyner <ben.tyner@ibm.com>
Change-Id: Ia2b5e4bd3d7baa57ca46600cb5ed150144d5728e
diff --git a/attn/ti_handler.cpp b/attn/ti_handler.cpp
index fb0893f..de692ac 100644
--- a/attn/ti_handler.cpp
+++ b/attn/ti_handler.cpp
@@ -98,7 +98,7 @@
// We are finished creating the event log entries so transition host to
// the required state.
- if (autoRebootEnabled())
+ if (true == util::dbus::autoRebootEnabled())
{
// If autoreboot is enabled we will start crash (mpipl) mode target
util::dbus::transitionHost(util::dbus::HostState::Crash);
@@ -392,39 +392,6 @@
}
}
-/** @brief Read state of autoreboot propertyi via dbus */
-bool autoRebootEnabled()
-{
- // Use dbus get-property interface to read the autoreboot property
- auto bus = sdbusplus::bus::new_system();
- auto method =
- bus.new_method_call("xyz.openbmc_project.Settings",
- "/xyz/openbmc_project/control/host0/auto_reboot",
- "org.freedesktop.DBus.Properties", "Get");
-
- method.append("xyz.openbmc_project.Control.Boot.RebootPolicy",
- "AutoReboot");
-
- bool autoReboot = false; // assume autoreboot attribute not available
-
- try
- {
- auto reply = bus.call(method);
-
- std::variant<bool> result;
- reply.read(result);
- autoReboot = std::get<bool>(result);
- }
- catch (const sdbusplus::exception::SdBusError& e)
- {
- trace<level::INFO>("autoRebootEnbabled exception");
- std::string traceMsg = std::string(e.what(), maxTraceLen);
- trace<level::ERROR>(traceMsg.c_str());
- }
-
- return autoReboot;
-}
-
/**
* Callback for dump request properties change signal monitor
*
diff --git a/attn/ti_handler.hpp b/attn/ti_handler.hpp
index 23cc58b..9472c2c 100644
--- a/attn/ti_handler.hpp
+++ b/attn/ti_handler.hpp
@@ -125,14 +125,6 @@
TiDataArea* i_tiDataArea);
/**
- * @brief Read autoreboot property
- *
- * Read the autoreboot property via dbus. This status will be used to
- * determine whether to either mpipl or quiesce the host on TI condition.
- */
-bool autoRebootEnabled();
-
-/**
* Request a dump from the dump manager
*
* Request a dump from the dump manager and register a monitor for observing
diff --git a/util/dbus.cpp b/util/dbus.cpp
index 968a44f..e9526df 100644
--- a/util/dbus.cpp
+++ b/util/dbus.cpp
@@ -197,6 +197,34 @@
}
}
+/** @brief Read state of autoreboot propertyi via dbus */
+bool autoRebootEnabled()
+{
+ bool autoReboot = false; // assume autoreboot attribute not available
+
+ constexpr auto interface = "xyz.openbmc_project.Control.Boot.RebootPolicy";
+
+ DBusService service;
+ DBusPath path;
+
+ // find a dbus object and path that implements the interface
+ if (0 == find(interface, path, service))
+ {
+ DBusValue value;
+
+ // autoreboot policy is implemented as a property
+ constexpr auto property = "AutoReboot";
+
+ if (0 == getProperty(interface, path, service, property, value))
+ {
+ // return value is a variant, autoreboot policy is boolean
+ autoReboot = std::get<bool>(value);
+ }
+ }
+
+ return autoReboot;
+}
+
} // namespace dbus
} // namespace util
diff --git a/util/dbus.hpp b/util/dbus.hpp
index 66a2ad4..d1e152f 100644
--- a/util/dbus.hpp
+++ b/util/dbus.hpp
@@ -81,6 +81,14 @@
*/
void transitionHost(const HostState i_hostState);
+/**
+ * @brief Read autoreboot property
+ *
+ * Read the autoreboot property via dbus. This status will be used to
+ * determine whether to either mpipl or quiesce the host on TI condition.
+ */
+bool autoRebootEnabled();
+
} // namespace dbus
} // namespace util