CVB++ 15.0
detail_server.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#include "../_decl/decl_server.hpp"
8#include "../_decl/decl_stream.hpp"
9#include "../logical_network_interface.hpp"
10
11namespace Cvb
12{
13 CVB_BEGIN_INLINE_NS
14 namespace GevServer
15 {
17 {
18 return nodeMap_;
19 }
20
22 {
23 if (hasStream_)
24 return gsStream_.AtomicGet(
25 [&]() { return std::make_shared<GevServer::Stream>(std::const_pointer_cast<Server>(shared_from_this())); });
26 else
27 return nullptr;
28 }
29
31 {
32 ServerPtr server(new Server(HandleGuard<Server>(CVB_CALL_CAPI(CreateGevServer())), false));
33 server->CreateNodeMap();
34 return server;
35 }
36
38 GevServer::DriverType driverType)
39 {
40 // Check here is necessary as we cast to uint
41 if (size.Width() < 1)
42 throw std::runtime_error("Width must be larger or equal to 1");
43 if (size.Height() < 1)
44 throw std::runtime_error("Height must be larger or equal to 1");
45 if (pixelFormat == PfncFormat::InvalidPixelFormat)
46 throw std::runtime_error("Invalid pixel format");
47
48 using namespace CExports;
49 auto pixelFormatName = PfncFormatValue::ToANSI(pixelFormat);
50 GSFixedSizeInitInfo init{GSSI_FixedSize,
51 static_cast<cvbuint32_t>(pixelFormat),
52 pixelFormatName.c_str(),
53 static_cast<cvbuint32_t>(size.Width()),
54 static_cast<cvbuint32_t>(size.Height()),
55 intptr_t()}; // Auto calculation
56
57 ServerPtr server(new Server(HandleGuard<Server>(CVB_CALL_CAPI(CreateGevServer2(
58 static_cast<TDriver>(driverType), reinterpret_cast<GSInitInfo &>(init)))),
59 true));
60 server->CreateNodeMap();
61 return server;
62 }
63
65 GevServer::DriverType driverType)
66 {
67 return CreateWithConstSize(size, PfncFormatValue::From(colorModel, dataType), driverType);
68 }
69
71 GevServer::DriverType driverType)
72 {
73 return CreateWithVariableSize(maxSize, PfncFormatValue::From(colorModel, dataType), driverType);
74 }
75
77 GevServer::DriverType driverType)
78 {
79 // check here is necessary as we cast to uint
80 if (maxSize.Width() < 1)
81 throw std::runtime_error("Width must be larger or equal to 1");
82 if (maxSize.Height() < 1)
83 throw std::runtime_error("Height must be larger or equal to 1");
84 if (pixelFormat == PfncFormat::InvalidPixelFormat)
85 throw std::runtime_error("Invalid pixel format");
86
87 using namespace CExports;
88 GSDynamicSizeInitInfo init{GSFixedSizeInitInfo{GSSI_DynamicSize, static_cast<CExports::cvbuint32_t>(pixelFormat),
89 PfncFormatValue::ToANSI(pixelFormat).c_str(),
90 static_cast<CExports::cvbuint32_t>(maxSize.Width()),
91 static_cast<CExports::cvbuint32_t>(maxSize.Height()), intptr_t()},
92 static_cast<CExports::cvbuint32_t>(maxSize.Width()),
93 static_cast<CExports::cvbuint32_t>(maxSize.Height())};
94
95 ServerPtr server(new Server(HandleGuard<Server>(CVB_CALL_CAPI(CreateGevServer2(
96 static_cast<TDriver>(driverType), reinterpret_cast<GSInitInfo &>(init)))),
97 true));
98 server->CreateNodeMap();
99 return server;
100 }
101
103 {
104 return state_;
105 }
106
108 {
109 CExports::TDriver driverType = CExports::DT_Auto;
110 NativeCall([&]() { return CVB_CALL_CAPI(GSDriverType(Handle(), driverType)); });
111 return static_cast<GevServer::DriverType>(driverType);
112 }
113
115 {
116 return GetInfoAsString(Info::ServerUserVersion);
117 }
118
119 inline void Server::SetUserVersion(const String &value)
120 {
121 NativeCall(
122 [&]() { return CExports::GSSetInfoAsStringTyped(Handle(), CExports::GSI_ServerUserVersion, value.c_str()); });
123 }
124
126 {
127 CExports::gsipv4 ip = 0;
128 CExports::gsport port = 0;
129 NativeCall([&]() { return CVB_CALL_CAPI(GSGetLocalIPv4(Handle(), ip, port)); });
130 return Cvb::NetworkConnection{ip, port};
131 }
132
134 {
135 CExports::gsipv4 ip = 0;
136 CExports::gsport port = 0;
137 CVB_CALL_CAPI(GSGetRemoteIPv4(Handle(), ip, port));
138 return Cvb::NetworkConnection{ip, port};
139 }
140
141 inline void Server::Start(const Cvb::NetworkConnection::IPAddress &address)
142 {
144 NativeCall(
145 [&]() { return CVB_CALL_CAPI(GSStartIPv4(Handle(), Cvb::NetworkConnection::ToIPAddressUInt(address))); });
146 state_ = GevServer::State::Disconnected;
147 }
148
149 inline void Server::Start(const Cvb::NetworkConnection::IPAddressUInt &address)
150 {
152 NativeCall([&]() { return CVB_CALL_CAPI(GSStartIPv4(Handle(), address)); });
153 state_ = GevServer::State::Disconnected;
154 }
155
156 inline void Server::Stop()
157 {
159 NativeCall([&]() { return CVB_CALL_CAPI(GSStop(Handle())); });
160 state_ = GevServer::State::Configuration;
161 }
162
163 inline String Server::GetInfoAsString(Info command) const
164 {
165 auto bufferSize = NativeCall<size_t>([&](size_t &size) {
166 return CExports::GSGetInfoAsStringTyped(Handle(), static_cast<CExports::TGSInfo>(command),
167 reinterpret_cast<Char *>(0), size);
168 });
169
170 bufferSize += sizeof(Char);
171 std::vector<Char> buffer(bufferSize);
172
173 NativeCall([&]() {
174 return CExports::GSGetInfoAsStringTyped(Handle(), static_cast<CExports::TGSInfo>(command), buffer.data(),
175 bufferSize);
176 });
177
178 return buffer.data();
179 }
180
181 inline void Server::SetState(const GevServer::State &state) noexcept
182 {
183 state_ = state;
184 }
185
186 inline void Server::CreateNodeMap()
187 {
188 std::lock_guard<std::mutex> lock(mtx);
189 nodeMap_ = std::make_shared<GevServer::NodeMap>(std::const_pointer_cast<Server>(shared_from_this()));
190 }
191 } // namespace GevServer
192 CVB_END_INLINE_NS
193} // namespace Cvb
Data type description for an image plane.
Definition data_type.hpp:23
String UserVersion() const
Gets the user defined version that is appended to the device version.
Definition detail_server.hpp:114
void Stop()
Stops this server.
Definition detail_server.hpp:156
void SetUserVersion(const String &value)
Sets the user defined version that is appended to the device version.
Definition detail_server.hpp:119
GevServer::DriverType DriverType()
Gets the GigE Vision driver used by this server object.
Definition detail_server.hpp:107
Cvb::NetworkConnection LocalEndpoint() const
Gets the local end point this server is bound to.
Definition detail_server.hpp:125
void Start(const Cvb::NetworkConnection::IPAddress &address)
Starts this server and binds it to the given address .
Definition detail_server.hpp:141
static ServerPtr CreateNonStreaming()
Creates a non-streaming GigE Vision server object.
Definition detail_server.hpp:30
static ServerPtr CreateWithVariableSize(Size2D< int > maxSize, ColorModel colorModel, DataType dataType, GevServer::DriverType driverType=GevServer::DriverType::Auto)
Creates a new Server object with a client configurable width, height and offsets.
Definition detail_server.hpp:70
GevServer::State State()
Gets the the current state this server is in.
Definition detail_server.hpp:102
NodeMapPtr NodeMap() const
Gets this servers node map.
Definition detail_server.hpp:16
Cvb::NetworkConnection RemoteEndpoint() const
Gets the remote end point this server is connected to.
Definition detail_server.hpp:133
static ServerPtr CreateWithConstSize(Size2D< int > size, PfncFormat pixelFormat, GevServer::DriverType driverType=GevServer::DriverType::Auto)
Creates a new Server object with a constant width and height.
Definition detail_server.hpp:37
StreamPtr Stream() const
Gets the Cvb::GevServer::Stream for sending Images or other data.
Definition detail_server.hpp:21
void * Handle() const noexcept
Classic API device handle.
Definition decl_server.hpp:147
static PfncFormat From(const ColorModel &colorModel, const DataType &dataType)
Tries to coerce the PfncFormat from the given colorModel and dataType .
Definition pfnc_format.hpp:1068
Stores a pair of numbers that represents the width and the height of a subject, typically a rectangle...
Definition size_2d.hpp:20
T Height() const noexcept
Gets the vertical component of the size.
Definition size_2d.hpp:77
T Width() const noexcept
Gets the horizontal component of the size.
Definition size_2d.hpp:57
T lock(T... args)
T make_shared(T... args)
Namespace for GevServer based device configuration.
Definition decl_int_swiss_knife_node.hpp:11
Info
General version and acquisition information.
Definition gevserver.hpp:190
@ ServerUserVersion
User version of the server.
Definition gevserver.hpp:194
std::shared_ptr< Stream > StreamPtr
Convenience shared pointer for Stream.
Definition gevserver.hpp:49
State
The possible states this GevServer can be in.
Definition decl_server.hpp:32
DriverType
GigE Vision driver to use for communication and streaming.
Definition gevserver.hpp:139
std::shared_ptr< NodeMap > NodeMapPtr
Convenience shared pointer for NodeMap.
Definition gevserver.hpp:45
std::shared_ptr< Server > ServerPtr
Convenience shared pointer for GevServer.
Definition gevserver.hpp:37
@ String
Node is a string node (no reg).
Definition gevserver.hpp:177
PfncFormat
GenICam Pixel Format Naming Convention (PFNC) format values.
Definition pfnc_format.hpp:34
Root namespace for the Image Manager interface.
Definition c_bayer_to_rgb.h:17
char Char
Character type for wide characters or unicode characters.
Definition string.hpp:63
ColorModel
Color model that this image is using.
Definition global.hpp:176
T const_pointer_cast(T... args)
Basic network connection operations.
Definition network_connection.hpp:15
static IPAddressUInt ToIPAddressUInt(const IPAddress &ip)
Creates an uint ip . from the given IPAddress
Definition network_connection.hpp:68