Create active association

Create an association between an active image
and the active image's version object.
This change includes code to remove the active
association if the image is deleted.

Change-Id: Id5b2d353d7df05854b035641765e1066d64a3ef5
Signed-off-by: Gunnar Mills <gmills@us.ibm.com>
diff --git a/activation.cpp b/activation.cpp
index 3f16b7b..5b54571 100755
--- a/activation.cpp
+++ b/activation.cpp
@@ -102,6 +102,8 @@
     squashfsLoaded = false;
     rwVolumesCreated = false;
     Activation::unsubscribeFromSystemdSignals();
+    // Create active association
+    parent.createActiveAssociation(path);
 }
 
 auto Activation::activation(Activations value) ->
@@ -232,6 +234,9 @@
 
 void Activation::delete_()
 {
+    // Remove active association
+    parent.removeActiveAssociation(path);
+
     parent.erase(versionId);
 }
 
diff --git a/configure.ac b/configure.ac
index 9bfb226..bbfd979 100755
--- a/configure.ac
+++ b/configure.ac
@@ -58,6 +58,9 @@
 AC_DEFINE(ACTIVATION_REV_ASSOCIATION, "inventory", [The name of the activation's reverse association.])
 AC_DEFINE(HOST_INVENTORY_PATH, "/xyz/openbmc_project/inventory/system/chassis", [The host inventory path.])
 
+AC_DEFINE(ACTIVE_FWD_ASSOCIATION, "active", [The name of the active's forward association.])
+AC_DEFINE(ACTIVE_REV_ASSOCIATION, "software_version", [The name of the active's reverse association.])
+
 AC_DEFINE(VERSION_IFACE, "xyz.openbmc_project.Software.Version",
     [The software version manager interface])
 AC_DEFINE(FILEPATH_IFACE, "xyz.openbmc_project.Common.FilePath",
diff --git a/item_updater.cpp b/item_updater.cpp
index 9038471..6df57ac 100644
--- a/item_updater.cpp
+++ b/item_updater.cpp
@@ -398,6 +398,30 @@
     }
 }
 
+void ItemUpdater::createActiveAssociation(std::string path)
+{
+    assocs.emplace_back(std::make_tuple(ACTIVE_FWD_ASSOCIATION,
+                                        ACTIVE_REV_ASSOCIATION,
+                                        path));
+    associations(assocs);
+}
+
+void ItemUpdater::removeActiveAssociation(std::string path)
+{
+    for (auto iter = assocs.begin(); iter != assocs.end();)
+    {
+        if ((std::get<2>(*iter)).compare(path) == 0)
+        {
+            iter = assocs.erase(iter);
+            associations(assocs);
+        }
+        else
+        {
+            ++iter;
+        }
+    }
+}
+
 } // namespace updater
 } // namespace software
 } // namespace openpower
diff --git a/item_updater.hpp b/item_updater.hpp
index a9bc8f4..affbe53 100755
--- a/item_updater.hpp
+++ b/item_updater.hpp
@@ -4,6 +4,7 @@
 #include "activation.hpp"
 #include <xyz/openbmc_project/Common/FactoryReset/server.hpp>
 #include "version.hpp"
+#include "org/openbmc/Associations/server.hpp"
 
 namespace openpower
 {
@@ -13,9 +14,13 @@
 {
 
 using ItemUpdaterInherit = sdbusplus::server::object::object<
-    sdbusplus::xyz::openbmc_project::Common::server::FactoryReset>;
+    sdbusplus::xyz::openbmc_project::Common::server::FactoryReset,
+    sdbusplus::org::openbmc::server::Associations>;
 namespace MatchRules = sdbusplus::bus::match::rules;
 
+using AssociationList =
+        std::vector<std::tuple<std::string, std::string, std::string>>;
+
 /** @class ItemUpdater
  *  @brief Manages the activation of the version items.
  */
@@ -79,6 +84,19 @@
          */
         void freeSpace();
 
+        /** @brief Creates an active association to the
+         *  newly active software image
+         *
+         * @param[in]  path - The path to create the association to.
+         */
+        void createActiveAssociation(std::string path);
+
+        /** @brief Removes an active association to the software image
+         *
+         * @param[in]  path - The path to remove the association from.
+         */
+        void removeActiveAssociation(std::string path);
+
     private:
         /** @brief Callback function for Software.Version match.
          *  @details Creates an Activation dbus object.
@@ -110,6 +128,9 @@
         /** @brief sdbusplus signal match for Software.Version */
         sdbusplus::bus::match_t versionMatch;
 
+        /** @brief This entry's associations */
+        AssociationList assocs = {};
+
         /** @brief Clears read only PNOR partition for
          *  given Activation dbus object
          *