ChimeraTK-DeviceAccess 03.25.00
Loading...
Searching...
No Matches
LogicalNameMappingBackend.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
6#include "DeviceBackendImpl.h"
8#include "LNMVariable.h"
9
10#include <mutex>
11#include <unordered_set>
12#include <utility>
13
14namespace ChimeraTK {
15
20 public:
21 explicit LogicalNameMappingBackend(std::string lmapFileName = "");
22
23 void open() override;
24
25 void close() override;
26
27 std::string readDeviceInfo() override { return std::string("Logical name mapping file: ") + _lmapFileName; }
28
29 static boost::shared_ptr<DeviceBackend> createInstance(
30 std::string address, std::map<std::string, std::string> parameters);
31
33
34 void setExceptionImpl() noexcept override;
35
36 void activateAsyncRead() noexcept override;
37
38 template<typename UserType>
39 boost::shared_ptr<NDRegisterAccessor<UserType>> getRegisterAccessor_impl(const RegisterPath& registerPathName,
40 size_t numberOfWords, size_t wordOffsetInRegister, AccessModeFlags flags, size_t omitPlugins = 0);
41
42 template<typename UserType>
43 boost::shared_ptr<NDRegisterAccessor<UserType>> getRegisterAccessor_internal(
44 const RegisterPath& registerPathName, size_t numberOfWords, size_t wordOffsetInRegister, AccessModeFlags flags);
45
47
49 void parse() const;
50
52 mutable bool hasParsed;
53
56
58 mutable std::map<std::string, boost::shared_ptr<DeviceBackend>> _devices;
59
61 std::map<std::string, std::string> _parameters;
62
66 // mutable LNMRegisterCatalogue _catalogue_mutable;
69 mutable bool catalogueCompleted{false};
70
72 template<typename UserType>
74 boost::weak_ptr<NDRegisterAccessor<UserType>> accessor;
75 std::recursive_mutex mutex;
76 };
77
81 using AccessorKey = std::pair<DeviceBackend*, RegisterPath>;
82 template<typename UserType>
83 using SharedAccessorMap = std::map<AccessorKey, SharedAccessor<UserType>>;
87
91 mutable std::map<std::string /*name*/, LNMVariable> _variables;
92
93 template<typename T>
95
96 template<typename T>
98
99 template<typename T>
101
102 template<typename T>
104
106 std::atomic<bool> _asyncReadActive{false};
107
109 std::unordered_set<std::string> getTargetDevices() const;
110
111 private:
112 // A version number created when opening the backend. All variables will report this version number until they are
113 // changed for the first time after opening the device.
114 std::atomic<ChimeraTK::VersionNumber> _versionOnOpen{ChimeraTK::VersionNumber{nullptr}};
115
116 public:
118 };
119
120} // namespace ChimeraTK
Set of AccessMode flags with additional functionality for an easier handling.
Definition AccessMode.h:48
Interface for backends to the register catalogue.
The base class for backends providing IO functionality for the Device class.
DeviceBackendImpl implements some basic functionality which should be available for all backends.
RegisterInfo structure for the LogicalNameMappingBackend.
Backend to map logical register names onto real hardware registers.
BackendRegisterCatalogue< LNMBackendRegisterInfo > _catalogue_mutable
We need to make the catalogue mutable, since we fill it within getRegisterCatalogue()
std::set< DeviceBackend::BackendID > getInvolvedBackendIDs() override
Get the backend IDs of all involved backends.
std::unordered_set< std::string > getTargetDevices() const
Obtain list of all target devices referenced in the catalogue.
static boost::shared_ptr< DeviceBackend > createInstance(std::string address, std::map< std::string, std::string > parameters)
std::pair< DeviceBackend *, RegisterPath > AccessorKey
Map of target accessors which are potentially shared across our accessors.
void parse() const
parse the logical map file, if not yet done
std::map< AccessorKey, SharedAccessor< UserType > > SharedAccessorMap
RegisterCatalogue getRegisterCatalogue() const override
Return the register catalogue with detailed information on all registers.
ChimeraTK::VersionNumber getVersionOnOpen() const
std::map< std::string, boost::shared_ptr< DeviceBackend > > _devices
map of target devices
std::atomic< bool > _asyncReadActive
Flag storing whether asynchronous read has been activated.
boost::shared_ptr< NDRegisterAccessor< UserType > > getRegisterAccessor_internal(const RegisterPath &registerPathName, size_t numberOfWords, size_t wordOffsetInRegister, AccessModeFlags flags)
std::string readDeviceInfo() override
Return a device information string containing hardware details like the firmware version number or th...
boost::shared_ptr< NDRegisterAccessor< UserType > > getRegisterAccessor_impl(const RegisterPath &registerPathName, size_t numberOfWords, size_t wordOffsetInRegister, AccessModeFlags flags, size_t omitPlugins=0)
void setExceptionImpl() noexcept override
Function to be (optionally) implemented by backends if additional actions are needed when switching t...
std::map< std::string, LNMVariable > _variables
Map of variables and constants.
void activateAsyncRead() noexcept override
Activate asyncronous read for all transfer elements where AccessMode::wait_for_new_data is set.
std::mutex sharedAccessorMap_mutex
a mutex to be locked when sharedAccessorMap (the container) is changed
bool catalogueCompleted
Flag whether the catalogue has already been filled with extra information from the target backends.
TemplateUserTypeMap< SharedAccessorMap > sharedAccessorMap
std::map< std::string, std::string > _parameters
map of parameters passed through the CDD
std::string _lmapFileName
name of the logical map file
N-dimensional register accessor.
Catalogue of register information.
Class to store a register path name.
Map of UserType to a class template with the UserType as template argument.
Class for generating and holding version numbers without exposing a numeric representation.
STL namespace.
Struct holding shared accessors together with a mutex for thread safety.
boost::weak_ptr< NDRegisterAccessor< UserType > > accessor