CVB++ 15.0
decl_stream.hpp
1#pragma once
2
3#include "../../global.hpp"
4
5#include "../../image.hpp"
6
7#include "../chunk_image_buffer_description.hpp"
8#include "../gevserver.hpp"
9
10namespace Cvb
11{
12 CVB_BEGIN_INLINE_NS
13 namespace GevServer
14 {
16
18 class Stream : public std::enable_shared_from_this<Stream>
19 {
20 public:
25 explicit Stream(const ServerPtr &parent)
26 : parent_(parent)
27 {
28 if (!parent_)
29 throw std::runtime_error("Server for stream creation must not be null.");
30 }
31
32 virtual ~Stream() {}
33 Stream(const Stream &other) noexcept = delete;
34 Stream(Stream &&) noexcept = default;
35 Stream &operator=(Stream &&) noexcept = default;
36 Stream &operator=(const Stream &) noexcept = delete;
37
42
60 bool IsRunning() const;
61
71 std::int64_t ResendBuffersCount() const;
72
86 void SetResendBuffersCount(const std::int64_t &numBuffers);
87
109 void Send(const ImagePtr &image, std::function<void(const ImagePtr &)> imageReleased);
110
136 bool TrySend(const ImagePtr &image, std::function<void(const ImagePtr &)> imageReleased);
137
154 void Send(const Image &image);
155
176 bool TrySend(const Image &image);
177
200 void Send(const ImageBufferDescription &bufferDescription, void *basePtr, const std::size_t &bufferSize,
201 std::function<void(void *)> bufferReleased);
202
217 bool TrySend(const ImageBufferDescription &bufferDescription, void *basePtr, const std::size_t &bufferSize,
218 std::function<void(void *)> bufferReleased);
219
220 private:
221 static void __stdcall SendDispatcher(void *pPrivate)
222 {
223 try
224 {
225 // Call thread context of Send function
226 if (auto pFunction = reinterpret_cast<std::function<void(void)> *>(pPrivate))
227 {
228 (*pFunction)();
229 delete pFunction; // NOLINT(cppcoreguidelines-owning-memory)
230 }
231 }
232 catch (...)
233 {
234 // swallow exception so they don't propagate to native library.
235 }
236 }
237
238 CExports::cvbres_t InnerSend(const ImagePtr &image, std::function<void(const ImagePtr &)> callback);
239
240 CExports::cvbres_t InnerSend(const Image &image);
241
242 CExports::cvbres_t InnerSend(const ImageBufferDescription &description, void *basePtr, std::size_t bufferSize,
243 std::function<void(void *)> callback);
244
245 CExports::cvbres_t InnerSend(const ChunkImageBufferDescription &description, void *basePtr,
246 std::size_t bufferSize, std::function<void(void *)> callback);
247
248 ServerPtr parent_;
249 };
250 } // namespace GevServer
251 CVB_END_INLINE_NS
252} // namespace Cvb
Represents one acquisition stream of a device.
Definition decl_stream.hpp:33
The stream to send Images or other data.
Definition decl_stream.hpp:19
bool TrySend(const ImagePtr &image, std::function< void(const ImagePtr &)> imageReleased)
Tries to send the given image to the remote client.
Definition detail_stream.hpp:46
Stream(const ServerPtr &parent)
Creates the stream from the given parent server.
Definition decl_stream.hpp:25
ServerPtr Parent()
Gets the parent server object.
Definition detail_stream.hpp:17
void Send(const ImagePtr &image, std::function< void(const ImagePtr &)> imageReleased)
Sends the given image to the remote client.
Definition detail_stream.hpp:39
void SetResendBuffersCount(const std::int64_t &numBuffers)
Sets the number of resend buffers.
Definition detail_stream.hpp:34
std::int64_t ResendBuffersCount() const
Gets the number of resend buffers.
Definition detail_stream.hpp:27
bool IsRunning() const
Gets whether this stream is running.
Definition detail_stream.hpp:22
The Common Vision Blox image.
Definition decl_image.hpp:50
Namespace for GevServer based device configuration.
Definition decl_int_swiss_knife_node.hpp:11
@ Image
Image payload.
Definition gevserver.hpp:271
std::shared_ptr< Server > ServerPtr
Convenience shared pointer for GevServer.
Definition gevserver.hpp:37
Root namespace for the Image Manager interface.
Definition c_bayer_to_rgb.h:17
std::shared_ptr< Image > ImagePtr
Convenience shared pointer for Image.
Definition global.hpp:86