CVB++ 15.1
Loading...
Searching...
No Matches
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 {
17 class Stream;
18
19 inline void Stream::Send(const ImagePtr &image, std::function<void(const ImagePtr &)> imageReleased)
20 {
21 int result = InnerSend(image, imageReleased);
22 if (result < 0)
23 throw std::runtime_error("Could not send image");
24 }
25
26 inline bool Stream::TrySend(const ImagePtr &image, std::function<void(const ImagePtr &)> imageReleased)
27 {
28 return InnerSend(image, imageReleased) >= 0;
29 }
30
31 inline void Stream::Send(const Image &image)
32 {
33 if (ResendBuffersCount() > 0)
34 throw std::runtime_error("Packet resend must be disabled for send without callback");
35
36 int result = InnerSend(image);
37 if (result < 0)
38 throw std::runtime_error("Could not send image");
39 }
40
41 inline bool Stream::TrySend(const Image &image)
42 {
43 if (ResendBuffersCount() > 0)
44 throw std::runtime_error("Packet resend must be disabled for send without callback");
45
46 return InnerSend(image) >= 0;
47 }
48
49 inline void Stream::Send(const ImageBufferDescription &bufferDescription, void *basePtr,
50 const std::size_t &bufferSize, std::function<void(void *)> bufferReleased)
51 {
52 int result = InnerSend(bufferDescription, basePtr, bufferSize, bufferReleased);
53 if (result < 0)
54 throw std::runtime_error("Could not send image");
55 }
56
57 inline bool Stream::TrySend(const ImageBufferDescription &bufferDescription, void *basePtr,
58 const std::size_t &bufferSize, std::function<void(void *)> bufferReleased)
59 {
60 return InnerSend(bufferDescription, basePtr, bufferSize, bufferReleased) >= 0;
61 }
62
63 inline CExports::cvbres_t Stream::InnerSend(const ImagePtr &image, std::function<void(const ImagePtr &)> callback)
64 {
65 auto pPrivate =
66 new std::function<void()>([imagePtr = image, callback]() mutable // NOLINT(cppcoreguidelines-owning-memory)
67 {
68 callback(imagePtr);
69 imagePtr.reset();
70 });
71 auto res = CVB_CALL_CAPI(GSSendImageCB(parent_->Handle(), image->Handle(), &Stream::SendDispatcher, pPrivate));
72 if (res < 0)
73 delete pPrivate; // NOLINT(cppcoreguidelines-owning-memory) on success pPrivate is released in the
74 // SendDispatcher
75 return res;
76 }
77
78 inline CExports::cvbres_t Stream::InnerSend(const Image &image)
79 {
80 return CVB_CALL_CAPI(GSSendImage(parent_->Handle(), image.Handle()));
81 }
82
83 inline CExports::cvbres_t Stream::InnerSend(const ImageBufferDescription &description, void *basePtr,
84 std::size_t bufferSize, std::function<void(void *)> callback)
85 {
86 auto pPrivate = new std::function<void()>([basePtr, callback]() { callback(basePtr); });
87 auto dataBlock = description.ImageDataBlock();
88 auto res = CVB_CALL_CAPI(
89 GSSendBlock(parent_->Handle(), reinterpret_cast<const CExports::GSDataBlock &>(dataBlock),
90 static_cast<CExports::cvbuint8_t *>(basePtr), bufferSize, &Stream::SendDispatcher, pPrivate));
91 if (res < 0)
92 delete pPrivate; // NOLINT(cppcoreguidelines-owning-memory) on success pPrivate is released in the
93 // SendDispatcher
94 return res;
95 }
96
97 inline CExports::cvbres_t Stream::InnerSend(const ChunkImageBufferDescription &description, void *basePtr,
98 std::size_t bufferSize, std::function<void(void *)> callback)
99 {
100 auto pPrivate = new std::function<void()>([basePtr, callback]() { callback(basePtr); });
101 auto dataBlock = description.ChunkImageDataBlock();
102 auto res = CVB_CALL_CAPI(
103 GSSendBlock(parent_->Handle(), reinterpret_cast<const CExports::GSDataBlock &>(dataBlock),
104 static_cast<CExports::cvbuint8_t *>(basePtr), bufferSize, &Stream::SendDispatcher, pPrivate));
105 if (res < 0)
106 delete pPrivate; // NOLINT(cppcoreguidelines-owning-memory) on success pPrivate is released in the
107 // SendDispatcher
108 return res;
109 }
110 } // namespace GevServer
111 CVB_END_INLINE_NS
112} // 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
virtual std::int64_t ResendBuffersCount() const
Gets the number of resend buffers.
Definition detail_stream_base.hpp:22
The stream to send Images or other data.
Definition decl_stream.hpp:20
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:26
void Send(const ImagePtr &image, std::function< void(const ImagePtr &)> imageReleased)
Sends the given image to the remote client.
Definition detail_stream.hpp:19
Namespace for GevServer based device configuration.
Definition decl_int_swiss_knife_node.hpp:11
@ Image
Image payload.
Definition gevserver.hpp:313
Root namespace for the Image Manager interface.
Definition version.hpp:11
std::shared_ptr< Image > ImagePtr
Convenience shared pointer for Image.
Definition global.hpp:86