1 | /* $Id: VirtualBoxErrorInfo.cpp 21878 2009-07-30 12:42:08Z vboxsync $ */
|
---|
2 |
|
---|
3 | /** @file
|
---|
4 | * MS COM / XPCOM Abstraction Layer:
|
---|
5 | * VirtualBoxErrorInfo COM class implementation
|
---|
6 | */
|
---|
7 |
|
---|
8 | /*
|
---|
9 | * Copyright (C) 2008-2009 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 | #include "VBox/com/VirtualBoxErrorInfo.h"
|
---|
25 |
|
---|
26 | #include "../include/Logging.h"
|
---|
27 |
|
---|
28 | #include <list>
|
---|
29 |
|
---|
30 | namespace com
|
---|
31 | {
|
---|
32 |
|
---|
33 | ////////////////////////////////////////////////////////////////////////////////
|
---|
34 | // VirtualBoxErrorInfo class
|
---|
35 | ////////////////////////////////////////////////////////////////////////////////
|
---|
36 |
|
---|
37 | // public initializer/uninitializer for internal purposes only
|
---|
38 | ////////////////////////////////////////////////////////////////////////////////
|
---|
39 |
|
---|
40 | /**
|
---|
41 | * Initializes the error info object with the given error details.
|
---|
42 | */
|
---|
43 | HRESULT VirtualBoxErrorInfo::init (HRESULT aResultCode, const GUID *aIID,
|
---|
44 | const char *aComponent, const char *aText,
|
---|
45 | IVirtualBoxErrorInfo *aNext)
|
---|
46 | {
|
---|
47 | mResultCode = aResultCode;
|
---|
48 |
|
---|
49 | if (aIID != NULL)
|
---|
50 | mIID = *aIID;
|
---|
51 |
|
---|
52 | mComponent = aComponent;
|
---|
53 | mText = aText;
|
---|
54 | mNext = aNext;
|
---|
55 |
|
---|
56 | return S_OK;
|
---|
57 | }
|
---|
58 |
|
---|
59 | // IVirtualBoxErrorInfo properties
|
---|
60 | ////////////////////////////////////////////////////////////////////////////////
|
---|
61 |
|
---|
62 | STDMETHODIMP VirtualBoxErrorInfo::COMGETTER(ResultCode) (LONG *aResultCode)
|
---|
63 | {
|
---|
64 | if (!aResultCode)
|
---|
65 | return E_POINTER;
|
---|
66 |
|
---|
67 | *aResultCode = mResultCode;
|
---|
68 | return S_OK;
|
---|
69 | }
|
---|
70 |
|
---|
71 | STDMETHODIMP VirtualBoxErrorInfo::COMGETTER(InterfaceID) (BSTR *aIID)
|
---|
72 | {
|
---|
73 | if (!aIID)
|
---|
74 | return E_POINTER;
|
---|
75 |
|
---|
76 | mIID.toUtf16().cloneTo(aIID);
|
---|
77 | return S_OK;
|
---|
78 | }
|
---|
79 |
|
---|
80 | STDMETHODIMP VirtualBoxErrorInfo::COMGETTER(Component) (BSTR *aComponent)
|
---|
81 | {
|
---|
82 | if (!aComponent)
|
---|
83 | return E_POINTER;
|
---|
84 |
|
---|
85 | mComponent.cloneTo(aComponent);
|
---|
86 | return S_OK;
|
---|
87 | }
|
---|
88 |
|
---|
89 | STDMETHODIMP VirtualBoxErrorInfo::COMGETTER(Text) (BSTR *aText)
|
---|
90 | {
|
---|
91 | if (!aText)
|
---|
92 | return E_POINTER;
|
---|
93 |
|
---|
94 | mText.cloneTo(aText);
|
---|
95 | return S_OK;
|
---|
96 | }
|
---|
97 |
|
---|
98 | STDMETHODIMP VirtualBoxErrorInfo::COMGETTER(Next) (IVirtualBoxErrorInfo **aNext)
|
---|
99 | {
|
---|
100 | if (!aNext)
|
---|
101 | return E_POINTER;
|
---|
102 |
|
---|
103 | /* this will set aNext to NULL if mNext is null */
|
---|
104 | return mNext.queryInterfaceTo(aNext);
|
---|
105 | }
|
---|
106 |
|
---|
107 | #if !defined (VBOX_WITH_XPCOM)
|
---|
108 |
|
---|
109 | /**
|
---|
110 | * Initializes itself by fetching error information from the given error info
|
---|
111 | * object.
|
---|
112 | */
|
---|
113 | HRESULT VirtualBoxErrorInfo::init (IErrorInfo *aInfo)
|
---|
114 | {
|
---|
115 | AssertReturn(aInfo, E_FAIL);
|
---|
116 |
|
---|
117 | HRESULT rc = S_OK;
|
---|
118 |
|
---|
119 | /* We don't return a failure if talking to IErrorInfo fails below to
|
---|
120 | * protect ourselves from bad IErrorInfo implementations (the
|
---|
121 | * corresponding fields will simply remain null in this case). */
|
---|
122 |
|
---|
123 | mResultCode = S_OK;
|
---|
124 | rc = aInfo->GetGUID (mIID.asOutParam());
|
---|
125 | AssertComRC (rc);
|
---|
126 | rc = aInfo->GetSource (mComponent.asOutParam());
|
---|
127 | AssertComRC (rc);
|
---|
128 | rc = aInfo->GetDescription (mText.asOutParam());
|
---|
129 | AssertComRC (rc);
|
---|
130 |
|
---|
131 | return S_OK;
|
---|
132 | }
|
---|
133 |
|
---|
134 | // IErrorInfo methods
|
---|
135 | ////////////////////////////////////////////////////////////////////////////////
|
---|
136 |
|
---|
137 | STDMETHODIMP VirtualBoxErrorInfo::GetDescription (BSTR *description)
|
---|
138 | {
|
---|
139 | return COMGETTER(Text) (description);
|
---|
140 | }
|
---|
141 |
|
---|
142 | STDMETHODIMP VirtualBoxErrorInfo::GetGUID (GUID *guid)
|
---|
143 | {
|
---|
144 | Bstr iid;
|
---|
145 | HRESULT rc = COMGETTER(InterfaceID) (iid.asOutParam());
|
---|
146 | if (SUCCEEDED(rc))
|
---|
147 | *guid = Guid(iid);
|
---|
148 | return rc;
|
---|
149 | }
|
---|
150 |
|
---|
151 | STDMETHODIMP VirtualBoxErrorInfo::GetHelpContext (DWORD *pdwHelpContext)
|
---|
152 | {
|
---|
153 | return E_NOTIMPL;
|
---|
154 | }
|
---|
155 |
|
---|
156 | STDMETHODIMP VirtualBoxErrorInfo::GetHelpFile (BSTR *pbstrHelpFile)
|
---|
157 | {
|
---|
158 | return E_NOTIMPL;
|
---|
159 | }
|
---|
160 |
|
---|
161 | STDMETHODIMP VirtualBoxErrorInfo::GetSource (BSTR *source)
|
---|
162 | {
|
---|
163 | return COMGETTER(Component) (source);
|
---|
164 | }
|
---|
165 |
|
---|
166 | #else // !defined (VBOX_WITH_XPCOM)
|
---|
167 |
|
---|
168 | /**
|
---|
169 | * Initializes itself by fetching error information from the given error info
|
---|
170 | * object.
|
---|
171 | */
|
---|
172 | HRESULT VirtualBoxErrorInfo::init (nsIException *aInfo)
|
---|
173 | {
|
---|
174 | AssertReturn(aInfo, E_FAIL);
|
---|
175 |
|
---|
176 | HRESULT rc = S_OK;
|
---|
177 |
|
---|
178 | /* We don't return a failure if talking to nsIException fails below to
|
---|
179 | * protect ourselves from bad nsIException implementations (the
|
---|
180 | * corresponding fields will simply remain null in this case). */
|
---|
181 |
|
---|
182 | rc = aInfo->GetResult (&mResultCode);
|
---|
183 | AssertComRC (rc);
|
---|
184 | Utf8Str message;
|
---|
185 | rc = aInfo->GetMessage(message.asOutParam());
|
---|
186 | message.jolt();
|
---|
187 | AssertComRC (rc);
|
---|
188 | mText = message;
|
---|
189 |
|
---|
190 | return S_OK;
|
---|
191 | }
|
---|
192 |
|
---|
193 | // nsIException methods
|
---|
194 | ////////////////////////////////////////////////////////////////////////////////
|
---|
195 |
|
---|
196 | /* readonly attribute string message; */
|
---|
197 | NS_IMETHODIMP VirtualBoxErrorInfo::GetMessage (char **aMessage)
|
---|
198 | {
|
---|
199 | if (!aMessage)
|
---|
200 | return NS_ERROR_INVALID_POINTER;
|
---|
201 |
|
---|
202 | Utf8Str (mText).cloneTo(aMessage);
|
---|
203 | return S_OK;
|
---|
204 | }
|
---|
205 |
|
---|
206 | /* readonly attribute nsresult result; */
|
---|
207 | NS_IMETHODIMP VirtualBoxErrorInfo::GetResult (nsresult *aResult)
|
---|
208 | {
|
---|
209 | if (!aResult)
|
---|
210 | return NS_ERROR_INVALID_POINTER;
|
---|
211 |
|
---|
212 | PRInt32 lrc;
|
---|
213 | nsresult rc = COMGETTER(ResultCode) (&lrc);
|
---|
214 | if (SUCCEEDED(rc))
|
---|
215 | *aResult = lrc;
|
---|
216 | return rc;
|
---|
217 | }
|
---|
218 |
|
---|
219 | /* readonly attribute string name; */
|
---|
220 | NS_IMETHODIMP VirtualBoxErrorInfo::GetName (char **aName)
|
---|
221 | {
|
---|
222 | return NS_ERROR_NOT_IMPLEMENTED;
|
---|
223 | }
|
---|
224 |
|
---|
225 | /* readonly attribute string filename; */
|
---|
226 | NS_IMETHODIMP VirtualBoxErrorInfo::GetFilename (char **aFilename)
|
---|
227 | {
|
---|
228 | return NS_ERROR_NOT_IMPLEMENTED;
|
---|
229 | }
|
---|
230 |
|
---|
231 | /* readonly attribute PRUint32 lineNumber; */
|
---|
232 | NS_IMETHODIMP VirtualBoxErrorInfo::GetLineNumber (PRUint32 *aLineNumber)
|
---|
233 | {
|
---|
234 | return NS_ERROR_NOT_IMPLEMENTED;
|
---|
235 | }
|
---|
236 |
|
---|
237 | /* readonly attribute PRUint32 columnNumber; */
|
---|
238 | NS_IMETHODIMP VirtualBoxErrorInfo::GetColumnNumber (PRUint32 *aColumnNumber)
|
---|
239 | {
|
---|
240 | return NS_ERROR_NOT_IMPLEMENTED;
|
---|
241 | }
|
---|
242 |
|
---|
243 | /* readonly attribute nsIStackFrame location; */
|
---|
244 | NS_IMETHODIMP VirtualBoxErrorInfo::GetLocation (nsIStackFrame **aLocation)
|
---|
245 | {
|
---|
246 | return NS_ERROR_NOT_IMPLEMENTED;
|
---|
247 | }
|
---|
248 |
|
---|
249 | /* readonly attribute nsIException inner; */
|
---|
250 | NS_IMETHODIMP VirtualBoxErrorInfo::GetInner (nsIException **aInner)
|
---|
251 | {
|
---|
252 | ComPtr<IVirtualBoxErrorInfo> info;
|
---|
253 | nsresult rv = COMGETTER(Next) (info.asOutParam());
|
---|
254 | CheckComRCReturnRC(rv);
|
---|
255 | return info.queryInterfaceTo(aInner);
|
---|
256 | }
|
---|
257 |
|
---|
258 | /* readonly attribute nsISupports data; */
|
---|
259 | NS_IMETHODIMP VirtualBoxErrorInfo::GetData (nsISupports **aData)
|
---|
260 | {
|
---|
261 | return NS_ERROR_NOT_IMPLEMENTED;
|
---|
262 | }
|
---|
263 |
|
---|
264 | /* string toString (); */
|
---|
265 | NS_IMETHODIMP VirtualBoxErrorInfo::ToString (char **_retval)
|
---|
266 | {
|
---|
267 | return NS_ERROR_NOT_IMPLEMENTED;
|
---|
268 | }
|
---|
269 |
|
---|
270 | NS_IMPL_THREADSAFE_ISUPPORTS2 (VirtualBoxErrorInfo,
|
---|
271 | nsIException, IVirtualBoxErrorInfo)
|
---|
272 |
|
---|
273 | #endif /* !defined (VBOX_WITH_XPCOM) */
|
---|
274 |
|
---|
275 | ////////////////////////////////////////////////////////////////////////////////
|
---|
276 | // VirtualBoxErrorInfoGlue class
|
---|
277 | ////////////////////////////////////////////////////////////////////////////////
|
---|
278 |
|
---|
279 | // public initializer/uninitializer for internal purposes only
|
---|
280 | ////////////////////////////////////////////////////////////////////////////////
|
---|
281 |
|
---|
282 | /**
|
---|
283 | * Initializes the glue object with two given error info chains.
|
---|
284 | *
|
---|
285 | * @param aHead Chain placed to the beginning.
|
---|
286 | * @param aTail Chain placed to the end.
|
---|
287 | */
|
---|
288 | HRESULT VirtualBoxErrorInfoGlue::init (IVirtualBoxErrorInfo *aHead,
|
---|
289 | IVirtualBoxErrorInfo *aTail)
|
---|
290 | {
|
---|
291 | AssertReturn(aHead != NULL, E_INVALIDARG);
|
---|
292 | AssertReturn(aTail != NULL, E_INVALIDARG);
|
---|
293 |
|
---|
294 | HRESULT rc = S_OK;
|
---|
295 |
|
---|
296 | typedef std::list <ComPtr<IVirtualBoxErrorInfo> > List;
|
---|
297 | List list;
|
---|
298 |
|
---|
299 | ComPtr<IVirtualBoxErrorInfo> cur = aHead;
|
---|
300 |
|
---|
301 | do
|
---|
302 | {
|
---|
303 | ComPtr<IVirtualBoxErrorInfo> next;
|
---|
304 | rc = cur->COMGETTER(Next) (next.asOutParam());
|
---|
305 | CheckComRCReturnRC(rc);
|
---|
306 |
|
---|
307 | if (next.isNull())
|
---|
308 | break;
|
---|
309 |
|
---|
310 | list.push_back (next);
|
---|
311 | cur = next;
|
---|
312 | }
|
---|
313 | while (true);
|
---|
314 |
|
---|
315 | if (list.size() == 0)
|
---|
316 | {
|
---|
317 | /* simplest case */
|
---|
318 | mReal = aHead;
|
---|
319 | mNext = aTail;
|
---|
320 | return S_OK;
|
---|
321 | }
|
---|
322 |
|
---|
323 | for (List::iterator it = list.end(), prev = it; it != list.begin(); -- it)
|
---|
324 | {
|
---|
325 | ComObjPtr<VirtualBoxErrorInfoGlue> wrapper;
|
---|
326 | rc = wrapper.createObject();
|
---|
327 | CheckComRCBreakRC (rc);
|
---|
328 |
|
---|
329 | -- prev;
|
---|
330 |
|
---|
331 | if (it == list.end())
|
---|
332 | rc = wrapper->protectedInit (*prev, aTail);
|
---|
333 | else
|
---|
334 | rc = wrapper->protectedInit (*prev, *it);
|
---|
335 |
|
---|
336 | *prev = wrapper;
|
---|
337 |
|
---|
338 | CheckComRCBreakRC (rc);
|
---|
339 | }
|
---|
340 |
|
---|
341 | mReal = aHead;
|
---|
342 | mNext = list.front();
|
---|
343 |
|
---|
344 | return S_OK;
|
---|
345 | }
|
---|
346 |
|
---|
347 | /**
|
---|
348 | * Protected initializer that just sets the data fields as given.
|
---|
349 | *
|
---|
350 | * @param aReal Real error info object (not NULL) to forward calls to.
|
---|
351 | * @param aNext Next error info object (may be NULL).
|
---|
352 | */
|
---|
353 | HRESULT VirtualBoxErrorInfoGlue::protectedInit (IVirtualBoxErrorInfo *aReal,
|
---|
354 | IVirtualBoxErrorInfo *aNext)
|
---|
355 | {
|
---|
356 | AssertReturn(aReal != NULL, E_INVALIDARG);
|
---|
357 |
|
---|
358 | mReal = aReal;
|
---|
359 | mNext = aNext;
|
---|
360 |
|
---|
361 | return S_OK;
|
---|
362 | }
|
---|
363 |
|
---|
364 | // IVirtualBoxErrorInfo properties
|
---|
365 | ////////////////////////////////////////////////////////////////////////////////
|
---|
366 |
|
---|
367 | STDMETHODIMP VirtualBoxErrorInfoGlue::COMGETTER(Next) (IVirtualBoxErrorInfo **aNext)
|
---|
368 | {
|
---|
369 | if (!aNext)
|
---|
370 | return E_POINTER;
|
---|
371 |
|
---|
372 | /* this will set aNext to NULL if mNext is null */
|
---|
373 | return mNext.queryInterfaceTo(aNext);
|
---|
374 | }
|
---|
375 |
|
---|
376 | #if defined (VBOX_WITH_XPCOM)
|
---|
377 |
|
---|
378 | NS_IMPL_THREADSAFE_ISUPPORTS2 (VirtualBoxErrorInfoGlue,
|
---|
379 | nsIException, IVirtualBoxErrorInfo)
|
---|
380 |
|
---|
381 | #endif /* defined (VBOX_WITH_XPCOM) */
|
---|
382 |
|
---|
383 | } /* namespace com */
|
---|
384 |
|
---|