ChimeraTK-DeviceAccess 03.25.00
Loading...
Searching...
No Matches
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
10
11#include <sstream>
12
13// macro to avoid code duplication
14#define TRY_REGISTER_ACCESS(COMMAND) \
15 try { \
16 COMMAND \
17 } \
18 catch(std::out_of_range & outOfRangeException) { \
19 std::stringstream errorMessage; \
20 errorMessage << "Invalid address offset " << address << " in bar " << bar << "." \
21 << "Caught out_of_range exception: " << outOfRangeException.what(); \
22 std::cout << errorMessage.str() << std::endl; \
23 throw ChimeraTK::logic_error(errorMessage.str()); \
24 }
25
26namespace ChimeraTK {
31 public:
32 explicit DummyBackendBase(std::string const& mapFileName, const std::string& dataConsistencyKeyDescriptor = "");
33
34 ~DummyBackendBase() override = default;
35
36 size_t minimumTransferAlignment([[maybe_unused]] uint64_t bar) const override;
37
38 // Declare that we are going to override getRegisterAccessor_impl
40 boost::shared_ptr<NDRegisterAccessor<T>>(const RegisterPath&, size_t, size_t, AccessModeFlags));
41
49 virtual VersionNumber triggerInterrupt(uint32_t interruptNumber) = 0;
50
54 void read([[maybe_unused]] uint8_t bar, [[maybe_unused]] uint32_t address, [[maybe_unused]] int32_t* data,
55 [[maybe_unused]] size_t sizeInBytes) final {
56 throw;
57 }
58
62 void write([[maybe_unused]] uint8_t bar, [[maybe_unused]] uint32_t address, [[maybe_unused]] int32_t const* data,
63 [[maybe_unused]] size_t sizeInBytes) final {
64 throw;
65 }
66
68 bool barIndexValid([[maybe_unused]] uint64_t bar) override;
69
71 std::map<uint64_t, size_t> getBarSizesInBytesFromRegisterMapping() const;
72
73 static void checkSizeIsMultipleOfWordSize(size_t sizeInBytes);
74
75 std::atomic<bool> throwExceptionOpen{false};
76 std::atomic<bool> throwExceptionRead{false};
77 std::atomic<bool> throwExceptionWrite{false};
78 std::atomic<size_t> throwExceptionCounter{0};
79
81 template<typename UserType>
82 boost::shared_ptr<NDRegisterAccessor<UserType>> getRegisterAccessor_impl(
83 const RegisterPath& registerPathName, size_t numberOfWords, size_t wordOffsetInRegister, AccessModeFlags flags);
84
100 template<typename T, typename... Args>
101 static boost::shared_ptr<DeviceBackend> returnInstance(
102 [[maybe_unused]] const std::string& instanceId, Args&&... arguments) {
103 return boost::make_shared<T>(std::forward<Args>(arguments)...);
104 }
105
106 // Helper function to get x from DUMMY_INTERRUPT_x.
107 // The first element of the returned pair is "true" if an according interrupt is in the catalogue. If the
108 // registerPathName is not DUMMY_INTERRUPT_x or the interrupt is not in the catalogue, the first element is
109 // "false", and the second/ parameter is invalid.
110 std::pair<bool, int> extractControllerInterrupt(const RegisterPath& registerPathName) const;
111
112 }; // class DummyBackendBase
113
114} // namespace ChimeraTK
Set of AccessMode flags with additional functionality for an easier handling.
Definition AccessMode.h:48
Base class for DummyBackends, provides common functionality.
std::pair< bool, int > extractControllerInterrupt(const RegisterPath &registerPathName) const
std::atomic< bool > throwExceptionWrite
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.
static void checkSizeIsMultipleOfWordSize(size_t sizeInBytes)
size_t minimumTransferAlignment(uint64_t bar) const override
Determines the supported minimum alignment for any read/write requests.
void write(uint8_t bar, uint32_t address, int32_t const *data, size_t sizeInBytes) final
You cannot override the write version with 32 bit address any more.
static boost::shared_ptr< DeviceBackend > returnInstance(const std::string &instanceId, Args &&... arguments)
Backward compatibility: Leftover from the time when the dummy managed it's own map to return the same...
std::map< uint64_t, size_t > getBarSizesInBytesFromRegisterMapping() const
Determines the size of each bar because the DummyBackends allocate memory per bar.
void read(uint8_t bar, uint32_t address, int32_t *data, size_t sizeInBytes) final
You cannot override the read version with 32 bit address any more.
std::atomic< bool > throwExceptionRead
virtual VersionNumber triggerInterrupt(uint32_t interruptNumber)=0
Simulate the arrival of an interrupt.
bool barIndexValid(uint64_t bar) override
All bars are valid in dummies.
std::atomic< size_t > throwExceptionCounter
DEFINE_VIRTUAL_FUNCTION_OVERRIDE_VTABLE(NumericAddressedBackend, getRegisterAccessor_impl, boost::shared_ptr< NDRegisterAccessor< T > >(const RegisterPath &, size_t, size_t, AccessModeFlags))
std::atomic< bool > throwExceptionOpen
~DummyBackendBase() override=default
N-dimensional register accessor.
Base class for address-based device backends (e.g.
Class to store a register path name.
Class for generating and holding version numbers without exposing a numeric representation.