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/data_handler.hpp b/bmc/data_handler.hpp
index bf17934..162347c 100644
--- a/bmc/data_handler.hpp
+++ b/bmc/data_handler.hpp
@@ -1,6 +1,7 @@
#pragma once
#include <cstdint>
+#include <memory>
#include <vector>
namespace ipmi_flash
@@ -57,7 +58,19 @@
struct DataHandlerPack
{
std::uint16_t bitmask;
- DataInterface* handler;
+ std::unique_ptr<DataInterface> handler;
+
+ DataHandlerPack(std::uint16_t bitmask,
+ std::unique_ptr<DataInterface> handler) :
+ bitmask(bitmask),
+ handler(std::move(handler))
+ {}
+
+ /* Don't allow copying, assignment or move assignment, only moving. */
+ DataHandlerPack(const DataHandlerPack&) = delete;
+ DataHandlerPack& operator=(const DataHandlerPack&) = delete;
+ DataHandlerPack(DataHandlerPack&&) = default;
+ DataHandlerPack& operator=(DataHandlerPack&&) = delete;
};
} // namespace ipmi_flash