VirtualBoxErrorInfoImpl.cpp revision e07acfb7f2dbb8bb40804024c79fd3139bdb3f24
887dfcedd826364b6159847dbd25800c0eeede4avboxsync/** @file
887dfcedd826364b6159847dbd25800c0eeede4avboxsync *
887dfcedd826364b6159847dbd25800c0eeede4avboxsync * VirtualBoxErrorInfo COM classe implementation
887dfcedd826364b6159847dbd25800c0eeede4avboxsync */
887dfcedd826364b6159847dbd25800c0eeede4avboxsync
887dfcedd826364b6159847dbd25800c0eeede4avboxsync/*
29b69a4bd6aaf319dd7b525994002eddc22de841vboxsync * Copyright (C) 2006-2009 Oracle Corporation
887dfcedd826364b6159847dbd25800c0eeede4avboxsync *
1c94c0a63ba68be1a7b2c640e70d7a06464e4fcavboxsync * This file is part of VirtualBox Open Source Edition (OSE), as
1c94c0a63ba68be1a7b2c640e70d7a06464e4fcavboxsync * available from http://www.virtualbox.org. This file is free software;
1c94c0a63ba68be1a7b2c640e70d7a06464e4fcavboxsync * you can redistribute it and/or modify it under the terms of the GNU
1c94c0a63ba68be1a7b2c640e70d7a06464e4fcavboxsync * General Public License (GPL) as published by the Free Software
1c94c0a63ba68be1a7b2c640e70d7a06464e4fcavboxsync * Foundation, in version 2 as it comes in the "COPYING" file of the
1c94c0a63ba68be1a7b2c640e70d7a06464e4fcavboxsync * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
1c94c0a63ba68be1a7b2c640e70d7a06464e4fcavboxsync * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
887dfcedd826364b6159847dbd25800c0eeede4avboxsync */
887dfcedd826364b6159847dbd25800c0eeede4avboxsync
887dfcedd826364b6159847dbd25800c0eeede4avboxsync#include "VirtualBoxErrorInfoImpl.h"
887dfcedd826364b6159847dbd25800c0eeede4avboxsync#include "Logging.h"
887dfcedd826364b6159847dbd25800c0eeede4avboxsync
a5095136db25095b1bebc90f76da25cbd4cdefebvboxsync// public initializer/uninitializer for internal purposes only
887dfcedd826364b6159847dbd25800c0eeede4avboxsync////////////////////////////////////////////////////////////////////////////////
887dfcedd826364b6159847dbd25800c0eeede4avboxsync
887dfcedd826364b6159847dbd25800c0eeede4avboxsyncHRESULT VirtualBoxErrorInfo::init(HRESULT aResultCode,
887dfcedd826364b6159847dbd25800c0eeede4avboxsync const GUID &aIID,
887dfcedd826364b6159847dbd25800c0eeede4avboxsync const char *pcszComponent,
887dfcedd826364b6159847dbd25800c0eeede4avboxsync const Utf8Str &strText,
887dfcedd826364b6159847dbd25800c0eeede4avboxsync IVirtualBoxErrorInfo *aNext)
887dfcedd826364b6159847dbd25800c0eeede4avboxsync{
887dfcedd826364b6159847dbd25800c0eeede4avboxsync m_resultCode = aResultCode;
887dfcedd826364b6159847dbd25800c0eeede4avboxsync m_IID = aIID;
887dfcedd826364b6159847dbd25800c0eeede4avboxsync m_strComponent = pcszComponent;
887dfcedd826364b6159847dbd25800c0eeede4avboxsync m_strText = strText;
887dfcedd826364b6159847dbd25800c0eeede4avboxsync mNext = aNext;
887dfcedd826364b6159847dbd25800c0eeede4avboxsync
887dfcedd826364b6159847dbd25800c0eeede4avboxsync return S_OK;
29b69a4bd6aaf319dd7b525994002eddc22de841vboxsync}
887dfcedd826364b6159847dbd25800c0eeede4avboxsync
887dfcedd826364b6159847dbd25800c0eeede4avboxsync// IVirtualBoxErrorInfo properties
887dfcedd826364b6159847dbd25800c0eeede4avboxsync////////////////////////////////////////////////////////////////////////////////
887dfcedd826364b6159847dbd25800c0eeede4avboxsync
e465512ca00838f2eee92814ee935296396cd2d3vboxsyncSTDMETHODIMP VirtualBoxErrorInfo::COMGETTER(ResultCode) (LONG *aResultCode)
e465512ca00838f2eee92814ee935296396cd2d3vboxsync{
e465512ca00838f2eee92814ee935296396cd2d3vboxsync CheckComArgOutPointerValid(aResultCode);
e465512ca00838f2eee92814ee935296396cd2d3vboxsync
e465512ca00838f2eee92814ee935296396cd2d3vboxsync *aResultCode = m_resultCode;
e465512ca00838f2eee92814ee935296396cd2d3vboxsync return S_OK;
e465512ca00838f2eee92814ee935296396cd2d3vboxsync}
e465512ca00838f2eee92814ee935296396cd2d3vboxsync
e465512ca00838f2eee92814ee935296396cd2d3vboxsyncSTDMETHODIMP VirtualBoxErrorInfo::COMGETTER(InterfaceID) (BSTR *aIID)
e465512ca00838f2eee92814ee935296396cd2d3vboxsync{
887dfcedd826364b6159847dbd25800c0eeede4avboxsync CheckComArgOutPointerValid(aIID);
887dfcedd826364b6159847dbd25800c0eeede4avboxsync
887dfcedd826364b6159847dbd25800c0eeede4avboxsync m_IID.toUtf16().cloneTo(aIID);
887dfcedd826364b6159847dbd25800c0eeede4avboxsync return S_OK;
e465512ca00838f2eee92814ee935296396cd2d3vboxsync}
e465512ca00838f2eee92814ee935296396cd2d3vboxsync
e465512ca00838f2eee92814ee935296396cd2d3vboxsyncSTDMETHODIMP VirtualBoxErrorInfo::COMGETTER(Component) (BSTR *aComponent)
e465512ca00838f2eee92814ee935296396cd2d3vboxsync{
e465512ca00838f2eee92814ee935296396cd2d3vboxsync CheckComArgOutPointerValid(aComponent);
e465512ca00838f2eee92814ee935296396cd2d3vboxsync
887dfcedd826364b6159847dbd25800c0eeede4avboxsync m_strComponent.cloneTo(aComponent);
887dfcedd826364b6159847dbd25800c0eeede4avboxsync return S_OK;
887dfcedd826364b6159847dbd25800c0eeede4avboxsync}
e465512ca00838f2eee92814ee935296396cd2d3vboxsync
e465512ca00838f2eee92814ee935296396cd2d3vboxsyncSTDMETHODIMP VirtualBoxErrorInfo::COMGETTER(Text) (BSTR *aText)
887dfcedd826364b6159847dbd25800c0eeede4avboxsync{
887dfcedd826364b6159847dbd25800c0eeede4avboxsync CheckComArgOutPointerValid(aText);
887dfcedd826364b6159847dbd25800c0eeede4avboxsync
887dfcedd826364b6159847dbd25800c0eeede4avboxsync m_strText.cloneTo(aText);
e465512ca00838f2eee92814ee935296396cd2d3vboxsync return S_OK;
887dfcedd826364b6159847dbd25800c0eeede4avboxsync}
887dfcedd826364b6159847dbd25800c0eeede4avboxsync
887dfcedd826364b6159847dbd25800c0eeede4avboxsyncSTDMETHODIMP VirtualBoxErrorInfo::COMGETTER(Next) (IVirtualBoxErrorInfo **aNext)
887dfcedd826364b6159847dbd25800c0eeede4avboxsync{
e465512ca00838f2eee92814ee935296396cd2d3vboxsync CheckComArgOutPointerValid(aNext);
e465512ca00838f2eee92814ee935296396cd2d3vboxsync
e465512ca00838f2eee92814ee935296396cd2d3vboxsync /* this will set aNext to NULL if mNext is null */
e465512ca00838f2eee92814ee935296396cd2d3vboxsync return mNext.queryInterfaceTo(aNext);
887dfcedd826364b6159847dbd25800c0eeede4avboxsync}
e465512ca00838f2eee92814ee935296396cd2d3vboxsync
887dfcedd826364b6159847dbd25800c0eeede4avboxsync#if !defined(VBOX_WITH_XPCOM)
887dfcedd826364b6159847dbd25800c0eeede4avboxsync
887dfcedd826364b6159847dbd25800c0eeede4avboxsync/**
887dfcedd826364b6159847dbd25800c0eeede4avboxsync * Initializes itself by fetching error information from the given error info
e465512ca00838f2eee92814ee935296396cd2d3vboxsync * object.
887dfcedd826364b6159847dbd25800c0eeede4avboxsync */
887dfcedd826364b6159847dbd25800c0eeede4avboxsyncHRESULT VirtualBoxErrorInfo::init (IErrorInfo *aInfo)
a5095136db25095b1bebc90f76da25cbd4cdefebvboxsync{
887dfcedd826364b6159847dbd25800c0eeede4avboxsync AssertReturn(aInfo, E_FAIL);
887dfcedd826364b6159847dbd25800c0eeede4avboxsync
887dfcedd826364b6159847dbd25800c0eeede4avboxsync HRESULT rc = S_OK;
/* We don't return a failure if talking to IErrorInfo fails below to
* protect ourselves from bad IErrorInfo implementations (the
* corresponding fields will simply remain null in this case). */
m_resultCode = S_OK;
rc = aInfo->GetGUID(m_IID.asOutParam());
AssertComRC (rc);
Bstr bstrComponent;
rc = aInfo->GetSource(bstrComponent.asOutParam());
AssertComRC (rc);
m_strComponent = bstrComponent;
Bstr bstrText;
rc = aInfo->GetDescription(bstrText.asOutParam());
AssertComRC (rc);
m_strText = bstrText;
return S_OK;
}
// IErrorInfo methods
////////////////////////////////////////////////////////////////////////////////
STDMETHODIMP VirtualBoxErrorInfo::GetDescription (BSTR *description)
{
return COMGETTER(Text) (description);
}
STDMETHODIMP VirtualBoxErrorInfo::GetGUID (GUID *guid)
{
Bstr iid;
HRESULT rc = COMGETTER(InterfaceID) (iid.asOutParam());
if (SUCCEEDED(rc))
*guid = Guid(iid);
return rc;
}
STDMETHODIMP VirtualBoxErrorInfo::GetHelpContext (DWORD *pdwHelpContext)
{
return E_NOTIMPL;
}
STDMETHODIMP VirtualBoxErrorInfo::GetHelpFile (BSTR *pbstrHelpFile)
{
return E_NOTIMPL;
}
STDMETHODIMP VirtualBoxErrorInfo::GetSource (BSTR *source)
{
return COMGETTER(Component) (source);
}
#else // defined(VBOX_WITH_XPCOM)
/**
* Initializes itself by fetching error information from the given error info
* object.
*/
HRESULT VirtualBoxErrorInfo::init(nsIException *aInfo)
{
AssertReturn(aInfo, E_FAIL);
HRESULT rc = S_OK;
/* We don't return a failure if talking to nsIException fails below to
* protect ourselves from bad nsIException implementations (the
* corresponding fields will simply remain null in this case). */
rc = aInfo->GetResult(&m_resultCode);
AssertComRC(rc);
char *pszMsg; /* No Utf8Str.asOutParam, different allocator! */
rc = aInfo->GetMessage(&pszMsg);
AssertComRC(rc);
if (NS_SUCCEEDED(rc))
{
m_strText = pszMsg;
nsMemory::Free(pszMsg);
}
else
m_strText.setNull();
return S_OK;
}
// nsIException methods
////////////////////////////////////////////////////////////////////////////////
/* readonly attribute string message; */
NS_IMETHODIMP VirtualBoxErrorInfo::GetMessage (char **aMessage)
{
CheckComArgOutPointerValid(aMessage);
m_strText.cloneTo(aMessage);
return S_OK;
}
/* readonly attribute nsresult result; */
NS_IMETHODIMP VirtualBoxErrorInfo::GetResult (nsresult *aResult)
{
if (!aResult)
return NS_ERROR_INVALID_POINTER;
PRInt32 lrc;
nsresult rc = COMGETTER(ResultCode) (&lrc);
if (SUCCEEDED(rc))
*aResult = lrc;
return rc;
}
/* readonly attribute string name; */
NS_IMETHODIMP VirtualBoxErrorInfo::GetName (char ** /* aName */)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
/* readonly attribute string filename; */
NS_IMETHODIMP VirtualBoxErrorInfo::GetFilename (char ** /* aFilename */)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
/* readonly attribute PRUint32 lineNumber; */
NS_IMETHODIMP VirtualBoxErrorInfo::GetLineNumber (PRUint32 * /* aLineNumber */)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
/* readonly attribute PRUint32 columnNumber; */
NS_IMETHODIMP VirtualBoxErrorInfo::GetColumnNumber (PRUint32 * /*aColumnNumber */)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
/* readonly attribute nsIStackFrame location; */
NS_IMETHODIMP VirtualBoxErrorInfo::GetLocation (nsIStackFrame ** /* aLocation */)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
/* readonly attribute nsIException inner; */
NS_IMETHODIMP VirtualBoxErrorInfo::GetInner (nsIException **aInner)
{
ComPtr<IVirtualBoxErrorInfo> info;
nsresult rv = COMGETTER(Next) (info.asOutParam());
if (FAILED(rv)) return rv;
return info.queryInterfaceTo(aInner);
}
/* readonly attribute nsISupports data; */
NS_IMETHODIMP VirtualBoxErrorInfo::GetData (nsISupports ** /* aData */)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
/* string toString (); */
NS_IMETHODIMP VirtualBoxErrorInfo::ToString (char ** /* retval */)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMPL_THREADSAFE_ISUPPORTS2 (VirtualBoxErrorInfo,
nsIException, IVirtualBoxErrorInfo)
#endif // defined(VBOX_WITH_XPCOM)
/* vi: set tabstop=4 shiftwidth=4 expandtab: */