ChimeraTK-DeviceAccess  03.18.00
DummyInterruptTriggerAccessor.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 
5 
6 #include "DummyBackendBase.h"
7 
8 namespace ChimeraTK {
9 
10  /********************************************************************************************************************/
11 
12  template<typename UserType>
14  std::function<VersionNumber(void)> interruptTrigger, const RegisterPath& registerPathName,
15  size_t numberOfElements, size_t elementsOffset, const AccessModeFlags& flags)
16  : NDRegisterAccessor<UserType>(registerPathName, {}),
17  _backend(boost::dynamic_pointer_cast<DummyBackendBase>(backend)), _interruptTrigger(std::move(interruptTrigger)) {
18  assert(_backend); // Accessor created with wrong backend type?
19 
20  if(numberOfElements > 1) {
21  throw ChimeraTK::logic_error("DUMMY_INTERRUPT accessor register can have at most one element");
22  }
23 
24  if(elementsOffset != 0) {
25  throw ChimeraTK::logic_error("DUMMY_INTERRUPT accessor register cannot have any offset");
26  }
27 
28  flags.checkForUnknownFlags({});
29 
32  NDRegisterAccessor<UserType>::buffer_2D[0][0] = numericToUserType<UserType>(0);
33  }
34 
35  /********************************************************************************************************************/
36 
37  template<typename UserType>
39  _interruptTrigger();
40 
41  return false;
42  }
43 
44  /********************************************************************************************************************/
45 
46  template<typename UserType>
48  throw ChimeraTK::logic_error("Cannot read from write-only accessor.");
49  }
50 
51  /********************************************************************************************************************/
52 
53  template<typename UserType>
55  //
56  if(not _backend->isOpen()) {
57  throw ChimeraTK::logic_error("Device is not opened.");
58  }
59 
60  if(_backend->throwExceptionWrite) {
61  _backend->throwExceptionCounter++;
62  throw ChimeraTK::runtime_error("DummyBackend: exception on write requested by user");
63  }
64 
65  _backend->checkActiveException();
66  }
67 
68  /********************************************************************************************************************/
69 
71 } // namespace ChimeraTK
ChimeraTK::DummyInterruptTriggerAccessor
The DummyInterruptTriggerAccessor class.
Definition: DummyInterruptTriggerAccessor.h:21
ChimeraTK::NDRegisterAccessor::buffer_2D
std::vector< std::vector< UserType > > buffer_2D
Buffer of converted data elements.
Definition: NDRegisterAccessor.h:123
ChimeraTK::runtime_error
Exception thrown when a runtime error has occured.
Definition: Exception.h:18
ChimeraTK::DummyInterruptTriggerAccessor::DummyInterruptTriggerAccessor
DummyInterruptTriggerAccessor(boost::shared_ptr< DeviceBackend > backend, std::function< VersionNumber(void)> interruptTrigger, const RegisterPath &registerPathName, size_t numberOfElements=1, size_t elementsOffset=0, const AccessModeFlags &flags={})
Definition: DummyInterruptTriggerAccessor.cc:13
ChimeraTK::DummyInterruptTriggerAccessor::doPreRead
void doPreRead(TransferType) override
Definition: DummyInterruptTriggerAccessor.cc:47
ChimeraTK::DummyInterruptTriggerAccessor::doWriteTransfer
bool doWriteTransfer(ChimeraTK::VersionNumber) override
Definition: DummyInterruptTriggerAccessor.cc:38
DummyInterruptTriggerAccessor.h
ChimeraTK::DummyInterruptTriggerAccessor::doPreWrite
void doPreWrite(TransferType, VersionNumber) override
Definition: DummyInterruptTriggerAccessor.cc:54
ChimeraTK::TransferType
TransferType
Used to indicate the applicable operation on a Transferelement.
Definition: TransferElement.h:51
ChimeraTK::INSTANTIATE_TEMPLATE_FOR_CHIMERATK_USER_TYPES
INSTANTIATE_TEMPLATE_FOR_CHIMERATK_USER_TYPES(LNMBackendBitAccessor)
ChimeraTK::RegisterPath
Class to store a register path name.
Definition: RegisterPath.h:16
ChimeraTK::VersionNumber
Class for generating and holding version numbers without exposing a numeric representation.
Definition: VersionNumber.h:23
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::NDRegisterAccessor
N-dimensional register accessor.
Definition: ForwardDeclarations.h:17
ChimeraTK::logic_error
Exception thrown when a logic error has occured.
Definition: Exception.h:51