summaryrefslogtreecommitdiff
path: root/image/backends
diff options
context:
space:
mode:
authorA. Wilcox <AWilcox@Wilcox-Tech.com>2020-04-02 19:42:45 -0500
committerA. Wilcox <AWilcox@Wilcox-Tech.com>2020-04-02 19:42:45 -0500
commit988817625a3acca49205c6f15fff743e2789c8ca (patch)
treebc283da3df36c8c0b76de5c023aeadac6c474ae3 /image/backends
parentc6b0e5fc81d905f57688c696f80e480712f612ab (diff)
downloadhorizon-988817625a3acca49205c6f15fff743e2789c8ca.tar.gz
horizon-988817625a3acca49205c6f15fff743e2789c8ca.tar.bz2
horizon-988817625a3acca49205c6f15fff743e2789c8ca.tar.xz
horizon-988817625a3acca49205c6f15fff743e2789c8ca.zip
image: Actually make backends registerable
Diffstat (limited to 'image/backends')
-rw-r--r--image/backends/README.rst7
-rw-r--r--image/backends/basic.cc6
-rw-r--r--image/backends/basic.hh26
3 files changed, 24 insertions, 15 deletions
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<BackendDescriptor> known_backends = {
{"squashfs", "Create a SquashFS image (.squashfs)", [](std::string, std::string){ return nullptr; } }
};
-const std::vector<BackendDescriptor> BasicBackend::available_backends() {
+const std::vector<BackendDescriptor> 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<BasicBackend *(std::string, std::string)> 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<BackendDescriptor> 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<BasicBackend *(std::string, std::string)> creation_fn;
+};
+
+class BackendManager {
+public:
+ /*! Returns a list of available backends. */
+ static const std::vector<BackendDescriptor> available_backends();
+
+ /*! Register a new backend. */
+ static void register_backend(BackendDescriptor desc);
+};
+
}
}