ChimeraTK-DeviceAccess  03.18.00
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 
11 namespace 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 
32  explicit ForceReadOnlyPluginDecorator(const boost::shared_ptr<ChimeraTK::NDRegisterAccessor<UserType>>& target)
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
ChimeraTK::LNMBackend::ForceReadOnlyPlugin::doRegisterInfoUpdate
void doRegisterInfoUpdate() override
Implementation of the plugin specific register information update.
Definition: LNMForceReadOnlyPlugin.cc:21
ChimeraTK::LNMBackend::AccessorPlugin
Base class for plugins that modify the behaviour of accessors in the logical name mapping backend.
Definition: LNMAccessorPlugin.h:104
ChimeraTK::LNMBackend
Definition: LNMMathPluginFormulaHelper.h:16
TransferElement.h
NDRegisterAccessorDecorator.h
ChimeraTK::LNMBackend::ForceReadOnlyPluginDecorator
Definition: LNMForceReadOnlyPlugin.cc:29
ChimeraTK::LNMBackend::UndecoratedParams
Helper struct to hold extra parameters needed by some plugins, used in decorateAccessor()
Definition: LNMAccessorPlugin.h:13
ChimeraTK::LNMBackend::ForceReadOnlyPluginDecorator::doPreWrite
void doPreWrite(TransferType, VersionNumber) override
Definition: LNMForceReadOnlyPlugin.cc:43
ChimeraTK::LNMBackendRegisterInfo::writeable
bool writeable
Flag if the register is writeable.
Definition: LNMBackendRegisterInfo.h:103
ChimeraTK::LNMBackend::ForceReadOnlyPlugin::decorateAccessor
boost::shared_ptr< NDRegisterAccessor< UserType > > decorateAccessor(boost::shared_ptr< LogicalNameMappingBackend > &backend, boost::shared_ptr< NDRegisterAccessor< TargetType >> &target, const UndecoratedParams &accessorParams)
Definition: LNMForceReadOnlyPlugin.cc:55
ChimeraTK::LNMBackendRegisterInfo
RegisterInfo structure for the LogicalNameMappingBackend.
Definition: LNMBackendRegisterInfo.h:22
ChimeraTK::LNMBackend::AccessorPluginBase::_info
LNMBackendRegisterInfo _info
RegisterInfo describing the the target register for which this plugin instance should work.
Definition: LNMAccessorPlugin.h:93
ChimeraTK::TransferType
TransferType
Used to indicate the applicable operation on a Transferelement.
Definition: TransferElement.h:51
ChimeraTK::LNMBackend::ForceReadOnlyPluginDecorator::ForceReadOnlyPluginDecorator
ForceReadOnlyPluginDecorator(const boost::shared_ptr< ChimeraTK::NDRegisterAccessor< UserType >> &target)
Definition: LNMForceReadOnlyPlugin.cc:32
ChimeraTK::NDRegisterAccessorDecorator
Base class for decorators of the NDRegisterAccessor.
Definition: NDRegisterAccessorDecorator.h:120
ChimeraTK::LNMBackend::ForceReadOnlyPluginDecorator::isWriteable
bool isWriteable() const override
Definition: LNMForceReadOnlyPlugin.cc:41
ChimeraTK::VersionNumber
Class for generating and holding version numbers without exposing a numeric representation.
Definition: VersionNumber.h:23
ChimeraTK::LNMBackend::ForceReadOnlyPlugin::ForceReadOnlyPlugin
ForceReadOnlyPlugin(const LNMBackendRegisterInfo &info, size_t pluginIndex, const std::map< std::string, std::string > &parameters)
Definition: LNMForceReadOnlyPlugin.cc:15
LNMBackendRegisterInfo.h
ChimeraTK
Definition: DummyBackend.h:16
ChimeraTK::NDRegisterAccessor
N-dimensional register accessor.
Definition: ForwardDeclarations.h:17
LNMAccessorPlugin.h
ChimeraTK::logic_error
Exception thrown when a logic error has occured.
Definition: Exception.h:51
ChimeraTK::LNMBackend::ForceReadOnlyPluginDecorator::doPostWrite
void doPostWrite(TransferType, VersionNumber) override
Definition: LNMForceReadOnlyPlugin.cc:47