ChimeraTK-DeviceAccess  03.18.00
DeviceInfoMap.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 
5 #include <boost/shared_ptr.hpp>
6 
7 #include <cstdint>
8 #include <iostream>
9 #include <list>
10 #include <string>
11 #include <vector>
12 
13 namespace ChimeraTK {
14 
25  class DeviceInfoMap {
26  public:
30  class DeviceInfo {
31  public:
32  std::string deviceName;
33  std::string uri;
35  std::string mapFileName;
37  std::string dmapFileName;
38  uint32_t dmapFileLineNumber;
44  DeviceInfo();
45 
55  [[nodiscard]] std::pair<std::string, std::string> getDeviceFileAndMapFileName() const;
56 
57  friend std::ostream& operator<<(std::ostream& os, const DeviceInfo& deviceInfo);
58  };
59 
60  using iterator = std::vector<DeviceInfo>::iterator;
61  using const_iterator = std::vector<DeviceInfo>::const_iterator;
68  class ErrorList {
69  friend class DeviceInfoMap;
70 
71  public:
78  class ErrorElem {
79  public:
86  };
87 
95  enum TYPE {
98  };
116  ErrorElem(TYPE infoType, DMAP_FILE_ERR errorType, const DeviceInfoMap::DeviceInfo& device1,
117  const DeviceInfoMap::DeviceInfo& device2);
118  friend std::ostream& operator<<(std::ostream& os, const TYPE& me);
119  friend std::ostream& operator<<(std::ostream& os, const ErrorElem& me);
120  };
121  std::list<ErrorElem> _errors;
124  friend std::ostream& operator<<(std::ostream& os, const ErrorList& me);
125 
126  private:
130  void clear();
135  void insert(const ErrorElem& elem);
136  };
151  bool check(ErrorList& err, ErrorList::ErrorElem::TYPE level);
152 
153  friend std::ostream& operator<<(std::ostream& os, const DeviceInfoMap& deviceInfoMap);
163  void getDeviceInfo(const std::string& deviceName, DeviceInfo& value);
169  size_t getSize();
176  iterator begin();
177  [[nodiscard]] const_iterator begin() const;
184  iterator end();
185  [[nodiscard]] const_iterator end() const;
186 
189  std::vector<std::string> getPluginLibraries();
190 
193  void addPluginLibrary(const std::string& soFile);
194 
195  protected:
196  std::vector<DeviceInfo> _deviceInfoElements;
197  std::string _dmapFileName;
198  std::vector<std::string> _pluginLibraries;
199 
200  public:
209  explicit DeviceInfoMap(std::string fileName);
214  void insert(const DeviceInfo& elem);
215  };
221  using DeviceInfoMapPointer = boost::shared_ptr<DeviceInfoMap>;
222 
223 } // namespace ChimeraTK
ChimeraTK::DeviceInfoMap::DeviceInfo::operator<<
friend std::ostream & operator<<(std::ostream &os, const DeviceInfo &deviceInfo)
Definition: DeviceInfoMap.cc:51
ChimeraTK::DeviceInfoMap::const_iterator
std::vector< DeviceInfo >::const_iterator const_iterator
Definition: DeviceInfoMap.h:61
ChimeraTK::DeviceInfoMap::DeviceInfo::DeviceInfo
DeviceInfo()
Default class constructor.
Definition: DeviceInfoMap.cc:45
ChimeraTK::DeviceInfoMap::ErrorList::ErrorElem::_errorDevice1
DeviceInfoMap::DeviceInfo _errorDevice1
Detailed information about first device that generate error or warning.
Definition: DeviceInfoMap.h:99
ChimeraTK::DeviceInfoMap::ErrorList::ErrorElem::_errorDevice2
DeviceInfoMap::DeviceInfo _errorDevice2
Detailed information about second device that generate error or warning.
Definition: DeviceInfoMap.h:101
ChimeraTK::DeviceInfoMap::iterator
std::vector< DeviceInfo >::iterator iterator
Definition: DeviceInfoMap.h:60
ChimeraTK::DeviceInfoMap::_pluginLibraries
std::vector< std::string > _pluginLibraries
Names of the so files with the plugins.
Definition: DeviceInfoMap.h:198
ChimeraTK::DeviceInfoMap::ErrorList::ErrorElem::_type
TYPE _type
Class of detected problem - ERROR or WARNING.
Definition: DeviceInfoMap.h:104
ChimeraTK::DeviceInfoMap
Definition: DeviceInfoMap.h:25
ChimeraTK::DeviceInfoMap::DeviceInfo::deviceName
std::string deviceName
logical name of the device
Definition: DeviceInfoMap.h:32
ChimeraTK::DeviceInfoMap::DeviceInfo::mapFileName
std::string mapFileName
name of the MAP file storing information about PCIe registers mapping
Definition: DeviceInfoMap.h:35
ChimeraTK::DeviceInfoMap::ErrorList::ErrorElem::WARNING
@ WARNING
Non-critical error was detected.
Definition: DeviceInfoMap.h:97
ChimeraTK::DeviceInfoMap::begin
iterator begin()
Return iterator to first device described in DMAP file.
Definition: DeviceInfoMap.cc:139
ChimeraTK::DeviceInfoMap::end
iterator end()
Return iterator to element after last one in DMAP file.
Definition: DeviceInfoMap.cc:143
ChimeraTK::DeviceInfoMap::getSize
size_t getSize()
Returns number of records in DMAP file.
Definition: DeviceInfoMap.cc:16
ChimeraTK::DeviceInfoMap::ErrorList::ErrorElem::ErrorElem
ErrorElem(TYPE infoType, DMAP_FILE_ERR errorType, const DeviceInfoMap::DeviceInfo &device1, const DeviceInfoMap::DeviceInfo &device2)
Creates obiect that describe one detected error or warning.
Definition: DeviceInfoMap.cc:103
ChimeraTK::DeviceInfoMap::DeviceInfo::dmapFileName
std::string dmapFileName
name of the DMAP file
Definition: DeviceInfoMap.h:37
ChimeraTK::DeviceInfoMap::ErrorList::ErrorElem::TYPE
TYPE
Defines available classes of detected problems.
Definition: DeviceInfoMap.h:95
ChimeraTK::DeviceInfoMap::ErrorList
Stores information about errors and warnings.
Definition: DeviceInfoMap.h:68
ChimeraTK::DeviceInfoMapPointer
boost::shared_ptr< DeviceInfoMap > DeviceInfoMapPointer
Definition: DeviceInfoMap.h:221
ChimeraTK::DeviceInfoMap::DeviceInfo::dmapFileLineNumber
uint32_t dmapFileLineNumber
line number in DMAP file storing listed above information
Definition: DeviceInfoMap.h:38
ChimeraTK::DeviceInfoMap::ErrorList::ErrorElem
Stores detailed information about one error or warning.
Definition: DeviceInfoMap.h:78
ChimeraTK::DeviceInfoMap::ErrorList::ErrorElem::DMAP_FILE_ERR
DMAP_FILE_ERR
Defines available types of detected problems.
Definition: DeviceInfoMap.h:83
ChimeraTK::DeviceInfoMap::check
bool check(ErrorList &err, ErrorList::ErrorElem::TYPE level)
Checks logical correctness of DMAP file.
Definition: DeviceInfoMap.cc:58
ChimeraTK::DeviceInfoMap::_dmapFileName
std::string _dmapFileName
name of DMAP file
Definition: DeviceInfoMap.h:197
ChimeraTK::DeviceInfoMap::DeviceInfoMap
DeviceInfoMap(std::string fileName)
Constructor.
Definition: DeviceInfoMap.cc:14
ChimeraTK::DeviceInfoMap::ErrorList::ErrorElem::_errorType
DMAP_FILE_ERR _errorType
Type of detected problem.
Definition: DeviceInfoMap.h:103
ChimeraTK::DeviceInfoMap::addPluginLibrary
void addPluginLibrary(const std::string &soFile)
Add the name of a library to the list.
Definition: DeviceInfoMap.cc:147
ChimeraTK::DeviceInfoMap::_deviceInfoElements
std::vector< DeviceInfo > _deviceInfoElements
vector storing parsed contents of DMAP file
Definition: DeviceInfoMap.h:196
ChimeraTK::DeviceInfoMap::DeviceInfo
Stores information about one device.
Definition: DeviceInfoMap.h:30
ChimeraTK::DeviceInfoMap::ErrorList::operator<<
friend std::ostream & operator<<(std::ostream &os, const ErrorList &me)
Definition: DeviceInfoMap.cc:131
ChimeraTK::DeviceInfoMap::ErrorList::ErrorElem::operator<<
friend std::ostream & operator<<(std::ostream &os, const TYPE &me)
Definition: DeviceInfoMap.cc:88
ChimeraTK::DeviceInfoMap::operator<<
friend std::ostream & operator<<(std::ostream &os, const DeviceInfoMap &deviceInfoMap)
Definition: DeviceInfoMap.cc:20
ChimeraTK::DeviceInfoMap::ErrorList::_errors
std::list< ErrorElem > _errors
Lists of errors or warnings detected during MAP file correctness checking.
Definition: DeviceInfoMap.h:121
ChimeraTK::DeviceInfoMap::DeviceInfo::uri
std::string uri
uri which describes the device (or name of the device file in /dev in backward compatibility mode)
Definition: DeviceInfoMap.h:33
ChimeraTK::DeviceInfoMap::DeviceInfo::getDeviceFileAndMapFileName
std::pair< std::string, std::string > getDeviceFileAndMapFileName() const
Convenience function to extract the device file name and the map file name as one object (a pair).
Definition: DeviceInfoMap.cc:47
ChimeraTK
Definition: DummyBackend.h:16
ChimeraTK::DeviceInfoMap::insert
void insert(const DeviceInfo &elem)
Insert new element read from DMAP file.
Definition: DeviceInfoMap.cc:32
ChimeraTK::DeviceInfoMap::getDeviceInfo
void getDeviceInfo(const std::string &deviceName, DeviceInfo &value)
Returns information about specified device.
Definition: DeviceInfoMap.cc:36
ChimeraTK::DeviceInfoMap::ErrorList::ErrorElem::NONUNIQUE_DEVICE_NAME
@ NONUNIQUE_DEVICE_NAME
Names of two devices are the same - treated as critical error.
Definition: DeviceInfoMap.h:84
ChimeraTK::DeviceInfoMap::getPluginLibraries
std::vector< std::string > getPluginLibraries()
You can define shared libraries with Backend plugins in the DMAP file.
Definition: DeviceInfoMap.cc:151
ChimeraTK::DeviceInfoMap::ErrorList::ErrorElem::ERROR
@ ERROR
Critical error was detected.
Definition: DeviceInfoMap.h:96