Determine host state on application startup
This code brings some coherence to the internal host state
and transition values within the host state manager
Change-Id: I989a40bb01d5c1c16c7e42cceac1bc99ce3222f4
Signed-off-by: Andrew Geissler <andrewg@us.ibm.com>
diff --git a/host_state_manager.hpp b/host_state_manager.hpp
index 4a755db..d1f17d4 100644
--- a/host_state_manager.hpp
+++ b/host_state_manager.hpp
@@ -21,6 +21,10 @@
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
@@ -30,9 +34,32 @@
const char* objPath) :
sdbusplus::server::object::object<
sdbusplus::xyz::openbmc_project::State::server::Host>(
- bus, objPath) {};
+ bus, objPath, true),
+ bus(bus)
+ {
+ // Will throw exception on fail
+ determineInitialState();
+
+ // We deferred this until we could get our property correct
+ this->emit_object_added();
+ }
+
+ /**
+ * @brief Determine initial host state and set internally
+ *
+ * @return Will throw exceptions on failure
+ **/
+ void determineInitialState();
+
+ /** @brief Set value of HostTransition */
+ Transition requestedHostTransition(Transition value) override;
+
+ /** @brief Set value of CurrentHostState */
+ HostState currentHostState(HostState value) override;
private:
+ /** @brief Persistent sdbusplus DBus bus connection. */
+ sdbusplus::bus::bus& bus;
};
} // namespace manager