VirtualBox

source: vbox/trunk/src/VBox/Main/src-server/CloudNetworkImpl.cpp@ 106378

Last change on this file since 106378 was 106061, checked in by vboxsync, 3 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: 6.3 KB
Line 
1/* $Id: CloudNetworkImpl.cpp 106061 2024-09-16 14:03:52Z vboxsync $ */
2/** @file
3 * ICloudNetwork COM class implementations.
4 */
5
6/*
7 * Copyright (C) 2019-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_CLOUDNETWORK
30#include <VBox/settings.h>
31#include <iprt/cpp/utils.h>
32
33#include "VirtualBoxImpl.h"
34#include "CloudNetworkImpl.h"
35#include "AutoCaller.h"
36#include "LoggingNew.h"
37
38
39struct CloudNetwork::Data
40{
41 Data() : pVirtualBox(NULL) {}
42 virtual ~Data() {}
43
44 /** weak VirtualBox parent */
45 VirtualBox * const pVirtualBox;
46
47 /** CloudNetwork settings */
48 settings::CloudNetwork s;
49};
50
51////////////////////////////////////////////////////////////////////////////////
52//
53// CloudNetwork constructor / destructor
54//
55// ////////////////////////////////////////////////////////////////////////////////
56CloudNetwork::CloudNetwork() : m(NULL)
57{
58}
59
60CloudNetwork::~CloudNetwork()
61{
62}
63
64
65HRESULT CloudNetwork::FinalConstruct()
66{
67 return BaseFinalConstruct();
68}
69
70void CloudNetwork::FinalRelease()
71{
72 uninit();
73
74 BaseFinalRelease();
75}
76
77HRESULT CloudNetwork::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.strProviderShortName = "OCI";
90 m->s.strProfileName = "Default";
91
92 autoInitSpan.setSucceeded();
93 return S_OK;
94}
95
96void CloudNetwork::uninit()
97{
98 // Enclose the state transition Ready->InUninit->NotReady.
99 AutoUninitSpan autoUninitSpan(this);
100 if (autoUninitSpan.uninitDone())
101 return;
102}
103
104HRESULT CloudNetwork::i_loadSettings(const settings::CloudNetwork &data)
105{
106 AutoCaller autoCaller(this);
107 AssertComRCReturnRC(autoCaller.hrc());
108
109 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
110 m->s = data;
111
112 return S_OK;
113}
114
115HRESULT CloudNetwork::i_saveSettings(settings::CloudNetwork &data)
116{
117 AutoCaller autoCaller(this);
118 if (FAILED(autoCaller.hrc())) return autoCaller.hrc();
119
120 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
121 AssertReturn(!m->s.strNetworkName.isEmpty(), E_FAIL);
122 data = m->s;
123
124 return S_OK;
125}
126
127Utf8Str CloudNetwork::i_getProvider()
128{
129 return m->s.strProviderShortName;
130}
131
132Utf8Str CloudNetwork::i_getProfile()
133{
134 return m->s.strProfileName;
135}
136
137Utf8Str CloudNetwork::i_getNetworkId()
138{
139 return m->s.strNetworkId;
140}
141
142Utf8Str CloudNetwork::i_getNetworkName()
143{
144 return m->s.strNetworkName;
145}
146
147
148HRESULT CloudNetwork::getNetworkName(com::Utf8Str &aNetworkName)
149{
150 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
151 AssertReturn(!m->s.strNetworkName.isEmpty(), E_FAIL);
152 aNetworkName = m->s.strNetworkName;
153 return S_OK;
154}
155
156HRESULT CloudNetwork::setNetworkName(const com::Utf8Str &aNetworkName)
157{
158 if (aNetworkName.isEmpty())
159 return setError(E_INVALIDARG,
160 tr("Network name cannot be empty"));
161 {
162 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
163 if (aNetworkName == m->s.strNetworkName)
164 return S_OK;
165
166 m->s.strNetworkName = aNetworkName;
167 }
168
169 AutoWriteLock vboxLock(m->pVirtualBox COMMA_LOCKVAL_SRC_POS);
170 HRESULT hrc = m->pVirtualBox->i_saveSettings();
171 ComAssertComRCRetRC(hrc);
172 return S_OK;
173}
174
175HRESULT CloudNetwork::getEnabled(BOOL *aEnabled)
176{
177 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
178 *aEnabled = m->s.fEnabled;
179 return S_OK;
180}
181
182HRESULT CloudNetwork::setEnabled(BOOL aEnabled)
183{
184 {
185 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
186 if (RT_BOOL(aEnabled) == m->s.fEnabled)
187 return S_OK;
188 m->s.fEnabled = RT_BOOL(aEnabled);
189 }
190
191 AutoWriteLock vboxLock(m->pVirtualBox COMMA_LOCKVAL_SRC_POS);
192 HRESULT hrc = m->pVirtualBox->i_saveSettings();
193 ComAssertComRCRetRC(hrc);
194 return S_OK;
195}
196
197HRESULT CloudNetwork::getProvider(com::Utf8Str &aProvider)
198{
199 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
200 aProvider = m->s.strProviderShortName;
201 return S_OK;
202}
203
204HRESULT CloudNetwork::setProvider(const com::Utf8Str &aProvider)
205{
206 {
207 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
208 if (aProvider == m->s.strProviderShortName)
209 return S_OK;
210 m->s.strProviderShortName = aProvider;
211 }
212
213 AutoWriteLock vboxLock(m->pVirtualBox COMMA_LOCKVAL_SRC_POS);
214 HRESULT hrc = m->pVirtualBox->i_saveSettings();
215 ComAssertComRCRetRC(hrc);
216 return S_OK;
217}
218
219HRESULT CloudNetwork::getProfile(com::Utf8Str &aProfile)
220{
221 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
222 aProfile = m->s.strProfileName;
223 return S_OK;
224}
225
226HRESULT CloudNetwork::setProfile(const com::Utf8Str &aProfile)
227{
228 {
229 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
230 if (aProfile == m->s.strProfileName)
231 return S_OK;
232 m->s.strProfileName = aProfile;
233 }
234
235 AutoWriteLock vboxLock(m->pVirtualBox COMMA_LOCKVAL_SRC_POS);
236 HRESULT hrc = m->pVirtualBox->i_saveSettings();
237 ComAssertComRCRetRC(hrc);
238 return S_OK;
239}
240
241HRESULT CloudNetwork::getNetworkId(com::Utf8Str &aNetworkId)
242{
243 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
244 aNetworkId = m->s.strNetworkId;
245 return S_OK;
246}
247
248HRESULT CloudNetwork::setNetworkId(const com::Utf8Str &aNetworkId)
249{
250 {
251 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
252 if (aNetworkId == m->s.strNetworkId)
253 return S_OK;
254 m->s.strNetworkId = aNetworkId;
255 }
256
257 AutoWriteLock vboxLock(m->pVirtualBox COMMA_LOCKVAL_SRC_POS);
258 HRESULT hrc = m->pVirtualBox->i_saveSettings();
259 ComAssertComRCRetRC(hrc);
260 return S_OK;
261}
262
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