1 | /* $Id: CloudClientImpl.cpp 73173 2018-07-17 11:47:51Z 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 | }
|
---|
82 |
|
---|
83 | HRESULT CloudClient::init(VirtualBox *aParent)
|
---|
84 | {
|
---|
85 | LogRel(("aParent=%p\n", aParent));
|
---|
86 | ComAssertRet(aParent, E_INVALIDARG);
|
---|
87 |
|
---|
88 | /* Enclose the state transition NotReady->InInit->Ready */
|
---|
89 | AutoInitSpan autoInitSpan(this);
|
---|
90 | AssertReturn(autoInitSpan.isOk(), E_FAIL);
|
---|
91 |
|
---|
92 | unconst(mParent) = aParent;
|
---|
93 |
|
---|
94 | mCloudProvider = CloudProviderId_OCI;
|
---|
95 |
|
---|
96 | LogRel(("aParent=%p\n", aParent));
|
---|
97 |
|
---|
98 | /*
|
---|
99 | * Confirm a successful initialization
|
---|
100 | */
|
---|
101 | autoInitSpan.setSucceeded();
|
---|
102 |
|
---|
103 | return S_OK;
|
---|
104 | }
|
---|
105 |
|
---|
106 | HRESULT CloudClient::initCloudClient(CloudUserProfileList *aProfiles,
|
---|
107 | VirtualBox *aParent,
|
---|
108 | CloudProviderId_T aCloudProvider,
|
---|
109 | const com::Utf8Str &aProfileName)
|
---|
110 | {
|
---|
111 | LogRel(("aParent=%p\n", aParent));
|
---|
112 | ComAssertRet(aParent, E_INVALIDARG);
|
---|
113 |
|
---|
114 | /* Enclose the state transition NotReady->InInit->Ready */
|
---|
115 | AutoInitSpan autoInitSpan(this);
|
---|
116 | AssertReturn(autoInitSpan.isOk(), E_FAIL);
|
---|
117 |
|
---|
118 | unconst(mParent) = aParent;
|
---|
119 |
|
---|
120 | HRESULT hrc = S_OK;
|
---|
121 |
|
---|
122 | try
|
---|
123 | {
|
---|
124 | mCloudProvider = aCloudProvider;
|
---|
125 | LogRel(("CloudProvider = %d\n", mCloudProvider));
|
---|
126 | CloudUserProfileList *lProfiles = aProfiles;
|
---|
127 | std::vector<com::Utf8Str> lNames;
|
---|
128 | std::vector<com::Utf8Str> lValues;
|
---|
129 | hrc = lProfiles->getProfileProperties(aProfileName, lNames, lValues);
|
---|
130 | if (FAILED(hrc))
|
---|
131 | {
|
---|
132 | throw hrc;
|
---|
133 | }
|
---|
134 |
|
---|
135 | for (size_t i=0;i<lNames.size();++i)
|
---|
136 | {
|
---|
137 | com::Utf8Str value = (i<lValues.size()) ? lValues.at(i) : "";
|
---|
138 | userProfile[lNames.at(i)] = value;
|
---|
139 | }
|
---|
140 |
|
---|
141 | CloudProviderId_T aProvider;
|
---|
142 | hrc = lProfiles->getProvider(&aProvider);
|
---|
143 |
|
---|
144 | switch(aProvider)
|
---|
145 | {
|
---|
146 | case CloudProviderId_OCI:
|
---|
147 | default:
|
---|
148 | LogRel(("Reading profile %s has been done\n", aProfileName.c_str()));
|
---|
149 | break;
|
---|
150 | }
|
---|
151 | }
|
---|
152 | catch (HRESULT arc)
|
---|
153 | {
|
---|
154 | hrc = arc;
|
---|
155 | LogRel(("Get cought an exception %d\n", hrc));
|
---|
156 | }
|
---|
157 | catch (std::bad_alloc)
|
---|
158 | {
|
---|
159 | return E_OUTOFMEMORY;
|
---|
160 | }
|
---|
161 |
|
---|
162 | /*
|
---|
163 | * Confirm a successful initialization
|
---|
164 | */
|
---|
165 | autoInitSpan.setSucceeded();
|
---|
166 |
|
---|
167 | return hrc;
|
---|
168 | }
|
---|
169 |
|
---|
170 | HRESULT CloudClient::getOperationParameters(CloudOperation_T aCloudOperation, com::Utf8Str &aJsonString)
|
---|
171 | {
|
---|
172 | LogRel(("CloudClient::getOperationParameters: %d, %s\n", aCloudOperation, aJsonString.c_str()));
|
---|
173 | HRESULT hrc = VERR_NOT_IMPLEMENTED;
|
---|
174 |
|
---|
175 | return hrc;
|
---|
176 | }
|
---|
177 |
|
---|
178 | HRESULT CloudClient::createOperation(const com::Utf8Str &aProfileName,
|
---|
179 | CloudOperation_T aCloudOperation,
|
---|
180 | com::Guid &aOpId)
|
---|
181 | {
|
---|
182 | LogRel(("CloudClient::createOperation: %s, %d, %s\n", aProfileName.c_str(),
|
---|
183 | aCloudOperation,
|
---|
184 | aOpId.toString().c_str()));
|
---|
185 | HRESULT hrc = VERR_NOT_IMPLEMENTED;
|
---|
186 | return hrc;
|
---|
187 | }
|
---|
188 |
|
---|
189 | HRESULT CloudClient::runOperation(const com::Guid &aOpId,
|
---|
190 | LONG64 aTimeout)
|
---|
191 | {
|
---|
192 | LogRel(("CloudClient::runOperation: %s, %d\n", aOpId.toString().c_str(), aTimeout));
|
---|
193 | HRESULT hrc = VERR_NOT_IMPLEMENTED;
|
---|
194 | return hrc;
|
---|
195 | }
|
---|
196 |
|
---|
197 | HRESULT CloudClient::checkOperationResult(const com::Guid &aOpId,
|
---|
198 | LONG64 *aStartOpTime,
|
---|
199 | LONG64 *aLastTime,
|
---|
200 | CloudOperationResult_T *aResult)
|
---|
201 | {
|
---|
202 | LogRel(("CloudClient::checkOperationResult: %s, %d, %d, %d\n",
|
---|
203 | aOpId.toString().c_str(),
|
---|
204 | *aStartOpTime,
|
---|
205 | *aLastTime,
|
---|
206 | *aResult));
|
---|
207 | HRESULT hrc = VERR_NOT_IMPLEMENTED;
|
---|
208 | return hrc;
|
---|
209 | }
|
---|
210 |
|
---|
211 | HRESULT CloudClient::getOperationParameterNames(CloudOperation_T aCloudOperation,
|
---|
212 | std::vector<com::Utf8Str> &aParameterNames)
|
---|
213 | {
|
---|
214 | LogRel(("CloudClient::getOperationParameterNames: %d\n", aCloudOperation));
|
---|
215 | aParameterNames.clear();
|
---|
216 | HRESULT hrc = VERR_NOT_IMPLEMENTED;
|
---|
217 | return hrc;
|
---|
218 | }
|
---|
219 |
|
---|
220 | HRESULT CloudClient::getOperationParameterProperties(const com::Utf8Str &aOpParameterName,
|
---|
221 | com::Utf8Str &aOpParameterType,
|
---|
222 | com::Utf8Str &aOpParameterDesc,
|
---|
223 | std::vector<com::Utf8Str> &aOpParameterValues)
|
---|
224 | {
|
---|
225 | LogRel(("CloudClient::getOperationParameterProperties: %s, %s, %s\n",
|
---|
226 | aOpParameterName.c_str(),
|
---|
227 | aOpParameterType.c_str(),
|
---|
228 | aOpParameterDesc.c_str()));
|
---|
229 | aOpParameterValues.clear();
|
---|
230 | HRESULT hrc = VERR_NOT_IMPLEMENTED;
|
---|
231 | return hrc;
|
---|
232 | }
|
---|
233 |
|
---|
234 | HRESULT CloudClient::setParametersForOperation(const com::Guid &aOpId,
|
---|
235 | const std::vector<com::Utf8Str> &aValues)
|
---|
236 | {
|
---|
237 | LogRel(("CloudClient::setParametersForOperation: %s\n", aOpId.toString().c_str()));
|
---|
238 | for (size_t i=0;i<aValues.size();++i)
|
---|
239 | {
|
---|
240 | LogRel(("value %d: %s\n", i, aValues.at(i).c_str()));
|
---|
241 | }
|
---|
242 |
|
---|
243 | HRESULT hrc = VERR_NOT_IMPLEMENTED;
|
---|
244 | return hrc;
|
---|
245 | }
|
---|