bmc: move data handler to owned object

To handle the case where one cannot have complex static or global
objects, the object must be owned.  In this case, it is reasonable to
pass ownership to the only object that will use the data handler.

Alternatively, singletons can be used to get around this, but just using
ownership is more appropriate.

Signed-off-by: Patrick Venture <venture@google.com>
Change-Id: I47b291d1cd01af9d4b7287c1411ed9ba37aa7a4c
diff --git a/bmc/test/firmware_unittest.hpp b/bmc/test/firmware_unittest.hpp
index 0b4dc53..2b97d01 100644
--- a/bmc/test/firmware_unittest.hpp
+++ b/bmc/test/firmware_unittest.hpp
@@ -59,6 +59,9 @@
         ActionMap packs;
         packs[staticLayoutBlobId] = std::move(actionPack);
 
+        std::vector<DataHandlerPack> data;
+        data.emplace_back(FirmwareFlags::UpdateFlags::ipmi, nullptr);
+
         handler = FirmwareBlobHandler::CreateFirmwareBlobHandler(
             std::move(blobs), std::move(data), std::move(packs));
     }
@@ -174,8 +177,6 @@
     ImageHandlerMock *hashImageMock, *imageMock2;
 
     std::vector<HandlerPack> blobs;
-    std::vector<DataHandlerPack> data = {
-        {FirmwareFlags::UpdateFlags::ipmi, nullptr}};
 
     std::unique_ptr<blobs::GenericBlobInterface> handler;
 
@@ -197,8 +198,6 @@
   protected:
     ImageHandlerMock *hashImageMock, *imageMock;
     std::vector<HandlerPack> blobs;
-    std::vector<DataHandlerPack> data = {
-        {FirmwareFlags::UpdateFlags::ipmi, nullptr}};
     std::unique_ptr<blobs::GenericBlobInterface> handler;
 
     void SetUp() override
@@ -212,6 +211,9 @@
         imageMock = reinterpret_cast<ImageHandlerMock*>(image.get());
         blobs.push_back(std::move(HandlerPack("asdf", std::move(image))));
 
+        std::vector<DataHandlerPack> data;
+        data.emplace_back(FirmwareFlags::UpdateFlags::ipmi, nullptr);
+
         handler = FirmwareBlobHandler::CreateFirmwareBlobHandler(
             std::move(blobs), std::move(data),
             std::move(CreateActionMap("asdf")));
@@ -221,10 +223,9 @@
 class FakeLpcFirmwareTest : public ::testing::Test
 {
   protected:
-    DataHandlerMock dataMock;
+    DataHandlerMock* dataMock;
     ImageHandlerMock *hashImageMock, *imageMock;
     std::vector<HandlerPack> blobs;
-    std::vector<DataHandlerPack> data;
     std::unique_ptr<blobs::GenericBlobInterface> handler;
 
     void SetUp() override
@@ -238,10 +239,13 @@
         imageMock = reinterpret_cast<ImageHandlerMock*>(image.get());
         blobs.push_back(std::move(HandlerPack("asdf", std::move(image))));
 
-        data = {
-            {FirmwareFlags::UpdateFlags::ipmi, nullptr},
-            {FirmwareFlags::UpdateFlags::lpc, &dataMock},
-        };
+        auto dataMockInstance = std::make_unique<DataHandlerMock>();
+        dataMock = dataMockInstance.get();
+
+        std::vector<DataHandlerPack> data;
+        data.emplace_back(FirmwareFlags::UpdateFlags::ipmi, nullptr);
+        data.emplace_back(FirmwareFlags::UpdateFlags::lpc,
+                          std::move(dataMockInstance));
         handler = FirmwareBlobHandler::CreateFirmwareBlobHandler(
             std::move(blobs), std::move(data),
             std::move(CreateActionMap("asdf")));