CVB++ 15.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 DiscoveryInformation(const DiscoveryInformation& other) = delete;
35 DiscoveryInformation& operator=(const DiscoveryInformation& other) = delete;
36
38 : DiscoveryInformation(other.list_, other.index_)
39 {
40 }
41
42 ~DiscoveryInformation() = default;
43
45
49 int Index() const noexcept
50 {
51 return index_;
52 }
53
55
61 void SetGenApiFeature(const String & nodeMapId, const String & featureName, const String & featureValue)
62 {
63 if (nodeMapId.empty())
64 throw std::invalid_argument("node map ID must not be empty");
65 if (featureName.empty())
66 throw std::invalid_argument("feature name must not be empty");
67 if (featureValue.empty())
68 throw std::invalid_argument("feature value must not be empty");
69
70 auto result = CExports::DOSetFeatureTyped(list_.get(), static_cast<size_t>(index_), nodeMapId.c_str(), featureName.c_str(), featureValue.c_str());
71 if (result < 0)
72 std::rethrow_exception(CvbException::FromCvbResult(result, "failed to set device object feature"));
73 }
74
76
86 void SetParameter(const String & name, const String & value)
87 {
88 if (name.empty())
89 throw std::invalid_argument("name must not be empty");
90 if (value.empty())
91 throw std::invalid_argument("value must not be empty");
92
93 auto result = CExports::DOSetParameterTyped(list_.get(), static_cast<size_t>(index_), name.c_str(), value.c_str());
94 if (result < 0)
95 std::rethrow_exception(CvbException::FromCvbResult(result, "failed to set device object parameter"));
96 }
97
99
104 {
105 return (*this)[static_cast<DiscoveryProperties>(1000)];
106 }
107
109
114 {
115 try
116 {
117 return static_cast<ModuleLayer>(std::stoi((*this)[static_cast<DiscoveryProperties>(1001)]));
118 }
119 catch (...)
120 {
122 }
123
124 }
125
126
127
129
135 bool TryGetProperty(DiscoveryProperties id, String & property) const noexcept
136 {
137 return (!InternalTryGetProperty(id, property)) ? true : false;
138 }
139
141
147 {
148 String property;
149 auto error = InternalTryGetProperty(id, property);
150 if (error)
151 std::rethrow_exception(error);
152 return property;
153 }
154
155
157
163
164
165 private:
166
168
169 DiscoveryInformation(List list, int index) noexcept
170 : list_(list)
171 , index_(index)
172 {
173 }
174
175
176
177 std::exception_ptr InternalTryGetProperty(DiscoveryProperties id, String & property) const noexcept
178 {
179
180
181 std::size_t bufferSize = 0;
182 auto bufferSizeResult = CExports::DOEntryGetInfoTyped(list_.get(), index_, static_cast<CExports::DODiscoverInfoCommands>(id), reinterpret_cast<Char *>(0), bufferSize);
183 if (bufferSizeResult < 0)
184 return CvbException::FromCvbResult(bufferSizeResult, "failed to get device object info (buffer size)");
185 if (bufferSize < 2)
186 {
187 property.clear();
188 return std::exception_ptr();
189 }
190
191 std::vector<std::uint8_t> buffer(bufferSize);
192 auto entryResult = CExports::DOEntryGetInfoTyped(list_.get(), index_, static_cast<CExports::DODiscoverInfoCommands>(id), reinterpret_cast<Char *>(&buffer[0]), bufferSize);
193 if (entryResult < 0)
194 return CvbException::FromCvbResult(entryResult, "failed to get device object info");
195
196 property = String(reinterpret_cast<Char *>(&buffer[0]));
197 return std::exception_ptr();
198 }
199
200 List list_;
201 int index_;
202};
203
204}
205
206using Driver::DiscoveryInformation;
207
208CVB_END_INLINE_NS
209
210}
Factory object for creating device objects.
Definition: decl_device_factory.hpp:39
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:86
int Index() const noexcept
Gets the index of this element in the list.
Definition: discovery_information.hpp:49
DiscoveryInformation & operator=(DiscoveryInformation &&other)=default
move assignment operator.
String AccessToken() const
The access token for opening the device/node.
Definition: discovery_information.hpp:103
ModuleLayer DiscoveryLayer() const noexcept
Gets the highest module layer in this discovery information.
Definition: discovery_information.hpp:113
String operator[](DiscoveryProperties id) const
Gets the value of the information property with the given id.
Definition: discovery_information.hpp:146
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:61
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:135
ModuleLayer
Level of an access token entry.
Definition: driver.hpp:342
@ 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:70