VirtualBox

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

Last change on this file since 70217 was 69500, checked in by vboxsync, 7 years ago

*: scm --update-copyright-year

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