CVB++ 15.0
Loading...
Searching...
No Matches
decl_device_factory.hpp
1#pragma once
2
3#include <exception>
4#include <memory>
5#include <mutex>
6#include <stdexcept>
7#include <chrono>
8#include <vector>
9
10#include "../global.hpp"
11#include "../exception.hpp"
12#include "../string.hpp"
13
14#include "../utilities/system_info.hpp"
15
16#include "../driver/discovery_information.hpp"
17
18namespace Cvb
19{
20
21 CVB_BEGIN_INLINE_NS
22
24
29
30 class DeviceFactory final
31 {
32 public:
34
47 template <class T>
48 static std::shared_ptr<T> Open(const String &provider,
49 AcquisitionStack acquisitionStack = AcquisitionStack::PreferVin)
50 {
51 static_assert(std::is_base_of<Device, T>::value, "CVB: Device must be a base of T");
52 auto device = std::dynamic_pointer_cast<T>(Open(provider, acquisitionStack));
53 if (!device)
54 throw std::runtime_error("open failed to cast to device type");
55 return device;
56 }
57
59
80 static DevicePtr Open(const String &provider, AcquisitionStack acquisitionStack = AcquisitionStack::PreferVin);
81
83
96 template <class T>
97 static std::shared_ptr<T> Open(const String &provider, int port, int board)
98 {
99 static_assert(std::is_base_of<Device, T>::value, "CVB: Device must be a base of T");
100 auto device = std::dynamic_pointer_cast<T>(Open(provider, port, board));
101 if (!device)
102 throw std::runtime_error("open failed to cast to device type");
103 return device;
104 }
105
107
120 static DevicePtr Open(const String &provider, int port, int board)
121 {
122 if (Internal::IsAccessToken(provider))
123 throw std::logic_error("access tokens do not support port or board switch");
124 auto device = Open(provider, AcquisitionStack::PreferVin);
125 ChangeBoard(device, board);
126 ChangePort(device, port);
127 return device;
128 }
129
131
137 template <class T>
138 static std::shared_ptr<T> OpenBoard(const String &provider, int board)
139 {
140 static_assert(std::is_base_of<Device, T>::value, "CVB: Device must be a base of T");
141 auto device = std::dynamic_pointer_cast<T>(OpenBoard(provider, board));
142 if (!device)
143 throw std::runtime_error("open board failed to cast to device type");
144 return device;
145 }
146
148
154 static DevicePtr OpenBoard(const String &provider, int board)
155 {
156 if (Internal::IsAccessToken(provider))
157 throw std::logic_error("access tokens do not support port or board switch");
158 auto device = Open(provider, AcquisitionStack::PreferVin);
159 ChangeBoard(device, board);
160 return device;
161 }
162
164
170 template <class T>
171 static std::shared_ptr<T> OpenPort(const String &provider, int port)
172 {
173 static_assert(std::is_base_of<Device, T>::value, "CVB: Device must be a base of T");
174 auto device = std::dynamic_pointer_cast<T>(OpenPort(provider, port));
175 if (!device)
176 throw std::runtime_error("open port failed to cast to device type");
177 return device;
178 }
179
181
187 static DevicePtr OpenPort(const String &provider, int port)
188 {
189 if (Internal::IsAccessToken(provider))
190 throw std::logic_error("access tokens do not support port or board switch");
191 auto device = Open(provider, AcquisitionStack::PreferVin);
192 ChangePort(device, port);
193 return device;
194 }
195
197
210 {
211#if defined _WIN32
212 return Discover(DiscoverFlags::IgnoreVins | DiscoverFlags::IgnoreGevSD);
213#else
214 return Discover(DiscoverFlags::IgnoreVins);
215#endif
216 }
217
219
231
233
242 template <class Rep, class Period>
245 {
246 return Discover(String(), flags, timeSpan);
247 }
248
250
260 template <class Rep, class Period>
262 const std::chrono::duration<Rep, Period> &timeSpan);
263
265
275 {
276 return Discover(accessToken, flags, std::chrono::milliseconds(300));
277 }
278
280
289 {
290 return Discover(accessToken, DiscoverFlags::FindAll);
291 }
292
295
304 {
305 return Discover(info.AccessToken());
306 }
307
309
322
324
334 template <class Rep, class Period>
337 {
338 return Discover(info.AccessToken(), flags, timeSpan);
339 }
340
341 static CExports::cvbguid_t AviMpgGuid()
342 {
343 static CExports::cvbguid_t guid = {0x7DBE4A03, 0xAD3D, 0x4533, 0x85, 0x1F, 0x61, 0xB4, 0xAE, 0x62, 0xC2, 0x0E};
344 return guid;
345 }
346
347 static CExports::cvbguid_t EmuGuid()
348 {
349 static CExports::cvbguid_t guid = {0x10cb8e8f, 0x00b6, 0x4bb0, 0xbb, 0x82, 0xcd, 0x77, 0x2c, 0xba, 0xb7, 0x57};
350 return guid;
351 }
352
353 static std::mutex &LockAnchor()
354 {
355 static std::mutex mutex;
356 return mutex;
357 }
358
359 private:
360 DeviceFactory() noexcept = delete;
361
362 static void ChangeBoard(DevicePtr &device, int board);
363
364 static void ChangeBoard1(DevicePtr &device, int board);
365
366 static void ChangeBoard2(DevicePtr &device, int board);
367
368 static void ChangePort(DevicePtr &device, int port);
369
370 static void ChangePort1(DevicePtr &device, int port);
371
372 static void ChangePort2(DevicePtr &device, int port);
373
374 static bool AllowFallback(AcquisitionStack acquisitionStack) noexcept
375 {
376 return acquisitionStack == Cvb::AcquisitionStack::PreferVin
377 || acquisitionStack == Cvb::AcquisitionStack::PreferGenTL;
378 }
379
380 static HandleGuard<Device> LoadAsGenTL(const String &provider, AcquisitionStack acquisitionStack);
381
382 static HandleGuard<Device> LoadAsVin(const String &provider, AcquisitionStack acquisitionStack);
383
384 static HandleGuard<Device> LoadAsNonStreaming(const String &provider);
385
386 static DevicePtr CreateDeviceByDriverGUID(const String &provider, HandleGuard<Device> &&guard) noexcept;
387 };
388
389 CVB_END_INLINE_NS
390
391} // namespace Cvb
static DevicePtr OpenBoard(const String &provider, int board)
Open a device with the given provider and board.
Definition decl_device_factory.hpp:154
static std::vector< DiscoveryInformation > Discover(const String &accessToken)
Discovers available nodes starting on level of the given access token with a default time span of 300...
Definition decl_device_factory.hpp:288
static std::vector< DiscoveryInformation > Discover(DiscoverFlags flags, const std::chrono::duration< Rep, Period > &timeSpan)
Discovers available devices/nodes depending on the given flags.
Definition decl_device_factory.hpp:243
static std::vector< DiscoveryInformation > Discover()
Discovers available devices (not vins) with a default time span of 300ms.
Definition decl_device_factory.hpp:209
static std::vector< DiscoveryInformation > Discover(const String &accessToken, DiscoverFlags flags, const std::chrono::duration< Rep, Period > &timeSpan)
Discovers available nodes starting on level of the given access token.
static std::shared_ptr< T > OpenPort(const String &provider, int port)
Open a device with the given provider and port.
Definition decl_device_factory.hpp:171
static std::vector< DiscoveryInformation > Discover(const DiscoveryInformation &info, DiscoverFlags flags, const std::chrono::duration< Rep, Period > &timeSpan)
Discovers available nodes starting on level of the given info.
Definition decl_device_factory.hpp:335
static DevicePtr OpenPort(const String &provider, int port)
Open a device with the given provider and port.
Definition decl_device_factory.hpp:187
static std::vector< DiscoveryInformation > Discover(DiscoverFlags flags)
Discovers available devices/nodes depending on the given flags, with a default time span of 300ms.
Definition decl_device_factory.hpp:227
static DevicePtr Open(const String &provider, int port, int board)
Opens a device with the given provider.
Definition decl_device_factory.hpp:120
static std::vector< DiscoveryInformation > Discover(const DiscoveryInformation &info, DiscoverFlags flags)
Discovers available nodes starting on level of the given info with a default time span of 300ms.
Definition decl_device_factory.hpp:318
static std::vector< DiscoveryInformation > Discover(const DiscoveryInformation &info)
Discovers available nodes starting on level of the given discovery info with a default time span of 3...
Definition decl_device_factory.hpp:303
static std::shared_ptr< T > Open(const String &provider, int port, int board)
Opens a device with the given provider.
Definition decl_device_factory.hpp:97
static std::shared_ptr< T > OpenBoard(const String &provider, int board)
Open a device with the given provider and board.
Definition decl_device_factory.hpp:138
static std::shared_ptr< T > Open(const String &provider, AcquisitionStack acquisitionStack=AcquisitionStack::PreferVin)
Opens a device with the given provider with its default board and port (if applicable).
Definition decl_device_factory.hpp:48
static std::vector< DiscoveryInformation > Discover(const String &accessToken, DiscoverFlags flags)
Discovers available nodes starting on level of the given access token with a default time span of 300...
Definition decl_device_factory.hpp:274
Stores information on a discovered device/node.
Definition discovery_information.hpp:22
String AccessToken() const
The access token for opening the device/node.
Definition discovery_information.hpp:100
AcquisitionStack
Defines the acquisition stack when opening the device.
Definition driver.hpp:273
DiscoverFlags
Flags controlling the discovery process.
Definition driver.hpp:293
Root namespace for the Image Manager interface.
Definition c_bayer_to_rgb.h:17
std::string String
String for wide characters or unicode characters.
Definition string.hpp:49
std::shared_ptr< Device > DevicePtr
Convenience shared pointer for Device.
Definition global.hpp:98
T dynamic_pointer_cast(T... args)