SupportErrorInfo.cpp revision b43b89b5cb80d216855101adf14a56dcabb5911d
/* $Id$ */
/** @file
* MS COM / XPCOM Abstraction Layer:
* SupportErrorInfo* class family implementations
*/
/*
* Copyright (C) 2008 Sun Microsystems, Inc.
*
* This file is part of VirtualBox Open Source Edition (OSE), as
* available from http://www.virtualbox.org. This file is free software;
* General Public License (GPL) as published by the Free Software
* Foundation, in version 2 as it comes in the "COPYING" file of the
* VirtualBox OSE distribution. VirtualBox OSE is distributed in the
* hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
* Clara, CA 95054 USA or visit http://www.sun.com if you need
* additional information or have any questions.
*/
#include "VBox/com/SupportErrorInfo.h"
#include "VBox/com/VirtualBoxErrorInfo.h"
#if defined (VBOX_WITH_XPCOM)
# include <nsIServiceManager.h>
# include <nsIExceptionService.h>
#endif /* defined (VBOX_WITH_XPCOM) */
namespace com
{
// MultiResult methods
////////////////////////////////////////////////////////////////////////////////
/*static*/
void MultiResult::incCounter()
{
{
sCounter = RTTlsAlloc();
}
++ counter;
}
/*static*/
void MultiResult::decCounter()
{
AssertReturnVoid (counter != 0);
-- counter;
}
// SupportErrorInfoBase methods
////////////////////////////////////////////////////////////////////////////////
/**
* Sets error info for the current thread. This is an internal function that
* gets eventually called by all public setError(), setWarning() and
* setErrorInfo() variants.
*
* The previous error info object (if any) will be preserved if the multi-error
* mode (see MultiResult) is turned on for the current thread.
*
* If @a aWarning is @c true, then the highest (31) bit in the @a aResultCode
* value which indicates the error severity is reset to zero to make sure the
* receiver will recognize that the created error info object represents a
* warning rather than an error.
*
* If @a aInfo is not NULL then all other paremeters are ignored and the given
* error info object is set on the current thread. Note that in this case, the
* existing error info object (if any) will be preserved by attaching it to the
* tail of the error chain of the given aInfo object in multi-error mode.
*
* If the error info is successfully set then this method returns aResultCode
* (or the result code returned as an output parameter of the
* aInfo->GetResultCode() call when @a aInfo is not NULL). This is done for
* conveinence: this way, setError() and friends may be used in return
* statements of COM method implementations.
*
* If setting error info fails then this method asserts and the failed result
* code is returned.
*/
/* static */
const char *aComponent, const char *aText,
{
/* whether multi-error mode is turned on */
LogRel (("ERROR [COM]: aRC=%#08x aIID={%Vuuid} aComponent={%s} aText={%s} "
"aWarning=%RTbool, aInfo=%p, preserve=%RTbool\n",
preserve));
{
/* these are mandatory, others -- not */
E_FAIL);
/* reset the error severity bit if it's a warning */
if (aWarning)
aResultCode &= ~0x80000000;
}
do
{
#if !defined (VBOX_WITH_XPCOM)
if (preserve)
{
/* get the current error info if any */
{
/* create a IVirtualBoxErrorInfo wrapper for the native
* IErrorInfo object */
{
}
}
}
/* On failure, curInfo will stay null */
/* set the current error info and preserve the previous one if any */
{
{
}
else
{
}
/* we want to return the head's result code */
}
else
{
}
#else // !defined (VBOX_WITH_XPCOM)
if (NS_SUCCEEDED (rc))
{
if (preserve)
{
/* get the current error info if any */
{
/* create a IVirtualBoxErrorInfo wrapper for the native
* nsIException object */
{
}
}
}
/* On failure, curInfo will stay null */
/* set the current error info and preserve the previous one if any */
{
{
}
else
{
}
/* we want to return the head's result code */
}
else
{
}
}
else if (rc == NS_ERROR_UNEXPECTED)
{
/*
* It is possible that setError() is being called by the object
* after the XPCOM shutdown sequence has been initiated
* (for example, when XPCOM releases all instances it internally
* references, which can cause object's FinalConstruct() and then
* uninit()). In this case, do_GetService() above will return
* NS_ERROR_UNEXPECTED and it doesn't actually make sense to
* set the exception (nobody will be able to read it).
*/
LogWarningFunc (("Will not set an exception because "
"nsIExceptionService is not available "
"(NS_ERROR_UNEXPECTED). "
"XPCOM is being shutdown?\n"));
}
#endif // !defined (VBOX_WITH_XPCOM)
}
while (0);
AssertComRC (rc);
}
/* static */
const char *aComponent, const char *aText,
...)
{
return rc;
}
/* static */
const char *aComponent, const char *aText,
...)
{
return rc;
}
{
return rc;
}
{
return rc;
}
const char *aText, ...)
{
return rc;
}
const char *aText, ...)
{
return rc;
}
} /* namespace com */