VirtualBox

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

Last change on this file since 31883 was 28800, checked in by vboxsync, 15 years ago

Automated rebranding to Oracle copyright/license strings via filemuncher

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