1 | /* $Id: CloudUserProfileManagerImpl.cpp 73174 2018-07-17 11:52:00Z 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 "CloudUserProfileListImpl.h"
|
---|
26 | #include "VirtualBoxImpl.h"
|
---|
27 | #include "Global.h"
|
---|
28 | #include "ProgressImpl.h"
|
---|
29 | #include "MachineImpl.h"
|
---|
30 | #include "AutoCaller.h"
|
---|
31 | #include "Logging.h"
|
---|
32 |
|
---|
33 | using namespace std;
|
---|
34 |
|
---|
35 | ////////////////////////////////////////////////////////////////////////////////
|
---|
36 | //
|
---|
37 | // CloudUserProfileManager constructor / destructor
|
---|
38 | //
|
---|
39 | // ////////////////////////////////////////////////////////////////////////////////
|
---|
40 | CloudUserProfileManager::CloudUserProfileManager()
|
---|
41 | : mParent(NULL)
|
---|
42 | {
|
---|
43 | }
|
---|
44 |
|
---|
45 | CloudUserProfileManager::~CloudUserProfileManager()
|
---|
46 | {
|
---|
47 | }
|
---|
48 |
|
---|
49 |
|
---|
50 | HRESULT CloudUserProfileManager::FinalConstruct()
|
---|
51 | {
|
---|
52 | return BaseFinalConstruct();
|
---|
53 | }
|
---|
54 |
|
---|
55 | void CloudUserProfileManager::FinalRelease()
|
---|
56 | {
|
---|
57 | uninit();
|
---|
58 |
|
---|
59 | BaseFinalRelease();
|
---|
60 | }
|
---|
61 |
|
---|
62 | HRESULT CloudUserProfileManager::init(VirtualBox *aParent)
|
---|
63 | {
|
---|
64 | /* Enclose the state transition NotReady->InInit->Ready */
|
---|
65 | AutoInitSpan autoInitSpan(this);
|
---|
66 | AssertReturn(autoInitSpan.isOk(), E_FAIL);
|
---|
67 |
|
---|
68 | unconst(mParent) = aParent;
|
---|
69 | mSupportedProviders.clear();
|
---|
70 | mSupportedProviders.push_back(CloudProviderId_OCI);
|
---|
71 |
|
---|
72 | autoInitSpan.setSucceeded();
|
---|
73 | return S_OK;
|
---|
74 | }
|
---|
75 |
|
---|
76 | void CloudUserProfileManager::uninit()
|
---|
77 | {
|
---|
78 | /* Enclose the state transition Ready->InUninit->NotReady */
|
---|
79 | AutoUninitSpan autoUninitSpan(this);
|
---|
80 | if (autoUninitSpan.uninitDone())
|
---|
81 | return;
|
---|
82 |
|
---|
83 | unconst(mParent) = NULL;
|
---|
84 | }
|
---|
85 |
|
---|
86 | HRESULT CloudUserProfileManager::getSupportedProviders(std::vector<CloudProviderId_T> &aSupportedProviders)
|
---|
87 | {
|
---|
88 | aSupportedProviders = mSupportedProviders;
|
---|
89 | return S_OK;
|
---|
90 | }
|
---|
91 |
|
---|
92 | HRESULT CloudUserProfileManager::getAllProfiles(std::vector<ComPtr<ICloudUserProfileList> > &aProfilesList)
|
---|
93 | {
|
---|
94 | HRESULT hrc = S_OK;
|
---|
95 | std::vector<ComPtr<ICloudUserProfileList> > lProfilesList;
|
---|
96 | for (size_t i=0;i<mSupportedProviders.size();++i)
|
---|
97 | {
|
---|
98 | ComPtr<ICloudUserProfileList> lProfiles;
|
---|
99 | hrc = getProfilesByProvider(mSupportedProviders.at(i), lProfiles);
|
---|
100 | if (FAILED(hrc))
|
---|
101 | break;
|
---|
102 |
|
---|
103 | lProfilesList.push_back(lProfiles);
|
---|
104 | }
|
---|
105 |
|
---|
106 | if (SUCCEEDED(hrc))
|
---|
107 | aProfilesList = lProfilesList;
|
---|
108 |
|
---|
109 | return hrc;
|
---|
110 | }
|
---|
111 |
|
---|
112 | HRESULT CloudUserProfileManager::getProfilesByProvider(CloudProviderId_T aProviderType,
|
---|
113 | ComPtr<ICloudUserProfileList> &aProfiles)
|
---|
114 | {
|
---|
115 | ComObjPtr<CloudUserProfileList> ptrCloudUserProfileList;
|
---|
116 | HRESULT hrc = ptrCloudUserProfileList.createObject();
|
---|
117 | switch(aProviderType)
|
---|
118 | {
|
---|
119 | case CloudProviderId_OCI:
|
---|
120 | default:
|
---|
121 | ComObjPtr<OCIUserProfileList> ptrOCIUserProfileList;
|
---|
122 | hrc = ptrOCIUserProfileList.createObject();
|
---|
123 | if (SUCCEEDED(hrc))
|
---|
124 | {
|
---|
125 | AutoReadLock wlock(this COMMA_LOCKVAL_SRC_POS);
|
---|
126 |
|
---|
127 | hrc = ptrOCIUserProfileList->init(mParent);
|
---|
128 | if (SUCCEEDED(hrc))
|
---|
129 | {
|
---|
130 | char szHomeDir[RTPATH_MAX];
|
---|
131 | RTPathUserHome(szHomeDir, sizeof(szHomeDir));
|
---|
132 | Utf8Str strConfigPath(szHomeDir);
|
---|
133 | strConfigPath.append(RTPATH_SLASH_STR)
|
---|
134 | .append(".oci")
|
---|
135 | .append(RTPATH_SLASH_STR)
|
---|
136 | .append("config");
|
---|
137 | LogRel(("config = %s\n", strConfigPath.c_str()));
|
---|
138 | hrc = ptrOCIUserProfileList->readProfiles(strConfigPath);
|
---|
139 | if (SUCCEEDED(hrc))
|
---|
140 | {
|
---|
141 | LogRel(("Reading profiles from %s has been done\n", strConfigPath.c_str()));
|
---|
142 | }
|
---|
143 | else
|
---|
144 | {
|
---|
145 | LogRel(("Reading profiles from %s hasn't been done\n", strConfigPath.c_str()));
|
---|
146 | }
|
---|
147 | ptrCloudUserProfileList = ptrOCIUserProfileList;
|
---|
148 | hrc = ptrCloudUserProfileList.queryInterfaceTo(aProfiles.asOutParam());
|
---|
149 | }
|
---|
150 | }
|
---|
151 | break;
|
---|
152 | }
|
---|
153 |
|
---|
154 | return hrc;
|
---|
155 | }
|
---|
156 |
|
---|