version-handler: Refactor handler construction

Instead of requiring callers to build maps and info blobs, take the
minimal required amount of information about the blob configuration and
build required datastructures internally.

This reduces the amount of code, and nearly eliminates all of the
untested code in main.cpp.

Change-Id: Iaa398eb404814e9263e6707b71b38a9831d96697
Signed-off-by: William A. Kennington III <wak@google.com>
diff --git a/bmc/version-handler/version_handler.hpp b/bmc/version-handler/version_handler.hpp
index 336a869..ad380b8 100644
--- a/bmc/version-handler/version_handler.hpp
+++ b/bmc/version-handler/version_handler.hpp
@@ -6,77 +6,32 @@
 
 #include <blobs-ipmid/blobs.hpp>
 
-#include <algorithm>
 #include <cstdint>
 #include <map>
 #include <memory>
 #include <string>
 #include <unordered_map>
 #include <vector>
+
 namespace ipmi_flash
 {
-struct VersionActionPack
-{
-  public:
-    VersionActionPack(std::unique_ptr<TriggerableActionInterface> openAction) :
-        onOpen(std::move(openAction)){};
-    VersionActionPack() = default;
-    /** Only file operation action supported currently */
-    std::unique_ptr<TriggerableActionInterface> onOpen;
-};
-
-/*
- * All the information associated with a version blob
- */
-struct VersionInfoPack
-{
-  public:
-    VersionInfoPack(const std::string& blobId,
-                    std::unique_ptr<VersionActionPack> actionPackIn,
-                    std::unique_ptr<ImageHandlerInterface> imageHandler) :
-        blobId(blobId),
-        actionPack(std::move(actionPackIn)),
-        imageHandler(std::move(imageHandler)),
-        blobState(static_cast<blobs::StateFlags>(0)){};
-    VersionInfoPack() = default;
-
-    std::string blobId;
-    std::unique_ptr<VersionActionPack> actionPack;
-    std::unique_ptr<ImageHandlerInterface> imageHandler;
-    blobs::StateFlags blobState;
-};
-
-/* convenience alias: the key (std::string) is blobId, same as
- * VersionInfoPack.blobId */
-using VersionInfoMap = std::unordered_map<std::string, VersionInfoPack>;
 
 class VersionBlobHandler : public blobs::GenericBlobInterface
 {
   public:
-    /**
-     * Factory to create a BlobHandler for use by phosphor-ipmi-blobs
-     *
-     * @param[in] versionMap - blob names to VersionInfoPack which contains
-     * triggers, file handlers, state and blobID.
-     *
-     * @returns a unique_ptr to a GenericBlobInterface which is used by
-     * phosphor-ipmi-blobs. The underlying implementation (VersionBlobHandler)
-     * implements all the blob operations for the blobs owned by
-     * VersionBlobHandler.
-     */
-    static std::unique_ptr<blobs::GenericBlobInterface>
-        create(VersionInfoMap&& versionMap);
+    struct ActionPack
+    {
+        /** Only file operation action supported currently */
+        std::unique_ptr<TriggerableActionInterface> onOpen;
+    };
+
     /**
      * Create a VersionBlobHandler.
      *
-     * @param[in] blobs - list of blobs_ids to support
-     * @param[in] actions - a map of blobId to VersionInfoPack
+     * @param[in] configs - list of blob configurations to support
      */
-    VersionBlobHandler(std::vector<std::string>&& blobs,
-                       VersionInfoMap&& handlerMap) :
-        blobIds(blobs),
-        versionInfoMap(std::move(handlerMap))
-    {}
+    VersionBlobHandler(std::vector<HandlerConfig<ActionPack>>&& configs);
+
     ~VersionBlobHandler() = default;
     VersionBlobHandler(const VersionBlobHandler&) = delete;
     VersionBlobHandler& operator=(const VersionBlobHandler&) = delete;
@@ -111,8 +66,15 @@
     bool cleanup(uint16_t session);
 
   private:
-    std::vector<std::string> blobIds;
-    VersionInfoMap versionInfoMap;
+    struct BlobInfo
+    {
+        std::string blobId;
+        std::unique_ptr<ActionPack> actions;
+        std::unique_ptr<ImageHandlerInterface> handler;
+        blobs::StateFlags blobState = static_cast<blobs::StateFlags>(0);
+    };
+
+    std::unordered_map<std::string, BlobInfo> blobInfoMap;
     std::unordered_map<uint16_t, std::string> sessionToBlob;
 };
 } // namespace ipmi_flash