VirtualBox

source: vbox/trunk/src/VBox/Main/glue/VirtualBoxErrorInfo.cpp@ 25414

Last change on this file since 25414 was 25149, checked in by vboxsync, 15 years ago

Main: cleanup: remove all CheckComRC* macros (no functional change)

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

© 2023 Oracle
ContactPrivacy policyTerms of Use