1 | /* $Id: CloudNetworkImpl.cpp 98103 2023-01-17 14:15:46Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * ICloudNetwork COM class implementations.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2019-2023 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 |
|
---|
39 | struct 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 | // ////////////////////////////////////////////////////////////////////////////////
|
---|
56 | CloudNetwork::CloudNetwork() : m(NULL)
|
---|
57 | {
|
---|
58 | }
|
---|
59 |
|
---|
60 | CloudNetwork::~CloudNetwork()
|
---|
61 | {
|
---|
62 | }
|
---|
63 |
|
---|
64 |
|
---|
65 | HRESULT CloudNetwork::FinalConstruct()
|
---|
66 | {
|
---|
67 | return BaseFinalConstruct();
|
---|
68 | }
|
---|
69 |
|
---|
70 | void CloudNetwork::FinalRelease()
|
---|
71 | {
|
---|
72 | uninit();
|
---|
73 |
|
---|
74 | BaseFinalRelease();
|
---|
75 | }
|
---|
76 |
|
---|
77 | HRESULT 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 |
|
---|
96 | void CloudNetwork::uninit()
|
---|
97 | {
|
---|
98 | // Enclose the state transition Ready->InUninit->NotReady.
|
---|
99 | AutoUninitSpan autoUninitSpan(this);
|
---|
100 | if (autoUninitSpan.uninitDone())
|
---|
101 | return;
|
---|
102 | }
|
---|
103 |
|
---|
104 | HRESULT CloudNetwork::i_loadSettings(const settings::CloudNetwork &data)
|
---|
105 | {
|
---|
106 | AutoCaller autoCaller(this);
|
---|
107 | AssertComRCReturnRC(autoCaller.rc());
|
---|
108 |
|
---|
109 | AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
110 | m->s = data;
|
---|
111 |
|
---|
112 | return S_OK;
|
---|
113 | }
|
---|
114 |
|
---|
115 | HRESULT CloudNetwork::i_saveSettings(settings::CloudNetwork &data)
|
---|
116 | {
|
---|
117 | AutoCaller autoCaller(this);
|
---|
118 | if (FAILED(autoCaller.rc())) return autoCaller.rc();
|
---|
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 |
|
---|
127 | Utf8Str CloudNetwork::i_getProvider()
|
---|
128 | {
|
---|
129 | return m->s.strProviderShortName;
|
---|
130 | }
|
---|
131 |
|
---|
132 | Utf8Str CloudNetwork::i_getProfile()
|
---|
133 | {
|
---|
134 | return m->s.strProfileName;
|
---|
135 | }
|
---|
136 |
|
---|
137 | Utf8Str CloudNetwork::i_getNetworkId()
|
---|
138 | {
|
---|
139 | return m->s.strNetworkId;
|
---|
140 | }
|
---|
141 |
|
---|
142 | Utf8Str CloudNetwork::i_getNetworkName()
|
---|
143 | {
|
---|
144 | return m->s.strNetworkName;
|
---|
145 | }
|
---|
146 |
|
---|
147 |
|
---|
148 | HRESULT 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 |
|
---|
156 | HRESULT 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 rc = m->pVirtualBox->i_saveSettings();
|
---|
171 | ComAssertComRCRetRC(rc);
|
---|
172 | return S_OK;
|
---|
173 | }
|
---|
174 |
|
---|
175 | HRESULT CloudNetwork::getEnabled(BOOL *aEnabled)
|
---|
176 | {
|
---|
177 | AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
178 | *aEnabled = m->s.fEnabled;
|
---|
179 | return S_OK;
|
---|
180 | }
|
---|
181 |
|
---|
182 | HRESULT 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 rc = m->pVirtualBox->i_saveSettings();
|
---|
193 | ComAssertComRCRetRC(rc);
|
---|
194 | return S_OK;
|
---|
195 | }
|
---|
196 |
|
---|
197 | HRESULT 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 |
|
---|
204 | HRESULT 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 rc = m->pVirtualBox->i_saveSettings();
|
---|
215 | ComAssertComRCRetRC(rc);
|
---|
216 | return S_OK;
|
---|
217 | }
|
---|
218 |
|
---|
219 | HRESULT 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 |
|
---|
226 | HRESULT 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 rc = m->pVirtualBox->i_saveSettings();
|
---|
237 | ComAssertComRCRetRC(rc);
|
---|
238 | return S_OK;
|
---|
239 | }
|
---|
240 |
|
---|
241 | HRESULT 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 |
|
---|
248 | HRESULT 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 rc = m->pVirtualBox->i_saveSettings();
|
---|
259 | ComAssertComRCRetRC(rc);
|
---|
260 | return S_OK;
|
---|
261 | }
|
---|
262 |
|
---|