bmc: firmware handler owns update mechanism

The firmware handler owns the update mechanism object.  The update
mechanism is currently unused.

Signed-off-by: Patrick Venture <venture@google.com>
Change-Id: I5051ee6597f66de941ad7c1f209f6cb7e3d5a835
diff --git a/firmware_handler.cpp b/firmware_handler.cpp
index fc6f01a..39086be 100644
--- a/firmware_handler.cpp
+++ b/firmware_handler.cpp
@@ -38,7 +38,8 @@
     FirmwareBlobHandler::CreateFirmwareBlobHandler(
         const std::vector<HandlerPack>& firmwares,
         const std::vector<DataHandlerPack>& transports,
-        std::unique_ptr<VerificationInterface> verification)
+        std::unique_ptr<VerificationInterface> verification,
+        std::unique_ptr<UpdateInterface> update)
 {
     /* There must be at least one. */
     if (!firmwares.size())
@@ -71,7 +72,8 @@
     }
 
     return std::make_unique<FirmwareBlobHandler>(
-        firmwares, blobs, transports, bitmask, std::move(verification));
+        firmwares, blobs, transports, bitmask, std::move(verification),
+        std::move(update));
 }
 
 /* Check if the path is in our supported list (or active list). */
diff --git a/firmware_handler.hpp b/firmware_handler.hpp
index e997c71..73a0668 100644
--- a/firmware_handler.hpp
+++ b/firmware_handler.hpp
@@ -4,6 +4,7 @@
 
 #include "data_handler.hpp"
 #include "image_handler.hpp"
+#include "update.hpp"
 #include "util.hpp"
 #include "verify.hpp"
 
@@ -105,11 +106,13 @@
      * @param[in] firmwares - list of firmware blob_ids to support.
      * @param[in] transports - list of transports to support.
      * @param[in] verification - pointer to object for triggering verification
+     * @param[in] update - point to object for triggering the update
      */
     static std::unique_ptr<GenericBlobInterface> CreateFirmwareBlobHandler(
         const std::vector<HandlerPack>& firmwares,
         const std::vector<DataHandlerPack>& transports,
-        std::unique_ptr<VerificationInterface> verification);
+        std::unique_ptr<VerificationInterface> verification,
+        std::unique_ptr<UpdateInterface> update);
 
     /**
      * Create a FirmwareBlobHandler.
@@ -119,17 +122,19 @@
      * @param[in] transports - list of transport types and their handlers
      * @param[in] bitmask - bitmask of transports to support
      * @param[in] verification - pointer to object for triggering verification
+     * @param[in] update - point to object for triggering the update
      */
     FirmwareBlobHandler(const std::vector<HandlerPack>& firmwares,
                         const std::vector<std::string>& blobs,
                         const std::vector<DataHandlerPack>& transports,
                         std::uint16_t bitmask,
-                        std::unique_ptr<VerificationInterface> verification) :
+                        std::unique_ptr<VerificationInterface> verification,
+                        std::unique_ptr<UpdateInterface> update) :
         handlers(firmwares),
         blobIDs(blobs), transports(transports), bitmask(bitmask),
         activeImage(activeImageBlobId), activeHash(activeHashBlobId),
         verifyImage(verifyBlobId), lookup(), state(UpdateState::notYetStarted),
-        verification(std::move(verification))
+        verification(std::move(verification)), update(std::move(update))
     {
     }
     ~FirmwareBlobHandler() = default;
@@ -193,6 +198,8 @@
 
     std::unique_ptr<VerificationInterface> verification;
 
+    std::unique_ptr<UpdateInterface> update;
+
     /** Temporary variable to track whether a blob is open. */
     bool fileOpen = false;
 };
diff --git a/main.cpp b/main.cpp
index 7e9b5a3..36b4ee7 100644
--- a/main.cpp
+++ b/main.cpp
@@ -115,7 +115,8 @@
         ipmi_flash::supportedFirmware, ipmi_flash::supportedTransports,
         ipmi_flash::SystemdVerification::CreateVerification(
             sdbusplus::bus::new_default(), VERIFY_STATUS_FILENAME,
-            VERIFY_DBUS_SERVICE));
+            VERIFY_DBUS_SERVICE),
+        std::move(updater));
 
     if (!handler)
     {
diff --git a/test/bmc_update_mock.hpp b/test/bmc_update_mock.hpp
index 5331b50..3db9221 100644
--- a/test/bmc_update_mock.hpp
+++ b/test/bmc_update_mock.hpp
@@ -6,7 +6,7 @@
 #include <memory>
 #include <vector>
 
-#include <gtest/gtest.h>
+#include <gmock/gmock.h>
 
 namespace ipmi_flash
 {
@@ -19,4 +19,9 @@
     MOCK_METHOD0(status, UpdateStatus());
 };
 
+std::unique_ptr<UpdateInterface> CreateUpdateMock()
+{
+    return std::make_unique<UpdateMock>();
+}
+
 } // namespace ipmi_flash
