ChimeraTK-DeviceAccess 03.31.00
Loading...
Searching...
No Matches
BackendFactory.h
Go to the documentation of this file.
1// SPDX-FileCopyrightText: Deutsches Elektronen-Synchrotron DESY, MSK, ChimeraTK Project <chimeratk-support@desy.de>
2// SPDX-License-Identifier: LGPL-3.0-or-later
3#pragma once
4
5#include "DeviceAccessVersion.h"
6#include "DeviceInfoMap.h"
8
9#include <boost/function.hpp>
10
11#include <map>
12#include <mutex>
13
14namespace ChimeraTK {
15
20 public:
26 void setDMapFilePath(std::string dMapFilePath);
27
29 std::string getDMapFilePath();
30
48 void registerBackendType(const std::string& backendType,
49 boost::shared_ptr<DeviceBackend> (*creatorFunction)(
50 std::string address, std::map<std::string, std::string> parameters),
51 const std::vector<std::string>& sdmParameterNames = {},
52 const std::string& deviceAccessVersion = CHIMERATK_DEVICEACCESS_VERSION);
53
58 [[deprecated]] void registerBackendType(const std::string& interface, const std::string& protocol,
59 boost::shared_ptr<DeviceBackend> (*creatorFunction)(
60 std::string host, std::string instance, std::list<std::string> parameters, std::string mapFileName),
61 const std::string& version);
62
67 boost::shared_ptr<DeviceBackend> createBackend(const std::string& aliasOrUri);
68
71
74 void loadPluginLibrary(const std::string& soFile);
75
76 protected:
77 std::string _dMapFile;
78
81 std::map<std::string,
82 boost::function<boost::shared_ptr<DeviceBackend>(
83 std::string address, std::map<std::string, std::string> parameters)>>
85
88 std::map<std::pair<std::string, std::string>,
89 boost::function<boost::shared_ptr<DeviceBackend>(
90 std::string host, std::string instance, std::list<std::string> parameters, std::string mapFileName)>>
92
94 std::string aliasLookUp(std::string aliasName, std::string dmapFilePath);
95
97 boost::shared_ptr<DeviceBackend> createBackendInternal(const DeviceInfoMap::DeviceInfo& deviceInfo);
98
101 std::map<std::string, boost::weak_ptr<DeviceBackend>> _existingBackends;
102
105 std::mutex _mutex;
106
107 // A function which has the signature of a creator function, plus one string
108 // 'exception_what'. If a plugins fails to register, this function is bound to
109 // an error string and stored in the creatorMap. It later it is tried to open
110 // the backend, an exception with this error message is thrown.
111 static boost::shared_ptr<DeviceBackend> failedRegistrationThrowerFunction(std::string host, std::string instance,
112 std::list<std::string> parameters, std::string mapFileName, std::string exception_what);
113
117
121
122 private:
123 // These functions are not to be inherited. As also the constructor is
124 // private, you cannot derrive from this class.
128
130 BackendFactory(BackendFactory const&&) noexcept;
131 void operator=(BackendFactory const&);
132 };
133
134} // namespace ChimeraTK
BackendFactory is a the factory class to create devices.
static BackendFactory & getInstance()
Static function to get an instance of factory.
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.
std::mutex _mutex
A mutex to protect backend creation and returning to keep the maps consistent.
std::map< std::string, boost::weak_ptr< DeviceBackend > > _existingBackends
A map of all created backends.
boost::shared_ptr< DeviceBackend > createBackendInternal(const DeviceInfoMap::DeviceInfo &deviceInfo)
Internal function to return a DeviceBackend.
void setDMapFilePath(std::string dMapFilePath)
This function sets the _DMapFilePath.
bool called_registerBackendType
Flag whether the function registerBackendType() was called.
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.
boost::shared_ptr< DeviceBackend > createBackend(const std::string &aliasOrUri)
Create a new backend and return the instance as a shared pointer.
std::string getDMapFilePath()
Returns the _DMapFilePath.
void loadPluginLibrary(const std::string &soFile)
Load a shared library (.so file) with a Backend at run time.
std::string aliasLookUp(std::string aliasName, std::string dmapFilePath)
Look for the alias and if found return a uri.
static boost::shared_ptr< DeviceBackend > failedRegistrationThrowerFunction(std::string host, std::string instance, std::list< std::string > parameters, std::string mapFileName, std::string exception_what)
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.
void loadAllPluginsFromDMapFile()
Load all shared libraries specified in the dmap file.
Stores information about one device.
This header collects some conversion routines which should be useful both for ApplicationCore Python ...