CVB++ 15.0
Loading...
Searching...
No Matches
discovery_information.hpp
1#pragma once
2
3#include "../global.hpp"
4#include "../string.hpp"
5
6#include "driver.hpp"
7
8#include "../utilities/system_info.hpp"
9
10namespace Cvb
11{
12
13 CVB_BEGIN_INLINE_NS
14
15 namespace Driver
16 {
17
19
25 class DiscoveryInformation final
26 {
27 friend DeviceFactory;
28
29 public:
30 DiscoveryInformation(const DiscoveryInformation &other) = delete;
31 DiscoveryInformation &operator=(const DiscoveryInformation &other) = delete;
32
33 DiscoveryInformation(DiscoveryInformation &&other) noexcept
34 : DiscoveryInformation(other.list_, other.index_)
35 {
36 }
37
38 ~DiscoveryInformation() = default;
39
41
45 int Index() const noexcept
46 {
47 return index_;
48 }
49
52
58 void SetGenApiFeature(const String &nodeMapId, const String &featureName, const String &featureValue)
59 {
60 if (nodeMapId.empty())
61 throw std::invalid_argument("node map ID must not be empty");
62 if (featureName.empty())
63 throw std::invalid_argument("feature name must not be empty");
64 if (featureValue.empty())
65 throw std::invalid_argument("feature value must not be empty");
66
67 auto result = CExports::DOSetFeatureTyped(list_.get(), static_cast<size_t>(index_), nodeMapId.c_str(),
68 featureName.c_str(), featureValue.c_str());
69 if (result < 0)
70 std::rethrow_exception(CvbException::FromCvbResult(result, "failed to set device object feature"));
71 }
72
74
87 void SetParameter(const String &name, const String &value)
88 {
89 if (name.empty())
90 throw std::invalid_argument("name must not be empty");
91 if (value.empty())
92 throw std::invalid_argument("value must not be empty");
93
94 auto result =
95 CExports::DOSetParameterTyped(list_.get(), static_cast<size_t>(index_), name.c_str(), value.c_str());
96 if (result < 0)
97 std::rethrow_exception(CvbException::FromCvbResult(result, "failed to set device object parameter"));
98 }
99
101
106 {
107 return (*this)[static_cast<DiscoveryProperties>(1000)];
108 }
109
111
116 {
117 try
118 {
119 return static_cast<ModuleLayer>(std::stoi((*this)[static_cast<DiscoveryProperties>(1001)]));
120 }
121 catch (...)
122 {
124 }
125 }
126
128
134 bool TryGetProperty(DiscoveryProperties id, String &property) const noexcept
135 {
136 return (!InternalTryGetProperty(id, property)) ? true : false;
137 }
138
140
146 {
147 String property;
148 auto error = InternalTryGetProperty(id, property);
149 if (error)
151 return property;
152 }
153
155
160 DiscoveryInformation &operator=(DiscoveryInformation &&other) = default;
161
162 private:
163 typedef std::shared_ptr<void> List;
164
165 DiscoveryInformation(List list, int index) noexcept
166 : list_(list)
167 , index_(index)
168 {
169 }
170
171 std::exception_ptr InternalTryGetProperty(DiscoveryProperties id, String &property) const noexcept
172 {
173
174 std::size_t bufferSize = 0;
175 auto bufferSizeResult =
176 CExports::DOEntryGetInfoTyped(list_.get(), index_, static_cast<CExports::DODiscoverInfoCommands>(id),
177 reinterpret_cast<Char *>(0), bufferSize);
178 if (bufferSizeResult < 0)
179 return CvbException::FromCvbResult(bufferSizeResult, "failed to get device object info (buffer size)");
180 if (bufferSize < 2)
181 {
182 property.clear();
183 return std::exception_ptr();
184 }
185
186 std::vector<std::uint8_t> buffer(bufferSize);
187 auto entryResult =
188 CExports::DOEntryGetInfoTyped(list_.get(), index_, static_cast<CExports::DODiscoverInfoCommands>(id),
189 reinterpret_cast<Char *>(&buffer[0]), bufferSize);
190 if (entryResult < 0)
191 return CvbException::FromCvbResult(entryResult, "failed to get device object info");
192
193 property = String(reinterpret_cast<Char *>(&buffer[0]));
194 return std::exception_ptr();
195 }
196
197 List list_;
198 int index_;
199 };
200
201 } // namespace Driver
202
204
205 CVB_END_INLINE_NS
206
207} // namespace Cvb
Stores information on a discovered device/node.
Definition discovery_information.hpp:26
void SetParameter(const String &name, const String &value)
Sets a custom GenTL Producer dependent parameter.
Definition discovery_information.hpp:87
int Index() const noexcept
Gets the index of this element in the list.
Definition discovery_information.hpp:45
DiscoveryInformation & operator=(DiscoveryInformation &&other)=default
move assignment operator.
String AccessToken() const
The access token for opening the device/node.
Definition discovery_information.hpp:105
ModuleLayer DiscoveryLayer() const noexcept
Gets the highest module layer in this discovery information.
Definition discovery_information.hpp:115
String operator[](DiscoveryProperties id) const
Gets the value of the information property with the given id.
Definition discovery_information.hpp:145
void SetGenApiFeature(const String &nodeMapId, const String &featureName, const String &featureValue)
Sets a GenICam GenApi feature to be set with a new discover run or while opening a device via this in...
Definition discovery_information.hpp:58
bool TryGetProperty(DiscoveryProperties id, String &property) const noexcept
Tries to get the value of the information property with the given id.
Definition discovery_information.hpp:134
Namespace for driver or device related operations.
Definition decl_composite.hpp:27
ModuleLayer
Level of an access token entry.
Definition driver.hpp:339
@ Unknown
Invalid or not filled yet.
Definition driver.hpp:341
DiscoveryProperties
Properties which can be queried from a DiscoveryInformation entry.
Definition driver.hpp:213
@ String
String value.
Definition driver.hpp:366
Root namespace for the Image Manager interface.
Definition version.hpp:11
char Char
Character type for wide characters or unicode characters.
Definition string.hpp:63
T rethrow_exception(T... args)
T stoi(T... args)