diff --git a/test/firmware_canhandle_unittest.cpp b/test/firmware_canhandle_unittest.cpp
index 02549fe..c9685bd 100644
--- a/test/firmware_canhandle_unittest.cpp
+++ b/test/firmware_canhandle_unittest.cpp
@@ -1,3 +1,4 @@
+#include "bmc_update_mock.hpp"
 #include "data_mock.hpp"
 #include "firmware_handler.hpp"
 #include "image_mock.hpp"
@@ -33,7 +34,7 @@
     };
 
     auto handler = FirmwareBlobHandler::CreateFirmwareBlobHandler(
-        blobs, data, CreateVerifyMock());
+        blobs, data, CreateVerifyMock(), CreateUpdateMock());
 
     for (const auto& item : items)
     {
diff --git a/test/firmware_commit_unittest.cpp b/test/firmware_commit_unittest.cpp
index 5f2f82e..87dba97 100644
--- a/test/firmware_commit_unittest.cpp
+++ b/test/firmware_commit_unittest.cpp
@@ -1,3 +1,4 @@
+#include "bmc_update_mock.hpp"
 #include "data_mock.hpp"
 #include "firmware_handler.hpp"
 #include "image_mock.hpp"
@@ -49,7 +50,7 @@
         std::make_unique<StrictMock<VerificationMock>>();
 
     auto handler = FirmwareBlobHandler::CreateFirmwareBlobHandler(
-        blobs, data, std::move(verifyMock));
+        blobs, data, std::move(verifyMock), CreateUpdateMock());
 
     EXPECT_CALL(imageMock2, open("asdf")).WillOnce(Return(true));
 
@@ -71,7 +72,7 @@
         std::make_unique<StrictMock<VerificationMock>>();
 
     auto handler = FirmwareBlobHandler::CreateFirmwareBlobHandler(
-        blobs, data, std::move(verifyMock));
+        blobs, data, std::move(verifyMock), CreateUpdateMock());
 
     EXPECT_CALL(imageMock1, open(StrEq(hashBlobId))).WillOnce(Return(true));
 
@@ -91,7 +92,7 @@
     auto verifyMockPtr = reinterpret_cast<VerificationMock*>(verifyMock.get());
 
     auto handler = FirmwareBlobHandler::CreateFirmwareBlobHandler(
-        blobs, data, std::move(verifyMock));
+        blobs, data, std::move(verifyMock), CreateUpdateMock());
 
     EXPECT_TRUE(handler->open(0, blobs::OpenFlags::write, verifyBlobId));
 
@@ -110,7 +111,7 @@
     auto verifyMockPtr = reinterpret_cast<VerificationMock*>(verifyMock.get());
 
     auto handler = FirmwareBlobHandler::CreateFirmwareBlobHandler(
-        blobs, data, std::move(verifyMock));
+        blobs, data, std::move(verifyMock), CreateUpdateMock());
 
     EXPECT_TRUE(handler->open(0, blobs::OpenFlags::write, verifyBlobId));
 
diff --git a/test/firmware_createhandler_unittest.cpp b/test/firmware_createhandler_unittest.cpp
index 10e8410..3bc52fe 100644
--- a/test/firmware_createhandler_unittest.cpp
+++ b/test/firmware_createhandler_unittest.cpp
@@ -1,3 +1,4 @@
+#include "bmc_update_mock.hpp"
 #include "data_mock.hpp"
 #include "firmware_handler.hpp"
 #include "image_mock.hpp"
@@ -31,7 +32,7 @@
     };
 
     auto handler = FirmwareBlobHandler::CreateFirmwareBlobHandler(
-        blobs, data, CreateVerifyMock());
+        blobs, data, CreateVerifyMock(), CreateUpdateMock());
 
     //    EXPECT_EQ(handler, nullptr);
     EXPECT_FALSE(handler == nullptr);
diff --git a/test/firmware_delete_unittest.cpp b/test/firmware_delete_unittest.cpp
index 755dc30..3c58623 100644
--- a/test/firmware_delete_unittest.cpp
+++ b/test/firmware_delete_unittest.cpp
@@ -1,3 +1,4 @@
+#include "bmc_update_mock.hpp"
 #include "data_mock.hpp"
 #include "firmware_handler.hpp"
 #include "image_mock.hpp"
