ChimeraTK-DeviceAccess
03.18.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. More... | |
std::string | getDMapFilePath () |
Returns the _DMapFilePath. More... | |
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. More... | |
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. More... | |
boost::shared_ptr< DeviceBackend > | createBackend (const std::string &aliasOrUri) |
Create a new backend and return the instance as a shared pointer. More... | |
void | loadPluginLibrary (const std::string &soFile) |
Load a shared library (.so file) with a Backend at run time. More... | |
Static Public Member Functions | |
static BackendFactory & | getInstance () |
Static function to get an instance of factory. More... | |
Protected Member Functions | |
std::string | aliasLookUp (std::string aliasName, std::string dmapFilePath) |
Look for the alias and if found return a uri. More... | |
boost::shared_ptr< DeviceBackend > | createBackendInternal (const DeviceInfoMap::DeviceInfo &deviceInfo) |
Internal function to return a DeviceBackend. More... | |
void | loadAllPluginsFromDMapFile () |
Load all shared libraries specified in the dmap file. More... | |
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. More... | |
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. More... | |
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. More... | |
std::map< std::string, boost::weak_ptr< DeviceBackend > > | _existingBackends |
A map of all created backends. More... | |
std::mutex | _mutex |
A mutex to protect backend creation and returning to keep the maps consistent. More... | |
bool | called_registerBackendType {false} |
Flag whether the function registerBackendType() was called. More... | |
BackendFactory is a the factory class to create devices.
It is implemented as a Meyers' singleton.
Definition at line 26 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 201 of file BackendFactory.cc.
|
protected |
Internal function to return a DeviceBackend.
Definition at line 222 of file BackendFactory.cc.
|
staticprotected |
Definition at line 328 of file BackendFactory.cc.
std::string ChimeraTK::BackendFactory::getDMapFilePath | ( | ) |
Returns the _DMapFilePath.
Definition at line 167 of file BackendFactory.cc.
|
static |
Static function to get an instance of factory.
Thread safe in C++11
Definition at line 191 of file BackendFactory.cc.
|
protected |
Load all shared libraries specified in the dmap file.
Definition at line 302 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 281 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 45 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 114 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 161 of file BackendFactory.cc.
|
protected |
The dmap file set at run time.
Definition at line 84 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 108 of file BackendFactory.h.
|
protected |
A mutex to protect backend creation and returning to keep the maps consistent.
Definition at line 112 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 127 of file BackendFactory.h.
|
protected |
Holds device type and function pointer to the createInstance function of plugin.
Definition at line 91 of file BackendFactory.h.
|
protected |
Compatibility creatorMap for old-style backends which just take a plain list of parameters.
Definition at line 98 of file BackendFactory.h.