refactor power restore controller

Currently PowerRestorePolicy handling code uses two undocumented
interfaces:
* `xyz.openbmc_project.Control.Power.RestoreDelay`
* `xyz.openbmc_project.Common.ACBoot`

Power Restore Delay seems to be logical part of
`xyz.openbmc_project.Control.Power.RestorePolicy` interface and has
been moved there.

ACBoot depends on some custom logic that can be found only in Intel-BMC
fork.

This commit reorganize PowerRestorePolicy-related code to be more clear
and flexible, fixes interface for RestoreDelay. Use of ACBoot feature is
now optional and can be compile-time enabled.

Tested: Model power loss event with Off, On and Restore policy, verify,
        that power restored as expected.
	Test On policy with Delay set to 300000000 - ensure, power on
	delayed by 5 minutes.
	Test with ACBoot interface emulated.
Signed-off-by: Andrei Kartashev <a.kartashev@yadro.com>
Change-Id: Id8b42d2085f44418e02a7f52836cc1a6f55f50db
diff --git a/src/power_control.hpp b/src/power_control.hpp
index 5dda797..9e54184 100644
--- a/src/power_control.hpp
+++ b/src/power_control.hpp
@@ -5,7 +5,11 @@
 
 #pragma once
 
+#include <boost/asio/io_service.hpp>
+#include <boost/asio/steady_timer.hpp>
+#include <boost/container/flat_map.hpp>
 #include <nlohmann/json.hpp>
+#include <sdbusplus/asio/object_server.hpp>
 
 #include <filesystem>
 #include <string_view>
@@ -21,6 +25,70 @@
  * default values, hardcoded in getDefault() method.
  * @note: currently only string parameters supported
  */
+using dbusPropertiesList =
+    boost::container::flat_map<std::string,
+                               std::variant<std::string, uint64_t>>;
+/**
+ * @brief The class contains functions to invoke power restore policy.
+ *
+ * This class only exists to unite all PowerRestore-related code. It supposed
+ * to run only once on application startup.
+ */
+class PowerRestoreController
+{
+  public:
+    PowerRestoreController(boost::asio::io_service& io) :
+        policyInvoked(false), powerRestoreDelay(-1), powerRestoreTimer(io),
+        timerFired(false)
+    {}
+    /**
+     * @brief Power Restore entry point.
+     *
+     * Call this to start Power Restore algorithm.
+     */
+    void run();
+    /**
+     * @brief Initialize configuration parameters.
+     *
+     * Parse list of properties, received from dbus, to set Power Restore
+     * algorithm configuration.
+     * @param props - map of property names and values
+     */
+    void setProperties(const dbusPropertiesList& props);
+
+  private:
+    bool policyInvoked;
+    std::string powerRestorePolicy;
+    int powerRestoreDelay;
+    std::list<sdbusplus::bus::match::match> matches;
+    boost::asio::steady_timer powerRestoreTimer;
+    bool timerFired;
+#ifdef USE_ACBOOT
+    std::string acBoot;
+#endif // USE_ACBOOT
+
+    /**
+     * @brief Check if all required algorithms parameters are set
+     *
+     * Call this after set any of Power Restore algorithm parameters. Once all
+     * parameters are set this will run invoke() function.
+     */
+    void invokeIfReady();
+    /**
+     * @brief Actually perform power restore actions.
+     *
+     * Take Power Restore actions according to Policy and other parameters.
+     */
+    void invoke();
+    /**
+     * @brief Check if power was dropped.
+     *
+     * Read last saved power state to determine if host power was enabled before
+     * last BMC reboot.
+     */
+    bool wasPowerDropped();
+};
+
 class PersistentState
 {
   public: