ChimeraTK-DeviceAccess  03.18.00
DummyBackendBase.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 <DummyBackendBase.h>
5 
6 namespace ChimeraTK {
7 
8  DummyBackendBase::DummyBackendBase(std::string const& mapFileName)
9  : NumericAddressedBackend(mapFileName, std::make_unique<DummyBackendRegisterCatalogue>()) {
10  // Copy the old vtable
12  }
13 
14  size_t DummyBackendBase::minimumTransferAlignment([[maybe_unused]] uint64_t bar) const {
15  return 4;
16  }
17 
19  bool DummyBackendBase::barIndexValid([[maybe_unused]] uint64_t bar) {
20  return true;
21  }
22 
23  std::map<uint64_t, size_t> DummyBackendBase::getBarSizesInBytesFromRegisterMapping() const {
24  std::map<uint64_t, size_t> barSizesInBytes;
25  for(auto const& info : _registerMap) {
26  if(info.elementPitchBits % 8 != 0) {
27  throw ChimeraTK::logic_error("DummyBackendBase: Elements have to be byte aligned.");
28  }
29  barSizesInBytes[info.bar] = std::max(
30  barSizesInBytes[info.bar], static_cast<size_t>(info.address + info.nElements * info.elementPitchBits / 8));
31  }
32  return barSizesInBytes;
33  }
34 
36  if(sizeInBytes % sizeof(int32_t)) {
37  throw ChimeraTK::logic_error("Read/write size has to be a multiple of 4");
38  }
39  }
40 
41  template<typename UserType>
42  boost::shared_ptr<NDRegisterAccessor<UserType>> DummyBackendBase::getRegisterAccessor_impl(
43  const RegisterPath& registerPathName, size_t numberOfWords, size_t wordOffsetInRegister, AccessModeFlags flags) {
44  // First check if the request is for one of the special DUMMY_INTEERRUPT_X registers. if so, early return
45  // this special accessor.
46  if(registerPathName.startsWith("DUMMY_INTERRUPT_")) {
47  bool interruptFound;
48  uint32_t interrupt;
49 
50  auto* dummyCatalogue = dynamic_cast<DummyBackendRegisterCatalogue*>(_registerMapPointer.get());
51  assert(dummyCatalogue);
52  std::tie(interruptFound, interrupt) = dummyCatalogue->extractControllerInterrupt(registerPathName);
53  if(!interruptFound) {
54  throw ChimeraTK::logic_error("Unknown dummy interrupt " + registerPathName);
55  }
56 
57  // Delegate the other parameters down to the accessor which will throw accordingly, to satisfy the specification
58  // Since the accessor will keep a shared pointer to the backend, we can safely capture "this"
60  shared_from_this(), [this, interrupt]() { return triggerInterrupt(interrupt); }, registerPathName,
61  numberOfWords, wordOffsetInRegister, flags);
62 
63  return boost::shared_ptr<NDRegisterAccessor<UserType>>(d);
64  }
65 
66  // Chain up to to the base class using the previously stored function
68  numberOfWords, wordOffsetInRegister, flags);
69  }
70 
71 } // namespace ChimeraTK
ChimeraTK::DummyBackendBase::DummyBackendBase
DummyBackendBase(std::string const &mapFileName)
Definition: DummyBackendBase.cc:8
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::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::DummyInterruptTriggerAccessor
The DummyInterruptTriggerAccessor class.
Definition: DummyInterruptTriggerAccessor.h:21
ChimeraTK::DummyBackendBase::checkSizeIsMultipleOfWordSize
static void checkSizeIsMultipleOfWordSize(size_t sizeInBytes)
Definition: DummyBackendBase.cc:35
CALL_BASE_FUNCTION_TEMPLATE
#define CALL_BASE_FUNCTION_TEMPLATE(BaseClass, functionName, templateArgument,...)
Execute the virtual function template call to the base implementation of the function.
Definition: VirtualFunctionTemplate.h:78
ChimeraTK::NumericAddressedBackend::_registerMap
NumericAddressedRegisterCatalogue & _registerMap
Definition: NumericAddressedBackend.h:153
ChimeraTK::NumericAddressedBackend
Base class for address-based device backends (e.g.
Definition: NumericAddressedBackend.h:20
ChimeraTK::DummyBackendRegisterCatalogue
Definition: DummyBackendRegisterCatalogue.h:11
OVERRIDE_VIRTUAL_FUNCTION_TEMPLATE
#define OVERRIDE_VIRTUAL_FUNCTION_TEMPLATE(BaseClass, functionName)
Save the old vtable to be accessible by CALL_BASE_FUNCTION_TEMPLATE and overwrite it with the new imp...
Definition: VirtualFunctionTemplate.h:93
ChimeraTK::RegisterPath::startsWith
bool startsWith(const RegisterPath &compare) const
check if the register path starts with the given path
Definition: RegisterPath.h:141
ChimeraTK::NumericAddressedBackend::_registerMapPointer
std::unique_ptr< NumericAddressedRegisterCatalogue > _registerMapPointer
Definition: NumericAddressedBackend.h:152
ChimeraTK::RegisterPath
Class to store a register path name.
Definition: RegisterPath.h:16
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
DummyBackendBase.h
ChimeraTK
Definition: DummyBackend.h:16
ChimeraTK::logic_error
Exception thrown when a logic error has occured.
Definition: Exception.h:51