power-restore: one-time support

The one_time PowerRestorePolicy property was introduced so system owners
could utilize the feature for one time type scenarios without rewriting
all of the logic on their own.

IBM wishes to utilize the one_time power restore policy to cause an
automatic power on after an in-band firmware update.

The one_time setting is defined by default within meta-phosphor here:
https://gerrit.openbmc-project.xyz/c/openbmc/openbmc/+/40948

Testing:
- Set one time and verify it's the one used and then reset to default
busctl set-property xyz.openbmc_project.Settings /xyz/openbmc_project/control/host0/power_restore_policy/one_time xyz.openbmc_project.Control.Power.RestorePolicy PowerRestorePolicy s xyz.openbmc_project.Control.Power.RestorePolicy.Policy.AlwaysOff

busctl get-property xyz.openbmc_project.Settings /xyz/openbmc_project/control/host0/power_restore_policy/one_time xyz.openbmc_project.Control.Power.RestorePolicy PowerRestorePolicy
s "xyz.openbmc_project.Control.Power.RestorePolicy.Policy.AlwaysOff"

phosphor-discover-system-state

Feb 25 19:44:11 witherspoon phosphor-discover-system-state[495]: One time set, use it and reset to default

busctl get-property xyz.openbmc_project.Settings /xyz/openbmc_project/control/host0/power_restore_policy/one_time xyz.openbmc_project.Control.Power.RestorePolicy PowerRestorePolicy
s "xyz.openbmc_project.Control.Power.RestorePolicy.Policy.None"

- Verify when one time setting is at default it is ignored
busctl get-property xyz.openbmc_project.Settings /xyz/openbmc_project/control/host0/power_restore_policy/one_time xyz.openbmc_project.Control.Power.RestorePolicy PowerRestorePolicy
s "xyz.openbmc_project.Control.Power.RestorePolicy.Policy.None"

phosphor-discover-system-state

Feb 25 19:47:08 witherspoon phosphor-discover-system-state[498]: One time not set, check user setting of power policy
Feb 25 19:47:08 witherspoon phosphor-discover-system-state[498]: Host power is off, processing power policy

- Verify the one time power on path
busctl get-property xyz.openbmc_project.Settings /xyz/openbmc_project/control/host0/power_restore_policy/one_time xyz.openbmc_project.Control.Power.RestorePolicy PowerRestorePolicy
s "xyz.openbmc_project.Control.Power.RestorePolicy.Policy.AlwaysOn"

phosphor-discover-system-state

Feb 25 20:14:15 witherspoon phosphor-discover-system-state[504]: One time set, use it and reset to default
Feb 25 20:14:15 witherspoon phosphor-discover-system-state[504]: Host power is off, processing power policy
Feb 25 20:14:15 witherspoon phosphor-discover-system-state[504]: power_policy=ALWAYS_POWER_ON, powering host on

busctl get-property xyz.openbmc_project.Settings /xyz/openbmc_project/control/host0/power_restore_policy/one_time xyz.openbmc_project.Control.Power.RestorePolicy PowerRestorePolicy
s "xyz.openbmc_project.Control.Power.RestorePolicy.Policy.None"

Signed-off-by: Andrew Geissler <geissonator@yahoo.com>
Change-Id: I13715ad2fda1f7aa0d170e506570e85f1cef8722
diff --git a/settings.cpp b/settings.cpp
index cc0b4cb..f9f100f 100644
--- a/settings.cpp
+++ b/settings.cpp
@@ -77,7 +77,20 @@
                 }
                 else if (powerRestoreIntf == interface)
                 {
-                    powerRestorePolicy = path;
+                    /* There are two implementations of the PowerRestorePolicy
+                     * Interface. A persistent user setting and a one-time
+                     * setting which is only valid for one boot of the system.
+                     * The one-time setting will have "one_time" in its
+                     * object path.
+                     */
+                    if (path.find("one_time") != std::string::npos)
+                    {
+                        powerRestorePolicyOneTime = path;
+                    }
+                    else
+                    {
+                        powerRestorePolicy = path;
+                    }
                 }
             }
         }