Logo Search packages:      
Sourcecode: virtualbox-ose version File versions

HRESULT MediumBase::detachFrom ( const Guid aMachineId,
const Guid aSnapshotId = Guid::Empty 
)

Removes the given machine and optionally the snapshot from the list of the objects this image is attached to.

Parameters:
aMachineId Machine ID.
aSnapshotId Snapshot ID; when non-empty, removes the snapshot attachment.

Definition at line 641 of file MediumImpl.cpp.

References AssertComRCReturnRC, AssertReturn, and com::Guid::isEmpty().

{
    AssertReturn (!aMachineId.isEmpty(), E_FAIL);

    AutoCaller autoCaller (this);
    AssertComRCReturnRC (autoCaller.rc());

    AutoWriteLock alock (this);

    BackRefList::iterator it =
        std::find_if (m.backRefs.begin(), m.backRefs.end(),
                      BackRef::EqualsTo (aMachineId));
    AssertReturn (it != m.backRefs.end(), E_FAIL);

    if (aSnapshotId.isEmpty())
    {
        /* remove the current state attachment */
        it->inCurState = false;
    }
    else
    {
        /* remove the snapshot attachment */
        BackRef::GuidList::iterator jt =
            std::find (it->snapshotIds.begin(), it->snapshotIds.end(), aSnapshotId);

        AssertReturn (jt != it->snapshotIds.end(), E_FAIL);
        it->snapshotIds.erase (jt);
    }

    /* if the backref becomes empty, remove it */
    if (it->inCurState == false && it->snapshotIds.size() == 0)
        m.backRefs.erase (it);

    return S_OK;
}


Generated by  Doxygen 1.6.0   Back to index