VirtualBox

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

Last change on this file since 61644 was 55401, checked in by vboxsync, 10 years ago

added a couple of missing Id headers

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 8.2 KB
Line 
1/* $Id: VirtualBoxErrorInfoImpl.cpp 55401 2015-04-23 10:03:17Z vboxsync $ */
2/** @file
3 *
4 * VirtualBoxErrorInfo COM class implementation
5 */
6
7/*
8 * Copyright (C) 2006-2013 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 return E_NOTIMPL;
185}
186
187STDMETHODIMP VirtualBoxErrorInfo::GetHelpFile(BSTR *pbstrHelpFile)
188{
189 return E_NOTIMPL;
190}
191
192STDMETHODIMP VirtualBoxErrorInfo::GetSource(BSTR *source)
193{
194 return COMGETTER(Component)(source);
195}
196
197#else // defined(VBOX_WITH_XPCOM)
198
199/**
200 * Initializes itself by fetching error information from the given error info
201 * object.
202 */
203HRESULT VirtualBoxErrorInfo::init(nsIException *aInfo)
204{
205 AssertReturn(aInfo, E_FAIL);
206
207 HRESULT rc = S_OK;
208
209 /* We don't return a failure if talking to nsIException fails below to
210 * protect ourselves from bad nsIException implementations (the
211 * corresponding fields will simply remain null in this case). */
212
213 rc = aInfo->GetResult(&m_resultCode);
214 AssertComRC(rc);
215 m_resultDetail = 0; /* Not being used. */
216
217 char *pszMsg; /* No Utf8Str.asOutParam, different allocator! */
218 rc = aInfo->GetMessage(&pszMsg);
219 AssertComRC(rc);
220 if (NS_SUCCEEDED(rc))
221 {
222 m_strText = pszMsg;
223 nsMemory::Free(pszMsg);
224 }
225 else
226 m_strText.setNull();
227
228 return S_OK;
229}
230
231// nsIException methods
232////////////////////////////////////////////////////////////////////////////////
233
234/* readonly attribute string message; */
235NS_IMETHODIMP VirtualBoxErrorInfo::GetMessage(char **aMessage)
236{
237 CheckComArgOutPointerValid(aMessage);
238
239 m_strText.cloneTo(aMessage);
240 return S_OK;
241}
242
243/* readonly attribute nsresult result; */
244NS_IMETHODIMP VirtualBoxErrorInfo::GetResult(nsresult *aResult)
245{
246 if (!aResult)
247 return NS_ERROR_INVALID_POINTER;
248
249 PRInt32 lrc;
250 nsresult rc = COMGETTER(ResultCode)(&lrc);
251 if (SUCCEEDED(rc))
252 *aResult = lrc;
253 return rc;
254}
255
256/* readonly attribute string name; */
257NS_IMETHODIMP VirtualBoxErrorInfo::GetName(char ** /* aName */)
258{
259 return NS_ERROR_NOT_IMPLEMENTED;
260}
261
262/* readonly attribute string filename; */
263NS_IMETHODIMP VirtualBoxErrorInfo::GetFilename(char ** /* aFilename */)
264{
265 return NS_ERROR_NOT_IMPLEMENTED;
266}
267
268/* readonly attribute PRUint32 lineNumber; */
269NS_IMETHODIMP VirtualBoxErrorInfo::GetLineNumber(PRUint32 * /* aLineNumber */)
270{
271 return NS_ERROR_NOT_IMPLEMENTED;
272}
273
274/* readonly attribute PRUint32 columnNumber; */
275NS_IMETHODIMP VirtualBoxErrorInfo::GetColumnNumber(PRUint32 * /*aColumnNumber */)
276{
277 return NS_ERROR_NOT_IMPLEMENTED;
278}
279
280/* readonly attribute nsIStackFrame location; */
281NS_IMETHODIMP VirtualBoxErrorInfo::GetLocation(nsIStackFrame ** /* aLocation */)
282{
283 return NS_ERROR_NOT_IMPLEMENTED;
284}
285
286/* readonly attribute nsIException inner; */
287NS_IMETHODIMP VirtualBoxErrorInfo::GetInner(nsIException **aInner)
288{
289 ComPtr<IVirtualBoxErrorInfo> info;
290 nsresult rv = COMGETTER(Next)(info.asOutParam());
291 if (FAILED(rv)) return rv;
292 return info.queryInterfaceTo(aInner);
293}
294
295/* readonly attribute nsISupports data; */
296NS_IMETHODIMP VirtualBoxErrorInfo::GetData(nsISupports ** /* aData */)
297{
298 return NS_ERROR_NOT_IMPLEMENTED;
299}
300
301/* string toString(); */
302NS_IMETHODIMP VirtualBoxErrorInfo::ToString(char ** /* retval */)
303{
304 return NS_ERROR_NOT_IMPLEMENTED;
305}
306
307NS_IMPL_THREADSAFE_ISUPPORTS2(VirtualBoxErrorInfo,
308 nsIException, IVirtualBoxErrorInfo)
309
310#endif // defined(VBOX_WITH_XPCOM)
311/* 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