common: split inventory association function

Create Software::createInventoryAssociation to split the
object mapper call from actually creating the association.

This makes unit testing the functions easier and provides a clean
separation between the logic provided by common code versus the external
information we are fetching.

Tested: Inspection only.

Change-Id: I0147480219b9c9fbc709699b9e50411fb11bea6e
Signed-off-by: Alexander Hansen <alexander.hansen@9elements.com>
diff --git a/common/include/software.hpp b/common/include/software.hpp
index 2993707..46129da 100644
--- a/common/include/software.hpp
+++ b/common/include/software.hpp
@@ -92,6 +92,13 @@
     // @returns        a random software id (swid) for that device
     static std::string getRandomSoftwareId(device::Device& parent);
 
+    // @param isRunning             if the software version is currently running
+    // on the device. Otherwise the software is assumed to be activating (not
+    // yet running).
+    // @param objectPath            The object path of the inventory item to
+    // associate with. We only ever associate to one inventory item.
+    void createInventoryAssociation(bool isRunning, std::string objectPath);
+
   private:
     Software(sdbusplus::async::context& ctx, device::Device& parent,
              const std::string& swid);
diff --git a/common/src/software.cpp b/common/src/software.cpp
index d20451d..1554b05 100644
--- a/common/src/software.cpp
+++ b/common/src/software.cpp
@@ -74,22 +74,28 @@
         co_return;
     }
 
+    createInventoryAssociation(isRunning, endpoint);
+}
+
+void Software::createInventoryAssociation(bool isRunning,
+                                          std::string objectPath)
+{
     std::vector<std::tuple<std::string, std::string, std::string>> assocs;
 
     if (isRunning)
     {
         debug("{SWID}: creating 'running' association to {OBJPATH}", "SWID",
-              swid, "OBJPATH", endpoint);
+              swid, "OBJPATH", objectPath);
         std::tuple<std::string, std::string, std::string> assocRunning = {
-            "running", "ran_on", endpoint};
+            "running", "ran_on", objectPath};
         assocs.push_back(assocRunning);
     }
     else
     {
         debug("{SWID}: creating 'activating' association to {OBJPATH}", "SWID",
-              swid, "OBJPATH", endpoint);
+              swid, "OBJPATH", objectPath);
         std::tuple<std::string, std::string, std::string> assocActivating = {
-            "activating", "activated_on", endpoint};
+            "activating", "activated_on", objectPath};
         assocs.push_back(assocActivating);
     }
 
@@ -99,15 +105,12 @@
     }
     else
     {
-        std::string path = objectPath;
         associationDefinitions =
             std::make_unique<SoftwareAssociationDefinitions>(
-                ctx, path.c_str(),
+                ctx, Software::objectPath.str.c_str(),
                 SoftwareAssociationDefinitions::properties_t{assocs});
         associationDefinitions->emit_added();
     }
-
-    co_return;
 }
 
 void Software::setVersion(const std::string& versionStr,