- Timestamp:
- Dec 4, 2009 11:37:03 AM (15 years ago)
- svn:sync-xref-src-repo-rev:
- 55652
- Location:
- trunk/src/VBox/Main
- Files:
-
- 1 added
- 11 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Main/DHCPServerImpl.cpp
r25182 r25184 52 52 return; 53 53 54 // /* we uninit children and reset mParent55 // * and VirtualBox::removeDependentChild() needs a write lock */56 // AutoMultiWriteLock2 alock (mVirtualBox->lockHandle(), this->treeLock());57 58 mVirtualBox->removeDependentChild (this);59 60 54 unconst(mVirtualBox).setNull(); 61 55 } … … 78 72 m.upperIP = "0.0.0.0"; 79 73 80 /* register with VirtualBox early, since uninit() will81 * unconditionally unregister on failure */82 aVirtualBox->addDependentChild (this);83 84 74 /* Confirm a successful initialization */ 85 75 autoInitSpan.setSucceeded(); … … 97 87 /* share VirtualBox weakly (parent remains NULL so far) */ 98 88 unconst(mVirtualBox) = aVirtualBox; 99 100 aVirtualBox->addDependentChild (this);101 89 102 90 unconst(mName) = data.strNetworkName; -
trunk/src/VBox/Main/MachineImpl.cpp
r25182 r25184 395 395 unconst(mParent) = aParent; 396 396 397 /* register with parent early, since uninit() will unconditionally398 * unregister on failure */399 mParent->addDependentChild (this);400 401 397 /* allocate the essential machine data structure (the rest will be 402 398 * allocated later by initDataAndChildObjects() */ … … 691 687 /* free the essential data structure last */ 692 688 mData.free(); 693 694 mParent->removeDependentChild (this);695 689 696 690 LogFlowThisFuncLeave(); … … 5099 5093 * children for writing. 5100 5094 */ 5101 HRESULT Machine::trySetRegistered (BOOL aRegistered)5095 HRESULT Machine::trySetRegistered(BOOL argNewRegistered) 5102 5096 { 5103 5097 AssertReturn(mParent->isWriteLockOnCurrentThread(), E_FAIL); … … 5111 5105 ensureNoStateDependencies(); 5112 5106 5113 ComAssertRet (mData->mRegistered != aRegistered, E_FAIL);5107 ComAssertRet(mData->mRegistered != argNewRegistered, E_FAIL); 5114 5108 5115 5109 if (!mData->mAccessible) … … 5118 5112 5119 5113 /* inaccessible machines can only be unregistered */ 5120 AssertReturn(!a Registered, E_FAIL);5114 AssertReturn(!argNewRegistered, E_FAIL); 5121 5115 5122 5116 /* Uninitialize ourselves here because currently there may be no … … 5135 5129 AssertReturn(autoCaller.state() == Ready, E_FAIL); 5136 5130 5137 if (a Registered)5131 if (argNewRegistered) 5138 5132 { 5139 5133 if (mData->mRegistered) … … 5181 5175 * so create it by calling saveSettings() too. */ 5182 5176 if ( isModified() 5183 || (a Registered && !mData->m_pMachineConfigFile->fileExists())5177 || (argNewRegistered && !mData->m_pMachineConfigFile->fileExists()) 5184 5178 ) 5185 5179 { … … 5195 5189 commit(); 5196 5190 5197 mData->mRegistered = a Registered;5191 mData->mRegistered = argNewRegistered; 5198 5192 } 5199 5193 else … … 5464 5458 for (ULONG slot = 0; slot < RT_ELEMENTS (mNetworkAdapters); slot ++) 5465 5459 { 5466 if (mNetworkAdapters 5467 { 5468 mNetworkAdapters 5469 unconst(mNetworkAdapters 5460 if (mNetworkAdapters[slot]) 5461 { 5462 mNetworkAdapters[slot]->uninit(); 5463 unconst(mNetworkAdapters[slot]).setNull(); 5470 5464 } 5471 5465 } … … 5485 5479 for (ULONG slot = 0; slot < RT_ELEMENTS (mParallelPorts); slot ++) 5486 5480 { 5487 if (mParallelPorts 5488 { 5489 mParallelPorts 5490 unconst(mParallelPorts 5481 if (mParallelPorts[slot]) 5482 { 5483 mParallelPorts[slot]->uninit(); 5484 unconst(mParallelPorts[slot]).setNull(); 5491 5485 } 5492 5486 } … … 5494 5488 for (ULONG slot = 0; slot < RT_ELEMENTS (mSerialPorts); slot ++) 5495 5489 { 5496 if (mSerialPorts 5497 { 5498 mSerialPorts 5499 unconst(mSerialPorts 5490 if (mSerialPorts[slot]) 5491 { 5492 mSerialPorts[slot]->uninit(); 5493 unconst(mSerialPorts[slot]).setNull(); 5500 5494 } 5501 5495 } … … 9024 9018 ComAssertRet (!control.isNull(), E_INVALIDARG); 9025 9019 9026 /* Creating a Progress object requires the VirtualBox childrenlock, and9020 /* Creating a Progress object requires the VirtualBox lock, and 9027 9021 * thus locking it here is required by the lock order rules. */ 9028 AutoMultiWriteLock2 alock(mParent-> childrenLock(), this->lockHandle());9029 9030 if (control.equalsTo 9022 AutoMultiWriteLock2 alock(mParent->lockHandle(), this->lockHandle()); 9023 9024 if (control.equalsTo(mData->mSession.mDirectControl)) 9031 9025 { 9032 9026 ComAssertRet (aProgress, E_POINTER); -
trunk/src/VBox/Main/MediumImpl.cpp
r25182 r25184 896 896 unconst(m->pVirtualBox) = aVirtualBox; 897 897 898 /* register with VirtualBox early, since uninit() will899 * unconditionally unregister on failure */900 aVirtualBox->addDependentChild(this);901 902 898 /* no storage yet */ 903 899 m->state = MediumState_NotCreated; … … 995 991 unconst(m->pVirtualBox) = aVirtualBox; 996 992 997 /* register with VirtualBox early, since uninit() will998 * unconditionally unregister on failure */999 aVirtualBox->addDependentChild(this);1000 1001 993 /* there must be a storage unit */ 1002 994 m->state = MediumState_Created; … … 1082 1074 /* register with VirtualBox/parent early, since uninit() will 1083 1075 * unconditionally unregister on failure */ 1084 if (aParent == NULL) 1085 // base disk: add to global list 1086 aVirtualBox->addDependentChild(this); 1087 else 1076 if (aParent) 1088 1077 { 1089 1078 // differencing image: add to parent … … 1226 1215 /* share VirtualBox weakly (parent remains NULL so far) */ 1227 1216 unconst(m->pVirtualBox) = aVirtualBox; 1228 aVirtualBox->addDependentChild(this);1229 1217 1230 1218 /* fake up a UUID which is unique, but also reproducible */ … … 1314 1302 deparent(); 1315 1303 } 1316 else1317 // base image: remove it from the global list1318 m->pVirtualBox->removeDependentChild(this);1319 1304 } 1320 1305 … … 2333 2318 if (FAILED(autoCaller.rc())) return autoCaller.rc(); 2334 2319 2335 ComObjPtr<Medium> diff; 2336 HRESULT rc = m->pVirtualBox->cast(aTarget, diff); 2337 if (FAILED(rc)) return rc; 2320 ComObjPtr<Medium> diff = static_cast<Medium*>(aTarget); 2338 2321 2339 2322 AutoWriteLock alock(this); … … 2346 2329 /* We want to be locked for reading as long as our diff child is being 2347 2330 * created */ 2348 rc = LockRead(NULL);2331 HRESULT rc = LockRead(NULL); 2349 2332 if (FAILED(rc)) return rc; 2350 2333 … … 2386 2369 if (FAILED(autoCaller.rc())) return autoCaller.rc(); 2387 2370 2388 ComObjPtr <Medium> target; 2389 HRESULT rc = m->pVirtualBox->cast(aTarget, target); 2390 if (FAILED(rc)) return rc; 2391 ComObjPtr <Medium> parent; 2371 ComObjPtr<Medium> target = static_cast<Medium*>(aTarget); 2372 ComObjPtr<Medium> parent; 2392 2373 if (aParent) 2393 { 2394 rc = m->pVirtualBox->cast(aParent, parent); 2395 if (FAILED(rc)) return rc; 2396 } 2374 parent = static_cast<Medium*>(aParent); 2397 2375 2398 2376 AutoMultiWriteLock3 alock(this, target, parent); 2399 2377 2400 ComObjPtr <Progress> progress; 2378 ComObjPtr<Progress> progress; 2379 HRESULT rc = S_OK; 2401 2380 2402 2381 try … … 3876 3855 } 3877 3856 3878 /* deassociate from VirtualBox, associate with parent */3879 3880 m->pVirtualBox->removeDependentChild(this);3881 3882 3857 /* we set mParent & children() */ 3883 3858 AutoWriteLock treeLock(m->pVirtualBox->hardDiskTreeLockHandle()); … … 4703 4678 4704 4679 if (m->pParent) 4705 {4706 /* deassociate from the parent, associate with VirtualBox */4707 m->pVirtualBox->addDependentChild(this);4708 4680 deparent(); 4709 }4710 4681 4711 4682 HRESULT rc = E_FAIL; … … 4713 4684 { 4714 4685 case DeviceType_DVD: 4715 rc = m->pVirtualBox->unregister DVDImage(this);4686 rc = m->pVirtualBox->unregisterImage(this, DeviceType_DVD); 4716 4687 break; 4717 4688 case DeviceType_Floppy: 4718 rc = m->pVirtualBox->unregister FloppyImage(this);4689 rc = m->pVirtualBox->unregisterImage(this, DeviceType_Floppy); 4719 4690 break; 4720 4691 case DeviceType_HardDisk: … … 4733 4704 m->pParent = pParentBackup; 4734 4705 m->pParent->m->llChildren.push_back(this); 4735 m->pVirtualBox->removeDependentChild(this);4736 4706 } 4737 4707 } … … 5139 5109 Assert(target->m->pParent.isNull()); 5140 5110 5141 /* associate the child with the parent and deassociate from 5142 * VirtualBox */ 5111 /* associate the child with the parent */ 5143 5112 target->m->pParent = that; 5144 5113 that->m->llChildren.push_back(target); 5145 target->m->pVirtualBox->removeDependentChild(target);5146 5114 5147 5115 /** @todo r=klaus neither target nor that->base() are locked, … … 5158 5126 5159 5127 if (FAILED(rc)) 5160 {5161 5128 /* break the parent association on failure to register */ 5162 target->m->pVirtualBox->addDependentChild(target);5163 5129 that->deparent(); 5164 }5165 5130 } 5166 5131 … … 5372 5337 source->deparent(); 5373 5338 } 5374 else5375 {5376 target->m->pVirtualBox->addDependentChild(target);5377 target->m->pVirtualBox->removeDependentChild(source);5378 }5379 5339 5380 5340 /* then, register again */ … … 5650 5610 target->m->pParent = parent; 5651 5611 parent->m->llChildren.push_back(target); 5652 target->m->pVirtualBox->removeDependentChild(target);5653 5612 5654 5613 /* register with mVirtualBox as the last step and move to … … 5658 5617 5659 5618 if (FAILED(rc)) 5660 {5661 5619 /* break parent association on failure to register */ 5662 target->m->pVirtualBox->addDependentChild(target);5663 5620 target->deparent(); // removes target from parent 5664 }5665 5621 } 5666 5622 else -
trunk/src/VBox/Main/PerformanceImpl.cpp
r25182 r25184 528 528 if (!SUCCEEDED(autoCaller.rc())) return; 529 529 530 Log(("PerformanceCollector::suspendSampling\n"));531 530 int rc = RTTimerLRStop(m.sampler); 532 531 AssertRC(rc); … … 538 537 if (!SUCCEEDED(autoCaller.rc())) return; 539 538 540 Log(("PerformanceCollector::resumeSampling\n"));541 539 int rc = RTTimerLRStart(m.sampler, 0); 542 540 AssertRC(rc); … … 556 554 if (collector->mMagic == MAGIC) 557 555 { 558 Log(("staticSamplerCallback %RX64\n", RTTimeNanoTS()));559 556 collector->samplerCallback(); 560 557 } -
trunk/src/VBox/Main/ProgressImpl.cpp
r25182 r25184 121 121 /* share parent weakly */ 122 122 unconst(mParent) = aParent; 123 124 /* register with parent early, since uninit() will unconditionally125 * unregister on failure */126 mParent->addDependentChild (this);127 123 #endif 128 124 … … 194 190 if (aAutoUninitSpan.initFailed() && !mId.isEmpty()) 195 191 mParent->removeProgress (mId); 196 197 mParent->removeDependentChild (this);198 192 199 193 unconst(mParent).setNull(); -
trunk/src/VBox/Main/SharedFolderImpl.cpp
r25182 r25184 161 161 unconst(mVirtualBox) = aVirtualBox; 162 162 163 HRESULT rc = protectedInit 163 HRESULT rc = protectedInit(aVirtualBox, aName, aHostPath, aWritable); 164 164 165 165 /* Confirm a successful initialization when it's the case */ … … 176 176 * Must be called from under the object's lock! 177 177 */ 178 HRESULT SharedFolder::protectedInit (VirtualBoxBaseWithChildrenNEXT *aParent, 179 CBSTR aName, CBSTR aHostPath, BOOL aWritable) 178 HRESULT SharedFolder::protectedInit(VirtualBoxBase *aParent, 179 CBSTR aName, 180 CBSTR aHostPath, 181 BOOL aWritable) 180 182 { 181 183 LogFlowThisFunc(("aName={%ls}, aHostPath={%ls}, aWritable={%d}\n", … … 221 223 unconst(mParent) = aParent; 222 224 223 /* register with parent */224 mParent->addDependentChild (this);225 226 225 unconst(m.name) = aName; 227 226 unconst(m.hostPath) = hostPath; … … 243 242 if (autoUninitSpan.uninitDone()) 244 243 return; 245 246 if (mParent)247 mParent->removeDependentChild (this);248 244 249 245 unconst(mParent) = NULL; -
trunk/src/VBox/Main/VirtualBoxBase.cpp
r25182 r25184 38 38 #include "Logging.h" 39 39 40 // VirtualBoxBaseProto methods 40 #include "objectslist.h" 41 42 //////////////////////////////////////////////////////////////////////////////// 43 // 44 // VirtualBoxBaseProto 45 // 41 46 //////////////////////////////////////////////////////////////////////////////// 42 47 … … 286 291 } 287 292 293 //////////////////////////////////////////////////////////////////////////////// 294 // 288 295 // VirtualBoxBaseProto::AutoInitSpan methods 296 // 289 297 //////////////////////////////////////////////////////////////////////////////// 290 298 … … 637 645 } 638 646 639 // VirtualBoxBase methods 647 //////////////////////////////////////////////////////////////////////////////// 648 // 649 // VirtualBoxBase 650 // 640 651 //////////////////////////////////////////////////////////////////////////////// 641 652 … … 675 686 } 676 687 677 // VirtualBoxSupportTranslationBase methods 688 //////////////////////////////////////////////////////////////////////////////// 689 // 690 // VirtualBoxSupportTranslationBase 691 // 678 692 //////////////////////////////////////////////////////////////////////////////// 679 693 … … 738 752 } 739 753 740 // VirtualBoxSupportErrorInfoImplBase methods 754 //////////////////////////////////////////////////////////////////////////////// 755 // 756 // VirtualBoxSupportErrorInfoImplBase 757 // 741 758 //////////////////////////////////////////////////////////////////////////////// 742 759 … … 912 929 } 913 930 914 // VirtualBoxBaseWithChildrenNEXT methods915 ////////////////////////////////////////////////////////////////////////////////916 931 917 932 /** -
trunk/src/VBox/Main/VirtualBoxImpl.cpp
r25182 r25184 70 70 71 71 #include "Logging.h" 72 #include "objectslist.h" 72 73 73 74 #ifdef RT_OS_WINDOWS … … 82 83 83 84 #define VBOX_GLOBAL_SETTINGS_FILE "VirtualBox.xml" 84 85 typedef std::vector< ComObjPtr<Machine> > MachineVector;86 87 typedef std::list< ComObjPtr<Machine> > MachineList;88 typedef std::vector< ComObjPtr<SessionMachine> > SessionMachineVector;89 typedef std::list< ComObjPtr<GuestOSType> > GuestOSTypeList;90 91 typedef std::map<Guid, ComPtr<IProgress> > ProgressMap;92 93 typedef std::list <ComObjPtr<SharedFolder> > SharedFolderList;94 typedef std::list <ComObjPtr<DHCPServer> > DHCPServerList;95 96 typedef std::map<Guid, ComObjPtr<Medium> > HardDiskMap;97 98 85 99 86 //////////////////////////////////////////////////////////////////////////////// … … 169 156 #endif 170 157 158 typedef ObjectsList<Machine> MachinesOList; 159 typedef ObjectsList<Medium> MediaOList; 160 typedef ObjectsList<GuestOSType> GuestOSTypesOList; 161 typedef ObjectsList<SharedFolder> SharedFoldersOList; 162 typedef ObjectsList<DHCPServer> DHCPServersOList; 163 164 typedef std::map<Guid, ComPtr<IProgress> > ProgressMap; 165 typedef std::map<Guid, ComObjPtr<Medium> > HardDiskMap; 166 171 167 /** 172 168 * Main VirtualBox data structure. … … 198 194 #endif /* VBOX_WITH_RESOURCE_USAGE_API */ 199 195 200 MachineList llMachines; 201 GuestOSTypeList llGuestOSTypes; 196 // the following lists all have an RWLockHandle as a member and are locked 197 // individually; getting the VirtualBox object lock is NOT necessary, but 198 // see the remarks which ObjectsList method lock themselves and which require 199 // external locking 200 MachinesOList ollMachines; 201 GuestOSTypesOList ollGuestOSTypes; 202 203 MediaOList ollHardDisks, // only base hard disks; the RWLockHandle in here is also used 204 // for hardDiskTreeLockHandle() 205 ollDVDImages, 206 ollFloppyImages; 207 SharedFoldersOList ollSharedFolders; 208 DHCPServersOList ollDHCPServers; 209 210 // the hard disks map is an additional map sorted by UUID for quick lookup 211 // and contains ALL hard disks (base and differencing); 212 // the map must also be protected by ollHardDisks.getLockHandle()! 213 HardDiskMap mapHardDisks; 202 214 203 215 ProgressMap mapProgressOperations; 204 205 MediaList llHardDisks,206 llDVDImages,207 llFloppyImages;208 SharedFolderList llSharedFolders;209 DHCPServerList llDHCPServers;210 211 /// @todo NEWMEDIA do we really need this map? Used only in212 /// find() it seems213 HardDiskMap mapHardDisks;214 215 216 CallbackList llCallbacks; 216 217 217 218 RWLockHandle mtxProgressOperations; 218 219 // protects mutex operations; "leaf" lock, no other lock may be requested after this 219 RWLockHandle mtxHardDiskTree;220 // protects the hard disk tree; this is implemented here, but only requested through221 // Medium::treeLock, which returns exactly this222 RWLockHandle mtxChildrenMap;223 // used for VirtualBoxWithChildrenNEXT management224 220 225 221 // the following are data for the client watcher thread … … 373 369 Global::sOSTypes [i].numSerialEnabled); 374 370 if (SUCCEEDED(rc)) 375 m-> llGuestOSTypes.push_back(guestOSTypeObj);371 m->ollGuestOSTypes.addChild(guestOSTypeObj); 376 372 } 377 373 ComAssertComRCThrowRC (rc); … … 533 529 if (FAILED(rc)) return rc; 534 530 535 rc = register DVDImage(pImage, false /* aSaveRegistry */);531 rc = registerImage(pImage, DeviceType_DVD, false /* aSaveRegistry */); 536 532 if (FAILED(rc)) return rc; 537 533 } … … 548 544 if (FAILED(rc)) return rc; 549 545 550 rc = register FloppyImage(pImage, false /* aSaveRegistry */);546 rc = registerImage(pImage, DeviceType_Floppy, false /* aSaveRegistry */); 551 547 if (FAILED(rc)) return rc; 552 548 } … … 568 564 /* tell all our child objects we've been uninitialized */ 569 565 570 LogFlowThisFunc(("Uninitializing machines (%d)...\n", m->llMachines.size())); 571 if (m->llMachines.size()) 572 { 573 MachineList::iterator it = m->llMachines.begin(); 574 while (it != m->llMachines.end()) 575 (*it++)->uninit(); 576 m->llMachines.clear(); 577 } 578 579 /* Uninit all other children still referenced by clients (unregistered 580 * machines, hard disks, DVD/floppy images, server-side progress 581 * operations). */ 582 uninitDependentChildren(); 583 584 m->mapHardDisks.clear(); 585 586 m->llFloppyImages.clear(); 587 m->llDVDImages.clear(); 588 m->llHardDisks.clear(); 589 m->llDHCPServers.clear(); 566 LogFlowThisFunc(("Uninitializing machines (%d)...\n", m->ollMachines.size())); 567 m->ollMachines.uninitAll(); 568 m->ollFloppyImages.uninitAll(); 569 m->ollDVDImages.uninitAll(); 570 m->ollHardDisks.uninitAll(); 571 m->ollDHCPServers.uninitAll(); 590 572 591 573 m->mapProgressOperations.clear(); 592 574 593 m-> llGuestOSTypes.clear();575 m->ollGuestOSTypes.uninitAll(); 594 576 595 577 /* Note that we release singleton children after we've all other children. … … 788 770 if (FAILED(autoCaller.rc())) return autoCaller.rc(); 789 771 790 AutoReadLock alock(this); 791 792 SafeIfaceArray<IMachine> machines(m->llMachines); 772 AutoReadLock al(m->ollMachines.getLockHandle()); 773 SafeIfaceArray<IMachine> machines(m->ollMachines.getList()); 793 774 machines.detachTo(ComSafeArrayOutArg(aMachines)); 794 775 … … 804 785 if (FAILED(autoCaller.rc())) return autoCaller.rc(); 805 786 806 AutoReadLock alock(this); 807 808 SafeIfaceArray<IMedium> hardDisks(m->llHardDisks); 787 AutoReadLock al(m->ollHardDisks.getLockHandle()); 788 SafeIfaceArray<IMedium> hardDisks(m->ollHardDisks.getList()); 809 789 hardDisks.detachTo(ComSafeArrayOutArg(aHardDisks)); 810 790 … … 812 792 } 813 793 814 STDMETHODIMP 815 VirtualBox::COMGETTER(DVDImages) (ComSafeArrayOut(IMedium *, aDVDImages)) 794 STDMETHODIMP VirtualBox::COMGETTER(DVDImages) (ComSafeArrayOut(IMedium *, aDVDImages)) 816 795 { 817 796 if (ComSafeArrayOutIsNull(aDVDImages)) … … 821 800 if (FAILED(autoCaller.rc())) return autoCaller.rc(); 822 801 823 AutoReadLock alock(this); 824 825 SafeIfaceArray<IMedium> images(m->llDVDImages); 802 AutoReadLock al(m->ollDVDImages.getLockHandle()); 803 SafeIfaceArray<IMedium> images(m->ollDVDImages.getList()); 826 804 images.detachTo(ComSafeArrayOutArg(aDVDImages)); 827 805 … … 829 807 } 830 808 831 STDMETHODIMP 832 VirtualBox::COMGETTER(FloppyImages) (ComSafeArrayOut(IMedium *, aFloppyImages)) 809 STDMETHODIMP VirtualBox::COMGETTER(FloppyImages) (ComSafeArrayOut(IMedium *, aFloppyImages)) 833 810 { 834 811 if (ComSafeArrayOutIsNull(aFloppyImages)) … … 838 815 if (FAILED(autoCaller.rc())) return autoCaller.rc(); 839 816 840 AutoReadLock alock(this); 841 842 SafeIfaceArray<IMedium> images(m->llFloppyImages); 817 AutoReadLock al(m->ollFloppyImages.getLockHandle()); 818 SafeIfaceArray<IMedium> images(m->ollFloppyImages.getList()); 843 819 images.detachTo(ComSafeArrayOutArg(aFloppyImages)); 844 820 … … 855 831 /* protect mProgressOperations */ 856 832 AutoReadLock safeLock(m->mtxProgressOperations); 857 858 833 SafeIfaceArray<IProgress> progress(m->mapProgressOperations); 859 834 progress.detachTo(ComSafeArrayOutArg(aOperations)); … … 869 844 if (FAILED(autoCaller.rc())) return autoCaller.rc(); 870 845 871 AutoReadLock alock(this); 872 873 SafeIfaceArray<IGuestOSType> ostypes(m->llGuestOSTypes); 846 AutoReadLock al(m->ollGuestOSTypes.getLockHandle()); 847 SafeIfaceArray<IGuestOSType> ostypes(m->ollGuestOSTypes.getList()); 874 848 ostypes.detachTo(ComSafeArrayOutArg(aGuestOSTypes)); 875 849 … … 877 851 } 878 852 879 STDMETHODIMP 880 VirtualBox::COMGETTER(SharedFolders) (ComSafeArrayOut(ISharedFolder *, aSharedFolders)) 853 STDMETHODIMP VirtualBox::COMGETTER(SharedFolders) (ComSafeArrayOut(ISharedFolder *, aSharedFolders)) 881 854 { 882 855 #ifndef RT_OS_WINDOWS … … 919 892 if (FAILED(autoCaller.rc())) return autoCaller.rc(); 920 893 921 AutoReadLock alock(this); 922 923 SafeIfaceArray<IDHCPServer> svrs (m->llDHCPServers); 894 AutoReadLock al(m->ollDHCPServers.getLockHandle()); 895 SafeIfaceArray<IDHCPServer> svrs (m->ollDHCPServers.getList()); 924 896 svrs.detachTo(ComSafeArrayOutArg(aDHCPServers)); 925 897 … … 1177 1149 1178 1150 /** @note Locks objects! */ 1179 STDMETHODIMP VirtualBox::RegisterMachine 1151 STDMETHODIMP VirtualBox::RegisterMachine(IMachine *aMachine) 1180 1152 { 1181 1153 CheckComArgNotNull(aMachine); … … 1190 1162 if (FAILED(rc)) return rc; 1191 1163 1192 /* We need the children map lock here to keep the getDependentChild() result1193 * valid until we finish */1194 AutoReadLock chLock (childrenLock());1195 1196 1164 /* We can safely cast child to Machine * here because only Machine 1197 1165 * implementations of IMachine can be among our children. */ 1198 Machine *machine = static_cast <Machine *> (getDependentChild (aMachine)); 1199 if (machine == NULL) 1200 { 1201 /* this machine was not created by CreateMachine() or opened by 1202 * OpenMachine() or loaded during startup */ 1203 return setError (VBOX_E_INVALID_OBJECT_STATE, 1204 tr ("The machine named '%ls' is not created within this " 1205 "VirtualBox instance"), name.raw()); 1206 } 1207 1208 AutoCaller machCaller (machine); 1209 ComAssertComRCRetRC (machCaller.rc()); 1210 1211 rc = registerMachine (machine); 1212 1166 Machine *pMachine = static_cast<Machine*>(aMachine); 1167 1168 AutoCaller machCaller(pMachine); 1169 ComAssertComRCRetRC(machCaller.rc()); 1170 1171 rc = registerMachine(pMachine); 1213 1172 /* fire an event */ 1214 1173 if (SUCCEEDED(rc)) 1215 onMachineRegistered( machine->getId(), TRUE);1174 onMachineRegistered(pMachine->getId(), TRUE); 1216 1175 1217 1176 return rc; … … 1219 1178 1220 1179 /** @note Locks objects! */ 1221 STDMETHODIMP VirtualBox::GetMachine 1180 STDMETHODIMP VirtualBox::GetMachine(IN_BSTR aId, IMachine **aMachine) 1222 1181 { 1223 1182 CheckComArgOutSafeArrayPointerValid(aMachine); … … 1236 1195 1237 1196 /** @note Locks this object for reading, then some machine objects for reading. */ 1238 STDMETHODIMP VirtualBox::FindMachine 1197 STDMETHODIMP VirtualBox::FindMachine(IN_BSTR aName, IMachine **aMachine) 1239 1198 { 1240 1199 LogFlowThisFuncEnter(); … … 1248 1207 1249 1208 /* start with not found */ 1250 ComObjPtr<Machine> machine; 1251 MachineList machines; 1252 { 1253 /* take a copy for safe iteration outside the lock */ 1254 AutoReadLock alock(this); 1255 machines = m->llMachines; 1256 } 1257 1258 for (MachineList::iterator it = machines.begin(); 1259 !machine && it != machines.end(); 1260 ++ it) 1209 ComObjPtr<Machine> pMachineFound; 1210 1211 AutoReadLock al(m->ollMachines.getLockHandle()); 1212 for (MachinesOList::iterator it = m->ollMachines.begin(); 1213 it != m->ollMachines.end(); 1214 ++it) 1261 1215 { 1262 1216 ComObjPtr<Machine> &pMachine2 = *it; … … 1269 1223 AutoReadLock machLock(pMachine2); 1270 1224 if (pMachine2->getName() == aName) 1271 machine = pMachine2; 1225 { 1226 pMachineFound = pMachine2; 1227 break; 1228 } 1272 1229 } 1273 1230 } 1274 1231 1275 1232 /* this will set (*machine) to NULL if machineObj is null */ 1276 machine.queryInterfaceTo(aMachine);1277 1278 HRESULT rc = machine1233 pMachineFound.queryInterfaceTo(aMachine); 1234 1235 HRESULT rc = pMachineFound 1279 1236 ? S_OK 1280 : setError 1281 tr("Could not find a registered machine named '%ls'"), aName);1237 : setError(VBOX_E_OBJECT_NOT_FOUND, 1238 tr("Could not find a registered machine named '%ls'"), aName); 1282 1239 1283 1240 LogFlowThisFunc(("aName=\"%ls\", aMachine=%p, rc=%08X\n", aName, *aMachine, rc)); … … 1288 1245 1289 1246 /** @note Locks objects! */ 1290 STDMETHODIMP VirtualBox::UnregisterMachine 1291 1247 STDMETHODIMP VirtualBox::UnregisterMachine(IN_BSTR aId, 1248 IMachine **aMachine) 1292 1249 { 1293 1250 Guid id(aId); … … 1298 1255 if (FAILED(autoCaller.rc())) return autoCaller.rc(); 1299 1256 1257 // find machine from the given ID 1258 ComObjPtr<Machine> pMachine; 1259 HRESULT rc = findMachine(id, true /* setError */, &pMachine); 1260 if (FAILED(rc)) return rc; 1261 1262 // trySetRegistered needs VirtualBox object write lock 1300 1263 AutoWriteLock alock(this); 1301 1302 ComObjPtr<Machine> machine; 1303 1304 HRESULT rc = findMachine (id, true /* setError */, &machine); 1264 rc = pMachine->trySetRegistered(FALSE); 1305 1265 if (FAILED(rc)) return rc; 1306 1266 1307 rc = machine->trySetRegistered (FALSE);1308 if (FAILED(rc)) return rc;1309 1310 1267 /* remove from the collection of registered machines */ 1311 m-> llMachines.remove (machine);1268 m->ollMachines.removeChild(pMachine); 1312 1269 1313 1270 /* save the global registry */ … … 1315 1272 1316 1273 /* return the unregistered machine to the caller */ 1317 machine.queryInterfaceTo(aMachine);1274 pMachine.queryInterfaceTo(aMachine); 1318 1275 1319 1276 /* fire an event */ 1320 onMachineRegistered 1277 onMachineRegistered(id, FALSE); 1321 1278 1322 1279 return rc; … … 1461 1418 if (SUCCEEDED(rc)) 1462 1419 { 1463 rc = register DVDImage (image);1420 rc = registerImage(image, DeviceType_DVD); 1464 1421 1465 1422 if (SUCCEEDED(rc)) … … 1528 1485 if (SUCCEEDED(rc)) 1529 1486 { 1530 rc = register FloppyImage (image);1487 rc = registerImage(image, DeviceType_Floppy); 1531 1488 1532 1489 if (SUCCEEDED(rc)) … … 1616 1573 *aType = NULL; 1617 1574 1618 AutoReadLock alock(this); 1619 1620 for (GuestOSTypeList::iterator it = m->llGuestOSTypes.begin(); 1621 it != m->llGuestOSTypes.end(); 1622 ++ it) 1575 AutoReadLock alock(m->ollGuestOSTypes.getLockHandle()); 1576 for (GuestOSTypesOList::iterator it = m->ollGuestOSTypes.begin(); 1577 it != m->ollGuestOSTypes.end(); 1578 ++it) 1623 1579 { 1624 1580 const Bstr &typeId = (*it)->id(); … … 1637 1593 } 1638 1594 1639 STDMETHODIMP 1640 VirtualBox::CreateSharedFolder (IN_BSTR aName, IN_BSTR aHostPath, BOOL /* aWritable */) 1595 STDMETHODIMP VirtualBox::CreateSharedFolder(IN_BSTR aName, IN_BSTR aHostPath, BOOL /* aWritable */) 1641 1596 { 1642 1597 CheckComArgNotNull(aName); … … 1649 1604 } 1650 1605 1651 STDMETHODIMP VirtualBox::RemoveSharedFolder 1606 STDMETHODIMP VirtualBox::RemoveSharedFolder(IN_BSTR aName) 1652 1607 { 1653 1608 CheckComArgNotNull(aName); … … 2006 1961 void VirtualBox::dumpAllBackRefs() 2007 1962 { 2008 for (MediaList::const_iterator mt = m->llHardDisks.begin(); 2009 mt != m->llHardDisks.end(); 2010 ++mt) 2011 { 2012 ComObjPtr<Medium> pMedium = *mt; 2013 pMedium->dumpBackRefs(); 2014 } 2015 for (MediaList::const_iterator mt = m->llDVDImages.begin(); 2016 mt != m->llDVDImages.end(); 2017 ++mt) 2018 { 2019 ComObjPtr<Medium> pMedium = *mt; 2020 pMedium->dumpBackRefs(); 1963 { 1964 AutoReadLock al(m->ollHardDisks.getLockHandle()); 1965 for (MediaList::const_iterator mt = m->ollHardDisks.begin(); 1966 mt != m->ollHardDisks.end(); 1967 ++mt) 1968 { 1969 ComObjPtr<Medium> pMedium = *mt; 1970 pMedium->dumpBackRefs(); 1971 } 1972 } 1973 { 1974 AutoReadLock al(m->ollDVDImages.getLockHandle()); 1975 for (MediaList::const_iterator mt = m->ollDVDImages.begin(); 1976 mt != m->ollDVDImages.end(); 1977 ++mt) 1978 { 1979 ComObjPtr<Medium> pMedium = *mt; 1980 pMedium->dumpBackRefs(); 1981 } 2021 1982 } 2022 1983 } … … 2662 2623 { 2663 2624 ComObjPtr<GuestOSType> type; 2664 2665 2625 AutoCaller autoCaller(this); 2666 2626 AssertComRCReturn(autoCaller.rc(), type); 2667 2627 2668 AutoReadLock alock(this);2669 2670 2628 /* unknown type must always be the first */ 2671 ComAssertRet (m->llGuestOSTypes.size() > 0, type); 2672 2673 type = m->llGuestOSTypes.front(); 2674 return type; 2629 ComAssertRet(m->ollGuestOSTypes.size() > 0, type); 2630 2631 return m->ollGuestOSTypes.front(); 2675 2632 } 2676 2633 … … 2703 2660 AutoReadLock alock(this); 2704 2661 2705 for (Machine List::iterator it = m->llMachines.begin();2706 it != m-> llMachines.end();2662 for (MachinesOList::iterator it = m->ollMachines.begin(); 2663 it != m->ollMachines.end(); 2707 2664 ++it) 2708 2665 { … … 2739 2696 ComObjPtr<Machine> *aMachine /* = NULL */) 2740 2697 { 2698 HRESULT rc = VBOX_E_OBJECT_NOT_FOUND; 2699 2741 2700 AutoCaller autoCaller(this); 2742 2701 AssertComRCReturn(autoCaller.rc(), autoCaller.rc()); 2743 2702 2744 bool found = false; 2745 2746 { 2747 AutoReadLock alock(this); 2748 2749 for (MachineList::iterator it = m->llMachines.begin(); 2750 !found && it != m->llMachines.end(); 2751 ++ it) 2703 { 2704 AutoReadLock al(m->ollMachines.getLockHandle()); 2705 2706 for (MachinesOList::iterator it = m->ollMachines.begin(); 2707 it != m->ollMachines.end(); 2708 ++it) 2752 2709 { 2753 2710 ComObjPtr<Machine> pMachine2 = *it; … … 2756 2713 AssertComRC(machCaller.rc()); 2757 2714 2758 found = pMachine2->getId() == aId;2759 if (found && aMachine)2760 *aMachine = pMachine2;2761 }2762 }2763 2764 HRESULT rc = found ? S_OK : VBOX_E_OBJECT_NOT_FOUND;2765 2766 if (aSetError && !found)2767 { 2768 setError (VBOX_E_OBJECT_NOT_FOUND,2769 tr ("Could not find a registered machine with UUID {%RTuuid}"),2770 aId.raw());2771 }2715 if (pMachine2->getId() == aId) 2716 { 2717 rc = S_OK; 2718 if (aMachine) 2719 *aMachine = pMachine2; 2720 break; 2721 } 2722 } 2723 } 2724 2725 if (aSetError && FAILED(rc)) 2726 setError(VBOX_E_OBJECT_NOT_FOUND, 2727 tr("Could not find a registered machine with UUID {%RTuuid}"), 2728 aId.raw()); 2772 2729 2773 2730 return rc; … … 2796 2753 AssertReturn(aId || aLocation, E_INVALIDARG); 2797 2754 2798 AutoReadLock alock(this); 2755 // we use the hard disks map, but it is protected by the 2756 // hard disk _list_ lock handle 2757 AutoReadLock alock(m->ollHardDisks.getLockHandle()); 2799 2758 2800 2759 /* first, look up by UUID in the map if UUID is provided */ 2801 2760 if (aId) 2802 2761 { 2803 HardDiskMap::const_iterator it = m->mapHardDisks.find 2762 HardDiskMap::const_iterator it = m->mapHardDisks.find(*aId); 2804 2763 if (it != m->mapHardDisks.end()) 2805 2764 { … … 2887 2846 } 2888 2847 2889 AutoReadLock alock( this);2848 AutoReadLock alock(m->ollDVDImages.getLockHandle()); 2890 2849 2891 2850 bool found = false; 2892 2851 2893 for (MediaList::const_iterator it = m-> llDVDImages.begin();2894 it != m-> llDVDImages.end();2852 for (MediaList::const_iterator it = m->ollDVDImages.begin(); 2853 it != m->ollDVDImages.end(); 2895 2854 ++ it) 2896 2855 { … … 2963 2922 } 2964 2923 2965 AutoReadLock alock( this);2924 AutoReadLock alock(m->ollFloppyImages.getLockHandle()); 2966 2925 2967 2926 bool found = false; 2968 2927 2969 for (MediaList::const_iterator it = m-> llFloppyImages.begin();2970 it != m-> llFloppyImages.end();2928 for (MediaList::const_iterator it = m->ollFloppyImages.begin(); 2929 it != m->ollFloppyImages.end(); 2971 2930 ++ it) 2972 2931 { … … 3009 2968 GuestOSType*& pGuestOSType) 3010 2969 { 3011 AutoReadLock alock(this);3012 3013 2970 /* Look for a GuestOSType object */ 3014 AssertMsg(m-> llGuestOSTypes.size() != 0,2971 AssertMsg(m->ollGuestOSTypes.size() != 0, 3015 2972 ("Guest OS types array must be filled")); 3016 2973 … … 3021 2978 } 3022 2979 3023 for (GuestOSTypeList::const_iterator it = m->llGuestOSTypes.begin(); 3024 it != m->llGuestOSTypes.end(); 2980 AutoReadLock alock(m->ollGuestOSTypes.getLockHandle()); 2981 for (GuestOSTypesOList::const_iterator it = m->ollGuestOSTypes.begin(); 2982 it != m->ollGuestOSTypes.end(); 3025 2983 ++it) 3026 2984 { … … 3166 3124 * @note Locks this object and media objects for reading. 3167 3125 */ 3168 HRESULT VirtualBox::checkMediaForConflicts2 3169 3170 3126 HRESULT VirtualBox::checkMediaForConflicts2(const Guid &aId, 3127 const Utf8Str &aLocation, 3128 Utf8Str &aConflict) 3171 3129 { 3172 3130 aConflict.setNull(); … … 3239 3197 HRESULT rc = S_OK; 3240 3198 3241 /* serialize file access (prevents concurrent reads and writes) */3242 AutoWriteLock alock(this);3243 3244 3199 try 3245 3200 { 3246 3201 // machines 3247 m->pMainConfigFile->llMachines.clear(); 3248 for (MachineList::iterator it = m->llMachines.begin(); 3249 it != m->llMachines.end(); 3250 ++it) 3251 { 3252 settings::MachineRegistryEntry mre; 3253 rc = (*it)->saveRegistryEntry(mre); 3254 m->pMainConfigFile->llMachines.push_back(mre); 3202 settings::MachinesRegistry machinesTemp; 3203 { 3204 AutoReadLock al(m->ollMachines.getLockHandle()); 3205 for (MachinesOList::iterator it = m->ollMachines.begin(); 3206 it != m->ollMachines.end(); 3207 ++it) 3208 { 3209 settings::MachineRegistryEntry mre; 3210 rc = (*it)->saveRegistryEntry(mre); 3211 machinesTemp.push_back(mre); 3212 } 3255 3213 } 3256 3214 3257 3215 // hard disks 3258 m->pMainConfigFile->llHardDisks.clear(); 3259 for (MediaList::const_iterator it = m->llHardDisks.begin(); 3260 it != m->llHardDisks.end(); 3261 ++it) 3262 { 3263 settings::Medium med; 3264 rc = (*it)->saveSettings(med); 3265 m->pMainConfigFile->llHardDisks.push_back(med); 3266 if (FAILED(rc)) throw rc; 3216 settings::MediaList hardDisksTemp; 3217 { 3218 AutoReadLock al(m->ollHardDisks.getLockHandle()); 3219 for (MediaList::const_iterator it = m->ollHardDisks.begin(); 3220 it != m->ollHardDisks.end(); 3221 ++it) 3222 { 3223 settings::Medium med; 3224 rc = (*it)->saveSettings(med); 3225 if (FAILED(rc)) throw rc; 3226 hardDisksTemp.push_back(med); 3227 } 3267 3228 } 3268 3229 3269 3230 /* CD/DVD images */ 3270 m->pMainConfigFile->llDvdImages.clear(); 3271 for (MediaList::const_iterator it = m->llDVDImages.begin(); 3272 it != m->llDVDImages.end(); 3273 ++it) 3274 { 3275 settings::Medium med; 3276 rc = (*it)->saveSettings(med); 3277 if (FAILED(rc)) throw rc; 3278 m->pMainConfigFile->llDvdImages.push_back(med); 3231 settings::MediaList dvdsTemp; 3232 { 3233 AutoReadLock al(m->ollDVDImages.getLockHandle()); 3234 for (MediaList::const_iterator it = m->ollDVDImages.begin(); 3235 it != m->ollDVDImages.end(); 3236 ++it) 3237 { 3238 settings::Medium med; 3239 rc = (*it)->saveSettings(med); 3240 if (FAILED(rc)) throw rc; 3241 dvdsTemp.push_back(med); 3242 } 3279 3243 } 3280 3244 3281 3245 /* floppy images */ 3282 m->pMainConfigFile->llFloppyImages.clear(); 3283 for (MediaList::const_iterator it = m->llFloppyImages.begin(); 3284 it != m->llFloppyImages.end(); 3285 ++it) 3286 { 3287 settings::Medium med; 3288 rc = (*it)->saveSettings(med); 3289 if (FAILED(rc)) throw rc; 3290 m->pMainConfigFile->llFloppyImages.push_back(med); 3291 } 3292 3293 m->pMainConfigFile->llDhcpServers.clear(); 3294 for (DHCPServerList::const_iterator it = 3295 m->llDHCPServers.begin(); 3296 it != m->llDHCPServers.end(); 3297 ++ it) 3298 { 3299 settings::DHCPServer d; 3300 rc = (*it)->saveSettings(d); 3301 if (FAILED(rc)) throw rc; 3302 m->pMainConfigFile->llDhcpServers.push_back(d); 3303 } 3246 settings::MediaList floppiesTemp; 3247 { 3248 AutoReadLock al(m->ollFloppyImages.getLockHandle()); 3249 for (MediaList::const_iterator it = m->ollFloppyImages.begin(); 3250 it != m->ollFloppyImages.end(); 3251 ++it) 3252 { 3253 settings::Medium med; 3254 rc = (*it)->saveSettings(med); 3255 if (FAILED(rc)) throw rc; 3256 floppiesTemp.push_back(med); 3257 } 3258 } 3259 3260 settings::DHCPServersList dhcpServersTemp; 3261 { 3262 AutoReadLock al(m->ollDHCPServers.getLockHandle()); 3263 for (DHCPServersOList::const_iterator it = m->ollDHCPServers.begin(); 3264 it != m->ollDHCPServers.end(); 3265 ++it) 3266 { 3267 settings::DHCPServer d; 3268 rc = (*it)->saveSettings(d); 3269 if (FAILED(rc)) throw rc; 3270 dhcpServersTemp.push_back(d); 3271 } 3272 } 3273 3274 /* finally, lock VirtualBox object for writing */ 3275 AutoWriteLock alock(this); 3276 3277 /* now copy the temp data to the config file under the VirtualBox lock */ 3278 m->pMainConfigFile->llMachines = machinesTemp; 3279 m->pMainConfigFile->llHardDisks = hardDisksTemp; 3280 m->pMainConfigFile->llDvdImages = dvdsTemp; 3281 m->pMainConfigFile->llFloppyImages = floppiesTemp; 3282 m->pMainConfigFile->llDhcpServers = dhcpServersTemp; 3283 3284 // leave extra data alone, it's still in the config file 3304 3285 3305 3286 /* host data (USB filters) */ … … 3310 3291 if (FAILED(rc)) throw rc; 3311 3292 3312 // now write out the XML3293 // and write out the XML, still under the lock 3313 3294 m->pMainConfigFile->write(m->strSettingsFilePath); 3314 3295 } … … 3348 3329 if (FAILED(autoCaller.rc())) return autoCaller.rc(); 3349 3330 3350 AutoWriteLock alock(this);3351 3352 3331 HRESULT rc = S_OK; 3353 3332 … … 3373 3352 if (autoCaller.state() != InInit) 3374 3353 { 3375 /* Machine::trySetRegistered() will commit and save machine settings */ 3354 // trySetRegistered needs VirtualBox object write lock; 3355 // it will commit and save machine settings 3356 AutoWriteLock alock(this); 3376 3357 rc = aMachine->trySetRegistered(TRUE); 3377 3358 if (FAILED(rc)) return rc; … … 3379 3360 3380 3361 /* add to the collection of registered machines */ 3381 m-> llMachines.push_back(aMachine);3362 m->ollMachines.addChild(aMachine); 3382 3363 3383 3364 if (autoCaller.state() != InInit) … … 3410 3391 AssertComRCReturn(autoCaller.rc(), autoCaller.rc()); 3411 3392 3412 AutoWriteLock alock(this); 3413 3414 AutoCaller hardDiskCaller (aHardDisk); 3393 AutoCaller hardDiskCaller(aHardDisk); 3415 3394 AssertComRCReturn(hardDiskCaller.rc(), hardDiskCaller.rc()); 3416 3395 3417 AutoReadLock hardDiskLock (aHardDisk); 3418 3419 Utf8Str strConflict; 3420 HRESULT rc = checkMediaForConflicts2(aHardDisk->getId(), 3421 aHardDisk->getLocationFull(), 3422 strConflict); 3423 if (FAILED(rc)) return rc; 3424 3425 if (strConflict.length()) 3426 { 3427 return setError(E_INVALIDARG, 3428 tr("Cannot register the hard disk '%s' with UUID {%RTuuid} because a %s already exists in the media registry ('%s')"), 3429 aHardDisk->getLocationFull().raw(), 3430 aHardDisk->getId().raw(), 3431 strConflict.raw(), 3432 m->strSettingsFilePath.raw()); 3433 } 3434 3435 if (aHardDisk->getParent().isNull()) 3436 { 3437 /* base (root) hard disk */ 3438 m->llHardDisks.push_back (aHardDisk); 3439 } 3440 3441 m->mapHardDisks.insert(HardDiskMap::value_type(aHardDisk->getId(), 3442 HardDiskMap::mapped_type(aHardDisk))); 3396 Guid id; 3397 Utf8Str strLocationFull; 3398 ComObjPtr<Medium> pParent; 3399 { 3400 AutoReadLock hardDiskLock(aHardDisk); 3401 id = aHardDisk->getId(); 3402 strLocationFull = aHardDisk->getLocationFull(); 3403 pParent = aHardDisk->getParent(); 3404 } 3405 3406 HRESULT rc; 3407 { 3408 // lock the hard disk lists (list + map) while checking for conflicts 3409 AutoWriteLock al(m->ollHardDisks.getLockHandle()); 3410 3411 Utf8Str strConflict; 3412 rc = checkMediaForConflicts2(id, 3413 strLocationFull, 3414 strConflict); 3415 if (FAILED(rc)) return rc; 3416 if (strConflict.length()) 3417 return setError(E_INVALIDARG, 3418 tr("Cannot register the hard disk '%s' with UUID {%RTuuid} because a %s already exists in the media registry ('%s')"), 3419 strLocationFull.raw(), 3420 id.raw(), 3421 strConflict.raw(), 3422 m->strSettingsFilePath.raw()); 3423 3424 // store base (root) hard disks in the list 3425 if (pParent.isNull()) 3426 m->ollHardDisks.getList().push_back(aHardDisk); 3427 // access the list directly because we already locked the list above 3428 3429 // store all hard disks (even differencing images) in the map 3430 m->mapHardDisks[id] = aHardDisk; 3431 } 3443 3432 3444 3433 if (aSaveRegistry) 3445 3434 { 3446 3435 rc = saveSettings(); 3447 if (FAILED 3436 if (FAILED(rc)) 3448 3437 unregisterHardDisk(aHardDisk, false /* aSaveRegistry */); 3449 3438 } … … 3475 3464 AssertComRCReturn(autoCaller.rc(), autoCaller.rc()); 3476 3465 3477 AutoWriteLock alock(this);3478 3479 3466 AutoCaller hardDiskCaller (aHardDisk); 3480 3467 AssertComRCReturn(hardDiskCaller.rc(), hardDiskCaller.rc()); 3481 3468 3482 AutoReadLock hardDiskLock (aHardDisk); 3483 3484 size_t cnt = m->mapHardDisks.erase(aHardDisk->getId()); 3485 Assert(cnt == 1); 3486 NOREF(cnt); 3487 3488 if (aHardDisk->getParent().isNull()) 3489 { 3490 /* base (root) hard disk */ 3491 m->llHardDisks.remove(aHardDisk); 3469 Guid id; 3470 ComObjPtr<Medium> pParent; 3471 { 3472 AutoReadLock hardDiskLock(aHardDisk); 3473 id = aHardDisk->getId(); 3474 pParent = aHardDisk->getParent(); 3475 } 3476 3477 { 3478 // lock the hard disk lists (list + map) 3479 AutoWriteLock al(m->ollHardDisks.getLockHandle()); 3480 3481 // remove base (root) hard disks from the list 3482 if (pParent.isNull()) 3483 m->ollHardDisks.getList().remove(aHardDisk); 3484 // access the list directly because we already locked the list above 3485 3486 // remove all hard disks (even differencing images) from map 3487 size_t cnt = m->mapHardDisks.erase(id); 3488 Assert(cnt == 1); 3489 NOREF(cnt); 3492 3490 } 3493 3491 … … 3497 3495 { 3498 3496 rc = saveSettings(); 3499 if (FAILED 3497 if (FAILED(rc)) 3500 3498 registerHardDisk(aHardDisk, false /* aSaveRegistry */); 3501 3499 } … … 3505 3503 3506 3504 /** 3507 * Remembers the given image by storing it in the CD/DVD image registry. 3508 * 3509 * @param aImage Image object to remember. 3505 * Remembers the given image by storing it in the CD/DVD or floppy image registry. 3506 * 3507 * @param argImage Image object to remember. 3508 * @param argType Either DeviceType_DVD or DeviceType_Floppy. 3510 3509 * @param aSaveRegistry @c true to save the image registry to disk (default). 3511 3510 * … … 3519 3518 * @note Locks this object for writing and @a aImage for reading. 3520 3519 */ 3521 HRESULT VirtualBox::registerDVDImage (Medium *aImage, 3522 bool aSaveRegistry /*= true*/) 3523 { 3524 AssertReturn(aImage != NULL, E_INVALIDARG); 3520 HRESULT VirtualBox::registerImage(Medium *argImage, 3521 DeviceType_T argType, 3522 bool argSaveRegistry /*= true*/) 3523 { 3524 AssertReturn(argImage != NULL, E_INVALIDARG); 3525 3525 3526 3526 AutoCaller autoCaller(this); 3527 3527 AssertComRCReturn(autoCaller.rc(), autoCaller.rc()); 3528 3528 3529 AutoWriteLock alock(this); 3530 3531 AutoCaller imageCaller (aImage); 3529 AutoCaller imageCaller(argImage); 3532 3530 AssertComRCReturn(imageCaller.rc(), imageCaller.rc()); 3533 3531 3534 AutoReadLock imageLock (aImage); 3535 3536 Utf8Str strConflict; 3537 HRESULT rc = checkMediaForConflicts2(aImage->getId(), 3538 aImage->getLocationFull(), 3539 strConflict); 3540 if (FAILED(rc)) return rc; 3541 3542 if (strConflict.length()) 3543 { 3544 return setError(VBOX_E_INVALID_OBJECT_STATE, 3545 tr("Cannot register the CD/DVD image '%s' with UUID {%RTuuid} because a %s already exists in the media registry ('%s')"), 3546 aImage->getLocationFull().raw(), 3547 aImage->getId().raw(), 3548 strConflict.raw(), 3549 m->strSettingsFilePath.raw()); 3550 } 3551 3552 /* add to the collection */ 3553 m->llDVDImages.push_back (aImage); 3554 3555 if (aSaveRegistry) 3532 Guid id; 3533 Utf8Str strLocationFull; 3534 ComObjPtr<Medium> pParent; 3535 { 3536 AutoReadLock al(argImage); 3537 id = argImage->getId(); 3538 strLocationFull = argImage->getLocationFull(); 3539 pParent = argImage->getParent(); 3540 } 3541 3542 // work on DVDs or floppies list? 3543 ObjectsList<Medium> &oll = (argType == DeviceType_DVD) ? m->ollDVDImages : m->ollFloppyImages; 3544 3545 HRESULT rc; 3546 { 3547 // lock the images lists (list + map) while checking for conflicts 3548 AutoWriteLock al(oll.getLockHandle()); 3549 3550 Utf8Str strConflict; 3551 rc = checkMediaForConflicts2(id, 3552 strLocationFull, 3553 strConflict); 3554 if (FAILED(rc)) return rc; 3555 3556 if (strConflict.length()) 3557 return setError(VBOX_E_INVALID_OBJECT_STATE, 3558 tr("Cannot register the image '%s' with UUID {%RTuuid} because a %s already exists in the media registry ('%s')"), 3559 strLocationFull.raw(), 3560 id.raw(), 3561 strConflict.raw(), 3562 m->strSettingsFilePath.raw()); 3563 3564 // add to the collection 3565 oll.getList().push_back(argImage); 3566 // access the list directly because we already locked the list above 3567 } 3568 3569 if (argSaveRegistry) 3556 3570 { 3557 3571 rc = saveSettings(); 3558 if (FAILED 3559 unregister DVDImage (aImage, false /* aSaveRegistry */);3572 if (FAILED(rc)) 3573 unregisterImage(argImage, argType, false /* aSaveRegistry */); 3560 3574 } 3561 3575 … … 3564 3578 3565 3579 /** 3566 * Removes the given image from the CD/DVD image registry registry. 3567 * 3568 * @param aImage Image object to remove. 3569 * @param aSaveRegistry @c true to save hard disk registry to disk (default). 3580 * Removes the given image from the CD/DVD or floppy image registry. 3581 * 3582 * @param argImage Image object to remove. 3583 * @param argType Either DeviceType_DVD or DeviceType_Floppy. 3584 * @param argSaveRegistry @c true to save hard disk registry to disk (default). 3570 3585 * 3571 3586 * When @a aSaveRegistry is @c true, this operation may fail because of the … … 3578 3593 * @note Locks this object for writing and @a aImage for reading. 3579 3594 */ 3580 HRESULT VirtualBox::unregisterDVDImage (Medium *aImage, 3581 bool aSaveRegistry /*= true*/) 3582 { 3583 AssertReturn(aImage != NULL, E_INVALIDARG); 3595 HRESULT VirtualBox::unregisterImage(Medium *argImage, 3596 DeviceType_T argType, 3597 bool argSaveRegistry /*= true*/) 3598 { 3599 AssertReturn(argImage != NULL, E_INVALIDARG); 3584 3600 3585 3601 AutoCaller autoCaller(this); 3586 3602 AssertComRCReturn(autoCaller.rc(), autoCaller.rc()); 3587 3603 3588 AutoWriteLock alock(this); 3589 3590 AutoCaller imageCaller (aImage); 3604 AutoCaller imageCaller(argImage); 3591 3605 AssertComRCReturn(imageCaller.rc(), imageCaller.rc()); 3592 3606 3593 AutoReadLock imageLock (aImage); 3594 3595 m->llDVDImages.remove (aImage); 3607 Guid id; 3608 ComObjPtr<Medium> pParent; 3609 { 3610 AutoReadLock al(argImage); 3611 id = argImage->getId(); 3612 pParent = argImage->getParent(); 3613 } 3614 3615 // work on DVDs or floppies list? 3616 ObjectsList<Medium> &oll = (argType == DeviceType_DVD) ? m->ollDVDImages : m->ollFloppyImages; 3617 3618 oll.removeChild(argImage); 3596 3619 3597 3620 HRESULT rc = S_OK; 3598 3621 3599 if (a SaveRegistry)3622 if (argSaveRegistry) 3600 3623 { 3601 3624 rc = saveSettings(); 3602 if (FAILED 3603 register DVDImage (aImage, false /* aSaveRegistry */);3625 if (FAILED(rc)) 3626 registerImage(argImage, argType, false /* aSaveRegistry */); 3604 3627 } 3605 3628 3606 3629 return rc; 3607 }3608 3609 /**3610 * Remembers the given image by storing it in the floppy image registry.3611 *3612 * @param aImage Image object to remember.3613 * @param aSaveRegistry @c true to save the image registry to disk (default).3614 *3615 * When @a aSaveRegistry is @c true, this operation may fail because of the3616 * failed #saveSettings() method it calls. In this case, the image object3617 * will not be remembered. It is therefore the responsibility of the caller to3618 * call this method as the last step of some action that requires registration3619 * in order to make sure that only fully functional image objects get3620 * registered.3621 *3622 * @note Locks this object for writing and @a aImage for reading.3623 */3624 HRESULT VirtualBox::registerFloppyImage(Medium *aImage,3625 bool aSaveRegistry /*= true*/)3626 {3627 AssertReturn(aImage != NULL, E_INVALIDARG);3628 3629 AutoCaller autoCaller(this);3630 AssertComRCReturn(autoCaller.rc(), autoCaller.rc());3631 3632 AutoWriteLock alock(this);3633 3634 AutoCaller imageCaller (aImage);3635 AssertComRCReturn(imageCaller.rc(), imageCaller.rc());3636 3637 AutoReadLock imageLock (aImage);3638 3639 Utf8Str strConflict;3640 HRESULT rc = checkMediaForConflicts2(aImage->getId(),3641 aImage->getLocationFull(),3642 strConflict);3643 if (FAILED(rc)) return rc;3644 3645 if (strConflict.length())3646 {3647 return setError(VBOX_E_INVALID_OBJECT_STATE,3648 tr("Cannot register the floppy image '%s' with UUID {%RTuuid} because a %s already exists in the media registry ('%s')"),3649 aImage->getLocationFull().raw(),3650 aImage->getId().raw(),3651 strConflict.raw(),3652 m->strSettingsFilePath.raw());3653 }3654 3655 /* add to the collection */3656 m->llFloppyImages.push_back (aImage);3657 3658 if (aSaveRegistry)3659 {3660 rc = saveSettings();3661 if (FAILED (rc))3662 unregisterFloppyImage(aImage, false /* aSaveRegistry */);3663 }3664 3665 return rc;3666 }3667 3668 /**3669 * Removes the given image from the floppy image registry registry.3670 *3671 * @param aImage Image object to remove.3672 * @param aSaveRegistry @c true to save hard disk registry to disk (default).3673 *3674 * When @a aSaveRegistry is @c true, this operation may fail because of the3675 * failed #saveSettings() method it calls. In this case, the image object3676 * will NOT be removed from the registry when this method returns. It is3677 * therefore the responsibility of the caller to call this method as the first3678 * step of some action that requires unregistration, before calling uninit() on3679 * @a aImage.3680 *3681 * @note Locks this object for writing and @a aImage for reading.3682 */3683 HRESULT VirtualBox::unregisterFloppyImage(Medium *aImage,3684 bool aSaveRegistry /*= true*/)3685 {3686 AssertReturn(aImage != NULL, E_INVALIDARG);3687 3688 AutoCaller autoCaller(this);3689 AssertComRCReturn(autoCaller.rc(), autoCaller.rc());3690 3691 AutoWriteLock alock(this);3692 3693 AutoCaller imageCaller (aImage);3694 AssertComRCReturn(imageCaller.rc(), imageCaller.rc());3695 3696 AutoReadLock imageLock (aImage);3697 3698 m->llFloppyImages.remove (aImage);3699 3700 HRESULT rc = S_OK;3701 3702 if (aSaveRegistry)3703 {3704 rc = saveSettings();3705 if (FAILED (rc))3706 registerFloppyImage (aImage, false /* aSaveRegistry */);3707 }3708 3709 return rc;3710 }3711 3712 /**3713 * Attempts to cast from a raw interface pointer to an underlying object.3714 * On success, @a aTo will contain the object reference. On failure, @a aTo will3715 * be set to @c null and an extended error info will be returned.3716 *3717 * @param aFrom Interface pointer to cast from.3718 * @param aTo Where to store a reference to the underlying object.3719 *3720 * @note Locks #childrenLock() for reading.3721 */3722 HRESULT VirtualBox::cast (IMedium *aFrom, ComObjPtr<Medium> &aTo)3723 {3724 AssertReturn(aFrom != NULL, E_INVALIDARG);3725 3726 AutoCaller autoCaller(this);3727 AssertComRCReturn(autoCaller.rc(), autoCaller.rc());3728 3729 /* We need the children map lock here to keep the getDependentChild() result3730 * valid until we finish */3731 AutoReadLock chLock (childrenLock());3732 3733 VirtualBoxBase *child = getDependentChild (aFrom);3734 if (!child)3735 return setError (E_FAIL, tr ("The given hard disk object is not created "3736 "within this VirtualBox instance"));3737 3738 /* we can safely cast child to Medium * here because only Medium3739 * implementations of IMedium can be among our children */3740 3741 aTo = static_cast<Medium*>(child);3742 3743 return S_OK;3744 3630 } 3745 3631 … … 3754 3640 * @note Locks this object + DVD, Floppy and HardDisk children for writing. 3755 3641 */ 3756 HRESULT VirtualBox::updateSettings 3642 HRESULT VirtualBox::updateSettings(const char *aOldPath, const char *aNewPath) 3757 3643 { 3758 3644 LogFlowThisFunc(("aOldPath={%s} aNewPath={%s}\n", aOldPath, aNewPath)); … … 3764 3650 AssertComRCReturn(autoCaller.rc(), autoCaller.rc()); 3765 3651 3766 AutoWriteLock alock(this); 3767 3768 /* check DVD paths */ 3769 for (MediaList::iterator it = m->llDVDImages.begin(); 3770 it != m->llDVDImages.end(); 3652 ObjectsList<Medium> ollAll; 3653 ollAll.appendOtherList(m->ollDVDImages); 3654 ollAll.appendOtherList(m->ollFloppyImages); 3655 ollAll.appendOtherList(m->ollHardDisks); 3656 3657 for (MediaList::iterator it = ollAll.begin(); 3658 it != ollAll.end(); 3771 3659 ++ it) 3772 3660 { 3773 3661 (*it)->updatePath(aOldPath, aNewPath); 3774 }3775 3776 /* check Floppy paths */3777 for (MediaList::iterator it = m->llFloppyImages.begin();3778 it != m->llFloppyImages .end();3779 ++ it)3780 {3781 (*it)->updatePath(aOldPath, aNewPath);3782 }3783 3784 /* check HardDisk paths */3785 for (MediaList::const_iterator it = m->llHardDisks.begin();3786 it != m->llHardDisks.end();3787 ++ it)3788 {3789 (*it)->updatePaths(aOldPath, aNewPath);3790 3662 } 3791 3663 … … 3899 3771 RWLockHandle& VirtualBox::hardDiskTreeLockHandle() 3900 3772 { 3901 return m->mtxHardDiskTree; 3902 } 3903 3904 /** 3905 * Reimplements VirtualBoxWithTypedChildren::childrenLock() to return a 3906 * dedicated lock instead of the main object lock. The dedicated lock for 3907 * child map operations frees callers of init() methods of these children 3908 * from acquiring a write parent (VirtualBox) lock (which would be mandatory 3909 * otherwise). Since VirtualBox has a lot of heterogenous children which 3910 * init() methods are called here and there, it definitely makes sense. 3911 */ 3912 RWLockHandle* VirtualBox::childrenLock() 3913 { 3914 return &m->mtxChildrenMap; 3773 return m->ollHardDisks.getLockHandle(); 3915 3774 } 3916 3775 … … 3924 3783 LogFlowFuncEnter(); 3925 3784 3926 VirtualBox *that = (VirtualBox *) pvUser; 3927 Assert (that); 3785 VirtualBox *that = (VirtualBox*)pvUser; 3786 Assert(that); 3787 3788 typedef std::vector< ComObjPtr<Machine> > MachineVector; 3789 typedef std::vector< ComObjPtr<SessionMachine> > SessionMachineVector; 3928 3790 3929 3791 SessionMachineVector machines; … … 3978 3840 { 3979 3841 /* machine mutex is released */ 3980 (machines 3842 (machines[rc - WAIT_OBJECT_0 - 1])->checkForDeath(); 3981 3843 update = true; 3982 3844 } … … 3984 3846 { 3985 3847 /* machine mutex is abandoned due to client process termination */ 3986 (machines 3848 (machines[rc - WAIT_ABANDONED_0 - 1])->checkForDeath(); 3987 3849 update = true; 3988 3850 } … … 3998 3860 { 3999 3861 /* close old process handles */ 4000 for (size_t i = 1 + cnt; i < 1 + cnt + cntSpawned; ++ i) 4001 CloseHandle (handles [i]); 4002 4003 AutoReadLock thatLock (that); 3862 for (size_t i = 1 + cnt; i < 1 + cnt + cntSpawned; ++i) 3863 CloseHandle(handles[i]); 3864 3865 // lock the machines list for reading 3866 AutoReadLock thatLock(that->m->ollMachines.getLockHandle()); 4004 3867 4005 3868 /* obtain a new set of opened machines */ … … 4007 3870 machines.clear(); 4008 3871 4009 for (MachineList::iterator it = that->m->llMachines.begin(); 4010 it != that->m->llMachines.end(); ++ it) 3872 for (MachinesOList::iterator it = that->m->ollMachines.begin(); 3873 it != that->m->ollMachines.end(); 3874 ++it) 4011 3875 { 4012 3876 /// @todo handle situations with more than 64 objects … … 4016 3880 ComObjPtr<SessionMachine> sm; 4017 3881 HANDLE ipcSem; 4018 if ((*it)->isSessionOpenOrClosing 3882 if ((*it)->isSessionOpenOrClosing(sm, NULL, &ipcSem)) 4019 3883 { 4020 machines.push_back 4021 handles 4022 ++ 3884 machines.push_back(sm); 3885 handles[1 + cnt] = ipcSem; 3886 ++cnt; 4023 3887 } 4024 3888 } … … 4030 3894 spawnedMachines.clear(); 4031 3895 4032 for (MachineList::iterator it = that->m->llMachines.begin(); 4033 it != that->m->llMachines.end(); ++ it) 3896 for (MachinesOList::iterator it = that->m->ollMachines.begin(); 3897 it != that->m->ollMachines.end(); 3898 ++it) 4034 3899 { 4035 3900 /// @todo handle situations with more than 64 objects … … 4038 3903 4039 3904 RTPROCESS pid; 4040 if ((*it)->isSessionSpawning 3905 if ((*it)->isSessionSpawning(&pid)) 4041 3906 { 4042 HANDLE ph = OpenProcess 3907 HANDLE ph = OpenProcess(SYNCHRONIZE, FALSE, pid); 4043 3908 AssertMsg (ph != NULL, ("OpenProcess (pid=%d) failed with %d\n", 4044 3909 pid, GetLastError())); 4045 3910 if (rc == 0) 4046 3911 { 4047 spawnedMachines.push_back 4048 handles 4049 ++ 3912 spawnedMachines.push_back(*it); 3913 handles[1 + cnt + cntSpawned] = ph; 3914 ++cntSpawned; 4050 3915 } 4051 3916 } … … 4053 3918 4054 3919 LogFlowFunc (("UPDATE: spawned session count = %d\n", cntSpawned)); 3920 3921 // machines lock unwinds here 4055 3922 } 4056 3923 } … … 4090 3957 autoCaller.release(); 4091 3958 4092 int vrc = RTSemEventWait 3959 int vrc = RTSemEventWait(that->m->updateReq, 500); 4093 3960 4094 3961 /* Restore the caller before using VirtualBox. If it fails, this … … 4129 3996 #ifdef DEBUG 4130 3997 { 4131 AutoReadLock machineLock (machines[semId]);3998 AutoReadLock machineLock(machines[semId]); 4132 3999 LogFlowFunc (("released mutex: machine='%ls'\n", 4133 machines 4000 machines[semId]->name().raw())); 4134 4001 } 4135 4002 #endif 4136 machines 4003 machines[semId]->checkForDeath(); 4137 4004 } 4138 4005 update = true; … … 4159 4026 #ifdef DEBUG 4160 4027 { 4161 AutoReadLock machineLock (machines[semId]);4162 LogFlowFunc 4163 machines[i]->name().raw()));4028 AutoReadLock machineLock(machines[semId]); 4029 LogFlowFunc(("mutex owner dead: machine='%ls'\n", 4030 machines[i]->name().raw())); 4164 4031 } 4165 4032 #endif 4166 machines 4033 machines[i]->checkForDeath(); 4167 4034 } 4168 4035 } … … 4198 4065 machines.clear(); 4199 4066 4200 for (Machine List::iterator it = that->m->llMachines.begin();4067 for (MachinesOList::iterator it = that->m->llMachines.begin(); 4201 4068 it != that->m->llMachines.end(); ++ it) 4202 4069 { … … 4211 4078 { 4212 4079 machines.push_back (sm); 4213 handles 4214 handles 4080 handles[cnt].hsemCur = (HSEM) ipcSem; 4081 handles[cnt].ulUser = cnt; 4215 4082 ++ cnt; 4216 4083 } … … 4236 4103 spawnedMachines.clear(); 4237 4104 4238 for (Machine List::iterator it = that->m->llMachines.begin();4105 for (MachinesOList::iterator it = that->m->llMachines.begin(); 4239 4106 it != that->m->llMachines.end(); ++ it) 4240 4107 { … … 4290 4157 /* RT_SUCCESS(rc) means an update event is signaled */ 4291 4158 4292 AutoReadLock thatLock (that); 4159 // lock the machines list for reading 4160 AutoReadLock thatLock(that->m->ollMachines.getLockHandle()); 4293 4161 4294 4162 if (RT_SUCCESS(rc) || update) … … 4297 4165 machines.clear(); 4298 4166 4299 for (MachineList::iterator it = that->m->llMachines.begin(); 4300 it != that->m->llMachines.end(); ++ it) 4167 for (MachinesOList::iterator it = that->m->ollMachines.begin(); 4168 it != that->m->ollMachines.end(); 4169 ++it) 4301 4170 { 4302 4171 ComObjPtr<SessionMachine> sm; 4303 if ((*it)->isSessionOpenOrClosing 4304 machines.push_back 4172 if ((*it)->isSessionOpenOrClosing(sm)) 4173 machines.push_back(sm); 4305 4174 } 4306 4175 4307 4176 cnt = machines.size(); 4308 LogFlowFunc 4177 LogFlowFunc(("UPDATE: direct session count = %d\n", cnt)); 4309 4178 } 4310 4179 … … 4314 4183 spawnedMachines.clear(); 4315 4184 4316 for (MachineList::iterator it = that->m->llMachines.begin(); 4317 it != that->m->llMachines.end(); ++ it) 4185 for (MachinesOList::iterator it = that->m->ollMachines.begin(); 4186 it != that->m->ollMachines.end(); 4187 ++it) 4318 4188 { 4319 4189 if ((*it)->isSessionSpawning()) 4320 spawnedMachines.push_back 4190 spawnedMachines.push_back(*it); 4321 4191 } 4322 4192 4323 4193 cntSpawned = spawnedMachines.size(); 4324 LogFlowFunc 4194 LogFlowFunc(("UPDATE: spawned session count = %d\n", cntSpawned)); 4325 4195 } 4196 4197 // machines lock unwinds here 4326 4198 } 4327 4199 … … 4490 4362 } 4491 4363 4492 //STDMETHODIMP VirtualBox::FindDHCPServerForInterface (IHostNetworkInterface * aIinterface, IDHCPServer ** aServer) 4493 //{ 4494 // return E_NOTIMPL; 4495 //} 4496 4497 STDMETHODIMP VirtualBox::FindDHCPServerByNetworkName (IN_BSTR aName, IDHCPServer ** aServer) 4364 STDMETHODIMP VirtualBox::FindDHCPServerByNetworkName(IN_BSTR aName, IDHCPServer ** aServer) 4498 4365 { 4499 4366 CheckComArgNotNull(aName); … … 4502 4369 AutoCaller autoCaller(this); 4503 4370 if (FAILED(autoCaller.rc())) return autoCaller.rc(); 4504 4505 AutoWriteLock alock(this);4506 4371 4507 4372 HRESULT rc; … … 4509 4374 ComPtr<DHCPServer> found; 4510 4375 4511 for (DHCPServerList::const_iterator it = 4512 m->llDHCPServers.begin(); 4513 it != m->llDHCPServers.end(); 4514 ++ it) 4515 { 4516 rc = (*it)->COMGETTER(NetworkName) (bstr.asOutParam()); 4376 AutoReadLock alock(m->ollDHCPServers.getLockHandle()); 4377 4378 for (DHCPServersOList::const_iterator it = m->ollDHCPServers.begin(); 4379 it != m->ollDHCPServers.end(); 4380 ++it) 4381 { 4382 rc = (*it)->COMGETTER(NetworkName)(bstr.asOutParam()); 4517 4383 if (FAILED(rc)) throw rc; 4518 4384 4519 if (bstr == aName)4385 if (bstr == aName) 4520 4386 { 4521 4387 found = *it; … … 4558 4424 */ 4559 4425 HRESULT VirtualBox::registerDHCPServer(DHCPServer *aDHCPServer, 4560 bool aSaveRegistry /*= true*/)4426 bool aSaveRegistry /*= true*/) 4561 4427 { 4562 4428 AssertReturn(aDHCPServer != NULL, E_INVALIDARG); … … 4565 4431 AssertComRCReturn(autoCaller.rc(), autoCaller.rc()); 4566 4432 4567 AutoWriteLock alock(this); 4568 4569 AutoCaller dhcpServerCaller (aDHCPServer); 4433 AutoCaller dhcpServerCaller(aDHCPServer); 4570 4434 AssertComRCReturn(dhcpServerCaller.rc(), dhcpServerCaller.rc()); 4571 4572 AutoReadLock dhcpServerLock (aDHCPServer);4573 4435 4574 4436 Bstr name; 4575 4437 HRESULT rc; 4576 rc = aDHCPServer->COMGETTER(NetworkName) 4438 rc = aDHCPServer->COMGETTER(NetworkName)(name.asOutParam()); 4577 4439 if (FAILED(rc)) return rc; 4578 4440 4579 4441 ComPtr<IDHCPServer> existing; 4580 4442 rc = FindDHCPServerByNetworkName(name.mutableRaw(), existing.asOutParam()); 4581 if (SUCCEEDED(rc))4443 if (SUCCEEDED(rc)) 4582 4444 { 4583 4445 return E_INVALIDARG; 4584 4446 } 4447 4585 4448 rc = S_OK; 4586 4449 4587 m-> llDHCPServers.push_back(aDHCPServer);4450 m->ollDHCPServers.addChild(aDHCPServer); 4588 4451 4589 4452 if (aSaveRegistry) … … 4625 4488 AssertComRCReturn(dhcpServerCaller.rc(), dhcpServerCaller.rc()); 4626 4489 4627 AutoReadLock dhcpServerLock (aDHCPServer); 4628 4629 m->llDHCPServers.remove (aDHCPServer); 4490 m->ollDHCPServers.removeChild(aDHCPServer); 4630 4491 4631 4492 HRESULT rc = S_OK; -
trunk/src/VBox/Main/include/SharedFolderImpl.h
r25182 r25184 31 31 32 32 class ATL_NO_VTABLE SharedFolder : 33 public VirtualBoxBase ,33 public VirtualBoxBaseWithChildrenNEXT, 34 34 public VirtualBoxSupportErrorInfoImpl<SharedFolder, ISharedFolder>, 35 35 public VirtualBoxSupportTranslation<SharedFolder>, … … 94 94 protected: 95 95 96 HRESULT protectedInit (VirtualBoxBaseWithChildrenNEXT*aParent,97 96 HRESULT protectedInit(VirtualBoxBase *aParent, 97 CBSTR aName, CBSTR aHostPath, BOOL aWritable); 98 98 99 99 private: 100 100 101 VirtualBoxBase WithChildrenNEXT*const mParent;101 VirtualBoxBase *const mParent; 102 102 103 103 /* weak parents (only one of them is not null) */ -
trunk/src/VBox/Main/include/StorageControllerImpl.h
r25182 r25184 32 32 33 33 class ATL_NO_VTABLE StorageController : 34 public VirtualBoxBase WithChildrenNEXT,34 public VirtualBoxBase, 35 35 public VirtualBoxSupportErrorInfoImpl<StorageController, IStorageController>, 36 36 public VirtualBoxSupportTranslation<StorageController>, -
trunk/src/VBox/Main/include/VirtualBoxImpl.h
r25182 r25184 60 60 61 61 class ATL_NO_VTABLE VirtualBox : 62 public VirtualBoxBase WithChildrenNEXT,62 public VirtualBoxBase, 63 63 public VirtualBoxSupportErrorInfoImpl<VirtualBox, IVirtualBox>, 64 64 public VirtualBoxSupportTranslation<VirtualBox>, … … 257 257 HRESULT unregisterHardDisk(Medium *aHardDisk, bool aSaveRegistry = true); 258 258 259 HRESULT registerDVDImage(Medium *aImage, bool aSaveRegistry = true); 260 HRESULT unregisterDVDImage(Medium *aImage, bool aSaveRegistry = true); 261 262 HRESULT registerFloppyImage (Medium *aImage, bool aSaveRegistry = true); 263 HRESULT unregisterFloppyImage (Medium *aImage, bool aSaveRegistry = true); 264 265 HRESULT cast (IMedium *aFrom, ComObjPtr<Medium> &aTo); 259 HRESULT registerImage(Medium *aImage, DeviceType_T argType, bool aSaveRegistry = true); 260 HRESULT unregisterImage(Medium *aImage, DeviceType_T argType, bool aSaveRegistry = true); 266 261 267 262 HRESULT saveSettings(); … … 275 270 276 271 RWLockHandle& hardDiskTreeLockHandle(); 277 RWLockHandle* childrenLock();278 272 279 273 /* for VirtualBoxSupportErrorInfoImpl */
Note:
See TracChangeset
for help on using the changeset viewer.