third_party/virtualbox/src/VBox/Main/src-server/MachineImpl.cpp
/**
 *  Performs machine state checks based on the @a aDepType value. If a check
 *  fails, this method will set extended error info, otherwise it will return
 *  S_OK. It is supposed, that on failure, the caller will immediately return
 *  the return value of this method to the upper level.
 *
 *  When @a aDepType is AnyStateDep, this method always returns S_OK.
 *
 *  When @a aDepType is MutableStateDep, this method returns S_OK only if the
 *  current state of this machine object allows to change settings of the
 *  machine (i.e. the machine is not registered, or registered but not running
 *  and not saved). It is useful to call this method from Machine setters
 *  before performing any change.
 *
 *  When @a aDepType is MutableOrSavedStateDep, this method behaves the same
 *  as for MutableStateDep except that if the machine is saved, S_OK is also
 *  returned. This is useful in setters which allow changing machine
 *  properties when it is in the saved state.
 *
 *  When @a aDepType is MutableOrRunningStateDep, this method returns S_OK only
 *  if the current state of this machine object allows to change runtime
 *  changeable settings of the machine (i.e. the machine is not registered, or
 *  registered but either running or not running and not saved). It is useful
 *  to call this method from Machine setters before performing any changes to
 *  runtime changeable settings.
 *
 *  When @a aDepType is MutableOrSavedOrRunningStateDep, this method behaves
 *  the same as for MutableOrRunningStateDep except that if the machine is
 *  saved, S_OK is also returned. This is useful in setters which allow
 *  changing runtime and saved state changeable machine properties.
 *
 *  @param aDepType     Dependency type to check.
 *
 *  @note Non Machine based classes should use #i_addStateDependency() and
 *  #i_releaseStateDependency() methods or the smart AutoStateDependency
 *  template.
 *
 *  @note This method must be called from under this object's read or write
 *        lock.
 */
Performs machine state checks based on the @a aDepType value. If a check
fails, this method will set extended error info, otherwise it will return
S_OK. It is supposed, that on failure, the caller will immediately return
the return value of this method to the upper level.

When @a aDepType is AnyStateDep, this method always returns S_OK.

When @a aDepType is MutableStateDep, this method returns S_OK only if the
current state of this machine object allows to change settings of the
machine . It is useful to call this method from Machine setters
before performing any change.

When @a aDepType is MutableOrSavedStateDep, this method behaves the same
as for MutableStateDep except that if the machine is saved, S_OK is also
returned. This is useful in setters which allow changing machine
properties when it is in the saved state.

When @a aDepType is MutableOrRunningStateDep, this method returns S_OK only
if the current state of this machine object allows to change runtime
changeable settings of the machine . It is useful
to call this method from Machine setters before performing any changes to
runtime changeable settings.

When @a aDepType is MutableOrSavedOrRunningStateDep, this method behaves
the same as for MutableOrRunningStateDep except that if the machine is
saved, S_OK is also returned. This is useful in setters which allow
changing runtime and saved state changeable machine properties.

@param aDepType     Dependency type to check.

@note Non Machine based classes should use #i_addStateDependency() and
#i_releaseStateDependency() methods or the smart AutoStateDependency
template.

