![]() |
ChimeraTK-DeviceAccess 03.20.00
|
BackendFactory is a the factory class to create devices. More...
#include <BackendFactory.h>
Public Member Functions | |
void | setDMapFilePath (std::string dMapFilePath) |
This function sets the _DMapFilePath. | |
std::string | getDMapFilePath () |
Returns the _DMapFilePath. | |
void | registerBackendType (const std::string &backendType, boost::shared_ptr< DeviceBackend >(*creatorFunction)(std::string address, std::map< std::string, std::string > parameters), const std::vector< std::string > &sdmParameterNames={}, const std::string &deviceAccessVersion=CHIMERATK_DEVICEACCESS_VERSION) |
Register a backend by the name backendType with the given creatorFunction. | |
void | registerBackendType (const std::string &interface, const std::string &protocol, boost::shared_ptr< DeviceBackend >(*creatorFunction)(std::string host, std::string instance, std::list< std::string > parameters, std::string mapFileName), const std::string &version) |
Old signature of BackendFactory::registerBackendType(), for compatibility only. | |
boost::shared_ptr< DeviceBackend > | createBackend (const std::string &aliasOrUri) |
Create a new backend and return the instance as a shared pointer. | |
void | loadPluginLibrary (const std::string &soFile) |
Load a shared library (.so file) with a Backend at run time. | |
Static Public Member Functions | |
static BackendFactory & | getInstance () |
Static function to get an instance of factory. | |
Protected Member Functions | |
std::string | aliasLookUp (std::string aliasName, std::string dmapFilePath) |
Look for the alias and if found return a uri. | |
boost::shared_ptr< DeviceBackend > | createBackendInternal (const DeviceInfoMap::DeviceInfo &deviceInfo) |
Internal function to return a DeviceBackend. | |
void | loadAllPluginsFromDMapFile () |
Load all shared libraries specified in the dmap file. | |
Static Protected Member Functions | |
static boost::shared_ptr< DeviceBackend > | failedRegistrationThrowerFunction (std::string host, std::string instance, std::list< std::string > parameters, std::string mapFileName, std::string exception_what) |
Protected Attributes | |
std::string | _dMapFile |
The dmap file set at run time. | |
std::map< std::string, boost::function< boost::shared_ptr< DeviceBackend >(std::string address, std::map< std::string, std::string > parameters)> > | creatorMap |
Holds device type and function pointer to the createInstance function of plugin. | |
std::map< std::pair< std::string, std::string >, boost::function< boost::shared_ptr< DeviceBackend >(std::string host, std::string instance, std::list< std::string > parameters, std::string mapFileName)> > | creatorMap_compat |
Compatibility creatorMap for old-style backends which just take a plain list of parameters. | |
std::map< std::string, boost::weak_ptr< DeviceBackend > > | _existingBackends |
A map of all created backends. | |
std::mutex | _mutex |
A mutex to protect backend creation and returning to keep the maps consistent. | |
bool | called_registerBackendType {false} |
Flag whether the function registerBackendType() was called. | |
BackendFactory is a the factory class to create devices.
It is implemented as a Meyers' singleton.
Definition at line 19 of file BackendFactory.h.
|
protected |
Look for the alias and if found return a uri.
boost::shared_ptr< DeviceBackend > ChimeraTK::BackendFactory::createBackend | ( | const std::string & | aliasOrUri | ) |
Create a new backend and return the instance as a shared pointer.
The input argument can either be an alias name from a dmap file, or an sdm::/ URI.
Definition at line 202 of file BackendFactory.cc.
|
protected |
Internal function to return a DeviceBackend.
Definition at line 223 of file BackendFactory.cc.
|
staticprotected |
Definition at line 329 of file BackendFactory.cc.
std::string ChimeraTK::BackendFactory::getDMapFilePath | ( | ) |
Returns the _DMapFilePath.
Definition at line 168 of file BackendFactory.cc.
|
static |
Static function to get an instance of factory.
Thread safe in C++11
Definition at line 192 of file BackendFactory.cc.
|
protected |
Load all shared libraries specified in the dmap file.
Definition at line 303 of file BackendFactory.cc.
void ChimeraTK::BackendFactory::loadPluginLibrary | ( | const std::string & | soFile | ) |
Load a shared library (.so file) with a Backend at run time.
Definition at line 282 of file BackendFactory.cc.
void ChimeraTK::BackendFactory::registerBackendType | ( | const std::string & | backendType, |
boost::shared_ptr< DeviceBackend >(*)(std::string address, std::map< std::string, std::string > parameters) | creatorFunction, | ||
const std::vector< std::string > & | sdmParameterNames = {} , |
||
const std::string & | deviceAccessVersion = CHIMERATK_DEVICEACCESS_VERSION |
||
) |
Register a backend by the name backendType with the given creatorFunction.
If a backend by the given name is already registered, a ChimeraTK::logic_error is thrown.
The optional parameter sdmParameterNames specifies a list of key names, which is used when a device is created using a SDM URI. The parameters from the (unkeyed) parameter list of the SDM are put into in order the parameter map by the keys specified in sdmParameterNames. If sdmParameterNames is left empty, the device cannot be created through a SDM URI when parameters need to be specified.
The last argument deviceAccessVersion must always be set to CHIMERATK_DEVICEACCESS_VERSION as defined in DeviceAccessVersion.h. This is automatically the case if the argument is omitted, so it should never be specified.
Definition at line 46 of file BackendFactory.cc.
void ChimeraTK::BackendFactory::registerBackendType | ( | const std::string & | interface, |
const std::string & | protocol, | ||
boost::shared_ptr< DeviceBackend >(*)(std::string host, std::string instance, std::list< std::string > parameters, std::string mapFileName) | creatorFunction, | ||
const std::string & | version | ||
) |
Old signature of BackendFactory::registerBackendType(), for compatibility only.
Please use only the new form which allows to pass key-equal-value pairs for the parameters. DO NOT call this function in addition to the new signature!
Definition at line 115 of file BackendFactory.cc.
void ChimeraTK::BackendFactory::setDMapFilePath | ( | std::string | dMapFilePath | ) |
This function sets the _DMapFilePath.
This dmap file path is the second path where factory looks for dmap file. The first location where dmap file path is searched by library is set by enviroment variable.
Definition at line 162 of file BackendFactory.cc.
|
protected |
The dmap file set at run time.
Definition at line 77 of file BackendFactory.h.
|
protected |
A map of all created backends.
If the same URI is located again, the existing backend is returned.
Definition at line 101 of file BackendFactory.h.
|
protected |
A mutex to protect backend creation and returning to keep the maps consistent.
Definition at line 105 of file BackendFactory.h.
|
protected |
Flag whether the function registerBackendType() was called.
This is used to determine if a loaded plugin registered any backends.
Definition at line 120 of file BackendFactory.h.
|
protected |
Holds device type and function pointer to the createInstance function of plugin.
Definition at line 84 of file BackendFactory.h.
|
protected |
Compatibility creatorMap for old-style backends which just take a plain list of parameters.
Definition at line 91 of file BackendFactory.h.