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
10namespace Cvb
11{
12
13 CVB_BEGIN_INLINE_NS
14
15 namespace Driver
16 {
17
19
21 class DiscoveryInformation final
22 {
23 friend DeviceFactory;
24
25 public:
26 DiscoveryInformation(const DiscoveryInformation &other) = delete;
27 DiscoveryInformation &operator=(const DiscoveryInformation &other) = delete;
28
29 DiscoveryInformation(DiscoveryInformation &&other) noexcept
30 : DiscoveryInformation(other.list_, other.index_)
31 {
32 }
33
34 ~DiscoveryInformation() = default;
35
37
41 int Index() const noexcept
42 {
43 return index_;
44 }
45
48
54 void SetGenApiFeature(const String &nodeMapId, const String &featureName, const String &featureValue)
55 {
56 if (nodeMapId.empty())
57 throw std::invalid_argument("node map ID must not be empty");
58 if (featureName.empty())
59 throw std::invalid_argument("feature name must not be empty");
60 if (featureValue.empty())
61 throw std::invalid_argument("feature value must not be empty");
62
63 auto result = CExports::DOSetFeatureTyped(list_.get(), static_cast<size_t>(index_), nodeMapId.c_str(),
64 featureName.c_str(), featureValue.c_str());
65 if (result < 0)
66 std::rethrow_exception(CvbException::FromCvbResult(result, "failed to set device object feature"));
67 }
68
70
82 void SetParameter(const String &name, const String &value)
83 {
84 if (name.empty())
85 throw std::invalid_argument("name must not be empty");
86 if (value.empty())
87 throw std::invalid_argument("value must not be empty");
88
89 auto result =
90 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
123
129 bool TryGetProperty(DiscoveryProperties id, String &property) const noexcept
130 {
131 return (!InternalTryGetProperty(id, property)) ? true : false;
132 }
133
135
141 {
142 String property;
143 auto error = InternalTryGetProperty(id, property);
144 if (error)
146 return property;
147 }
148
150
155 DiscoveryInformation &operator=(DiscoveryInformation &&other) = default;
156
157 private:
158 typedef std::shared_ptr<void> List;
159
160 DiscoveryInformation(List list, int index) noexcept
161 : list_(list)
162 , index_(index)
163 {
164 }
165
166 std::exception_ptr InternalTryGetProperty(DiscoveryProperties id, String &property) const noexcept
167 {
168
169 std::size_t bufferSize = 0;
170 auto bufferSizeResult =
171 CExports::DOEntryGetInfoTyped(list_.get(), index_, static_cast<CExports::DODiscoverInfoCommands>(id),
172 reinterpret_cast<Char *>(0), bufferSize);
173 if (bufferSizeResult < 0)
174 return CvbException::FromCvbResult(bufferSizeResult, "failed to get device object info (buffer size)");
175 if (bufferSize < 2)
176 {
177 property.clear();
178 return std::exception_ptr();
179 }
180
181 std::vector<std::uint8_t> buffer(bufferSize);
182 auto entryResult =
183 CExports::DOEntryGetInfoTyped(list_.get(), index_, static_cast<CExports::DODiscoverInfoCommands>(id),
184 reinterpret_cast<Char *>(&buffer[0]), bufferSize);
185 if (entryResult < 0)
186 return CvbException::FromCvbResult(entryResult, "failed to get device object info");
187
188 property = String(reinterpret_cast<Char *>(&buffer[0]));
189 return std::exception_ptr();
190 }
191
192 List list_;
193 int index_;
194 };
195
196 } // namespace Driver
197
199
200 CVB_END_INLINE_NS
201
202} // namespace Cvb
Stores information on a discovered device/node.
Definition discovery_information.hpp:22
void SetParameter(const String &name, const String &value)
Sets a custom GenTL Producer dependent parameter.
Definition discovery_information.hpp:82
int Index() const noexcept
Gets the index of this element in the list.
Definition discovery_information.hpp:41
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:140
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:54
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:129
Namespace for driver or device related operations.
Definition decl_composite.hpp:27
ModuleLayer
Level of an access token entry.
Definition driver.hpp:341
@ Unknown
Invalid or not filled yet.
Definition driver.hpp:343
DiscoveryProperties
Properties which can be queried from a DiscoveryInformation entry.
Definition driver.hpp:204
@ String
String value.
Definition driver.hpp:368
Root namespace for the Image Manager interface.
Definition c_bayer_to_rgb.h:17
char Char
Character type for wide characters or unicode characters.
Definition string.hpp:63
T rethrow_exception(T... args)
T stoi(T... args)