Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/bareos/bareos.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Rogge <andreas.rogge@bareos.com>2022-10-10 15:32:27 +0300
committerAndreas Rogge <andreas.rogge@bareos.com>2022-11-07 19:37:29 +0300
commit0a346707d3feb60d6beb8c547a641eb8c5c53911 (patch)
tree2e37e30508677e0ba3dc7dd2dab106cfe3cce1f7
parentef44197e0986ecc0dc7de8730ddb7a35924fcd4a (diff)
stored: remove BackendInterface layer
Instead of returning a factory that will then provide Device*, we can return the Device* from the PluginRegistry's factory directly. This removes the BackendInterface layer that wrapped the factory again.
-rw-r--r--core/src/stored/dev.cc10
-rw-r--r--core/src/stored/sd_backends.h26
-rw-r--r--core/src/stored/sd_backends_dynamic.cc2
-rw-r--r--core/src/stored/stored_conf.cc5
4 files changed, 9 insertions, 34 deletions
diff --git a/core/src/stored/dev.cc b/core/src/stored/dev.cc
index 285396764..bfae1a23c 100644
--- a/core/src/stored/dev.cc
+++ b/core/src/stored/dev.cc
@@ -122,20 +122,14 @@ Device* FactoryCreateDevice(JobControlRecord* jcr,
Dmsg1(400, "max_block_size in device_resource res is %u\n",
device_resource->max_block_size);
- if (!PluginRegistry<BackendInterface>::IsRegistered(
- device_resource->dev_type)) {
+ if (!PluginRegistry<Device>::IsRegistered(device_resource->dev_type)) {
Jmsg2(jcr, M_ERROR, 0, _("%s has an unknown device type %s\n"),
device_resource->archive_device_string,
device_resource->dev_type.c_str());
return nullptr;
}
- // FIXME: the PluginRegistry should return the device instead of the factory
- // so we save one call and a delete.
- auto factory
- = PluginRegistry<BackendInterface>::Create(device_resource->dev_type);
- Device* dev = factory->GetDevice();
- delete factory;
+ Device* dev = PluginRegistry<Device>::Create(device_resource->dev_type);
dev->device_resource = device_resource;
device_resource->dev = dev;
diff --git a/core/src/stored/sd_backends.h b/core/src/stored/sd_backends.h
index 71b8c7108..f137137bf 100644
--- a/core/src/stored/sd_backends.h
+++ b/core/src/stored/sd_backends.h
@@ -1,8 +1,7 @@
/*
BAREOSĀ® - Backup Archiving REcovery Open Sourced
- Copyright (C) 2014-2014 Planets Communications B.V.
- Copyright (C) 2014-2022 Bareos GmbH & Co. KG
+ Copyright (C) 2022-2022 Bareos GmbH & Co. KG
This program is Free Software; you can redistribute it and/or
modify it under the terms of version three of the GNU Affero General Public
@@ -19,11 +18,6 @@
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301, USA.
*/
-// Marco van Wieringen, June 2014
-/**
- * @file
- * Dynamic loading of SD backend plugins.
- */
#ifndef BAREOS_STORED_SD_BACKENDS_H_
#define BAREOS_STORED_SD_BACKENDS_H_
@@ -32,18 +26,8 @@
namespace storagedaemon {
-class BackendInterface {
- public:
- virtual ~BackendInterface() = default;
- virtual Device* GetDevice() = 0;
-};
-
-template <typename T> class Backend : public BackendInterface {
- public:
- Device* GetDevice(void) override { return new T(); }
-};
-
-template <typename T> BackendInterface* BackendFactory(void) { return new T(); }
+class Device;
+template <typename T> Device* DeviceFactory(void) { return new T(); }
#if defined(HAVE_DYNAMIC_SD_BACKENDS)
bool LoadStorageBackend(const std::string& dev_type,
@@ -52,8 +36,8 @@ bool LoadStorageBackend(const std::string& dev_type,
#define REGISTER_SD_BACKEND(backend_name, backend_class) \
[[maybe_unused]] static bool backend_name##_backend_ \
- = PluginRegistry<BackendInterface>::Add( \
- #backend_name, BackendFactory<Backend<backend_class>>);
+ = PluginRegistry<Device>::Add(#backend_name, \
+ DeviceFactory<backend_class>);
} // namespace storagedaemon
diff --git a/core/src/stored/sd_backends_dynamic.cc b/core/src/stored/sd_backends_dynamic.cc
index 4917f08b9..e73a0028c 100644
--- a/core/src/stored/sd_backends_dynamic.cc
+++ b/core/src/stored/sd_backends_dynamic.cc
@@ -65,7 +65,7 @@ bool LoadStorageBackend(const std::string& dev_type,
return false;
}
- if (!PluginRegistry<BackendInterface>::IsRegistered(dev_type)) {
+ if (!PluginRegistry<Device>::IsRegistered(dev_type)) {
Jmsg(nullptr, M_ERROR_TERM, 0,
"Loaded backend library for %s did not register its backend. This is "
"probably a bug in the backend library.\n",
diff --git a/core/src/stored/stored_conf.cc b/core/src/stored/stored_conf.cc
index 990f25101..8e6640e2a 100644
--- a/core/src/stored/stored_conf.cc
+++ b/core/src/stored/stored_conf.cc
@@ -547,20 +547,17 @@ static void GuessMissingDeviceTypes(ConfigurationParser& my_config)
static void CheckAndLoadDeviceBackends(ConfigurationParser& my_config)
{
- PluginRegistry<BackendInterface>::DumpDbg();
-
#if defined(HAVE_DYNAMIC_SD_BACKENDS)
auto storage_res
= dynamic_cast<StorageResource*>(my_config.GetNextRes(R_STORAGE, NULL));
#endif
BareosResource* p = nullptr;
-
while ((p = my_config.GetNextRes(R_DEVICE, p)) != nullptr) {
DeviceResource* d = dynamic_cast<DeviceResource*>(p);
if (d) {
to_lower(d->dev_type);
- if (!PluginRegistry<BackendInterface>::IsRegistered(d->dev_type)) {
+ if (!PluginRegistry<Device>::IsRegistered(d->dev_type)) {
#if defined(HAVE_DYNAMIC_SD_BACKENDS)
if (!storage_res || storage_res->backend_directories.empty()) {
Jmsg2(nullptr, M_ERROR_TERM, 0,