VirtualBox

Changeset 23914 in vbox


Ignore:
Timestamp:
Oct 20, 2009 4:31:36 PM (15 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
53716
Message:

Main/MediumAttachment: very ugly fix for the fact that MediumAttachment instances can't have references to StorageController objects, because the reference would be invalid after changed settings are saved.

Location:
trunk/src/VBox/Main
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Main/MachineImpl.cpp

    r23911 r23914  
    309309        while (thatIt != thatAtts.end())
    310310        {
    311             if ((*it)->controller() == (*thatIt)->controller() &&
    312                 (*it)->port() == (*thatIt)->port() &&
    313                 (*it)->device() == (*thatIt)->device() &&
     311            if ((*it)->matches((*thatIt)->controllerName(),
     312                               (*thatIt)->port(),
     313                               (*thatIt)->device()) &&
    314314                (*it)->passthrough() == (*thatIt)->passthrough() &&
    315315                (*it)->medium().equalsTo ((*thatIt)->medium()))
     
    24332433    ComObjPtr<MediumAttachment> attachment;
    24342434    attachment.createObject();
    2435     rc = attachment->init(this, medium, ctl, aControllerPort, aDevice, aType, indirect);
     2435    rc = attachment->init(this, medium, aControllerName, aControllerPort, aDevice, aType, indirect);
    24362436    CheckComRCReturnRC(rc);
    24372437
     
    35583558         ++it)
    35593559    {
    3560         if (Bstr((*it)->controller()->name()) == aName)
     3560        if (Bstr((*it)->controllerName()) == aName)
    35613561            return setError(VBOX_E_OBJECT_IN_USE,
    35623562                            tr("Storage controller named '%ls' has still devices attached"),
     
    56085608        rc = pAttachment->init(this,
    56095609                               medium,
    5610                                aStorageController,
     5610                               aStorageController->name(),
    56115611                               dev.lPort,
    56125612                               dev.lDevice,
     
    57515751         ++it)
    57525752    {
    5753         if (Bstr((*it)->controller()->name()) == aName)
     5753        if (Bstr((*it)->controllerName()) == aName)
    57545754            atts.push_back(*it);
    57555755    }
     
    66426642            rc = attachment->init(this,
    66436643                                  diff,
    6644                                   pAtt->controller(),
     6644                                  pAtt->controllerName(),
    66456645                                  pAtt->port(),
    66466646                                  pAtt->device(),
  • trunk/src/VBox/Main/MediumAttachmentImpl.cpp

    r23880 r23914  
    5858HRESULT MediumAttachment::init(Machine *aParent,
    5959                               Medium *aMedium,
    60                                StorageController *aController,
     60                               const Bstr &aControllerName,
    6161                               LONG aPort,
    6262                               LONG aDevice,
     
    6565{
    6666    LogFlowThisFuncEnter();
    67     LogFlowThisFunc(("aParent=%p aMedium=%p aController=%ls aPort=%d aDevice=%d aType=%d aImplicit=%d\n", aParent, aMedium, aController, aPort, aDevice, aType, aImplicit));
     67    LogFlowThisFunc(("aParent=%p aMedium=%p aControllerName=%ls aPort=%d aDevice=%d aType=%d aImplicit=%d\n", aParent, aMedium, aControllerName.raw(), aPort, aDevice, aType, aImplicit));
    6868
    6969    if (aType == DeviceType_HardDisk)
     
    7878    m.allocate();
    7979    m->medium = aMedium;
    80     unconst(m->controller) = aController;
     80    unconst(m->controllerName) = aControllerName;
    8181    unconst(m->port)   = aPort;
    8282    unconst(m->device) = aDevice;
     
    190190
    191191    /* m->controller is constant during life time, no need to lock */
    192     m->controller.queryInterfaceTo(aController);
    193 
    194     LogFlowThisFuncLeave();
    195     return S_OK;
     192    /** @todo ugly hack, MediumAttachment should have a direct reference
     193     * to the storage controller, but can't have that right now due to
     194     * how objects are created for settings rollback support. */
     195    HRESULT rc = mParent->GetStorageControllerByName(m->controllerName, aController);
     196
     197    LogFlowThisFuncLeave();
     198    return rc;
    196199}
    197200
  • trunk/src/VBox/Main/include/MediumAttachmentImpl.h

    r23880 r23914  
    5454    HRESULT init(Machine *aParent,
    5555                 Medium *aMedium,
    56                  StorageController *aController,
     56                 const Bstr &aControllerName,
    5757                 LONG aPort,
    5858                 LONG aDevice,
     
    8383
    8484    const ComObjPtr<Medium> &medium() const { return m->medium; }
    85     const ComObjPtr<StorageController> &controller() const { return m->controller; }
     85    Bstr controllerName() const { return m->controllerName; }
    8686    LONG port() const { return m->port; }
    8787    LONG device() const { return m->device; }
     
    8989    bool passthrough() const { AutoReadLock lock(this); return m->passthrough; }
    9090
    91     bool matches(CBSTR aController, LONG aPort, LONG aDevice)
     91    bool matches(CBSTR aControllerName, LONG aPort, LONG aDevice)
    9292    {
    93         return (    aController == m->controller->name()
     93        return (    aControllerName == m->controllerName
    9494                 && aPort == m->port
    9595                 && aDevice == m->device);
     
    125125
    126126        ComObjPtr<Medium> medium;
    127         ComObjPtr<StorageController> controller;
     127        /* Since MediumAttachment is not a first class citizen when it
     128         * comes to managing settings, having a reference to the storage
     129         * controller will not work - when settings are changed it will point
     130         * to the old, uninitialized instance. Changing this requires
     131         * substantial changes to MediumImpl.cpp. */
     132        Bstr controllerName;
    128133        const LONG port;
    129134        const LONG device;
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette