Changeset 23636 in vbox for trunk/src/VBox/Main
- Timestamp:
- Oct 9, 2009 11:18:56 AM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Main/include/VirtualBoxBase.h
r23327 r23636 138 138 */ 139 139 #if defined (DEBUG) 140 #define ComAssert(expr) Assert 140 #define ComAssert(expr) Assert(expr) 141 141 #else 142 142 #define ComAssert(expr) \ 143 143 do { \ 144 if ( !(expr)) \145 setError 146 147 144 if (RT_UNLIKELY(!(expr))) \ 145 setError(E_FAIL, "Assertion failed: [%s] at '%s' (%d) in %s.\n" \ 146 "Please contact the product vendor!", \ 147 #expr, __FILE__, __LINE__, __PRETTY_FUNCTION__); \ 148 148 } while (0) 149 149 #endif … … 159 159 */ 160 160 #if defined (DEBUG) 161 #define ComAssertMsg(expr, a) AssertMsg 161 #define ComAssertMsg(expr, a) AssertMsg(expr, a) 162 162 #else 163 163 #define ComAssertMsg(expr, a) \ 164 164 do { \ 165 if ( !(expr)) \166 setError 167 168 169 165 if (RT_UNLIKELY(!(expr))) \ 166 setError(E_FAIL, "Assertion failed: [%s] at '%s' (%d) in %s.\n" \ 167 "%s.\n" \ 168 "Please contact the product vendor!", \ 169 #expr, __FILE__, __LINE__, __PRETTY_FUNCTION__, Utf8StrFmt a .raw()); \ 170 170 } while (0) 171 171 #endif … … 180 180 */ 181 181 #if defined (DEBUG) 182 #define ComAssertRC(vrc) AssertRC 182 #define ComAssertRC(vrc) AssertRC(vrc) 183 183 #else 184 #define ComAssertRC(vrc) ComAssertMsgRC 184 #define ComAssertRC(vrc) ComAssertMsgRC(vrc, ("%Rra", vrc)) 185 185 #endif 186 186 … … 195 195 */ 196 196 #if defined (DEBUG) 197 #define ComAssertMsgRC(vrc, msg) AssertMsgRC 197 #define ComAssertMsgRC(vrc, msg) AssertMsgRC(vrc, msg) 198 198 #else 199 #define ComAssertMsgRC(vrc, msg) ComAssertMsg (RT_SUCCESS(vrc), msg)199 #define ComAssertMsgRC(vrc, msg) ComAssertMsg(RT_SUCCESS(vrc), msg) 200 200 #endif 201 201 … … 212 212 #define ComAssertFailed() \ 213 213 do { \ 214 setError 215 216 214 setError(E_FAIL, "Assertion failed at '%s' (%d) in %s.\n" \ 215 "Please contact the product vendor!", \ 216 __FILE__, __LINE__, __PRETTY_FUNCTION__); \ 217 217 } while (0) 218 218 #endif … … 231 231 #define ComAssertMsgFailed(a) \ 232 232 do { \ 233 setError 234 235 236 233 setError(E_FAIL, "Assertion failed at '%s' (%d) in %s.\n" \ 234 "%s.\n" \ 235 "Please contact the product vendor!", \ 236 __FILE__, __LINE__, __PRETTY_FUNCTION__, Utf8StrFmt a .raw()); \ 237 237 } while (0) 238 238 #endif … … 249 249 #define ComAssertMsgFailedPos(a, file, line, func) \ 250 250 do { \ 251 AssertMsg1 ((const char *) 0, line, file, func);\251 AssertMsg1((const char *)0, line, file, func); \ 252 252 AssertMsg2 a; \ 253 253 AssertBreakpoint(); \ … … 256 256 #define ComAssertMsgFailedPos(a, file, line, func) \ 257 257 do { \ 258 setError (E_FAIL,\259 "Assertion failed at '%s' (%d) in %s.\n"\260 "%s.\n"\261 "Please contact the product vendor!",\262 file, line, func, Utf8StrFmt a .raw());\258 setError(E_FAIL, \ 259 "Assertion failed at '%s' (%d) in %s.\n" \ 260 "%s.\n" \ 261 "Please contact the product vendor!", \ 262 file, line, func, Utf8StrFmt a .raw()); \ 263 263 } while (0) 264 264 #endif … … 273 273 */ 274 274 #if defined (DEBUG) 275 #define ComAssertComRC(rc) AssertComRC 275 #define ComAssertComRC(rc) AssertComRC(rc) 276 276 #else 277 #define ComAssertComRC(rc) ComAssertMsg (SUCCEEDED(rc), ("COM RC = %Rhrc (0x%08X)", (rc), (rc)))277 #define ComAssertComRC(rc) ComAssertMsg(SUCCEEDED(rc), ("COM RC = %Rhrc (0x%08X)", (rc), (rc))) 278 278 #endif 279 279 … … 281 281 /** Special version of ComAssert that returns ret if expr fails */ 282 282 #define ComAssertRet(expr, ret) \ 283 do { ComAssert 283 do { ComAssert(expr); if (!(expr)) return (ret); } while (0) 284 284 /** Special version of ComAssertMsg that returns ret if expr fails */ 285 285 #define ComAssertMsgRet(expr, a, ret) \ 286 do { ComAssertMsg 286 do { ComAssertMsg(expr, a); if (!(expr)) return (ret); } while (0) 287 287 /** Special version of ComAssertRC that returns ret if vrc does not succeed */ 288 288 #define ComAssertRCRet(vrc, ret) \ 289 do { ComAssertRC (vrc); if (!RT_SUCCESS(vrc)) return (ret); } while (0)289 do { ComAssertRC(vrc); if (!RT_SUCCESS(vrc)) return (ret); } while (0) 290 290 /** Special version of ComAssertMsgRC that returns ret if vrc does not succeed */ 291 291 #define ComAssertMsgRCRet(vrc, msg, ret) \ 292 do { ComAssertMsgRC (vrc, msg); if (!RT_SUCCESS(vrc)) return (ret); } while (0)292 do { ComAssertMsgRC(vrc, msg); if (!RT_SUCCESS(vrc)) return (ret); } while (0) 293 293 /** Special version of ComAssertFailed that returns ret */ 294 294 #define ComAssertFailedRet(ret) \ … … 296 296 /** Special version of ComAssertMsgFailed that returns ret */ 297 297 #define ComAssertMsgFailedRet(msg, ret) \ 298 do { ComAssertMsgFailed 298 do { ComAssertMsgFailed(msg); return (ret); } while (0) 299 299 /** Special version of ComAssertComRC that returns ret if rc does not succeed */ 300 300 #define ComAssertComRCRet(rc, ret) \ 301 do { ComAssertComRC (rc); if (!SUCCEEDED(rc)) return (ret); } while (0)301 do { ComAssertComRC(rc); if (!SUCCEEDED(rc)) return (ret); } while (0) 302 302 /** Special version of ComAssertComRC that returns rc if rc does not succeed */ 303 303 #define ComAssertComRCRetRC(rc) \ 304 do { ComAssertComRC (rc); if (!SUCCEEDED(rc)) return (rc); } while (0)304 do { ComAssertComRC(rc); if (!SUCCEEDED(rc)) return (rc); } while (0) 305 305 306 306 307 307 /** Special version of ComAssert that evaluates eval and breaks if expr fails */ 308 308 #define ComAssertBreak(expr, eval) \ 309 if (1) { ComAssert 309 if (1) { ComAssert(expr); if (!(expr)) { eval; break; } } else do {} while (0) 310 310 /** Special version of ComAssertMsg that evaluates eval and breaks if expr fails */ 311 311 #define ComAssertMsgBreak(expr, a, eval) \ 312 if (1) { ComAssertMsg 312 if (1) { ComAssertMsg(expr, a); if (!(expr)) { eval; break; } } else do {} while (0) 313 313 /** Special version of ComAssertRC that evaluates eval and breaks if vrc does not succeed */ 314 314 #define ComAssertRCBreak(vrc, eval) \ 315 if (1) { ComAssertRC (vrc); if (!RT_SUCCESS(vrc)) { eval; break; } } else do {} while (0)315 if (1) { ComAssertRC(vrc); if (!RT_SUCCESS(vrc)) { eval; break; } } else do {} while (0) 316 316 /** Special version of ComAssertMsgRC that evaluates eval and breaks if vrc does not succeed */ 317 317 #define ComAssertMsgRCBreak(vrc, msg, eval) \ 318 if (1) { ComAssertMsgRC (vrc, msg); if (!RT_SUCCESS(vrc)) { eval; break; } } else do {} while (0)318 if (1) { ComAssertMsgRC(vrc, msg); if (!RT_SUCCESS(vrc)) { eval; break; } } else do {} while (0) 319 319 /** Special version of ComAssertFailed that evaluates eval and breaks */ 320 320 #define ComAssertFailedBreak(eval) \ … … 325 325 /** Special version of ComAssertComRC that evaluates eval and breaks if rc does not succeed */ 326 326 #define ComAssertComRCBreak(rc, eval) \ 327 if (1) { ComAssertComRC (rc); if (!SUCCEEDED(rc)) { eval; break; } } else do {} while (0)327 if (1) { ComAssertComRC(rc); if (!SUCCEEDED(rc)) { eval; break; } } else do {} while (0) 328 328 /** Special version of ComAssertComRC that just breaks if rc does not succeed */ 329 329 #define ComAssertComRCBreakRC(rc) \ 330 if (1) { ComAssertComRC (rc); if (!SUCCEEDED(rc)) { break; } } else do {} while (0)330 if (1) { ComAssertComRC(rc); if (!SUCCEEDED(rc)) { break; } } else do {} while (0) 331 331 332 332 333 333 /** Special version of ComAssert that evaluates eval and throws it if expr fails */ 334 334 #define ComAssertThrow(expr, eval) \ 335 if (1) { ComAssert 335 if (1) { ComAssert(expr); if (!(expr)) { throw (eval); } } else do {} while (0) 336 336 /** Special version of ComAssertMsg that evaluates eval and throws it if expr fails */ 337 337 #define ComAssertMsgThrow(expr, a, eval) \ 338 if (1) { ComAssertMsg 338 if (1) { ComAssertMsg(expr, a); if (!(expr)) { throw (eval); } } else do {} while (0) 339 339 /** Special version of ComAssertRC that evaluates eval and throws it if vrc does not succeed */ 340 340 #define ComAssertRCThrow(vrc, eval) \ 341 if (1) { ComAssertRC (vrc); if (!RT_SUCCESS(vrc)) { throw (eval); } } else do {} while (0)341 if (1) { ComAssertRC(vrc); if (!RT_SUCCESS(vrc)) { throw (eval); } } else do {} while (0) 342 342 /** Special version of ComAssertMsgRC that evaluates eval and throws it if vrc does not succeed */ 343 343 #define ComAssertMsgRCThrow(vrc, msg, eval) \ 344 if (1) { ComAssertMsgRC (vrc, msg); if (!RT_SUCCESS(vrc)) { throw (eval); } } else do {} while (0)344 if (1) { ComAssertMsgRC(vrc, msg); if (!RT_SUCCESS(vrc)) { throw (eval); } } else do {} while (0) 345 345 /** Special version of ComAssertFailed that evaluates eval and throws it */ 346 346 #define ComAssertFailedThrow(eval) \ … … 351 351 /** Special version of ComAssertComRC that evaluates eval and throws it if rc does not succeed */ 352 352 #define ComAssertComRCThrow(rc, eval) \ 353 if (1) { ComAssertComRC (rc); if (!SUCCEEDED(rc)) { throw (eval); } } else do {} while (0)353 if (1) { ComAssertComRC(rc); if (!SUCCEEDED(rc)) { throw (eval); } } else do {} while (0) 354 354 /** Special version of ComAssertComRC that just throws rc if rc does not succeed */ 355 355 #define ComAssertComRCThrowRC(rc) \ 356 if (1) { ComAssertComRC (rc); if (!SUCCEEDED(rc)) { throw rc; } } else do {} while (0)356 if (1) { ComAssertComRC(rc); if (!SUCCEEDED(rc)) { throw rc; } } else do {} while (0) 357 357 358 358 //////////////////////////////////////////////////////////////////////////////// … … 365 365 #define CheckComArgNotNull(arg) \ 366 366 do { \ 367 if ( (arg) == NULL) \368 return setError (E_INVALIDARG, tr("Argument %s is NULL"), #arg); \367 if (RT_UNLIKELY((arg) == NULL)) \ 368 return setError(E_INVALIDARG, tr("Argument %s is NULL"), #arg); \ 369 369 } while (0) 370 370 … … 376 376 #define CheckComArgSafeArrayNotNull(arg) \ 377 377 do { \ 378 if ( ComSafeArrayInIsNull (arg)) \379 return setError (E_INVALIDARG, tr("Argument %s is NULL"), #arg); \378 if (RT_UNLIKELY(ComSafeArrayInIsNull(arg))) \ 379 return setError(E_INVALIDARG, tr("Argument %s is NULL"), #arg); \ 380 380 } while (0) 381 381 … … 387 387 #define CheckComArgStrNotEmptyOrNull(arg) \ 388 388 do { \ 389 if ( (arg) == NULL || *(arg) == '\0') \390 return setError 391 tr 389 if (RT_UNLIKELY((arg) == NULL || *(arg) == '\0')) \ 390 return setError(E_INVALIDARG, \ 391 tr("Argument %s is empty or NULL"), #arg); \ 392 392 } while (0) 393 393 … … 400 400 #define CheckComArgExpr(arg, expr) \ 401 401 do { \ 402 if ( !(expr)) \403 return setError 404 tr 402 if (RT_UNLIKELY(!(expr))) \ 403 return setError(E_INVALIDARG, \ 404 tr("Argument %s is invalid (must be %s)"), #arg, #expr); \ 405 405 } while (0) 406 406 … … 416 416 #define CheckComArgExprMsg(arg, expr, msg) \ 417 417 do { \ 418 if ( !(expr)) \419 return setError 420 418 if (RT_UNLIKELY(!(expr))) \ 419 return setError(E_INVALIDARG, tr ("Argument %s %s"), \ 420 #arg, Utf8StrFmt msg .raw()); \ 421 421 } while (0) 422 422 … … 428 428 #define CheckComArgOutPointerValid(arg) \ 429 429 do { \ 430 if ( !VALID_PTR (arg)) \431 return setError 432 tr 430 if (RT_UNLIKELY(!VALID_PTR(arg))) \ 431 return setError(E_POINTER, \ 432 tr("Output argument %s points to invalid memory location (%p)"), \ 433 433 #arg, (void *) (arg)); \ 434 434 } while (0) … … 441 441 #define CheckComArgOutSafeArrayPointerValid(arg) \ 442 442 do { \ 443 if ( ComSafeArrayOutIsNull (arg)) \444 return setError 445 tr 443 if (RT_UNLIKELY(ComSafeArrayOutIsNull(arg))) \ 444 return setError(E_POINTER, \ 445 tr("Output argument %s points to invalid memory location (%p)"), \ 446 446 #arg, (void *) (arg)); \ 447 447 } while (0) … … 452 452 #define ReturnComNotImplemented() \ 453 453 do { \ 454 return setError (E_NOTIMPL, tr("Method %s is not implemented"), __FUNCTION__); \454 return setError(E_NOTIMPL, tr("Method %s is not implemented"), __FUNCTION__); \ 455 455 } while (0) 456 456 … … 584 584 virtual void uninit() {} 585 585 586 virtual HRESULT addCaller 586 virtual HRESULT addCaller(State *aState = NULL, bool aLimited = false); 587 587 virtual void releaseCaller(); 588 588 … … 592 592 * better self-descriptiveness. See #addCaller() for more info. 593 593 */ 594 HRESULT addLimitedCaller 595 { 596 return addCaller 594 HRESULT addLimitedCaller(State *aState = NULL) 595 { 596 return addCaller(aState, true /* aLimited */); 597 597 } 598 598 … … 619 619 * self-descriptiveness. 620 620 */ 621 template 621 template<bool aLimited> 622 622 class AutoCallerBase 623 623 { … … 633 633 * NotReady). 634 634 */ 635 AutoCallerBase 636 : mObj 637 , mRC 638 , mState 635 AutoCallerBase(VirtualBoxBaseProto *aObj) 636 : mObj(aObj) 637 , mRC(S_OK) 638 , mState(NotReady) 639 639 { 640 640 if (mObj) 641 mRC = mObj->addCaller(&mState, aLimited);641 mRC = mObj->addCaller(&mState, aLimited); 642 642 } 643 643 … … 648 648 ~AutoCallerBase() 649 649 { 650 if (mObj && SUCCEEDED 650 if (mObj && SUCCEEDED(mRC)) 651 651 mObj->releaseCaller(); 652 652 } … … 663 663 * |true| means the number of callers was successfully increased. 664 664 */ 665 bool isOk() const { return SUCCEEDED 665 bool isOk() const { return SUCCEEDED(mRC); } 666 666 667 667 /** … … 678 678 void release() 679 679 { 680 Assert (SUCCEEDED(mRC));681 if (SUCCEEDED 680 Assert(SUCCEEDED(mRC)); 681 if (SUCCEEDED(mRC)) 682 682 { 683 683 if (mObj) … … 693 693 void add() 694 694 { 695 Assert (!SUCCEEDED(mRC));696 if (mObj && !SUCCEEDED 697 mRC = mObj->addCaller 695 Assert(!SUCCEEDED(mRC)); 696 if (mObj && !SUCCEEDED(mRC)) 697 mRC = mObj->addCaller(&mState, aLimited); 698 698 } 699 699 … … 704 704 * @param aObj New object to attach, may be @c NULL. 705 705 */ 706 void attach 706 void attach(VirtualBoxBaseProto *aObj) 707 707 { 708 708 /* detect simple self-reattachment */ 709 709 if (mObj != aObj) 710 710 { 711 if (mObj && SUCCEEDED 711 if (mObj && SUCCEEDED(mRC)) 712 712 release(); 713 713 mObj = aObj; … … 717 717 718 718 /** Verbose equivalent to <tt>attach (NULL)</tt>. */ 719 void detach() { attach 719 void detach() { attach(NULL); } 720 720 721 721 private: 722 722 723 DECLARE_CLS_COPY_CTOR_ASSIGN_NOOP 724 DECLARE_CLS_NEW_DELETE_NOOP 723 DECLARE_CLS_COPY_CTOR_ASSIGN_NOOP(AutoCallerBase) 724 DECLARE_CLS_NEW_DELETE_NOOP(AutoCallerBase) 725 725 726 726 VirtualBoxBaseProto *mObj; … … 752 752 * See AutoCallerBase for more information about auto caller functionality. 753 753 */ 754 typedef AutoCallerBase 754 typedef AutoCallerBase<false> AutoCaller; 755 755 756 756 /** … … 777 777 * See AutoCallerBase for more information about auto caller functionality. 778 778 */ 779 typedef AutoCallerBase 779 typedef AutoCallerBase<true> AutoLimitedCaller; 780 780 781 781 protected: … … 836 836 enum Result { Failed = 0x0, Succeeded = 0x1, Limited = 0x2 }; 837 837 838 AutoInitSpan 838 AutoInitSpan(VirtualBoxBaseProto *aObj, Result aResult = Failed); 839 839 ~AutoInitSpan(); 840 840 … … 873 873 private: 874 874 875 DECLARE_CLS_COPY_CTOR_ASSIGN_NOOP 876 DECLARE_CLS_NEW_DELETE_NOOP 875 DECLARE_CLS_COPY_CTOR_ASSIGN_NOOP(AutoInitSpan) 876 DECLARE_CLS_NEW_DELETE_NOOP(AutoInitSpan) 877 877 878 878 VirtualBoxBaseProto *mObj; … … 930 930 public: 931 931 932 AutoReinitSpan 932 AutoReinitSpan(VirtualBoxBaseProto *aObj); 933 933 ~AutoReinitSpan(); 934 934 … … 948 948 private: 949 949 950 DECLARE_CLS_COPY_CTOR_ASSIGN_NOOP 951 DECLARE_CLS_NEW_DELETE_NOOP 950 DECLARE_CLS_COPY_CTOR_ASSIGN_NOOP(AutoReinitSpan) 951 DECLARE_CLS_NEW_DELETE_NOOP(AutoReinitSpan) 952 952 953 953 VirtualBoxBaseProto *mObj; … … 999 999 public: 1000 1000 1001 AutoUninitSpan 1001 AutoUninitSpan(VirtualBoxBaseProto *aObj); 1002 1002 ~AutoUninitSpan(); 1003 1003 … … 1010 1010 private: 1011 1011 1012 DECLARE_CLS_COPY_CTOR_ASSIGN_NOOP 1013 DECLARE_CLS_NEW_DELETE_NOOP 1012 DECLARE_CLS_COPY_CTOR_ASSIGN_NOOP(AutoUninitSpan) 1013 DECLARE_CLS_NEW_DELETE_NOOP(AutoUninitSpan) 1014 1014 1015 1015 VirtualBoxBaseProto *mObj; … … 1070 1070 public: 1071 1071 1072 AutoMayUninitSpan 1072 AutoMayUninitSpan(VirtualBoxBaseProto *aObj); 1073 1073 ~AutoMayUninitSpan(); 1074 1074 … … 1095 1095 private: 1096 1096 1097 DECLARE_CLS_COPY_CTOR_ASSIGN_NOOP 1098 DECLARE_CLS_NEW_DELETE_NOOP 1097 DECLARE_CLS_COPY_CTOR_ASSIGN_NOOP(AutoMayUninitSpan) 1098 DECLARE_CLS_NEW_DELETE_NOOP(AutoMayUninitSpan) 1099 1099 1100 1100 VirtualBoxBaseProto *mObj; … … 1115 1115 private: 1116 1116 1117 void setState 1118 { 1119 Assert 1117 void setState(State aState) 1118 { 1119 Assert(mState != aState); 1120 1120 mState = aState; 1121 1121 mStateChangeThread = RTThreadSelf(); … … 1160 1160 */ 1161 1161 #define VIRTUALBOXBASE_ADD_ERRORINFO_SUPPORT(C) \ 1162 virtual HRESULT addCaller 1163 1162 virtual HRESULT addCaller(VirtualBoxBaseProto::State *aState = NULL, \ 1163 bool aLimited = false) \ 1164 1164 { \ 1165 1165 VirtualBoxBaseProto::State state; \ 1166 HRESULT rc = VirtualBoxBaseProto::addCaller 1167 if (FAILED 1166 HRESULT rc = VirtualBoxBaseProto::addCaller(&state, aLimited); \ 1167 if (FAILED(rc)) \ 1168 1168 { \ 1169 1169 if (state == VirtualBoxBaseProto::Limited) \ 1170 rc = setError (rc, tr("The object functionality is limited")); \1170 rc = setError(rc, tr("The object functionality is limited")); \ 1171 1171 else \ 1172 rc = setError (rc, tr("The object is not ready")); \1172 rc = setError(rc, tr("The object is not ready")); \ 1173 1173 } \ 1174 1174 if (aState) \ … … 1181 1181 class ATL_NO_VTABLE VirtualBoxBase 1182 1182 : virtual public VirtualBoxBaseProto 1183 , public CComObjectRootEx 1183 , public CComObjectRootEx<CComMultiThreadModel> 1184 1184 { 1185 1185 … … 1201 1201 {} 1202 1202 1203 static const char *translate 1204 1203 static const char *translate(const char *context, const char *sourceText, 1204 const char *comment = 0); 1205 1205 }; 1206 1206 … … 1211 1211 { 1212 1212 protected: 1213 static bool cutClassNameFrom__PRETTY_FUNCTION__ 1213 static bool cutClassNameFrom__PRETTY_FUNCTION__(char *aPrettyFunctionName); 1214 1214 }; 1215 1215 … … 1236 1236 * ambiguity of the #tr() function). 1237 1237 */ 1238 template 1238 template<class C> 1239 1239 class VirtualBoxSupportTranslation : virtual protected VirtualBoxSupportTranslationBase 1240 1240 { … … 1254 1254 * specified context. 1255 1255 */ 1256 inline static const char *tr 1257 1258 { 1259 return VirtualBoxBase::translate 1256 inline static const char *tr(const char *aSourceText, 1257 const char *aComment = NULL) 1258 { 1259 return VirtualBoxBase::translate(className(), aSourceText, aComment); 1260 1260 } 1261 1261 … … 1264 1264 static const char *className() 1265 1265 { 1266 static char fn [sizeof(__PRETTY_FUNCTION__) + 1];1266 static char fn[sizeof(__PRETTY_FUNCTION__) + 1]; 1267 1267 if (!sClassName) 1268 1268 { 1269 strcpy 1270 cutClassNameFrom__PRETTY_FUNCTION__ 1269 strcpy(fn, __PRETTY_FUNCTION__); 1270 cutClassNameFrom__PRETTY_FUNCTION__(fn); 1271 1271 sClassName = fn; 1272 1272 } … … 1279 1279 }; 1280 1280 1281 template 1281 template<class C> 1282 1282 const char *VirtualBoxSupportTranslation<C>::sClassName = NULL; 1283 1283 … … 1292 1292 */ 1293 1293 #define VIRTUALBOXSUPPORTTRANSLATION_OVERRIDE(C) \ 1294 inline static const char *tr 1295 1294 inline static const char *tr(const char *aSourceText, \ 1295 const char *aComment = NULL) \ 1296 1296 { \ 1297 return VirtualBoxSupportTranslation<C>::tr 1297 return VirtualBoxSupportTranslation<C>::tr(aSourceText, aComment); \ 1298 1298 } 1299 1299 … … 1314 1314 class VirtualBoxSupportErrorInfoImplBase 1315 1315 { 1316 static HRESULT setErrorInternal 1317 1318 1316 static HRESULT setErrorInternal(HRESULT aResultCode, const GUID &aIID, 1317 const Bstr &aComponent, const Bstr &aText, 1318 bool aWarning, bool aLogIt); 1319 1319 1320 1320 protected: … … 1401 1401 * @copydoc com::FWResult::FWResult(). 1402 1402 */ 1403 MultiResult (HRESULT aRC = E_FAIL) : FWResult(aRC) { init(); }1404 1405 MultiResult (const MultiResult &aThat) : FWResult(aThat)1403 MultiResult(HRESULT aRC = E_FAIL) : FWResult(aRC) { init(); } 1404 1405 MultiResult(const MultiResult &aThat) : FWResult(aThat) 1406 1406 { 1407 1407 /* We need this copy constructor only for GCC that wants to have … … 1415 1415 ~MultiResult(); 1416 1416 1417 MultiResult &operator= 1417 MultiResult &operator=(HRESULT aRC) 1418 1418 { 1419 com::FWResult::operator= 1419 com::FWResult::operator=(aRC); 1420 1420 return *this; 1421 1421 } 1422 1422 1423 MultiResult &operator= 1423 MultiResult &operator=(const MultiResult &aThat) 1424 1424 { 1425 1425 /* We need this copy constructor only for GCC that wants to have … … 1428 1428 * temporary and call the other constructor directly instead. */ 1429 1429 AssertFailed(); 1430 com::FWResult::operator= 1430 com::FWResult::operator=(aThat); 1431 1431 return *this; 1432 1432 } … … 1434 1434 private: 1435 1435 1436 DECLARE_CLS_NEW_DELETE_NOOP 1436 DECLARE_CLS_NEW_DELETE_NOOP(MultiResult) 1437 1437 1438 1438 void init(); … … 1443 1443 }; 1444 1444 1445 static HRESULT setError 1446 1447 1448 1449 { 1450 return setErrorInternal 1451 1452 } 1453 1454 static HRESULT setWarning 1455 1456 1457 { 1458 return setErrorInternal 1459 1460 } 1461 1462 static HRESULT setError 1463 1464 1465 { 1466 return setErrorInternal 1467 1468 1469 } 1470 1471 static HRESULT setWarning 1472 1473 1474 { 1475 return setErrorInternal 1476 1477 1445 static HRESULT setError(HRESULT aResultCode, const GUID &aIID, 1446 const Bstr &aComponent, 1447 const Bstr &aText, 1448 bool aLogIt = true) 1449 { 1450 return setErrorInternal(aResultCode, aIID, aComponent, aText, 1451 false /* aWarning */, aLogIt); 1452 } 1453 1454 static HRESULT setWarning(HRESULT aResultCode, const GUID &aIID, 1455 const Bstr &aComponent, 1456 const Bstr &aText) 1457 { 1458 return setErrorInternal(aResultCode, aIID, aComponent, aText, 1459 true /* aWarning */, true /* aLogIt */); 1460 } 1461 1462 static HRESULT setError(HRESULT aResultCode, const GUID &aIID, 1463 const Bstr &aComponent, 1464 const char *aText, va_list aArgs, bool aLogIt = true) 1465 { 1466 return setErrorInternal(aResultCode, aIID, aComponent, 1467 Utf8StrFmtVA (aText, aArgs), 1468 false /* aWarning */, aLogIt); 1469 } 1470 1471 static HRESULT setWarning(HRESULT aResultCode, const GUID &aIID, 1472 const Bstr &aComponent, 1473 const char *aText, va_list aArgs) 1474 { 1475 return setErrorInternal(aResultCode, aIID, aComponent, 1476 Utf8StrFmtVA (aText, aArgs), 1477 true /* aWarning */, true /* aLogIt */); 1478 1478 } 1479 1479 }; … … 1503 1503 */ 1504 1504 /// @todo switch to com::SupportErrorInfo* and remove 1505 template 1505 template<class C, class I> 1506 1506 class ATL_NO_VTABLE VirtualBoxSupportErrorInfoImpl 1507 1507 : protected VirtualBoxSupportErrorInfoImplBase … … 1514 1514 1515 1515 #if !defined (VBOX_WITH_XPCOM) 1516 STDMETHOD(InterfaceSupportsErrorInfo) 1516 STDMETHOD(InterfaceSupportsErrorInfo)(REFIID riid) 1517 1517 { 1518 1518 const _ATL_INTMAP_ENTRY* pEntries = C::_GetEntries(); 1519 Assert 1519 Assert(pEntries); 1520 1520 if (!pEntries) 1521 1521 return S_FALSE; … … 1530 1530 // skip the com map entries until ISupportErrorInfo is found 1531 1531 bISupportErrorInfoFound = 1532 InlineIsEqualGUID 1532 InlineIsEqualGUID(*(pEntries->piid), IID_ISupportErrorInfo); 1533 1533 } 1534 1534 else 1535 1535 { 1536 1536 // look for the requested interface in the rest of the com map 1537 bSupports = InlineIsEqualGUID 1537 bSupports = InlineIsEqualGUID(*(pEntries->piid), riid); 1538 1538 } 1539 1539 pEntries++; 1540 1540 } 1541 1541 1542 Assert 1542 Assert(bISupportErrorInfoFound); 1543 1543 1544 1544 return bSupports ? S_OK : S_FALSE; … … 1588 1588 * error argument. 1589 1589 */ 1590 static HRESULT setError 1591 1592 1590 static HRESULT setError(HRESULT aResultCode, const GUID &aIID, 1591 const wchar_t *aComponent, 1592 const char *aText, ...) 1593 1593 { 1594 1594 va_list args; 1595 va_start 1596 HRESULT rc = VirtualBoxSupportErrorInfoImplBase::setError 1597 (aResultCode, aIID, aComponent, aText, args, true /* aLogIt */);1598 va_end 1595 va_start(args, aText); 1596 HRESULT rc = VirtualBoxSupportErrorInfoImplBase::setError( 1597 aResultCode, aIID, aComponent, aText, args, true /* aLogIt */); 1598 va_end(args); 1599 1599 return rc; 1600 1600 } … … 1609 1609 * behavior may be non-standard on some COM platforms. 1610 1610 */ 1611 static HRESULT setWarning 1612 1613 1611 static HRESULT setWarning(HRESULT aResultCode, const GUID &aIID, 1612 const wchar_t *aComponent, 1613 const char *aText, ...) 1614 1614 { 1615 1615 va_list args; 1616 va_start 1617 HRESULT rc = VirtualBoxSupportErrorInfoImplBase::setWarning 1618 (aResultCode, aIID, aComponent, aText, args);1619 va_end 1616 va_start(args, aText); 1617 HRESULT rc = VirtualBoxSupportErrorInfoImplBase::setWarning( 1618 aResultCode, aIID, aComponent, aText, args); 1619 va_end(args); 1620 1620 return rc; 1621 1621 } … … 1644 1644 * </code> 1645 1645 */ 1646 static HRESULT setError 1646 static HRESULT setError(HRESULT aResultCode, const char *aText, ...) 1647 1647 { 1648 1648 va_list args; 1649 va_start 1650 HRESULT rc = VirtualBoxSupportErrorInfoImplBase::setError 1651 (aResultCode, COM_IIDOF(I), C::getComponentName(), aText, args, true /* aLogIt */);1652 va_end 1649 va_start(args, aText); 1650 HRESULT rc = VirtualBoxSupportErrorInfoImplBase::setError( 1651 aResultCode, COM_IIDOF(I), C::getComponentName(), aText, args, true /* aLogIt */); 1652 va_end(args); 1653 1653 return rc; 1654 1654 } … … 1663 1663 * behavior may be non-standard on some COM platforms. 1664 1664 */ 1665 static HRESULT setWarning 1665 static HRESULT setWarning(HRESULT aResultCode, const char *aText, ...) 1666 1666 { 1667 1667 va_list args; 1668 va_start 1669 HRESULT rc = VirtualBoxSupportErrorInfoImplBase::setWarning 1670 (aResultCode, COM_IIDOF(I), C::getComponentName(), aText, args);1671 va_end 1668 va_start(args, aText); 1669 HRESULT rc = VirtualBoxSupportErrorInfoImplBase::setWarning( 1670 aResultCode, COM_IIDOF(I), C::getComponentName(), aText, args); 1671 va_end(args); 1672 1672 return rc; 1673 1673 } … … 1682 1682 * and #setError (HRESULT, const char *, ...) for details. 1683 1683 */ 1684 static HRESULT setErrorV 1685 1686 { 1687 HRESULT rc = VirtualBoxSupportErrorInfoImplBase::setError 1688 (aResultCode, COM_IIDOF(I), C::getComponentName(), aText, aArgs, true /* aLogIt */);1684 static HRESULT setErrorV(HRESULT aResultCode, const char *aText, 1685 va_list aArgs) 1686 { 1687 HRESULT rc = VirtualBoxSupportErrorInfoImplBase::setError( 1688 aResultCode, COM_IIDOF(I), C::getComponentName(), aText, aArgs, true /* aLogIt */); 1689 1689 return rc; 1690 1690 } … … 1699 1699 * behavior may be non-standard on some COM platforms. 1700 1700 */ 1701 static HRESULT setWarningV 1702 1703 { 1704 HRESULT rc = VirtualBoxSupportErrorInfoImplBase::setWarning 1705 (aResultCode, COM_IIDOF(I), C::getComponentName(), aText, aArgs);1701 static HRESULT setWarningV(HRESULT aResultCode, const char *aText, 1702 va_list aArgs) 1703 { 1704 HRESULT rc = VirtualBoxSupportErrorInfoImplBase::setWarning( 1705 aResultCode, COM_IIDOF(I), C::getComponentName(), aText, aArgs); 1706 1706 return rc; 1707 1707 } … … 1719 1719 * and #setError (HRESULT, const char *, ...) for details. 1720 1720 */ 1721 static HRESULT setErrorBstr 1722 { 1723 HRESULT rc = VirtualBoxSupportErrorInfoImplBase::setError 1724 (aResultCode, COM_IIDOF(I), C::getComponentName(), aText, true /* aLogIt */);1721 static HRESULT setErrorBstr(HRESULT aResultCode, const Bstr &aText) 1722 { 1723 HRESULT rc = VirtualBoxSupportErrorInfoImplBase::setError( 1724 aResultCode, COM_IIDOF(I), C::getComponentName(), aText, true /* aLogIt */); 1725 1725 return rc; 1726 1726 } … … 1735 1735 * behavior may be non-standard on some COM platforms. 1736 1736 */ 1737 static HRESULT setWarningBstr 1738 { 1739 HRESULT rc = VirtualBoxSupportErrorInfoImplBase::setWarning 1740 (aResultCode, COM_IIDOF(I), C::getComponentName(), aText);1737 static HRESULT setWarningBstr(HRESULT aResultCode, const Bstr &aText) 1738 { 1739 HRESULT rc = VirtualBoxSupportErrorInfoImplBase::setWarning( 1740 aResultCode, COM_IIDOF(I), C::getComponentName(), aText); 1741 1741 return rc; 1742 1742 } … … 1751 1751 * for details. 1752 1752 */ 1753 static HRESULT setError 1754 1753 static HRESULT setError(HRESULT aResultCode, const GUID &aIID, 1754 const char *aText, ...) 1755 1755 { 1756 1756 va_list args; 1757 va_start 1758 HRESULT rc = VirtualBoxSupportErrorInfoImplBase::setError 1759 (aResultCode, aIID, C::getComponentName(), aText, args, true /* aLogIt */);1760 va_end 1757 va_start(args, aText); 1758 HRESULT rc = VirtualBoxSupportErrorInfoImplBase::setError( 1759 aResultCode, aIID, C::getComponentName(), aText, args, true /* aLogIt */); 1760 va_end(args); 1761 1761 return rc; 1762 1762 } … … 1771 1771 * behavior may be non-standard on some COM platforms. 1772 1772 */ 1773 static HRESULT setWarning 1774 1773 static HRESULT setWarning(HRESULT aResultCode, const GUID &aIID, 1774 const char *aText, ...) 1775 1775 { 1776 1776 va_list args; 1777 va_start 1778 HRESULT rc = VirtualBoxSupportErrorInfoImplBase::setWarning 1779 (aResultCode, aIID, C::getComponentName(), aText, args);1780 va_end 1777 va_start(args, aText); 1778 HRESULT rc = VirtualBoxSupportErrorInfoImplBase::setWarning( 1779 aResultCode, aIID, C::getComponentName(), aText, args); 1780 va_end(args); 1781 1781 return rc; 1782 1782 } … … 1789 1789 * It is otherwise identical to #setError (HRESULT, const char *text, ...). 1790 1790 */ 1791 static HRESULT setErrorNoLog 1791 static HRESULT setErrorNoLog(HRESULT aResultCode, const char *aText, ...) 1792 1792 { 1793 1793 va_list args; 1794 va_start 1795 HRESULT rc = VirtualBoxSupportErrorInfoImplBase::setError 1796 (aResultCode, COM_IIDOF(I), C::getComponentName(), aText, args, false /* aLogIt */);1797 va_end 1794 va_start(args, aText); 1795 HRESULT rc = VirtualBoxSupportErrorInfoImplBase::setError( 1796 aResultCode, COM_IIDOF(I), C::getComponentName(), aText, args, false /* aLogIt */); 1797 va_end(args); 1798 1798 return rc; 1799 1799 } … … 1901 1901 * @note Locks #childrenLock() for writing. 1902 1902 */ 1903 template 1904 void addDependentChild 1905 { 1906 AssertReturnVoid 1907 doAddDependentChild (ComPtr<IUnknown>(aChild), aChild);1903 template<class C> 1904 void addDependentChild(C *aChild) 1905 { 1906 AssertReturnVoid(aChild != NULL); 1907 doAddDependentChild(ComPtr<IUnknown>(aChild), aChild); 1908 1908 } 1909 1909 … … 1912 1912 * but takes a ComObjPtr<C> argument. 1913 1913 */ 1914 template 1915 void addDependentChild 1916 { 1917 AssertReturnVoid 1918 doAddDependentChild (ComPtr<IUnknown> (static_cast <C *>(aChild)), aChild);1914 template<class C> 1915 void addDependentChild(const ComObjPtr<C> &aChild) 1916 { 1917 AssertReturnVoid(!aChild.isNull()); 1918 doAddDependentChild(ComPtr<IUnknown>(static_cast<C *>(aChild)), aChild); 1919 1919 } 1920 1920 … … 1946 1946 * @note Locks #childrenLock() for writing. 1947 1947 */ 1948 template 1949 void removeDependentChild 1950 { 1951 AssertReturnVoid 1952 doRemoveDependentChild (ComPtr<IUnknown>(aChild));1948 template<class C> 1949 void removeDependentChild(C *aChild) 1950 { 1951 AssertReturnVoid(aChild != NULL); 1952 doRemoveDependentChild(ComPtr<IUnknown>(aChild)); 1953 1953 } 1954 1954 … … 1957 1957 * but takes a ComObjPtr<C> argument. 1958 1958 */ 1959 template 1960 void removeDependentChild 1961 { 1962 AssertReturnVoid 1963 doRemoveDependentChild (ComPtr<IUnknown> (static_cast <C *>(aChild)));1959 template<class C> 1960 void removeDependentChild(const ComObjPtr<C> &aChild) 1961 { 1962 AssertReturnVoid(!aChild.isNull()); 1963 doRemoveDependentChild(ComPtr<IUnknown>(static_cast<C *>(aChild))); 1964 1964 } 1965 1965 … … 1972 1972 private: 1973 1973 void doAddDependentChild(IUnknown *aUnk, VirtualBoxBase *aChild); 1974 void doRemoveDependentChild 1974 void doRemoveDependentChild(IUnknown *aUnk); 1975 1975 1976 1976 typedef std::map<IUnknown*, VirtualBoxBase*> DependentChildren; … … 2007 2007 * has gone. 2008 2008 */ 2009 template 2009 template<class C> 2010 2010 class VirtualBoxBaseWithTypedChildren : public VirtualBoxBase 2011 2011 { 2012 2012 public: 2013 2013 2014 typedef std::list 2014 typedef std::list<ComObjPtr<C> > DependentChildren; 2015 2015 2016 2016 VirtualBoxBaseWithTypedChildren() … … 2050 2050 * @note Locks #childrenLock() for writing. 2051 2051 */ 2052 void addDependentChild 2053 { 2054 AssertReturnVoid 2055 2056 AutoCaller autoCaller 2052 void addDependentChild(C *aChild) 2053 { 2054 AssertReturnVoid(aChild != NULL); 2055 2056 AutoCaller autoCaller(this); 2057 2057 2058 2058 /* sanity */ 2059 AssertReturnVoid 2060 2061 2062 2063 AutoWriteLock chLock 2064 mDependentChildren.push_back 2059 AssertReturnVoid(autoCaller.state() == InInit || 2060 autoCaller.state() == Ready || 2061 autoCaller.state() == Limited); 2062 2063 AutoWriteLock chLock(childrenLock()); 2064 mDependentChildren.push_back(aChild); 2065 2065 } 2066 2066 … … 2090 2090 * @note Locks #childrenLock() for writing. 2091 2091 */ 2092 void removeDependentChild 2093 { 2094 AssertReturnVoid 2095 2096 AutoCaller autoCaller 2092 void removeDependentChild(C *aChild) 2093 { 2094 AssertReturnVoid(aChild); 2095 2096 AutoCaller autoCaller(this); 2097 2097 2098 2098 /* sanity */ 2099 AssertReturnVoid 2100 2101 2102 2099 AssertReturnVoid(autoCaller.state() == InUninit || 2100 autoCaller.state() == InInit || 2101 autoCaller.state() == Ready || 2102 autoCaller.state() == Limited); 2103 2103 2104 2104 /* return shortly; we are strongly referenced so the object won't get … … 2109 2109 return; 2110 2110 2111 AutoWriteLock chLock 2112 mDependentChildren.remove 2111 AutoWriteLock chLock(childrenLock()); 2112 mDependentChildren.remove(aChild); 2113 2113 } 2114 2114 … … 2141 2141 void uninitDependentChildren() 2142 2142 { 2143 AutoCaller autoCaller 2143 AutoCaller autoCaller(this); 2144 2144 2145 2145 /* We don't want to hold the childrenLock() write lock here (necessary … … 2160 2160 * since no any object may access us by that time. 2161 2161 */ 2162 AssertReturnVoid 2163 2162 AssertReturnVoid(autoCaller.state() == InUninit || 2163 autoCaller.state() == InInit); 2164 2164 2165 2165 if (mDependentChildren.size()) … … 2169 2169 { 2170 2170 C *child = (*it); 2171 Assert 2171 Assert(child); 2172 2172 2173 2173 /* Note that if child->uninit() happens to be called on another … … 2196 2196 void removeDependentChildren() 2197 2197 { 2198 AutoWriteLock chLock 2198 AutoWriteLock chLock(childrenLock()); 2199 2199 mDependentChildren.clear(); 2200 2200 } … … 2219 2219 public: 2220 2220 2221 Shareable() : mData (NULL), mIsShared 2221 Shareable() : mData (NULL), mIsShared(FALSE) {} 2222 2222 ~Shareable() { free(); } 2223 2223 2224 void allocate() { attach 2224 void allocate() { attach(new D); } 2225 2225 2226 2226 virtual void free() { … … 2233 2233 } 2234 2234 2235 void attach 2236 AssertMsg 2235 void attach(D *data) { 2236 AssertMsg(data, ("new data must not be NULL")); 2237 2237 if (data && mData != data) { 2238 2238 if (mData && !mIsShared) … … 2243 2243 } 2244 2244 2245 void attach 2246 AssertMsg 2245 void attach(Shareable &data) { 2246 AssertMsg( 2247 2247 data.mData == mData || !data.mIsShared, 2248 2248 ("new data must not be shared") … … 2254 2254 } 2255 2255 2256 void share 2257 AssertMsg 2256 void share(D *data) { 2257 AssertMsg(data, ("new data must not be NULL")); 2258 2258 if (mData != data) { 2259 2259 if (mData && !mIsShared) … … 2264 2264 } 2265 2265 2266 void share 2267 2268 void attachCopy 2269 AssertMsg 2266 void share(const Shareable &data) { share (data.mData); } 2267 2268 void attachCopy(const D *data) { 2269 AssertMsg(data, ("data to copy must not be NULL")); 2270 2270 if (data) 2271 attach 2272 } 2273 2274 void attachCopy 2275 attachCopy 2271 attach(new D (*data)); 2272 } 2273 2274 void attachCopy(const Shareable &data) { 2275 attachCopy(data.mData); 2276 2276 } 2277 2277 … … 2288 2288 2289 2289 D *operator->() const { 2290 AssertMsg 2290 AssertMsg(mData, ("data must not be NULL")); 2291 2291 return mData; 2292 2292 } … … 2309 2309 * structure). 2310 2310 */ 2311 template 2312 class Backupable : public Shareable 2311 template<class D> 2312 class Backupable : public Shareable<D> 2313 2313 { 2314 2314 public: 2315 2315 2316 Backupable() : Shareable <D> (), mBackupData(NULL) {}2316 Backupable() : Shareable<D> (), mBackupData(NULL) {} 2317 2317 2318 2318 void free() 2319 2319 { 2320 AssertMsg 2320 AssertMsg(this->mData || !mBackupData, ("backup must be NULL if data is NULL")); 2321 2321 rollback(); 2322 Shareable 2322 Shareable<D>::free(); 2323 2323 } 2324 2324 2325 2325 D *detach() 2326 2326 { 2327 AssertMsg 2327 AssertMsg(this->mData || !mBackupData, ("backup must be NULL if data is NULL")); 2328 2328 rollback(); 2329 return Shareable 2330 } 2331 2332 void share 2333 { 2334 AssertMsg 2329 return Shareable<D>::detach(); 2330 } 2331 2332 void share(const Backupable &data) 2333 { 2334 AssertMsg(!data.isBackedUp(), ("data to share must not be backed up")); 2335 2335 if (!data.isBackedUp()) 2336 Shareable <D>::share(data.mData);2336 Shareable<D>::share(data.mData); 2337 2337 } 2338 2338 … … 2343 2343 void backup() 2344 2344 { 2345 AssertMsg 2345 AssertMsg(this->mData, ("data must not be NULL")); 2346 2346 if (this->mData && !mBackupData) 2347 2347 { 2348 2348 mBackupData = this->mData; 2349 this->mData = new D 2349 this->mData = new D(*mBackupData); 2350 2350 } 2351 2351 } … … 2409 2409 } 2410 2410 2411 void assignCopy 2412 { 2413 AssertMsg 2414 AssertMsg 2411 void assignCopy(const D *data) 2412 { 2413 AssertMsg(this->mData, ("data must not be NULL")); 2414 AssertMsg(data, ("data to copy must not be NULL")); 2415 2415 if (this->mData && data) 2416 2416 { … … 2425 2425 } 2426 2426 2427 void assignCopy 2428 { 2429 assignCopy 2427 void assignCopy(const Backupable &data) 2428 { 2429 assignCopy(data.mData); 2430 2430 } 2431 2431 … … 2437 2437 bool hasActualChanges() const 2438 2438 { 2439 AssertMsg 2439 AssertMsg(this->mData, ("data must not be NULL")); 2440 2440 return this->mData != NULL && mBackupData != NULL && 2441 2441 !(*this->mData == *mBackupData); … … 2452 2452 }; 2453 2453 2454 #endif // ____H_VIRTUALBOXBASEIMPL2455 2454 #endif // !____H_VIRTUALBOXBASEIMPL 2455
Note:
See TracChangeset
for help on using the changeset viewer.