item_updater: Use Common.FilePath to locate images

The image manager implements the Common.FilePath.Path interface,
make use of it to find the image files instead of hardcoding the
path, since the updater shouldn't know/care where the images are.

Change-Id: Ieb9ad8e393a7f91645631db9f302095eb82d7f61
Signed-off-by: Saqib Khan <khansa@us.ibm.com>
diff --git a/configure.ac b/configure.ac
index cc65c1b..96a51cd 100755
--- a/configure.ac
+++ b/configure.ac
@@ -66,6 +66,8 @@
 
 AC_DEFINE(VERSION_IFACE, "xyz.openbmc_project.Software.Version",
     [The software version manager interface])
+AC_DEFINE(FILEPATH_IFACE, "xyz.openbmc_project.Common.FilePath",
+    [The common file path interface])
 
 AC_ARG_VAR(IMG_UPLOAD_DIR, [Directory where downloaded software images are placed])
 AS_IF([test "x$IMG_UPLOAD_DIR" == "x"], [IMG_UPLOAD_DIR="/tmp/images"])
diff --git a/item_updater.cpp b/item_updater.cpp
index efff65f..cd12688 100644
--- a/item_updater.cpp
+++ b/item_updater.cpp
@@ -32,6 +32,7 @@
                       sdbusplus::message::variant<std::string>>> interfaces;
     msg.read(objPath, interfaces);
     std::string path(std::move(objPath));
+    std::string filePath;
 
     for (const auto& intf : interfaces)
     {
@@ -53,8 +54,20 @@
                 }
             }
         }
+        else if (intf.first == FILEPATH_IFACE)
+        {
+            for (const auto& property : intf.second)
+            {
+                if (property.first == "Path")
+                {
+                    filePath = sdbusplus::message::variant_ns::get<
+                            std::string>(property.second);
+                }
+            }
+        }
     }
     if (version.empty() ||
+        filePath.empty() ||
         (purpose != server::Version::VersionPurpose::BMC &&
         purpose != server::Version::VersionPurpose::System))
     {
@@ -77,15 +90,11 @@
         // Determine the Activation state by processing the given image dir.
         auto activationState = server::Activation::Activations::Invalid;
         ItemUpdater::ActivationStatus result = ItemUpdater::
-                     validateSquashFSImage(versionId);
+                     validateSquashFSImage(filePath);
         if (result == ItemUpdater::ActivationStatus::ready)
         {
             activationState = server::Activation::Activations::Ready;
         }
-        else if (result == ItemUpdater::ActivationStatus::active)
-        {
-            activationState = server::Activation::Activations::Active;
-        }
         activations.insert(std::make_pair(
                                versionId,
                                std::make_unique<Activation>(
@@ -101,7 +110,7 @@
                                 path,
                                 version,
                                 purpose,
-                                "")));
+                                filePath)));
     }
     return;
 }
@@ -132,19 +141,10 @@
 }
 
 ItemUpdater::ActivationStatus ItemUpdater::validateSquashFSImage(
-             const std::string& versionId)
+             const std::string& filePath)
 {
 
-    // TODO openbmc/openbmc#1715 Check the Common.FilePath to
-    //      determine the active image.
-    fs::path imageDirPath(IMG_UPLOAD_DIR);
-    imageDirPath /= versionId;
-    if (!fs::is_directory(imageDirPath))
-    {
-        return ItemUpdater::ActivationStatus::active;
-    }
-
-    fs::path file(imageDirPath);
+    fs::path file(filePath);
     file /= bmcImage;
     std::ifstream efile(file.c_str());
 
@@ -154,7 +154,7 @@
     }
     else
     {
-        log<level::ERR>("Failed to find the SquashFS image.");
+        log<level::ERR>("Failed to find the BMC image.");
         return ItemUpdater::ActivationStatus::invalid;
     }
 }
diff --git a/item_updater.hpp b/item_updater.hpp
index 082dbf7..fb8e9df 100644
--- a/item_updater.hpp
+++ b/item_updater.hpp
@@ -70,14 +70,14 @@
         /**
          * @brief Validates the presence of SquashFS iamge in the image dir.
          *
-         * @param[in]  versionId - The software version ID.
+         * @param[in]  filePath  - The path to the image dir.
          * @param[out] result    - ActivationStatus Enum.
          *                         ready if validation was successful.
          *                         invalid if validation fail.
          *                         active if image is the current version.
          *
          */
-        ActivationStatus validateSquashFSImage(const std::string& versionId);
+        ActivationStatus validateSquashFSImage(const std::string& filePath);
 
         /** @brief Persistent sdbusplus DBus bus connection. */
         sdbusplus::bus::bus& bus;