VirtualBox

Ignore:
Timestamp:
May 16, 2007 3:31:49 PM (18 years ago)
Author:
vboxsync
Message:

Main: Ported latest dmik/exp branch changes (r21219:21226) into the trunk.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Main/VirtualBoxBase.cpp

    r1 r2672  
    641641////////////////////////////////////////////////////////////////////////////////
    642642
     643/**
     644 *  Sets error info for the current thread. This is an internal function that
     645 *  gets eventually called by all public variants.  If @a aPreserve is
     646 *  @c true, then the current error info object set on the thread before this
     647 *  method is called will be preserved in the IVirtualBoxErrorInfo::next
     648 *  attribute of the new error info object that will be then set as the
     649 *  current error info object.
     650 */
    643651// static
    644 HRESULT VirtualBoxSupportErrorInfoImplBase::setError (
    645     HRESULT resultCode, const GUID &iid,
    646     const Bstr &component,
    647     const Bstr &text)
    648 {
    649     LogRel (("ERROR [COM]: rc=%#08x IID={%Vuuid} component={%ls} text={%ls}\n",
    650               resultCode, &iid, component.raw(), text.raw()));
     652HRESULT VirtualBoxSupportErrorInfoImplBase::setErrorInternal (
     653    HRESULT aResultCode, const GUID &aIID,
     654    const Bstr &aComponent, const Bstr &aText,
     655    bool aPreserve)
     656{
     657    LogRel (("ERROR [COM]: aRC=%#08x aIID={%Vuuid} aComponent={%ls} aText={%ls} "
     658             "aPreserve=%RTbool\n",
     659             aResultCode, &aIID, aComponent.raw(), aText.raw(), aPreserve));
    651660
    652661    /* these are mandatory, others -- not */
    653     Assert (FAILED (resultCode));
    654     Assert (!text.isEmpty());
    655     if (SUCCEEDED (resultCode) || text.isEmpty())
    656         return E_FAIL;
    657 
    658     ComObjPtr <VirtualBoxErrorInfo> info;
    659     HRESULT rc = info.createObject();
    660     if (SUCCEEDED (rc))
    661     {
    662         info->init (resultCode, iid, component, text);
     662    AssertReturn (FAILED (aResultCode), E_FAIL);
     663    AssertReturn (!aText.isEmpty(), E_FAIL);
     664
     665    HRESULT rc = S_OK;
     666
     667    do
     668    {
     669        ComObjPtr <VirtualBoxErrorInfo> info;
     670        rc = info.createObject();
     671        CheckComRCBreakRC (rc);
    663672
    664673#if defined (__WIN__)
     674
     675        ComPtr <IVirtualBoxErrorInfo> curInfo;
     676        if (aPreserve)
     677        {
     678            /* get the current error info if any */
     679            ComPtr <IErrorInfo> err;
     680            rc = ::GetErrorInfo (0, err.asOutParam());
     681            CheckComRCBreakRC (rc);
     682            rc = err.queryInterfaceTo (curInfo.asOutParam());
     683            if (FAILED (rc))
     684            {
     685                /* create a IVirtualBoxErrorInfo wrapper for the native
     686                 * IErrorInfo object */
     687                ComObjPtr <VirtualBoxErrorInfo> wrapper;
     688                rc = wrapper.createObject();
     689                if (SUCCEEDED (rc))
     690                {
     691                    rc = wrapper->init (err);
     692                    if (SUCCEEDED (rc))
     693                        curInfo = wrapper;
     694                }
     695            }
     696        }
     697        /* On failure, curInfo will stay null */
     698        Assert (SUCCEEDED (rc) || curInfo.isNull());
     699
     700        /* set the current error info and preserve the previous one if any */
     701        rc = info->init (aResultCode, aIID, aComponent, aText, curInfo);
     702        CheckComRCBreakRC (rc);
    665703
    666704        ComPtr <IErrorInfo> err;
     
    677715            nsCOMPtr <nsIExceptionManager> em;
    678716            rc = es->GetCurrentExceptionManager (getter_AddRefs (em));
    679             if (NS_SUCCEEDED (rc))
     717            CheckComRCBreakRC (rc);
     718
     719            ComPtr <IVirtualBoxErrorInfo> curInfo;
     720            if (aPreserve)
    680721            {
     722                /* get the current error info if any */
    681723                ComPtr <nsIException> ex;
    682                 rc = info.queryInterfaceTo (ex.asOutParam());
    683                 if (SUCCEEDED (rc))
    684                     rc = em->SetCurrentException (ex);
     724                rc = em->GetCurrentException (ex.asOutParam());
     725                CheckComRCBreakRC (rc);
     726                rc = ex.queryInterfaceTo (curInfo.asOutParam());
     727                if (FAILED (rc))
     728                {
     729                    /* create a IVirtualBoxErrorInfo wrapper for the native
     730                     * nsIException object */
     731                    ComObjPtr <VirtualBoxErrorInfo> wrapper;
     732                    rc = wrapper.createObject();
     733                    if (SUCCEEDED (rc))
     734                    {
     735                        rc = wrapper->init (ex);
     736                        if (SUCCEEDED (rc))
     737                            curInfo = wrapper;
     738                    }
     739                }
    685740            }
     741            /* On failure, curInfo will stay null */
     742            Assert (SUCCEEDED (rc) || curInfo.isNull());
     743
     744            /* set the current error info and preserve the previous one if any */
     745            rc = info->init (aResultCode, aIID, aComponent, aText, curInfo);
     746            CheckComRCBreakRC (rc);
     747
     748            ComPtr <nsIException> ex;
     749            rc = info.queryInterfaceTo (ex.asOutParam());
     750            if (SUCCEEDED (rc))
     751                rc = em->SetCurrentException (ex);
    686752        }
    687753        else if (rc == NS_ERROR_UNEXPECTED)
     
    705771#endif // !defined (__WIN__)
    706772    }
     773    while (0);
    707774
    708775    AssertComRC (rc);
    709776
    710     return SUCCEEDED (rc) ? resultCode : rc;
    711 }
    712 
    713 // static
    714 HRESULT VirtualBoxSupportErrorInfoImplBase::setError (
    715     HRESULT resultCode, const GUID &iid,
    716     const Bstr &component,
    717     const char *text, va_list args)
    718 {
    719     return VirtualBoxSupportErrorInfoImplBase::setError (
    720         resultCode, iid, component, Utf8StrFmt (text, args));
     777    return SUCCEEDED (rc) ? aResultCode : rc;
    721778}
    722779
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette