|
RTC Toolkit 5.1.0
|
A simple registry of various factory objects. More...
#include <factoryRegistry.hpp>
Classes | |
| class | FactoryIf |
| The base class for all factory objects that are registered in the FactoryRegistry. More... | |
Public Types | |
| using | AdapterIdType = typename BaseIf::AdapterIdType |
Public Member Functions | |
| FactoryRegistry ()=default | |
| ~FactoryRegistry () | |
| void | Register (const FactoryIf *factory) |
| Register the factory if it was not already registered. | |
| void | Deregister (const FactoryIf *factory) noexcept |
| Remove the factory from the registry if it was already registered. | |
| const FactoryIf * | FindCompatibleFactory (const AdapterIdType &id) const noexcept |
| Finds the first factory that can handle the given identifier. | |
Static Public Member Functions | |
| static std::shared_ptr< FactoryRegistry< BaseIf > > | GetInstance () |
| Returns the registry singleton. | |
A simple registry of various factory objects.
This is effectively a polymorphic container of factory instances deriving from FactoryIf. The purpose of the registry is to allow registration in a single place of factories for service adapters, e.g. repository adapters, that are implemented in different shared libraries. There should be only one instance of a registry in the process for any particular abstract/base interface type given by BaseIf, i.e. for each template specialisation. Thus, various libraries should be accessing the registry through the singleton returned by the GetInstance() method, and not instantiating this class directly.
The factory registry is used to implement generic factory functions/methods for various services represented by a particular interface, e.g. to implement RuntimeRepoIf::CreateAdapter, which can have different adapters implemented for different supported backends, e.g. RuntimeRepoAdapter versus FileRuntimeRepoAdapter. By registering a factory for a particular adapter using the RegisterFactory helper class, it is possible to have different adapters implemented in different shared libraries and made available when the shared library is loaded dynamically or linked against, without needing to modify the generic factory function/method, e.g. the RuntimeRepoIf::CreateAdapter method in the above example.
| BaseIf | The abstract/base interface class of the service adapter instances created by the factories that are registered with the registry. |
| using rtctk::componentFramework::FactoryRegistry< BaseIf >::AdapterIdType = typename BaseIf::AdapterIdType |
|
default |
|
noexcept |
Remove the factory from the registry if it was already registered.
If the factory has been previously registered then it will be removed from the registry. Otherwise this is a no-op if the factory is not already registered.
| [in] | factory | The factory instance that should be deregistered. |
|
noexcept |
Finds the first factory that can handle the given identifier.
The available factories will be searched in the order that they were registered in, i.e. the shared library load order. The first one for which the FactoryIf::CanHandle method returns true will be returned by this method.
| [in] | id | The identifier for which a compatible factory will be found. This could be a URI for example, depending on the AdapterIdType. |
nullptr if no supporting factory can be found.
|
static |
Returns the registry singleton.
This singleton should be used for registering, deregistering and finding supported factories.
| void rtctk::componentFramework::FactoryRegistry< BaseIf >::Register | ( | const FactoryIf * | factory | ) |
Register the factory if it was not already registered.
If the factory has not yet been added to the registry yet, it will be added. Otherwise this is a no-op if the factory is already registered.
| [in] | factory | The factory instance that should be registered. |