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
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
148 template <class T>
150 AcquisitionStack acquisitionStack = AcquisitionStack::PreferVin)
151 {
152 static_assert(std::is_base_of<Device, T>::value, "CVB: Device must be a base of T");
153 auto device = std::dynamic_pointer_cast<T>(Open(info, acquisitionStack));
154 if (!device)
155 throw std::runtime_error("open failed to cast to device type");
156 return device;
157 }
158
160
173 static DevicePtr Open(const String &provider, int port, int board)
174 {
175 if (Internal::IsAccessToken(provider))
176 throw std::logic_error("access tokens do not support port or board switch");
177 auto device = Open(provider, AcquisitionStack::PreferVin);
178 ChangeBoard(device, board);
179 ChangePort(device, port);
180 return device;
181 }
182
184
190 template <class T>
191 static std::shared_ptr<T> OpenBoard(const String &provider, int board)
192 {
193 static_assert(std::is_base_of<Device, T>::value, "CVB: Device must be a base of T");
194 auto device = std::dynamic_pointer_cast<T>(OpenBoard(provider, board));
195 if (!device)
196 throw std::runtime_error("open board failed to cast to device type");
197 return device;
198 }
199
201
207 static DevicePtr OpenBoard(const String &provider, int board)
208 {
209 if (Internal::IsAccessToken(provider))
210 throw std::logic_error("access tokens do not support port or board switch");
211 auto device = Open(provider, AcquisitionStack::PreferVin);
212 ChangeBoard(device, board);
213 return device;
214 }
215
217
223 template <class T>
224 static std::shared_ptr<T> OpenPort(const String &provider, int port)
225 {
226 static_assert(std::is_base_of<Device, T>::value, "CVB: Device must be a base of T");
227 auto device = std::dynamic_pointer_cast<T>(OpenPort(provider, port));
228 if (!device)
229 throw std::runtime_error("open port failed to cast to device type");
230 return device;
231 }
232
234
240 static DevicePtr OpenPort(const String &provider, int port)
241 {
242 if (Internal::IsAccessToken(provider))
243 throw std::logic_error("access tokens do not support port or board switch");
244 auto device = Open(provider, AcquisitionStack::PreferVin);
245 ChangePort(device, port);
246 return device;
247 }
248
250
263 {
264#if defined _WIN32
265 return Discover(DiscoverFlags::IgnoreVins | DiscoverFlags::IgnoreGevSD);
266#else
267 return Discover(DiscoverFlags::IgnoreVins);
268#endif
269 }
270
272
284
286
295 template <class Rep, class Period>
298 {
299 return Discover(String(), flags, timeSpan);
300 }
301
303
313 template <class Rep, class Period>
315 const std::chrono::duration<Rep, Period> &timeSpan);
316
318
328 {
329 return Discover(accessToken, flags, std::chrono::milliseconds(300));
330 }
331
333
342 {
343 return Discover(accessToken, DiscoverFlags::FindAll);
344 }
345
348
357 {
358 return Discover(info.AccessToken());
359 }
360
362
375
377
387 template <class Rep, class Period>
390 {
391 return Discover(info.AccessToken(), flags, timeSpan);
392 }
393
394 static CExports::cvbguid_t AviMpgGuid()
395 {
396 static CExports::cvbguid_t guid = {0x7DBE4A03, 0xAD3D, 0x4533, 0x85, 0x1F, 0x61, 0xB4, 0xAE, 0x62, 0xC2, 0x0E};
397 return guid;
398 }
399
400 static CExports::cvbguid_t EmuGuid()
401 {
402 static CExports::cvbguid_t guid = {0x10cb8e8f, 0x00b6, 0x4bb0, 0xbb, 0x82, 0xcd, 0x77, 0x2c, 0xba, 0xb7, 0x57};
403 return guid;
404 }
405
406 static std::mutex &LockAnchor()
407 {
408 static std::mutex mutex;
409 return mutex;
410 }
411
412 private:
413 DeviceFactory() noexcept = delete;
414
415 static void ChangeBoard(DevicePtr &device, int board);
416
417 static void ChangeBoard1(DevicePtr &device, int board);
418
419 static void ChangeBoard2(DevicePtr &device, int board);
420
421 static void ChangePort(DevicePtr &device, int port);
422
423 static void ChangePort1(DevicePtr &device, int port);
424
425 static void ChangePort2(DevicePtr &device, int port);
426
427 static bool AllowFallback(AcquisitionStack acquisitionStack) noexcept
428 {
429 return acquisitionStack == Cvb::AcquisitionStack::PreferVin
430 || acquisitionStack == Cvb::AcquisitionStack::PreferGenTL;
431 }
432
433 static HandleGuard<Device> LoadAsGenTL(const String &provider, AcquisitionStack acquisitionStack);
434
435 static HandleGuard<Device> LoadAsVin(const String &provider, AcquisitionStack acquisitionStack);
436
437 static HandleGuard<Device> LoadAsNonStreaming(const String &provider);
438
439 static DevicePtr CreateDeviceByDriverGUID(const String &provider, HandleGuard<Device> &&guard) noexcept;
440 };
441
442 CVB_END_INLINE_NS
443
444} // namespace Cvb
static DevicePtr OpenBoard(const String &provider, int board)
Open a device with the given provider and board.
Definition decl_device_factory.hpp:207
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:341
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:296
static std::vector< DiscoveryInformation > Discover()
Discovers available devices (not vins) with a default time span of 300ms.
Definition decl_device_factory.hpp:262
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:224
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:388
static DevicePtr OpenPort(const String &provider, int port)
Open a device with the given provider and port.
Definition decl_device_factory.hpp:240
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:280
static DevicePtr Open(const String &provider, int port, int board)
Opens a device with the given provider.
Definition decl_device_factory.hpp:173
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:371
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:149
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:356
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:191
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:327
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)