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