ChimeraTK-DeviceAccess  03.18.00
DummyBackendRegisterCatalogue.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 <regex>
7 
8 namespace ChimeraTK {
9 
10  constexpr auto DUMMY_WRITEABLE_SUFFIX = "DUMMY_WRITEABLE";
11  constexpr auto DUMMY_READABLE_SUFFIX = "DUMMY_READABLE";
12 
13  /********************************************************************************************************************/
14 
16  const RegisterPath& registerPathName) const {
17  auto path = registerPathName;
18  path.setAltSeparator(".");
19  if(path.endsWith(DUMMY_WRITEABLE_SUFFIX) || path.endsWith(DUMMY_READABLE_SUFFIX)) {
20  auto basePath = path;
21  basePath--;
24  return info;
25  }
26  if(registerPathName.startsWith("DUMMY_INTERRUPT_") && hasRegister(registerPathName)) {
27  NumericAddressedRegisterInfo info(registerPathName, 0 /*nElements*/, 0 /*address*/, 0 /*nBytes*/, 0 /*bar*/,
28  0 /*width*/, 0 /*facBits*/, false /*signed*/, NumericAddressedRegisterInfo::Access::WRITE_ONLY,
30  return info;
31  }
33  }
34 
35  /********************************************************************************************************************/
36 
37  bool DummyBackendRegisterCatalogue::hasRegister(const RegisterPath& registerPathName) const {
38  auto path = registerPathName;
39  path.setAltSeparator(".");
40  if(path.endsWith(DUMMY_WRITEABLE_SUFFIX) || path.endsWith(DUMMY_READABLE_SUFFIX)) {
41  auto basePath = path;
42  basePath--;
44  }
45  if(extractControllerInterrupt(registerPathName).first) {
46  return true;
47  }
49  }
50 
51  /********************************************************************************************************************/
52 
54  const RegisterPath& registerPathName) const {
55  static const std::string DUMMY_INTERRUPT_REGISTER_NAME{"^/DUMMY_INTERRUPT_([0-9]+)$"};
56 
57  const std::string regPathNameStr{registerPathName};
58  const std::regex dummyInterruptRegex{DUMMY_INTERRUPT_REGISTER_NAME};
59  std::smatch match;
60  std::regex_search(regPathNameStr, match, dummyInterruptRegex);
61 
62  if(not match.empty()) {
63  // FIXME: Ideally, this test and the need for passing in the lambda function should be done
64  // in the constructor of the accessor. But passing down the base-class of the backend is very weird
65  // due to the sort-of CRTP pattern used in this base class.
66  auto primaryInterrupt = static_cast<unsigned int>(std::stoul(match[1].str()));
67  for(auto& interruptID : _listOfInterrupts) {
68  if(interruptID.front() == primaryInterrupt) {
69  return {true, primaryInterrupt};
70  }
71  }
72  }
73  return {false, 0};
74  }
75  /********************************************************************************************************************/
76 
77  std::unique_ptr<BackendRegisterCatalogueBase> DummyBackendRegisterCatalogue::clone() const {
78  // FIXME: Copy of NumericAddressedRegisterCatalogue. We don't have different data types
79  // or additional data members, but need an instance of DummyBackendRegisterCatalogue
80  // for the special functions.
81  // This should go away once the pattern is changed to a CRTP, so the base classes know the
82  // actual type they are.
83  std::unique_ptr<BackendRegisterCatalogueBase> c = std::make_unique<DummyBackendRegisterCatalogue>();
84  auto* c_impl = dynamic_cast<DummyBackendRegisterCatalogue*>(c.get());
85  fillFromThis(c_impl);
86  c_impl->_listOfInterrupts = _listOfInterrupts;
87  c_impl->_canonicalInterrupts = _canonicalInterrupts;
88  return c;
89  }
90 
91  /********************************************************************************************************************/
92 
93 } // namespace ChimeraTK
ChimeraTK::NumericAddressedRegisterCatalogue::getBackendRegister
NumericAddressedRegisterInfo getBackendRegister(const RegisterPath &registerPathName) const override
Note: Override this function if backend has "hidden" registers which are not added to the map and hen...
Definition: NumericAddressedRegisterCatalogue.cc:209
ChimeraTK::DummyBackendRegisterCatalogue::hasRegister
bool hasRegister(const RegisterPath &registerPathName) const override
Check if register with the given path name exists.
Definition: DummyBackendRegisterCatalogue.cc:37
ChimeraTK::NumericAddressedRegisterInfo
Definition: NumericAddressedRegisterCatalogue.h:15
ChimeraTK::NumericAddressedRegisterInfo::Type::VOID
@ VOID
ChimeraTK::RegisterPath::setAltSeparator
void setAltSeparator(const std::string &altSeparator)
set alternative separator.
Definition: RegisterPath.h:37
ChimeraTK::DummyBackendRegisterCatalogue
Definition: DummyBackendRegisterCatalogue.h:11
ChimeraTK::RegisterPath::startsWith
bool startsWith(const RegisterPath &compare) const
check if the register path starts with the given path
Definition: RegisterPath.h:141
ChimeraTK::DUMMY_READABLE_SUFFIX
constexpr auto DUMMY_READABLE_SUFFIX
Definition: DummyBackendRegisterCatalogue.cc:11
DummyBackendRegisterCatalogue.h
ChimeraTK::BackendRegisterCatalogue< NumericAddressedRegisterInfo >::fillFromThis
void fillFromThis(BackendRegisterCatalogue< NumericAddressedRegisterInfo > *target) const
Helper function for clone functions.
Definition: BackendRegisterCatalogue.h:328
ChimeraTK::DummyBackendRegisterCatalogue::clone
std::unique_ptr< BackendRegisterCatalogueBase > clone() const override
Create deep copy of the catalogue.
Definition: DummyBackendRegisterCatalogue.cc:77
ChimeraTK::DummyBackendRegisterCatalogue::getBackendRegister
NumericAddressedRegisterInfo getBackendRegister(const RegisterPath &registerPathName) const override
Note: Override this function if backend has "hidden" registers which are not added to the map and hen...
Definition: DummyBackendRegisterCatalogue.cc:15
ChimeraTK::RegisterPath
Class to store a register path name.
Definition: RegisterPath.h:16
ChimeraTK::NumericAddressedRegisterInfo::Access::WRITE_ONLY
@ WRITE_ONLY
ChimeraTK::DUMMY_WRITEABLE_SUFFIX
constexpr auto DUMMY_WRITEABLE_SUFFIX
Definition: DummyBackendRegisterCatalogue.cc:10
ChimeraTK::DummyBackendRegisterCatalogue::extractControllerInterrupt
std::pair< bool, int > extractControllerInterrupt(const RegisterPath &registerPathName) const
Definition: DummyBackendRegisterCatalogue.cc:53
ChimeraTK::NumericAddressedRegisterInfo::Access::READ_WRITE
@ READ_WRITE
ChimeraTK::NumericAddressedRegisterCatalogue::hasRegister
bool hasRegister(const RegisterPath &registerPathName) const override
Check if register with the given path name exists.
Definition: NumericAddressedRegisterCatalogue.cc:250
ChimeraTK
Definition: DummyBackend.h:16
ChimeraTK::NumericAddressedRegisterCatalogue::_canonicalInterrupts
std::map< RegisterPath, std::vector< size_t > > _canonicalInterrupts
A canonical interrupt path consists of an exclamation mark, followed by a numeric interrupt and a col...
Definition: NumericAddressedRegisterCatalogue.h:163
ChimeraTK::NumericAddressedRegisterCatalogue::_listOfInterrupts
std::set< std::vector< size_t > > _listOfInterrupts
set of interrupt IDs.
Definition: NumericAddressedRegisterCatalogue.h:152