Changeset 30681 in vbox
- Timestamp:
- Jul 6, 2010 5:20:20 PM (15 years ago)
- Location:
- trunk
- Files:
-
- 41 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 /** -
trunk/include/iprt/cpp/utils.h
r30676 r30681 27 27 #define ___iprt_cpputils_h 28 28 29 #include <iprt/assert.h>30 31 #include <memory>32 33 29 /** @defgroup grp_rt_cpputils C++ Utilities 34 30 * @ingroup grp_rt … … 48 44 */ 49 45 template <class C> 50 inline C &unconst (const C &that) { return const_cast <C &>(that); }46 inline C& unconst(const C &that) { return const_cast<C&>(that); } 51 47 52 48 … … 63 59 */ 64 60 template <class C> 65 inline C *unconst (const C *that) { return const_cast <C *>(that); }61 inline C* unconst(const C *that) { return const_cast<C*>(that); } 66 62 67 63 68 /** 69 * Extensions to the std namespace. 70 */ 71 namespace stdx 64 namespace iprt 72 65 { 73 74 /* forward */75 template <class> class auto_ref_ptr;76 77 /**78 * Base class for objects willing to support smart reference counting using79 * the auto_ref_ptr template.80 *81 * When a class wants to be used with the auto_ref_ptr template it simply82 * declares the auto_ref class among its public base classes -- there is no83 * need to implement any additional methods.84 */85 class auto_ref86 {87 protected:88 89 auto_ref() : mRefs (0) {}90 91 /** Increases the reference counter and returns it */92 size_t ref() { return ++ mRefs; }93 94 /** Decreases the reference counter and returns it */95 size_t unref() { Assert (mRefs > 0); return -- mRefs; }96 97 private:98 99 size_t mRefs;100 101 template <class> friend class auto_ref_ptr;102 };103 104 /**105 * The auto_ref_ptr template manages pointers to objects that support106 * reference counting by implementing auto_ref or a similar interface.107 *108 * Pointer management includes the following key points:109 *110 * 1) Automatic increment of the object's reference counter when the given111 * auto_ref_ptr instance starts managing a pointer to this object.112 *113 * 2) Automatic decrement of the reference counter when the given114 * auto_ref_ptr instance is destroyed, or before it is assigned a pointer115 * to a new object.116 *117 * 3) Automatic deletion of the managed object whenever its reference118 * counter reaches zero after a decrement.119 *120 * 4) Providing the dereference operator-> that gives direct access to the121 * managed pointer.122 *123 * The object class to manage must provide ref() and unref() methods that have124 * the same syntax and semantics as defined in the auto_ref class.125 *126 * @param C Class to manage.127 */128 template <class C>129 class auto_ref_ptr130 {131 public:132 133 /**134 * Creates a null instance that does not manage anything.135 */136 auto_ref_ptr() : m (NULL) {}137 138 /**139 * Creates an instance that starts managing the given pointer. The140 * reference counter of the object pointed to by @a a is incremented by141 * one.142 *143 * @param a Pointer to manage.144 */145 auto_ref_ptr (C* a) : m (a) { if (m) m->ref(); }146 147 /**148 * Creates an instance that starts managing a pointer managed by the given149 * instance. The reference counter of the object managed by @a that is150 * incremented by one.151 *152 * @param that Instance to take a pointer to manage from.153 */154 auto_ref_ptr (const auto_ref_ptr &that) : m (that.m) { if (m) m->ref(); }155 156 ~auto_ref_ptr() { do_unref(); }157 158 /**159 * Assigns the given pointer to this instance and starts managing it. The160 * reference counter of the object pointed to by @a a is incremented by161 * one. The reference counter of the object previously managed by this162 * instance is decremented by one.163 *164 * @param a Pointer to assign.165 */166 auto_ref_ptr &operator= (C *a) { do_reref (a); return *this; }167 168 /**169 * Assigns a pointer managed by the given instance to this instance and170 * starts managing it. The reference counter of the object managed by @a171 * that is incremented by one. The reference counter of the object172 * previously managed by this instance is decremented by one.173 *174 * @param that Instance which pointer to reference.175 */176 auto_ref_ptr &operator= (const auto_ref_ptr &that) { do_reref (that.m); return *this; }177 178 /**179 * Returns @c true if this instance is @c null and false otherwise.180 */181 bool is_null() const { return m == NULL; }182 183 /**184 * Dereferences the instance by returning the managed pointer.185 * Asserts that the managed pointer is not @c NULL.186 */187 C *operator-> () const { AssertMsg (m, ("Managed pointer is NULL!\n")); return m; }188 189 /**190 * Returns the managed pointer or @c NULL if this instance is @c null.191 */192 C *raw() const { return m; }193 194 /**195 * Compares this auto_ref_ptr instance with another instance and returns196 * @c true if both instances manage the same or @c NULL pointer.197 *198 * Note that this method compares pointer values only, it doesn't try to199 * compare objects themselves. Doing otherwise would a) break the common200 * 'pointer to something' comparison semantics auto_ref_ptr tries to201 * follow and b) require to define the comparison operator in the managed202 * class which is not always possible. You may analyze pointed objects203 * yourself if you need more precise comparison.204 *205 * @param that Instance to compare this instance with.206 */207 bool operator== (const auto_ref_ptr &that) const208 {209 return m == that.m;210 }211 212 protected:213 214 void do_reref (C *a)215 {216 /* be aware of self assignment */217 if (a)218 a->ref();219 if (m)220 {221 size_t refs = m->unref();222 if (refs == 0)223 {224 refs = 1; /* stabilize */225 delete m;226 }227 }228 m = a;229 }230 231 void do_unref() { do_reref (NULL); }232 233 C *m;234 };235 236 /**237 * The exception_trap_base class is an abstract base class for all238 * exception_trap template instantiations.239 *240 * Pointer variables of this class are used to store a pointer any object of241 * any class instantiated from the exception_trap template, or in other words242 * to store a full copy of any exception wrapped into the exception_trap instance243 * allocated on the heap.244 *245 * See the exception_trap template for more info.246 */247 class exception_trap_base248 {249 public:250 virtual void rethrow() = 0;251 virtual ~exception_trap_base() {}252 };253 254 /**255 * The exception_trap template acts like a wrapper for the given exception256 * class that stores a full copy of the exception and therefore allows to257 * rethrow it preserving the actual type information about the exception258 * class.259 *260 * This functionality is useful in situations where it is necessary to catch a261 * (known) number of exception classes and pass the caught exception instance262 * to an upper level using a regular variable (rather than the exception263 * unwinding mechanism itself) *and* preserve all information about the type264 * (class) of the caight exception so that it may be rethrown on the upper265 * level unchanged.266 *267 * Usage pattern:268 * @code269 using namespace std;270 using namespace stdx;271 272 auto_ptr <exception_trap_base> trapped;273 274 int callback();275 276 int safe_callback()277 {278 try279 {280 // callback may throw a set of exceptions but we don't want it to start281 // unwinding the stack right now282 283 return callback();284 }285 catch (const MyException &err) { trapped = new_exception_trap (err); }286 catch (const MyException2 &err) { trapped = new_exception_trap (err); }287 catch (...) { trapped = new_exception_trap (logic_error()); }288 289 return -1;290 }291 292 void bar()293 {294 // call a funciton from some C library that supports callbacks but knows295 // nothing about exceptions so throwing one from a callback will leave296 // the library in an undetermined state297 298 do_something_with_callback (safe_callback());299 300 // check if we have got an exeption from callback() and rethrow it now301 // when we are not in the C library any more302 if (trapped.get() != NULL)303 trapped->rethrow();304 }305 * @endcode306 *307 * @param T Exception class to wrap.308 */309 template <typename T>310 class exception_trap : public exception_trap_base311 {312 public:313 314 exception_trap (const T &aTrapped) : trapped (aTrapped) {}315 void rethrow() { throw trapped; }316 317 T trapped;318 };319 320 /**321 * Convenience function that allocates a new exception_trap instance on the322 * heap by automatically deducing the exception_trap template argument from323 * the type of the exception passed in @a aTrapped.324 *325 * The following two lines of code inside the catch block are equivalent:326 *327 * @code328 using namespace std;329 using namespace stdx;330 catch (const MyException &err)331 {332 auto_ptr <exception_trap_base> t1 = new exception_trap <MyException> (err);333 auto_ptr <exception_trap_base> t2 = new_exception_trap (err);334 }335 * @endcode336 *337 * @param aTrapped Exception to put to the allocated trap.338 *339 * @return Allocated exception_trap object.340 */341 template <typename T>342 static exception_trap <T> *343 new_exception_trap (const T &aTrapped)344 {345 return new exception_trap <T> (aTrapped);346 }347 348 /**349 * Enhancement of std::auto_ptr @<char@> intended to take pointers to char350 * buffers allocated using new[].351 *352 * This differs from std::auto_ptr @<char@> so that it overloads some methods to353 * uses delete[] instead of delete to delete the owned data in order to354 * conform to the C++ standard (and avoid valgrind complaints).355 *356 * Note that you should not use instances of this class where pointers or357 * references to objects of std::auto_ptr @<char@> are expeced. Despite the fact358 * the classes are related, the base is not polymorphic (in particular,359 * neither the destructor nor the reset() method are virtual). It means that when360 * acessing instances of this class through the base pointer, overloaded361 * methods won't be called.362 */363 class char_auto_ptr : public std::auto_ptr <char>364 {365 public:366 367 explicit char_auto_ptr (char *a = 0) throw()368 : std::auto_ptr <char> (a) {}369 370 /* Note: we use unconst brute force below because the non-const version371 * of the copy constructor won't accept temporary const objects372 * (e.g. function return values) in GCC. std::auto_ptr has the same373 * "problem" but it seems overcome it using #pragma GCC system_header374 * which doesn't work here. */375 char_auto_ptr (const char_auto_ptr &that) throw()376 : std::auto_ptr <char> (unconst (that).release()) {}377 378 ~char_auto_ptr() { delete[] (release()); }379 380 char_auto_ptr &operator= (char_auto_ptr &that) throw()381 {382 std::auto_ptr <char>::operator= (that);383 return *this;384 }385 386 void reset (char *a) throw()387 {388 if (a != get())389 {390 delete[] (release());391 std::auto_ptr <char>::reset (a);392 }393 }394 };395 396 66 /** 397 67 * A simple class used to prevent copying and assignment. Inherit from this … … 409 79 }; 410 80 411 } / * namespace stdx */81 } // namespace iprt 412 82 413 83 /** @} */ 414 84 415 #endif 85 #endif // ___iprt_cpputils_h 416 86 -
trunk/include/iprt/memory
r30676 r30681 1 /** @file2 * IPRT - C++ Extensions: memory.3 */4 5 /*6 * Copyright (C) 2007 Oracle Corporation7 *8 * This file is part of VirtualBox Open Source Edition (OSE), as9 * available from http://www.virtualbox.org. This file is free software;10 * you can redistribute it and/or modify it under the terms of the GNU11 * General Public License (GPL) as published by the Free Software12 * Foundation, in version 2 as it comes in the "COPYING" file of the13 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the14 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.15 *16 * The contents of this file may alternatively be used under the terms17 * of the Common Development and Distribution License Version 1.018 * (CDDL) only, as it comes in the "COPYING.CDDL" file of the19 * VirtualBox OSE distribution, in which case the provisions of the20 * CDDL are applicable instead of those of the GPL.21 *22 * You may elect to license modified versions of this file under the23 * terms and conditions of either the GPL or the CDDL or both.24 */25 26 #ifndef ___iprt_memory___27 #define ___iprt_memory___28 29 /** @defgroup grp_rt_cppx_memory IPRT C++ Extensions: memory30 * @ingroup grp_rt_cppx31 * @{32 */33 34 #ifdef __cplusplus35 36 #include <memory> /* for auto_ptr */37 38 namespace cppx39 {40 41 /**42 * A simple std::auto_ptr extension that adds CopyConstructible and43 * Assignable semantics.44 *45 * Instances of this class, when constructed from or assigned with instances46 * of the same class, create a copy of the managed object using the new47 * operator and the managed object's copy constructor, as opposed to48 * std::auto_ptr which simply transfers ownership in these cases.49 *50 * This template is useful for member variables of a class that store51 * dynamically allocated instances of some other class and these instances52 * need to be copied when the containing class instance is copied itself.53 *54 * Be careful when returning instances of this class by value: it will call55 * cause to create a copy of the managed object which is probably is not what56 * you want, especially if its constructor is quite an expensive operation.57 */58 template <typename T>59 class auto_copy_ptr : public std::auto_ptr <T>60 {61 public:62 63 /** @see std::auto_ptr <T>::auto_ptr() */64 auto_copy_ptr (T *p = 0) throw() : std::auto_ptr <T> (p) {}65 66 /**67 * Copy constructor.68 * Takes a copy of the given instance by taking a copy of the managed69 * object using its copy constructor. Both instances will continue to own70 * their objects.71 */72 auto_copy_ptr (const auto_copy_ptr &that) throw()73 : std::auto_ptr <T> (that.get() ? new T (*that.get()) : NULL) {}74 75 /**76 * Assignment operator.77 * Takes a copy of the given instance by taking a copy of the managed78 * object using its copy constructor. Both instances will continue to own79 * their objects.80 */81 auto_copy_ptr &operator= (const auto_copy_ptr &that) throw()82 {83 std::auto_ptr <T>::reset (that.get() ? new T (*that.get()) : NULL);84 return *this;85 }86 };87 88 } /* namespace cppx */89 90 91 #endif /* __cplusplus */92 93 /** @} */94 95 #endif -
trunk/src/VBox/Additions/x11/VBoxClient/VBoxClient.h
r30676 r30681 26 26 /** A simple class describing a service. VBoxClient will run exactly one 27 27 * service per invocation. */ 28 class Service : public stdx::non_copyable28 class Service : public iprt::non_copyable 29 29 { 30 30 public: -
trunk/src/VBox/Frontends/VBoxHeadless/testcase/tstHeadless.cpp
r30676 r30681 139 139 if (FAILED (resultCode)) 140 140 { 141 ComPtr 142 CHECK_ERROR_BREAK 143 144 ErrorInfo info (errorInfo);141 ComPtr<IVirtualBoxErrorInfo> errorInfo; 142 CHECK_ERROR_BREAK(progress, 143 COMGETTER(ErrorInfo) (errorInfo.asOutParam())); 144 ErrorInfo info(errorInfo, COM_IIDOF(IVirtualBoxErrorInfo)); 145 145 com::GluePrintErrorInfo(info); 146 146 } … … 175 175 if (FAILED (resultCode)) 176 176 { 177 ComPtr 178 CHECK_ERROR_BREAK 179 180 ErrorInfo info (errorInfo);177 ComPtr<IVirtualBoxErrorInfo> errorInfo; 178 CHECK_ERROR_BREAK(progress, 179 COMGETTER(ErrorInfo) (errorInfo.asOutParam())); 180 ErrorInfo info(errorInfo, COM_IIDOF(IVirtualBoxErrorInfo)); 181 181 com::GluePrintErrorInfo(info); 182 182 } -
trunk/src/VBox/Frontends/VBoxManage/VBoxManageGuestCtrl.cpp
r30676 r30681 324 324 /* If we got a VBOX_E_IPRT error we handle the error in a more gentle way 325 325 * because it contains more accurate info about what went wrong. */ 326 ErrorInfo info(guest );326 ErrorInfo info(guest, COM_IIDOF(IGuest)); 327 327 if (info.isFullAvailable()) 328 328 { 329 329 if (rc == VBOX_E_IPRT_ERROR) 330 {331 330 RTPrintf("%ls.\n", info.getText().raw()); 332 }333 331 else 334 {335 332 RTPrintf("ERROR: %ls (%Rhrc).\n", info.getText().raw(), info.getResultCode()); 336 }337 333 } 338 334 break; … … 398 394 /* If we got a VBOX_E_IPRT error we handle the error in a more gentle way 399 395 * because it contains more accurate info about what went wrong. */ 400 ErrorInfo info(guest );396 ErrorInfo info(guest, COM_IIDOF(IGuest)); 401 397 if (info.isFullAvailable()) 402 398 { … … 493 489 ComPtr<IVirtualBoxErrorInfo> execError; 494 490 rc = progress->COMGETTER(ErrorInfo)(execError.asOutParam()); 495 com::ErrorInfo info (execError);491 com::ErrorInfo info(execError, COM_IIDOF(IVirtualBoxErrorInfo)); 496 492 if (SUCCEEDED(rc) && info.isFullAvailable()) 497 493 { -
trunk/src/VBox/Frontends/VBoxManage/VBoxManageImport.cpp
r30676 r30681 267 267 RTPrintf("Interpreting %ls...\n", path.raw()); 268 268 rc = pAppliance->Interpret(); 269 com::ErrorInfo info0(pAppliance );269 com::ErrorInfo info0(pAppliance, COM_IIDOF(IAppliance)); 270 270 271 271 com::SafeArray<BSTR> aWarnings; -
trunk/src/VBox/Frontends/VBoxManage/VBoxManageInfo.cpp
r30676 r30681 170 170 rc = machine->COMGETTER(AccessError)(accessError.asOutParam()); 171 171 RTPrintf("Access error details:\n"); 172 ErrorInfo ei(accessError );172 ErrorInfo ei(accessError, COM_IIDOF(IVirtualBoxErrorInfo)); 173 173 GluePrintErrorInfo(ei); 174 174 RTPrintf("\n"); … … 1291 1291 if (FAILED(rc)) 1292 1292 { 1293 com::ErrorInfo info (display);1293 com::ErrorInfo info(display, COM_IIDOF(IDisplay)); 1294 1294 GluePrintErrorInfo(info); 1295 1295 return rc; … … 1356 1356 if (FAILED(rc)) 1357 1357 { 1358 com::ErrorInfo info (remoteDisplayInfo);1358 com::ErrorInfo info(remoteDisplayInfo, COM_IIDOF(IRemoteDisplayInfo)); 1359 1359 GluePrintErrorInfo(info); 1360 1360 return rc; -
trunk/src/VBox/Frontends/VBoxManage/VBoxManageMisc.cpp
r30676 r30681 387 387 if (FAILED(iRc)) 388 388 { 389 ComPtr 389 ComPtr<IVirtualBoxErrorInfo> errorInfo; 390 390 CHECK_ERROR_RET(progress, COMGETTER(ErrorInfo)(errorInfo.asOutParam()), 1); 391 ErrorInfo info (errorInfo);391 ErrorInfo info(errorInfo, COM_IIDOF(IVirtualBoxErrorInfo)); 392 392 com::GluePrintErrorInfo(info); 393 393 } -
trunk/src/VBox/Frontends/VBoxSDL/VBoxSDL.cpp
r30676 r30681 2008 2008 if (rc != S_OK) 2009 2009 { 2010 com::ErrorInfo info(gConsole );2010 com::ErrorInfo info(gConsole, COM_IIDOF(IConsole)); 2011 2011 if (info.isBasicAvailable()) 2012 2012 PrintError("Failed to power up VM", info.getText().raw()); … … 2792 2792 for (unsigned i = 0; i < gcMonitors; i++) 2793 2793 gDisplay->SetFramebuffer(i, NULL); 2794 } 2794 } 2795 2795 2796 2796 gMouse = NULL; -
trunk/src/VBox/Frontends/VirtualBox/src/VBoxMedium.h
r30676 r30681 26 26 /* Local includes */ 27 27 #include "COMDefs.h" 28 29 #include <iprt/cpp/utils.h> 28 30 29 31 /** -
trunk/src/VBox/Frontends/VirtualBox/src/globals/COMDefs.cpp
r30676 r30681 224 224 //////////////////////////////////////////////////////////////////////////////// 225 225 226 void COMErrorInfo::init 226 void COMErrorInfo::init(const CVirtualBoxErrorInfo &info) 227 227 { 228 228 AssertReturnVoid (!info.isNull()); … … 249 249 gotAll &= info.isOk(); 250 250 251 m_pNext = NULL; 252 251 253 CVirtualBoxErrorInfo next = info.GetNext(); 252 254 if (info.isOk() && !next.isNull()) 253 255 { 254 mNext.reset (new COMErrorInfo (next)); 255 Assert (mNext.get()); 256 } 257 else 258 mNext.reset(); 256 m_pNext = new COMErrorInfo(next); 257 Assert(m_pNext); 258 } 259 259 260 gotSomething |= info.isOk(); 260 261 gotAll &= info.isOk(); … … 266 267 267 268 AssertMsg (gotSomething, ("Nothing to fetch!\n")); 269 } 270 271 void COMErrorInfo::copyFrom(const COMErrorInfo &x) 272 { 273 mIsNull = x.mIsNull; 274 mIsBasicAvailable = x.mIsBasicAvailable; 275 mIsFullAvailable = x.mIsFullAvailable; 276 277 mResultCode = x.mResultCode; 278 mInterfaceID = x.mInterfaceID; 279 mComponent = x.mComponent; 280 mText = mText; 281 282 if (x.m_pNext) 283 m_pNext = new COMErrorInfo(*x.m_pNext); 284 else 285 m_pNext = NULL; 286 287 mInterfaceName = x.mInterfaceName; 288 mCalleeIID = x.mCalleeIID; 289 mCalleeName = x.mCalleeName; 290 } 291 292 void COMErrorInfo::cleanup() 293 { 294 if (m_pNext) 295 { 296 delete m_pNext; 297 m_pNext = NULL; 298 } 268 299 } 269 300 … … 278 309 * UUID of the callee's interface. Ignored when callee is NULL 279 310 */ 280 void COMErrorInfo::fetchFromCurrentThread 311 void COMErrorInfo::fetchFromCurrentThread(IUnknown *callee, const GUID *calleeIID) 281 312 { 282 313 mIsNull = true; -
trunk/src/VBox/Frontends/VirtualBox/src/globals/COMDefs.h
r30676 r30681 84 84 #include <QMetaType> 85 85 86 #include <iprt/memory> // for auto_copy_ptr87 88 86 /* 89 87 * Additional COM / XPCOM defines and includes … … 123 121 124 122 COMErrorInfo() 125 : mIsNull (true) 126 , mIsBasicAvailable (false), mIsFullAvailable (false) 127 , mResultCode (S_OK) {} 128 129 COMErrorInfo (const CVirtualBoxErrorInfo &info) { init (info); } 130 131 /* the default copy ctor and assignment op are ok */ 123 : mIsNull(true), 124 mIsBasicAvailable(false), 125 mIsFullAvailable(false), 126 mResultCode(S_OK), 127 m_pNext(NULL) 128 {} 129 130 COMErrorInfo(const COMErrorInfo &info) 131 { 132 copyFrom(info); 133 } 134 135 COMErrorInfo(const CVirtualBoxErrorInfo &info) 136 { 137 init(info); 138 } 139 140 ~COMErrorInfo() 141 { 142 cleanup(); 143 } 144 145 COMErrorInfo& operator=(const COMErrorInfo &info) 146 { 147 cleanup(); 148 copyFrom(info); 149 return *this; 150 } 132 151 133 152 bool isNull() const { return mIsNull; } … … 141 160 QString text() const { return mText; } 142 161 143 const COMErrorInfo *next() const { return m Next.get(); }162 const COMErrorInfo *next() const { return m_pNext; } 144 163 145 164 QString interfaceName() const { return mInterfaceName; } … … 148 167 149 168 private: 150 151 void init (const CVirtualBoxErrorInfo &info); 152 void fetchFromCurrentThread (IUnknown *callee, const GUID *calleeIID); 169 void init(const CVirtualBoxErrorInfo &info); 170 void copyFrom(const COMErrorInfo &x); 171 void cleanup(); 172 173 void fetchFromCurrentThread(IUnknown *callee, const GUID *calleeIID); 153 174 154 175 static QString getInterfaceNameFromIID (const QUuid &id); … … 163 184 QString mText; 164 185 165 cppx::auto_copy_ptr <COMErrorInfo> mNext;186 COMErrorInfo *m_pNext; 166 187 167 188 QString mInterfaceName; … … 537 558 * Queries the current result code and error info from the given component. 538 559 */ 539 COMResult (const COMBaseWithEI &aComponent) 540 : mRC (aComponent.lastRC()) 541 , mErrInfo (aComponent.errorInfo()) {} 560 COMResult(const COMBaseWithEI &aComponent) 561 : mRC(aComponent.lastRC()), 562 mErrInfo(aComponent.errorInfo()) 563 { } 542 564 543 565 /** -
trunk/src/VBox/HostServices/GuestControl/service.cpp
r30676 r30681 147 147 * Class containing the shared information service functionality. 148 148 */ 149 class Service : public stdx::non_copyable149 class Service : public iprt::non_copyable 150 150 { 151 151 private: … … 718 718 switch (eFunction) 719 719 { 720 /* 721 * The guest asks the host for the next messsage to process. 720 /* 721 * The guest asks the host for the next messsage to process. 722 722 */ 723 723 case GUEST_GET_HOST_MSG: … … 737 737 738 738 /* 739 * The guest notifies the host that some output at stdout/stderr is available. 739 * The guest notifies the host that some output at stdout/stderr is available. 740 740 */ 741 741 case GUEST_EXEC_SEND_OUTPUT: … … 744 744 break; 745 745 746 /* 747 * The guest notifies the host of the current client status. 746 /* 747 * The guest notifies the host of the current client status. 748 748 */ 749 749 case GUEST_EXEC_SEND_STATUS: -
trunk/src/VBox/HostServices/GuestProperties/service.cpp
r30676 r30681 147 147 * Class containing the shared information service functionality. 148 148 */ 149 class Service : public stdx::non_copyable149 class Service : public iprt::non_copyable 150 150 { 151 151 private: -
trunk/src/VBox/Main/ApplianceImpl.cpp
r30676 r30681 18 18 19 19 #include <iprt/path.h> 20 #include <iprt/cpp/utils.h> 20 21 21 22 #include <VBox/com/array.h> -
trunk/src/VBox/Main/ConsoleVRDPServer.cpp
r30676 r30681 30 30 #include <iprt/path.h> 31 31 #include <iprt/alloca.h> 32 #include <iprt/cpp/utils.h> 32 33 33 34 #include <VBox/err.h> -
trunk/src/VBox/Main/DHCPServerImpl.cpp
r30676 r30681 22 22 #include "AutoCaller.h" 23 23 #include "Logging.h" 24 25 #include <iprt/cpp/utils.h> 24 26 25 27 #include <VBox/settings.h> -
trunk/src/VBox/Main/DisplayImpl.cpp
r30676 r30681 27 27 #include <iprt/thread.h> 28 28 #include <iprt/asm.h> 29 #include <iprt/cpp/utils.h> 29 30 30 31 #include <VBox/pdmdrv.h> -
trunk/src/VBox/Main/HostNetworkInterfaceImpl.cpp
r30676 r30681 22 22 #include "Logging.h" 23 23 #include "netif.h" 24 25 #include <iprt/cpp/utils.h> 24 26 25 27 #ifdef RT_OS_FREEBSD -
trunk/src/VBox/Main/KeyboardImpl.cpp
r30676 r30681 24 24 #include <VBox/com/array.h> 25 25 #include <VBox/pdmdrv.h> 26 26 27 #include <iprt/asm.h> 28 #include <iprt/cpp/utils.h> 27 29 28 30 // defines -
trunk/src/VBox/Main/MachineDebuggerImpl.cpp
r30676 r30681 33 33 #include <VBox/err.h> 34 34 #include <VBox/hwaccm.h> 35 #include <iprt/cpp/utils.h> 35 36 36 37 // defines -
trunk/src/VBox/Main/MediumAttachmentImpl.cpp
r30676 r30681 23 23 #include "AutoCaller.h" 24 24 #include "Logging.h" 25 26 #include <iprt/cpp/utils.h> 25 27 26 28 //////////////////////////////////////////////////////////////////////////////// -
trunk/src/VBox/Main/MediumFormatImpl.cpp
r30676 r30681 24 24 #include <VBox/VBoxHDD.h> 25 25 26 #include <iprt/cpp/utils.h> 27 26 28 // constructor / destructor 27 29 ///////////////////////////////////////////////////////////////////////////// … … 58 60 59 61 /* The ID of the backend */ 60 unconst 62 unconst(m.id) = aVDInfo->pszBackend; 61 63 /* The Name of the backend */ 62 64 /* Use id for now as long as VDBACKENDINFO hasn't any extra 63 65 * name/description field. */ 64 unconst 66 unconst(m.name) = aVDInfo->pszBackend; 65 67 /* The capabilities of the backend */ 66 unconst 68 unconst(m.capabilities) = aVDInfo->uBackendCaps; 67 69 /* Save the supported file extensions in a list */ 68 70 if (aVDInfo->papszFileExtensions) -
trunk/src/VBox/Main/MediumImpl.cpp
r30676 r30681 34 34 #include <iprt/file.h> 35 35 #include <iprt/tcp.h> 36 #include <iprt/cpp/utils.h> 36 37 37 38 #include <VBox/VBoxHDD.h> -
trunk/src/VBox/Main/MouseImpl.cpp
r30676 r30681 16 16 */ 17 17 18 #include <iprt/cpp/utils.h> 19 18 20 #include "MouseImpl.h" 19 21 #include "DisplayImpl.h" … … 24 26 25 27 #include <VBox/pdmdrv.h> 28 26 29 #include <iprt/asm.h> 30 27 31 #include <VBox/VMMDev.h> 28 32 -
trunk/src/VBox/Main/ProgressImpl.cpp
r30676 r30681 34 34 #include <iprt/time.h> 35 35 #include <iprt/semaphore.h> 36 #include <iprt/cpp/utils.h> 36 37 37 38 #include <VBox/err.h> -
trunk/src/VBox/Main/RemoteUSBDeviceImpl.cpp
r30676 r30681 24 24 #include "Logging.h" 25 25 26 #include <iprt/cpp/utils.h> 27 26 28 #include <VBox/err.h> 27 29 -
trunk/src/VBox/Main/SnapshotImpl.cpp
r30676 r30681 36 36 37 37 #include <iprt/path.h> 38 #include <iprt/cpp/utils.h> 39 38 40 #include <VBox/param.h> 39 41 #include <VBox/err.h> -
trunk/src/VBox/Main/SystemPropertiesImpl.cpp
r30676 r30681 31 31 #include <iprt/process.h> 32 32 #include <iprt/ldr.h> 33 #include <iprt/cpp/utils.h> 33 34 34 35 #include <VBox/err.h> -
trunk/src/VBox/Main/USBDeviceImpl.cpp
r30676 r30681 21 21 #include "Logging.h" 22 22 23 #include <iprt/cpp/utils.h> 24 23 25 // constructor / destructor 24 26 ///////////////////////////////////////////////////////////////////////////// -
trunk/src/VBox/Main/VFSExplorerImpl.cpp
r30676 r30681 21 21 #include <iprt/file.h> 22 22 #include <iprt/s3.h> 23 #include <iprt/cpp/utils.h> 23 24 24 25 #include <VBox/com/array.h> … … 33 34 #include "AutoCaller.h" 34 35 #include "Logging.h" 36 37 #include <memory> 35 38 36 39 //////////////////////////////////////////////////////////////////////////////// -
trunk/src/VBox/Main/glue/ErrorInfo.cpp
r30676 r30681 44 44 //////////////////////////////////////////////////////////////////////////////// 45 45 46 void ErrorInfo::init 46 void ErrorInfo::init(bool aKeepObj /* = false */) 47 47 { 48 48 HRESULT rc = E_FAIL; … … 144 144 } 145 145 146 void ErrorInfo::init (IUnknown *aI, const GUID &aIID, bool aKeepObj /* = false */) 146 void ErrorInfo::init(IUnknown *aI, 147 const GUID &aIID, 148 bool aKeepObj /* = false */) 147 149 { 148 150 Assert(aI); … … 175 177 } 176 178 177 void ErrorInfo::init 179 void ErrorInfo::init(IVirtualBoxErrorInfo *info) 178 180 { 179 181 AssertReturnVoid (info); … … 206 208 gotAll &= SUCCEEDED(rc); 207 209 210 m_pNext = NULL; 211 208 212 ComPtr<IVirtualBoxErrorInfo> next; 209 213 rc = info->COMGETTER(Next) (next.asOutParam()); 210 214 if (SUCCEEDED(rc) && !next.isNull()) 211 215 { 212 m Next.reset (new ErrorInfo (next));213 Assert(m Next.get());214 if (!m Next.get())216 m_pNext = new ErrorInfo(next); 217 Assert(m_pNext); 218 if (!m_pNext) 215 219 rc = E_OUTOFMEMORY; 216 220 } 217 else 218 mNext.reset(); 221 219 222 gotSomething |= SUCCEEDED(rc); 220 223 gotAll &= SUCCEEDED(rc); … … 228 231 ErrorInfo::~ErrorInfo() 229 232 { 233 if (m_pNext) 234 { 235 delete m_pNext; 236 m_pNext = NULL; 237 } 230 238 } 231 239 -
trunk/src/VBox/Main/glue/errorprint.cpp
r30676 r30681 28 28 namespace com 29 29 { 30 31 30 32 31 void GluePrintErrorInfo(com::ErrorInfo &info) … … 75 74 { 76 75 // if we have full error info, print something nice, and start with the actual error message 77 com::ErrorInfo info(iface );76 com::ErrorInfo info(iface, COM_IIDOF(IUnknown)); 78 77 if (info.isFullAvailable() || info.isBasicAvailable()) 79 78 GluePrintErrorInfo(info); -
trunk/src/VBox/Main/webservice/vboxweb.cpp
r30676 r30681 913 913 914 914 /** 915 * Raises a SOAP runtime fault. 915 * Raises a SOAP runtime fault. Implementation for the RaiseSoapRuntimeFault template 916 * function in vboxweb.h. 916 917 * 917 918 * @param pObj 918 919 */ 919 void RaiseSoapRuntimeFault(struct soap *soap, 920 HRESULT apirc, 921 IUnknown *pObj) 922 { 923 com::ErrorInfo info(pObj); 920 void RaiseSoapRuntimeFault2(struct soap *soap, 921 HRESULT apirc, 922 IUnknown *pObj, 923 const com::Guid &iid) 924 { 925 com::ErrorInfo info(pObj, iid); 924 926 925 927 WEBDEBUG((" error, raising SOAP exception\n")); -
trunk/src/VBox/Main/webservice/vboxweb.h
r30676 r30681 73 73 void RaiseSoapInvalidObjectFault(struct soap *soap, WSDLT_ID obj); 74 74 75 void RaiseSoapRuntimeFault(struct soap *soap, HRESULT apirc, IUnknown *pObj); 75 void RaiseSoapRuntimeFault2(struct soap *soap, HRESULT apirc, IUnknown *pObj, const com::Guid &iid); 76 77 /** 78 * Template function called everywhere from methodmaps.cpp which calls 79 * RaiseSoapRuntimeFault2() with the correct COM interface ID. 80 * @param soap 81 * @param apirc 82 * @param pObj 83 */ 84 template <class T> 85 void RaiseSoapRuntimeFault(struct soap *soap, HRESULT apirc, const ComPtr<T> &pObj) 86 { 87 RaiseSoapRuntimeFault2(soap, apirc, pObj, COM_IIDOF(T)); 88 } 76 89 77 90 /****************************************************************************
Note:
See TracChangeset
for help on using the changeset viewer.