CVB++ 15.0
decl_emu_device.hpp
1#pragma once
2
3#include <memory>
4#include <limits>
5#include <chrono>
6
7#include "../../_cexports/c_dc_emu.h"
8
9#include "../../global.hpp"
10#include "../../string.hpp"
11
12#include "decl_indexed_stream.hpp"
13
14#include "../../_decl/decl_device.hpp"
15
16namespace Cvb
17{
18
19 CVB_BEGIN_INLINE_NS
20
21 namespace Driver
22 {
23
25
26 class EmuDevice : public Device
27 {
28 public:
29 EmuDevice(HandleGuard<Device> &&guard, const String &fileName)
30 : Device(std::move(guard), fileName)
31 {
32 AnnounceStreams(1);
33 }
34
36
41
43
47 template <class Rep, class Period>
49 {
50#ifdef max
51# undef max
52#endif
53 auto msFrameTime = std::chrono::duration_cast<std::chrono::milliseconds>(frameTime).count();
54 if (msFrameTime > std::numeric_limits<uint32_t>::max())
55 throw std::overflow_error("timeout must fit to unsigned 32 bit integer in ms");
56
57 auto digitalIO = DigitalIO();
58 digitalIO->WriteOutputGroup(CExports::Emu::DelayGroup,
59 std::bitset<32>(static_cast<std::uint32_t>(msFrameTime)));
60 }
61
62 protected:
63 void ChangeHandle(HandleGuard<Device> &&, DeviceUpdateMode) override
64 {
65 throw std::runtime_error("handle change not supported");
66 }
67
68 DeviceImagePtr CreateDeviceImage() const override;
69
70 StreamBasePtr CreateStream(int, StreamType) const override;
71
72 private:
73 class EmuStream : public IndexedStream
74 {
75 public:
76 explicit EmuStream(const DevicePtr &device);
77
78 StreamImagePtr MakeStreamImage() override
79 {
80 return MakeSnapshotImage();
81 }
82
83 StreamImagePtr MakeSnapshotImage() override;
84
85 int ImageCount() const noexcept override
86 {
87 return imageCount_;
88 }
89
90 int ImageIndex() const override;
91
92 void SetImageIndex(int index) override;
93
94 private:
95 std::unique_ptr<Driver::BufferImage::ImageLayout> layout_;
96
97 int imageCount_;
98 };
99 };
100
101 } // namespace Driver
102
103 using Driver::EmuDevice;
104
105 CVB_END_INLINE_NS
106
107} // namespace Cvb
DigitalIOPtr DigitalIO() const
Gets the DigitalIO interface if present.
Definition detail_device.hpp:167
A device representing an image stream based on single image files.
Definition decl_emu_device.hpp:27
std::chrono::milliseconds FrameTime() const
Gets the time when frame is valid.
Definition detail_emu_device.hpp:20
void SetFrameTime(const std::chrono::duration< Rep, Period > &frameTime)
Sets the time one frame is valid.
Definition decl_emu_device.hpp:48
A stream with a finite number of images, which can also be accessed via an index.
Definition decl_indexed_stream.hpp:20
T duration_cast(T... args)
T max(T... args)
T move(T... args)
Namespace for driver or device related operations.
Definition decl_composite.hpp:28
std::shared_ptr< StreamImage > StreamImagePtr
Convenience shared pointer for StreamImage.
Definition driver.hpp:93
@ String
String value.
Definition driver.hpp:366
std::shared_ptr< DeviceImage > DeviceImagePtr
Convenience shared pointer for DeviceImage.
Definition driver.hpp:61
std::shared_ptr< StreamBase > StreamBasePtr
Convenience shared pointer for StreamBase.
Definition driver.hpp:113
Root namespace for the Image Manager interface.
Definition c_bayer_to_rgb.h:17
std::shared_ptr< Device > DevicePtr
Convenience shared pointer for Device.
Definition global.hpp:98
DeviceUpdateMode
Defines how to treat the optional device image, when the device itself is updated.
Definition global.hpp:252