VirtualBox

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

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

Main: Cleaned up the long standing const BSTR = const (OLECHAR *) on WIn32 vs (const PRunichar) * on XPCOM clash. Cleaned up BSTR/GUID macros (IN_BSTR replaces INPTR BSTR, IN_GUID replaces INPTR GUIDPARAM, OUT_GUID replaces GUIDPARAMOUT).

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