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