ChimeraTK-DeviceAccess 03.25.00
Loading...
Searching...
No Matches
LNMForceReadOnlyPlugin.cc
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
4#include "LNMAccessorPlugin.h"
7#include "TransferElement.h"
8
9#include <boost/make_shared.hpp>
10
11namespace ChimeraTK::LNMBackend {
12
13 /********************************************************************************************************************/
14
16 const LNMBackendRegisterInfo& info, size_t pluginIndex, const std::map<std::string, std::string>&)
17 : AccessorPlugin(info, pluginIndex) {}
18
19 /********************************************************************************************************************/
20
22 // Change register info to read-only
23 _info.writeable = false;
24 }
25
26 /********************************************************************************************************************/
27
28 template<typename UserType>
31
33 : ChimeraTK::NDRegisterAccessorDecorator<UserType>(target) {
34 // make sure the target register is writeable and scalar
35 if(!target->isReadable()) {
37 "LogicalNameMappingBackend ForceReadOnlyPlugin: Cannot target non-readable register.");
38 }
39 }
40
41 [[nodiscard]] bool isWriteable() const override { return false; }
42
44 throw ChimeraTK::logic_error("LogicalNameMappingBackend ForceReadOnlyPlugin: Writing is not allowed.");
45 }
46
48 // do not throw here again
49 }
50 };
51
52 /********************************************************************************************************************/
53
54 template<typename UserType, typename TargetType>
55 boost::shared_ptr<NDRegisterAccessor<UserType>> ForceReadOnlyPlugin::decorateAccessor(
56 boost::shared_ptr<LogicalNameMappingBackend>&, boost::shared_ptr<NDRegisterAccessor<TargetType>>& target,
57 const UndecoratedParams&) {
58 if constexpr(std::is_same<UserType, TargetType>::value) {
59 return boost::make_shared<ForceReadOnlyPluginDecorator<UserType>>(target);
60 }
61
62 assert(false);
63
64 return {};
65 }
66} // namespace ChimeraTK::LNMBackend
LNMBackendRegisterInfo _info
RegisterInfo describing the the target register for which this plugin instance should work.
Base class for plugins that modify the behaviour of accessors in the logical name mapping backend.
void doRegisterInfoUpdate() override
Implementation of the plugin specific register information update.
ForceReadOnlyPlugin(const LNMBackendRegisterInfo &info, size_t pluginIndex, const std::map< std::string, std::string > &parameters)
boost::shared_ptr< NDRegisterAccessor< UserType > > decorateAccessor(boost::shared_ptr< LogicalNameMappingBackend > &backend, boost::shared_ptr< NDRegisterAccessor< TargetType > > &target, const UndecoratedParams &accessorParams)
RegisterInfo structure for the LogicalNameMappingBackend.
bool writeable
Flag if the register is writeable.
Base class for decorators of the NDRegisterAccessor.
N-dimensional register accessor.
std::vector< std::vector< UserType > > buffer_2D
Buffer of converted data elements.
Class for generating and holding version numbers without exposing a numeric representation.
Exception thrown when a logic error has occured.
Definition Exception.h:51
TransferType
Used to indicate the applicable operation on a Transferelement.
void doPostWrite(TransferType, VersionNumber) override
Backend specific implementation of postWrite().
bool isWriteable() const override
Check if transfer element is writeable.
void doPreWrite(TransferType, VersionNumber) override
Backend specific implementation of preWrite().
ForceReadOnlyPluginDecorator(const boost::shared_ptr< ChimeraTK::NDRegisterAccessor< UserType > > &target)
Helper struct to hold extra parameters needed by some plugins, used in decorateAccessor()