1 | /* $Id: CloudClientImpl.cpp 73164 2018-07-16 17:54:23Z vboxsync $*/
|
---|
2 | /** @file
|
---|
3 | * ICloudClient 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 "CloudClientImpl.h"
|
---|
25 | #include "CloudUserProfileManagerImpl.h"
|
---|
26 | #include "CloudUserProfileListImpl.h"
|
---|
27 | #include "VirtualBoxImpl.h"
|
---|
28 | #include "Global.h"
|
---|
29 | #include "ProgressImpl.h"
|
---|
30 | #include "MachineImpl.h"
|
---|
31 | #include "AutoCaller.h"
|
---|
32 | #include "Logging.h"
|
---|
33 |
|
---|
34 | using namespace std;
|
---|
35 |
|
---|
36 |
|
---|
37 | ////////////////////////////////////////////////////////////////////////////////
|
---|
38 | //
|
---|
39 | // CloudClient constructor / destructor
|
---|
40 | //
|
---|
41 | // ////////////////////////////////////////////////////////////////////////////////
|
---|
42 | CloudClient::CloudClient()
|
---|
43 | : mParent(NULL)
|
---|
44 | {
|
---|
45 | LogRel(("CloudClient::CloudClient()\n"));
|
---|
46 | }
|
---|
47 |
|
---|
48 | CloudClient::~CloudClient()
|
---|
49 | {
|
---|
50 | LogRel(("CloudClient::~CloudClient()\n"));
|
---|
51 | }
|
---|
52 |
|
---|
53 | CloudClient::CloudClient(CloudProviderId_T aCloudProvider)
|
---|
54 | : mParent(NULL)
|
---|
55 | {
|
---|
56 | LogRel(("CloudClient::CloudClient(CloudProviderId_T %d)\n", mCloudProvider));
|
---|
57 | mCloudProvider = aCloudProvider;
|
---|
58 | }
|
---|
59 |
|
---|
60 | HRESULT CloudClient::FinalConstruct()
|
---|
61 | {
|
---|
62 | return BaseFinalConstruct();
|
---|
63 | }
|
---|
64 |
|
---|
65 | void CloudClient::FinalRelease()
|
---|
66 | {
|
---|
67 | uninit();
|
---|
68 |
|
---|
69 | BaseFinalRelease();
|
---|
70 | }
|
---|
71 |
|
---|
72 | void CloudClient::uninit()
|
---|
73 | {
|
---|
74 | LogRel(("CloudClient::uninit()\n"));
|
---|
75 | /* Enclose the state transition Ready->InUninit->NotReady */
|
---|
76 | AutoUninitSpan autoUninitSpan(this);
|
---|
77 | if (autoUninitSpan.uninitDone())
|
---|
78 | return;
|
---|
79 |
|
---|
80 | unconst(mParent) = NULL;
|
---|
81 | mMachine.setNull();
|
---|
82 | }
|
---|
83 |
|
---|
84 | HRESULT CloudClient::init(VirtualBox *aParent)
|
---|
85 | {
|
---|
86 | LogRel(("aParent=%p\n", aParent));
|
---|
87 | ComAssertRet(aParent, E_INVALIDARG);
|
---|
88 |
|
---|
89 | /* Enclose the state transition NotReady->InInit->Ready */
|
---|
90 | AutoInitSpan autoInitSpan(this);
|
---|
91 | AssertReturn(autoInitSpan.isOk(), E_FAIL);
|
---|
92 |
|
---|
93 | unconst(mParent) = aParent;
|
---|
94 |
|
---|
95 | mCloudProvider = CloudProviderId_OCI;
|
---|
96 |
|
---|
97 | LogRel(("aParent=%p\n", aParent));
|
---|
98 |
|
---|
99 | /*
|
---|
100 | * Confirm a successful initialization
|
---|
101 | */
|
---|
102 | autoInitSpan.setSucceeded();
|
---|
103 |
|
---|
104 | return S_OK;
|
---|
105 | }
|
---|
106 |
|
---|
107 | HRESULT CloudClient::initCloudClient(CloudUserProfileList *aProfiles,
|
---|
108 | VirtualBox *aParent,
|
---|
109 | CloudProviderId_T aCloudProvider,
|
---|
110 | const com::Utf8Str &aProfileName)
|
---|
111 | {
|
---|
112 | LogRel(("aParent=%p\n", aParent));
|
---|
113 | ComAssertRet(aParent, E_INVALIDARG);
|
---|
114 |
|
---|
115 | /* Enclose the state transition NotReady->InInit->Ready */
|
---|
116 | AutoInitSpan autoInitSpan(this);
|
---|
117 | AssertReturn(autoInitSpan.isOk(), E_FAIL);
|
---|
118 |
|
---|
119 | unconst(mParent) = aParent;
|
---|
120 |
|
---|
121 | HRESULT hrc = S_OK;
|
---|
122 |
|
---|
123 | try
|
---|
124 | {
|
---|
125 | mCloudProvider = aCloudProvider;
|
---|
126 | LogRel(("CloudProvider = %d\n", mCloudProvider));
|
---|
127 | CloudUserProfileList *lProfiles = aProfiles;
|
---|
128 | std::vector<com::Utf8Str> lNames;
|
---|
129 | std::vector<com::Utf8Str> lValues;
|
---|
130 | hrc = lProfiles->getProfileProperties(aProfileName, lNames, lValues);
|
---|
131 | if (FAILED(hrc))
|
---|
132 | {
|
---|
133 | throw hrc;
|
---|
134 | }
|
---|
135 |
|
---|
136 | for (size_t i=0;i<lNames.size();++i)
|
---|
137 | {
|
---|
138 | com::Utf8Str value = (i<lValues.size()) ? lValues.at(i) : "";
|
---|
139 | userProfile[lNames.at(i)] = value;
|
---|
140 | }
|
---|
141 |
|
---|
142 | CloudProviderId_T aProvider;
|
---|
143 | hrc = lProfiles->getProvider(&aProvider);
|
---|
144 |
|
---|
145 | switch(aProvider)
|
---|
146 | {
|
---|
147 | case CloudProviderId_OCI:
|
---|
148 | default:
|
---|
149 | LogRel(("Reading profile %s has been done\n", aProfileName.c_str()));
|
---|
150 | break;
|
---|
151 | }
|
---|
152 | }
|
---|
153 | catch (HRESULT arc)
|
---|
154 | {
|
---|
155 | hrc = arc;
|
---|
156 | LogRel(("Get cought an exception %d\n", hrc));
|
---|
157 | }
|
---|
158 | catch (std::bad_alloc)
|
---|
159 | {
|
---|
160 | return E_OUTOFMEMORY;
|
---|
161 | }
|
---|
162 |
|
---|
163 | /*
|
---|
164 | * Confirm a successful initialization
|
---|
165 | */
|
---|
166 | autoInitSpan.setSucceeded();
|
---|
167 |
|
---|
168 | return hrc;
|
---|
169 | }
|
---|
170 |
|
---|
171 | HRESULT CloudClient::getOperationParameters(CloudOperation_T aCloudOperation, com::Utf8Str &aJsonString)
|
---|
172 | {
|
---|
173 | LogRel(("CloudClient::getOperationParameters: %d, %s\n", aCloudOperation, aJsonString.c_str()));
|
---|
174 | HRESULT hrc = VERR_NOT_IMPLEMENTED;
|
---|
175 | /*
|
---|
176 |
|
---|
177 | createCloudAPI
|
---|
178 | */
|
---|
179 | return hrc;
|
---|
180 | }
|
---|
181 |
|
---|
182 | HRESULT CloudClient::createOperation(const com::Utf8Str &aProfileName,
|
---|
183 | CloudOperation_T aCloudOperation,
|
---|
184 | com::Guid &aOpId)
|
---|
185 | {
|
---|
186 | LogRel(("CloudClient::createOperation: %s, %d, %s\n", aProfileName.c_str(),
|
---|
187 | aCloudOperation,
|
---|
188 | aOpId.toString().c_str()));
|
---|
189 | HRESULT hrc = VERR_NOT_IMPLEMENTED;
|
---|
190 | return hrc;
|
---|
191 | }
|
---|
192 |
|
---|
193 | HRESULT CloudClient::runOperation(const com::Guid &aOpId,
|
---|
194 | LONG64 aTimeout)
|
---|
195 | {
|
---|
196 | LogRel(("CloudClient::runOperation: %s, %d\n", aOpId.toString().c_str(), aTimeout));
|
---|
197 | HRESULT hrc = VERR_NOT_IMPLEMENTED;
|
---|
198 | return hrc;
|
---|
199 | }
|
---|
200 |
|
---|
201 | HRESULT CloudClient::checkOperationResult(const com::Guid &aOpId,
|
---|
202 | LONG64 *aStartOpTime,
|
---|
203 | LONG64 *aLastTime,
|
---|
204 | CloudOperationResult_T *aResult)
|
---|
205 | {
|
---|
206 | LogRel(("CloudClient::checkOperationResult: %s, %d, %d, %d\n",
|
---|
207 | aOpId.toString().c_str(),
|
---|
208 | *aStartOpTime,
|
---|
209 | *aLastTime,
|
---|
210 | *aResult));
|
---|
211 | HRESULT hrc = VERR_NOT_IMPLEMENTED;
|
---|
212 | return hrc;
|
---|
213 | }
|
---|
214 |
|
---|
215 | HRESULT CloudClient::getOperationParameterNames(CloudOperation_T aCloudOperation,
|
---|
216 | std::vector<com::Utf8Str> &aParameterNames)
|
---|
217 | {
|
---|
218 | LogRel(("CloudClient::getOperationParameterNames: %d\n", aCloudOperation));
|
---|
219 | aParameterNames.clear();
|
---|
220 | HRESULT hrc = VERR_NOT_IMPLEMENTED;
|
---|
221 | return hrc;
|
---|
222 | }
|
---|
223 |
|
---|
224 | HRESULT CloudClient::getOperationParameterProperties(const com::Utf8Str &aOpParameterName,
|
---|
225 | com::Utf8Str &aOpParameterType,
|
---|
226 | com::Utf8Str &aOpParameterDesc,
|
---|
227 | std::vector<com::Utf8Str> &aOpParameterValues)
|
---|
228 | {
|
---|
229 | LogRel(("CloudClient::getOperationParameterProperties: %s, %s, %s\n",
|
---|
230 | aOpParameterName.c_str(),
|
---|
231 | aOpParameterType.c_str(),
|
---|
232 | aOpParameterDesc.c_str()));
|
---|
233 | aOpParameterValues.clear();
|
---|
234 | HRESULT hrc = VERR_NOT_IMPLEMENTED;
|
---|
235 | return hrc;
|
---|
236 | }
|
---|
237 |
|
---|
238 | HRESULT CloudClient::setParametersForOperation(const com::Guid &aOpId,
|
---|
239 | const std::vector<com::Utf8Str> &aValues)
|
---|
240 | {
|
---|
241 | LogRel(("CloudClient::setParametersForOperation: %s\n", aOpId.toString().c_str()));
|
---|
242 | for (size_t i=0;i<aValues.size();++i)
|
---|
243 | {
|
---|
244 | LogRel(("value %d: %s\n", i, aValues.at(i).c_str()));
|
---|
245 | }
|
---|
246 |
|
---|
247 | HRESULT hrc = VERR_NOT_IMPLEMENTED;
|
---|
248 | return hrc;
|
---|
249 | }
|
---|
250 |
|
---|