Changeset 5627 in vbox
- Timestamp:
- Nov 5, 2007 12:45:05 PM (17 years ago)
- Location:
- trunk/src/VBox/Main
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Main/HostImpl.cpp
r5368 r5627 1380 1380 1381 1381 if (device->state() == USBDeviceState_USBDeviceCaptured) 1382 { 1383 /* Machine::name() requires a read lock */ 1384 AutoReaderLock machLock (device->machine()); 1385 1382 1386 return setError (E_INVALIDARG, 1383 1387 tr ("USB device '%s' with UUID {%Vuuid} is already captured by the virtual " 1384 1388 "machine '%ls'"), 1385 1389 device->name().raw(), id.raw(), 1386 aMachine->userData()->mName.raw()); 1390 device->machine()->name()); 1391 } 1387 1392 1388 1393 /* try to capture the device */ … … 2186 2191 AssertReturn (aDevice->isStatePending() == false, false); 2187 2192 2188 bool hasMatch = false; 2189 2190 { 2191 /* We're going to use aMachine which is not our child/parent, add a 2192 * caller */ 2193 AutoCaller autoCaller (aMachine); 2194 if (!autoCaller.isOk()) 2195 { 2196 /* silently return, the machine might be not running any more */ 2197 return false; 2198 } 2199 2200 /* enter the machine's lock because we want to access its USB controller */ 2201 AutoReaderLock machineLock (aMachine); 2202 hasMatch = aMachine->usbController()->hasMatchingFilter (aDevice); 2203 } 2193 bool hasMatch = aMachine->hasMatchingUSBFilter (aDevice); 2204 2194 2205 2195 if (hasMatch) -
trunk/src/VBox/Main/MachineImpl.cpp
r5559 r5627 2515 2515 * The returned session machine is null if no direct session is currently open. 2516 2516 * 2517 * @ Note locks this object for reading.2517 * @note locks this object for reading. 2518 2518 */ 2519 2519 ComObjPtr <SessionMachine> Machine::sessionMachine() … … 2521 2521 ComObjPtr <SessionMachine> sm; 2522 2522 2523 AutoCaller autoCaller (this); 2524 /* the machine may be inaccessible, so don't assert below */ 2525 if (FAILED (autoCaller.rc())) 2523 AutoLimitedCaller autoCaller (this); 2524 AssertComRCReturn (autoCaller.rc(), sm); 2525 2526 /* return null for inaccessible machines */ 2527 if (autoCaller.state() != Ready) 2526 2528 return sm; 2527 2529 … … 2533 2535 2534 2536 return sm; 2537 } 2538 2539 /** 2540 * Saves the registry entry of this machine to the given configuration node. 2541 * 2542 * @param aEntryNode Node to save the registry entry to. 2543 * 2544 * @note locks this object for reading. 2545 */ 2546 HRESULT Machine::saveRegistryEntry (CFGNODE aEntryNode) 2547 { 2548 AssertReturn (aEntryNode, E_FAIL); 2549 2550 AutoLimitedCaller autoCaller (this); 2551 AssertComRCReturnRC (autoCaller.rc()); 2552 2553 AutoReaderLock alock (this); 2554 2555 /* UUID */ 2556 CFGLDRSetUUID (aEntryNode, "uuid", mData->mUuid.raw()); 2557 /* settings file name (possibly, relative) */ 2558 CFGLDRSetBSTR (aEntryNode, "src", mData->mConfigFile); 2559 2560 return S_OK; 2535 2561 } 2536 2562 … … 2638 2664 bool Machine::isDVDImageUsed (const Guid &aId, ResourceUsage_T aUsage) 2639 2665 { 2640 Auto Caller autoCaller (this);2641 AssertComRCReturn (autoCaller.rc() || autoCaller.state() == Limited, false);2666 AutoLimitedCaller autoCaller (this); 2667 AssertComRCReturn (autoCaller.rc(), false); 2642 2668 2643 2669 /* answer 'not attached' if the VM is limited */ … … 2655 2681 /* first, check the current state */ 2656 2682 { 2657 const ComObjPtr <DVDDrive> &dvd = m-> dvdDrive();2683 const ComObjPtr <DVDDrive> &dvd = m->mDVDDrive; 2658 2684 AssertReturn (!dvd.isNull(), false); 2659 2685 … … 2715 2741 { 2716 2742 AutoCaller autoCaller (this); 2717 AssertComRCReturn (autoCaller.rc() || autoCaller.state() == Limited, false);2743 AssertComRCReturn (autoCaller.rc(), false); 2718 2744 2719 2745 /* answer 'not attached' if the VM is limited */ … … 2731 2757 /* first, check the current state */ 2732 2758 { 2733 const ComObjPtr <FloppyDrive> &floppy = m-> floppyDrive();2759 const ComObjPtr <FloppyDrive> &floppy = m->mFloppyDrive; 2734 2760 AssertReturn (!floppy.isNull(), false); 2735 2761 … … 7167 7193 7168 7194 const HDData::HDAttachmentList &snapAtts = 7169 snap->data().mMachine-> hdData()->mHDAttachments;7195 snap->data().mMachine->mHDData->mHDAttachments; 7170 7196 7171 7197 HDData::HDAttachmentList::const_iterator foundIt = snapAtts.end(); … … 8017 8043 Task (SessionMachine *m, Progress *p) 8018 8044 : machine (m), progress (p) 8019 , state (m-> data()->mMachineState) // save the current machine state8045 , state (m->mData->mMachineState) // save the current machine state 8020 8046 , subTask (false), settingsChanged (false) 8021 8047 {} … … 9475 9501 9476 9502 AutoCaller autoCaller (this); 9477 AssertComRCReturn (autoCaller.rc(),autoCaller.rc());9503 AssertComRCReturnRC (autoCaller.rc()); 9478 9504 9479 9505 ComPtr <IInternalSessionControl> directControl; … … 9488 9514 9489 9515 return directControl->OnSharedFolderChange (FALSE /* aGlobal */); 9516 } 9517 9518 /** 9519 * Returns @c true if this machine's USB controller reports it has a matching 9520 * filter for the given USB device and @c false otherwise. 9521 * 9522 * @note Locks this object for reading. 9523 */ 9524 bool SessionMachine::hasMatchingUSBFilter (const ComObjPtr <HostUSBDevice> &aDevice) 9525 { 9526 AutoCaller autoCaller (this); 9527 /* silently return if not ready -- this method may be called after the 9528 * direct machine session has been called */ 9529 if (!autoCaller.isOk()) 9530 return false; 9531 9532 AutoReaderLock alock (this); 9533 9534 return mUSBController->hasMatchingFilter (aDevice); 9490 9535 } 9491 9536 -
trunk/src/VBox/Main/SnapshotImpl.cpp
r5218 r5627 316 316 const Bstr &Snapshot::stateFilePath() const 317 317 { 318 return mData.mMachine-> ssData()->mStateFilePath;318 return mData.mMachine->mSSData->mStateFilePath; 319 319 } 320 320 … … 409 409 410 410 AssertReturn (!mData.mMachine.isNull(), false); 411 AssertReturn (!mData.mMachine-> dvdDrive().isNull(), false);412 413 DVDDrive::Data *d = mData.mMachine-> dvdDrive()->data().data();411 AssertReturn (!mData.mMachine->mDVDDrive.isNull(), false); 412 413 DVDDrive::Data *d = mData.mMachine->mDVDDrive->data().data(); 414 414 415 415 if (d && … … 448 448 449 449 AssertReturn (!mData.mMachine.isNull(), false); 450 AssertReturn (!mData.mMachine-> dvdDrive().isNull(), false);451 452 FloppyDrive::Data *d = mData.mMachine-> floppyDrive()->data().data();450 AssertReturn (!mData.mMachine->mFloppyDrive.isNull(), false); 451 452 FloppyDrive::Data *d = mData.mMachine->mFloppyDrive->data().data(); 453 453 454 454 if (d && … … 494 494 AssertReturnVoid (isReady()); 495 495 496 Utf8Str path = mData.mMachine-> ssData()->mStateFilePath;496 Utf8Str path = mData.mMachine->mSSData->mStateFilePath; 497 497 LogFlowThisFunc (("Snap[%ls].statePath={%s}\n", mData.mName.raw(), path.raw())); 498 498 … … 501 501 { 502 502 path = Utf8StrFmt ("%s%s", aNewPath, path.raw() + strlen (aOldPath)); 503 mData.mMachine-> ssData()->mStateFilePath = path;503 mData.mMachine->mSSData->mStateFilePath = path; 504 504 505 505 LogFlowThisFunc (("-> updated: {%s}\n", path.raw())); -
trunk/src/VBox/Main/VirtualBoxImpl.cpp
r5390 r5627 806 806 } 807 807 808 /* 809 * Machine::trySetRegistered() will commit and save machine settings, and 810 * will also call #registerMachine() on success. 811 */ 808 AutoCaller machCaller (machine); 809 ComAssertComRCRetRC (machCaller.rc()); 810 812 811 rc = registerMachine (machine); 813 812 814 813 /* fire an event */ 815 814 if (SUCCEEDED (rc)) 816 onMachineRegistered (machine-> data()->mUuid, TRUE);815 onMachineRegistered (machine->uuid(), TRUE); 817 816 818 817 return rc; … … 864 863 ++ it) 865 864 { 866 AutoReaderLock machineLock (*it); 867 if ((*it)->userData()->mName == aName) 868 machine = *it; 865 AutoLimitedCaller machCaller (*it); 866 AssertComRC (machCaller.rc()); 867 868 /* skip inaccessible machines */ 869 if (machCaller.state() == Machine::Ready) 870 { 871 AutoReaderLock machLock (*it); 872 if ((*it)->name() == aName) 873 machine = *it; 874 } 869 875 } 870 876 … … 2775 2781 { 2776 2782 ComObjPtr <Machine> m = *mit; 2777 if (m->isDVDImageUsed (aId, aUsage)) 2783 2784 AutoLimitedCaller machCaller (m); 2785 AssertComRC (machCaller.rc()); 2786 2787 /* ignore inaccessible machines */ 2788 if (machCaller.state() == Machine::Ready) 2778 2789 { 2779 /* if not interested in the list, return shortly */ 2780 if (aMachineIDs == NULL) 2781 return true; 2782 2783 idSet.insert (m->data()->mUuid); 2790 if (m->isDVDImageUsed (aId, aUsage)) 2791 { 2792 /* if not interested in the list, return shortly */ 2793 if (aMachineIDs == NULL) 2794 return true; 2795 2796 idSet.insert (m->uuid()); 2797 } 2784 2798 } 2785 2799 } … … 2854 2868 { 2855 2869 ComObjPtr <Machine> m = *mit; 2856 if (m->isFloppyImageUsed (aId, aUsage)) 2870 2871 AutoLimitedCaller machCaller (m); 2872 AssertComRC (machCaller.rc()); 2873 2874 /* ignore inaccessible machines */ 2875 if (machCaller.state() == Machine::Ready) 2857 2876 { 2858 /* if not interested in the list, return shortly */ 2859 if (aMachineIDs == NULL) 2860 return true; 2861 2862 idSet.insert (m->data()->mUuid); 2877 if (m->isFloppyImageUsed (aId, aUsage)) 2878 { 2879 /* if not interested in the list, return shortly */ 2880 if (aMachineIDs == NULL) 2881 return true; 2882 2883 idSet.insert (m->uuid()); 2884 } 2863 2885 } 2864 2886 } … … 2961 2983 ++ it) 2962 2984 { 2963 /* mUuid is constant, no need to lock */ 2964 found = (*it)->data()->mUuid == aId; 2985 AutoLimitedCaller machCaller (*it); 2986 AssertComRC (machCaller.rc()); 2987 2988 found = (*it)->uuid() == aId; 2965 2989 if (found && aMachine) 2966 2990 *aMachine = *it; … … 3653 3677 /// @todo (dmik) move this part to Machine for better incapsulation 3654 3678 3655 ComObjPtr <Machine> m = *it; 3656 AutoReaderLock machineLock (m); 3657 3658 AssertMsg (m->data(), ("Machine data must not be NULL")); 3659 CFGNODE entryNode; 3679 CFGNODE entryNode = NULL; 3660 3680 CFGLDRAppendChildNode (registryNode, Entry, &entryNode); 3661 /* UUID + curly brackets */ 3662 CFGLDRSetUUID (entryNode, "uuid", unconst (m->data()->mUuid).ptr()); 3663 /* source */ 3664 CFGLDRSetBSTR (entryNode, "src", m->data()->mConfigFile); 3665 /* done */ 3681 rc = (*it)->saveRegistryEntry (entryNode); 3666 3682 CFGLDRReleaseNode (entryNode); 3683 CheckComRCBreakRC (rc); 3667 3684 } 3668 3685 … … 3670 3687 } 3671 3688 while (0); 3672 if (FAILED (rc)) 3673 break; 3689 CheckComRCBreakRC (rc); 3674 3690 3675 3691 /* disk images */ … … 3691 3707 rc = saveHardDisks (imagesNode); 3692 3708 CFGLDRReleaseNode (imagesNode); 3693 if (FAILED (rc)) 3694 break; 3709 CheckComRCBreakRC (rc); 3695 3710 } 3696 3711 … … 3740 3755 } 3741 3756 while (0); 3742 if (FAILED (rc)) 3743 break; 3757 CheckComRCBreakRC (rc); 3744 3758 3745 3759 do … … 3747 3761 /* host data (USB filters) */ 3748 3762 rc = mData.mHost->saveSettings (global); 3749 if (FAILED (rc)) 3750 break; 3763 CheckComRCBreakRC (rc); 3751 3764 3752 3765 rc = mData.mSystemProperties->saveSettings (global); 3753 if (FAILED (rc)) 3754 break; 3766 CheckComRCBreakRC (rc); 3755 3767 } 3756 3768 while (0); … … 3866 3878 * saves global settings. 3867 3879 * 3880 * @note The caller must have added itself as a caller of the @a aMachine 3881 * object if calls this method not on VirtualBox startup. 3882 * 3868 3883 * @param aMachine machine to register 3869 3884 * … … 3879 3894 AutoLock alock (this); 3880 3895 3881 ComAssertRet (findMachine (aMachine-> data()->mUuid,3896 ComAssertRet (findMachine (aMachine->uuid(), 3882 3897 false /* aDoSetError */, NULL) == E_INVALIDARG, 3883 3898 E_FAIL); -
trunk/src/VBox/Main/include/MachineImpl.h
r5390 r5627 60 60 class Snapshot; 61 61 class SharedFolder; 62 class HostUSBDevice; 62 63 63 64 class SessionMachine; … … 510 511 ComObjPtr <SessionMachine> sessionMachine(); 511 512 512 // Note: the below methods are intended to be called only after adding 513 // a caller to the Machine instance and, when necessary, from under 514 // the Machine lock in appropriate mode 515 516 /// @todo (dmik) revise code using these methods: improving incapsulation 517 // should make them not necessary 518 519 const ComObjPtr <VirtualBox, ComWeakRef> &virtualBox() { return mParent; } 520 521 const Shareable <Data> &data() const { return mData; } 522 const Backupable <UserData> &userData() const { return mUserData; } 523 const Backupable <HDData> &hdData() const { return mHDData; } 524 525 const Shareable <SSData> &ssData() const { return mSSData; } 526 527 const ComObjPtr <DVDDrive> &dvdDrive() { return mDVDDrive; } 528 const ComObjPtr <FloppyDrive> &floppyDrive() { return mFloppyDrive; } 529 const ComObjPtr <USBController> &usbController() { return mUSBController; } 530 513 /** 514 * Returns the VirtualBox object this machine belongs to. 515 * 516 * @note This method doesn't check this object's readiness as it is 517 * intended to be used only by Machine children where it is guaranteed 518 * that this object still exists in memory. 519 */ 520 const ComObjPtr <VirtualBox, ComWeakRef> &virtualBox() const { return mParent; } 521 522 /** 523 * Returns this machine's name. 524 * 525 * @note This method doesn't check this object's readiness as it is 526 * intended to be used only after adding a caller to this object (that 527 * guarantees that the object is ready or at least limited). 528 */ 529 const Guid &uuid() const { return mData->mUuid; } 530 531 /** 532 * Returns this machine's name. 533 * 534 * @note This method doesn't lock this object or check its readiness as 535 * it is intended to be used only after adding a caller to this object 536 * (that guarantees that the object is ready) and locking it for reading. 537 */ 538 const Bstr &name() const { return mUserData->mName; } 539 540 // callback handlers 531 541 virtual HRESULT onDVDDriveChange() { return S_OK; } 532 542 virtual HRESULT onFloppyDriveChange() { return S_OK; } … … 537 547 virtual HRESULT onUSBControllerChange() { return S_OK; } 538 548 virtual HRESULT onSharedFolderChange() { return S_OK; } 549 550 HRESULT saveRegistryEntry (CFGNODE aEntryNode); 539 551 540 552 int calculateFullPath (const char *aPath, Utf8Str &aResult); … … 794 806 HRESULT onSharedFolderChange(); 795 807 808 bool hasMatchingUSBFilter (const ComObjPtr <HostUSBDevice> &aDevice); 809 796 810 private: 797 811 … … 909 923 910 924 Guid mSnapshotId; 925 926 friend class Snapshot; 911 927 }; 912 928
Note:
See TracChangeset
for help on using the changeset viewer.