VirtualBox

source: vbox/trunk/src/VBox/Main/glue/ErrorInfo.cpp@ 20267

Last change on this file since 20267 was 20267, checked in by vboxsync, 16 years ago

Main: completed scriptable changes
Make VBox buildable on SMB share exported by Win box.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 7.3 KB
Line 
1/* $Id: ErrorInfo.cpp 20267 2009-06-04 11:27:27Z vboxsync $ */
2
3/** @file
4 *
5 * ErrorInfo class definition
6 */
7
8/*
9 * Copyright (C) 2006-2007 Sun Microsystems, Inc.
10 *
11 * This file is part of VirtualBox Open Source Edition (OSE), as
12 * available from http://www.virtualbox.org. This file is free software;
13 * you can redistribute it and/or modify it under the terms of the GNU
14 * General Public License (GPL) as published by the Free Software
15 * Foundation, in version 2 as it comes in the "COPYING" file of the
16 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
17 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
18 *
19 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
20 * Clara, CA 95054 USA or visit http://www.sun.com if you need
21 * additional information or have any questions.
22 */
23
24#if !defined (VBOX_WITH_XPCOM)
25
26#else
27
28#include <nsIServiceManager.h>
29#include <nsIExceptionService.h>
30#include <nsCOMPtr.h>
31
32#endif
33
34#include "VBox/com/VirtualBox.h"
35#include "VBox/com/ErrorInfo.h"
36#include "VBox/com/assert.h"
37#include "VBox/com/com.h"
38
39#include <iprt/stream.h>
40#include <iprt/string.h>
41
42#include <VBox/err.h>
43
44namespace com
45{
46
47// ErrorInfo class
48////////////////////////////////////////////////////////////////////////////////
49
50void ErrorInfo::init (bool aKeepObj /* = false */)
51{
52 HRESULT rc = E_FAIL;
53
54#if !defined (VBOX_WITH_XPCOM)
55
56 ComPtr <IErrorInfo> err;
57 rc = ::GetErrorInfo (0, err.asOutParam());
58 if (rc == S_OK && err)
59 {
60 if (aKeepObj)
61 mErrorInfo = err;
62
63 ComPtr <IVirtualBoxErrorInfo> info;
64 rc = err.queryInterfaceTo (info.asOutParam());
65 if (SUCCEEDED (rc) && info)
66 init (info);
67
68 if (!mIsFullAvailable)
69 {
70 bool gotSomething = false;
71
72 rc = err->GetGUID (mInterfaceID.asOutParam());
73 gotSomething |= SUCCEEDED (rc);
74 if (SUCCEEDED (rc))
75 GetInterfaceNameByIID (mInterfaceID, mInterfaceName.asOutParam());
76
77 rc = err->GetSource (mComponent.asOutParam());
78 gotSomething |= SUCCEEDED (rc);
79
80 rc = err->GetDescription (mText.asOutParam());
81 gotSomething |= SUCCEEDED (rc);
82
83 if (gotSomething)
84 mIsBasicAvailable = true;
85
86 AssertMsg (gotSomething, ("Nothing to fetch!\n"));
87 }
88 }
89
90#else // !defined (VBOX_WITH_XPCOM)
91
92 nsCOMPtr <nsIExceptionService> es;
93 es = do_GetService (NS_EXCEPTIONSERVICE_CONTRACTID, &rc);
94 if (NS_SUCCEEDED (rc))
95 {
96 nsCOMPtr <nsIExceptionManager> em;
97 rc = es->GetCurrentExceptionManager (getter_AddRefs (em));
98 if (NS_SUCCEEDED (rc))
99 {
100 ComPtr <nsIException> ex;
101 rc = em->GetCurrentException (ex.asOutParam());
102 if (NS_SUCCEEDED (rc) && ex)
103 {
104 if (aKeepObj)
105 mErrorInfo = ex;
106
107 ComPtr <IVirtualBoxErrorInfo> info;
108 rc = ex.queryInterfaceTo (info.asOutParam());
109 if (NS_SUCCEEDED (rc) && info)
110 init (info);
111
112 if (!mIsFullAvailable)
113 {
114 bool gotSomething = false;
115
116 rc = ex->GetResult (&mResultCode);
117 gotSomething |= NS_SUCCEEDED (rc);
118
119 Utf8Str message;
120 rc = ex->GetMessage (message.asOutParam());
121 gotSomething |= NS_SUCCEEDED (rc);
122 if (NS_SUCCEEDED (rc))
123 mText = message;
124
125 if (gotSomething)
126 mIsBasicAvailable = true;
127
128 AssertMsg (gotSomething, ("Nothing to fetch!\n"));
129 }
130
131 // set the exception to NULL (to emulate Win32 behavior)
132 em->SetCurrentException (NULL);
133
134 rc = NS_OK;
135 }
136 }
137 }
138
139 AssertComRC (rc);
140
141#endif // !defined (VBOX_WITH_XPCOM)
142}
143
144void ErrorInfo::init (IUnknown *aI, const GUID &aIID, bool aKeepObj /* = false */)
145{
146 Assert (aI);
147 if (!aI)
148 return;
149
150#if !defined (VBOX_WITH_XPCOM)
151
152 ComPtr <IUnknown> iface = aI;
153 ComPtr <ISupportErrorInfo> serr;
154 HRESULT rc = iface.queryInterfaceTo (serr.asOutParam());
155 if (SUCCEEDED (rc))
156 {
157 rc = serr->InterfaceSupportsErrorInfo (aIID);
158 if (SUCCEEDED (rc))
159 init (aKeepObj);
160 }
161
162#else
163
164 init (aKeepObj);
165
166#endif
167
168 if (mIsBasicAvailable)
169 {
170 mCalleeIID = aIID;
171 GetInterfaceNameByIID (aIID, mCalleeName.asOutParam());
172 }
173}
174
175void ErrorInfo::init (IVirtualBoxErrorInfo *info)
176{
177 AssertReturnVoid (info);
178
179 HRESULT rc = E_FAIL;
180 bool gotSomething = false;
181 bool gotAll = true;
182 LONG lrc;
183
184 rc = info->COMGETTER(ResultCode) (&lrc); mResultCode = lrc;
185 gotSomething |= SUCCEEDED (rc);
186 gotAll &= SUCCEEDED (rc);
187
188 rc = info->COMGETTER(InterfaceID) (mInterfaceID.asOutParam());
189 gotSomething |= SUCCEEDED (rc);
190 gotAll &= SUCCEEDED (rc);
191 if (SUCCEEDED (rc))
192 GetInterfaceNameByIID (mInterfaceID, mInterfaceName.asOutParam());
193
194 rc = info->COMGETTER(Component) (mComponent.asOutParam());
195 gotSomething |= SUCCEEDED (rc);
196 gotAll &= SUCCEEDED (rc);
197
198 rc = info->COMGETTER(Text) (mText.asOutParam());
199 gotSomething |= SUCCEEDED (rc);
200 gotAll &= SUCCEEDED (rc);
201
202 ComPtr <IVirtualBoxErrorInfo> next;
203 rc = info->COMGETTER(Next) (next.asOutParam());
204 if (SUCCEEDED (rc) && !next.isNull())
205 {
206 mNext.reset (new ErrorInfo (next));
207 Assert (mNext.get());
208 if (!mNext.get())
209 rc = E_OUTOFMEMORY;
210 }
211 else
212 mNext.reset();
213 gotSomething |= SUCCEEDED (rc);
214 gotAll &= SUCCEEDED (rc);
215
216 mIsBasicAvailable = gotSomething;
217 mIsFullAvailable = gotAll;
218
219 AssertMsg (gotSomething, ("Nothing to fetch!\n"));
220}
221
222ErrorInfo::~ErrorInfo()
223{
224}
225
226// ProgressErrorInfo class
227////////////////////////////////////////////////////////////////////////////////
228
229ProgressErrorInfo::ProgressErrorInfo (IProgress *progress) :
230 ErrorInfo (false /* aDummy */)
231{
232 Assert (progress);
233 if (!progress)
234 return;
235
236 ComPtr <IVirtualBoxErrorInfo> info;
237 HRESULT rc = progress->COMGETTER(ErrorInfo) (info.asOutParam());
238 if (SUCCEEDED (rc) && info)
239 init (info);
240}
241
242// ErrorInfoKeeper class
243////////////////////////////////////////////////////////////////////////////////
244
245HRESULT ErrorInfoKeeper::restore()
246{
247 if (mForgot)
248 return S_OK;
249
250 HRESULT rc = S_OK;
251
252#if !defined (VBOX_WITH_XPCOM)
253
254 ComPtr <IErrorInfo> err;
255 if (!mErrorInfo.isNull())
256 {
257 rc = mErrorInfo.queryInterfaceTo (err.asOutParam());
258 AssertComRC (rc);
259 }
260 rc = ::SetErrorInfo (0, err);
261
262#else // !defined (VBOX_WITH_XPCOM)
263
264 nsCOMPtr <nsIExceptionService> es;
265 es = do_GetService (NS_EXCEPTIONSERVICE_CONTRACTID, &rc);
266 if (NS_SUCCEEDED (rc))
267 {
268 nsCOMPtr <nsIExceptionManager> em;
269 rc = es->GetCurrentExceptionManager (getter_AddRefs (em));
270 if (NS_SUCCEEDED (rc))
271 {
272 ComPtr <nsIException> ex;
273 if (!mErrorInfo.isNull())
274 {
275 rc = mErrorInfo.queryInterfaceTo (ex.asOutParam());
276 AssertComRC (rc);
277 }
278 rc = em->SetCurrentException (ex);
279 }
280 }
281
282#endif // !defined (VBOX_WITH_XPCOM)
283
284 if (SUCCEEDED (rc))
285 {
286 mErrorInfo.setNull();
287 mForgot = true;
288 }
289
290 return rc;
291}
292
293} /* namespace com */
294
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