ChimeraTK-DeviceAccess 03.25.00
Loading...
Searching...
No Matches
DeviceInfoMap.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 "DeviceInfoMap.h"
5
6#include "Exception.h"
7#include "predicates.h"
8
9#include <algorithm>
10#include <utility>
11
12namespace ChimeraTK {
13
14 DeviceInfoMap::DeviceInfoMap(std::string fileName) : _dmapFileName(std::move(fileName)) {}
15
17 return _deviceInfoElements.size();
18 }
19
20 std::ostream& operator<<(std::ostream& os, const DeviceInfoMap& deviceInfoMap) {
21 size_t size;
22 os << "=======================================" << std::endl;
23 os << "MAP FILE NAME: " << deviceInfoMap._dmapFileName << std::endl;
24 os << "---------------------------------------" << std::endl;
25 for(size = 0; size < deviceInfoMap._deviceInfoElements.size(); size++) {
26 os << deviceInfoMap._deviceInfoElements[size] << std::endl;
27 }
28 os << "=======================================";
29 return os;
30 }
31
33 _deviceInfoElements.push_back(elem);
34 }
35
36 void DeviceInfoMap::getDeviceInfo(const std::string& deviceName, DeviceInfo& value) {
37 std::vector<DeviceInfo>::iterator iter;
38 iter = find_if(_deviceInfoElements.begin(), _deviceInfoElements.end(), findDevByName_pred(deviceName));
39 if(iter == _deviceInfoElements.end()) {
40 throw ChimeraTK::logic_error("Cannot find device \"" + deviceName + "\" in DMAP file:" + _dmapFileName);
41 }
42 value = *iter;
43 }
44
45 DeviceInfoMap::DeviceInfo::DeviceInfo() : dmapFileLineNumber(0) {}
46
47 std::pair<std::string, std::string> DeviceInfoMap::DeviceInfo::getDeviceFileAndMapFileName() const {
48 return {uri, mapFileName};
49 }
50
51 std::ostream& operator<<(std::ostream& os, const DeviceInfoMap::DeviceInfo& deviceInfo) {
52 os << "(" << deviceInfo.dmapFileName << ") NAME: " << deviceInfo.deviceName << " DEV : " << deviceInfo.uri
53 << " MAP : " << deviceInfo.mapFileName;
54 return os;
55 }
56
57 // fixme: why is level not used?
59 std::vector<DeviceInfoMap::DeviceInfo> dmaps = _deviceInfoElements;
60 std::vector<DeviceInfoMap::DeviceInfo>::iterator iter_p, iter_n;
61 bool ret = true;
62
63 err.clear();
64 if(dmaps.size() < 2) {
65 return true;
66 }
67
68 std::sort(dmaps.begin(), dmaps.end(), copmaredRegisterInfosByName2_functor());
69 iter_p = dmaps.begin();
70 iter_n = iter_p + 1;
71 while(true) {
72 if((*iter_p).deviceName == (*iter_n).deviceName) {
73 if((*iter_p).uri != (*iter_n).uri || (*iter_p).mapFileName != (*iter_n).mapFileName) {
74 err.insert(ErrorList::ErrorElem(
76 ret = false;
77 }
78 }
79 iter_p = iter_n;
80 iter_n = ++iter_n;
81 if(iter_n == dmaps.end()) {
82 break;
83 }
84 }
85 return ret;
86 }
87
88 std::ostream& operator<<(std::ostream& os, const DeviceInfoMap::ErrorList::ErrorElem::TYPE& me) {
89 switch(me) {
91 os << "ERROR";
92 break;
94 os << "WARNING";
95 break;
96 default:
97 os << "UNKNOWN";
98 break;
99 }
100 return os;
101 }
102
104 const DeviceInfoMap::DeviceInfo& device1, const DeviceInfoMap::DeviceInfo& device2) {
105 _errorType = errorType;
106 _errorDevice1 = device1;
107 _errorDevice2 = device2;
108 _type = infoType;
109 }
110
111 std::ostream& operator<<(std::ostream& os, const DeviceInfoMap::ErrorList::ErrorElem& me) {
112 switch(me._errorType) {
114 os << me._type << ": Found two devices with the same name but different properties: \""
115 << me._errorDevice1.deviceName << "\" in file \"" << me._errorDevice1.dmapFileName << "\" in line "
116 << me._errorDevice1.dmapFileLineNumber << " and \"" << me._errorDevice2.dmapFileName << "\" in line "
118 break;
119 }
120 return os;
121 }
122
123 void DeviceInfoMap::ErrorList::clear() {
124 _errors.clear();
125 }
126
127 void DeviceInfoMap::ErrorList::insert(const ErrorElem& elem) {
128 _errors.push_back(elem);
129 }
130
131 std::ostream& operator<<(std::ostream& os, const DeviceInfoMap::ErrorList& me) {
132 std::list<DeviceInfoMap::ErrorList::ErrorElem>::const_iterator iter;
133 for(iter = me._errors.begin(); iter != me._errors.end(); ++iter) {
134 os << (*iter) << std::endl;
135 }
136 return os;
137 }
138
142
146
147 void DeviceInfoMap::addPluginLibrary(const std::string& soFile) {
148 _pluginLibraries.push_back(soFile);
149 }
150
151 std::vector<std::string> DeviceInfoMap::getPluginLibraries() {
152 return _pluginLibraries;
153 }
154
155} // namespace ChimeraTK
Stores information about one device.
std::string uri
uri which describes the device (or name of the device file in /dev in backward compatibility mode)
DeviceInfo()
Default class constructor.
std::string dmapFileName
name of the DMAP file
std::string mapFileName
name of the MAP file storing information about PCIe registers mapping
uint32_t dmapFileLineNumber
line number in DMAP file storing listed above information
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).
std::string deviceName
logical name of the device
Stores detailed information about one error or warning.
DMAP_FILE_ERR
Defines available types of detected problems.
@ NONUNIQUE_DEVICE_NAME
Names of two devices are the same - treated as critical error.
TYPE
Defines available classes of detected problems.
@ WARNING
Non-critical error was detected.
DMAP_FILE_ERR _errorType
Type of detected problem.
DeviceInfoMap::DeviceInfo _errorDevice1
Detailed information about first device that generate error or warning.
ErrorElem(TYPE infoType, DMAP_FILE_ERR errorType, const DeviceInfoMap::DeviceInfo &device1, const DeviceInfoMap::DeviceInfo &device2)
Creates obiect that describe one detected error or warning.
DeviceInfoMap::DeviceInfo _errorDevice2
Detailed information about second device that generate error or warning.
TYPE _type
Class of detected problem - ERROR or WARNING.
Stores information about errors and warnings.
std::list< ErrorElem > _errors
Lists of errors or warnings detected during MAP file correctness checking.
std::vector< DeviceInfo > _deviceInfoElements
vector storing parsed contents of DMAP file
std::vector< std::string > _pluginLibraries
Names of the so files with the plugins.
bool check(ErrorList &err, ErrorList::ErrorElem::TYPE level)
Checks logical correctness of DMAP file.
friend std::ostream & operator<<(std::ostream &os, const DeviceInfoMap &deviceInfoMap)
void addPluginLibrary(const std::string &soFile)
Add the name of a library to the list.
void getDeviceInfo(const std::string &deviceName, DeviceInfo &value)
Returns information about specified device.
std::vector< DeviceInfo >::iterator iterator
iterator end()
Return iterator to element after last one in DMAP file.
size_t getSize()
Returns number of records in DMAP file.
void insert(const DeviceInfo &elem)
Insert new element read from DMAP file.
std::vector< std::string > getPluginLibraries()
You can define shared libraries with Backend plugins in the DMAP file.
std::string _dmapFileName
name of DMAP file
DeviceInfoMap(std::string fileName)
Constructor.
iterator begin()
Return iterator to first device described in DMAP file.
Provides predicate to compare devices by device file by name.
Definition predicates.h:28
Provides predicate to search device by name.
Definition predicates.h:15
Exception thrown when a logic error has occured.
Definition Exception.h:51
std::ostream & operator<<(std::ostream &stream, const DataDescriptor::FundamentalType &fundamentalType)
STL namespace.