Create PNOR Functional Association

Created the function updateFunctionalAssociation to update
the functional association for the "running" PNOR image.
This function will be called by the inotify code.

Change-Id: I871624044fbb11800de4d13e6a4b174494c68f13
Signed-off-by: Gunnar Mills <gmills@us.ibm.com>
diff --git a/configure.ac b/configure.ac
index 25629ca..4996623 100755
--- a/configure.ac
+++ b/configure.ac
@@ -61,6 +61,9 @@
 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(FUNCTIONAL_FWD_ASSOCIATION, "functional", [The name of the functional forward association.])
+AC_DEFINE(FUNCTIONAL_REV_ASSOCIATION, "software_version", [The functional 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 1539f95..d0a3562 100644
--- a/item_updater.cpp
+++ b/item_updater.cpp
@@ -494,11 +494,32 @@
     associations(assocs);
 }
 
+void ItemUpdater::updateFunctionalAssociation(const std::string& path)
+{
+    // remove all functional associations
+    for (auto iter = assocs.begin(); iter != assocs.end();)
+    {
+        if ((std::get<0>(*iter)).compare(FUNCTIONAL_FWD_ASSOCIATION) == 0)
+        {
+            iter = assocs.erase(iter);
+        }
+        else
+        {
+            ++iter;
+        }
+    }
+    assocs.emplace_back(std::make_tuple(FUNCTIONAL_FWD_ASSOCIATION,
+                                        FUNCTIONAL_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)
+        if ((std::get<0>(*iter)).compare(ACTIVE_FWD_ASSOCIATION) == 0 &&
+            (std::get<2>(*iter)).compare(path) == 0)
         {
             iter = assocs.erase(iter);
             associations(assocs);
diff --git a/item_updater.hpp b/item_updater.hpp
index 8e6637a..5d2a15e 100755
--- a/item_updater.hpp
+++ b/item_updater.hpp
@@ -91,6 +91,13 @@
          */
         void createActiveAssociation(std::string path);
 
+        /** @brief Updates the functional association to the
+         *  new "running" PNOR image
+         *
+         * @param[in]  path - The path to update the association to.
+         */
+        void updateFunctionalAssociation(const std::string& path);
+
         /** @brief Removes an active association to the software image
          *
          * @param[in]  path - The path to remove the association from.