common: host power utility

Create this utility class to abstract host power operation with a single
function call.

This was refactored out of [1] (BIOS Code Updater)

Tested: Has been tested as part of [1]

References:

[1] https://gerrit.openbmc.org/c/openbmc/phosphor-bmc-code-mgmt/+/76101

Change-Id: I97dc8b1824f70f0aeede3b39683c2ee4ef9ca3c9
Signed-off-by: Alexander Hansen <alexander.hansen@9elements.com>
diff --git a/common/include/host_power.hpp b/common/include/host_power.hpp
new file mode 100644
index 0000000..90cfff1
--- /dev/null
+++ b/common/include/host_power.hpp
@@ -0,0 +1,35 @@
+#pragma once
+
+#include <sdbusplus/async/context.hpp>
+#include <sdbusplus/async/match.hpp>
+#include <xyz/openbmc_project/State/Host/client.hpp>
+
+namespace phosphor::software::host_power
+{
+
+const auto stateOn =
+    sdbusplus::client::xyz::openbmc_project::state::Host<>::HostState::Running;
+const auto stateOff =
+    sdbusplus::client::xyz::openbmc_project::state::Host<>::HostState::Off;
+
+using HostState =
+    sdbusplus::client::xyz::openbmc_project::state::Host<>::HostState;
+
+class HostPower
+{
+  public:
+    HostPower(sdbusplus::async::context& ctx);
+
+    // @param state   desired powerstate
+    // @returns       true on success
+    static sdbusplus::async::task<bool> setState(sdbusplus::async::context& ctx,
+                                                 HostState state);
+
+    // @returns       host powerstate
+    static sdbusplus::async::task<HostState> getState(
+        sdbusplus::async::context& ctx);
+
+    sdbusplus::async::match stateChangedMatch;
+};
+
+}; // namespace phosphor::software::host_power