sched-host-tran: handle with the scheduled time

Add the basic process to handle with the scheduled time

Tested:
1. Scheduled time is 0
  # busctl set-property xyz.openbmc_project.State.ScheduledHostTransition \
    /xyz/openbmc_project/state/host0 \
    xyz.openbmc_project.State.ScheduledHostTransition ScheduledTime t 1
    ------
    Feb 19 08:09:47 witherspoon phosphor-scheduled-host-transition[28263]: \
    The function Scheduled Host Transition is disabled.
2. Scheduled time is the past
 # busctl set-property xyz.openbmc_project.State.ScheduledHostTransition \
   /xyz/openbmc_project/state/host0 \
   xyz.openbmc_project.State.ScheduledHostTransition ScheduledTime t 1582100042
   ------
   Failed to set property ScheduledTime on interface xyz.openbmc_project.State.\
   ScheduledHostTransition: Scheduled time is in the past
   Feb 19 08:14:42 witherspoon phosphor-scheduled-host-transition[28263]: \
   Scheduled time is earlier than current time. Fail to do host transition.
   Feb 19 08:14:42 witherspoon phosphor-scheduled-host-transition[28263]: \
   Scheduled time is in the past

Change-Id: I0b6a98dcb6d0e70336bf42fc88a633abf3e64633
Signed-off-by: Carol Wang <wangkair@cn.ibm.com>
diff --git a/scheduled_host_transition.cpp b/scheduled_host_transition.cpp
index e636579..4d59ff9 100644
--- a/scheduled_host_transition.cpp
+++ b/scheduled_host_transition.cpp
@@ -1,5 +1,11 @@
 #include "scheduled_host_transition.hpp"
 
+#include <phosphor-logging/elog-errors.hpp>
+#include <phosphor-logging/elog.hpp>
+#include <phosphor-logging/log.hpp>
+#include <xyz/openbmc_project/ScheduledTime/error.hpp>
+#include <chrono>
+
 namespace phosphor
 {
 namespace state
@@ -7,14 +13,45 @@
 namespace manager
 {
 
+using namespace std::chrono;
+using namespace phosphor::logging;
+using namespace xyz::openbmc_project::ScheduledTime;
+using InvalidTimeError =
+    sdbusplus::xyz::openbmc_project::ScheduledTime::Error::InvalidTime;
 using HostTransition =
     sdbusplus::xyz::openbmc_project::State::server::ScheduledHostTransition;
 
 uint64_t ScheduledHostTransition::scheduledTime(uint64_t value)
 {
+    if (value == 0)
+    {
+        // 0 means the function Scheduled Host Transition is disabled
+        // to do: check timer, stop timer
+        log<level::INFO>("The function Scheduled Host Transition is disabled.");
+        return HostTransition::scheduledTime(value);
+    }
+
+    auto deltaTime = seconds(value) - getTime();
+    if (deltaTime < seconds(0))
+    {
+        log<level::ERR>("Scheduled time is earlier than current time. Fail to "
+                        "do host transition.");
+        elog<InvalidTimeError>(
+            InvalidTime::REASON("Scheduled time is in the past"));
+    }
+    else
+    {
+        // start timer
+    }
     return HostTransition::scheduledTime(value);
 }
 
+seconds ScheduledHostTransition::getTime()
+{
+    auto now = system_clock::now();
+    return duration_cast<seconds>(now.time_since_epoch());
+}
+
 } // namespace manager
 } // namespace state
 } // namespace phosphor