CVB++ 15.0
detail_stream.hpp
1#pragma once
2
3#include "../../_cexports/c_gev_server.h"
4#include "../../global.hpp"
5
6#include "../_decl/decl_node_map.hpp"
7
8#include "../_decl/decl_server.hpp"
9#include "../_decl/decl_stream.hpp"
10
11namespace Cvb
12{
13 CVB_BEGIN_INLINE_NS
14
15 namespace GevServer
16 {
18 {
19 return parent_;
20 }
21
22 inline bool Stream::IsRunning() const
23 {
24 return parent_->State() == State::AcquisitionEnabled;
25 }
26
28 {
29 CExports::cvbval_t numBuffers = 0;
30 CVB_CALL_CAPI(GSGetPacketResendBuffers(parent_->Handle(), numBuffers));
31 return static_cast<std::int64_t>(numBuffers);
32 }
33
34 inline void Stream::SetResendBuffersCount(const std::int64_t &numBuffers)
35 {
36 CVB_CALL_CAPI(GSSetPacketResendBuffers(parent_->Handle(), static_cast<CExports::cvbval_t>(numBuffers)));
37 }
38
39 inline void Stream::Send(const ImagePtr &image, std::function<void(const ImagePtr &)> imageReleased)
40 {
41 int result = InnerSend(image, imageReleased);
42 if (result < 0)
43 throw std::runtime_error("Could not send image");
44 }
45
46 inline bool Stream::TrySend(const ImagePtr &image, std::function<void(const ImagePtr &)> imageReleased)
47 {
48 return InnerSend(image, imageReleased) >= 0;
49 }
50
51 inline void Stream::Send(const Image &image)
52 {
53 if (ResendBuffersCount() > 0)
54 throw std::runtime_error("Packet resend must be disabled for send without callback");
55
56 int result = InnerSend(image);
57 if (result < 0)
58 throw std::runtime_error("Could not send image");
59 }
60
61 inline bool Stream::TrySend(const Image &image)
62 {
63 if (ResendBuffersCount() > 0)
64 throw std::runtime_error("Packet resend must be disabled for send without callback");
65
66 return InnerSend(image) >= 0;
67 }
68
69 inline void Stream::Send(const ImageBufferDescription &bufferDescription, void *basePtr,
70 const std::size_t &bufferSize, std::function<void(void *)> bufferReleased)
71 {
72 int result = InnerSend(bufferDescription, basePtr, bufferSize, bufferReleased);
73 if (result < 0)
74 throw std::runtime_error("Could not send image");
75 }
76
77 inline bool Stream::TrySend(const ImageBufferDescription &bufferDescription, void *basePtr,
78 const std::size_t &bufferSize, std::function<void(void *)> bufferReleased)
79 {
80 return InnerSend(bufferDescription, basePtr, bufferSize, bufferReleased) >= 0;
81 }
82
83 inline CExports::cvbres_t Stream::InnerSend(const ImagePtr &image, std::function<void(const ImagePtr &)> callback)
84 {
85 auto pPrivate =
86 new std::function<void()>([imagePtr = image, callback]() mutable // NOLINT(cppcoreguidelines-owning-memory)
87 {
88 callback(imagePtr);
89 imagePtr.reset();
90 });
91 auto res = CVB_CALL_CAPI(GSSendImageCB(parent_->Handle(), image->Handle(), &Stream::SendDispatcher, pPrivate));
92 if (res < 0)
93 delete pPrivate; // NOLINT(cppcoreguidelines-owning-memory) on success pPrivate is released in the
94 // SendDispatcher
95 return res;
96 }
97
98 inline CExports::cvbres_t Stream::InnerSend(const Image &image)
99 {
100 return CVB_CALL_CAPI(GSSendImage(parent_->Handle(), image.Handle()));
101 }
102
103 inline CExports::cvbres_t Stream::InnerSend(const ImageBufferDescription &description, void *basePtr,
104 std::size_t bufferSize, std::function<void(void *)> callback)
105 {
106 auto pPrivate = new std::function<void()>([basePtr, callback]() { callback(basePtr); });
107 auto dataBlock = description.ImageDataBlock();
108 auto res = CVB_CALL_CAPI(
109 GSSendBlock(parent_->Handle(), reinterpret_cast<const CExports::GSDataBlock &>(dataBlock),
110 static_cast<CExports::cvbuint8_t *>(basePtr), bufferSize, &Stream::SendDispatcher, pPrivate));
111 if (res < 0)
112 delete pPrivate; // NOLINT(cppcoreguidelines-owning-memory) on success pPrivate is released in the
113 // SendDispatcher
114 return res;
115 }
116
117 inline CExports::cvbres_t Stream::InnerSend(const ChunkImageBufferDescription &description, void *basePtr,
118 std::size_t bufferSize, std::function<void(void *)> callback)
119 {
120 auto pPrivate = new std::function<void()>([basePtr, callback]() { callback(basePtr); });
121 auto dataBlock = description.ChunkImageDataBlock();
122 auto res = CVB_CALL_CAPI(
123 GSSendBlock(parent_->Handle(), reinterpret_cast<const CExports::GSDataBlock &>(dataBlock),
124 static_cast<CExports::cvbuint8_t *>(basePtr), bufferSize, &Stream::SendDispatcher, pPrivate));
125 if (res < 0)
126 delete pPrivate; // NOLINT(cppcoreguidelines-owning-memory) on success pPrivate is released in the
127 // SendDispatcher
128 return res;
129 }
130 } // namespace GevServer
131 CVB_END_INLINE_NS
132} // namespace Cvb
Describes a GenICam Pixel Format Naming Convention (PFNC) compatible image memory buffer with possibl...
Definition chunk_image_buffer_description.hpp:22
Describes a GenICam Pixel Format Naming Convention (PFNC) compatible image memory buffer.
Definition image_buffer_description.hpp:24
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
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
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