CVB++ 14.0
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
10
11
12namespace Cvb
13{
14
15 CVB_BEGIN_INLINE_NS
16
17
18
19
20namespace Driver
21{
22
23
25
28{
29 friend DeviceFactory;
30
31 public:
32
33
34
35
37 : DiscoveryInformation(other.list_, other.index_)
38 {
39 }
40
42
46 int Index() const noexcept
47 {
48 return index_;
49 }
50
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(), featureName.c_str(), featureValue.c_str());
68 if (result < 0)
69 std::rethrow_exception(CvbException::FromCvbResult(result, "failed to set device object feature"));
70 }
71
73
83 void SetParameter(const String & name, const String & value)
84 {
85 if (name.empty())
86 throw std::invalid_argument("name must not be empty");
87 if (value.empty())
88 throw std::invalid_argument("value must not be empty");
89
90 auto result = CExports::DOSetParameterTyped(list_.get(), static_cast<size_t>(index_), name.c_str(), value.c_str());
91 if (result < 0)
92 std::rethrow_exception(CvbException::FromCvbResult(result, "failed to set device object parameter"));
93 }
94
96
101 {
102 return (*this)[static_cast<DiscoveryProperties>(1000)];
103 }
104
106
111 {
112 try
113 {
114 return static_cast<ModuleLayer>(std::stoi((*this)[static_cast<DiscoveryProperties>(1001)]));
115 }
116 catch (...)
117 {
119 }
120
121 }
122
123
124
126
132 bool TryGetProperty(DiscoveryProperties id, String & property) const noexcept
133 {
134 return (!InternalTryGetProperty(id, property)) ? true : false;
135 }
136
138
144 {
145 String property;
146 auto error = InternalTryGetProperty(id, property);
147 if (error)
148 std::rethrow_exception(error);
149 return property;
150 }
151
152
154
160
161
162 private:
163
165
166 DiscoveryInformation(List list, int index) noexcept
167 : list_(list)
168 , index_(index)
169 {
170 }
171
172
173
174 std::exception_ptr InternalTryGetProperty(DiscoveryProperties id, String & property) const noexcept
175 {
176
177
178 std::size_t bufferSize = 0;
179 auto bufferSizeResult = CExports::DOEntryGetInfoTyped(list_.get(), index_, static_cast<CExports::DODiscoverInfoCommands>(id), reinterpret_cast<Char *>(0), bufferSize);
180 if (bufferSizeResult < 0)
181 return CvbException::FromCvbResult(bufferSizeResult, "failed to get device object info (buffer size)");
182 if (bufferSize < 2)
183 {
184 property.clear();
185 return std::exception_ptr();
186 }
187
188 std::vector<std::uint8_t> buffer(bufferSize);
189 auto entryResult = CExports::DOEntryGetInfoTyped(list_.get(), index_, static_cast<CExports::DODiscoverInfoCommands>(id), 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}
202
203using Driver::DiscoveryInformation;
204
205CVB_END_INLINE_NS
206
207}
Factory object for creating device objects.
Definition: decl_device_factory.hpp:34
Stores information on a discovered device/node.
Definition: discovery_information.hpp:28
void SetParameter(const String &name, const String &value)
Sets a custom GenTL Producer dependent parameter.
Definition: discovery_information.hpp:83
int Index() const noexcept
Gets the index of this element in the list.
Definition: discovery_information.hpp:46
DiscoveryInformation & operator=(DiscoveryInformation &&other)=default
move assignment operator.
String AccessToken() const
The access token for opening the device/node.
Definition: discovery_information.hpp:100
ModuleLayer DiscoveryLayer() const noexcept
Gets the highest module layer in this discovery information.
Definition: discovery_information.hpp:110
String operator[](DiscoveryProperties id) const
Gets the value of the information property with the given id.
Definition: discovery_information.hpp:143
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:132
ModuleLayer
Level of an access token entry.
Definition: driver.hpp:334
@ Unknown
Invalid or not filled yet.
DiscoveryProperties
Properties which can be queried from a DiscoveryInformation entry.
Definition: driver.hpp:205
Root namespace for the Image Manager interface.
Definition: c_barcode.h:24
char Char
Character type for wide characters or unicode characters.
Definition: string.hpp:59