diff options
-rw-r--r-- | Makefile.am | 16 | ||||
-rw-r--r-- | configure.ac | 2 | ||||
-rw-r--r-- | host_state_manager.cpp | 64 | ||||
-rw-r--r-- | host_state_manager.hpp | 7 |
4 files changed, 36 insertions, 53 deletions
diff --git a/Makefile.am b/Makefile.am index 0cea407..e392086 100644 --- a/Makefile.am +++ b/Makefile.am @@ -10,7 +10,8 @@ sbin_PROGRAMS = \ phosphor_host_state_manager_SOURCES = \ host_state_manager.cpp \ host_state_manager_main.cpp \ - host_state_serialize.cpp + host_state_serialize.cpp \ + settings.cpp phosphor_chassis_state_manager_SOURCES = \ chassis_state_manager.cpp \ @@ -26,8 +27,17 @@ phosphor_discover_system_state_SOURCES = \ phosphor_host_check_SOURCES = \ host_check_main.cpp -generic_cxxflags = $(SYSTEMD_CFLAGS) $(PHOSPHOR_DBUS_INTERFACES_CFLAGS) $(SDBUSPLUS_CFLAGS) -generic_ldflags = $(SYSTEMD_LIBS) $(PHOSPHOR_DBUS_INTERFACES_LIBS) $(SDBUSPLUS_LIBS) +generic_cxxflags = \ + $(SYSTEMD_CFLAGS) \ + $(PHOSPHOR_DBUS_INTERFACES_CFLAGS) \ + $(SDBUSPLUS_CFLAGS) \ + $(PHOSPHOR_LOGGING_CFLAGS) + +generic_ldflags = \ + $(SYSTEMD_LIBS) \ + $(PHOSPHOR_DBUS_INTERFACES_LIBS) \ + $(SDBUSPLUS_LIBS) + $(PHOSPHOR_LOGGING_LIBS) phosphor_host_state_manager_CXXFLAGS = $(generic_cxxflags) phosphor_host_state_manager_LDFLAGS = $(generic_ldflags) -lstdc++fs diff --git a/configure.ac b/configure.ac index eb1ac58..7c01962 100644 --- a/configure.ac +++ b/configure.ac @@ -16,6 +16,8 @@ PKG_CHECK_MODULES([PHOSPHOR_DBUS_INTERFACES], [phosphor-dbus-interfaces],,\ AC_MSG_ERROR(["Requires phosphor-dbus-interfaces package."])) PKG_CHECK_MODULES([SDBUSPLUS], [sdbusplus],, AC_MSG_ERROR(["Requires sdbusplus package."])) +PKG_CHECK_MODULES([PHOSPHOR_LOGGING], [phosphor-logging],,\ + AC_MSG_ERROR(["Requires phosphor-logging package."])) # Checks for typedefs, structures, and compiler characteristics. AX_CXX_COMPILE_STDCXX_14([noext]) diff --git a/host_state_manager.cpp b/host_state_manager.cpp index da42918..54321d2 100644 --- a/host_state_manager.cpp +++ b/host_state_manager.cpp @@ -255,59 +255,25 @@ void Host::setHostbootCount(int bootCount) bool Host::isAutoReboot() { - sdbusplus::message::variant<std::string> autoRebootParam; - std::string strParam; - - std::string HOST_PATH("/org/openbmc/settings/host0"); - std::string HOST_INTERFACE("org.openbmc.settings.Host"); - - auto mapper = this->bus.new_method_call(MAPPER_BUSNAME, - MAPPER_PATH, - MAPPER_INTERFACE, - "GetObject"); - - mapper.append(HOST_PATH, std::vector<std::string>({HOST_INTERFACE})); - auto mapperResponseMsg = this->bus.call(mapper); - - if (mapperResponseMsg.is_method_error()) - { - log<level::ERR>("Error in mapper call"); - return false; - } - - std::map<std::string, std::vector<std::string>> mapperResponse; - mapperResponseMsg.read(mapperResponse); - if (mapperResponse.empty()) - { - log<level::ERR>("Error reading mapper response"); - return false; - } - - const auto& host = mapperResponse.begin()->first; - - auto method = this->bus.new_method_call(host.c_str(), - HOST_PATH.c_str(), - "org.freedesktop.DBus.Properties", - "Get"); - - method.append(HOST_INTERFACE.c_str(), "auto_reboot"); - auto reply = this->bus.call(method); - + 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"); + method.append(autoRebootIntf, "AutoReboot"); + auto reply = bus.call(method); if (reply.is_method_error()) { - log<level::ERR>("Error in auto_reboot Get"); + log<level::ERR>("Error in AutoReboot Get"); return false; } - reply.read(autoRebootParam); - strParam = - sdbusplus::message::variant_ns::get<std::string>(autoRebootParam); - - if (strParam.empty()) - { - log<level::ERR>("Error reading auto_reboot response"); - return false; - } + sdbusplus::message::variant<bool> result; + reply.read(result); + auto autoReboot = result.get<bool>(); sdbusplus::message::variant<int> rebootCounterParam = 0; method = this->bus.new_method_call(REBOOTCOUNTER_SERVICE, @@ -322,7 +288,7 @@ bool Host::isAutoReboot() } reply.read(rebootCounterParam); - if (strParam == "yes") + if (autoReboot) { if ( rebootCounterParam > 0) { diff --git a/host_state_manager.hpp b/host_state_manager.hpp index af4fa15..8204931 100644 --- a/host_state_manager.hpp +++ b/host_state_manager.hpp @@ -4,6 +4,7 @@ #include <functional> #include <sdbusplus/bus.hpp> #include "xyz/openbmc_project/State/Host/server.hpp" +#include "settings.hpp" namespace phosphor { @@ -47,7 +48,8 @@ class Host : public HostInherit sdbusRule::interface( "org.freedesktop.systemd1.Manager"), std::bind(std::mem_fn(&Host::sysStateChange), - this, std::placeholders::_1)) + this, std::placeholders::_1)), + settings(bus) { // Enable systemd signals subscribeToSystemdSignals(); @@ -138,6 +140,9 @@ class Host : public HostInherit /** @brief Used to subscribe to dbus systemd signals **/ sdbusplus::bus::match_t systemdSignals; + + // Settings objects of interest + settings::Objects settings; }; } // namespace manager |