VirtualBox

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

Last change on this file since 74081 was 73873, checked in by vboxsync, 6 years ago

OCI: Move OCI code to the extension pack

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 6.4 KB
Line 
1/* $Id: CloudProviderManagerImpl.cpp 73873 2018-08-24 13:47:20Z 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
27using namespace std;
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(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_CLOUD_PROVIDERS_IN_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
83void 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_CLOUD_PROVIDERS_IN_EXTPACK
92void CloudProviderManager::i_refreshProviders()
93{
94 uint64_t cExtPackMgrUpdate;
95 {
96 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
97 cExtPackMgrUpdate = mpExtPackMgr->i_getUpdateCounter();
98 if (cExtPackMgrUpdate == mcExtPackMgrUpdate)
99 return;
100 }
101
102 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
103 // Reread the current value to figure out if some other thead did the work
104 // already before this thread got hold of the write lock.
105 cExtPackMgrUpdate = mpExtPackMgr->i_getUpdateCounter();
106 if (cExtPackMgrUpdate == mcExtPackMgrUpdate)
107 return;
108 mcExtPackMgrUpdate = cExtPackMgrUpdate;
109
110 if (!m_mapCloudProviderManagers.empty())
111 {
112 /// @todo The code below will need to be extended to handle extpack
113 // install and uninstall safely (and the latter needs non-trivial
114 // checks if any extpack related cloud activity is pending.
115 return;
116 }
117
118 std::vector<ComPtr<IUnknown> > apObjects;
119 std::vector<com::Utf8Str> astrExtPackNames;
120 com::Guid idObj(COM_IIDOF(ICloudProviderManager));
121 mpExtPackMgr->i_queryObjects(idObj.toString(), apObjects, &astrExtPackNames);
122 for (unsigned i = 0; i < apObjects.size(); i++)
123 {
124 ComPtr<ICloudProviderManager> pTmp;
125 HRESULT hrc = apObjects[i].queryInterfaceTo(pTmp.asOutParam());
126 if (SUCCEEDED(hrc))
127 m_mapCloudProviderManagers[astrExtPackNames[i]] = pTmp;
128 SafeIfaceArray<ICloudProvider> apProvidersFromCurrExtPack;
129 hrc = pTmp->COMGETTER(Providers)(ComSafeArrayAsOutParam(apProvidersFromCurrExtPack));
130 if (SUCCEEDED(hrc))
131 {
132 for (unsigned j = 0; j < apProvidersFromCurrExtPack.size(); j++)
133 m_apCloudProviders.push_back(apProvidersFromCurrExtPack[i]);
134 }
135 }
136}
137#endif
138
139HRESULT CloudProviderManager::getProviders(std::vector<ComPtr<ICloudProvider> > &aProviders)
140{
141 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
142 aProviders = m_apCloudProviders;
143 return S_OK;
144}
145
146HRESULT CloudProviderManager::getProviderById(const com::Guid &aProviderId,
147 ComPtr<ICloudProvider> &aProvider)
148{
149 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
150 for (size_t i = 0; i < m_apCloudProviders.size(); i++)
151 {
152 Bstr bstrId;
153 HRESULT hrc = m_apCloudProviders[i]->COMGETTER(Id)(bstrId.asOutParam());
154 if (SUCCEEDED(hrc) && aProviderId == bstrId)
155 {
156 aProvider = m_apCloudProviders[i];
157 return S_OK;
158 }
159 }
160 return setError(VBOX_E_OBJECT_NOT_FOUND, tr("Could not find a cloud provider with UUID {%RTuuid}"),
161 aProviderId.raw());
162}
163
164HRESULT CloudProviderManager::getProviderByShortName(const com::Utf8Str &aProviderName,
165 ComPtr<ICloudProvider> &aProvider)
166{
167 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
168 for (size_t i = 0; i < m_apCloudProviders.size(); i++)
169 {
170 Bstr bstrName;
171 HRESULT hrc = m_apCloudProviders[i]->COMGETTER(ShortName)(bstrName.asOutParam());
172 if (SUCCEEDED(hrc) && bstrName.equals(aProviderName))
173 {
174 aProvider = m_apCloudProviders[i];
175 return S_OK;
176 }
177 }
178 return setError(VBOX_E_OBJECT_NOT_FOUND, tr("Could not find a cloud provider with short name '%s'"),
179 aProviderName.c_str());
180}
181
182HRESULT CloudProviderManager::getProviderByName(const com::Utf8Str &aProviderName,
183 ComPtr<ICloudProvider> &aProvider)
184{
185 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
186 for (size_t i = 0; i < m_apCloudProviders.size(); i++)
187 {
188 Bstr bstrName;
189 HRESULT hrc = m_apCloudProviders[i]->COMGETTER(Name)(bstrName.asOutParam());
190 if (SUCCEEDED(hrc) && bstrName.equals(aProviderName))
191 {
192 aProvider = m_apCloudProviders[i];
193 return S_OK;
194 }
195 }
196 return setError(VBOX_E_OBJECT_NOT_FOUND, tr("Could not find a cloud provider with name '%s'"),
197 aProviderName.c_str());
198}
199
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