sched-host-tran: implement host transition process

Set the scheduled time and host transition to trigger power on/off.

Tested:
1. Check the state first
 $ curl -k -H "X-Auth-Token: $token" https://$bmc/xyz/openbmc_project/state/host0
 {
   "data": {
     "AttemptsLeft": 3,
     "BootProgress": "xyz.openbmc_project.State.Boot.Progress.ProgressStages.Unspecified",
     "CurrentHostState": "xyz.openbmc_project.State.Host.HostState.Off",
     "OperatingSystemState": "xyz.openbmc_project.State.OperatingSystem.Status.OSStatus.Inactive",
     "RequestedHostTransition": "xyz.openbmc_project.State.Host.Transition.Off",
     "RequestedTransition": "xyz.openbmc_project.State.Host.Transition.On",
     "ScheduledTime": 0
   },
   "message": "200 OK",
   "status": "ok"
 }
2. Set a time in future
 # busctl set-property xyz.openbmc_project.State.ScheduledHostTransition \
   /xyz/openbmc_project/state/host0 \
   xyz.openbmc_project.State.ScheduledHostTransition ScheduledTime t 1582184830
 # busctl get-property xyz.openbmc_project.State.ScheduledHostTransition \
   /xyz/openbmc_project/state/host0 \
   xyz.openbmc_project.State.ScheduledHostTransition ScheduledTime
   t 1582184830
3. Check the state again after scheduled time
 Jan 15 06:38:20 WS-Seq-FW-2 phosphor-host-state-manager[442]: Host State transaction request
 $ curl -k -H "X-Auth-Token: $token" https://$bmc/xyz/openbmc_project/state/host0
 {
   "data": {
     "AttemptsLeft": 3,
     "BootProgress": "xyz.openbmc_project.State.Boot.Progress.ProgressStages.Unspecified",
     "CurrentHostState": "xyz.openbmc_project.State.Host.HostState.Running",
     "OperatingSystemState": "xyz.openbmc_project.State.OperatingSystem.Status.OSStatus.Inactive",
     "RequestedHostTransition": "xyz.openbmc_project.State.Host.Transition.On",
     "RequestedTransition": "xyz.openbmc_project.State.Host.Transition.On",
     "ScheduledTime": 0
   },
   "message": "200 OK",
   "status": "ok"
 }
4. Set quested transition to off
 # busctl set-property xyz.openbmc_project.State.ScheduledHostTransition \
   /xyz/openbmc_project/state/host0 \
   xyz.openbmc_project.State.ScheduledHostTransition RequestedTransition \
   s "xyz.openbmc_project.State.Host.Transition.Off"
 # busctl set-property xyz.openbmc_project.State.ScheduledHostTransition \
   /xyz/openbmc_project/state/host0 \
   xyz.openbmc_project.State.ScheduledHostTransition ScheduledTime t 1582250580
 $ curl -k -H "X-Auth-Token: $token" https://$bmc/xyz/openbmc_project/state/host0
 {
   "data": {
   "AttemptsLeft": 3,
   "BootProgress": "xyz.openbmc_project.State.Boot.Progress.ProgressStages.Unspecified",
   "CurrentHostState": "xyz.openbmc_project.State.Host.HostState.Off",
   "OperatingSystemState": "xyz.openbmc_project.State.OperatingSystem.Status.OSStatus.Inactive",
   "RequestedHostTransition": "xyz.openbmc_project.State.Host.Transition.Off"
   "RequestedTransition": "xyz.openbmc_project.State.Host.Transition.Off",
   "ScheduledTime": 0
   },
 "message": "200 OK",
 "status": "ok"
 }

Change-Id: Ib9f3a3984005d9187a9b98603ec1598d8992869e
Signed-off-by: Carol Wang <wangkair@cn.ibm.com>
diff --git a/scheduled_host_transition_main.cpp b/scheduled_host_transition_main.cpp
index 40a3d4d..4cd2436 100644
--- a/scheduled_host_transition_main.cpp
+++ b/scheduled_host_transition_main.cpp
@@ -1,5 +1,4 @@
 #include <cstdlib>
-#include <iostream>
 #include <exception>
 #include <sdbusplus/bus.hpp>
 #include "config.h"
@@ -7,6 +6,10 @@
 
 int main()
 {
+    // Get a default event loop
+    auto event = sdeventplus::Event::get_default();
+
+    // Get a handle to system dbus
     auto bus = sdbusplus::bus::new_default();
 
     // For now, we only have one instance of the host
@@ -16,14 +19,13 @@
     sdbusplus::server::manager::manager objManager(bus, objPathInst.c_str());
 
     phosphor::state::manager::ScheduledHostTransition manager(
-        bus, objPathInst.c_str());
+        bus, objPathInst.c_str(), event);
 
     bus.request_name(SCHEDULED_HOST_TRANSITION_BUSNAME);
 
-    while (true)
-    {
-        bus.process_discard();
-        bus.wait();
-    }
+    // Attach the bus to sd_event to service user requests
+    bus.attach_event(event.get(), SD_EVENT_PRIORITY_NORMAL);
+    event.loop();
+
     return 0;
 }