CVB++ 15.1
Loading...
Searching...
No Matches
detail_server_base.hpp
1#pragma once
2
3#include "../../_cexports/c_gev_server.h"
4#include "../_decl/decl_node_map.hpp"
5#include "../_decl/decl_server_base.hpp"
6#include "../_decl/decl_stream_base.hpp"
7#include "../../driver/flow_set_pool.hpp"
8#include "../../driver/gendc_descriptor.hpp"
9#include "../logical_network_interface.hpp"
10
11namespace Cvb
12{
13 CVB_BEGIN_INLINE_NS
14 namespace GevServer
15 {
17 {
18 std::lock_guard<std::mutex> lock(nodemapMtx_);
19 if (!nodeMap_)
20 const_cast<ServerBase*>(this)->nodeMap_ = std::make_shared<GevServer::NodeMap>(std::const_pointer_cast<ServerBase>(shared_from_this()));
21
22 return nodeMap_;
23 }
24
26 {
27 return state_;
28 }
29
31 {
32 CExports::TDriver driverType = CExports::DT_Auto;
33 NativeCall([&]() { return CVB_CALL_CAPI(GSDriverType(Handle(), driverType)); });
34 return static_cast<GevServer::DriverType>(driverType);
35 }
36
38 {
39 return GetInfoAsString(Info::ServerUserVersion);
40 }
41
42 inline void ServerBase::SetUserVersion(const String &value)
43 {
44 NativeCall(
45 [&]() { return CExports::GSSetInfoAsStringTyped(Handle(), CExports::GSI_ServerUserVersion, value.c_str()); });
46 }
47
49 {
50 CExports::gsipv4 ip = 0;
51 CExports::gsport port = 0;
52 NativeCall([&]() { return CVB_CALL_CAPI(GSGetLocalIPv4(Handle(), ip, port)); });
53 return Cvb::NetworkConnection{ip, port};
54 }
55
57 {
58 CExports::gsipv4 ip = 0;
59 CExports::gsport port = 0;
60 CVB_CALL_CAPI(GSGetRemoteIPv4(Handle(), ip, port));
61 return Cvb::NetworkConnection{ip, port};
62 }
63
64 inline void ServerBase::Start(const Cvb::NetworkConnection::IPAddress &address)
65 {
67 NativeCall(
68 [&]() { return CVB_CALL_CAPI(GSStartIPv4(Handle(), Cvb::NetworkConnection::ToIPAddressUInt(address))); });
69 state_ = GevServer::State::Disconnected;
70 }
71
72 inline void ServerBase::Start(const Cvb::NetworkConnection::IPAddressUInt &address)
73 {
75 NativeCall([&]() { return CVB_CALL_CAPI(GSStartIPv4(Handle(), address)); });
76 state_ = GevServer::State::Disconnected;
77 }
78
79 inline void ServerBase::Stop()
80 {
82 NativeCall([&]() { return CVB_CALL_CAPI(GSStop(Handle())); });
83 state_ = GevServer::State::Configuration;
84 }
85
86 inline String ServerBase::GetInfoAsString(Info command) const
87 {
88 auto bufferSize = NativeCall<size_t>([&](size_t &size) {
89 return CExports::GSGetInfoAsStringTyped(Handle(), static_cast<CExports::TGSInfo>(command),
90 reinterpret_cast<Char *>(0), size);
91 });
92
93 bufferSize += sizeof(Char);
94 std::vector<Char> buffer(bufferSize);
95
96 NativeCall([&]() {
97 return CExports::GSGetInfoAsStringTyped(Handle(), static_cast<CExports::TGSInfo>(command), buffer.data(),
98 bufferSize);
99 });
100
101 return buffer.data();
102 }
103
104 inline void ServerBase::SetState(const GevServer::State &state) noexcept
105 {
106 state_ = state;
107 }
108
109 inline void ServerBase::RegisterEvents()
110 {
111 std::size_t dummy{0};
112 NativeCall([&]() {
113 return CVB_CALL_CAPI(
114 GSRegisterEvent(Handle(), CExports::TServerEvent::SE_Connected, &ServerBase::OnConnected, this, dummy));
115 });
116 NativeCall([&]() {
117 return CVB_CALL_CAPI(
118 GSRegisterEvent(Handle(), CExports::TServerEvent::SE_Disconnected, &OnDisconnected, this, dummy));
119 });
120 NativeCall([&]() {
121 return CVB_CALL_CAPI(
122 GSRegisterEvent(Handle(), CExports::TServerEvent::SE_AcquisitionStart, &OnAcquisitionStart, this, dummy));
123 });
124 NativeCall([&]() {
125 return CVB_CALL_CAPI(
126 GSRegisterEvent(Handle(), CExports::TServerEvent::SE_AcquisitionStop, &OnAcquisitionStop, this, dummy));
127 });
128 }
129
130 } // namespace GevServer
131 CVB_END_INLINE_NS
132} // namespace Cvb
virtual String UserVersion() const
Gets the user defined version that is appended to the device version.
Definition detail_server_base.hpp:37
virtual void Stop()
Stops this server.
Definition detail_server_base.hpp:79
virtual void SetUserVersion(const String &value)
Sets the user defined version that is appended to the device version.
Definition detail_server_base.hpp:42
virtual GevServer::DriverType DriverType()
Gets the GigE Vision driver used by this server object.
Definition detail_server_base.hpp:30
virtual Cvb::NetworkConnection LocalEndpoint() const
Gets the local end point this server is bound to.
Definition detail_server_base.hpp:48
virtual void * Handle() const noexcept=0
Returns the internal handle of this server object.
virtual void Start(const Cvb::NetworkConnection::IPAddress &address)
Starts this server and binds it to the given address .
Definition detail_server_base.hpp:64
virtual GevServer::State State()
Gets the the current state this server is in.
Definition detail_server_base.hpp:25
virtual NodeMapPtr NodeMap() const
Returns the GenApi node map of this server.
Definition detail_server_base.hpp:16
virtual Cvb::NetworkConnection RemoteEndpoint() const
Gets the remote end point this server is connected to.
Definition detail_server_base.hpp:56
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:231
@ ServerUserVersion
User version of the server.
Definition gevserver.hpp:235
State
These enum entries model the states the server can be in.
Definition decl_server_base.hpp:28
DriverType
GigE Vision driver to use for communication and streaming.
Definition gevserver.hpp:167
std::shared_ptr< NodeMap > NodeMapPtr
Convenience shared pointer for NodeMap.
Definition gevserver.hpp:56
@ String
Node is a string node (no reg).
Definition gevserver.hpp:218
Root namespace for the Image Manager interface.
Definition version.hpp:11
char Char
Character type for wide characters or unicode characters.
Definition string.hpp:63
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