CVB++ 15.0
logical_network_interface.hpp
1#pragma once
2
3#include "../global.hpp"
4
5#include "../network_connection.hpp"
6#include "gevserver.hpp"
7
8#include "../_cexports/c_img.h"
9
10namespace Cvb
11{
12 CVB_BEGIN_INLINE_NS
13
14 template <>
15 inline HandleGuard<CExports::GEVIFACELIST>::HandleGuard(void *handle) noexcept
16 : HandleGuard<CExports::GEVIFACELIST>(handle, [](void *handle) { CVB_CALL_CAPI(ReleaseObject(handle)); })
17 {
18 }
19
20 namespace GevServer
21 {
26 struct LogicalNetworkInterface
27 {
28 typedef Cvb::NetworkConnection::IPAddress IPAddressType;
29 typedef Cvb::NetworkConnection::IPAddress IPv4MaskType;
30 typedef Cvb::NetworkConnection::IPAddressUInt IPAddressTypeUInt;
31 typedef std::uint16_t PortType;
32
39 {
40 HandleGuard<CExports::GEVIFACELIST> guard(CVB_CALL_CAPI(CreateInterfaceList()));
41 if (!guard.Handle())
42 throw std::runtime_error("Failed to create interface list");
43
44 auto numInterfaces = CVB_CALL_CAPI(ILCount(guard.Handle()));
46
47 for (std::size_t i = 0; i < numInterfaces; ++i)
48 {
49 CExports::gsipv4 ip = 0;
50 if (CVB_CALL_CAPI(ILIPv4Address(guard.Handle(), i, ip)))
51 throw std::runtime_error("error retrieving IP");
52
53 CExports::gsipv4 subnetMask = 0;
54 if (CVB_CALL_CAPI(ILIPv4SubnetMask(guard.Handle(), i, subnetMask)))
55 throw std::runtime_error("error retrieving subnet mask");
56
57 interfaces.push_back(LogicalNetworkInterface(Cvb::NetworkConnection::ToIPAddress(ip),
59 }
60 return interfaces;
61 }
62
63 LogicalNetworkInterface(const IPAddressType &ip, const IPv4MaskType &ipv4Mask)
64 : ipAddress_{ip}
65 , ipv4Mask_{ipv4Mask}
66 {
67 }
68
69 LogicalNetworkInterface(const IPAddressTypeUInt &ipUInt, const IPv4MaskType &ipv4Mask)
70 : ipAddressUInt_{ipUInt}
71 , ipv4Mask_{ipv4Mask}
72 {
73 }
74
78 IPAddressType IPAddress() const
79 {
80 return ipAddress_;
81 }
82
86 void SetIPAddress(const IPAddressType &ipAddress)
87 {
88 ipAddress_ = ipAddress;
89 ipAddressUInt_ = Cvb::NetworkConnection::ToIPAddressUInt(ipAddress_);
90 }
91
95 IPAddressTypeUInt IPAddressUInt() const
96 {
97 return ipAddressUInt_;
98 }
99
103 void SetIPAddressUInt(const IPAddressTypeUInt &ipAddressUInt)
104 {
105 ipAddressUInt_ = ipAddressUInt;
106 ipAddress_ = Cvb::NetworkConnection::ToIPAddress(ipAddressUInt_);
107 }
108
112 IPAddressType IPv4Mask() const
113 {
114 return ipv4Mask_;
115 }
116
120 void IPv4Mask(const IPAddressType &ipv4Mask)
121 {
122 ipv4Mask_ = ipv4Mask;
123 }
124
125 IPAddressType ipAddress_;
126 IPAddressTypeUInt ipAddressUInt_ = 0;
127 IPv4MaskType ipv4Mask_;
128 };
129 } // namespace GevServer
130 CVB_END_INLINE_NS
131} // namespace Cvb
cvbbool_t ReleaseObject(OBJ &Object)
Namespace for GevServer based device configuration.
Definition decl_int_swiss_knife_node.hpp:11
Root namespace for the Image Manager interface.
Definition c_bayer_to_rgb.h:17
An IP network interface the GevServer can be bound to.
Definition logical_network_interface.hpp:27
void IPv4Mask(const IPAddressType &ipv4Mask)
Sets the subnet mask of the Address.
Definition logical_network_interface.hpp:120
static std::vector< LogicalNetworkInterface > GetAllAvailable()
Gets all available network interfaces usable by the GevServer.
Definition logical_network_interface.hpp:38
void SetIPAddress(const IPAddressType &ipAddress)
Sets the address of the interface as string and converted uint.
Definition logical_network_interface.hpp:86
void SetIPAddressUInt(const IPAddressTypeUInt &ipAddressUInt)
Sets the address of the interface as unsigned integer and converted string ip address.
Definition logical_network_interface.hpp:103
IPAddressTypeUInt IPAddressUInt() const
Gets the address of the interface as unsigned integer.
Definition logical_network_interface.hpp:95
IPAddressType IPAddress() const
Gets the address of the interface.
Definition logical_network_interface.hpp:78
IPAddressType IPv4Mask() const
Gets the subnet mask of the Address.
Definition logical_network_interface.hpp:112
static IPAddress ToIPAddress(const IPAddressUInt &ipAddressInt)
Creates an IPAddress from the given uint ip .
Definition network_connection.hpp:46
static IPAddressUInt ToIPAddressUInt(const IPAddress &ip)
Creates an uint ip . from the given IPAddress
Definition network_connection.hpp:68