ChimeraTK-DeviceAccess 03.25.00
Loading...
Searching...
No Matches
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
13namespace 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:
44 using ChimeraTK::NDRegisterAccessorDecorator<UserType>::_target;
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
Base class for plugins that modify the behaviour of accessors in the logical name mapping backend.
void doPreWrite(TransferType, VersionNumber) override
Backend specific implementation of preWrite().
void doReadTransferSynchronously() override
Implementation version of readTransfer() for synchronous reads.
void doPostRead(TransferType type, bool hasNewData) override
Backend specific implementation of postRead().
void replaceTransferElement(boost::shared_ptr< ChimeraTK::TransferElement >) override
bool isWriteable() const override
Check if transfer element is writeable.
std::list< boost::shared_ptr< TransferElement > > getInternalElements() override
Obtain the full list of TransferElements internally used by this TransferElement.
std::vector< boost::shared_ptr< TransferElement > > getHardwareAccessingElements() override
Obtain the underlying TransferElements with actual hardware access.
bool mayReplaceOther(const boost::shared_ptr< TransferElement const > &other) const override
Check whether the TransferElement can be used in places where the TransferElement "other" is currentl...
void doPostWrite(TransferType, VersionNumber) override
Backend specific implementation of postWrite().
void doPreRead(TransferType type) override
Backend specific implementation of preRead().
void doRegisterInfoUpdate() override
Implementation of the plugin specific register information update.
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.
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.
Helper struct to hold extra parameters needed by some plugins, used in decorateAccessor()