From 988817625a3acca49205c6f15fff743e2789c8ca Mon Sep 17 00:00:00 2001 From: "A. Wilcox" Date: Thu, 2 Apr 2020 19:42:45 -0500 Subject: image: Actually make backends registerable --- image/backends/README.rst | 7 ++++--- image/backends/basic.cc | 6 +++++- image/backends/basic.hh | 26 +++++++++++++++----------- 3 files changed, 24 insertions(+), 15 deletions(-) (limited to 'image/backends') diff --git a/image/backends/README.rst b/image/backends/README.rst index acb44ef..e2a91a7 100644 --- a/image/backends/README.rst +++ b/image/backends/README.rst @@ -41,9 +41,10 @@ Design Image creation backends shall derive from the Horizon::Image::BasicBackend class. Concrete backends can exist in any namespace. To be used with the -Image Creation utility, the backend must be registered in the ``basic.cc`` -file along with a unique Type Code. This Type Code can then be passed to -the Image Creation utility with the ``-t`` parameter for use. +Image Creation utility, the backend must be registered using the static +``BackendManager::register_backend`` function, using a unique Type Code. +This Type Code can then be passed to the Image Creation utility with the +``-t`` parameter for use. The Horizon::Image::BasicBackend is an abstract (pure virtual) class that has a single method that you must implement: ``create()``. This will be diff --git a/image/backends/basic.cc b/image/backends/basic.cc index dbe387c..bec3e41 100644 --- a/image/backends/basic.cc +++ b/image/backends/basic.cc @@ -20,10 +20,14 @@ std::vector known_backends = { {"squashfs", "Create a SquashFS image (.squashfs)", [](std::string, std::string){ return nullptr; } } }; -const std::vector BasicBackend::available_backends() { +const std::vector BackendManager::available_backends() { return known_backends; } +void BackendManager::register_backend(BackendDescriptor desc) { + known_backends.push_back(desc); +} + int BasicBackend::prepare() { /* The default implementation returns success immediately; * no preparation is required. */ diff --git a/image/backends/basic.hh b/image/backends/basic.hh index 3181f69..95b94ae 100644 --- a/image/backends/basic.hh +++ b/image/backends/basic.hh @@ -19,14 +19,6 @@ namespace Horizon { namespace Image { -class BasicBackend; - -struct BackendDescriptor { - std::string type_code; - std::string description; - std::function creation_fn; -}; - class BasicBackend { public: /*! Create the backend object. @@ -53,9 +45,6 @@ public: */ virtual int finalise(); - /*! Returns a list of available backends. */ - static const std::vector available_backends(); - /*! The intermediate directory which contains the sysroot the image * should contain. */ const std::string &ir_dir; @@ -63,5 +52,20 @@ public: const std::string &out_path; }; +struct BackendDescriptor { + std::string type_code; + std::string description; + std::function creation_fn; +}; + +class BackendManager { +public: + /*! Returns a list of available backends. */ + static const std::vector available_backends(); + + /*! Register a new backend. */ + static void register_backend(BackendDescriptor desc); +}; + } } -- cgit v1.2.3-70-g09d2