VirtualBox

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

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

ExtPack cloud stuf. bugref:9152

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 7.3 KB
Line 
1/* $Id: CloudUserProfileManagerImpl.cpp 73553 2018-08-07 18:17:43Z vboxsync $ */
2/** @file
3 * ICloudUserProfileManager 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// CloudUserProfileManager constructor / destructor
39//
40// ////////////////////////////////////////////////////////////////////////////////
41CloudUserProfileManager::CloudUserProfileManager()
42 : mParent(NULL)
43{
44}
45
46CloudUserProfileManager::~CloudUserProfileManager()
47{
48}
49
50
51HRESULT CloudUserProfileManager::FinalConstruct()
52{
53 return BaseFinalConstruct();
54}
55
56void CloudUserProfileManager::FinalRelease()
57{
58 uninit();
59
60 BaseFinalRelease();
61}
62
63HRESULT CloudUserProfileManager::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(ICloudUserProfileManager));
78 pExtPackMgr->i_queryObjects(idObj.toString(), Objects);
79 for (unsigned i = 0; i < Objects.size(); i++)
80 {
81 ComPtr<ICloudUserProfileManager> 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(CloudProviderId_OCI);
90#endif
91
92 autoInitSpan.setSucceeded();
93 return S_OK;
94}
95
96void CloudUserProfileManager::uninit()
97{
98 /* Enclose the state transition Ready->InUninit->NotReady */
99 AutoUninitSpan autoUninitSpan(this);
100 if (autoUninitSpan.uninitDone())
101 return;
102
103 unconst(mParent) = NULL;
104}
105
106HRESULT CloudUserProfileManager::getSupportedProviders(std::vector<CloudProviderId_T> &aSupportedProviders)
107{
108#ifdef VBOX_WITH_CLOUD_PROVIDERS_IN_EXTPACK
109 /*
110 * Collect all the provider names from all the extension pack objects.
111 */
112 HRESULT hrc = S_OK;
113 for (unsigned i = 0; i < mUserProfileManagers.size(); i++)
114 {
115 SafeArray<CloudProviderId_T> FromCurrent;
116 HRESULT hrc2 = mUserProfileManagers[i]->COMGETTER(SupportedProviders)(ComSafeArrayAsOutParam(FromCurrent));
117 if (SUCCEEDED(hrc2))
118 for (size_t i = 0; i < FromCurrent.size(); i++)
119 aSupportedProviders.push_back(FromCurrent[i]);
120 else if (SUCCEEDED(hrc))
121 hrc = hrc2;
122 }
123 if (aSupportedProviders.size() > 0)
124 hrc = S_OK;
125 return hrc;
126#else
127 aSupportedProviders = mSupportedProviders;
128 return S_OK;
129#endif
130}
131
132HRESULT CloudUserProfileManager::getAllProfiles(std::vector<ComPtr<ICloudUserProfiles> > &aProfilesList)
133{
134#ifdef VBOX_WITH_CLOUD_PROVIDERS_IN_EXTPACK
135 /*
136 * Collect all the cloud providers from all the extension pack objects.
137 */
138 HRESULT hrc = S_OK;
139 for (unsigned i = 0; i < mUserProfileManagers.size(); i++)
140 {
141 SafeIfaceArray<ICloudUserProfiles> FromCurrent;
142 HRESULT hrc2 = mUserProfileManagers[i]->GetAllProfiles(ComSafeArrayAsOutParam(FromCurrent));
143 if (SUCCEEDED(hrc2))
144 for (size_t i = 0; i < FromCurrent.size(); i++)
145 aProfilesList.push_back(FromCurrent[i]);
146 else if (SUCCEEDED(hrc))
147 hrc = hrc2;
148 }
149 if (aProfilesList.size() > 0)
150 hrc = S_OK;
151 return hrc;
152
153#else
154 HRESULT hrc = S_OK;
155 std::vector<ComPtr<ICloudUserProfiles> > lProfilesList;
156 for (size_t i=0;i<mSupportedProviders.size();++i)
157 {
158 ComPtr<ICloudUserProfiles> lProfiles;
159 hrc = getProfilesByProvider(mSupportedProviders.at(i), lProfiles);
160 if (FAILED(hrc))
161 break;
162
163 lProfilesList.push_back(lProfiles);
164 }
165
166 if (SUCCEEDED(hrc))
167 aProfilesList = lProfilesList;
168
169 return hrc;
170#endif
171}
172
173HRESULT CloudUserProfileManager::getProfilesByProvider(CloudProviderId_T aProviderType,
174 ComPtr<ICloudUserProfiles> &aProfiles)
175{
176#ifdef VBOX_WITH_CLOUD_PROVIDERS_IN_EXTPACK
177 /*
178 * Return the first provider we get.
179 */
180 HRESULT hrc = VBOX_E_OBJECT_NOT_FOUND;
181 for (unsigned i = 0; i < mUserProfileManagers.size(); i++)
182 {
183 hrc = mUserProfileManagers[i]->GetProfilesByProvider(aProviderType, aProfiles.asOutParam());
184 if (SUCCEEDED(hrc))
185 break;
186 }
187 return hrc;
188
189#else
190
191 ComObjPtr<CloudUserProfiles> ptrCloudUserProfiles;
192 HRESULT hrc = ptrCloudUserProfiles.createObject();
193 switch(aProviderType)
194 {
195 case CloudProviderId_OCI:
196 default:
197 ComObjPtr<OCIUserProfiles> ptrOCIUserProfiles;
198 hrc = ptrOCIUserProfiles.createObject();
199 if (SUCCEEDED(hrc))
200 {
201 AutoReadLock wlock(this COMMA_LOCKVAL_SRC_POS);
202
203 hrc = ptrOCIUserProfiles->init(mParent);
204 if (SUCCEEDED(hrc))
205 {
206 char szOciConfigPath[RTPATH_MAX];
207 int vrc = RTPathUserHome(szOciConfigPath, sizeof(szOciConfigPath));
208 if (RT_SUCCESS(vrc))
209 vrc = RTPathAppend(szOciConfigPath, sizeof(szOciConfigPath), ".oci" RTPATH_SLASH_STR "config");
210 if (RT_SUCCESS(vrc))
211 {
212 LogRel(("config = %s\n", szOciConfigPath));
213 if (RTFileExists(szOciConfigPath))
214 {
215 hrc = ptrOCIUserProfiles->readProfiles(szOciConfigPath);
216 if (SUCCEEDED(hrc))
217 LogRel(("Reading profiles from %s has been done\n", szOciConfigPath));
218 else
219 LogRel(("Reading profiles from %s hasn't been done\n", szOciConfigPath));
220
221 ptrCloudUserProfiles = ptrOCIUserProfiles;
222 hrc = ptrCloudUserProfiles.queryInterfaceTo(aProfiles.asOutParam());
223 }
224 else
225 hrc = setErrorBoth(E_FAIL, VERR_FILE_NOT_FOUND, tr("Could not locate the config file '%s'"),
226 szOciConfigPath);
227 }
228 else
229 hrc = setErrorVrc(vrc);
230 }
231 }
232 break;
233 }
234
235 return hrc;
236#endif
237}
238
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