Add journal entry for BOOTCOUNT

Update the jounal entry in the host state code to
indicate we may have hit the HOST BOOTCOUNT.

Resolves openbmc/openbmc#1424

Change-Id: I2bfd73f6051efb408eb4c683cebe95fda4700859
Signed-off-by: Saqib Khan <khansa@us.ibm.com>
diff --git a/host_state_manager.cpp b/host_state_manager.cpp
index 49fb910..3e06d73 100644
--- a/host_state_manager.cpp
+++ b/host_state_manager.cpp
@@ -51,8 +51,7 @@
 constexpr auto SYSTEMD_PROPERTY_IFACE = "org.freedesktop.DBus.Properties";
 constexpr auto SYSTEMD_INTERFACE_UNIT = "org.freedesktop.systemd1.Unit";
 
-const sdbusplus::message::variant<int>  DEFAULT_BOOTCOUNT = 2;
-
+constexpr auto DEFAULT_BOOTCOUNT = 2;
 
 /* Map a system state to the HostState */
 const std::map<std::string, server::Host::HostState> SYS_HOST_STATE_TABLE = {
@@ -179,6 +178,16 @@
     return true;
 }
 
+void Host::setHostbootCount(int bootCount)
+{
+    auto method = this->bus.new_method_call(REBOOTCOUNTER_SERVICE,
+                                            REBOOTCOUNTER_PATH,
+                                            REBOOTCOUNTER_INTERFACE,
+                                            "setValue");
+    sdbusplus::message::variant<int> newParam = bootCount;
+    method.append(newParam);
+    this->bus.call_noreply(method);
+}
 
 bool Host::isAutoReboot()
 {
@@ -236,7 +245,7 @@
         return false;
     }
 
-    sdbusplus::message::variant<int> rebootCounterParam;
+    sdbusplus::message::variant<int> rebootCounterParam = 0;
     method = this->bus.new_method_call(REBOOTCOUNTER_SERVICE,
                                        REBOOTCOUNTER_PATH,
                                        REBOOTCOUNTER_INTERFACE,
@@ -251,28 +260,35 @@
 
     if (strParam == "yes")
     {
-        method = this->bus.new_method_call(REBOOTCOUNTER_SERVICE,
-                                           REBOOTCOUNTER_PATH,
-                                           REBOOTCOUNTER_INTERFACE,
-                                           "setValue");
         if( rebootCounterParam > 0)
         {
             // Reduce BOOTCOUNT by 1
-            method.append((sdbusplus::message::variant_ns::
-                           get<int>(rebootCounterParam)) - 1);
-            this->bus.call_noreply(method);
+            log<level::INFO>("Auto reboot enabled. "
+                             "Reducing HOST BOOTCOUNT by 1.");
+            Host::setHostbootCount((sdbusplus::message::variant_ns::
+                                    get<int>(rebootCounterParam)) - 1);
             return true;
         }
-        if(rebootCounterParam == 0)
+        else if(rebootCounterParam == 0)
         {
             // Reset reboot counter and go to quiesce state
-            method.append(DEFAULT_BOOTCOUNT);
-            this->bus.call_noreply(method);
+            log<level::INFO>("Auto reboot enabled. "
+                             "HOST BOOTCOUNT already set to 0.");
+            Host::setHostbootCount(DEFAULT_BOOTCOUNT);
+            return false;
+        }
+        else
+        {
+            log<level::INFO>("Auto reboot enabled. "
+                             "HOST BOOTCOUNT has an invalid value.");
             return false;
         }
     }
-
-    return false;
+    else
+    {
+        log<level::INFO>("Auto reboot disabled.");
+        return false;
+    }
 }
 
 int Host::sysStateChangeSignal(sd_bus_message *msg, void *userData,
@@ -320,12 +336,12 @@
      {
          if (Host::isAutoReboot())
          {
-             log<level::INFO>("Auto reboot enabled. Beginning reboot...");
+             log<level::INFO>("Beginning reboot...");
              Host::requestedHostTransition(server::Host::Transition::Reboot);
          }
          else
          {
-             log<level::INFO>("Auto reboot disabled. Maintaining quiesce.");
+             log<level::INFO>("Maintaining quiesce");
              this->currentHostState(server::Host::HostState::Quiesced);
          }
 
diff --git a/host_state_manager.hpp b/host_state_manager.hpp
index e277289..e9158a3 100644
--- a/host_state_manager.hpp
+++ b/host_state_manager.hpp
@@ -100,6 +100,13 @@
         bool stateActive(const std::string& target);
 
         /**
+         * @brief Set the HOST BOOTCOUNT Sensor value
+         *
+         * @param[in] bootCount  - new BOOTCOUNT value
+         */
+        void setHostbootCount(int bootCount);
+
+        /**
          * @brief Determine if auto reboot flag is set
          *
          * @return boolean corresponding to current auto_reboot setting