firmwarehandler: receive firmware list from factory

Use factory to specify the list of firmware blob_ids to the constructor
of the firmware handler.

Change-Id: I5df0c2db37854bd5c7757e099755f0d65883c000
Signed-off-by: Patrick Venture <venture@google.com>
diff --git a/firmware_handler.cpp b/firmware_handler.cpp
index e459c61..89c7891 100644
--- a/firmware_handler.cpp
+++ b/firmware_handler.cpp
@@ -1,5 +1,3 @@
-#include "config.h"
-
 #include "firmware_handler.hpp"
 
 #include <memory>
@@ -9,17 +7,11 @@
 namespace blobs
 {
 
-std::vector<std::string> supportedFirmware = {
-    "/flash/hash",
-#ifdef ENABLE_STATIC_LAYOUT
-    "/flash/image",
-#endif
-};
-
 std::unique_ptr<GenericBlobInterface>
-    FirmwareBlobHandler::CreateFirmwareBlobHandler()
+    FirmwareBlobHandler::CreateFirmwareBlobHandler(
+        const std::vector<std::string>& firmwares)
 {
-    return std::make_unique<FirmwareBlobHandler>();
+    return std::make_unique<FirmwareBlobHandler>(firmwares);
 }
 
 bool FirmwareBlobHandler::canHandleBlob(const std::string& path)
@@ -34,7 +26,7 @@
      * Grab the list of supported firmware.
      * If there's an open session, add that to this list.
      */
-    std::vector<std::string> blobs = supportedFirmware;
+    std::vector<std::string> blobs = baseFirmwares;
 
     /*
      * If there's an open firmware session, it'll add "/flash/active/image",
diff --git a/firmware_handler.hpp b/firmware_handler.hpp
index e22c335..b206f56 100644
--- a/firmware_handler.hpp
+++ b/firmware_handler.hpp
@@ -2,6 +2,8 @@
 
 #include <blobs-ipmid/blobs.hpp>
 #include <memory>
+#include <string>
+#include <vector>
 
 namespace blobs
 {
@@ -19,9 +21,13 @@
 class FirmwareBlobHandler : public GenericBlobInterface
 {
   public:
-    static std::unique_ptr<GenericBlobInterface> CreateFirmwareBlobHandler();
+    static std::unique_ptr<GenericBlobInterface>
+        CreateFirmwareBlobHandler(const std::vector<std::string>& firmwares);
 
-    FirmwareBlobHandler() = default;
+    explicit FirmwareBlobHandler(const std::vector<std::string>& firmwares) :
+        baseFirmwares(firmwares)
+    {
+    }
     ~FirmwareBlobHandler() = default;
     FirmwareBlobHandler(const FirmwareBlobHandler&) = default;
     FirmwareBlobHandler& operator=(const FirmwareBlobHandler&) = default;
@@ -44,6 +50,9 @@
     bool close(uint16_t session) override;
     bool stat(uint16_t session, struct BlobMeta* meta) override;
     bool expire(uint16_t session) override;
+
+  private:
+    std::vector<std::string> baseFirmwares;
 };
 
 } // namespace blobs
diff --git a/main.cpp b/main.cpp
index b7d35d1..0ec159f 100644
--- a/main.cpp
+++ b/main.cpp
@@ -1,3 +1,5 @@
+#include "config.h"
+
 #include "firmware_handler.hpp"
 
 #include <blobs-ipmid/manager.hpp>
@@ -8,13 +10,20 @@
 {
 using namespace phosphor::logging;
 
+std::vector<std::string> supportedFirmware = {
+    "/flash/hash",
+#ifdef ENABLE_STATIC_LAYOUT
+    "/flash/image",
+#endif
+};
+
 void setupFirmwareHandler() __attribute__((constructor));
 
 void setupFirmwareHandler()
 {
     auto* manager = getBlobManager();
     if (!manager->registerHandler(
-            FirmwareBlobHandler::CreateFirmwareBlobHandler()))
+            FirmwareBlobHandler::CreateFirmwareBlobHandler(supportedFirmware)))
     {
         log<level::ERR>("Failed to register Firmware Handler");
     }