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

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

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

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

Definition at line 578 of file MediumImpl.cpp.

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

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

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

    AutoWriteLock alock (this);

    switch (m.state)
    {
        case MediaState_Created:
        case MediaState_Inaccessible:
        case MediaState_LockedRead:
        case MediaState_LockedWrite:
            break;

        default:
            return setStateError();
    }

    HRESULT rc = canAttach (aMachineId, aSnapshotId);
    CheckComRCReturnRC (rc);

    BackRefList::iterator it =
        std::find_if (m.backRefs.begin(), m.backRefs.end(),
                      BackRef::EqualsTo (aMachineId));
    if (it == m.backRefs.end())
    {
        BackRef ref (aMachineId, aSnapshotId);
        m.backRefs.push_back (ref);

        return S_OK;
    }

    if (aSnapshotId.isEmpty())
    {
        /* sanity: no duplicate attachments */
        AssertReturn (!it->inCurState, E_FAIL);
        it->inCurState = true;

        return S_OK;
    }

    /* sanity: no duplicate attachments */
    BackRef::GuidList::const_iterator jt =
        std::find (it->snapshotIds.begin(), it->snapshotIds.end(), aSnapshotId);
    AssertReturn (jt == it->snapshotIds.end(), E_FAIL);

    it->snapshotIds.push_back (aSnapshotId);

    return S_OK;
}


Generated by  Doxygen 1.6.0   Back to index