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 
12 namespace Cvb
13 {
14 
15  CVB_BEGIN_INLINE_NS
16 
17 
18 
19 
20 namespace 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 
110  ModuleLayer DiscoveryLayer() const noexcept
111  {
112  try
113  {
114  return static_cast<ModuleLayer>(std::stoi((*this)[static_cast<DiscoveryProperties>(1001)]));
115  }
116  catch (...)
117  {
118  return ModuleLayer::Unknown;
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 
164  typedef std::shared_ptr<void> List;
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 
203 using Driver::DiscoveryInformation;
204 
205 CVB_END_INLINE_NS
206 
207 }
ModuleLayer
Level of an access token entry.
Definition: driver.hpp:333
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
void SetParameter(const String &name, const String &value)
Sets a custom GenTL Producer dependent parameter.
Definition: discovery_information.hpp:83
Factory object for creating device objects.
Definition: decl_device_factory.hpp:33
DiscoveryInformation & operator=(DiscoveryInformation &&other)=default
move assignment operator.
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
String operator[](DiscoveryProperties id) const
Gets the value of the information property with the given id.
Definition: discovery_information.hpp:143
STL class.
Root namespace for the Image Manager interface.
Definition: version.hpp:11
int Index() const noexcept
Gets the index of this element in the list.
Definition: discovery_information.hpp:46
Stores information on a discovered device/node.
Definition: discovery_information.hpp:27
Invalid or not filled yet.
ModuleLayer DiscoveryLayer() const noexcept
Gets the highest module layer in this discovery information.
Definition: discovery_information.hpp:110
DiscoveryProperties
Properties which can be queried from a DiscoveryInformation entry.
Definition: driver.hpp:204
String AccessToken() const
The access token for opening the device/node.
Definition: discovery_information.hpp:100