ChimeraTK-DeviceAccess  03.18.00
LNMDoubleBufferPlugin.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 "LNMAccessorPlugin.h"
9 #include "TransferElement.h"
10 
11 #include <string>
12 
13 namespace ChimeraTK::LNMBackend {
14  class DoubleBufferPlugin : public AccessorPlugin<DoubleBufferPlugin> {
15  template<typename UserType>
17 
18  public:
20  const LNMBackendRegisterInfo& info, size_t pluginIndex, std::map<std::string, std::string> parameters);
21 
22  void doRegisterInfoUpdate() override;
23 
24  template<typename UserType, typename TargetType>
25  boost::shared_ptr<NDRegisterAccessor<UserType>> decorateAccessor(
26  boost::shared_ptr<LogicalNameMappingBackend>& backend,
27  boost::shared_ptr<NDRegisterAccessor<TargetType>>& target, const UndecoratedParams& accessorParams);
28 
29  private:
30  struct ReaderCount {
31  uint32_t value = 0;
32  std::mutex mutex;
33  };
34  std::map<std::string, std::string> _parameters;
35  std::string _targetDeviceName;
36  // number of currently active reader threads
37  ReaderCount _readerCount;
38  };
39 
40  template<typename UserType>
42  public:
45 
46  DoubleBufferAccessorDecorator(boost::shared_ptr<LogicalNameMappingBackend>& backend,
47  boost::shared_ptr<NDRegisterAccessor<UserType>>& target, DoubleBufferPlugin& plugin,
48  const UndecoratedParams& accessorParams);
49 
50  void doPreRead(TransferType type) override;
51 
52  void doReadTransferSynchronously() override;
53 
54  void doPostRead(TransferType type, bool hasNewData) override;
55 
56  [[nodiscard]] bool isWriteable() const override { return false; }
57 
59  throw ChimeraTK::logic_error("LogicalNameMappingBackend DoubleBufferPlugin: Writing is not allowed.");
60  }
61 
63  // do not throw here again
64  }
65 
66  // below functions are needed for TransferGroup to work
67  std::vector<boost::shared_ptr<TransferElement>> getHardwareAccessingElements() override;
68 
69  std::list<boost::shared_ptr<TransferElement>> getInternalElements() override { return {}; }
70 
71  void replaceTransferElement(boost::shared_ptr<ChimeraTK::TransferElement> /* newElement */) override {
72  // do nothing, we do not support merging of DoubleBufferAccessorDecorators
73  }
74  [[nodiscard]] bool mayReplaceOther(const boost::shared_ptr<TransferElement const>& other) const override;
75 
76  private:
77  // we know that plugin exists at least as long as any register (of the catalogue) refers to it,
78  // so no shared_ptr required here
79  DoubleBufferPlugin& _plugin;
80  boost::shared_ptr<ChimeraTK::NDRegisterAccessor<UserType>> _secondBufferReg;
81 
82  boost::shared_ptr<ChimeraTK::NDRegisterAccessor<uint32_t>> _enableDoubleBufferReg;
83  boost::shared_ptr<ChimeraTK::NDRegisterAccessor<uint32_t>> _currentBufferNumberReg;
84  uint32_t _currentBuffer{0};
85  // FIXME - remove testUSleep feature
86  uint32_t _testUSleep{0};
87  };
88 
89 } // namespace ChimeraTK::LNMBackend
ChimeraTK::LNMBackend::DoubleBufferAccessorDecorator::doPostWrite
void doPostWrite(TransferType, VersionNumber) override
Definition: LNMDoubleBufferPlugin.h:62
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::DoubleBufferAccessorDecorator::isWriteable
bool isWriteable() const override
Definition: LNMDoubleBufferPlugin.h:56
ChimeraTK::LNMBackend
Definition: LNMMathPluginFormulaHelper.h:16
TransferElement.h
ChimeraTK::LNMBackend::DoubleBufferPlugin::decorateAccessor
boost::shared_ptr< NDRegisterAccessor< UserType > > decorateAccessor(boost::shared_ptr< LogicalNameMappingBackend > &backend, boost::shared_ptr< NDRegisterAccessor< TargetType >> &target, const UndecoratedParams &accessorParams)
Definition: LNMDoubleBufferPlugin.cc:30
LogicalNameMappingBackend.h
ChimeraTK::LNMBackend::DoubleBufferAccessorDecorator::getHardwareAccessingElements
std::vector< boost::shared_ptr< TransferElement > > getHardwareAccessingElements() override
Definition: LNMDoubleBufferPlugin.cc:205
ChimeraTK::LNMBackend::DoubleBufferAccessorDecorator::doPreWrite
void doPreWrite(TransferType, VersionNumber) override
Definition: LNMDoubleBufferPlugin.h:58
ChimeraTK::LNMBackend::DoubleBufferPlugin::DoubleBufferPlugin
DoubleBufferPlugin(const LNMBackendRegisterInfo &info, size_t pluginIndex, std::map< std::string, std::string > parameters)
Definition: LNMDoubleBufferPlugin.cc:9
NDRegisterAccessorDecorator.h
ChimeraTK::LNMBackend::UndecoratedParams
Helper struct to hold extra parameters needed by some plugins, used in decorateAccessor()
Definition: LNMAccessorPlugin.h:13
ChimeraTK::LNMBackend::DoubleBufferAccessorDecorator::getInternalElements
std::list< boost::shared_ptr< TransferElement > > getInternalElements() override
Definition: LNMDoubleBufferPlugin.h:69
ChimeraTK::LNMBackend::DoubleBufferAccessorDecorator::DoubleBufferAccessorDecorator
DoubleBufferAccessorDecorator(boost::shared_ptr< LogicalNameMappingBackend > &backend, boost::shared_ptr< NDRegisterAccessor< UserType >> &target, DoubleBufferPlugin &plugin, const UndecoratedParams &accessorParams)
Definition: LNMDoubleBufferPlugin.cc:41
ChimeraTK::LNMBackendRegisterInfo
RegisterInfo structure for the LogicalNameMappingBackend.
Definition: LNMBackendRegisterInfo.h:22
ChimeraTK::TransferType
TransferType
Used to indicate the applicable operation on a Transferelement.
Definition: TransferElement.h:51
ChimeraTK::LNMBackend::DoubleBufferPlugin::doRegisterInfoUpdate
void doRegisterInfoUpdate() override
Implementation of the plugin specific register information update.
Definition: LNMDoubleBufferPlugin.cc:21
ChimeraTK::LNMBackend::DoubleBufferPlugin
Definition: LNMDoubleBufferPlugin.h:14
ChimeraTK::LNMBackend::DoubleBufferAccessorDecorator::doPreRead
void doPreRead(TransferType type) override
Definition: LNMDoubleBufferPlugin.cc:115
ChimeraTK::NDRegisterAccessorDecorator
Base class for decorators of the NDRegisterAccessor.
Definition: NDRegisterAccessorDecorator.h:120
ChimeraTK::LNMBackend::DoubleBufferAccessorDecorator
Definition: LNMDoubleBufferPlugin.h:41
ChimeraTK::VersionNumber
Class for generating and holding version numbers without exposing a numeric representation.
Definition: VersionNumber.h:23
ChimeraTK::LNMBackend::DoubleBufferAccessorDecorator::doPostRead
void doPostRead(TransferType type, bool hasNewData) override
Definition: LNMDoubleBufferPlugin.cc:154
LNMBackendRegisterInfo.h
ChimeraTK::LNMBackend::DoubleBufferAccessorDecorator::replaceTransferElement
void replaceTransferElement(boost::shared_ptr< ChimeraTK::TransferElement >) override
Definition: LNMDoubleBufferPlugin.h:71
ChimeraTK::LNMBackend::DoubleBufferAccessorDecorator::doReadTransferSynchronously
void doReadTransferSynchronously() override
Definition: LNMDoubleBufferPlugin.cc:144
ChimeraTK::LNMBackend::DoubleBufferAccessorDecorator::mayReplaceOther
bool mayReplaceOther(const boost::shared_ptr< TransferElement const > &other) const override
Definition: LNMDoubleBufferPlugin.cc:212
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