1 #pragma once 2 3 #include "firmware_handler.hpp" 4 #include "image_handler.hpp" 5 6 #include <nlohmann/json.hpp> 7 8 #include <memory> 9 #include <string> 10 #include <vector> 11 12 namespace ipmi_flash 13 { 14 15 class HandlerConfig 16 { 17 public: 18 HandlerConfig() = default; 19 ~HandlerConfig() = default; 20 HandlerConfig(const HandlerConfig&) = delete; 21 HandlerConfig& operator=(const HandlerConfig&) = delete; 22 HandlerConfig(HandlerConfig&&) = default; 23 HandlerConfig& operator=(HandlerConfig&&) = default; 24 25 /* A string in the form: /flash/{unique}, s.t. unique is something like, 26 * flash, ubitar, statictar, or bios 27 */ 28 std::string blobId; 29 30 /* This owns a handler interface, this is typically going to be a file 31 * writer object. 32 */ 33 std::unique_ptr<ImageHandlerInterface> handler; 34 35 /* Only the hashBlobId doesn't have an action pack, otherwise it's required. 36 */ 37 std::unique_ptr<ActionPack> actions; 38 }; 39 40 /** 41 * Given a list of handlers as json data, construct the appropriate 42 * HandlerConfig objects. This method is meant to be called per json 43 * configuration file found. 44 * 45 * The list will only contain validly build HandlerConfig objects. Any invalid 46 * configuration is skipped. The hope is that the BMC firmware update 47 * configuration will never be invalid, but if another aspect is invalid, it can 48 * be fixed with a BMC firmware update once the bug is identified. 49 * 50 * This code does not validate that the blob specified is unique, that should 51 * be handled at a higher layer. 52 * 53 * @param[in] data - json data from a json file. 54 * @return list of HandlerConfig objects. 55 */ 56 std::vector<HandlerConfig> buildHandlerFromJson(const nlohmann::json& data); 57 58 /** 59 * Given a folder of json configs, build the configurations. 60 * 61 * @param[in] directory - the directory to search (recurisvely). 62 * @return list of HandlerConfig objects. 63 */ 64 std::vector<HandlerConfig> BuildHandlerConfigs(const std::string& directory); 65 66 } // namespace ipmi_flash 67