VirtualBox

source: vbox/trunk/src/VBox/Main/VirtualBoxErrorInfoImpl.cpp@ 33238

Last change on this file since 33238 was 32780, checked in by vboxsync, 14 years ago

com/Guid: remove conversion operators to eliminate any compiler surprises. Caught one totally unexpected issue which was indirectly caused by the similar Bstr cleanup, as there still is a Bstr->Guid conversion and thus the Guid magic was triggered

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 6.7 KB
Line 
1/** @file
2 *
3 * VirtualBoxErrorInfo COM classe implementation
4 */
5
6/*
7 * Copyright (C) 2006-2010 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// public initializer/uninitializer for internal purposes only
22////////////////////////////////////////////////////////////////////////////////
23
24HRESULT VirtualBoxErrorInfo::init(HRESULT aResultCode,
25 const GUID &aIID,
26 const char *pcszComponent,
27 const Utf8Str &strText,
28 IVirtualBoxErrorInfo *aNext)
29{
30 m_resultCode = aResultCode;
31 m_IID = aIID;
32 m_strComponent = pcszComponent;
33 m_strText = strText;
34 mNext = aNext;
35
36 return S_OK;
37}
38
39// IVirtualBoxErrorInfo properties
40////////////////////////////////////////////////////////////////////////////////
41
42STDMETHODIMP VirtualBoxErrorInfo::COMGETTER(ResultCode) (LONG *aResultCode)
43{
44 CheckComArgOutPointerValid(aResultCode);
45
46 *aResultCode = m_resultCode;
47 return S_OK;
48}
49
50STDMETHODIMP VirtualBoxErrorInfo::COMGETTER(InterfaceID) (BSTR *aIID)
51{
52 CheckComArgOutPointerValid(aIID);
53
54 m_IID.toUtf16().cloneTo(aIID);
55 return S_OK;
56}
57
58STDMETHODIMP VirtualBoxErrorInfo::COMGETTER(Component) (BSTR *aComponent)
59{
60 CheckComArgOutPointerValid(aComponent);
61
62 m_strComponent.cloneTo(aComponent);
63 return S_OK;
64}
65
66STDMETHODIMP VirtualBoxErrorInfo::COMGETTER(Text) (BSTR *aText)
67{
68 CheckComArgOutPointerValid(aText);
69
70 m_strText.cloneTo(aText);
71 return S_OK;
72}
73
74STDMETHODIMP VirtualBoxErrorInfo::COMGETTER(Next) (IVirtualBoxErrorInfo **aNext)
75{
76 CheckComArgOutPointerValid(aNext);
77
78 /* this will set aNext to NULL if mNext is null */
79 return mNext.queryInterfaceTo(aNext);
80}
81
82#if !defined(VBOX_WITH_XPCOM)
83
84/**
85 * Initializes itself by fetching error information from the given error info
86 * object.
87 */
88HRESULT VirtualBoxErrorInfo::init (IErrorInfo *aInfo)
89{
90 AssertReturn(aInfo, E_FAIL);
91
92 HRESULT rc = S_OK;
93
94 /* We don't return a failure if talking to IErrorInfo fails below to
95 * protect ourselves from bad IErrorInfo implementations (the
96 * corresponding fields will simply remain null in this case). */
97
98 m_resultCode = S_OK;
99 rc = aInfo->GetGUID(m_IID.asOutParam());
100 AssertComRC (rc);
101 Bstr bstrComponent;
102 rc = aInfo->GetSource(bstrComponent.asOutParam());
103 AssertComRC (rc);
104 m_strComponent = bstrComponent;
105 Bstr bstrText;
106 rc = aInfo->GetDescription(bstrText.asOutParam());
107 AssertComRC (rc);
108 m_strText = bstrText;
109
110 return S_OK;
111}
112
113// IErrorInfo methods
114////////////////////////////////////////////////////////////////////////////////
115
116STDMETHODIMP VirtualBoxErrorInfo::GetDescription (BSTR *description)
117{
118 return COMGETTER(Text) (description);
119}
120
121STDMETHODIMP VirtualBoxErrorInfo::GetGUID (GUID *guid)
122{
123 Bstr iid;
124 HRESULT rc = COMGETTER(InterfaceID) (iid.asOutParam());
125 if (SUCCEEDED(rc))
126 *guid = Guid(iid).ref();
127 return rc;
128}
129
130STDMETHODIMP VirtualBoxErrorInfo::GetHelpContext (DWORD *pdwHelpContext)
131{
132 return E_NOTIMPL;
133}
134
135STDMETHODIMP VirtualBoxErrorInfo::GetHelpFile (BSTR *pbstrHelpFile)
136{
137 return E_NOTIMPL;
138}
139
140STDMETHODIMP VirtualBoxErrorInfo::GetSource (BSTR *source)
141{
142 return COMGETTER(Component) (source);
143}
144
145#else // defined(VBOX_WITH_XPCOM)
146
147/**
148 * Initializes itself by fetching error information from the given error info
149 * object.
150 */
151HRESULT VirtualBoxErrorInfo::init(nsIException *aInfo)
152{
153 AssertReturn(aInfo, E_FAIL);
154
155 HRESULT rc = S_OK;
156
157 /* We don't return a failure if talking to nsIException fails below to
158 * protect ourselves from bad nsIException implementations (the
159 * corresponding fields will simply remain null in this case). */
160
161 rc = aInfo->GetResult(&m_resultCode);
162 AssertComRC(rc);
163
164 char *pszMsg; /* No Utf8Str.asOutParam, different allocator! */
165 rc = aInfo->GetMessage(&pszMsg);
166 AssertComRC(rc);
167 if (NS_SUCCEEDED(rc))
168 {
169 m_strText = pszMsg;
170 nsMemory::Free(pszMsg);
171 }
172 else
173 m_strText.setNull();
174
175 return S_OK;
176}
177
178// nsIException methods
179////////////////////////////////////////////////////////////////////////////////
180
181/* readonly attribute string message; */
182NS_IMETHODIMP VirtualBoxErrorInfo::GetMessage (char **aMessage)
183{
184 CheckComArgOutPointerValid(aMessage);
185
186 m_strText.cloneTo(aMessage);
187 return S_OK;
188}
189
190/* readonly attribute nsresult result; */
191NS_IMETHODIMP VirtualBoxErrorInfo::GetResult (nsresult *aResult)
192{
193 if (!aResult)
194 return NS_ERROR_INVALID_POINTER;
195
196 PRInt32 lrc;
197 nsresult rc = COMGETTER(ResultCode) (&lrc);
198 if (SUCCEEDED(rc))
199 *aResult = lrc;
200 return rc;
201}
202
203/* readonly attribute string name; */
204NS_IMETHODIMP VirtualBoxErrorInfo::GetName (char ** /* aName */)
205{
206 return NS_ERROR_NOT_IMPLEMENTED;
207}
208
209/* readonly attribute string filename; */
210NS_IMETHODIMP VirtualBoxErrorInfo::GetFilename (char ** /* aFilename */)
211{
212 return NS_ERROR_NOT_IMPLEMENTED;
213}
214
215/* readonly attribute PRUint32 lineNumber; */
216NS_IMETHODIMP VirtualBoxErrorInfo::GetLineNumber (PRUint32 * /* aLineNumber */)
217{
218 return NS_ERROR_NOT_IMPLEMENTED;
219}
220
221/* readonly attribute PRUint32 columnNumber; */
222NS_IMETHODIMP VirtualBoxErrorInfo::GetColumnNumber (PRUint32 * /*aColumnNumber */)
223{
224 return NS_ERROR_NOT_IMPLEMENTED;
225}
226
227/* readonly attribute nsIStackFrame location; */
228NS_IMETHODIMP VirtualBoxErrorInfo::GetLocation (nsIStackFrame ** /* aLocation */)
229{
230 return NS_ERROR_NOT_IMPLEMENTED;
231}
232
233/* readonly attribute nsIException inner; */
234NS_IMETHODIMP VirtualBoxErrorInfo::GetInner (nsIException **aInner)
235{
236 ComPtr<IVirtualBoxErrorInfo> info;
237 nsresult rv = COMGETTER(Next) (info.asOutParam());
238 if (FAILED(rv)) return rv;
239 return info.queryInterfaceTo(aInner);
240}
241
242/* readonly attribute nsISupports data; */
243NS_IMETHODIMP VirtualBoxErrorInfo::GetData (nsISupports ** /* aData */)
244{
245 return NS_ERROR_NOT_IMPLEMENTED;
246}
247
248/* string toString (); */
249NS_IMETHODIMP VirtualBoxErrorInfo::ToString (char ** /* retval */)
250{
251 return NS_ERROR_NOT_IMPLEMENTED;
252}
253
254NS_IMPL_THREADSAFE_ISUPPORTS2 (VirtualBoxErrorInfo,
255 nsIException, IVirtualBoxErrorInfo)
256
257#endif // defined(VBOX_WITH_XPCOM)
258/* 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