ChimeraTK-DeviceAccess  03.18.00
DummyBackendBase.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 
11 
12 #include <sstream>
13 
14 // macro to avoid code duplication
15 #define TRY_REGISTER_ACCESS(COMMAND) \
16  try { \
17  COMMAND \
18  } \
19  catch(std::out_of_range & outOfRangeException) { \
20  std::stringstream errorMessage; \
21  errorMessage << "Invalid address offset " << address << " in bar " << bar << "." \
22  << "Caught out_of_range exception: " << outOfRangeException.what(); \
23  std::cout << errorMessage.str() << std::endl; \
24  throw ChimeraTK::logic_error(errorMessage.str()); \
25  }
26 
27 namespace ChimeraTK {
32  public:
33  explicit DummyBackendBase(std::string const& mapFileName);
34 
35  ~DummyBackendBase() override = default;
36 
37  size_t minimumTransferAlignment([[maybe_unused]] uint64_t bar) const override;
38 
39  // Declare that we are going to override getRegisterAccessor_impl
41  boost::shared_ptr<NDRegisterAccessor<T>>(const RegisterPath&, size_t, size_t, AccessModeFlags));
42 
50  virtual VersionNumber triggerInterrupt(uint32_t interruptNumber) = 0;
51 
55  void read([[maybe_unused]] uint8_t bar, [[maybe_unused]] uint32_t address, [[maybe_unused]] int32_t* data,
56  [[maybe_unused]] size_t sizeInBytes) final {
57  throw;
58  }
59 
63  void write([[maybe_unused]] uint8_t bar, [[maybe_unused]] uint32_t address, [[maybe_unused]] int32_t const* data,
64  [[maybe_unused]] size_t sizeInBytes) final {
65  throw;
66  }
67 
69  bool barIndexValid([[maybe_unused]] uint64_t bar) override;
70 
72  std::map<uint64_t, size_t> getBarSizesInBytesFromRegisterMapping() const;
73 
74  static void checkSizeIsMultipleOfWordSize(size_t sizeInBytes);
75 
76  std::atomic<bool> throwExceptionOpen{false};
77  std::atomic<bool> throwExceptionRead{false};
78  std::atomic<bool> throwExceptionWrite{false};
79  std::atomic<size_t> throwExceptionCounter{0};
80 
82  template<typename UserType>
83  boost::shared_ptr<NDRegisterAccessor<UserType>> getRegisterAccessor_impl(
84  const RegisterPath& registerPathName, size_t numberOfWords, size_t wordOffsetInRegister, AccessModeFlags flags);
85 
101  template<typename T, typename... Args>
102  static boost::shared_ptr<DeviceBackend> returnInstance(
103  [[maybe_unused]] const std::string& instanceId, Args&&... arguments) {
104  return boost::make_shared<T>(std::forward<Args>(arguments)...);
105  }
106 
107  }; // class DummyBackendBase
108 
109 } // namespace ChimeraTK
ChimeraTK::DummyBackendBase::read
void read([[maybe_unused]] uint8_t bar, [[maybe_unused]] uint32_t address, [[maybe_unused]] int32_t *data, [[maybe_unused]] size_t sizeInBytes) final
You cannot override the read version with 32 bit address any more.
Definition: DummyBackendBase.h:55
ChimeraTK::DummyBackendBase::throwExceptionWrite
std::atomic< bool > throwExceptionWrite
Definition: DummyBackendBase.h:78
ChimeraTK::DummyBackendBase::DEFINE_VIRTUAL_FUNCTION_OVERRIDE_VTABLE
DEFINE_VIRTUAL_FUNCTION_OVERRIDE_VTABLE(NumericAddressedBackend, getRegisterAccessor_impl, boost::shared_ptr< NDRegisterAccessor< T >>(const RegisterPath &, size_t, size_t, AccessModeFlags))
ChimeraTK::DummyBackendBase::~DummyBackendBase
~DummyBackendBase() override=default
ChimeraTK::DummyBackendBase::DummyBackendBase
DummyBackendBase(std::string const &mapFileName)
Definition: DummyBackendBase.cc:8
ChimeraTK::DummyBackendBase::returnInstance
static boost::shared_ptr< DeviceBackend > returnInstance([[maybe_unused]] const std::string &instanceId, Args &&... arguments)
Backward compatibility: Leftover from the time when the dummy managed it's own map to return the same...
Definition: DummyBackendBase.h:102
ChimeraTK::DummyBackendBase::barIndexValid
bool barIndexValid([[maybe_unused]] uint64_t bar) override
All bars are valid in dummies.
Definition: DummyBackendBase.cc:19
ChimeraTK::DummyBackendBase::getBarSizesInBytesFromRegisterMapping
std::map< uint64_t, size_t > getBarSizesInBytesFromRegisterMapping() const
Determines the size of each bar because the DummyBackends allocate memory per bar.
Definition: DummyBackendBase.cc:23
ChimeraTK::DummyBackendBase
Base class for DummyBackends, provides common functionality.
Definition: DummyBackendBase.h:31
ChimeraTK::DummyBackendBase::throwExceptionCounter
std::atomic< size_t > throwExceptionCounter
Definition: DummyBackendBase.h:79
ChimeraTK::DummyBackendBase::throwExceptionOpen
std::atomic< bool > throwExceptionOpen
Definition: DummyBackendBase.h:76
ChimeraTK::DummyBackendBase::triggerInterrupt
virtual VersionNumber triggerInterrupt(uint32_t interruptNumber)=0
Simulate the arrival of an interrupt.
ChimeraTK::DummyBackendBase::getRegisterAccessor_impl
boost::shared_ptr< NDRegisterAccessor< UserType > > getRegisterAccessor_impl(const RegisterPath &registerPathName, size_t numberOfWords, size_t wordOffsetInRegister, AccessModeFlags flags)
Specific override which allows to create "DUMMY_INTEERRUPT_X" accessors.
Definition: DummyBackendBase.cc:42
ChimeraTK::DummyBackendBase::checkSizeIsMultipleOfWordSize
static void checkSizeIsMultipleOfWordSize(size_t sizeInBytes)
Definition: DummyBackendBase.cc:35
ChimeraTK::DummyBackendBase::write
void write([[maybe_unused]] uint8_t bar, [[maybe_unused]] uint32_t address, [[maybe_unused]] int32_t const *data, [[maybe_unused]] size_t sizeInBytes) final
You cannot override the write version with 32 bit address any more.
Definition: DummyBackendBase.h:63
NumericAddressedBackend.h
ChimeraTK::NumericAddressedBackend
Base class for address-based device backends (e.g.
Definition: NumericAddressedBackend.h:20
DummyInterruptTriggerAccessor.h
NumericAddressedBackendRegisterAccessor.h
DummyBackendRegisterCatalogue.h
ChimeraTK::RegisterPath
Class to store a register path name.
Definition: RegisterPath.h:16
AsyncNDRegisterAccessor.h
ChimeraTK::VersionNumber
Class for generating and holding version numbers without exposing a numeric representation.
Definition: VersionNumber.h:23
NumericAddressedBackendMuxedRegisterAccessor.h
ChimeraTK::DummyBackendBase::minimumTransferAlignment
size_t minimumTransferAlignment([[maybe_unused]] uint64_t bar) const override
Determines the supported minimum alignment for any read/write requests.
Definition: DummyBackendBase.cc:14
ChimeraTK::AccessModeFlags
Set of AccessMode flags with additional functionality for an easier handling.
Definition: AccessMode.h:48
ChimeraTK::DummyBackendBase::throwExceptionRead
std::atomic< bool > throwExceptionRead
Definition: DummyBackendBase.h:77
ChimeraTK
Definition: DummyBackend.h:16
ChimeraTK::NDRegisterAccessor< T >