Index: /trunk/src/VBox/Main/NetworkAdapterImpl.cpp
===================================================================
--- /trunk/src/VBox/Main/NetworkAdapterImpl.cpp	(revision 26817)
+++ /trunk/src/VBox/Main/NetworkAdapterImpl.cpp	(revision 26818)
@@ -239,4 +239,6 @@
         mlock.release();
 
+        /* Changing the network adapter type during runtime is not allowed,
+         * therefore no immediate change in CFGM logic => changeAdapter=FALSE. */
         mParent->onNetworkAdapterChange(this, FALSE);
     }
@@ -297,4 +299,6 @@
         mlock.release();
 
+        /* Disabling the network adapter during runtime is not allowed
+         * therefore no immediate change in CFGM logic => changeAdapter=FALSE. */
         mParent->onNetworkAdapterChange(this, FALSE);
     }
@@ -408,5 +412,9 @@
 
     if (emitChangeEvent)
+    {
+        /* Changing the MAC via the Main API during runtime is not allowed,
+         * therefore no immediate change in CFGM logic => changeAdapter=FALSE. */
         mParent->onNetworkAdapterChange(this, FALSE);
+    }
 
     return rc;
@@ -470,5 +478,8 @@
         mlock.release();
 
-        mParent->onNetworkAdapterChange(this, FALSE);
+        /* When changing the host adapter, adapt the CFGM logic to make this
+         * change immediately effect and to notifiy the guest that the network
+         * might have changed, therefore changeAdapter=TRUE. */
+        mParent->onNetworkAdapterChange(this, TRUE);
     }
 
@@ -523,5 +534,8 @@
         mlock.release();
 
-        mParent->onNetworkAdapterChange(this, FALSE);
+        /* When changing the internal network, adapt the CFGM logic to make this
+         * change immediately effect and to notifiy the guest that the network
+         * might have changed, therefore changeAdapter=TRUE. */
+        mParent->onNetworkAdapterChange(this, TRUE);
     }
 
@@ -571,4 +585,6 @@
         mlock.release();
 
+        /* Changing the NAT network isn't allowed during runtime, therefore
+         * no immediate replug in CFGM logic => changeAdapter=FALSE */
         mParent->onNetworkAdapterChange(this, FALSE);
     }
@@ -615,4 +631,5 @@
         mlock.release();
 
+        /* No change in CFGM logic => changeAdapter=FALSE. */
         mParent->onNetworkAdapterChange(this, FALSE);
     }
@@ -659,4 +676,5 @@
         mlock.release();
 
+        /* No change in CFGM logic => changeAdapter=FALSE. */
         mParent->onNetworkAdapterChange(this, FALSE);
     }
@@ -702,4 +720,5 @@
         mlock.release();
 
+        /* Adapt the CFGM logic changeAdapter=TRUE */
         mParent->onNetworkAdapterChange(this, TRUE);
     }
@@ -746,4 +765,5 @@
         mlock.release();
 
+        /* No change in CFGM logic => changeAdapter=FALSE. */
         mParent->onNetworkAdapterChange(this, FALSE);
     }
@@ -784,4 +804,5 @@
         mlock.release();
 
+        /* Adapt the CFGM logic and notify the guest => changeAdapter=TRUE. */
         HRESULT rc = mParent->onNetworkAdapterChange(this, TRUE);
         if (FAILED(rc))
@@ -831,4 +852,60 @@
         mlock.release();
 
