power-utils: Initially add isReadyToUpdate

Initially add isReadyToUpdate() that checks the pre-condition for PSU
update.
For now it only checks the power state and return false if power is on.

When it is not ready to update, there is no need to unbind/bind the
driver, so move the unbind/bind calls into doUpdate() from ctor/dtor.

Tested: Verify it returns and logs "PSU not ready to update" when power
        is on, and continues the update when power is off.

Signed-off-by: Lei YU <mine260309@gmail.com>
Change-Id: I1cbb454baf735ceb3de883a7317753d46485696f
diff --git a/tools/power-utils/updater.cpp b/tools/power-utils/updater.cpp
index 024fabc..deab95f 100644
--- a/tools/power-utils/updater.cpp
+++ b/tools/power-utils/updater.cpp
@@ -69,11 +69,17 @@
         return false;
     }
 
-    // TODO: check if it is ready to update
-    // and return if not ready
-
     Updater updater(psuInventoryPath, devPath, imageDir);
+    if (!updater.isReadyToUpdate())
+    {
+        log<level::ERR>("PSU not ready to update",
+                        entry("PSU=%s", psuInventoryPath.c_str()));
+        return false;
+    }
+
+    updater.bindUnbind(false);
     int ret = updater.doUpdate();
+    updater.bindUnbind(true);
     return ret == 0;
 }
 
@@ -96,12 +102,6 @@
                         entry("ERROR=%s", e.what()));
         throw;
     }
-    bindUnbind(false);
-}
-
-Updater::~Updater()
-{
-    bindUnbind(true);
 }
 
 // During PSU update, it needs to access the PSU i2c device directly, so it
@@ -144,6 +144,20 @@
     }
 }
 
+bool Updater::isReadyToUpdate()
+{
+    // Pre-condition for updating PSU:
+    // * Host is powered off
+    // * All other PSUs are having AC input
+    // * All other PSUs are having standby output
+    if (util::isPoweredOn(bus))
+    {
+        return false;
+    }
+    // TODO
+    return true;
+}
+
 int Updater::doUpdate()
 {
     // TODO
diff --git a/tools/power-utils/updater.hpp b/tools/power-utils/updater.hpp
index 0d69c0b..befa4fb 100644
--- a/tools/power-utils/updater.hpp
+++ b/tools/power-utils/updater.hpp
@@ -54,7 +54,7 @@
             const std::string& imageDir);
 
     /** @brief Destructor */
-    ~Updater();
+    ~Updater() = default;
 
     /** @brief Bind or unbind the driver
      *
@@ -68,6 +68,12 @@
      */
     void setPresent(bool present);
 
+    /** @brief Check if it's ready to update the PSU
+     *
+     * @return true if it's ready, otherwise false
+     */
+    bool isReadyToUpdate();
+
     /** @brief Do the PSU update
      *
      * @return 0 if success, otherwise non-zero