VirtualBox

source: vbox/trunk/src/VBox/Main/src-all/VirtualBoxErrorInfoImpl.cpp@ 48009

Last change on this file since 48009 was 47391, checked in by vboxsync, 11 years ago

Main/VirtualBoxErrorInfo: Initialize mResultDetail.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 8.2 KB
Line 
1/** @file
2 *
3 * VirtualBoxErrorInfo COM class implementation
4 */
5
6/*
7 * Copyright (C) 2006-2013 Oracle Corporation
8 *
9 * This file is part of VirtualBox Open Source Edition (OSE), as
10 * available from http://www.virtualbox.org. This file is free software;
11 * you can redistribute it and/or modify it under the terms of the GNU
12 * General Public License (GPL) as published by the Free Software
13 * Foundation, in version 2 as it comes in the "COPYING" file of the
14 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
15 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
16 */
17
18#include "VirtualBoxErrorInfoImpl.h"
19#include "Logging.h"
20
21#include <VBox/com/ErrorInfo.h>
22
23// public initializer/uninitializer for internal purposes only
24////////////////////////////////////////////////////////////////////////////////
25
26HRESULT VirtualBoxErrorInfo::init(HRESULT aResultCode,
27 const GUID &aIID,
28 const char *pcszComponent,
29 const Utf8Str &strText,
30 IVirtualBoxErrorInfo *aNext)
31{
32 m_resultCode = aResultCode;
33 m_resultDetail = 0; /* Not being used. */
34 m_IID = aIID;
35 m_strComponent = pcszComponent;
36 m_strText = strText;
37 mNext = aNext;
38
39 return S_OK;
40}
41
42HRESULT VirtualBoxErrorInfo::initEx(HRESULT aResultCode,
43 LONG aResultDetail,
44 const GUID &aIID,
45 const char *pcszComponent,
46 const Utf8Str &strText,
47 IVirtualBoxErrorInfo *aNext)
48{
49 HRESULT hr = init(aResultCode, aIID, pcszComponent, strText, aNext);
50 m_resultDetail = aResultDetail;
51
52 return hr;
53}
54
55HRESULT VirtualBoxErrorInfo::init(const com::ErrorInfo &info,
56 IVirtualBoxErrorInfo *aNext)
57{
58 m_resultCode = info.getResultCode();
59 m_resultDetail = info.getResultDetail();
60 m_IID = info.getInterfaceID();
61 m_strComponent = info.getComponent();
62 m_strText = info.getText();
63
64 /* Recursively create VirtualBoxErrorInfo instances for the next objects. */
65 const com::ErrorInfo *pInfo = info.getNext();
66 if (pInfo)
67 {
68 ComObjPtr<VirtualBoxErrorInfo> nextEI;
69 HRESULT rc = nextEI.createObject();
70 if (FAILED(rc)) return rc;
71 rc = nextEI->init(*pInfo, aNext);
72 if (FAILED(rc)) return rc;
73 mNext = nextEI;
74 }
75 else
76 mNext = aNext;
77
78 return S_OK;
79}
80
81// IVirtualBoxErrorInfo properties
82////////////////////////////////////////////////////////////////////////////////
83
84STDMETHODIMP VirtualBoxErrorInfo::COMGETTER(ResultCode)(LONG *aResultCode)
85{
86 CheckComArgOutPointerValid(aResultCode);
87
88 *aResultCode = m_resultCode;
89 return S_OK;
90}
91
92STDMETHODIMP VirtualBoxErrorInfo::COMGETTER(ResultDetail)(LONG *aResultDetail)
93{
94 CheckComArgOutPointerValid(aResultDetail);
95
96 *aResultDetail = m_resultDetail;
97 return S_OK;
98}
99
100STDMETHODIMP VirtualBoxErrorInfo::COMGETTER(InterfaceID)(BSTR *aIID)
101{
102 CheckComArgOutPointerValid(aIID);
103
104 m_IID.toUtf16().cloneTo(aIID);
105 return S_OK;
106}
107
108STDMETHODIMP VirtualBoxErrorInfo::COMGETTER(Component)(BSTR *aComponent)
109{
110 CheckComArgOutPointerValid(aComponent);
111
112 m_strComponent.cloneTo(aComponent);
113 return S_OK;
114}
115
116STDMETHODIMP VirtualBoxErrorInfo::COMGETTER(Text)(BSTR *aText)
117{
118 CheckComArgOutPointerValid(aText);
119
120 m_strText.cloneTo(aText);
121 return S_OK;
122}
123
124STDMETHODIMP VirtualBoxErrorInfo::COMGETTER(Next)(IVirtualBoxErrorInfo **aNext)
125{
126 CheckComArgOutPointerValid(aNext);
127
128 /* this will set aNext to NULL if mNext is null */
129 return mNext.queryInterfaceTo(aNext);
130}
131
132#if !defined(VBOX_WITH_XPCOM)
133
134/**
135 * Initializes itself by fetching error information from the given error info
136 * object.
137 */
138HRESULT VirtualBoxErrorInfo::init(IErrorInfo *aInfo)
139{
140 AssertReturn(aInfo, E_FAIL);
141
142 HRESULT rc = S_OK;
143
144 /* We don't return a failure if talking to IErrorInfo fails below to
145 * protect ourselves from bad IErrorInfo implementations (the
146 * corresponding fields will simply remain null in this case). */
147
148 m_resultCode = S_OK;
149 m_resultDetail = 0;
150 rc = aInfo->GetGUID(m_IID.asOutParam());
151 AssertComRC(rc);
152 Bstr bstrComponent;
153 rc = aInfo->GetSource(bstrComponent.asOutParam());
154 AssertComRC(rc);
155 m_strComponent = bstrComponent;
156 Bstr bstrText;
157 rc = aInfo->GetDescription(bstrText.asOutParam());
158 AssertComRC(rc);
159 m_strText = bstrText;
160
161 return S_OK;
162}
163
164// IErrorInfo methods
165////////////////////////////////////////////////////////////////////////////////
166
167STDMETHODIMP VirtualBoxErrorInfo::GetDescription(BSTR *description)
168{
169 return COMGETTER(Text)(description);
170}
171
172STDMETHODIMP VirtualBoxErrorInfo::GetGUID(GUID *guid)
173{
174 Bstr iid;
175 HRESULT rc = COMGETTER(InterfaceID)(iid.asOutParam());
176 if (SUCCEEDED(rc))
177 *guid = Guid(iid).ref();
178 return rc;
179}
180
181STDMETHODIMP VirtualBoxErrorInfo::GetHelpContext(DWORD *pdwHelpContext)
182{
183 return E_NOTIMPL;
184}
185
186STDMETHODIMP VirtualBoxErrorInfo::GetHelpFile(BSTR *pbstrHelpFile)
187{
188 return E_NOTIMPL;
189}
190
191STDMETHODIMP VirtualBoxErrorInfo::GetSource(BSTR *source)
192{
193 return COMGETTER(Component)(source);
194}
195
196#else // defined(VBOX_WITH_XPCOM)
197
198/**
199 * Initializes itself by fetching error information from the given error info
200 * object.
201 */
202HRESULT VirtualBoxErrorInfo::init(nsIException *aInfo)
203{
204 AssertReturn(aInfo, E_FAIL);
205
206 HRESULT rc = S_OK;
207
208 /* We don't return a failure if talking to nsIException fails below to
209 * protect ourselves from bad nsIException implementations (the
210 * corresponding fields will simply remain null in this case). */
211
212 rc = aInfo->GetResult(&m_resultCode);
213 AssertComRC(rc);
214 m_resultDetail = 0; /* Not being used. */
215
216 char *pszMsg; /* No Utf8Str.asOutParam, different allocator! */
217 rc = aInfo->GetMessage(&pszMsg);
218 AssertComRC(rc);
219 if (NS_SUCCEEDED(rc))
220 {
221 m_strText = pszMsg;
222 nsMemory::Free(pszMsg);
223 }
224 else
225 m_strText.setNull();
226
227 return S_OK;
228}
229
230// nsIException methods
231////////////////////////////////////////////////////////////////////////////////
232
233/* readonly attribute string message; */
234NS_IMETHODIMP VirtualBoxErrorInfo::GetMessage(char **aMessage)
235{
236 CheckComArgOutPointerValid(aMessage);
237
238 m_strText.cloneTo(aMessage);
239 return S_OK;
240}
241
242/* readonly attribute nsresult result; */
243NS_IMETHODIMP VirtualBoxErrorInfo::GetResult(nsresult *aResult)
244{
245 if (!aResult)
246 return NS_ERROR_INVALID_POINTER;
247
248 PRInt32 lrc;
249 nsresult rc = COMGETTER(ResultCode)(&lrc);
250 if (SUCCEEDED(rc))
251 *aResult = lrc;
252 return rc;
253}
254
255/* readonly attribute string name; */
256NS_IMETHODIMP VirtualBoxErrorInfo::GetName(char ** /* aName */)
257{
258 return NS_ERROR_NOT_IMPLEMENTED;
259}
260
261/* readonly attribute string filename; */
262NS_IMETHODIMP VirtualBoxErrorInfo::GetFilename(char ** /* aFilename */)
263{
264 return NS_ERROR_NOT_IMPLEMENTED;
265}
266
267/* readonly attribute PRUint32 lineNumber; */
268NS_IMETHODIMP VirtualBoxErrorInfo::GetLineNumber(PRUint32 * /* aLineNumber */)
269{
270 return NS_ERROR_NOT_IMPLEMENTED;
271}
272
273/* readonly attribute PRUint32 columnNumber; */
274NS_IMETHODIMP VirtualBoxErrorInfo::GetColumnNumber(PRUint32 * /*aColumnNumber */)
275{
276 return NS_ERROR_NOT_IMPLEMENTED;
277}
278
279/* readonly attribute nsIStackFrame location; */
280NS_IMETHODIMP VirtualBoxErrorInfo::GetLocation(nsIStackFrame ** /* aLocation */)
281{
282 return NS_ERROR_NOT_IMPLEMENTED;
283}
284
285/* readonly attribute nsIException inner; */
286NS_IMETHODIMP VirtualBoxErrorInfo::GetInner(nsIException **aInner)
287{
288 ComPtr<IVirtualBoxErrorInfo> info;
289 nsresult rv = COMGETTER(Next)(info.asOutParam());
290 if (FAILED(rv)) return rv;
291 return info.queryInterfaceTo(aInner);
292}
293
294/* readonly attribute nsISupports data; */
295NS_IMETHODIMP VirtualBoxErrorInfo::GetData(nsISupports ** /* aData */)
296{
297 return NS_ERROR_NOT_IMPLEMENTED;
298}
299
300/* string toString(); */
301NS_IMETHODIMP VirtualBoxErrorInfo::ToString(char ** /* retval */)
302{
303 return NS_ERROR_NOT_IMPLEMENTED;
304}
305
306NS_IMPL_THREADSAFE_ISUPPORTS2(VirtualBoxErrorInfo,
307 nsIException, IVirtualBoxErrorInfo)
308
309#endif // defined(VBOX_WITH_XPCOM)
310/* vi: set tabstop=4 shiftwidth=4 expandtab: */
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