3#include "../_cexports/c_webstreaming.h"
4#include "webstreaming.hpp"
5#include "converter.hpp"
6#include "../string.hpp"
7#include "../global.hpp"
16inline HandleGuard<WebStreaming::Server>::HandleGuard(
void* handle) noexcept
17 : HandleGuard<WebStreaming::Server>(handle, [](
void* handle) { CVB_CALL_CAPI(ReleaseObject(handle)); })
35 using GuardType = HandleGuard<Server>;
55 return Internal::DoResCallShareOut<Server>([&](
void*& handle)
57 return CVB_CALL_CAPI(CVWSCreateServerTyped(ipAddress.c_str(),
static_cast<CExports::cvbval_t
>(port), converter->Handle(), handle));
58 }, ipAddress, port, converter);
72 CExports::CVWSCONVERTER converter =
nullptr;
73 CVB_CALL_CAPI_CHECKED(CVWSCreateConverter(CExports::CVWSCT_Raw, converter));
74 HandleGuard<Converter> converterGuard(converter);
75 return Internal::DoResCallShareOut<Server>([&](
void*& handle)
77 return CVB_CALL_CAPI(CVWSCreateServerTyped(ipAddress.c_str(),
static_cast<CExports::cvbval_t
>(port), converterGuard.Handle(), handle));
87 return std::make_shared<T>(std::move(guard), ipAddress, port, converter, PrivateTag{});
90 Server(HandleGuard<Server>&& guard,
const String& ipAddress,
int port,
const ConverterPtr& converter, PrivateTag) noexcept
91 : handle_(std::move(guard))
92 , ipAddress_(ipAddress)
94 , converter_(converter)
106 CExports::cvbint64_t value = -1;
107 CVB_CALL_CAPI_CHECKED(CVWSServerGetPropertyAsInteger(
Handle(), CExports::CVWSSP_ActiveConnections, value));
108 return static_cast<int>(value);
121 CVB_CALL_CAPI_CHECKED(CVWSStreamingSyncSendImage(
Handle(), image.
Handle()));
134 CVB_CALL_CAPI_CHECKED(CVWSStreamingAsyncSendImage(
Handle(), image.
Handle()));
144 return handle_.Handle();
171 HandleGuard<Server> handle_;
The Common Vision Blox image.
Definition: decl_image.hpp:45
void * Handle() const noexcept
Classic API image handle.
Definition: decl_image.hpp:226
A WebSocket server.
Definition: server.hpp:32
void SendAsync(const Image &image)
Sends an image asynchronously.
Definition: server.hpp:132
static ServerPtr Create(const String &ipAddress, int port, const ConverterPtr &converter)
Creates a WebSocket server with given converter.
Definition: server.hpp:53
String IPAddress() const noexcept
Get the IP address of the server.
Definition: server.hpp:153
int ActiveConnections() const
Get the number of active connections.
Definition: server.hpp:104
static ServerPtr Create(const String &ipAddress, int port)
Creates a WebSocket server.
Definition: server.hpp:70
int Port() const noexcept
Get destination port.
Definition: server.hpp:164
void SendSync(const Image &image)
Sends an image synchronously.
Definition: server.hpp:119
void * Handle() const noexcept
Returns C-API style handle to Server Object.
Definition: server.hpp:142
std::shared_ptr< Converter > ConverterPtr
Convenience shared pointer for Converter.
Definition: webstreaming.hpp:22
Root namespace for the Image Manager interface.
Definition: c_barcode.h:15