VirtualBox

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

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