+        /* Adapt the CFGM logic and notify the guest => changeAdapter=TRUE. */
+        HRESULT rc = mParent->onNetworkAdapterChange(this, TRUE);
+        if (FAILED(rc))
+        {
+            /* If changing the attachment failed then we can't assume that the
+             * previous attachment will attach correctly and thus return error
+             * along with dettaching all attachments.
+             */
+            Detach();
+            return rc;
+        }
+    }
+
+    return S_OK;
+}
+
+STDMETHODIMP NetworkAdapter::AttachToInternalNetwork()
+{
+    AutoCaller autoCaller(this);
+    if (FAILED(autoCaller.rc())) return autoCaller.rc();
+
+    /* the machine needs to be mutable */
+    AutoMutableStateDependency adep(mParent);
+    if (FAILED(adep.rc())) return adep.rc();
+
+    AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
+
+    /* don't do anything if we're already internal network attached */
+    if (mData->mAttachmentType != NetworkAttachmentType_Internal)
+    {
+        mData.backup();
+
+        /* first detach the current attachment */
+        // Commented this for now as it reset the parameter mData->mInternalNetwork
+        // which is essential while changing the Attachment dynamically.
+        //detach();
+
+        /* there must an internal network name */
+        if (mData->mInternalNetwork.isEmpty())
+        {
+            LogRel (("Internal network name not defined, "
+                     "setting to default \"intnet\"\n"));
+            mData->mInternalNetwork = "intnet";
+        }
+
+        mData->mAttachmentType = NetworkAttachmentType_Internal;
+
+        m_fModified = true;
+        // leave the lock before informing callbacks
+        alock.release();
+
+        AutoWriteLock mlock(mParent COMMA_LOCKVAL_SRC_POS);       // mParent is const, no need to lock
+        mParent->setModified(Machine::IsModified_NetworkAdapters);
+        mlock.release();
+
+        /* Adapt the CFGM logic and notify the guest => changeAdapter=TRUE. */
         HRESULT rc = mParent->onNetworkAdapterChange(this, TRUE);
         if (FAILED(rc))
@@ -847,43 +924,36 @@
 }
 
-STDMETHODIMP NetworkAdapter::AttachToInternalNetwork()
-{
-    AutoCaller autoCaller(this);
-    if (FAILED(autoCaller.rc())) return autoCaller.rc();
-
-    /* the machine needs to be mutable */
-    AutoMutableStateDependency adep(mParent);
-    if (FAILED(adep.rc())) return adep.rc();
-
-    AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
-
-    /* don't do anything if we're already internal network attached */
-    if (mData->mAttachmentType != NetworkAttachmentType_Internal)
+STDMETHODIMP NetworkAdapter::AttachToHostOnlyInterface()
+{
+    AutoCaller autoCaller(this);
+    if (FAILED(autoCaller.rc())) return autoCaller.rc();
+
+    /* the machine needs to be mutable */
+    AutoMutableStateDependency adep(mParent);
+    if (FAILED(adep.rc())) return adep.rc();
+
+    AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
+
+    /* don't do anything if we're already host interface attached */
+    if (mData->mAttachmentType != NetworkAttachmentType_HostOnly)
     {
         mData.backup();
 
         /* first detach the current attachment */
-        // Commented this for now as it reset the parameter mData->mInternalNetwork
+        // Commented this for now as it reset the parameter mData->mHostInterface
         // which is essential while changing the Attachment dynamically.
         //detach();
 
-        /* there must an internal network name */
-        if (mData->mInternalNetwork.isEmpty())
-        {
-            LogRel (("Internal network name not defined, "
-                     "setting to default \"intnet\"\n"));
-            mData->mInternalNetwork = "intnet";
-        }
-
-        mData->mAttachmentType = NetworkAttachmentType_Internal;
-
-        m_fModified = true;
-        // leave the lock before informing callbacks
-        alock.release();
-
-        AutoWriteLock mlock(mParent COMMA_LOCKVAL_SRC_POS);       // mParent is const, no need to lock
-        mParent->setModified(Machine::IsModified_NetworkAdapters);
-        mlock.release();
-
+        mData->mAttachmentType = NetworkAttachmentType_HostOnly;
+
+        m_fModified = true;
+        // leave the lock before informing callbacks
+        alock.release();
+
+        AutoWriteLock mlock(mParent COMMA_LOCKVAL_SRC_POS);       // mParent is const, no need to lock
+        mParent->setModified(Machine::IsModified_NetworkAdapters);
+        mlock.release();
+
+        /* Adapt the CFGM logic and notify the guest => changeAdpater=TRUE. */
         HRESULT rc = mParent->onNetworkAdapterChange(this, TRUE);
         if (FAILED(rc))
@@ -902,51 +972,4 @@
 }
 
-STDMETHODIMP NetworkAdapter::AttachToHostOnlyInterface()
-{
-    AutoCaller autoCaller(this);
-    if (FAILED(autoCaller.rc())) return autoCaller.rc();
-
-    /* the machine needs to be mutable */
-    AutoMutableStateDependency adep(mParent);
-    if (FAILED(adep.rc())) return adep.rc();
-
-    AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
-
-    /* don't do anything if we're already host interface attached */
-    if (mData->mAttachmentType != NetworkAttachmentType_HostOnly)
-    {
-        mData.backup();
-
-        /* first detach the current attachment */
-        // Commented this for now as it reset the parameter mData->mHostInterface
-        // which is essential while changing the Attachment dynamically.
-        //detach();
-
-        mData->mAttachmentType = NetworkAttachmentType_HostOnly;
-
-        m_fModified = true;
-        // leave the lock before informing callbacks
-        alock.release();
-
-        AutoWriteLock mlock(mParent COMMA_LOCKVAL_SRC_POS);       // mParent is const, no need to lock
-        mParent->setModified(Machine::IsModified_NetworkAdapters);
-        mlock.release();
-
-        HRESULT rc = mParent->onNetworkAdapterChange(this, TRUE);
-        if (FAILED(rc))
-        {
-            /* If changing the attachment failed then we can't assume
-             * that the previous attachment will attach correctly
-             * and thus return error along with dettaching all
-             * attachments.
-             */
-            Detach();
-            return rc;
-        }
-    }
-
-    return S_OK;
-}
-
 STDMETHODIMP NetworkAdapter::Detach()
 {
@@ -974,4 +997,5 @@
         mlock.release();
 
+        /* adapt the CFGM logic and notify the guest => changeAdapter=TRUE. */
         mParent->onNetworkAdapterChange(this, TRUE);
     }
