Changeset 26046 in vbox for trunk/src/VBox/Main/include/MachineImpl.h
- Timestamp:
- Jan 26, 2010 2:06:05 PM (15 years ago)
- svn:sync-xref-src-repo-rev:
- 56959
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Main/include/MachineImpl.h
r26044 r26046 94 94 95 95 enum InitMode { Init_New, Init_Import, Init_Registered }; 96 97 enum StateDependency 98 { 99 AnyStateDep = 0, MutableStateDep, MutableOrSavedStateDep 100 }; 96 101 97 102 /** … … 334 339 AttachmentList mAttachments; 335 340 }; 336 337 enum StateDependency338 {339 AnyStateDep = 0, MutableStateDep, MutableOrSavedStateDep340 };341 342 /**343 * Helper class that safely manages the machine state dependency by344 * calling Machine::addStateDependency() on construction and345 * Machine::releaseStateDependency() on destruction. Intended for Machine346 * children. The usage pattern is:347 *348 * @code349 * AutoCaller autoCaller(this);350 * if (FAILED(autoCaller.rc())) return autoCaller.rc();351 *352 * Machine::AutoStateDependency<MutableStateDep> adep(mParent);353 * if (FAILED(stateDep.rc())) return stateDep.rc();354 * ...355 * // code that depends on the particular machine state356 * ...357 * @endcode358 *359 * Note that it is more convenient to use the following individual360 * shortcut classes instead of using this template directly:361 * AutoAnyStateDependency, AutoMutableStateDependency and362 * AutoMutableOrSavedStateDependency. The usage pattern is exactly the363 * same as above except that there is no need to specify the template364 * argument because it is already done by the shortcut class.365 *366 * @param taDepType Dependecy type to manage.367 */368 template <StateDependency taDepType = AnyStateDep>369 class AutoStateDependency370 {371 public:372 373 AutoStateDependency(Machine *aThat)374 : mThat(aThat), mRC(S_OK)375 , mMachineState(MachineState_Null)376 , mRegistered(FALSE)377 {378 Assert(aThat);379 mRC = aThat->addStateDependency(taDepType, &mMachineState,380 &mRegistered);381 }382 ~AutoStateDependency()383 {384 if (SUCCEEDED(mRC))385 mThat->releaseStateDependency();386 }387 388 /** Decreases the number of dependencies before the instance is389 * destroyed. Note that will reset #rc() to E_FAIL. */390 void release()391 {392 AssertReturnVoid(SUCCEEDED(mRC));393 mThat->releaseStateDependency();394 mRC = E_FAIL;395 }396 397 /** Restores the number of callers after by #release(). #rc() will be398 * reset to the result of calling addStateDependency() and must be399 * rechecked to ensure the operation succeeded. */400 void add()401 {402 AssertReturnVoid(!SUCCEEDED(mRC));403 mRC = mThat->addStateDependency(taDepType, &mMachineState,404 &mRegistered);405 }406 407 /** Returns the result of Machine::addStateDependency(). */408 HRESULT rc() const { return mRC; }409 410 /** Shortcut to SUCCEEDED(rc()). */411 bool isOk() const { return SUCCEEDED(mRC); }412 413 /** Returns the machine state value as returned by414 * Machine::addStateDependency(). */415 MachineState_T machineState() const { return mMachineState; }416 417 /** Returns the machine state value as returned by418 * Machine::addStateDependency(). */419 BOOL machineRegistered() const { return mRegistered; }420 421 protected:422 423 Machine *mThat;424 HRESULT mRC;425 MachineState_T mMachineState;426 BOOL mRegistered;427 428 private:429 430 DECLARE_CLS_COPY_CTOR_ASSIGN_NOOP(AutoStateDependency)431 DECLARE_CLS_NEW_DELETE_NOOP(AutoStateDependency)432 };433 434 /**435 * Shortcut to AutoStateDependency<AnyStateDep>.436 * See AutoStateDependency to get the usage pattern.437 *438 * Accepts any machine state and guarantees the state won't change before439 * this object is destroyed. If the machine state cannot be protected (as440 * a result of the state change currently in progress), this instance's441 * #rc() method will indicate a failure, and the caller is not allowed to442 * rely on any particular machine state and should return the failed443 * result code to the upper level.444 */445 typedef AutoStateDependency<AnyStateDep> AutoAnyStateDependency;446 447 /**448 * Shortcut to AutoStateDependency<MutableStateDep>.449 * See AutoStateDependency to get the usage pattern.450 *451 * Succeeds only if the machine state is in one of the mutable states, and452 * guarantees the given mutable state won't change before this object is453 * destroyed. If the machine is not mutable, this instance's #rc() method454 * will indicate a failure, and the caller is not allowed to rely on any455 * particular machine state and should return the failed result code to456 * the upper level.457 *458 * Intended to be used within all setter methods of IMachine459 * children objects (DVDDrive, NetworkAdapter, AudioAdapter, etc.) to460 * provide data protection and consistency.461 */462 typedef AutoStateDependency<MutableStateDep> AutoMutableStateDependency;463 464 /**465 * Shortcut to AutoStateDependency<MutableOrSavedStateDep>.466 * See AutoStateDependency to get the usage pattern.467 *468 * Succeeds only if the machine state is in one of the mutable states, or469 * if the machine is in the Saved state, and guarantees the given mutable470 * state won't change before this object is destroyed. If the machine is471 * not mutable, this instance's #rc() method will indicate a failure, and472 * the caller is not allowed to rely on any particular machine state and473 * should return the failed result code to the upper level.474 *475 * Intended to be used within setter methods of IMachine476 * children objects that may also operate on Saved machines.477 */478 typedef AutoStateDependency<MutableOrSavedStateDep> AutoMutableOrSavedStateDependency;479 480 341 481 342 VIRTUALBOXBASE_ADD_ERRORINFO_SUPPORT(Machine)
Note:
See TracChangeset
for help on using the changeset viewer.