VirtualBox

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

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

bugref:9152. Fixed error handling

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 4.8 KB
Line 
1/* $Id: CloudUserProfileManagerImpl.cpp 73177 2018-07-17 12:19:50Z 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
33using namespace std;
34
35////////////////////////////////////////////////////////////////////////////////
36//
37// CloudUserProfileManager constructor / destructor
38//
39// ////////////////////////////////////////////////////////////////////////////////
40CloudUserProfileManager::CloudUserProfileManager()
41 : mParent(NULL)
42{
43}
44
45CloudUserProfileManager::~CloudUserProfileManager()
46{
47}
48
49
50HRESULT CloudUserProfileManager::FinalConstruct()
51{
52 return BaseFinalConstruct();
53}
54
55void CloudUserProfileManager::FinalRelease()
56{
57 uninit();
58
59 BaseFinalRelease();
60}
61
62HRESULT 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
76void 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
86HRESULT CloudUserProfileManager::getSupportedProviders(std::vector<CloudProviderId_T> &aSupportedProviders)
87{
88 aSupportedProviders = mSupportedProviders;
89 return S_OK;
90}
91
92HRESULT 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
112HRESULT 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 int vrc = RTPathUserHome(szHomeDir, sizeof(szHomeDir));
132 if (RT_SUCCESS(vrc))
133 {
134 Utf8Str strConfigPath(szHomeDir);
135 strConfigPath.append(RTPATH_SLASH_STR)
136 .append(".oci")
137 .append(RTPATH_SLASH_STR)
138 .append("config");
139 LogRel(("config = %s\n", strConfigPath.c_str()));
140 hrc = ptrOCIUserProfileList->readProfiles(strConfigPath);
141 if (SUCCEEDED(hrc))
142 {
143 LogRel(("Reading profiles from %s has been done\n", strConfigPath.c_str()));
144 }
145 else
146 {
147 LogRel(("Reading profiles from %s hasn't been done\n", strConfigPath.c_str()));
148 }
149 ptrCloudUserProfileList = ptrOCIUserProfileList;
150 hrc = ptrCloudUserProfileList.queryInterfaceTo(aProfiles.asOutParam());
151 }
152 else
153 hrc = setErrorVrc(vrc);
154 }
155 }
156 break;
157 }
158
159 return hrc;
160}
161
Note: See TracBrowser for help on using the repository browser.

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