VirtualBox

Changeset 30681 in vbox for trunk/include/VBox/com


Ignore:
Timestamp:
Jul 6, 2010 5:20:20 PM (15 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
63442
Message:

Main: COM header cleanup (remove obscure and unused templates), second try

Location:
trunk/include/VBox/com
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/include/VBox/com/ErrorInfo.h

    r30676 r30681  
    3232#include "VBox/com/Guid.h"
    3333#include "VBox/com/assert.h"
    34 
    35 #include <iprt/memory> // for auto_copy_ptr
    3634
    3735struct IProgress;
     
    109107     */
    110108    explicit ErrorInfo()
    111         : mIsBasicAvailable (false), mIsFullAvailable (false)
    112         , mResultCode (S_OK)
    113         { init(); }
    114 
    115     /**
    116      *  Constructs a new, "interfaceless" ErrorInfo instance that takes
    117      *  the error information possibly set on the current thread by an
    118      *  interface method of the given interface pointer.
    119 
    120      *  If the given interface does not support providing error information or,
    121      *  for some reason didn't set any error information, both
    122      *  #isFullAvailable() and #isBasicAvailable() will return |false|.
    123      *
    124      *  @param aPtr pointer to the interface whose method returned an
    125      *              error
    126      */
    127     template <class I> ErrorInfo (I *aPtr)
    128         : mIsBasicAvailable (false), mIsFullAvailable (false)
    129         , mResultCode (S_OK)
    130         { init (aPtr, COM_IIDOF(I)); }
    131 
    132     /**
    133      *  Constructs a new ErrorInfo instance from the smart interface pointer.
    134      *  See template <class I> ErrorInfo (I *aPtr) for details
    135      *
    136      *  @param aPtr smart pointer to the interface whose method returned
    137      *              an error
    138      */
    139     template <class I> ErrorInfo (const ComPtr <I> &aPtr)
    140         : mIsBasicAvailable (false), mIsFullAvailable (false)
    141         , mResultCode (S_OK)
    142         { init (static_cast <I*> (aPtr), COM_IIDOF(I)); }
    143 
    144     /** Specialization for the IVirtualBoxErrorInfo smart pointer */
    145     ErrorInfo (const ComPtr <IVirtualBoxErrorInfo> &aPtr)
    146         : mIsBasicAvailable (false), mIsFullAvailable (false)
    147         , mResultCode (S_OK)
    148         { init (aPtr); }
    149 
    150     /**
    151      *  Constructs a new ErrorInfo instance from the IVirtualBoxErrorInfo
    152      *  interface pointer. If this pointer is not NULL, both #isFullAvailable()
    153      *  and #isBasicAvailable() will return |true|.
    154      *
    155      *  @param aInfo    pointer to the IVirtualBoxErrorInfo interface that
    156      *                  holds error info to be fetched by this instance
    157      */
    158     ErrorInfo (IVirtualBoxErrorInfo *aInfo)
    159         : mIsBasicAvailable (false), mIsFullAvailable (false)
    160         , mResultCode (S_OK)
    161         { init (aInfo); }
     109        : mIsBasicAvailable(false),
     110          mIsFullAvailable(false),
     111          mResultCode(S_OK),
     112          m_pNext(NULL)
     113    {
     114        init();
     115    }
     116
     117    ErrorInfo(IUnknown *pObj, const GUID &aIID)
     118        : mIsBasicAvailable(false),
     119          mIsFullAvailable(false),
     120          mResultCode(S_OK),
     121          m_pNext(NULL)
     122    {
     123        init(pObj, aIID);
     124    }
    162125
    163126    virtual ~ErrorInfo();
     
    175138     *  this method returns true (otherwise they simply return NULL-like values).
    176139     */
    177     bool isBasicAvailable() const { return mIsBasicAvailable; }
     140    bool isBasicAvailable() const
     141    {
     142        return mIsBasicAvailable;
     143    }
    178144
    179145    /**
     
    189155     *  this method returns true (otherwise they simply return NULL-like values).
    190156     */
    191     bool isFullAvailable() const { return mIsFullAvailable; }
    192 
    193     /**
    194      *  Returns @c true if both isBasicAvailable() and isFullAvailable() are
    195      *  @c false.
    196      */
    197     bool isNull() const { return !mIsBasicAvailable && !mIsFullAvailable; }
     157    bool isFullAvailable() const
     158    {
     159        return mIsFullAvailable;
     160    }
    198161
    199162    /**
    200163     *  Returns the COM result code of the failed operation.
    201164     */
    202     HRESULT getResultCode() const { return mResultCode; }
     165    HRESULT getResultCode() const
     166    {
     167        return mResultCode;
     168    }
    203169
    204170    /**
    205171     *  Returns the IID of the interface that defined the error.
    206172     */
    207     const Guid &getInterfaceID() const { return mInterfaceID; }
     173    const Guid& getInterfaceID() const
     174    {
     175        return mInterfaceID;
     176    }
    208177
    209178    /**
    210179     *  Returns the name of the component that generated the error.
    211180     */
    212     const Bstr &getComponent() const { return mComponent; }
     181    const Bstr& getComponent() const
     182    {
     183        return mComponent;
     184    }
    213185
    214186    /**
    215187     *  Returns the textual description of the error.
    216188     */
    217     const Bstr &getText() const { return mText; }
     189    const Bstr& getText() const
     190    {
     191        return mText;
     192    }
    218193
    219194    /**
    220195     *  Returns the next error information object or @c NULL if there is none.
    221196     */
    222     const ErrorInfo *getNext() const { return mNext.get(); }
     197    const ErrorInfo* getNext() const
     198    {
     199        return m_pNext;
     200    }
    223201
    224202    /**
    225203     *  Returns the name of the interface that defined the error
    226204     */
    227     const Bstr &getInterfaceName() const { return mInterfaceName; }
     205    const Bstr& getInterfaceName() const
     206    {
     207        return mInterfaceName;
     208    }
    228209
    229210    /**
     
    234215     *  template <class I> ErrorInfo (const ComPtr <I> &i) constructor.
    235216     */
    236     const Guid &getCalleeIID() const { return mCalleeIID; }
     217    const Guid& getCalleeIID() const
     218    {
     219        return mCalleeIID;
     220    }
    237221
    238222    /**
     
    243227     *  template <class I> ErrorInfo (const ComPtr <I> &i) constructor.
    244228     */
    245     const Bstr &getCalleeName() const { return mCalleeName; }
     229    const Bstr& getCalleeName() const
     230    {
     231        return mCalleeName;
     232    }
    246233
    247234    /**
     
    253240        mIsBasicAvailable = false;
    254241        mIsFullAvailable = false;
     242
     243        if (m_pNext)
     244        {
     245            delete m_pNext;
     246            m_pNext = NULL;
     247        }
    255248
    256249        mResultCode = S_OK;
     
    258251        mComponent.setNull();
    259252        mText.setNull();
    260         mNext.reset();
    261253        mInterfaceName.setNull();
    262254        mCalleeIID.clear();
     
    267259protected:
    268260
    269     ErrorInfo (bool /* aDummy */)
    270         : mIsBasicAvailable (false), mIsFullAvailable (false)
    271         , mResultCode (S_OK)
    272         {}
    273 
    274     void init (bool aKeepObj = false);
    275     void init (IUnknown *aUnk, const GUID &aIID, bool aKeepObj = false);
    276     void init (IVirtualBoxErrorInfo *aInfo);
     261    ErrorInfo(bool /* aDummy */)
     262        : mIsBasicAvailable(false),
     263          mIsFullAvailable(false),
     264          mResultCode(S_OK),
     265          m_pNext(NULL)
     266    { }
     267
     268    void init(bool aKeepObj = false);
     269    void init(IUnknown *aUnk, const GUID &aIID, bool aKeepObj = false);
     270    void init(IVirtualBoxErrorInfo *aInfo);
    277271
    278272    bool mIsBasicAvailable : 1;
     
    284278    Bstr    mText;
    285279
    286     cppx::auto_copy_ptr <ErrorInfo> mNext;
     280    ErrorInfo *m_pNext;
    287281
    288282    Bstr mInterfaceName;
     
    290284    Bstr mCalleeName;
    291285
    292     ComPtr <IUnknown> mErrorInfo;
     286    ComPtr<IUnknown> mErrorInfo;
     287
     288private:
     289    ErrorInfo(const ErrorInfo&);
    293290};
    294291
     
    311308     *  @param  progress    the progress object representing a failed operation
    312309     */
    313     ProgressErrorInfo (IProgress *progress);
     310    ProgressErrorInfo(IProgress *progress);
    314311};
    315312
     
    381378        setNull();
    382379        mForgot = false;
    383         init (true /* aKeepObj */);
     380        init(true /* aKeepObj */);
    384381    }
    385382
  • trunk/include/VBox/com/Guid.h

    r30676 r30681  
    4444#include "VBox/com/string.h"
    4545
    46 #include <iprt/cpp/utils.h>
    4746#include <iprt/uuid.h>
    4847
  • trunk/include/VBox/com/array.h

    r30676 r30681  
    168168#include "VBox/com/ptr.h"
    169169#include "VBox/com/assert.h"
    170 
    171 #include "iprt/cpp/utils.h"
    172170
    173171#if defined (VBOX_WITH_XPCOM)
  • trunk/include/VBox/com/com.h

    r30676 r30681  
    5959void GetInterfaceNameByIID(const GUID &aIID, BSTR *aName);
    6060
    61 #ifdef VBOX_WITH_XPCOM
    62 
    63 /**
    64  *  Helper method to keep all the XPCOM headers out of include/VBox/com/ptr.h.
    65  */
    66 HRESULT GlueCreateObjectOnServer(const CLSID &clsid,
    67                                  const char *serverName,
    68                                  const nsIID &id,
    69                                  void** ppobj);
    70 
    71 /**
    72  *  Helper method to keep all the XPCOM headers out of include/VBox/com/ptr.h.
    73  */
    74 HRESULT GlueCreateInstance(const CLSID &clsid,
    75                            const nsIID &id,
    76                            void** ppobj);
    77 
    78 #endif // VBOX_WITH_XPCOM
    79 
    8061/**
    8162 *  Returns the VirtualBox user home directory.
  • trunk/include/VBox/com/defs.h

    r30676 r30681  
    521521        if ((FAILED (aRC) && !FAILED (mRC)) ||
    522522            (mRC == S_OK && aRC != S_OK))
    523             mRC = aRC;
    524 
    525         return *this;
    526     }
    527 
    528     operator HRESULT() const { return mRC; }
    529 
    530     HRESULT *operator&() { return &mRC; }
    531 
    532 private:
    533 
    534     HRESULT mRC;
    535 };
    536 
    537 /**
    538  * "Last worst" result type.
    539  *
    540  * Variables of this class are used instead of HRESULT variables when it is
    541  * desirable to memorize the "last worst" result code instead of the last
    542  * assigned one. In other words, an assignment operation to a variable of this
    543  * class will succeed only if the result code to assign has the same or worse
    544  * severity. The following table demonstrate this (the first column lists the
    545  * previous result code stored in the variable, the first row lists the new
    546  * assigned, 'A' means the assignment will take place, '> S_OK' means a warning
    547  * result code):
    548  *
    549  * {{{
    550  *             FAILED    > S_OK    S_OK
    551  * FAILED        A         -         -
    552  * > S_OK        A         A         -
    553  * S_OK          A         A         -
    554  *
    555  * }}}
    556  *
    557  * In practice, you will need to use a LWResult variable when you call some COM
    558  * method B after COM method A fails and want to return the result code of B
    559  * if B also fails, but still want to return the failed result code of A if B
    560  * issues a warning or succeeds.
    561  */
    562 class LWResult
    563 {
    564 
    565 public:
    566 
    567     /**
    568      * Constructs a new variable. Note that by default this constructor sets the
    569      * result code to E_FAIL to make sure a failure is returned to the caller if
    570      * the variable is never assigned another value (which is considered as the
    571      * improper use of this class).
    572      */
    573     LWResult (HRESULT aRC = E_FAIL) : mRC (aRC) {}
    574 
    575     LWResult &operator= (HRESULT aRC)
    576     {
    577         if (FAILED (aRC) ||
    578             (SUCCEEDED (mRC) && aRC != S_OK))
    579523            mRC = aRC;
    580524
  • trunk/include/VBox/com/ptr.h

    r30676 r30681  
    4343#else
    4444 #include <nsISupportsUtils.h>
     45
    4546#endif /* !defined (VBOX_WITH_XPCOM) */
    4647
    47 #include <VBox/com/com.h>
     48#include <VBox/com/defs.h>
     49
     50#ifdef VBOX_WITH_XPCOM
     51
     52namespace com
     53{
     54// declare a couple of XPCOM helper methods (defined in glue/com.cpp)
     55// so we don't have to include a ton of XPCOM implementation headers here
     56HRESULT GlueCreateObjectOnServer(const CLSID &clsid,
     57                                 const char *serverName,
     58                                 const nsIID &id,
     59                                 void** ppobj);
     60HRESULT GlueCreateInstance(const CLSID &clsid,
     61                           const nsIID &id,
     62                           void** ppobj);
     63}
     64
     65#endif // VBOX_WITH_XPCOM
    4866
    4967/**
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