bmc: provide disabled json support
Provide support such that a json configuration file can define a firmware
handler and its behavior. This is not yet enabled.
Signed-off-by: Patrick Venture <venture@google.com>
Change-Id: If21f4e97951b3bb91a8afc53bee493d8600a04b7
diff --git a/bmc/buildjson.hpp b/bmc/buildjson.hpp
new file mode 100644
index 0000000..5f9affd
--- /dev/null
+++ b/bmc/buildjson.hpp
@@ -0,0 +1,57 @@
+#pragma once
+
+#include "firmware_handler.hpp"
+#include "image_handler.hpp"
+
+#include <memory>
+#include <nlohmann/json.hpp>
+#include <string>
+#include <vector>
+
+namespace ipmi_flash
+{
+
+class HandlerConfig
+{
+ public:
+ HandlerConfig() = default;
+ ~HandlerConfig() = default;
+ HandlerConfig(const HandlerConfig&) = delete;
+ HandlerConfig& operator=(const HandlerConfig&) = delete;
+ HandlerConfig(HandlerConfig&&) = default;
+ HandlerConfig& operator=(HandlerConfig&&) = default;
+
+ /* A string in the form: /flash/{unique}, s.t. unique is something like,
+ * flash, ubitar, statictar, or bios
+ */
+ std::string blobId;
+
+ /* This owns a handler interface, this is typically going to be a file
+ * writer object.
+ */
+ std::unique_ptr<ImageHandlerInterface> handler;
+
+ /* Only the hashBlobId doesn't have an action pack, otherwise it's required.
+ */
+ std::unique_ptr<ActionPack> actions;
+};
+
+/**
+ * Given a list of handlers as json data, construct the appropriate
+ * HandlerConfig objects. This method is meant to be called per json
+ * configuration file found.
+ *
+ * The list will only contain validly build HandlerConfig objects. Any invalid
+ * configuration is skipped. The hope is that the BMC firmware update
+ * configuration will never be invalid, but if another aspect is invalid, it can
+ * be fixed with a BMC firmware update once the bug is identified.
+ *
+ * This code does not validate that the blob specified is unique, that should
+ * be handled at a higher layer.
+ *
+ * @param[in] data - json data from a json file.
+ * @return list of HandlerConfig objects.
+ */
+std::vector<HandlerConfig> buildHandlerFromJson(const nlohmann::json& data);
+
+} // namespace ipmi_flash