VirtualBox

source: vbox/trunk/src/VBox/Main/src-server/CloudUserProfileManagerImpl.cpp@ 73590

Last change on this file since 73590 was 73571, checked in by vboxsync, 7 years ago

bugref:9152. Renamed ICloudUserProfiles to ICloudProvider, ICloudUserProfileManager to ICloudProviderManager. Commented out some code in the frontend. Sergey will rewrite it according to actual realization.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 7.0 KB
Line 
1/* $Id: CloudUserProfileManagerImpl.cpp 73571 2018-08-08 16:10:30Z 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 <iprt/path.h>
20#include <iprt/cpp/utils.h>
21#include <VBox/com/array.h>
22#include <map>
23
24#include "CloudUserProfileManagerImpl.h"
25#include "CloudUserProfilesImpl.h"
26#include "VirtualBoxImpl.h"
27#include "ExtPackManagerImpl.h"
28#include "Global.h"
29#include "ProgressImpl.h"
30#include "MachineImpl.h"
31#include "AutoCaller.h"
32#include "Logging.h"
33
34using namespace std;
35
36////////////////////////////////////////////////////////////////////////////////
37//
38// CloudProviderManager constructor / destructor
39//
40// ////////////////////////////////////////////////////////////////////////////////
41CloudProviderManager::CloudProviderManager()
42 : mParent(NULL)
43{
44}
45
46CloudProviderManager::~CloudProviderManager()
47{
48}
49
50
51HRESULT CloudProviderManager::FinalConstruct()
52{
53 return BaseFinalConstruct();
54}
55
56void CloudProviderManager::FinalRelease()
57{
58 uninit();
59
60 BaseFinalRelease();
61}
62
63HRESULT CloudProviderManager::init(VirtualBox *aParent)
64{
65 /* Enclose the state transition NotReady->InInit->Ready */
66 AutoInitSpan autoInitSpan(this);
67 AssertReturn(autoInitSpan.isOk(), E_FAIL);
68
69 unconst(mParent) = aParent;
70
71#ifdef VBOX_WITH_CLOUD_PROVIDERS_IN_EXTPACK
72 /*
73 * Engage the extension pack manager and get all the implementations of this class.
74 */
75 ExtPackManager *pExtPackMgr = aParent->i_getExtPackManager();
76 std::vector<ComPtr<IUnknown> > Objects;
77 com::Guid idObj(COM_IIDOF(ICloudProviderManager));
78 pExtPackMgr->i_queryObjects(idObj.toString(), Objects);
79 for (unsigned i = 0; i < Objects.size(); i++)
80 {
81 ComPtr<ICloudProviderManager> ptrTmp;
82 HRESULT hrc = Objects[i].queryInterfaceTo(ptrTmp.asOutParam());
83 if (SUCCEEDED(hrc))
84 mUserProfileManagers.push_back(ptrTmp);
85 }
86#else
87
88 mSupportedProviders.clear();
89 mSupportedProviders.push_back("OCI");
90
91#endif
92
93 autoInitSpan.setSucceeded();
94 return S_OK;
95}
96
97void CloudProviderManager::uninit()
98{
99 /* Enclose the state transition Ready->InUninit->NotReady */
100 AutoUninitSpan autoUninitSpan(this);
101 if (autoUninitSpan.uninitDone())
102 return;
103
104 unconst(mParent) = NULL;
105}
106
107HRESULT CloudProviderManager::getSupportedProviders(std::vector<Utf8Str> &aSupportedProviders)
108{
109#ifdef VBOX_WITH_CLOUD_PROVIDERS_IN_EXTPACK
110 /*
111 * Collect all the provider names from all the extension pack objects.
112 */
113 HRESULT hrc = S_OK;
114 for (unsigned i = 0; i < mUserProfileManagers.size(); i++)
115 {
116 SafeArray<Utf8Str> FromCurrent;
117 HRESULT hrc2 = mUserProfileManagers[i]->COMGETTER(SupportedProviders)(ComSafeArrayAsOutParam(FromCurrent));
118 if (SUCCEEDED(hrc2))
119 for (size_t j = 0; j < FromCurrent.size(); j++)
120 aSupportedProviders.push_back(FromCurrent[j]);
121 else if (SUCCEEDED(hrc))
122 hrc = hrc2;
123 }
124 if (aSupportedProviders.size() > 0)
125 hrc = S_OK;
126 return hrc;
127#else
128 aSupportedProviders = mSupportedProviders;
129 return S_OK;
130#endif
131}
132
133HRESULT CloudProviderManager::getAllProfiles(std::vector<ComPtr<ICloudProvider> > &aProfilesList)
134{
135#ifdef VBOX_WITH_CLOUD_PROVIDERS_IN_EXTPACK
136 /*
137 * Collect all the cloud providers from all the extension pack objects.
138 */
139 HRESULT hrc = S_OK;
140 for (unsigned i = 0; i < mUserProfileManagers.size(); i++)
141 {
142 SafeIfaceArray<ICloudProvider> FromCurrent;
143 HRESULT hrc2 = mUserProfileManagers[i]->GetAllProfiles(ComSafeArrayAsOutParam(FromCurrent));
144 if (SUCCEEDED(hrc2))
145 for (size_t j = 0; j < FromCurrent.size(); j++)
146 aProfilesList.push_back(FromCurrent[j]);
147 else if (SUCCEEDED(hrc))
148 hrc = hrc2;
149 }
150 if (aProfilesList.size() > 0)
151 hrc = S_OK;
152 return hrc;
153
154#else
155 HRESULT hrc = S_OK;
156 std::vector<ComPtr<ICloudProvider> > lProfilesList;
157 for (size_t i=0;i<mSupportedProviders.size();++i)
158 {
159 ComPtr<ICloudProvider> lProfiles;
160 hrc = getProfilesByProvider(mSupportedProviders.at(i), lProfiles);
161 if (FAILED(hrc))
162 break;
163
164 lProfilesList.push_back(lProfiles);
165 }
166
167 if (SUCCEEDED(hrc))
168 aProfilesList = lProfilesList;
169
170 return hrc;
171#endif
172}
173
174HRESULT CloudProviderManager::getProfilesByProvider(const com::Utf8Str &aProviderName,
175 ComPtr<ICloudProvider> &aProfiles)
176{
177#ifdef VBOX_WITH_CLOUD_PROVIDERS_IN_EXTPACK
178 /*
179 * Return the first provider we get.
180 */
181 HRESULT hrc = VBOX_E_OBJECT_NOT_FOUND;
182 for (unsigned i = 0; i < mUserProfileManagers.size(); i++)
183 {
184 hrc = mUserProfileManagers[i]->GetProfilesByProvider(aProviderType, aProfiles.asOutParam());
185 if (SUCCEEDED(hrc))
186 break;
187 }
188 return hrc;
189
190#else
191
192 ComObjPtr<CloudProvider> ptrCloudProvider;
193 HRESULT hrc = ptrCloudProvider.createObject();
194 if (aProviderName.equals("OCI"))
195 {
196 ComObjPtr<OCIUserProfiles> ptrOCIUserProfiles;
197 hrc = ptrOCIUserProfiles.createObject();
198 if (SUCCEEDED(hrc))
199 {
200 AutoReadLock wlock(this COMMA_LOCKVAL_SRC_POS);
201
202 hrc = ptrOCIUserProfiles->init(mParent);
203 if (SUCCEEDED(hrc))
204 {
205 char szOciConfigPath[RTPATH_MAX];
206 int vrc = RTPathUserHome(szOciConfigPath, sizeof(szOciConfigPath));
207 if (RT_SUCCESS(vrc))
208 vrc = RTPathAppend(szOciConfigPath, sizeof(szOciConfigPath), ".oci" RTPATH_SLASH_STR "config");
209 if (RT_SUCCESS(vrc))
210 {
211 LogRel(("config = %s\n", szOciConfigPath));
212 if (RTFileExists(szOciConfigPath))
213 {
214 hrc = ptrOCIUserProfiles->readProfiles(szOciConfigPath);
215 if (SUCCEEDED(hrc))
216 LogRel(("Reading profiles from %s has been done\n", szOciConfigPath));
217 else
218 LogRel(("Reading profiles from %s hasn't been done\n", szOciConfigPath));
219
220 ptrCloudProvider = ptrOCIUserProfiles;
221 hrc = ptrCloudProvider.queryInterfaceTo(aProfiles.asOutParam());
222 }
223 else
224 hrc = setErrorBoth(E_FAIL, VERR_FILE_NOT_FOUND, tr("Could not locate the config file '%s'"),
225 szOciConfigPath);
226 }
227 else
228 hrc = setErrorVrc(vrc);
229 }
230 }
231 }
232
233 return hrc;
234#endif
235}
236
Note: See TracBrowser for help on using the repository browser.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette