Changeset 30681 in vbox for trunk/include/VBox/com
- Timestamp:
- Jul 6, 2010 5:20:20 PM (15 years ago)
- svn:sync-xref-src-repo-rev:
- 63442
- Location:
- trunk/include/VBox/com
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/include/VBox/com/ErrorInfo.h
r30676 r30681 32 32 #include "VBox/com/Guid.h" 33 33 #include "VBox/com/assert.h" 34 35 #include <iprt/memory> // for auto_copy_ptr36 34 37 35 struct IProgress; … … 109 107 */ 110 108 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 } 162 125 163 126 virtual ~ErrorInfo(); … … 175 138 * this method returns true (otherwise they simply return NULL-like values). 176 139 */ 177 bool isBasicAvailable() const { return mIsBasicAvailable; } 140 bool isBasicAvailable() const 141 { 142 return mIsBasicAvailable; 143 } 178 144 179 145 /** … … 189 155 * this method returns true (otherwise they simply return NULL-like values). 190 156 */ 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 } 198 161 199 162 /** 200 163 * Returns the COM result code of the failed operation. 201 164 */ 202 HRESULT getResultCode() const { return mResultCode; } 165 HRESULT getResultCode() const 166 { 167 return mResultCode; 168 } 203 169 204 170 /** 205 171 * Returns the IID of the interface that defined the error. 206 172 */ 207 const Guid &getInterfaceID() const { return mInterfaceID; } 173 const Guid& getInterfaceID() const 174 { 175 return mInterfaceID; 176 } 208 177 209 178 /** 210 179 * Returns the name of the component that generated the error. 211 180 */ 212 const Bstr &getComponent() const { return mComponent; } 181 const Bstr& getComponent() const 182 { 183 return mComponent; 184 } 213 185 214 186 /** 215 187 * Returns the textual description of the error. 216 188 */ 217 const Bstr &getText() const { return mText; } 189 const Bstr& getText() const 190 { 191 return mText; 192 } 218 193 219 194 /** 220 195 * Returns the next error information object or @c NULL if there is none. 221 196 */ 222 const ErrorInfo *getNext() const { return mNext.get(); } 197 const ErrorInfo* getNext() const 198 { 199 return m_pNext; 200 } 223 201 224 202 /** 225 203 * Returns the name of the interface that defined the error 226 204 */ 227 const Bstr &getInterfaceName() const { return mInterfaceName; } 205 const Bstr& getInterfaceName() const 206 { 207 return mInterfaceName; 208 } 228 209 229 210 /** … … 234 215 * template <class I> ErrorInfo (const ComPtr <I> &i) constructor. 235 216 */ 236 const Guid &getCalleeIID() const { return mCalleeIID; } 217 const Guid& getCalleeIID() const 218 { 219 return mCalleeIID; 220 } 237 221 238 222 /** … … 243 227 * template <class I> ErrorInfo (const ComPtr <I> &i) constructor. 244 228 */ 245 const Bstr &getCalleeName() const { return mCalleeName; } 229 const Bstr& getCalleeName() const 230 { 231 return mCalleeName; 232 } 246 233 247 234 /** … … 253 240 mIsBasicAvailable = false; 254 241 mIsFullAvailable = false; 242 243 if (m_pNext) 244 { 245 delete m_pNext; 246 m_pNext = NULL; 247 } 255 248 256 249 mResultCode = S_OK; … … 258 251 mComponent.setNull(); 259 252 mText.setNull(); 260 mNext.reset();261 253 mInterfaceName.setNull(); 262 254 mCalleeIID.clear(); … … 267 259 protected: 268 260 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); 277 271 278 272 bool mIsBasicAvailable : 1; … … 284 278 Bstr mText; 285 279 286 cppx::auto_copy_ptr <ErrorInfo> mNext;280 ErrorInfo *m_pNext; 287 281 288 282 Bstr mInterfaceName; … … 290 284 Bstr mCalleeName; 291 285 292 ComPtr <IUnknown> mErrorInfo; 286 ComPtr<IUnknown> mErrorInfo; 287 288 private: 289 ErrorInfo(const ErrorInfo&); 293 290 }; 294 291 … … 311 308 * @param progress the progress object representing a failed operation 312 309 */ 313 ProgressErrorInfo 310 ProgressErrorInfo(IProgress *progress); 314 311 }; 315 312 … … 381 378 setNull(); 382 379 mForgot = false; 383 init 380 init(true /* aKeepObj */); 384 381 } 385 382 -
trunk/include/VBox/com/Guid.h
r30676 r30681 44 44 #include "VBox/com/string.h" 45 45 46 #include <iprt/cpp/utils.h>47 46 #include <iprt/uuid.h> 48 47 -
trunk/include/VBox/com/array.h
r30676 r30681 168 168 #include "VBox/com/ptr.h" 169 169 #include "VBox/com/assert.h" 170 171 #include "iprt/cpp/utils.h"172 170 173 171 #if defined (VBOX_WITH_XPCOM) -
trunk/include/VBox/com/com.h
r30676 r30681 59 59 void GetInterfaceNameByIID(const GUID &aIID, BSTR *aName); 60 60 61 #ifdef VBOX_WITH_XPCOM62 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_XPCOM79 80 61 /** 81 62 * Returns the VirtualBox user home directory. -
trunk/include/VBox/com/defs.h
r30676 r30681 521 521 if ((FAILED (aRC) && !FAILED (mRC)) || 522 522 (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 is541 * desirable to memorize the "last worst" result code instead of the last542 * assigned one. In other words, an assignment operation to a variable of this543 * class will succeed only if the result code to assign has the same or worse544 * severity. The following table demonstrate this (the first column lists the545 * previous result code stored in the variable, the first row lists the new546 * assigned, 'A' means the assignment will take place, '> S_OK' means a warning547 * result code):548 *549 * {{{550 * FAILED > S_OK S_OK551 * 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 COM558 * method B after COM method A fails and want to return the result code of B559 * if B also fails, but still want to return the failed result code of A if B560 * issues a warning or succeeds.561 */562 class LWResult563 {564 565 public:566 567 /**568 * Constructs a new variable. Note that by default this constructor sets the569 * result code to E_FAIL to make sure a failure is returned to the caller if570 * the variable is never assigned another value (which is considered as the571 * 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))579 523 mRC = aRC; 580 524 -
trunk/include/VBox/com/ptr.h
r30676 r30681 43 43 #else 44 44 #include <nsISupportsUtils.h> 45 45 46 #endif /* !defined (VBOX_WITH_XPCOM) */ 46 47 47 #include <VBox/com/com.h> 48 #include <VBox/com/defs.h> 49 50 #ifdef VBOX_WITH_XPCOM 51 52 namespace 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 56 HRESULT GlueCreateObjectOnServer(const CLSID &clsid, 57 const char *serverName, 58 const nsIID &id, 59 void** ppobj); 60 HRESULT GlueCreateInstance(const CLSID &clsid, 61 const nsIID &id, 62 void** ppobj); 63 } 64 65 #endif // VBOX_WITH_XPCOM 48 66 49 67 /**
Note:
See TracChangeset
for help on using the changeset viewer.