VirtualBox

source: vbox/trunk/src/VBox/Main/src-server/CloudProviderManagerImpl.cpp@ 78376

Last change on this file since 78376 was 76592, checked in by vboxsync, 6 years ago

Main: Don't use Logging.h.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 7.8 KB
Line 
1/* $Id: CloudProviderManagerImpl.cpp 76592 2019-01-01 20:13:07Z vboxsync $ */
2/** @file
3 * ICloudProviderManager COM class implementations.
4 */
5
6/*
7 * Copyright (C) 2008-2019 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_CLOUDPROVIDERMANAGER
20#include <VBox/com/array.h>
21
22#include "VirtualBoxImpl.h"
23#include "CloudProviderManagerImpl.h"
24#include "ExtPackManagerImpl.h"
25#include "AutoCaller.h"
26#include "LoggingNew.h"
27
28
29////////////////////////////////////////////////////////////////////////////////
30//
31// CloudProviderManager constructor / destructor
32//
33// ////////////////////////////////////////////////////////////////////////////////
34CloudProviderManager::CloudProviderManager()
35{
36}
37
38CloudProviderManager::~CloudProviderManager()
39{
40}
41
42
43HRESULT CloudProviderManager::FinalConstruct()
44{
45 return BaseFinalConstruct();
46}
47
48void CloudProviderManager::FinalRelease()
49{
50 uninit();
51
52 BaseFinalRelease();
53}
54
55HRESULT CloudProviderManager::init()
56{
57 // Enclose the state transition NotReady->InInit->Ready.
58 AutoInitSpan autoInitSpan(this);
59 AssertReturn(autoInitSpan.isOk(), E_FAIL);
60
61 m_apCloudProviders.clear();
62
63 autoInitSpan.setSucceeded();
64 return S_OK;
65}
66
67void CloudProviderManager::uninit()
68{
69 // Enclose the state transition Ready->InUninit->NotReady.
70 AutoUninitSpan autoUninitSpan(this);
71 if (autoUninitSpan.uninitDone())
72 return;
73}
74
75#ifdef VBOX_WITH_EXTPACK
76bool CloudProviderManager::i_canRemoveExtPack(IExtPack *aExtPack)
77{
78 AssertReturn(aExtPack, false);
79
80 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
81
82 // If any cloud provider in this extension pack fails to prepare the
83 // uninstall it and the cloud provider will be kept, so that the user
84 // can retry safely later. All other cloud providers in this extpack
85 // will be done as usual. No attempt is made to bring back the other
86 // cloud providers into working shape.
87
88 bool fRes = true;
89 Bstr bstrName;
90 aExtPack->COMGETTER(Name)(bstrName.asOutParam());
91 Utf8Str strName(bstrName);
92 ExtPackNameCloudProviderManagerMap::iterator it = m_mapCloudProviderManagers.find(strName);
93 if (it != m_mapCloudProviderManagers.end())
94 {
95 ComPtr<ICloudProviderManager> pTmp(it->second);
96
97 Assert(m_astrExtPackNames.size() == m_apCloudProviders.size());
98 for (size_t i = 0; i < m_astrExtPackNames.size(); )
99 {
100 if (m_astrExtPackNames[i] != strName)
101 {
102 i++;
103 continue;
104 }
105
106 // pTmpProvider will point to an object with refcount > 0 until
107 // the ComPtr is removed from m_apCloudProviders.
108 HRESULT hrc = S_OK;
109 ULONG uRefCnt = 1;
110 ICloudProvider *pTmpProvider(m_apCloudProviders[i]);
111 if (pTmpProvider)
112 {
113 hrc = pTmpProvider->PrepareUninstall();
114 // Sanity check the refcount, it should be 1 at this point.
115 pTmpProvider->AddRef();
116 uRefCnt = pTmpProvider->Release();
117 Assert(uRefCnt == 1);
118 }
119 if (SUCCEEDED(hrc) && uRefCnt == 1)
120 {
121 m_astrExtPackNames.erase(m_astrExtPackNames.begin() + i);
122 m_apCloudProviders.erase(m_apCloudProviders.begin() + i);
123 }
124 else
125 {
126 LogRel(("CloudProviderManager: provider '%s' blocks extpack uninstall, result=%Rhrc, refcount=%u\n", strName.c_str(), hrc, uRefCnt));
127 fRes = false;
128 i++;
129 }
130 }
131
132 if (fRes)
133 m_mapCloudProviderManagers.erase(it);
134 }
135
136 return fRes;
137}
138
139void CloudProviderManager::i_addExtPack(IExtPack *aExtPack)
140{
141 AssertReturnVoid(aExtPack);
142
143 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
144
145 Bstr bstrName;
146 aExtPack->COMGETTER(Name)(bstrName.asOutParam());
147 Utf8Str strName(bstrName);
148 ComPtr<IUnknown> pObj;
149 std::vector<com::Utf8Str> astrExtPackNames;
150 com::Guid idObj(COM_IIDOF(ICloudProviderManager));
151 HRESULT hrc = aExtPack->QueryObject(Bstr(idObj.toString()).raw(), pObj.asOutParam());
152 if (FAILED(hrc))
153 return;
154
155 ComPtr<ICloudProviderManager> pTmp(pObj);
156 if (pTmp.isNull())
157 return;
158
159 SafeIfaceArray<ICloudProvider> apProvidersFromCurrExtPack;
160 hrc = pTmp->COMGETTER(Providers)(ComSafeArrayAsOutParam(apProvidersFromCurrExtPack));
161 if (FAILED(hrc))
162 return;
163
164 m_mapCloudProviderManagers[strName] = pTmp;
165 for (unsigned i = 0; i < apProvidersFromCurrExtPack.size(); i++)
166 {
167 // Sanity check each cloud provider by forcing a QueryInterface call,
168 // making sure that it implements the right interface.
169 ComPtr<ICloudProvider> pTmpCP1(apProvidersFromCurrExtPack[i]);
170 if (!pTmpCP1.isNull())
171 {
172 ComPtr<ICloudProvider> pTmpCP2;
173 pTmpCP1.queryInterfaceTo(pTmpCP2.asOutParam());
174 if (!pTmpCP2.isNull())
175 {
176 Assert(m_astrExtPackNames.size() == m_apCloudProviders.size());
177 m_astrExtPackNames.push_back(strName);
178 m_apCloudProviders.push_back(apProvidersFromCurrExtPack[i]);
179 }
180 }
181 }
182}
183#endif /* VBOX_WITH_EXTPACK */
184
185HRESULT CloudProviderManager::getProviders(std::vector<ComPtr<ICloudProvider> > &aProviders)
186{
187 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
188 aProviders = m_apCloudProviders;
189 return S_OK;
190}
191
192HRESULT CloudProviderManager::getProviderById(const com::Guid &aProviderId,
193 ComPtr<ICloudProvider> &aProvider)
194{
195 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
196 for (size_t i = 0; i < m_apCloudProviders.size(); i++)
197 {
198 Bstr bstrId;
199 HRESULT hrc = m_apCloudProviders[i]->COMGETTER(Id)(bstrId.asOutParam());
200 if (SUCCEEDED(hrc) && aProviderId == bstrId)
201 {
202 aProvider = m_apCloudProviders[i];
203 return S_OK;
204 }
205 }
206 return setError(VBOX_E_OBJECT_NOT_FOUND, tr("Could not find a cloud provider with UUID {%RTuuid}"),
207 aProviderId.raw());
208}
209
210HRESULT CloudProviderManager::getProviderByShortName(const com::Utf8Str &aProviderName,
211 ComPtr<ICloudProvider> &aProvider)
212{
213 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
214 for (size_t i = 0; i < m_apCloudProviders.size(); i++)
215 {
216 Bstr bstrName;
217 HRESULT hrc = m_apCloudProviders[i]->COMGETTER(ShortName)(bstrName.asOutParam());
218 if (SUCCEEDED(hrc) && bstrName.equals(aProviderName))
219 {
220 aProvider = m_apCloudProviders[i];
221 return S_OK;
222 }
223 }
224 return setError(VBOX_E_OBJECT_NOT_FOUND, tr("Could not find a cloud provider with short name '%s'"),
225 aProviderName.c_str());
226}
227
228HRESULT CloudProviderManager::getProviderByName(const com::Utf8Str &aProviderName,
229 ComPtr<ICloudProvider> &aProvider)
230{
231 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
232 for (size_t i = 0; i < m_apCloudProviders.size(); i++)
233 {
234 Bstr bstrName;
235 HRESULT hrc = m_apCloudProviders[i]->COMGETTER(Name)(bstrName.asOutParam());
236 if (SUCCEEDED(hrc) && bstrName.equals(aProviderName))
237 {
238 aProvider = m_apCloudProviders[i];
239 return S_OK;
240 }
241 }
242 return setError(VBOX_E_OBJECT_NOT_FOUND, tr("Could not find a cloud provider with name '%s'"),
243 aProviderName.c_str());
244}
245
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