1 | /* $Id: VirtualBoxErrorInfoImpl.cpp 63239 2016-08-10 09:39:08Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | *
|
---|
4 | * VirtualBoxErrorInfo COM class implementation
|
---|
5 | */
|
---|
6 |
|
---|
7 | /*
|
---|
8 | * Copyright (C) 2006-2016 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 |
|
---|
27 | HRESULT 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 |
|
---|
43 | HRESULT 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 |
|
---|
56 | HRESULT 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 |
|
---|
85 | STDMETHODIMP VirtualBoxErrorInfo::COMGETTER(ResultCode)(LONG *aResultCode)
|
---|
86 | {
|
---|
87 | CheckComArgOutPointerValid(aResultCode);
|
---|
88 |
|
---|
89 | *aResultCode = m_resultCode;
|
---|
90 | return S_OK;
|
---|
91 | }
|
---|
92 |
|
---|
93 | STDMETHODIMP VirtualBoxErrorInfo::COMGETTER(ResultDetail)(LONG *aResultDetail)
|
---|
94 | {
|
---|
95 | CheckComArgOutPointerValid(aResultDetail);
|
---|
96 |
|
---|
97 | *aResultDetail = m_resultDetail;
|
---|
98 | return S_OK;
|
---|
99 | }
|
---|
100 |
|
---|
101 | STDMETHODIMP VirtualBoxErrorInfo::COMGETTER(InterfaceID)(BSTR *aIID)
|
---|
102 | {
|
---|
103 | CheckComArgOutPointerValid(aIID);
|
---|
104 |
|
---|
105 | m_IID.toUtf16().cloneTo(aIID);
|
---|
106 | return S_OK;
|
---|
107 | }
|
---|
108 |
|
---|
109 | STDMETHODIMP VirtualBoxErrorInfo::COMGETTER(Component)(BSTR *aComponent)
|
---|
110 | {
|
---|
111 | CheckComArgOutPointerValid(aComponent);
|
---|
112 |
|
---|
113 | m_strComponent.cloneTo(aComponent);
|
---|
114 | return S_OK;
|
---|
115 | }
|
---|
116 |
|
---|
117 | STDMETHODIMP VirtualBoxErrorInfo::COMGETTER(Text)(BSTR *aText)
|
---|
118 | {
|
---|
119 | CheckComArgOutPointerValid(aText);
|
---|
120 |
|
---|
121 | m_strText.cloneTo(aText);
|
---|
122 | return S_OK;
|
---|
123 | }
|
---|
124 |
|
---|
125 | STDMETHODIMP 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 | */
|
---|
139 | HRESULT 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 |
|
---|
168 | STDMETHODIMP VirtualBoxErrorInfo::GetDescription(BSTR *description)
|
---|
169 | {
|
---|
170 | return COMGETTER(Text)(description);
|
---|
171 | }
|
---|
172 |
|
---|
173 | STDMETHODIMP 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 |
|
---|
182 | STDMETHODIMP VirtualBoxErrorInfo::GetHelpContext(DWORD *pdwHelpContext)
|
---|
183 | {
|
---|
184 | RT_NOREF(pdwHelpContext);
|
---|
185 | return E_NOTIMPL;
|
---|
186 | }
|
---|
187 |
|
---|
188 | STDMETHODIMP VirtualBoxErrorInfo::GetHelpFile(BSTR *pBstrHelpFile)
|
---|
189 | {
|
---|
190 | RT_NOREF(pBstrHelpFile);
|
---|
191 | return E_NOTIMPL;
|
---|
192 | }
|
---|
193 |
|
---|
194 | STDMETHODIMP 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 | */
|
---|
205 | HRESULT 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; */
|
---|
237 | NS_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; */
|
---|
246 | NS_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; */
|
---|
259 | NS_IMETHODIMP VirtualBoxErrorInfo::GetName(char ** /* aName */)
|
---|
260 | {
|
---|
261 | return NS_ERROR_NOT_IMPLEMENTED;
|
---|
262 | }
|
---|
263 |
|
---|
264 | /* readonly attribute string filename; */
|
---|
265 | NS_IMETHODIMP VirtualBoxErrorInfo::GetFilename(char ** /* aFilename */)
|
---|
266 | {
|
---|
267 | return NS_ERROR_NOT_IMPLEMENTED;
|
---|
268 | }
|
---|
269 |
|
---|
270 | /* readonly attribute PRUint32 lineNumber; */
|
---|
271 | NS_IMETHODIMP VirtualBoxErrorInfo::GetLineNumber(PRUint32 * /* aLineNumber */)
|
---|
272 | {
|
---|
273 | return NS_ERROR_NOT_IMPLEMENTED;
|
---|
274 | }
|
---|
275 |
|
---|
276 | /* readonly attribute PRUint32 columnNumber; */
|
---|
277 | NS_IMETHODIMP VirtualBoxErrorInfo::GetColumnNumber(PRUint32 * /*aColumnNumber */)
|
---|
278 | {
|
---|
279 | return NS_ERROR_NOT_IMPLEMENTED;
|
---|
280 | }
|
---|
281 |
|
---|
282 | /* readonly attribute nsIStackFrame location; */
|
---|
283 | NS_IMETHODIMP VirtualBoxErrorInfo::GetLocation(nsIStackFrame ** /* aLocation */)
|
---|
284 | {
|
---|
285 | return NS_ERROR_NOT_IMPLEMENTED;
|
---|
286 | }
|
---|
287 |
|
---|
288 | /* readonly attribute nsIException inner; */
|
---|
289 | NS_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; */
|
---|
298 | NS_IMETHODIMP VirtualBoxErrorInfo::GetData(nsISupports ** /* aData */)
|
---|
299 | {
|
---|
300 | return NS_ERROR_NOT_IMPLEMENTED;
|
---|
301 | }
|
---|
302 |
|
---|
303 | /* string toString(); */
|
---|
304 | NS_IMETHODIMP VirtualBoxErrorInfo::ToString(char ** /* retval */)
|
---|
305 | {
|
---|
306 | return NS_ERROR_NOT_IMPLEMENTED;
|
---|
307 | }
|
---|
308 |
|
---|
309 | NS_IMPL_THREADSAFE_ISUPPORTS2(VirtualBoxErrorInfo,
|
---|
310 | nsIException, IVirtualBoxErrorInfo)
|
---|
311 |
|
---|
312 | #endif // defined(VBOX_WITH_XPCOM)
|
---|
313 | /* vi: set tabstop=4 shiftwidth=4 expandtab: */
|
---|