version-handler: Refactor handler construction
Instead of requiring callers to build maps and info blobs, take the
minimal required amount of information about the blob configuration and
build required datastructures internally.
This reduces the amount of code, and nearly eliminates all of the
untested code in main.cpp.
Change-Id: Iaa398eb404814e9263e6707b71b38a9831d96697
Signed-off-by: William A. Kennington III <wak@google.com>
diff --git a/bmc/version-handler/main.cpp b/bmc/version-handler/main.cpp
index 8946fb3..51df8e1 100644
--- a/bmc/version-handler/main.cpp
+++ b/bmc/version-handler/main.cpp
@@ -14,64 +14,14 @@
* limitations under the License.
*/
-#include "config.h"
-
-#include "file_handler.hpp"
-#include "general_systemd.hpp"
-#include "image_handler.hpp"
-#include "status.hpp"
#include "version_handler.hpp"
#include "version_handlers_builder.hpp"
-#include <phosphor-logging/log.hpp>
-#include <sdbusplus/bus.hpp>
-
-#include <cstdint>
#include <memory>
-#include <string>
-#include <unordered_map>
-#include <vector>
-
-namespace ipmi_flash
-{
-
-namespace
-{
-
-static constexpr const char* jsonConfigurationPath =
- "/usr/share/phosphor-ipmi-flash/";
-} // namespace
-
-std::unique_ptr<blobs::GenericBlobInterface>
- createHandlerFromJsons(VersionHandlersBuilder& builder,
- const char* configPath)
-{
- std::vector<HandlerConfig<VersionActionPack>> configsFromJson =
- builder.buildHandlerConfigs(configPath);
-
- VersionInfoMap handlerMap;
- for (auto& config : configsFromJson)
- {
- auto [it, inserted] = handlerMap.try_emplace(
- config.blobId, config.blobId, std::move(config.actions),
- std::move(config.handler));
- if (inserted == false)
- {
- std::fprintf(stderr, "duplicate blob id %s, discarding\n",
- config.blobId.c_str());
- }
- else
- {
- std::fprintf(stderr, "config loaded: %s\n", config.blobId.c_str());
- }
- }
- return VersionBlobHandler::create(std::move(handlerMap));
-}
-} // namespace ipmi_flash
extern "C" std::unique_ptr<blobs::GenericBlobInterface> createHandler()
{
- ipmi_flash::VersionHandlersBuilder builder;
- return ipmi_flash::createHandlerFromJsons(
- builder, ipmi_flash::jsonConfigurationPath);
+ return std::make_unique<ipmi_flash::VersionBlobHandler>(
+ ipmi_flash::VersionHandlersBuilder().buildHandlerConfigs(
+ "/usr/share/phosphor-ipmi-flash/"));
}