VirtualBox

source: vbox/trunk/src/VBox/Main/src-server/HostOnlyNetworkImpl.cpp@ 106061

Last change on this file since 106061 was 106061, checked in by vboxsync, 2 months ago

Copyright year updates by scm.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 7.0 KB
Line 
1/* $Id: HostOnlyNetworkImpl.cpp 106061 2024-09-16 14:03:52Z vboxsync $ */
2/** @file
3 * IHostOnlyNetwork COM class implementations.
4 */
5
6/*
7 * Copyright (C) 2021-2024 Oracle and/or its affiliates.
8 *
9 * This file is part of VirtualBox base platform packages, as
10 * available from https://www.virtualbox.org.
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation, in version 3 of the
15 * License.
16 *
17 * This program is distributed in the hope that it will be useful, but
18 * WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 * General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, see <https://www.gnu.org/licenses>.
24 *
25 * SPDX-License-Identifier: GPL-3.0-only
26 */
27
28
29#define LOG_GROUP LOG_GROUP_MAIN_HOSTONLYNETWORK
30#include <VBox/settings.h>
31#include <iprt/cpp/utils.h>
32
33#include "VirtualBoxImpl.h"
34#include "HostOnlyNetworkImpl.h"
35#include "AutoCaller.h"
36#include "LoggingNew.h"
37
38
39struct HostOnlyNetwork::Data
40{
41 Data() : pVirtualBox(NULL) {}
42 virtual ~Data() {}
43
44 /** weak VirtualBox parent */
45 VirtualBox * const pVirtualBox;
46
47 /** HostOnlyNetwork settings */
48 settings::HostOnlyNetwork s;
49};
50
51////////////////////////////////////////////////////////////////////////////////
52//
53// HostOnlyNetwork constructor / destructor
54//
55// ////////////////////////////////////////////////////////////////////////////////
56HostOnlyNetwork::HostOnlyNetwork() : m(NULL)
57{
58}
59
60HostOnlyNetwork::~HostOnlyNetwork()
61{
62}
63
64
65HRESULT HostOnlyNetwork::FinalConstruct()
66{
67 return BaseFinalConstruct();
68}
69
70void HostOnlyNetwork::FinalRelease()
71{
72 uninit();
73
74 BaseFinalRelease();
75}
76
77HRESULT HostOnlyNetwork::init(VirtualBox *aVirtualBox, Utf8Str aName)
78{
79 // Enclose the state transition NotReady->InInit->Ready.
80 AutoInitSpan autoInitSpan(this);
81 AssertReturn(autoInitSpan.isOk(), E_FAIL);
82
83 m = new Data();
84 /* share VirtualBox weakly */
85 unconst(m->pVirtualBox) = aVirtualBox;
86
87 m->s.strNetworkName = aName;
88 m->s.fEnabled = true;
89 m->s.uuid.create();
90
91 autoInitSpan.setSucceeded();
92 return S_OK;
93}
94
95void HostOnlyNetwork::uninit()
96{
97 // Enclose the state transition Ready->InUninit->NotReady.
98 AutoUninitSpan autoUninitSpan(this);
99 if (autoUninitSpan.uninitDone())
100 return;
101}
102
103HRESULT HostOnlyNetwork::i_loadSettings(const settings::HostOnlyNetwork &data)
104{
105 AutoCaller autoCaller(this);
106 AssertComRCReturnRC(autoCaller.hrc());
107
108 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
109 m->s = data;
110
111 return S_OK;
112}
113
114HRESULT HostOnlyNetwork::i_saveSettings(settings::HostOnlyNetwork &data)
115{
116 AutoCaller autoCaller(this);
117 if (FAILED(autoCaller.hrc())) return autoCaller.hrc();
118
119 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
120 AssertReturn(!m->s.strNetworkName.isEmpty(), E_FAIL);
121 data = m->s;
122
123 return S_OK;
124}
125
126#if 0
127Utf8Str HostOnlyNetwork::i_getNetworkId()
128{
129 return m->s.strNetworkId;
130}
131
132Utf8Str HostOnlyNetwork::i_getNetworkName()
133{
134 return m->s.strNetworkName;
135}
136#endif
137
138
139HRESULT HostOnlyNetwork::getNetworkName(com::Utf8Str &aNetworkName)
140{
141 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
142 AssertReturn(!m->s.strNetworkName.isEmpty(), E_FAIL);
143 aNetworkName = m->s.strNetworkName;
144 return S_OK;
145}
146
147HRESULT HostOnlyNetwork::setNetworkName(const com::Utf8Str &aNetworkName)
148{
149 if (aNetworkName.isEmpty())
150 return setError(E_INVALIDARG,
151 tr("Network name cannot be empty"));
152 {
153 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
154 if (aNetworkName == m->s.strNetworkName)
155 return S_OK;
156
157 m->s.strNetworkName = aNetworkName;
158 }
159
160 AutoWriteLock vboxLock(m->pVirtualBox COMMA_LOCKVAL_SRC_POS);
161 HRESULT hrc = m->pVirtualBox->i_saveSettings();
162 ComAssertComRCRetRC(hrc);
163 return S_OK;
164}
165
166HRESULT HostOnlyNetwork::getNetworkMask(com::Utf8Str &aNetworkMask)
167{
168 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
169 AssertReturn(!m->s.strNetworkMask.isEmpty(), E_FAIL);
170 aNetworkMask = m->s.strNetworkMask;
171 return S_OK;
172}
173
174HRESULT HostOnlyNetwork::setNetworkMask(const com::Utf8Str &aNetworkMask)
175{
176 if (aNetworkMask.isEmpty())
177 return setError(E_INVALIDARG,
178 tr("Network mask cannot be empty"));
179 {
180 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
181 if (aNetworkMask == m->s.strNetworkMask)
182 return S_OK;
183
184 m->s.strNetworkMask = aNetworkMask;
185 }
186
187 AutoWriteLock vboxLock(m->pVirtualBox COMMA_LOCKVAL_SRC_POS);
188 HRESULT hrc = m->pVirtualBox->i_saveSettings();
189 ComAssertComRCRetRC(hrc);
190 return S_OK;
191}
192
193HRESULT HostOnlyNetwork::getEnabled(BOOL *aEnabled)
194{
195 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
196 *aEnabled = m->s.fEnabled;
197 return S_OK;
198}
199
200HRESULT HostOnlyNetwork::setEnabled(BOOL aEnabled)
201{
202 {
203 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
204 if (RT_BOOL(aEnabled) == m->s.fEnabled)
205 return S_OK;
206 m->s.fEnabled = RT_BOOL(aEnabled);
207 }
208
209 AutoWriteLock vboxLock(m->pVirtualBox COMMA_LOCKVAL_SRC_POS);
210 HRESULT hrc = m->pVirtualBox->i_saveSettings();
211 ComAssertComRCRetRC(hrc);
212 return S_OK;
213}
214
215HRESULT HostOnlyNetwork::getHostIP(com::Utf8Str &aHostIP)
216{
217 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
218 aHostIP = m->s.strIPLower;
219 return S_OK;
220}
221
222HRESULT HostOnlyNetwork::getLowerIP(com::Utf8Str &aLowerIP)
223{
224 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
225 aLowerIP = m->s.strIPLower;
226 return S_OK;
227}
228
229HRESULT HostOnlyNetwork::setLowerIP(const com::Utf8Str &aLowerIP)
230{
231 {
232 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
233 if (aLowerIP == m->s.strIPLower)
234 return S_OK;
235 m->s.strIPLower = aLowerIP;
236 }
237
238 AutoWriteLock vboxLock(m->pVirtualBox COMMA_LOCKVAL_SRC_POS);
239 HRESULT hrc = m->pVirtualBox->i_saveSettings();
240 ComAssertComRCRetRC(hrc);
241 return S_OK;
242}
243
244HRESULT HostOnlyNetwork::getUpperIP(com::Utf8Str &aUpperIP)
245{
246 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
247 aUpperIP = m->s.strIPUpper;
248 return S_OK;
249}
250
251HRESULT HostOnlyNetwork::setUpperIP(const com::Utf8Str &aUpperIP)
252{
253 {
254 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
255 if (aUpperIP == m->s.strIPUpper)
256 return S_OK;
257 m->s.strIPUpper = aUpperIP;
258 }
259
260 AutoWriteLock vboxLock(m->pVirtualBox COMMA_LOCKVAL_SRC_POS);
261 HRESULT hrc = m->pVirtualBox->i_saveSettings();
262 ComAssertComRCRetRC(hrc);
263 return S_OK;
264}
265
266HRESULT HostOnlyNetwork::getId(com::Guid &aId)
267{
268 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
269 aId = m->s.uuid;
270 return S_OK;
271}
272
273HRESULT HostOnlyNetwork::setId(const com::Guid &aId)
274{
275 {
276 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
277 if (aId == m->s.uuid)
278 return S_OK;
279 m->s.uuid = aId;
280 }
281
282 AutoWriteLock vboxLock(m->pVirtualBox COMMA_LOCKVAL_SRC_POS);
283 HRESULT hrc = m->pVirtualBox->i_saveSettings();
284 ComAssertComRCRetRC(hrc);
285 return S_OK;
286}
287
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette