Add activation, item_updater and version

Implement part of functions of Activation, ItemUpdater and Version.

Tested: Upload a dummy PSU tarball, and verify the activation object is
        created with expected ExtendedVersion, and the object is deleted
        when Delete is invoked.

Signed-off-by: Lei YU <mine260309@gmail.com>
Change-Id: I7b9d29f46914ace93d27a715b32c80957e88a0aa
diff --git a/src/item_updater.hpp b/src/item_updater.hpp
new file mode 100644
index 0000000..bc86af1
--- /dev/null
+++ b/src/item_updater.hpp
@@ -0,0 +1,97 @@
+#pragma once
+
+#include "config.h"
+
+#include "activation.hpp"
+#include "version.hpp"
+
+#include <sdbusplus/server.hpp>
+#include <xyz/openbmc_project/Collection/DeleteAll/server.hpp>
+
+namespace phosphor
+{
+namespace software
+{
+namespace updater
+{
+
+class Version;
+
+using ItemUpdaterInherit = sdbusplus::server::object::object<
+    sdbusplus::xyz::openbmc_project::Collection::server::DeleteAll>;
+namespace MatchRules = sdbusplus::bus::match::rules;
+
+/** @class ItemUpdater
+ *  @brief Manages the activation of the PSU version items.
+ */
+class ItemUpdater : public ItemUpdaterInherit
+{
+  public:
+    /** @brief Constructs ItemUpdater
+     *
+     * @param[in] bus    - The D-Bus bus object
+     * @param[in] path   - The D-Bus path
+     */
+    ItemUpdater(sdbusplus::bus::bus& bus, const std::string& path) :
+        ItemUpdaterInherit(bus, path.c_str()), bus(bus),
+        versionMatch(bus,
+                     MatchRules::interfacesAdded() +
+                         MatchRules::path(SOFTWARE_OBJPATH),
+                     std::bind(std::mem_fn(&ItemUpdater::createActivation),
+                               this, std::placeholders::_1))
+    {
+    }
+
+    /** @brief Deletes version
+     *
+     *  @param[in] versionId - Id of the version to delete
+     */
+    void erase(std::string versionId);
+
+    /**
+     * @brief Erases any non-active versions.
+     */
+    void deleteAll();
+
+  private:
+    /** @brief Callback function for Software.Version match.
+     *  @details Creates an Activation D-Bus object.
+     *
+     * @param[in]  msg       - Data associated with subscribed signal
+     */
+    void createActivation(sdbusplus::message::message& msg);
+
+    /** @brief Create Activation object */
+    std::unique_ptr<Activation> createActivationObject(
+        const std::string& path, const std::string& versionId,
+        const std::string& extVersion,
+        sdbusplus::xyz::openbmc_project::Software::server::Activation::
+            Activations activationStatus);
+
+    /** @brief Create Version object */
+    std::unique_ptr<Version>
+        createVersionObject(const std::string& objPath,
+                            const std::string& versionId,
+                            const std::string& versionString,
+                            sdbusplus::xyz::openbmc_project::Software::server::
+                                Version::VersionPurpose versionPurpose,
+                            const std::string& filePath);
+
+    /** @brief Persistent sdbusplus D-Bus bus connection. */
+    sdbusplus::bus::bus& bus;
+
+    /** @brief Persistent map of Activation D-Bus objects and their
+     * version id */
+    std::map<std::string, std::unique_ptr<Activation>> activations;
+
+    /** @brief Persistent map of Version D-Bus objects and their
+     * version id */
+    std::map<std::string, std::unique_ptr<Version>> versions;
+
+    /** @brief sdbusplus signal match for Software.Version */
+    sdbusplus::bus::match_t versionMatch;
+};
+
+} // namespace updater
+} // namespace software
+} // namespace phosphor