@@ -31,7 +32,7 @@
     };
 
     auto handler = FirmwareBlobHandler::CreateFirmwareBlobHandler(
-        blobs, data, CreateVerifyMock());
+        blobs, data, CreateVerifyMock(), CreateUpdateMock());
 
     EXPECT_CALL(imageMock, open(StrEq(hashBlobId))).WillOnce(Return(true));
 
diff --git a/test/firmware_handler_unittest.cpp b/test/firmware_handler_unittest.cpp
index d3a8c13..e1e3a78 100644
--- a/test/firmware_handler_unittest.cpp
+++ b/test/firmware_handler_unittest.cpp
@@ -1,3 +1,4 @@
+#include "bmc_update_mock.hpp"
 #include "firmware_handler.hpp"
 #include "image_mock.hpp"
 #include "util.hpp"
@@ -18,7 +19,7 @@
     };
 
     auto handler = FirmwareBlobHandler::CreateFirmwareBlobHandler(
-        {}, data, CreateVerifyMock());
+        {}, data, CreateVerifyMock(), CreateUpdateMock());
     EXPECT_EQ(handler, nullptr);
 }
 TEST(FirmwareHandlerTest, CreateEmptyDataHandlerListFails)
@@ -31,7 +32,7 @@
     };
 
     auto handler = FirmwareBlobHandler::CreateFirmwareBlobHandler(
-        blobs, {}, CreateVerifyMock());
+        blobs, {}, CreateVerifyMock(), CreateUpdateMock());
     EXPECT_EQ(handler, nullptr);
 }
 TEST(FirmwareHandlerTest, VerifyHashRequiredForHappiness)
@@ -47,13 +48,13 @@
     };
 
     auto handler = FirmwareBlobHandler::CreateFirmwareBlobHandler(
-        blobs, data, CreateVerifyMock());
+        blobs, data, CreateVerifyMock(), CreateUpdateMock());
     EXPECT_EQ(handler, nullptr);
 
     blobs.push_back({hashBlobId, &imageMock});
 
     handler = FirmwareBlobHandler::CreateFirmwareBlobHandler(
-        blobs, data, CreateVerifyMock());
+        blobs, data, CreateVerifyMock(), CreateUpdateMock());
     auto result = handler->getBlobIds();
     EXPECT_EQ(3, result.size());
     EXPECT_EQ(3, std::count(result.begin(), result.end(), "asdf") +
diff --git a/test/firmware_stat_unittest.cpp b/test/firmware_stat_unittest.cpp
index beab6f9..54c8be4 100644
--- a/test/firmware_stat_unittest.cpp
+++ b/test/firmware_stat_unittest.cpp
@@ -1,3 +1,4 @@
+#include "bmc_update_mock.hpp"
 #include "firmware_handler.hpp"
 #include "image_mock.hpp"
 #include "util.hpp"
@@ -29,7 +30,7 @@
     };
 
     auto handler = FirmwareBlobHandler::CreateFirmwareBlobHandler(
-        blobs, data, CreateVerifyMock());
+        blobs, data, CreateVerifyMock(), CreateUpdateMock());
 
     struct blobs::BlobMeta meta;
     EXPECT_TRUE(handler->stat("asdf", &meta));
diff --git a/test/firmware_unittest.hpp b/test/firmware_unittest.hpp
index da84c1b..748b212 100644
--- a/test/firmware_unittest.hpp
+++ b/test/firmware_unittest.hpp
@@ -1,5 +1,6 @@
 #pragma once
 
+#include "bmc_update_mock.hpp"
 #include "data_mock.hpp"
 #include "firmware_handler.hpp"
 #include "image_mock.hpp"
@@ -30,7 +31,7 @@
             {"asdf", &imageMock},
         };
         handler = FirmwareBlobHandler::CreateFirmwareBlobHandler(
-            blobs, data, CreateVerifyMock());
+            blobs, data, CreateVerifyMock(), CreateUpdateMock());
     }
 };
 
@@ -54,7 +55,7 @@
             {FirmwareBlobHandler::UpdateFlags::lpc, &dataMock},
         };
         handler = FirmwareBlobHandler::CreateFirmwareBlobHandler(
-            blobs, data, CreateVerifyMock());
+            blobs, data, CreateVerifyMock(), CreateUpdateMock());
     }
 };