Changeset 48709 in vbox
- Timestamp:
- Sep 26, 2013 1:43:05 PM (11 years ago)
- Location:
- trunk/src/VBox/Main
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Main/include/VirtualBoxImpl.h
r48297 r48709 226 226 IN_BSTR aHostIp, LONG aHostPort, 227 227 IN_BSTR aGuestIp, LONG aGuestPort); 228 229 int natNetworkRefInc(IN_BSTR aNetworkName); 230 int natNetworkRefDec(IN_BSTR aNetworkName); 228 231 229 232 ComObjPtr<GuestOSType> getUnknownOSType(); … … 360 363 static Bstr sPackageType; 361 364 static Bstr sAPIVersion; 365 static std::map<Bstr, int> sNatNetworkNameToRefCount; 366 static RWLockHandle* spMtxNatNetworkNameToRefCountLock; 362 367 363 368 static DECLCALLBACK(int) AsyncEventHandler(RTTHREAD thread, void *pvUser); -
trunk/src/VBox/Main/src-server/VirtualBoxImpl.cpp
r48297 r48709 113 113 Bstr VirtualBox::sAPIVersion; 114 114 115 // static 116 std::map<Bstr, int> VirtualBox::sNatNetworkNameToRefCount; 117 118 // static leaked (todo: find better place to free it.) 119 RWLockHandle *VirtualBox::spMtxNatNetworkNameToRefCountLock; 115 120 //////////////////////////////////////////////////////////////////////////////// 116 121 // … … 366 371 if (sAPIVersion.isEmpty()) 367 372 sAPIVersion = VBOX_API_VERSION_STRING; 373 if (!spMtxNatNetworkNameToRefCountLock) 374 spMtxNatNetworkNameToRefCountLock = new RWLockHandle(LOCKCLASS_VIRTUALBOXOBJECT); 375 368 376 LogFlowThisFunc(("Version: %ls, Package: %ls, API Version: %ls\n", sVersion.raw(), sPackageType.raw(), sAPIVersion.raw())); 369 377 … … 491 499 ComObjPtr<NATNetwork> pNATNetwork; 492 500 if (SUCCEEDED(rc = pNATNetwork.createObject())) 501 { 493 502 rc = pNATNetwork->init(this, net); 494 if (FAILED(rc)) throw rc; 503 AssertComRCReturnRC(rc); 504 } 495 505 496 506 rc = registerNATNetwork(pNATNetwork, false /* aSaveRegistry */); 497 if (FAILED(rc)) throw rc;507 AssertComRCReturnRC(rc); 498 508 } 499 509 … … 3084 3094 } 3085 3095 3096 3097 int VirtualBox::natNetworkRefInc(IN_BSTR aNetworkName) 3098 { 3099 AutoWriteLock safeLock(*spMtxNatNetworkNameToRefCountLock COMMA_LOCKVAL_SRC_POS); 3100 Bstr name(aNetworkName); 3101 3102 if (!sNatNetworkNameToRefCount[name]) 3103 { 3104 ComPtr<INATNetwork> nat; 3105 HRESULT rc = FindNATNetworkByName(aNetworkName, nat.asOutParam()); 3106 AssertComRCReturn(rc, -1); 3107 3108 rc = nat->Start(Bstr("whatever").raw()); 3109 AssertComRCReturn(rc, -1); 3110 } 3111 3112 sNatNetworkNameToRefCount[name]++; 3113 3114 return sNatNetworkNameToRefCount[name]; 3115 } 3116 3117 3118 int VirtualBox::natNetworkRefDec(IN_BSTR aNetworkName) 3119 { 3120 AutoWriteLock safeLock(*spMtxNatNetworkNameToRefCountLock COMMA_LOCKVAL_SRC_POS); 3121 Bstr name(aNetworkName); 3122 3123 if (!sNatNetworkNameToRefCount[name]) 3124 return 0; 3125 3126 sNatNetworkNameToRefCount[name]--; 3127 3128 if (!sNatNetworkNameToRefCount[name]) 3129 { 3130 ComPtr<INATNetwork> nat; 3131 HRESULT rc = FindNATNetworkByName(aNetworkName, nat.asOutParam()); 3132 AssertComRCReturn(rc, -1); 3133 3134 rc = nat->Stop(); 3135 AssertComRCReturn(rc, -1); 3136 } 3137 3138 return sNatNetworkNameToRefCount[name]; 3139 } 3140 3141 3086 3142 /** 3087 3143 * @note Locks this object for reading. … … 5126 5182 5127 5183 AutoCaller autoCaller(this); 5128 AssertComRCReturn (autoCaller.rc(),autoCaller.rc());5184 AssertComRCReturnRC(autoCaller.rc()); 5129 5185 5130 5186 AutoCaller natNetworkCaller(aNATNetwork); 5131 AssertComRCReturn (natNetworkCaller.rc(),natNetworkCaller.rc());5187 AssertComRCReturnRC(natNetworkCaller.rc()); 5132 5188 5133 5189 Bstr name; 5134 5190 HRESULT rc; 5135 5191 rc = aNATNetwork->COMGETTER(NetworkName)(name.asOutParam()); 5136 if (FAILED(rc)) return rc; 5137 5138 ComPtr<INATNetwork> existing; 5139 rc = FindNATNetworkByName(name.raw(), existing.asOutParam()); 5140 if (SUCCEEDED(rc)) 5141 return E_INVALIDARG; 5192 AssertComRCReturnRC(rc); 5193 5194 /* returned value isn't 0 and aSaveSettings is true 5195 * means that we create duplicate, otherwise we just load settings. 5196 */ 5197 if ( sNatNetworkNameToRefCount[name] 5198 && aSaveSettings) 5199 AssertComRCReturnRC(E_INVALIDARG); 5142 5200 5143 5201 rc = S_OK; 5202 5203 sNatNetworkNameToRefCount[name] = 0; 5144 5204 5145 5205 m->allNATNetworks.addChild(aNATNetwork); … … 5187 5247 AutoCaller natNetworkCaller(aNATNetwork); 5188 5248 AssertComRCReturn(natNetworkCaller.rc(), natNetworkCaller.rc()); 5249 5250 Bstr name; 5251 HRESULT rc = aNATNetwork->COMGETTER(NetworkName)(name.asOutParam()); 5252 /* Hm, there're still running clients. */ 5253 if (FAILED(rc) || sNatNetworkNameToRefCount[name]) 5254 AssertComRCReturnRC(E_INVALIDARG); 5189 5255 5190 5256 m->allNATNetworks.removeChild(aNATNetwork); 5191 5192 HRESULT rc = S_OK;5193 5257 5194 5258 if (aSaveSettings)
Note:
See TracChangeset
for help on using the changeset viewer.