ChimeraTK-DeviceAccess  03.18.00
VariableDistributor.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 "AsyncAccessorManager.h"
7 
8 #include <memory>
9 
10 namespace ChimeraTK::async {
11 
12  template<typename SourceType>
14  public:
15  VariableDistributor(boost::shared_ptr<DeviceBackend> backend, boost::shared_ptr<SubDomain<SourceType>> parent,
16  boost::shared_ptr<Domain> asyncDomain);
17 
18  template<typename UserType>
19  std::unique_ptr<AsyncVariable> createAsyncVariable(AccessorInstanceDescriptor const& descriptor);
20 
21  boost::shared_ptr<SubDomain<SourceType>> _parent;
22  };
23 
24  /********************************************************************************************************************/
25 
26  template<typename SourceType, typename UserType>
27  class GenericAsyncVariable : public AsyncVariableImpl<UserType> {
28  public:
29  GenericAsyncVariable(SourceType& dataBuffer, VersionNumber& v, unsigned int nChannels, unsigned int nElements)
30  : AsyncVariableImpl<UserType>(nChannels, nElements), _dataBuffer(dataBuffer), _version(v) {}
31 
32  // implement fillSendBuffer() in a derrived class for template specialisation
33 
36  const std::string& getUnit() override { return _emptyString; }
37 
40  const std::string& getDescription() override { return _emptyString; }
41 
42  protected:
43  std::string _emptyString{};
44  SourceType& _dataBuffer;
46  };
47 
48  /********************************************************************************************************************/
49 
50  // partial template specialisation by inheritance for void
51  template<typename UserType>
52  class VoidAsyncVariable : public GenericAsyncVariable<std::nullptr_t, UserType> {
54  void fillSendBuffer() final;
55  };
56 
57  /********************************************************************************************************************/
58  // Implementations
59  /********************************************************************************************************************/
60  template<typename SourceType>
61  VariableDistributor<SourceType>::VariableDistributor(boost::shared_ptr<DeviceBackend> backend,
62  boost::shared_ptr<SubDomain<SourceType>> parent, boost::shared_ptr<Domain> asyncDomain)
63  : SourceTypedAsyncAccessorManager<SourceType>(backend, asyncDomain), _parent(std::move(parent)) {
65  }
66 
67  /********************************************************************************************************************/
68 
69  // currently only for void
70  template<>
71  template<typename UserType>
74  // for the full implementation
75  // - extract size from catalogue and instance descriptor
76  return std::make_unique<VoidAsyncVariable<UserType>>(_sourceBuffer, _version, 1, 1);
77  }
78 
79  /********************************************************************************************************************/
80  template<typename UserType>
82  // We know that the SourceBuffer contains nullptr. We don't have a conversion formula for that to user type
83  // (especially for string). But we know how to convert ChimeraTK::Void, so we do this instead.
84  this->_sendBuffer.value[0][0] = userTypeToUserType<UserType, ChimeraTK::Void>({});
85  this->_sendBuffer.versionNumber = this->_version;
86  }
87 
88 } // namespace ChimeraTK::async
ChimeraTK::async::VariableDistributor::VariableDistributor
VariableDistributor(boost::shared_ptr< DeviceBackend > backend, boost::shared_ptr< SubDomain< SourceType >> parent, boost::shared_ptr< Domain > asyncDomain)
Definition: VariableDistributor.h:61
ChimeraTK::async::GenericAsyncVariable::getDescription
const std::string & getDescription() override
Make template specialisations on the SourceType in case the source data contains a description.
Definition: VariableDistributor.h:40
ChimeraTK::async::VoidAsyncVariable
Definition: VariableDistributor.h:52
ChimeraTK::async::GenericAsyncVariable::_emptyString
std::string _emptyString
Definition: VariableDistributor.h:43
ChimeraTK::async::GenericAsyncVariable
Definition: VariableDistributor.h:27
ChimeraTK::async::GenericAsyncVariable::_dataBuffer
SourceType & _dataBuffer
Definition: VariableDistributor.h:44
ChimeraTK::async::SubDomain
Send backend-specific asynchronous data to different distributors:
Definition: MuxedInterruptDistributor.h:23
ChimeraTK::async
Definition: design_AsyncNDRegisterAcessor_and_NumericAddressedBackend.dox:1
MuxedInterruptDistributor.h
FILL_VIRTUAL_FUNCTION_TEMPLATE_VTABLE
#define FILL_VIRTUAL_FUNCTION_TEMPLATE_VTABLE(functionName)
Fill the vtable of a virtual function template defined with DEFINE_VIRTUAL_FUNCTION_TEMPLATE.
Definition: VirtualFunctionTemplate.h:84
ChimeraTK::async::AsyncVariableImpl
AsyncVariableImpl contains a weak pointer to an AsyncNDRegisterAccessor<UserType> and a send buffer N...
Definition: AsyncAccessorManager.h:166
ChimeraTK::async::SourceTypedAsyncAccessorManager
Definition: AsyncAccessorManager.h:135
ChimeraTK::async::AccessorInstanceDescriptor
Helper class to have a complete descriton to create an Accessor.
Definition: AsyncAccessorManager.h:47
ChimeraTK::async::VariableDistributor::_parent
boost::shared_ptr< SubDomain< SourceType > > _parent
Definition: VariableDistributor.h:21
ChimeraTK::async::VariableDistributor::createAsyncVariable
std::unique_ptr< AsyncVariable > createAsyncVariable(AccessorInstanceDescriptor const &descriptor)
ChimeraTK::async::GenericAsyncVariable::getUnit
const std::string & getUnit() override
Make template specialisations on the SourceType in case the source data contains a unit.
Definition: VariableDistributor.h:36
ChimeraTK::async::GenericAsyncVariable::GenericAsyncVariable
GenericAsyncVariable(SourceType &dataBuffer, VersionNumber &v, unsigned int nChannels, unsigned int nElements)
Definition: VariableDistributor.h:29
AsyncAccessorManager.h
ChimeraTK::VersionNumber
Class for generating and holding version numbers without exposing a numeric representation.
Definition: VersionNumber.h:23
ChimeraTK::async::GenericAsyncVariable::_version
VersionNumber & _version
Definition: VariableDistributor.h:45
ChimeraTK::async::VariableDistributor
Definition: VariableDistributor.h:13