@note This method must be called from under this object's read or write
lock.
Performs machine state checks based on the @a aDepType value . If a check fails this method will set extended error info otherwise it will return S_OK . It is supposed that on failure the caller will immediately return the return value of this method to the upper level . When @a aDepType is AnyStateDep this method always returns S_OK . When @a aDepType is MutableStateDep this method returns S_OK only if the current state of this machine object allows to change settings of the machine . It is useful to call this method from Machine setters before performing any change . When @a aDepType is MutableOrSavedStateDep this method behaves the same as for MutableStateDep except that if the machine is saved S_OK is also returned . This is useful in setters which allow changing machine properties when it is in the saved state . When @a aDepType is MutableOrRunningStateDep this method returns S_OK only if the current state of this machine object allows to change runtime changeable settings of the machine . It is useful to call this method from Machine setters before performing any changes to runtime changeable settings . When @a aDepType is MutableOrSavedOrRunningStateDep this method behaves the same as for MutableOrRunningStateDep except that if the machine is saved S_OK is also returned . This is useful in setters which allow changing runtime and saved state changeable machine properties . @param aDepType Dependency type to check . @note Non Machine based classes should use #i_addStateDependency () and #i_releaseStateDependency () methods or the smart AutoStateDependency template . @note This method must be called from under this object ' s read or write lock .
HRESULT Machine::i_checkStateDependency(StateDependency aDepType)
{
    switch (aDepType)
    {
        case AnyStateDep:
        {
            break;
        }
        case MutableStateDep:
        {
            if (   mData->mRegistered
                && (   !i_isSessionMachine()
                    || (   mData->mMachineState != MachineState_Aborted
                        && mData->mMachineState != MachineState_Teleported
                        && mData->mMachineState != MachineState_PoweredOff
                       )
                   )
               )
                return setError(VBOX_E_INVALID_VM_STATE,
                                tr("The machine is not mutable (state is %s)"),
                                Global::stringifyMachineState(mData->mMachineState));
            break;
        }
        case MutableOrSavedStateDep:
        {
            if (   mData->mRegistered
                && (   !i_isSessionMachine()
                    || (   mData->mMachineState != MachineState_Aborted
                        && mData->mMachineState != MachineState_Teleported
                        && mData->mMachineState != MachineState_Saved
                        && mData->mMachineState != MachineState_PoweredOff
                       )
                   )
               )
                return setError(VBOX_E_INVALID_VM_STATE,
                                tr("The machine is not mutable or saved (state is %s)"),
                                Global::stringifyMachineState(mData->mMachineState));
            break;
        }
        case MutableOrRunningStateDep:
        {
            if (   mData->mRegistered
                && (   !i_isSessionMachine()
                    || (   mData->mMachineState != MachineState_Aborted
                        && mData->mMachineState != MachineState_Teleported
                        && mData->mMachineState != MachineState_PoweredOff
                        && !Global::IsOnline(mData->mMachineState)
                       )
                   )
               )
                return setError(VBOX_E_INVALID_VM_STATE,
                                tr("The machine is not mutable or running (state is %s)"),
                                Global::stringifyMachineState(mData->mMachineState));
            break;
        }
        case MutableOrSavedOrRunningStateDep:
        {
            if (   mData->mRegistered
                && (   !i_isSessionMachine()
                    || (   mData->mMachineState != MachineState_Aborted
                        && mData->mMachineState != MachineState_Teleported
                        && mData->mMachineState != MachineState_Saved
                        && mData->mMachineState != MachineState_PoweredOff
                        && !Global::IsOnline(mData->mMachineState)
                       )
                   )
               )
                return setError(VBOX_E_INVALID_VM_STATE,
                                tr("The machine is not mutable, saved or running (state is %s)"),
                                Global::stringifyMachineState(mData->mMachineState));
            break;
        }
    }
    return S_OK;
}
HRESULT Machine :: i_checkStateDependency ( StateDependency aDepType ) { switch ( aDepType ) { case AnyStateDep : { break ; } case MutableStateDep : { if ( mData -> mRegistered && ( ! i_isSessionMachine ( ) || ( mData -> mMachineState != MachineState_Aborted && mData -> mMachineState != MachineState_Teleported && mData -> mMachineState != MachineState_PoweredOff ) ) ) return setError ( VBOX_E_INVALID_VM_STATE , tr ( " " ) , Global :: stringifyMachineState ( mData -> mMachineState ) ) ; break ; } case MutableOrSavedStateDep : { if ( mData -> mRegistered && ( ! i_isSessionMachine ( ) || ( mData -> mMachineState != MachineState_Aborted && mData -> mMachineState != MachineState_Teleported && mData -> mMachineState != MachineState_Saved && mData -> mMachineState != MachineState_PoweredOff ) ) ) return setError ( VBOX_E_INVALID_VM_STATE , tr ( " " ) , Global :: stringifyMachineState ( mData -> mMachineState ) ) ; break ; } case MutableOrRunningStateDep : { if ( mData -> mRegistered && ( ! i_isSessionMachine ( ) || ( mData -> mMachineState != MachineState_Aborted && mData -> mMachineState != MachineState_Teleported && mData -> mMachineState != MachineState_PoweredOff && ! Global :: IsOnline ( mData -> mMachineState ) ) ) ) return setError ( VBOX_E_INVALID_VM_STATE , tr ( " " ) , Global :: stringifyMachineState ( mData -> mMachineState ) ) ; break ; } case MutableOrSavedOrRunningStateDep : { if ( mData -> mRegistered && ( ! i_isSessionMachine ( ) || ( mData -> mMachineState != MachineState_Aborted && mData -> mMachineState != MachineState_Teleported && mData -> mMachineState != MachineState_Saved && mData -> mMachineState != MachineState_PoweredOff && ! Global :: IsOnline ( mData -> mMachineState ) ) ) ) return setError ( VBOX_E_INVALID_VM_STATE , tr ( " " ) , Global :: stringifyMachineState ( mData -> mMachineState ) ) ; break ; } } return S_OK ; }
Performs machine state checks based on the @a aDepType value.
Performs machine state checks based on the @a aDepType value .