VirtualBox

Changeset 357 in vbox for trunk


Ignore:
Timestamp:
Jan 26, 2007 2:46:16 PM (18 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
17921
Message:

Main: Added VirtualBoxSupportErrorInfoImpl::setErrorBstr() and Progress::notifyCompleteBstr() to avoid an extra Utf8Str -> Bstr conversion.

Location:
trunk/src/VBox/Main
Files:
3 edited

Legend:

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

    r351 r357  
    839839                                  const char *aText, ...)
    840840{
     841    va_list args;
     842    va_start (args, aText);
     843    Bstr text = Utf8StrFmt (aText, args);
     844    va_end (args);
     845   
     846    return notifyCompleteBstr (aResultCode, aIID, aComponent, text);
     847}
     848
     849/**
     850 *  Marks the operation as complete and attaches full error info.
     851 *  See VirtualBoxSupportErrorInfoImpl::setError(HRESULT, const GUID &, const wchar_t *, const char *, ...)
     852 *  for more info.
     853 *
     854 *  This method is preferred iy you have a ready (translated and formatted)
     855 *  Bstr string, because it omits an extra conversion Utf8Str -> Bstr.
     856 *
     857 *  @param  aResultCode operation result (error) code, must not be S_OK
     858 *  @param  aIID        IID of the intrface that defines the error
     859 *  @param  aComponent  name of the component that generates the error
     860 *  @param  aText       error message (must not be null)
     861 */
     862HRESULT Progress::notifyCompleteBstr (HRESULT aResultCode, const GUID &aIID,
     863                                      const Bstr &aComponent, const Bstr &aText)
     864{
    841865    AutoLock lock (this);
    842866    AssertReturn (isReady(), E_UNEXPECTED);
     
    852876    if (SUCCEEDED (rc))
    853877    {
    854         va_list args;
    855         va_start (args, aText);
    856         Bstr bstrText = Utf8StrFmt (aText, args);
    857         va_end (args);
    858         errorInfo->init (aResultCode, aIID, aComponent, bstrText);
     878        errorInfo->init (aResultCode, aIID, aComponent, aText);
    859879        errorInfo.queryInterfaceTo (mErrorInfo.asOutParam());
    860880    }
  • trunk/src/VBox/Main/include/ProgressImpl.h

    r1 r357  
    182182                            const Bstr &aComponent,
    183183                            const char *aText, ...);
     184    HRESULT notifyCompleteBstr (HRESULT aResultCode, const GUID &aIID,
     185                                const Bstr &aComponent, const Bstr &aText);
    184186
    185187private:
  • trunk/src/VBox/Main/include/VirtualBoxBase.h

    r1 r357  
    12141214     *
    12151215     *  See #setError (HRESULT, const GUID &, const wchar_t *, const char *text, ...)
    1216      *  for details.
    1217      *
    1218      *  This method is the most common (and convenient) way  to set error
    1219      *  information from within interface methods. A typical pattern of usage
    1220      *  is looks like this:
    1221      *
    1222      *  <code>
    1223      *      return setErrorV (E_FAIL, pszFormat, args);
    1224      *  </code>
    1225      *  or
    1226      *  <code>
    1227      *      HRESULT rc = setErrorV (E_FAIL, pszFormat, args);
    1228      *      ...
    1229      *      return rc;
    1230      *  </code>
     1216     *  and #setError (HRESULT, const char *, ...)  for details.
    12311217     */
    12321218    inline static HRESULT setErrorV (HRESULT resultCode, const char *text, va_list args)
     
    12341220        HRESULT rc = VirtualBoxSupportErrorInfoImplBase::setError (
    12351221            resultCode, COM_IIDOF(I), C::getComponentName(), text, args);
     1222        return rc;
     1223    }
     1224
     1225    /**
     1226     *  Sets the error information for the current thread, BStr variant.
     1227     *  A convenience method that automatically sets the default interface
     1228     *  ID (taken from the I template argument) and the component name
     1229     *  (a value of C::getComponentName()).
     1230     *
     1231     *  This method is preferred iy you have a ready (translated and formatted)
     1232     *  Bstr string, because it omits an extra conversion Utf8Str -> Bstr.
     1233     *
     1234     *  See #setError (HRESULT, const GUID &, const wchar_t *, const char *text, ...)
     1235     *  and #setError (HRESULT, const char *, ...)  for details.
     1236     */
     1237    inline static HRESULT setErrorBstr (HRESULT resultCode, const Bstr &text)
     1238    {
     1239        HRESULT rc = VirtualBoxSupportErrorInfoImplBase::setError (
     1240            resultCode, COM_IIDOF(I), C::getComponentName(), text);
    12361241        return rc;
    12371242    }
Note: See TracChangeset for help on using the changeset viewer.

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