VirtualBox

Changeset 21961 in vbox for trunk/src/VBox/Main


Ignore:
Timestamp:
Aug 4, 2009 2:59:48 PM (15 years ago)
Author:
vboxsync
Message:

NetworkAttachment: trigger the network attachment change only when AttachTo* API are called

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

Legend:

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

    r21929 r21961  
    32723272 *  @note Locks this object for writing.
    32733273 */
    3274 HRESULT Console::onNetworkAdapterChange (INetworkAdapter *aNetworkAdapter)
     3274HRESULT Console::onNetworkAdapterChange (INetworkAdapter *aNetworkAdapter, BOOL changeAdapter)
    32753275{
    32763276    LogFlowThisFunc(("\n"));
     
    32893289    CheckComRCReturnRC(autoVMCaller.rc());
    32903290
    3291 #ifdef VBOX_DYNAMIC_NET_ATTACH
    3292     /* Get the current network attachment type */
    3293     HRESULT rc;
    3294     NetworkAttachmentType_T eAttachmentType;
    3295     Bstr eHostInterface;
    3296     Bstr eInternalNetwork;
    3297 
    3298     rc = aNetworkAdapter->COMGETTER (AttachmentType) (&eAttachmentType);
    3299     ComAssertComRCRetRC (rc);
    3300     rc = aNetworkAdapter->COMGETTER (HostInterface) (eHostInterface.asOutParam());
    3301     ComAssertComRCRetRC (rc);
    3302     rc = aNetworkAdapter->COMGETTER (InternalNetwork) (eInternalNetwork.asOutParam());
    3303     ComAssertComRCRetRC (rc);
    3304 #endif /* VBOX_DYNAMIC_NET_ATTACH */
    3305 
    33063291    /* Get the properties we need from the adapter */
    33073292    BOOL fCableConnected;
    3308 #ifdef VBOX_DYNAMIC_NET_ATTACH
    3309     rc = aNetworkAdapter->COMGETTER(CableConnected) (&fCableConnected);
    3310 #else /* !VBOX_DYNAMIC_NET_ATTACH */
    33113293    HRESULT rc = aNetworkAdapter->COMGETTER(CableConnected) (&fCableConnected);
    3312 #endif /* !VBOX_DYNAMIC_NET_ATTACH */
    33133294    AssertComRC(rc);
    33143295    if (SUCCEEDED(rc))
     
    33583339
    33593340#ifdef VBOX_DYNAMIC_NET_ATTACH
    3360             if (VBOX_SUCCESS (vrc))
     3341            if ((VBOX_SUCCESS (vrc)) && (changeAdapter == TRUE))
    33613342            {
    33623343                VMSTATE enmVMState = VMR3GetState (mpVM);
    3363                 if (   (enmVMState == VMSTATE_RUNNING)
    3364                     || (enmVMState == VMSTATE_SUSPENDED))
    3365                 {
    3366                     bool changeAdaptor = false;
    3367 
    3368                     if ( !(   (eAttachmentType == NetworkAttachmentType_Null)
    3369                            && (meAttachmentType[ulInstance] == NetworkAttachmentType_Null)))
    3370                         changeAdaptor = true;
    3371 
    3372                     /** @todo pritesh: Need to check for mNATNetwork as well here
    3373                      * when NAT is shifted to use IntNet, till then just compare
    3374                      * if the current and next attachment types are not same
    3375                      */
    3376                     if ( !(   (eAttachmentType == NetworkAttachmentType_NAT)
    3377                            && (meAttachmentType[ulInstance] == NetworkAttachmentType_NAT)))
    3378                         changeAdaptor = true;
    3379 
    3380                     if ( !(   (eAttachmentType == NetworkAttachmentType_Bridged)
    3381                            && (meAttachmentType[ulInstance] == NetworkAttachmentType_Bridged)
    3382                            && (mHostInterface[ulInstance] == eHostInterface)))
    3383                         changeAdaptor = true;
    3384 
    3385                     if ( !(   (eAttachmentType == NetworkAttachmentType_HostOnly)
    3386                            && (meAttachmentType[ulInstance] == NetworkAttachmentType_HostOnly)
    3387                            && (mHostInterface[ulInstance] == eHostInterface)))
    3388                         changeAdaptor = true;
    3389 
    3390                     if ( !(   (eAttachmentType == NetworkAttachmentType_Internal)
    3391                            && (meAttachmentType[ulInstance] == NetworkAttachmentType_Internal)
    3392                            && (mInternalNetwork[ulInstance] == eInternalNetwork)))
    3393                         changeAdaptor = true;
    3394 
    3395                     if (changeAdaptor)
    3396                         rc = doNetworkAdapterChange(pszAdapterName, ulInstance, 0, aNetworkAdapter);
    3397                 }
     3344
     3345                if ((enmVMState == VMSTATE_RUNNING) || (enmVMState == VMSTATE_SUSPENDED))
     3346                    rc = doNetworkAdapterChange(pszAdapterName, ulInstance, 0, aNetworkAdapter);
    33983347            }
    33993348#endif /* VBOX_DYNAMIC_NET_ATTACH */
     
    76787627 */
    76797628NetworkAttachmentType_T Console::meAttachmentType[] = {};
    7680 #ifdef VBOX_DYNAMIC_NET_ATTACH
    7681 Bstr Console::mHostInterface[];
    7682 Bstr Console::mInternalNetwork[];
    7683 Bstr Console::mNATNetwork[];
    7684 #endif
    76857629
    76867630/* vi: set tabstop=4 shiftwidth=4 expandtab: */
  • trunk/src/VBox/Main/ConsoleImpl2.cpp

    r21916 r21961  
    22162216                        /* NAT uses its own DHCP implementation */
    22172217                        //networkName = Bstr(psz);
    2218 #ifdef VBOX_DYNAMIC_NET_ATTACH
    2219                         mNATNetwork[uInstance] = str;
    2220 #endif
    22212218                    }
    22222219
     
    25742571# error "Port me"
    25752572#endif
    2576 #ifdef VBOX_DYNAMIC_NET_ATTACH
    2577                 mHostInterface[uInstance] = HifName;
    2578 #endif
    25792573                break;
    25802574            }
     
    26092603                        networkName = Bstr(psz);
    26102604                        trunkType = Bstr(TRUNKTYPE_WHATEVER);
    2611 #ifdef VBOX_DYNAMIC_NET_ATTACH
    2612                         mInternalNetwork[uInstance] = str;
    2613 #endif
    26142605                    }
    26152606                    STR_FREE();
     
    28272818                    hrc = hostInterface->EnableStaticIpConfigV6(tmpAddr, Utf8Str(tmpMask).toUInt32());
    28282819#endif
    2829 #ifdef VBOX_DYNAMIC_NET_ATTACH
    2830                 mHostInterface[uInstance] = HifName;
    2831 #endif
    28322820                break;
    28332821            }
  • trunk/src/VBox/Main/MachineImpl.cpp

    r21878 r21961  
    78577857        for (ULONG slot = 0; slot < RT_ELEMENTS (networkAdapters); slot ++)
    78587858            if (networkAdapters [slot])
    7859                 that->onNetworkAdapterChange (networkAdapters [slot]);
     7859                that->onNetworkAdapterChange (networkAdapters [slot], FALSE);
    78607860        for (ULONG slot = 0; slot < RT_ELEMENTS (serialPorts); slot ++)
    78617861            if (serialPorts [slot])
     
    97459745 *  @note Locks this object for reading.
    97469746 */
    9747 HRESULT SessionMachine::onNetworkAdapterChange (INetworkAdapter *networkAdapter)
     9747HRESULT SessionMachine::onNetworkAdapterChange (INetworkAdapter *networkAdapter, BOOL changeAdapter)
    97489748{
    97499749    LogFlowThisFunc(("\n"));
     
    97629762        return S_OK;
    97639763
    9764     return directControl->OnNetworkAdapterChange (networkAdapter);
     9764    return directControl->OnNetworkAdapterChange (networkAdapter, changeAdapter);
    97659765}
    97669766
  • trunk/src/VBox/Main/NetworkAdapterImpl.cpp

    r21878 r21961  
    226226        alock.unlock();
    227227
    228         mParent->onNetworkAdapterChange (this);
     228        mParent->onNetworkAdapterChange (this, FALSE);
    229229    }
    230230
     
    279279        alock.unlock();
    280280
    281         mParent->onNetworkAdapterChange (this);
     281        mParent->onNetworkAdapterChange (this, FALSE);
    282282    }
    283283
     
    375375        alock.unlock();
    376376
    377         mParent->onNetworkAdapterChange (this);
     377        mParent->onNetworkAdapterChange (this, FALSE);
    378378    }
    379379
     
    435435        alock.unlock();
    436436
    437         mParent->onNetworkAdapterChange (this);
     437        mParent->onNetworkAdapterChange (this, FALSE);
    438438    }
    439439
     
    483483        alock.unlock();
    484484
    485         mParent->onNetworkAdapterChange (this);
     485        mParent->onNetworkAdapterChange (this, FALSE);
    486486    }
    487487
     
    522522        alock.unlock();
    523523
    524         mParent->onNetworkAdapterChange (this);
     524        mParent->onNetworkAdapterChange (this, FALSE);
    525525    }
    526526
     
    561561        alock.unlock();
    562562
    563         mParent->onNetworkAdapterChange (this);
     563        mParent->onNetworkAdapterChange (this, FALSE);
    564564    }
    565565
     
    600600        alock.unlock();
    601601
    602         mParent->onNetworkAdapterChange (this);
     602        mParent->onNetworkAdapterChange (this, FALSE);
    603603    }
    604604
     
    638638        alock.unlock();
    639639
    640         mParent->onNetworkAdapterChange (this);
     640        mParent->onNetworkAdapterChange (this, FALSE);
    641641    }
    642642
     
    677677        alock.unlock();
    678678
    679         mParent->onNetworkAdapterChange (this);
     679        mParent->onNetworkAdapterChange (this, FALSE);
    680680    }
    681681
     
    710710        alock.unlock();
    711711
    712         mParent->onNetworkAdapterChange (this);
     712        HRESULT rc = mParent->onNetworkAdapterChange (this, TRUE);
     713        if (FAILED (rc))
     714        {
     715            /* If changing the attachment failed then we can't assume
     716             * that the previous attachment will attach correctly
     717             * and thus return error along with dettaching all
     718             * attachments.
     719             */
     720            Detach();
     721            return rc;
     722        }
    713723    }
    714724
     
    742752        alock.unlock();
    743753
    744         mParent->onNetworkAdapterChange (this);
     754        HRESULT rc = mParent->onNetworkAdapterChange (this, TRUE);
     755        if (FAILED (rc))
     756        {
     757            /* If changing the attachment failed then we can't assume
     758             * that the previous attachment will attach correctly
     759             * and thus return error along with dettaching all
     760             * attachments.
     761             */
     762            Detach();
     763            return rc;
     764        }
    745765    }
    746766
     
    782802        alock.unlock();
    783803
    784         mParent->onNetworkAdapterChange (this);
     804        HRESULT rc = mParent->onNetworkAdapterChange (this, TRUE);
     805        if (FAILED (rc))
     806        {
     807            /* If changing the attachment failed then we can't assume
     808             * that the previous attachment will attach correctly
     809             * and thus return error along with dettaching all
     810             * attachments.
     811             */
     812            Detach();
     813            return rc;
     814        }
    785815    }
    786816
     
    814844        alock.unlock();
    815845
    816         mParent->onNetworkAdapterChange (this);
     846        HRESULT rc = mParent->onNetworkAdapterChange (this, TRUE);
     847        if (FAILED (rc))
     848        {
     849            /* If changing the attachment failed then we can't assume
     850             * that the previous attachment will attach correctly
     851             * and thus return error along with dettaching all
     852             * attachments.
     853             */
     854            Detach();
     855            return rc;
     856        }
    817857    }
    818858
     
    840880        alock.unlock();
    841881
    842         mParent->onNetworkAdapterChange (this);
     882        mParent->onNetworkAdapterChange (this, TRUE);
    843883    }
    844884
  • trunk/src/VBox/Main/SessionImpl.cpp

    r21878 r21961  
    532532}
    533533
    534 STDMETHODIMP Session::OnNetworkAdapterChange(INetworkAdapter *networkAdapter)
     534STDMETHODIMP Session::OnNetworkAdapterChange(INetworkAdapter *networkAdapter, BOOL changeAdapter)
    535535{
    536536    LogFlowThisFunc(("\n"));
     
    543543    AssertReturn(mType == SessionType_Direct, VBOX_E_INVALID_OBJECT_STATE);
    544544
    545     return mConsole->onNetworkAdapterChange(networkAdapter);
     545    return mConsole->onNetworkAdapterChange(networkAdapter, changeAdapter);
    546546}
    547547
  • trunk/src/VBox/Main/idl/VirtualBox.xidl

    r21818 r21961  
    1211912119  <interface
    1212012120     name="IInternalSessionControl" extends="$unknown"
    12121      uuid="b26552e7-9534-4f47-b766-98eac648a90d"
     12121     uuid="e28e19fb-23c2-4d1a-b6bf-ce147fa37b24"
    1212212122     internal="yes"
    1212312123     wsmap="suppress"
     
    1224912249      </desc>
    1225012250      <param name="networkAdapter" type="INetworkAdapter" dir="in"/>
     12251      <param name="changeAdapter" type="boolean" dir="in"/>
    1225112252    </method>
    1225212253
  • trunk/src/VBox/Main/include/ConsoleImpl.h

    r21878 r21961  
    177177    HRESULT onDVDDriveChange();
    178178    HRESULT onFloppyDriveChange();
    179     HRESULT onNetworkAdapterChange (INetworkAdapter *aNetworkAdapter);
     179    HRESULT onNetworkAdapterChange (INetworkAdapter *aNetworkAdapter, BOOL changeAdapter);
    180180    HRESULT onSerialPortChange (ISerialPort *aSerialPort);
    181181    HRESULT onParallelPortChange (IParallelPort *aParallelPort);
     
    557557    DriveState_T meFloppyState;
    558558
    559     /** The current network attachment type/name in the VM.
    560      * These don't have to match the network attachment type/name
    561      * maintained in the NetworkAdapter. These are needed to
     559    /** The current network attachment type in the VM.
     560     * This doesn't have to match the network attachment type
     561     * maintained in the NetworkAdapter. This is needed to
    562562     * change the network attachment dynamically.
    563563     */
    564564    static NetworkAttachmentType_T meAttachmentType[SchemaDefs::NetworkAdapterCount];
    565 #ifdef VBOX_DYNAMIC_NET_ATTACH
    566     static Bstr mHostInterface[SchemaDefs::NetworkAdapterCount];
    567     static Bstr mInternalNetwork[SchemaDefs::NetworkAdapterCount];
    568     static Bstr mNATNetwork[SchemaDefs::NetworkAdapterCount];
    569 #endif
    570565
    571566    VMMDev * const mVMMDev;
  • trunk/src/VBox/Main/include/MachineImpl.h

    r21878 r21961  
    639639    virtual HRESULT onDVDDriveChange() { return S_OK; }
    640640    virtual HRESULT onFloppyDriveChange() { return S_OK; }
    641     virtual HRESULT onNetworkAdapterChange(INetworkAdapter * /* networkAdapter */) { return S_OK; }
     641    virtual HRESULT onNetworkAdapterChange(INetworkAdapter * /* networkAdapter */, BOOL /* changeAdapter */) { return S_OK; }
    642642    virtual HRESULT onSerialPortChange(ISerialPort * /* serialPort */) { return S_OK; }
    643643    virtual HRESULT onParallelPortChange(IParallelPort * /* parallelPort */) { return S_OK; }
     
    964964    HRESULT onDVDDriveChange();
    965965    HRESULT onFloppyDriveChange();
    966     HRESULT onNetworkAdapterChange(INetworkAdapter *networkAdapter);
     966    HRESULT onNetworkAdapterChange(INetworkAdapter *networkAdapter, BOOL changeAdapter);
    967967    HRESULT onStorageControllerChange();
    968968    HRESULT onSerialPortChange(ISerialPort *serialPort);
  • trunk/src/VBox/Main/include/SessionImpl.h

    r21878 r21961  
    9595    STDMETHOD(OnDVDDriveChange)();
    9696    STDMETHOD(OnFloppyDriveChange)();
    97     STDMETHOD(OnNetworkAdapterChange)(INetworkAdapter *networkAdapter);
     97    STDMETHOD(OnNetworkAdapterChange)(INetworkAdapter *networkAdapter, BOOL changeAdapter);
    9898    STDMETHOD(OnSerialPortChange)(ISerialPort *serialPort);
    9999    STDMETHOD(OnParallelPortChange)(IParallelPort *parallelPort);
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