Changeset 3424 in vbox for trunk/src/VBox
- Timestamp:
- Jul 4, 2007 4:10:37 PM (18 years ago)
- Location:
- trunk/src/VBox/Main
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Main/MachineImpl.cpp
r3191 r3424 71 71 // defines / prototypes 72 72 ///////////////////////////////////////////////////////////////////////////// 73 74 /**75 * Local mutability check macro for Machine implementation only.76 */77 #define CHECK_SETTER() \78 if (!isMutable()) \79 return setError (E_ACCESSDENIED, tr ("The machine is not mutable"));80 73 81 74 // globals … … 801 794 AutoLock alock (this); 802 795 803 CHECK_SETTER(); 796 HRESULT rc = checkStateDependency (MutableStateDep); 797 CheckComRCReturnRC (rc); 804 798 805 799 mUserData.backup(); … … 831 825 AutoLock alock (this); 832 826 833 CHECK_SETTER(); 827 HRESULT rc = checkStateDependency (MutableStateDep); 828 CheckComRCReturnRC (rc); 834 829 835 830 mUserData.backup(); … … 885 880 AutoLock alock (this); 886 881 887 CHECK_SETTER(); 882 rc = checkStateDependency (MutableStateDep); 883 CheckComRCReturnRC (rc); 888 884 889 885 mUserData.backup(); … … 922 918 AutoLock alock (this); 923 919 924 CHECK_SETTER(); 920 HRESULT rc = checkStateDependency (MutableStateDep); 921 CheckComRCReturnRC (rc); 925 922 926 923 mHWData.backup(); … … 959 956 AutoLock alock (this); 960 957 961 CHECK_SETTER(); 958 HRESULT rc = checkStateDependency (MutableStateDep); 959 CheckComRCReturnRC (rc); 962 960 963 961 mHWData.backup(); … … 995 993 AutoLock alock (this); 996 994 997 CHECK_SETTER(); 995 HRESULT rc = checkStateDependency (MutableStateDep); 996 CheckComRCReturnRC (rc); 998 997 999 998 mHWData.backup(); … … 1039 1038 AutoLock alock (this); 1040 1039 1041 CHECK_SETTER(); 1040 HRESULT rc = checkStateDependency (MutableStateDep); 1041 CheckComRCReturnRC (rc); 1042 1042 1043 1043 /** @todo check validity! */ … … 1078 1078 AutoLock alock (this); 1079 1079 1080 CHECK_SETTER(); 1080 HRESULT rc = checkStateDependency (MutableStateDep); 1081 CheckComRCReturnRC (rc); 1081 1082 1082 1083 if (!mData->mCurrentSnapshot.isNull()) … … 1245 1246 AutoLock alock (this); 1246 1247 1247 CHECK_SETTER(); 1248 HRESULT rc = checkStateDependency (MutableStateDep); 1249 CheckComRCReturnRC (rc); 1248 1250 1249 1251 if (!isConfigLocked()) … … 1467 1469 AutoLock alock (this); 1468 1470 1469 CHECK_SETTER(); 1471 HRESULT rc = checkStateDependency (MutableStateDep); 1472 CheckComRCReturnRC (rc); 1470 1473 1471 1474 mHWData.backup(); … … 1494 1497 AutoLock alock (this); 1495 1498 1496 CHECK_SETTER(); 1499 HRESULT rc = checkStateDependency (MutableStateDep); 1500 CheckComRCReturnRC (rc); 1497 1501 1498 1502 mHWData.backup(); … … 1534 1538 AutoLock alock (this); 1535 1539 1536 CHECK_SETTER(); 1540 HRESULT rc = checkStateDependency (MutableStateDep); 1541 CheckComRCReturnRC (rc); 1537 1542 1538 1543 if (!mData->mRegistered) … … 1564 1569 /* find a hard disk by UUID */ 1565 1570 ComObjPtr <HardDisk> hd; 1566 HRESULT rc = mParent->getHardDisk (id, hd); 1567 if (FAILED (rc)) 1568 return rc; 1571 rc = mParent->getHardDisk (id, hd); 1572 CheckComRCReturnRC (rc); 1569 1573 1570 1574 AutoLock hdLock (hd); … … 1728 1732 AutoLock alock (this); 1729 1733 1730 CHECK_SETTER(); 1734 HRESULT rc = checkStateDependency (MutableStateDep); 1735 CheckComRCReturnRC (rc); 1731 1736 1732 1737 AssertReturn (mData->mMachineState != MachineState_Saved, E_FAIL); … … 1995 2000 1996 2001 if (mType == IsSnapshotMachine) 1997 CHECK_SETTER(); 2002 { 2003 HRESULT rc = checkStateDependency (MutableStateDep); 2004 CheckComRCReturnRC (rc); 2005 } 1998 2006 1999 2007 bool changed = false; … … 2126 2134 AutoMultiLock <2> alock (mParent->wlock(), this->wlock()); 2127 2135 2128 CHECK_SETTER(); 2136 HRESULT rc = checkStateDependency (MutableStateDep); 2137 CheckComRCReturnRC (rc); 2129 2138 2130 2139 /* the settings file path may never be null */ … … 2142 2151 AutoLock alock (this); 2143 2152 2144 CHECK_SETTER(); 2153 HRESULT rc = checkStateDependency (MutableStateDep); 2154 CheckComRCReturnRC (rc); 2145 2155 2146 2156 /* … … 2160 2170 AutoLock alock (this); 2161 2171 2162 CHECK_SETTER(); 2172 HRESULT rc = checkStateDependency (MutableStateDep); 2173 CheckComRCReturnRC (rc); 2163 2174 2164 2175 if (mData->mRegistered) … … 2277 2288 AutoLock alock (this); 2278 2289 2279 CHECK_SETTER(); 2290 HRESULT rc = checkStateDependency (MutableStateDep); 2291 CheckComRCReturnRC (rc); 2280 2292 2281 2293 /// @todo (dmik) check global shared folders when they are done 2282 2294 2283 2295 ComObjPtr <SharedFolder> sharedFolder; 2284 HRESULTrc = findSharedFolder (aName, sharedFolder, false /* aSetError */);2296 rc = findSharedFolder (aName, sharedFolder, false /* aSetError */); 2285 2297 if (SUCCEEDED (rc)) 2286 2298 return setError (E_FAIL, … … 2289 2301 sharedFolder.createObject(); 2290 2302 rc = sharedFolder->init (machine(), aName, aHostPath); 2291 if (FAILED (rc)) 2292 return rc; 2303 CheckComRCReturnRC (rc); 2293 2304 2294 2305 BOOL accessible = FALSE; 2295 2306 rc = sharedFolder->COMGETTER(Accessible) (&accessible); 2296 if (FAILED (rc)) 2297 return rc; 2307 CheckComRCReturnRC (rc); 2298 2308 2299 2309 if (!accessible) … … 2317 2327 AutoReaderLock alock (this); 2318 2328 2319 CHECK_SETTER(); 2329 HRESULT rc = checkStateDependency (MutableStateDep); 2330 CheckComRCReturnRC (rc); 2320 2331 2321 2332 ComObjPtr <SharedFolder> sharedFolder; 2322 HRESULT rc = findSharedFolder (aName, sharedFolder, true /* aSetError */); 2323 if (FAILED (rc)) 2324 return rc; 2333 rc = findSharedFolder (aName, sharedFolder, true /* aSetError */); 2334 CheckComRCReturnRC (rc); 2325 2335 2326 2336 mHWData.backup(); … … 2339 2349 2340 2350 AutoCaller autoCaller (this); 2341 AssertComRCReturn (autoCaller.rc(),autoCaller.rc());2351 AssertComRCReturnRC (autoCaller.rc()); 2342 2352 2343 2353 ComPtr <IInternalSessionControl> directControl; … … 3034 3044 * 3035 3045 * Depending on the @a aDepType value, additional state checks may be 3036 * made. These checks will set extended error info on failure. 3046 * made. These checks will set extended error info on failure. See 3047 * #checkStateDependency() for more info. 3037 3048 * 3038 3049 * If this method returns a failure, the dependency is not added and the … … 3041 3052 * upper level. 3042 3053 * 3043 * @param aDepType Dependency type to choose3054 * @param aDepType Dependency type to add. 3044 3055 * @param aState Current machine state (NULL if not interested). 3045 3056 * @param aRegistered Current registered state (NULL if not interested). … … 3068 3079 mData->mMachineState); 3069 3080 } 3081 3082 HRESULT rc = checkStateDependency (aDepType); 3083 CheckComRCReturnRC (rc); 3084 3085 if (aState) 3086 *aState = mData->mMachineState; 3087 if (aRegistered) 3088 *aRegistered = mData->mRegistered; 3089 3090 ++ mData->mMachineStateDeps; 3091 3092 return S_OK; 3093 } 3094 3095 /** 3096 * Decreases the number of objects dependent on the machine state. 3097 * Must always complete the #addStateDependency() call after the state 3098 * dependency no more necessary. 3099 */ 3100 void Machine::releaseStateDependency() 3101 { 3102 AutoCaller autoCaller (this); 3103 AssertComRCReturnVoid (autoCaller.rc()); 3104 3105 AutoLock alock (this); 3106 3107 AssertReturnVoid (mData->mMachineStateDeps > 0); 3108 -- mData->mMachineStateDeps; 3109 3110 if (mData->mMachineStateDeps == 0 && 3111 mData->mZeroMachineStateDepsSem != NIL_RTSEMEVENT) 3112 { 3113 /* inform checkStateDependencies() that there are no more deps */ 3114 RTSemEventSignal (mData->mZeroMachineStateDepsSem); 3115 } 3116 } 3117 3118 // protected methods 3119 ///////////////////////////////////////////////////////////////////////////// 3120 3121 /** 3122 * Performs machine state checks based on the @a aDepType value. If a check 3123 * fails, this method will set extended error info, otherwise it will return 3124 * S_OK. It is supposed, that on failure, the caller will immedieately return 3125 * the return value of this method to the upper level. 3126 * 3127 * When @a aDepType is AnyStateDep, this method always returns S_OK. 3128 * 3129 * When @a aDepType is MutableStateDep, this method returns S_OK only if the 3130 * current state of this machine object allows to change settings of the 3131 * machine (i.e. the machine is not registered, or registered but not running 3132 * and not saved). It is useful to call this method from Machine setters 3133 * before performing any change. 3134 * 3135 * When @a aDepType is MutableOrSavedStateDep, this method behaves the same 3136 * as for MutableStateDep except that if the machine is saved, S_OK is also 3137 * returned. This is useful in setters which allow changing machine 3138 * properties when it is in the saved state. 3139 * 3140 * @param aDepType Dependency type to check. 3141 * 3142 * @note External classes should use #addStateDependency() and 3143 * #releaseStateDependency() methods or the smart AutoStateDependency 3144 * template. 3145 * 3146 * @note This method must be called from under this object's lock. 3147 */ 3148 HRESULT Machine::checkStateDependency (StateDependency aDepType) 3149 { 3150 AssertReturn (isLockedOnCurrentThread(), E_FAIL); 3070 3151 3071 3152 switch (aDepType) … … 3098 3179 } 3099 3180 3100 if (aState)3101 *aState = mData->mMachineState;3102 if (aRegistered)3103 *aRegistered = mData->mRegistered;3104 3105 ++ mData->mMachineStateDeps;3106 3107 3181 return S_OK; 3108 3182 } 3109 3110 /**3111 * Decreases the number of objects dependent on the machine state.3112 * Must always complete the #addStateDependency() call after the state3113 * dependency no more necessary.3114 */3115 void Machine::releaseStateDependency()3116 {3117 AutoCaller autoCaller (this);3118 AssertComRCReturnVoid (autoCaller.rc());3119 3120 AutoLock alock (this);3121 3122 AssertReturnVoid (mData->mMachineStateDeps > 0);3123 -- mData->mMachineStateDeps;3124 3125 if (mData->mMachineStateDeps == 0 &&3126 mData->mZeroMachineStateDepsSem != NIL_RTSEMEVENT)3127 {3128 /* inform checkStateDependencies() that there are no more deps */3129 RTSemEventSignal (mData->mZeroMachineStateDepsSem);3130 }3131 }3132 3133 // protected methods3134 /////////////////////////////////////////////////////////////////////////////3135 3183 3136 3184 /** … … 3546 3594 * otherwise it will be not possible to change the settings 3547 3595 * somewehere in the code above because all setters will be 3548 * blocked by CHECK_SETTER()3596 * blocked by checkStateDependency (MutableStateDep). 3549 3597 */ 3550 3598 … … 3820 3868 #ifdef VBOX_VRDP 3821 3869 /* RemoteDisplay node (optional) */ 3822 /// @todo (dmik) move the code to VRDPServer3823 /// @todo r=sunlover: moved. dmik, please review.3824 3870 { 3825 3871 CFGNODE remoteDisplayNode = 0; … … 3827 3873 if (remoteDisplayNode) 3828 3874 { 3829 mVRDPServer->loadConfig(remoteDisplayNode);3875 HRESULT rc = mVRDPServer->loadSettings (remoteDisplayNode); 3830 3876 CFGLDRReleaseNode (remoteDisplayNode); 3877 CheckComRCReturnRC (rc); 3831 3878 } 3832 3879 } … … 4070 4117 CFGLDRReleaseNode (driveNode); 4071 4118 4072 if (FAILED (rc)) 4073 return rc; 4119 CheckComRCReturnRC (rc); 4074 4120 } 4075 4121 … … 4077 4123 { 4078 4124 HRESULT rc = mUSBController->loadSettings (aNode); 4079 if (FAILED (rc)) 4080 return rc; 4125 CheckComRCReturnRC (rc); 4081 4126 } 4082 4127 … … 5678 5723 while (0); 5679 5724 5680 if (FAILED (rc)) 5681 return rc; 5725 CheckComRCReturnRC (rc); 5682 5726 5683 5727 /* display (required) */ … … 5692 5736 #ifdef VBOX_VRDP 5693 5737 /* VRDP settings (optional) */ 5694 /// @todo (dmik) move the code to VRDPServer5695 /// @todo r=sunlover: moved. dmik, please review.5696 5738 { 5697 5739 CFGNODE remoteDisplayNode = 0; 5698 5740 CFGLDRCreateChildNode (aNode, "RemoteDisplay", &remoteDisplayNode); 5699 5700 5741 if (remoteDisplayNode) 5701 5742 { 5702 mVRDPServer->saveConfig(remoteDisplayNode);5743 rc = mVRDPServer->saveSettings (remoteDisplayNode); 5703 5744 CFGLDRReleaseNode (remoteDisplayNode); 5745 CheckComRCReturnRC (rc); 5704 5746 } 5705 5747 } … … 5829 5871 while (0); 5830 5872 5831 if (FAILED (rc)) 5832 return rc; 5873 CheckComRCReturnRC (rc); 5833 5874 5834 5875 /* Flooppy drive (required) */ … … 5886 5927 while (0); 5887 5928 5888 if (FAILED (rc)) 5889 return rc; 5929 CheckComRCReturnRC (rc); 5890 5930 5891 5931 5892 5932 /* USB Controller (required) */ 5893 5933 rc = mUSBController->saveSettings (aNode); 5894 if (FAILED (rc)) 5895 return rc; 5934 CheckComRCReturnRC (rc); 5896 5935 5897 5936 /* Network adapters (required) */ -
trunk/src/VBox/Main/include/MachineImpl.h
r3302 r3424 48 48 // defines 49 49 //////////////////////////////////////////////////////////////////////////////// 50 51 /**52 * Checks whether the given Machine object is mutable (allows for calling setters)53 * or not. When the machine is not mutable, sets error info and returns E_ACCESSDENIED.54 * The translatable error message is defined in null context.55 *56 * This macro <b>must</b> be used within setters of all Machine children57 * (DVDDrive, NetworkAdapter, AudioAdapter, etc.).58 *59 * @param machine the machine object (must cast to Machine *)60 */61 /// @todo replace with AutoStateDependency62 #define CHECK_MACHINE_MUTABILITY(machine) \63 do { \64 if (!machine->isMutable()) \65 return setError (E_ACCESSDENIED, tr ("The machine is not mutable")); \66 } while (0)67 68 /** Like CHECK_MACHINE_MUTABILITY but a saved state is OK, too. */69 /// @todo replace with AutoStateDependency70 #define CHECK_MACHINE_MUTABILITY_IGNORING_SAVED(machine) \71 do { \72 if (!machine->isMutableIgnoringSavedState()) \73 return setError (E_ACCESSDENIED, \74 tr ("The machine is not mutable or in saved state")); \75 } while (0)76 77 50 78 51 // helper declarations … … 525 498 526 499 /// @todo (dmik) add lock and make non-inlined after revising classes 527 // that use it (actually, the CHECK_MACHINE_MUTABILITY macro).528 // Note: these classes should enter Machine lock to keep the returned529 // information valid!530 /// @todo replace with AutoStateDependency531 bool isMutable()532 {533 return ((!mData->mRegistered) ||534 (mType == IsSessionMachine &&535 mData->mMachineState <= MachineState_Paused &&536 mData->mMachineState != MachineState_Saved));537 }538 539 /// @todo (dmik) add lock and make non-inlined after revising classes540 // that use it (actually, the CHECK_MACHINE_MUTABILITY_IGNORING_SAVED macro).541 // Note: these classes should enter Machine lock to keep the returned542 // information valid!543 /// @todo replace with AutoStateDependency544 bool isMutableIgnoringSavedState()545 {546 return ((!mData->mRegistered) ||547 (mType == IsSessionMachine &&548 mData->mMachineState <= MachineState_Paused));549 }550 551 /// @todo (dmik) add lock and make non-inlined after revising classes552 500 // that use it. Note: they should enter Machine lock to keep the returned 553 501 // information valid! … … 614 562 615 563 HRESULT registeredInit(); 564 565 HRESULT checkStateDependency (StateDependency aDepType); 616 566 617 567 inline Machine *machine();
Note:
See TracChangeset
for help on using the changeset viewer.