1 | /* $Id: CloudProviderManagerImpl.cpp 73716 2018-08-16 15:58:57Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * ICloudProviderManager COM class implementations.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2008-2018 Oracle Corporation
|
---|
8 | *
|
---|
9 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
10 | * available from http://www.215389.xyz. 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 | #include <VBox/com/array.h>
|
---|
20 |
|
---|
21 | #include "VirtualBoxImpl.h"
|
---|
22 | #include "CloudProviderManagerImpl.h"
|
---|
23 | #ifdef VBOX_WITH_CLOUD_PROVIDERS_IN_EXTPACK
|
---|
24 | # include "ExtPackManagerImpl.h"
|
---|
25 | #else
|
---|
26 | # include "OCIProvider.h"
|
---|
27 | #endif
|
---|
28 | #include "AutoCaller.h"
|
---|
29 | #include "Logging.h"
|
---|
30 |
|
---|
31 | using namespace std;
|
---|
32 |
|
---|
33 | ////////////////////////////////////////////////////////////////////////////////
|
---|
34 | //
|
---|
35 | // CloudProviderManager constructor / destructor
|
---|
36 | //
|
---|
37 | // ////////////////////////////////////////////////////////////////////////////////
|
---|
38 | CloudProviderManager::CloudProviderManager()
|
---|
39 | {
|
---|
40 | }
|
---|
41 |
|
---|
42 | CloudProviderManager::~CloudProviderManager()
|
---|
43 | {
|
---|
44 | }
|
---|
45 |
|
---|
46 |
|
---|
47 | HRESULT CloudProviderManager::FinalConstruct()
|
---|
48 | {
|
---|
49 | return BaseFinalConstruct();
|
---|
50 | }
|
---|
51 |
|
---|
52 | void CloudProviderManager::FinalRelease()
|
---|
53 | {
|
---|
54 | uninit();
|
---|
55 |
|
---|
56 | BaseFinalRelease();
|
---|
57 | }
|
---|
58 |
|
---|
59 | HRESULT CloudProviderManager::init(VirtualBox *aParent)
|
---|
60 | {
|
---|
61 | // Enclose the state transition NotReady->InInit->Ready.
|
---|
62 | AutoInitSpan autoInitSpan(this);
|
---|
63 | AssertReturn(autoInitSpan.isOk(), E_FAIL);
|
---|
64 |
|
---|
65 | m_apCloudProviders.clear();
|
---|
66 |
|
---|
67 | #ifdef VBOX_WITH_CLOUD_PROVIDERS_IN_EXTPACK
|
---|
68 | // Engage the extension pack manager and get all the implementations of
|
---|
69 | // this class and all implemented cloud providers.
|
---|
70 | ExtPackManager *pExtPackMgr = aParent->i_getExtPackManager();
|
---|
71 | mpExtPackMgr = pExtPackMgr;
|
---|
72 | if (pExtPackMgr)
|
---|
73 | {
|
---|
74 | mcExtPackMgrUpdate = pExtPackMgr->i_getUpdateCounter();
|
---|
75 | // Make sure that the current value doesn't match, forcing a refresh.
|
---|
76 | mcExtPackMgrUpdate--;
|
---|
77 | iRefreshProviders();
|
---|
78 | }
|
---|
79 | #else
|
---|
80 | ComObjPtr<OCIProvider> pOCIProvider;
|
---|
81 | HRESULT hrc = pOCIProvider.createObject();
|
---|
82 | if (FAILED(hrc))
|
---|
83 | return hrc;
|
---|
84 | hrc = pOCIProvider->init(aParent);
|
---|
85 | if (FAILED(hrc))
|
---|
86 | return hrc;
|
---|
87 | m_apCloudProviders.push_back(pOCIProvider);
|
---|
88 | #endif
|
---|
89 |
|
---|
90 | autoInitSpan.setSucceeded();
|
---|
91 | return S_OK;
|
---|
92 | }
|
---|
93 |
|
---|
94 | void CloudProviderManager::uninit()
|
---|
95 | {
|
---|
96 | // Enclose the state transition Ready->InUninit->NotReady.
|
---|
97 | AutoUninitSpan autoUninitSpan(this);
|
---|
98 | if (autoUninitSpan.uninitDone())
|
---|
99 | return;
|
---|
100 | }
|
---|
101 |
|
---|
102 | #ifdef VBOX_WITH_CLOUD_PROVIDERS_IN_EXTPACK
|
---|
103 | void CloudProviderManager::i_refreshProviders()
|
---|
104 | {
|
---|
105 | {
|
---|
106 | AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
107 | uint64_t cExtPackMgrUpdate = mpExtPackMgr->i_getUpdateCounter();
|
---|
108 | if (cExtPackMgrUpdate == mcExtPackMgrUpdate)
|
---|
109 | return;
|
---|
110 | }
|
---|
111 |
|
---|
112 | AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
113 | // Reread the current value to figure out if some other thead did the work
|
---|
114 | // already before this thread got hold of the write lock.
|
---|
115 | cExtPackMgrUpdate = pExtPackMgr->i_getUpdateCounter();
|
---|
116 | if (cExtPackMgrUpdate == mcExtPackMgrUpdate)
|
---|
117 | return;
|
---|
118 | mcExtPackMgrUpdate = cExtPackMgrUpdate;
|
---|
119 |
|
---|
120 | if (!m_mapCloudProviderManagers.empty())
|
---|
121 | {
|
---|
122 | /// @todo The code below will need to be extended to handle extpack
|
---|
123 | // install and uninstall safely (and the latter needs non-trivial
|
---|
124 | // checks if any extpack related cloud activity is pending.
|
---|
125 | return;
|
---|
126 | }
|
---|
127 |
|
---|
128 | std::vector<ComPtr<IUnknown> > apObjects;
|
---|
129 | std::vector<com::Utf8Str> astrExtPackNames;
|
---|
130 | com::Guid idObj(COM_IIDOF(ICloudProviderManager));
|
---|
131 | pExtPackMgr->i_queryObjects(idObj.toString(), apObjects, &astrExtPackNames);
|
---|
132 | for (unsigned i = 0; i < apObjects.size(); i++)
|
---|
133 | {
|
---|
134 | ComPtr<ICloudProviderManager> pTmp;
|
---|
135 | HRESULT hrc = apObjects[i].queryInterfaceTo(pTmp.asOutParam());
|
---|
136 | if (SUCCEEDED(hrc))
|
---|
137 | m_mapCloudProviderManagers[astrExtPackNames[i]] = pTmp;
|
---|
138 | SafeIfaceArray<ICloudProvider> apProvidersFromCurrExtPack;
|
---|
139 | hrc = pTmp->COMGETTER(Providers)(ComSafeArrayAsOutParam(apProvidersFromCurrExtPack));
|
---|
140 | if (SUCCEEDED(hrc))
|
---|
141 | {
|
---|
142 | for (unsigned j = 0; j < apProvidersFromCurrExtPack.size(); j++)
|
---|
143 | m_apCloudProviders.push_back(apProvidersFromCurrExtPack[i]);
|
---|
144 | }
|
---|
145 | }
|
---|
146 | }
|
---|
147 | #endif
|
---|
148 |
|
---|
149 | HRESULT CloudProviderManager::getProviders(std::vector<ComPtr<ICloudProvider> > &aProviders)
|
---|
150 | {
|
---|
151 | AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
152 | aProviders = m_apCloudProviders;
|
---|
153 | return S_OK;
|
---|
154 | }
|
---|
155 |
|
---|
156 | HRESULT CloudProviderManager::getProviderById(const com::Guid &aProviderId,
|
---|
157 | ComPtr<ICloudProvider> &aProvider)
|
---|
158 | {
|
---|
159 | AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
160 | for (size_t i = 0; i < m_apCloudProviders.size(); i++)
|
---|
161 | {
|
---|
162 | Bstr bstrId;
|
---|
163 | HRESULT hrc = m_apCloudProviders[i]->COMGETTER(Id)(bstrId.asOutParam());
|
---|
164 | if (SUCCEEDED(hrc) && aProviderId == bstrId)
|
---|
165 | {
|
---|
166 | aProvider = m_apCloudProviders[i];
|
---|
167 | return S_OK;
|
---|
168 | }
|
---|
169 | }
|
---|
170 | return setError(VBOX_E_OBJECT_NOT_FOUND, tr("Could not find a cloud provider with UUID {%RTuuid}"),
|
---|
171 | aProviderId.raw());
|
---|
172 | }
|
---|
173 |
|
---|
174 | HRESULT CloudProviderManager::getProviderByShortName(const com::Utf8Str &aProviderName,
|
---|
175 | ComPtr<ICloudProvider> &aProvider)
|
---|
176 | {
|
---|
177 | AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
178 | for (size_t i = 0; i < m_apCloudProviders.size(); i++)
|
---|
179 | {
|
---|
180 | Bstr bstrName;
|
---|
181 | HRESULT hrc = m_apCloudProviders[i]->COMGETTER(ShortName)(bstrName.asOutParam());
|
---|
182 | if (SUCCEEDED(hrc) && bstrName.equals(aProviderName))
|
---|
183 | {
|
---|
184 | aProvider = m_apCloudProviders[i];
|
---|
185 | return S_OK;
|
---|
186 | }
|
---|
187 | }
|
---|
188 | return setError(VBOX_E_OBJECT_NOT_FOUND, tr("Could not find a cloud provider with short name '%s'"),
|
---|
189 | aProviderName.c_str());
|
---|
190 | }
|
---|
191 |
|
---|
192 | HRESULT CloudProviderManager::getProviderByName(const com::Utf8Str &aProviderName,
|
---|
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 bstrName;
|
---|
199 | HRESULT hrc = m_apCloudProviders[i]->COMGETTER(Name)(bstrName.asOutParam());
|
---|
200 | if (SUCCEEDED(hrc) && bstrName.equals(aProviderName))
|
---|
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 name '%s'"),
|
---|
207 | aProviderName.c_str());
|
---|
208 | }
|
---|
209 |
|
---|