VirtualBox

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

Last change on this file since 94722 was 93115, checked in by vboxsync, 3 years ago

scm --update-copyright-year

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