Changeset 45119 in vbox for trunk/src/VBox/Main/src-server
- Timestamp:
- Mar 21, 2013 8:38:30 AM (12 years ago)
- Location:
- trunk/src/VBox/Main/src-server
- Files:
-
- 2 deleted
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Main/src-server/VirtualBoxImpl.cpp
r45117 r45119 63 63 #include "DHCPServerRunner.h" 64 64 #include "DHCPServerImpl.h" 65 #include "NATNetworkImpl.h"66 65 #ifdef VBOX_WITH_RESOURCE_USAGE_API 67 66 # include "PerformanceImpl.h" … … 183 182 typedef ObjectsList<SharedFolder> SharedFoldersOList; 184 183 typedef ObjectsList<DHCPServer> DHCPServersOList; 185 typedef ObjectsList<NATNetwork> NATNetworksOList;186 184 187 185 typedef std::map<Guid, ComPtr<IProgress> > ProgressMap; … … 211 209 lockDHCPServers(LOCKCLASS_LISTOFOTHEROBJECTS), 212 210 allDHCPServers(lockDHCPServers), 213 lockNATNetworks(LOCKCLASS_LISTOFOTHEROBJECTS),214 allNATNetworks(lockNATNetworks),215 211 mtxProgressOperations(LOCKCLASS_PROGRESSLIST), 216 212 updateReq(UPDATEREQARG), … … 290 286 RWLockHandle lockDHCPServers; 291 287 DHCPServersOList allDHCPServers; 292 293 RWLockHandle lockNATNetworks;294 NATNetworksOList allNATNetworks;295 288 296 289 RWLockHandle mtxProgressOperations; … … 493 486 #endif 494 487 495 /* net services - dhcp services*/488 /* net services */ 496 489 for (settings::DHCPServersList::const_iterator it = m->pMainConfigFile->llDhcpServers.begin(); 497 490 it != m->pMainConfigFile->llDhcpServers.end(); … … 506 499 507 500 rc = registerDHCPServer(pDhcpServer, false /* aSaveRegistry */); 508 if (FAILED(rc)) throw rc;509 }510 511 /* net services - nat networks */512 for (settings::NATNetworksList::const_iterator it = m->pMainConfigFile->llNATNetworks.begin();513 it != m->pMainConfigFile->llNATNetworks.end();514 ++it)515 {516 const settings::NATNetwork &net = *it;517 518 ComObjPtr<NATNetwork> pNATNetwork;519 if (SUCCEEDED(rc = pNATNetwork.createObject()))520 rc = pNATNetwork->init(this, net);521 if (FAILED(rc)) throw rc;522 523 rc = registerNATNetwork(pNATNetwork, false /* aSaveRegistry */);524 501 if (FAILED(rc)) throw rc; 525 502 } … … 1171 1148 return S_OK; 1172 1149 } 1173 1174 1175 STDMETHODIMP1176 VirtualBox::COMGETTER(NATNetworks)(ComSafeArrayOut(INATNetwork *, aNATNetworks))1177 {1178 #ifdef VBOX_WITH_NAT_SERVICE1179 CheckComArgOutSafeArrayPointerValid(aNATNetworks);1180 1181 AutoCaller autoCaller(this);1182 if (FAILED(autoCaller.rc())) return autoCaller.rc();1183 1184 AutoReadLock al(m->allNATNetworks.getLockHandle() COMMA_LOCKVAL_SRC_POS);1185 SafeIfaceArray<INATNetwork> nets(m->allNATNetworks.getList());1186 nets.detachTo(ComSafeArrayOutArg(aNATNetworks));1187 1188 return S_OK;1189 #else1190 NOREF(aNATNetworks);1191 NOREF(aNATNetworksSize);1192 return E_NOTIMPL;1193 #endif1194 }1195 1196 1150 1197 1151 STDMETHODIMP … … 3169 3123 } 3170 3124 3171 void VirtualBox::onNATNetworkChange(IN_BSTR aName)3172 {3173 fireNATNetworkChangedEvent(m->pEventSource, aName);3174 }3175 3176 void VirtualBox::onNATNetworkStartStop(IN_BSTR aName, BOOL fStart)3177 {3178 fireNATNetworkStartStopEvent(m->pEventSource, aName, fStart);3179 }3180 void VirtualBox::onNATNetworkSetting(IN_BSTR aNetworkName, BOOL aEnabled,3181 IN_BSTR aNetwork, IN_BSTR aGateway,3182 BOOL aAdvertiseDefaultIpv6RouteEnabled,3183 BOOL fNeedDhcpServer)3184 {3185 fireNATNetworkSettingEvent(m->pEventSource, aNetworkName, aEnabled,3186 aNetwork, aGateway,3187 aAdvertiseDefaultIpv6RouteEnabled, fNeedDhcpServer);3188 }3189 3190 void VirtualBox::onNATNetworkPortForward(IN_BSTR aNetworkName, BOOL create, BOOL fIpv6,3191 IN_BSTR aRuleName, NATProtocol_T proto,3192 IN_BSTR aHostIp, LONG aHostPort,3193 IN_BSTR aGuestIp, LONG aGuestPort)3194 {3195 fireNATNetworkPortForwardEvent(m->pEventSource, aNetworkName, create,3196 fIpv6, aRuleName, proto,3197 aHostIp, aHostPort,3198 aGuestIp, aGuestPort);3199 }3200 3201 3125 /** 3202 3126 * @note Locks this object for reading. … … 4275 4199 } 4276 4200 } 4277 4278 #ifdef VBOX_WITH_NAT_SERVICE4279 /* Saving NAT Network configuration */4280 m->pMainConfigFile->llNATNetworks.clear();4281 {4282 AutoReadLock natNetworkLock(m->allNATNetworks.getLockHandle() COMMA_LOCKVAL_SRC_POS);4283 for (NATNetworksOList::const_iterator it = m->allNATNetworks.begin();4284 it != m->allNATNetworks.end();4285 ++it)4286 {4287 settings::NATNetwork n;4288 rc = (*it)->saveSettings(n);4289 if (FAILED(rc)) throw rc;4290 m->pMainConfigFile->llNATNetworks.push_back(n);4291 }4292 }4293 #endif4294 4201 4295 4202 // leave extra data alone, it's still in the config file … … 5586 5493 } 5587 5494 5588 5589 /**5590 * NAT Network5591 */5592 5593 STDMETHODIMP VirtualBox::CreateNATNetwork(IN_BSTR aName, INATNetwork ** aNatNetwork)5594 {5595 #ifdef VBOX_WITH_NAT_SERVICE5596 CheckComArgStrNotEmptyOrNull(aName);5597 CheckComArgNotNull(aNatNetwork);5598 5599 AutoCaller autoCaller(this);5600 if (FAILED(autoCaller.rc())) return autoCaller.rc();5601 5602 ComObjPtr<NATNetwork> natNetwork;5603 natNetwork.createObject();5604 HRESULT rc = natNetwork->init(this, aName);5605 if (FAILED(rc)) return rc;5606 5607 rc = registerNATNetwork(natNetwork, true);5608 if (FAILED(rc)) return rc;5609 5610 natNetwork.queryInterfaceTo(aNatNetwork);5611 5612 fireNATNetworkCreationDeletionEvent(m->pEventSource, aName, TRUE);5613 return rc;5614 #else5615 NOREF(aName);5616 NOREF(aNatNetwork);5617 return E_NOTIMPL;5618 #endif5619 }5620 5621 STDMETHODIMP VirtualBox::FindNATNetworkByName(IN_BSTR aName, INATNetwork ** aNetwork)5622 {5623 #ifdef VBOX_WITH_NAT_SERVICE5624 CheckComArgStrNotEmptyOrNull(aName);5625 CheckComArgNotNull(aNetwork);5626 5627 AutoCaller autoCaller(this);5628 if (FAILED(autoCaller.rc())) return autoCaller.rc();5629 5630 HRESULT rc;5631 Bstr bstr;5632 ComPtr<NATNetwork> found;5633 5634 AutoReadLock alock(m->allNATNetworks.getLockHandle() COMMA_LOCKVAL_SRC_POS);5635 5636 for (NATNetworksOList::const_iterator it = m->allNATNetworks.begin();5637 it != m->allNATNetworks.end();5638 ++it)5639 {5640 rc = (*it)->COMGETTER(NetworkName)(bstr.asOutParam());5641 if (FAILED(rc)) return rc;5642 5643 if (bstr == aName)5644 {5645 found = *it;5646 break;5647 }5648 }5649 5650 if (!found)5651 return E_INVALIDARG;5652 5653 return found.queryInterfaceTo(aNetwork);5654 #else5655 NOREF(aName);5656 NOREF(aNetwork);5657 return E_NOTIMPL;5658 #endif5659 }5660 5661 STDMETHODIMP VirtualBox::RemoveNATNetwork(INATNetwork * aNetwork)5662 {5663 #ifdef VBOX_WITH_NAT_SERVICE5664 CheckComArgNotNull(aNetwork);5665 5666 AutoCaller autoCaller(this);5667 if (FAILED(autoCaller.rc())) return autoCaller.rc();5668 Bstr name;5669 HRESULT rc;5670 NATNetwork *network = static_cast<NATNetwork *>(aNetwork);5671 rc = network->COMGETTER(NetworkName)(name.asOutParam());5672 rc = unregisterNATNetwork(network, true);5673 fireNATNetworkCreationDeletionEvent(m->pEventSource, name.raw(), FALSE);5674 return rc;5675 #else5676 NOREF(aNetwork);5677 return E_NOTIMPL;5678 #endif5679 5680 }5681 /**5682 * Remembers the given NAT network in the settings.5683 *5684 * @param aNATNetwork NAT Network object to remember.5685 * @param aSaveSettings @c true to save settings to disk (default).5686 *5687 *5688 * @note Locks this object for writing and @a aNATNetwork for reading.5689 */5690 HRESULT VirtualBox::registerNATNetwork(NATNetwork *aNATNetwork,5691 bool aSaveSettings /*= true*/)5692 {5693 #ifdef VBOX_WITH_NAT_SERVICE5694 AssertReturn(aNATNetwork != NULL, E_INVALIDARG);5695 5696 AutoCaller autoCaller(this);5697 AssertComRCReturn(autoCaller.rc(), autoCaller.rc());5698 5699 AutoCaller natNetworkCaller(aNATNetwork);5700 AssertComRCReturn(natNetworkCaller.rc(), natNetworkCaller.rc());5701 5702 Bstr name;5703 HRESULT rc;5704 rc = aNATNetwork->COMGETTER(NetworkName)(name.asOutParam());5705 if (FAILED(rc)) return rc;5706 5707 ComPtr<INATNetwork> existing;5708 rc = FindNATNetworkByName(name.raw(), existing.asOutParam());5709 if (SUCCEEDED(rc))5710 return E_INVALIDARG;5711 5712 rc = S_OK;5713 5714 m->allNATNetworks.addChild(aNATNetwork);5715 5716 if (aSaveSettings)5717 {5718 AutoWriteLock vboxLock(this COMMA_LOCKVAL_SRC_POS);5719 rc = saveSettings();5720 vboxLock.release();5721 5722 if (FAILED(rc))5723 unregisterNATNetwork(aNATNetwork, false /* aSaveSettings */);5724 }5725 5726 return rc;5727 #else5728 NOREF(aNATNetwork);5729 NOREF(aSaveSettings);5730 return E_NOTIMPL;5731 #endif5732 }5733 5734 /**5735 * Removes the given NAT network from the settings.5736 *5737 * @param aNATNetwork NAT network object to remove.5738 * @param aSaveSettings @c true to save settings to disk (default).5739 *5740 * When @a aSaveSettings is @c true, this operation may fail because of the5741 * failed #saveSettings() method it calls. In this case, the DHCP server5742 * will NOT be removed from the settingsi when this method returns.5743 *5744 * @note Locks this object for writing.5745 */5746 HRESULT VirtualBox::unregisterNATNetwork(NATNetwork *aNATNetwork,5747 bool aSaveSettings /*= true*/)5748 {5749 #ifdef VBOX_WITH_NAT_SERVICE5750 AssertReturn(aNATNetwork != NULL, E_INVALIDARG);5751 5752 AutoCaller autoCaller(this);5753 AssertComRCReturn(autoCaller.rc(), autoCaller.rc());5754 5755 AutoCaller natNetworkCaller(aNATNetwork);5756 AssertComRCReturn(natNetworkCaller.rc(), natNetworkCaller.rc());5757 5758 m->allNATNetworks.removeChild(aNATNetwork);5759 5760 HRESULT rc = S_OK;5761 5762 if (aSaveSettings)5763 {5764 AutoWriteLock vboxLock(this COMMA_LOCKVAL_SRC_POS);5765 rc = saveSettings();5766 vboxLock.release();5767 5768 if (FAILED(rc))5769 registerNATNetwork(aNATNetwork, false /* aSaveSettings */);5770 }5771 5772 return rc;5773 #else5774 NOREF(aNATNetwork);5775 NOREF(aSaveSettings);5776 return E_NOTIMPL;5777 #endif5778 }5779 5495 /* vi: set tabstop=4 shiftwidth=4 expandtab: */ -
trunk/src/VBox/Main/src-server/xpcom/server.cpp
r45117 r45119 96 96 # include "ExtPackManagerImpl.h" 97 97 #endif 98 # include "NATNetworkImpl.h"99 100 98 101 99 /* implement nsISupports parts of our objects with support for nsIClassInfo */ … … 154 152 NS_DECL_CLASSINFO(DHCPServer) 155 153 NS_IMPL_THREADSAFE_ISUPPORTS1_CI(DHCPServer, IDHCPServer) 156 157 NS_DECL_CLASSINFO(NATNetwork)158 NS_IMPL_THREADSAFE_ISUPPORTS1_CI(NATNetwork, INATNetwork)159 154 160 155 NS_DECL_CLASSINFO(GuestOSType)
Note:
See TracChangeset
for help on using the changeset viewer.