CVB++ 15.1
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
37
38 class DeviceFactory final
39 {
40 public:
42
55 template <class T>
56 static std::shared_ptr<T> Open(const String &provider,
57 AcquisitionStack acquisitionStack = AcquisitionStack::PreferVin)
58 {
59 static_assert(std::is_base_of<Device, T>::value, "CVB: Device must be a base of T");
60 auto device = std::dynamic_pointer_cast<T>(Open(provider, acquisitionStack));
61 if (!device)
62 throw std::runtime_error("open failed to cast to device type");
63 return device;
64 }
65
67
88 static DevicePtr Open(const String &provider, AcquisitionStack acquisitionStack = AcquisitionStack::PreferVin);
89
91
103 static DevicePtr Open(const DiscoveryInformation &info,
104 AcquisitionStack acquisitionStack = AcquisitionStack::PreferVin);
105
107
120 template <class T>
121 static std::shared_ptr<T> Open(const String &provider, int port, int board)
122 {
123 static_assert(std::is_base_of<Device, T>::value, "CVB: Device must be a base of T");
124 auto device = std::dynamic_pointer_cast<T>(Open(provider, port, board));
125 if (!device)
126 throw std::runtime_error("open failed to cast to device type");
127 return device;
128 }
129
131
149 template <class T>
151 AcquisitionStack acquisitionStack = AcquisitionStack::PreferVin)
152 {
153 static_assert(std::is_base_of<Device, T>::value, "CVB: Device must be a base of T");
154 auto device = std::dynamic_pointer_cast<T>(Open(info, acquisitionStack));
155 if (!device)
156 throw std::runtime_error("open failed to cast to device type");
157 return device;
158 }
159
161
174 static DevicePtr Open(const String &provider, int port, int board)
175 {
176 if (Internal::IsAccessToken(provider))
177 throw std::logic_error("access tokens do not support port or board switch");
178 auto device = Open(provider, AcquisitionStack::PreferVin);
179 ChangeBoard(device, board);
180 ChangePort(device, port);
181 return device;
182 }
183
185
191 template <class T>
192 static std::shared_ptr<T> OpenBoard(const String &provider, int board)
193 {
194 static_assert(std::is_base_of<Device, T>::value, "CVB: Device must be a base of T");
195 auto device = std::dynamic_pointer_cast<T>(OpenBoard(provider, board));
196 if (!device)
197 throw std::runtime_error("open board failed to cast to device type");
198 return device;
199 }
200
202
208 static DevicePtr OpenBoard(const String &provider, int board)
209 {
210 if (Internal::IsAccessToken(provider))
211 throw std::logic_error("access tokens do not support port or board switch");
212 auto device = Open(provider, AcquisitionStack::PreferVin);
213 ChangeBoard(device, board);
214 return device;
215 }
216
218
224 template <class T>
225 static std::shared_ptr<T> OpenPort(const String &provider, int port)
226 {
227 static_assert(std::is_base_of<Device, T>::value, "CVB: Device must be a base of T");
228 auto device = std::dynamic_pointer_cast<T>(OpenPort(provider, port));
229 if (!device)
230 throw std::runtime_error("open port failed to cast to device type");
231 return device;
232 }
233
235
241 static DevicePtr OpenPort(const String &provider, int port)
242 {
243 if (Internal::IsAccessToken(provider))
244 throw std::logic_error("access tokens do not support port or board switch");
245 auto device = Open(provider, AcquisitionStack::PreferVin);
246 ChangePort(device, port);
247 return device;
248 }
249
251
264 {
265#if defined _WIN32
266 return Discover(DiscoverFlags::IgnoreVins | DiscoverFlags::IgnoreGevSD);
267#else
268 return Discover(DiscoverFlags::IgnoreVins);
269#endif
270 }
271
273
285
287
296 template <class Rep, class Period>
299 {
300 return Discover(String(), flags, timeSpan);
301 }
302
304
314 template <class Rep, class Period>
316 const std::chrono::duration<Rep, Period> &timeSpan);
317
319
329 {
330 return Discover(accessToken, flags, std::chrono::milliseconds(300));
331 }
332
334
343 {
344 return Discover(accessToken, DiscoverFlags::FindAll);
345 }
346
349
358 {
359 return Discover(info.AccessToken());
360 }
361
363
376
378
388 template <class Rep, class Period>
391 {
392 return Discover(info.AccessToken(), flags, timeSpan);
393 }
394
395 static CExports::cvbguid_t AviMpgGuid()
396 {
397 static CExports::cvbguid_t guid = {0x7DBE4A03, 0xAD3D, 0x4533, {0x85, 0x1F, 0x61, 0xB4, 0xAE, 0x62, 0xC2, 0x0E}};
398 return guid;
399 }
400
401 static CExports::cvbguid_t EmuGuid()
402 {
403 static CExports::cvbguid_t guid = {0x10cb8e8f, 0x00b6, 0x4bb0, {0xbb, 0x82, 0xcd, 0x77, 0x2c, 0xba, 0xb7, 0x57}};
404 return guid;
405 }
406
407 static std::mutex &LockAnchor()
408 {
409 static std::mutex mutex;
410 return mutex;
411 }
412
413 private:
414 DeviceFactory() noexcept = delete;
415
416 static void ChangeBoard(DevicePtr &device, int board);
417
418 static void ChangeBoard1(DevicePtr &device, int board);
419
420 static void ChangeBoard2(DevicePtr &device, int board);
421
422 static void ChangePort(DevicePtr &device, int port);
423
424 static void ChangePort1(DevicePtr &device, int port);
425
426 static void ChangePort2(DevicePtr &device, int port);
427
428 static bool AllowFallback(AcquisitionStack acquisitionStack) noexcept
429 {
430 return acquisitionStack == Cvb::AcquisitionStack::PreferVin
431 || acquisitionStack == Cvb::AcquisitionStack::PreferGenTL;
432 }
433
434 static HandleGuard<Device> LoadAsGenTL(const String &provider, AcquisitionStack acquisitionStack);
435
436 static HandleGuard<Device> LoadAsVin(const String &provider, AcquisitionStack acquisitionStack);
437
438 static HandleGuard<Device> LoadAsNonStreaming(const String &provider);
439
440 static DevicePtr CreateDeviceByDriverGUID(const String &provider, HandleGuard<Device> &&guard) noexcept;
441 };
442
443 CVB_END_INLINE_NS
444
445} // namespace Cvb
static DevicePtr OpenBoard(const String &provider, int board)
Open a device with the given provider and board.
Definition decl_device_factory.hpp:208
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:342
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:297
static std::vector< DiscoveryInformation > Discover()
Discovers available devices (not vins) with a default time span of 300ms.
Definition decl_device_factory.hpp:263
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:225
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:389
static DevicePtr OpenPort(const String &provider, int port)
Open a device with the given provider and port.
Definition decl_device_factory.hpp:241
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:281
static DevicePtr Open(const String &provider, int port, int board)
Opens a device with the given provider.
Definition decl_device_factory.hpp:174
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:372
static std::shared_ptr< T > Open(const DiscoveryInformation &info, AcquisitionStack acquisitionStack=AcquisitionStack::PreferVin)
Opens a device with the given discovery information.
Definition decl_device_factory.hpp:150
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:357
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:121
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:192
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:56
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:328
Stores information on a discovered device/node.
Definition discovery_information.hpp:26
String AccessToken() const
The access token for opening the device/node.
Definition discovery_information.hpp:105
AcquisitionStack
Defines the acquisition stack when opening the device.
Definition driver.hpp:282
DiscoverFlags
Flags controlling the discovery process.
Definition driver.hpp:302
Root namespace for the Image Manager interface.
Definition version.hpp:11
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)