item_updater: Add version dbus object.

Need to create the Version object under itemUpdater
class to retain the version of the active images
after the bmc is rebooted and the image_dir no
longer holds the image files.

Change-Id: Iac78d577b970c6fa766b94041742f77077b14e62
Signed-off-by: Saqib Khan <khansa@us.ibm.com>
diff --git a/item_updater.cpp b/item_updater.cpp
index fa1c38d..41e4196 100755
--- a/item_updater.cpp
+++ b/item_updater.cpp
@@ -30,8 +30,9 @@
                       sdbusplus::message::variant<std::string>>> interfaces;
     m.read(objPath, interfaces);
     std::string path(std::move(objPath));
-
     std::string filePath;
+    auto purpose = server::Version::VersionPurpose::Unknown;
+    std::string version;
 
     for (const auto& intf : interfaces)
     {
@@ -42,16 +43,21 @@
                 if (property.first == "Purpose")
                 {
                     // Only process the Host and System images
-                    std::string value = sdbusplus::message::variant_ns::get<
-                            std::string>(property.second);
-                    if ((value != convertForMessage(
-                            server::Version::VersionPurpose::Host)) &&
-                        (value != convertForMessage(
-                            server::Version::VersionPurpose::System)))
+                    std::string str = sdbusplus::message::variant_ns::get<
+                        std::string>(property.second);
+                    auto value = server::Version::
+                        convertVersionPurposeFromString(str);
+                    if (value == server::Version::VersionPurpose::Host ||
+                        value == server::Version::VersionPurpose::System)
                     {
-                        return;
+                        purpose = value;
                     }
                 }
+                else if (property.first == "Version")
+                {
+                    version = sdbusplus::message::variant_ns::
+                        get<std::string>(property.second);
+                }
             }
         }
         else if (intf.first == FILEPATH_IFACE)
@@ -66,7 +72,8 @@
             }
         }
     }
-    if (filePath.empty())
+    if ((filePath.empty()) || (purpose == server::Version::
+            VersionPurpose::Unknown))
     {
         return;
     }
@@ -120,6 +127,14 @@
                         extendedVersion,
                         activationState)));
     }
+        versions.insert(std::make_pair(
+                            versionId,
+                            std::make_unique<Version>(
+                                bus,
+                                path,
+                                version,
+                                purpose,
+                                filePath)));
     return;
 }