blob: 8946fb360346621fe901ab0db55f3f98523c777e [file] [log] [blame]
Jason Lingc78bfc82020-11-05 18:58:16 -08001/*
2 * Copyright 2018 Google Inc.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#include "config.h"
18
19#include "file_handler.hpp"
20#include "general_systemd.hpp"
21#include "image_handler.hpp"
22#include "status.hpp"
23#include "version_handler.hpp"
24#include "version_handlers_builder.hpp"
25
26#include <phosphor-logging/log.hpp>
27#include <sdbusplus/bus.hpp>
28
29#include <cstdint>
30#include <memory>
31#include <string>
32#include <unordered_map>
33#include <vector>
34
35namespace ipmi_flash
36{
37
38namespace
39{
40
41static constexpr const char* jsonConfigurationPath =
42 "/usr/share/phosphor-ipmi-flash/";
43} // namespace
44
45std::unique_ptr<blobs::GenericBlobInterface>
46 createHandlerFromJsons(VersionHandlersBuilder& builder,
47 const char* configPath)
48{
49 std::vector<HandlerConfig<VersionActionPack>> configsFromJson =
50 builder.buildHandlerConfigs(configPath);
51
52 VersionInfoMap handlerMap;
53 for (auto& config : configsFromJson)
54 {
55 auto [it, inserted] = handlerMap.try_emplace(
56 config.blobId, config.blobId, std::move(config.actions),
57 std::move(config.handler));
58 if (inserted == false)
59 {
60 std::fprintf(stderr, "duplicate blob id %s, discarding\n",
61 config.blobId.c_str());
62 }
63 else
64 {
65 std::fprintf(stderr, "config loaded: %s\n", config.blobId.c_str());
66 }
67 }
William A. Kennington IIIa62c1702020-12-22 12:07:13 -080068 return VersionBlobHandler::create(std::move(handlerMap));
Jason Lingc78bfc82020-11-05 18:58:16 -080069}
70} // namespace ipmi_flash
Jason Lingc78bfc82020-11-05 18:58:16 -080071
William A. Kennington IIIf4167532020-12-14 09:41:34 -080072extern "C" std::unique_ptr<blobs::GenericBlobInterface> createHandler()
Jason Lingc78bfc82020-11-05 18:58:16 -080073{
74 ipmi_flash::VersionHandlersBuilder builder;
75 return ipmi_flash::createHandlerFromJsons(
76 builder, ipmi_flash::jsonConfigurationPath);
77}