blob_handler: provide a convenience static factory
Provide a static factory for convenience to get a unique_ptr to the base
object.
Change-Id: I058e7a28a6bc30182ed9ada5ea479a317d071893
Signed-off-by: Patrick Venture <venture@google.com>
diff --git a/src/ipmiblob/blob_handler.cpp b/src/ipmiblob/blob_handler.cpp
index 7a688bf..77fcb6c 100644
--- a/src/ipmiblob/blob_handler.cpp
+++ b/src/ipmiblob/blob_handler.cpp
@@ -19,9 +19,11 @@
#include "blob_errors.hpp"
#include "crc.hpp"
#include "ipmi_errors.hpp"
+#include "ipmi_interface.hpp"
#include <array>
#include <cstring>
+#include <memory>
namespace ipmiblob
{
@@ -31,6 +33,12 @@
const std::array<std::uint8_t, 3> ipmiPhosphorOen = {0xcf, 0xc2, 0x00};
}
+std::unique_ptr<BlobInterface>
+ BlobHandler::CreateBlobHandler(std::unique_ptr<IpmiInterface> ipmi)
+{
+ return std::make_unique<BlobHandler>(std::move(ipmi));
+}
+
std::vector<std::uint8_t>
BlobHandler::sendIpmiPayload(BlobOEMCommands command,
const std::vector<std::uint8_t>& payload)
diff --git a/src/ipmiblob/blob_handler.hpp b/src/ipmiblob/blob_handler.hpp
index 6c4ba7a..0b6db17 100644
--- a/src/ipmiblob/blob_handler.hpp
+++ b/src/ipmiblob/blob_handler.hpp
@@ -26,6 +26,15 @@
bmcBlobWriteMeta = 10,
};
+ /**
+ * Create a BlobInterface pointer for use given an ipmi handler.
+ *
+ * @note This is a convenience method.
+ * @return a BlobHandler wrapped as a BlobInterface pointer.
+ */
+ static std::unique_ptr<BlobInterface>
+ CreateBlobHandler(std::unique_ptr<IpmiInterface> ipmi);
+
explicit BlobHandler(std::unique_ptr<IpmiInterface> ipmi) :
ipmi(std::move(ipmi)){};