ChimeraTK-DeviceAccess  03.18.00
ChimeraTK::BackendFactory Class Reference

BackendFactory is a the factory class to create devices. More...

#include <BackendFactory.h>

+ Collaboration diagram for ChimeraTK::BackendFactory:

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< DeviceBackendcreateBackend (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 BackendFactorygetInstance ()
 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< DeviceBackendcreateBackendInternal (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< DeviceBackendfailedRegistrationThrowerFunction (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...
 

Detailed Description

BackendFactory is a the factory class to create devices.

It is implemented as a Meyers' singleton.

Definition at line 26 of file BackendFactory.h.

Member Function Documentation

◆ aliasLookUp()

std::string ChimeraTK::BackendFactory::aliasLookUp ( std::string  aliasName,
std::string  dmapFilePath 
)
protected

Look for the alias and if found return a uri.

◆ createBackend()

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.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ createBackendInternal()

boost::shared_ptr< DeviceBackend > ChimeraTK::BackendFactory::createBackendInternal ( const DeviceInfoMap::DeviceInfo deviceInfo)
protected

Internal function to return a DeviceBackend.

Definition at line 222 of file BackendFactory.cc.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ failedRegistrationThrowerFunction()

boost::shared_ptr< DeviceBackend > ChimeraTK::BackendFactory::failedRegistrationThrowerFunction ( std::string  host,
std::string  instance,
std::list< std::string >  parameters,
std::string  mapFileName,
std::string  exception_what 
)
staticprotected

Definition at line 328 of file BackendFactory.cc.

◆ getDMapFilePath()

std::string ChimeraTK::BackendFactory::getDMapFilePath ( )

Returns the _DMapFilePath.

Definition at line 167 of file BackendFactory.cc.

+ Here is the caller graph for this function:

◆ getInstance()

BackendFactory & ChimeraTK::BackendFactory::getInstance ( )
static

Static function to get an instance of factory.

Thread safe in C++11

Examples
CustomBackend.cc.

Definition at line 191 of file BackendFactory.cc.

+ Here is the caller graph for this function:

◆ loadAllPluginsFromDMapFile()

void ChimeraTK::BackendFactory::loadAllPluginsFromDMapFile ( )
protected

Load all shared libraries specified in the dmap file.

Definition at line 302 of file BackendFactory.cc.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ loadPluginLibrary()

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.

+ Here is the caller graph for this function:

◆ registerBackendType() [1/2]

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.

Examples
CustomBackend.cc.

Definition at line 45 of file BackendFactory.cc.

+ Here is the caller graph for this function:

◆ registerBackendType() [2/2]

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.

◆ setDMapFilePath()

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.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Member Data Documentation

◆ _dMapFile

std::string ChimeraTK::BackendFactory::_dMapFile
protected

The dmap file set at run time.

Definition at line 84 of file BackendFactory.h.

◆ _existingBackends

std::map<std::string, boost::weak_ptr<DeviceBackend> > ChimeraTK::BackendFactory::_existingBackends
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.

◆ _mutex

std::mutex ChimeraTK::BackendFactory::_mutex
protected

A mutex to protect backend creation and returning to keep the maps consistent.

Definition at line 112 of file BackendFactory.h.

◆ called_registerBackendType

bool ChimeraTK::BackendFactory::called_registerBackendType {false}
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.

◆ creatorMap

std::map<std::string, boost::function<boost::shared_ptr<DeviceBackend> std::string address, std::map<std::string, std::string> parameters)> > ChimeraTK::BackendFactory::creatorMap
protected

Holds device type and function pointer to the createInstance function of plugin.

Definition at line 91 of file BackendFactory.h.

◆ creatorMap_compat

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)> > ChimeraTK::BackendFactory::creatorMap_compat
protected

Compatibility creatorMap for old-style backends which just take a plain list of parameters.

Definition at line 98 of file BackendFactory.h.


The documentation for this class was generated from the following files: