Line | Branch | Exec | Source |
---|---|---|---|
1 | /* GATE PROJECT LICENSE: | ||
2 | +----------------------------------------------------------------------------+ | ||
3 | | Copyright(c) 2018-2025, Stefan Meislinger | | ||
4 | | All rights reserved. | | ||
5 | | | | ||
6 | | Redistribution and use in source and binary forms, with or without | | ||
7 | | modification, are permitted provided that the following conditions are met:| | ||
8 | | | | ||
9 | | 1. Redistributions of source code must retain the above copyright notice, | | ||
10 | | this list of conditions and the following disclaimer. | | ||
11 | | 2. Redistributions in binary form must reproduce the above copyright | | ||
12 | | notice, this list of conditions and the following disclaimer in the | | ||
13 | | documentation and/or other materials provided with the distribution. | | ||
14 | | | | ||
15 | | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"| | ||
16 | | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | | ||
17 | | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | | ||
18 | | ARE DISCLAIMED.IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE | | ||
19 | | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | | ||
20 | | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | | ||
21 | | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | | ||
22 | | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | | ||
23 | | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | | ||
24 | | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF | | ||
25 | | THE POSSIBILITY OF SUCH DAMAGE. | | ||
26 | +----------------------------------------------------------------------------+ | ||
27 | */ | ||
28 | |||
29 | #include "gate/system/netconfigs.hpp" | ||
30 | #include "gate/exceptions.hpp" | ||
31 | #include "gate/memalloc.hpp" | ||
32 | |||
33 | namespace gate | ||
34 | { | ||
35 | namespace sys | ||
36 | { | ||
37 | |||
38 | ✗ | NetInterface::NetInterface() noexcept | |
39 | { | ||
40 | ✗ | Mem::clear(this->impl); | |
41 | ✗ | } | |
42 | |||
43 | 2 | NetInterface::NetInterface(gate_netconfig_nif_t const& src) noexcept | |
44 | { | ||
45 | 2 | Mem::copy(this->impl, src); | |
46 | 2 | } | |
47 | |||
48 | |||
49 | 2 | NetInterface::NetInterface(NetInterface const& src) noexcept | |
50 | { | ||
51 | 2 | Mem::copy(this->impl, src.impl); | |
52 | 2 | } | |
53 | ✗ | NetInterface& NetInterface::operator=(NetInterface const& src) noexcept | |
54 | { | ||
55 | ✗ | if (this != &src) | |
56 | { | ||
57 | ✗ | Mem::copy(this->impl, src.impl); | |
58 | } | ||
59 | ✗ | return *this; | |
60 | } | ||
61 | |||
62 | 4 | NetInterface::~NetInterface() noexcept | |
63 | { | ||
64 | 4 | } | |
65 | |||
66 | ✗ | String NetInterface::Uid() const | |
67 | { | ||
68 | ✗ | return String(this->impl.uid); | |
69 | } | ||
70 | |||
71 | ✗ | String NetInterface::Name() const | |
72 | { | ||
73 | ✗ | return String(this->impl.name); | |
74 | } | ||
75 | |||
76 | ✗ | String NetInterface::DevicePath() const | |
77 | { | ||
78 | ✗ | return String(this->impl.device_path); | |
79 | } | ||
80 | |||
81 | ✗ | String NetInterface::Address() const | |
82 | { | ||
83 | ✗ | return String(this->impl.address); | |
84 | } | ||
85 | |||
86 | ✗ | size_t NetInterface::Index() const | |
87 | { | ||
88 | ✗ | return this->impl.index; | |
89 | } | ||
90 | |||
91 | ✗ | NetInterface::TypeEnum NetInterface::Type() const | |
92 | { | ||
93 | ✗ | return TypeEnum(this->impl.type); | |
94 | } | ||
95 | |||
96 | ✗ | String NetInterface::TypeText() const | |
97 | { | ||
98 | ✗ | return String::createStatic(gate_netconfig_print_type(this->impl.type)); | |
99 | } | ||
100 | |||
101 | ✗ | enumint_t NetInterface::Status() const | |
102 | { | ||
103 | ✗ | return this->impl.status; | |
104 | } | ||
105 | |||
106 | ✗ | String NetInterface::printStatusBit(enumint_t status) | |
107 | { | ||
108 | ✗ | return String::createStatic(gate_netconfig_print_status(status)); | |
109 | } | ||
110 | |||
111 | ✗ | gate_netconfig_nif_t& NetInterface::c_impl() | |
112 | { | ||
113 | ✗ | return this->impl; | |
114 | } | ||
115 | |||
116 | ✗ | gate_netconfig_nif_t const& NetInterface::c_impl() const | |
117 | { | ||
118 | ✗ | return this->impl; | |
119 | } | ||
120 | |||
121 | |||
122 | |||
123 | ✗ | static gate_bool_t nifDispatcherCallback(gate_netconfig_nif_t const* nif, void* userparam) | |
124 | { | ||
125 | ✗ | bool_t ret = true; | |
126 | ✗ | NetConfig::EnumNetInterfaceCallback* ptrCb = static_cast<NetConfig::EnumNetInterfaceCallback*>(userparam); | |
127 | ✗ | if (ptrCb) | |
128 | { | ||
129 | ✗ | NetInterface const obj(*nif); | |
130 | ✗ | ptrCb->invoke(obj, ret); | |
131 | } | ||
132 | ✗ | return ret; | |
133 | } | ||
134 | |||
135 | ✗ | void NetConfig::enumNetInterfaces(EnumNetInterfaceCallback const& callback) | |
136 | { | ||
137 | ✗ | void* param = const_cast<EnumNetInterfaceCallback*>(&callback); | |
138 | ✗ | result_t result = gate_netconfig_enum_nifs(&nifDispatcherCallback, param); | |
139 | ✗ | GATEXX_CHECK_EXCEPTION(result); | |
140 | ✗ | } | |
141 | |||
142 | 2 | static gate_bool_t nifListCallback(gate_netconfig_nif_t const* nif, void* userparam) | |
143 | { | ||
144 | 2 | ArrayList<NetInterface>* ptrList = static_cast<ArrayList<NetInterface>*>(userparam); | |
145 |
1/2✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
|
2 | if (ptrList) |
146 | { | ||
147 | 4 | NetInterface obj(*nif); | |
148 |
1/2✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
|
2 | ptrList->add(obj); |
149 | } | ||
150 | 2 | return true; | |
151 | } | ||
152 | |||
153 | 1 | Array<NetInterface> NetConfig::findAllNetInterfaces() | |
154 | { | ||
155 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
2 | ArrayList<NetInterface> ret; |
156 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | result_t result = gate_netconfig_enum_nifs(&nifListCallback, &ret); |
157 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
|
1 | GATEXX_CHECK_EXCEPTION(result); |
158 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
2 | return ret.toArray(); |
159 | } | ||
160 | |||
161 | } // end of namespace sys | ||
162 | } // end of namespace gate | ||
163 | |||
164 |