Changeset 15762 in vbox for trunk/src/VBox/Main
- Timestamp:
- Dec 25, 2008 11:53:50 PM (16 years ago)
- Location:
- trunk/src/VBox/Main
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Main/ConsoleImpl.cpp
r15708 r15762 38 38 39 39 #include "ConsoleImpl.h" 40 41 #include "Global.h" 40 42 #include "GuestImpl.h" 41 43 #include "KeyboardImpl.h" … … 1352 1354 AutoWriteLock alock (this); 1353 1355 1354 if (mMachineState != MachineState_Running && 1355 mMachineState != MachineState_Paused && 1356 mMachineState != MachineState_Stuck) 1356 if (!Global::IsActive (mMachineState)) 1357 1357 { 1358 1358 /* extra nice error message for a common case */ … … 1392 1392 AutoWriteLock alock (this); 1393 1393 1394 if (mMachineState != MachineState_Running && 1395 mMachineState != MachineState_Paused && 1396 mMachineState != MachineState_Stuck) 1394 if (!Global::IsActive (mMachineState)) 1397 1395 { 1398 1396 /* extra nice error message for a common case */ … … 1456 1454 1457 1455 if (mMachineState != MachineState_Running) 1458 return setError(VBOX_E_INVALID_VM_STATE, 1459 tr ("Cannot reset the machine as it is not running " 1460 "(machine state: %d)"), mMachineState); 1456 return setError (VBOX_E_INVALID_VM_STATE, 1457 tr ("Invalid machine state: %d)"), mMachineState); 1461 1458 1462 1459 /* protect mpVM */ … … 1488 1485 if (mMachineState != MachineState_Running) 1489 1486 return setError (VBOX_E_INVALID_VM_STATE, 1490 tr ("Cannot pause the machine as it is not running " 1491 "(machine state: %d)"), mMachineState); 1487 tr ("Invalid machine state: %d)"), mMachineState); 1492 1488 1493 1489 /* protect mpVM */ … … 1560 1556 if (mMachineState != MachineState_Running) 1561 1557 return setError (VBOX_E_INVALID_VM_STATE, 1562 tr ("Cannot power off the machine as it is not running " 1563 "(machine state: %d)"), mMachineState); 1558 tr ("Invalid machine state: %d)"), mMachineState); 1564 1559 1565 1560 /* protect mpVM */ … … 1599 1594 1600 1595 if (mMachineState != MachineState_Running) 1601 return E_FAIL; 1596 return setError (VBOX_E_INVALID_VM_STATE, 1597 tr ("Invalid machine state: %d)"), mMachineState); 1602 1598 1603 1599 /* protect mpVM */ … … 1642 1638 if (mMachineState != MachineState_Running) 1643 1639 return setError (VBOX_E_INVALID_VM_STATE, 1644 tr ("Cannot get guest ACPI mode as it is " 1645 "not running (machine state: %d)"), mMachineState); 1640 tr ("Invalid machine state: %d)"), mMachineState); 1646 1641 1647 1642 /* protect mpVM */ … … 1677 1672 if (mMachineState != MachineState_Running) 1678 1673 return setError (VBOX_E_INVALID_VM_STATE, 1679 tr ("Cannot send the sleep button event as it is " 1680 "not running (machine state: %d)"), mMachineState); 1674 tr ("Invalid machine state: %d)"), mMachineState); 1681 1675 1682 1676 /* protect mpVM */ … … 1720 1714 return setError (VBOX_E_INVALID_VM_STATE, 1721 1715 tr ("Cannot save the execution state as the machine " 1722 "is not running (machine state: %d)"), mMachineState);1716 "is not running or paused (machine state: %d)"), mMachineState); 1723 1717 } 1724 1718 … … 1987 1981 AutoWriteLock alock (this); 1988 1982 1989 /// @todo (r=dmik) is it legal to attach USB devices when the machine is1990 // Paused, Starting, Saving, Stopping, etc? if not, we should make a1991 // stricter check (mMachineState != MachineState_Running).1992 //1993 // I'm changing it to the semi-strict check for the time being. We'll1994 // consider the below later.1995 //1996 /* bird: It is not permitted to attach or detach while the VM is saving,1997 * is restoring or has stopped - definitely not.1998 *1999 * Attaching while starting, well, if you don't create any deadlock it2000 * should work... Paused should work I guess, but we shouldn't push our2001 * luck if we're pausing because an runtime error condition was raised2002 * (which is one of the reasons there better be a separate state for that2003 * in the VMM).2004 */2005 1983 if (mMachineState != MachineState_Running && 2006 1984 mMachineState != MachineState_Paused) 2007 1985 return setError (VBOX_E_INVALID_VM_STATE, 2008 tr ("Cannot attach a USB device to the machine which is not running"2009 " (machine state: %d)"), mMachineState);1986 tr ("Cannot attach a USB device to the machine which is not " 1987 "running or paused (machine state: %d)"), mMachineState); 2010 1988 2011 1989 /* protect mpVM */ … … 2241 2219 AutoWriteLock alock (this); 2242 2220 2243 if ( mMachineState > MachineState_Paused)2221 if (Global::IsTransient (mMachineState)) 2244 2222 { 2245 2223 return setError (VBOX_E_INVALID_VM_STATE, … … 2410 2388 AutoWriteLock alock (this); 2411 2389 2412 if ( mMachineState >= MachineState_Running)2390 if (Global::IsOnlineOrTransient (mMachineState)) 2413 2391 return setError (VBOX_E_INVALID_VM_STATE, 2414 2392 tr ("Cannot discard a snapshot of the running machine " … … 2431 2409 AutoWriteLock alock (this); 2432 2410 2433 if ( mMachineState >= MachineState_Running)2411 if (Global::IsOnlineOrTransient (mMachineState)) 2434 2412 return setError (VBOX_E_INVALID_VM_STATE, 2435 2413 tr ("Cannot discard the current state of the running machine " … … 2452 2430 AutoWriteLock alock (this); 2453 2431 2454 if ( mMachineState >= MachineState_Running)2432 if (Global::IsOnlineOrTransient (mMachineState)) 2455 2433 return setError (VBOX_E_INVALID_VM_STATE, 2456 2434 tr ("Cannot discard the current snapshot and state of the " … … 4248 4226 AutoWriteLock alock (this); 4249 4227 4250 if ( mMachineState >= MachineState_Running)4228 if (Global::IsOnlineOrTransient (mMachineState)) 4251 4229 return setError(VBOX_E_INVALID_VM_STATE, 4252 tr ("Virtual machine is already running "4230 tr ("Virtual machine is already running or busy " 4253 4231 "(machine state: %d)"), mMachineState); 4254 4232 … … 4910 4888 if (aUpdateServer) 4911 4889 { 4912 /* 4913 * Server notification MUST be done from under the lock; otherwise4914 * the machine state here and on the server might go out of sync, that4915 * can lead to various unexpected results (like the machine state being4916 * >= MachineState_Running on the server, while the session state is4917 * already SessionState_Closed at the same timethere).4890 /* Server notification MUST be done from under the lock; otherwise 4891 * the machine state here and on the server might go out of sync 4892 * whihc can lead to various unexpected results (like the machine 4893 * state being >= MachineState_Running on the server, while the 4894 * session state is already SessionState_Closed at the same time 4895 * there). 4918 4896 * 4919 * 4920 * 4921 * (remember that here we're holding the Console lock here, and4922 * alsoall locks that have been entered by the thread before calling4923 * 4897 * Cross-lock conditions should be carefully watched out: calling 4898 * UpdateState we will require Machine and SessionMachine locks 4899 * (remember that here we're holding the Console lock here, and also 4900 * all locks that have been entered by the thread before calling 4901 * this method). 4924 4902 */ 4925 4903 LogFlowThisFunc (("Doing mControl->UpdateState()...\n")); … … 5441 5419 5442 5420 /* Guru respects only running VMs */ 5443 Assert ( (that->mMachineState >= MachineState_Running));5421 Assert (Global::IsOnline (that->mMachineState)); 5444 5422 5445 5423 that->setMachineState (MachineState_Stuck); -
trunk/src/VBox/Main/DisplayImpl.cpp
r15732 r15762 205 205 if (machineState == MachineState_Running) 206 206 { 207 LogFlowFunc (("Machine running\n"));207 LogFlowFunc (("Machine is running.\n")); 208 208 209 209 mfMachineRunning = true; -
trunk/src/VBox/Main/MachineDebuggerImpl.cpp
r15051 r15762 23 23 24 24 #include "MachineDebuggerImpl.h" 25 26 #include "Global.h" 25 27 #include "ConsoleImpl.h" 26 28 #include "Logging.h" … … 799 801 MachineState_T machineState; 800 802 mParent->COMGETTER(State) (&machineState); 801 if ( machineState != MachineState_Running 802 && machineState != MachineState_Paused 803 && machineState != MachineState_Stuck) 803 if (!Global::IsActive (machineState)) 804 804 // queue the request 805 805 return true; -
trunk/src/VBox/Main/MachineImpl.cpp
r15582 r15762 670 670 (SessionMachine *) mData->mSession.mMachine)); 671 671 672 if ( mData->mMachineState >= MachineState_Running)672 if (Global::IsOnlineOrTransient (mData->mMachineState)) 673 673 { 674 674 LogWarningThisFunc (("Setting state to Aborted!\n")); … … 1945 1945 AssertReturn (mData->mMachineState != MachineState_Saved, E_FAIL); 1946 1946 1947 if ( mData->mMachineState >= MachineState_Running)1947 if (Global::IsOnlineOrTransient (mData->mMachineState)) 1948 1948 return setError (VBOX_E_INVALID_VM_STATE, 1949 1949 tr ("Invalid machine state: %d"), mData->mMachineState); … … 2265 2265 AssertReturn (mData->mMachineState != MachineState_Saved, E_FAIL); 2266 2266 2267 if ( mData->mMachineState >= MachineState_Running)2267 if (Global::IsOnlineOrTransient (mData->mMachineState)) 2268 2268 return setError (VBOX_E_INVALID_VM_STATE, 2269 2269 tr ("Invalid machine state: %d"), mData->mMachineState); … … 3396 3396 mUserData->mName.raw()); 3397 3397 3398 /* may not be Running*/3399 AssertReturn ( mData->mMachineState < MachineState_Running, E_FAIL);3398 /* may not be busy */ 3399 AssertReturn (!Global::IsOnlineOrTransient (mData->mMachineState), E_FAIL); 3400 3400 3401 3401 /* get the session PID */ … … 3603 3603 mUserData->mName.raw()); 3604 3604 3605 /* may not be Running*/3606 AssertReturn ( mData->mMachineState < MachineState_Running, E_FAIL);3605 /* may not be busy */ 3606 AssertReturn (!Global::IsOnlineOrTransient (mData->mMachineState), E_FAIL); 3607 3607 3608 3608 /* get the path to the executable */ … … 7553 7553 AssertReturnVoid (aThat->mType == IsSnapshotMachine); 7554 7554 7555 AssertReturnVoid (mData->mMachineState < MachineState_Running || 7556 mData->mMachineState >= MachineState_Discarding); 7555 AssertReturnVoid (!Global::IsOnline (mData->mMachineState)); 7557 7556 7558 7557 mHWData.assignCopy (aThat->mHWData); … … 7937 7936 if (aReason == Uninit::Abnormal) 7938 7937 { 7939 LogWarningThisFunc (("ABNORMAL client termination! (was Running=%d)\n",7940 lastState >= MachineState_Running));7938 LogWarningThisFunc (("ABNORMAL client termination! (wasBusy=%d)\n", 7939 Global::IsOnlineOrTransient (lastState))); 7941 7940 7942 7941 /* reset the state to Aborted */ … … 7965 7964 #ifdef VBOX_WITH_USB 7966 7965 /* release all captured USB devices */ 7967 if (aReason == Uninit::Abnormal && lastState >= MachineState_Running)7966 if (aReason == Uninit::Abnormal && Global::IsOnline (lastState)) 7968 7967 { 7969 7968 /* Console::captureUSBDevices() is called in the VM process only after … … 8481 8480 AutoMultiWriteLock2 alock (mParent, this); 8482 8481 8483 AssertReturn (( mData->mMachineState < MachineState_Running||8482 AssertReturn ((!Global::IsOnlineOrTransient (mData->mMachineState) || 8484 8483 mData->mMachineState == MachineState_Paused) && 8485 8484 mSnapshotData.mLastState == MachineState_Null && … … 8667 8666 AutoMultiWriteLock2 alock (mParent, this); 8668 8667 8669 ComAssertRet ( mData->mMachineState < MachineState_Running, E_FAIL);8668 ComAssertRet (!Global::IsOnlineOrTransient (mData->mMachineState), E_FAIL); 8670 8669 8671 8670 ComObjPtr <Snapshot> snapshot; … … 8749 8748 AutoWriteLock alock (this); 8750 8749 8751 ComAssertRet ( mData->mMachineState < MachineState_Running, E_FAIL);8750 ComAssertRet (!Global::IsOnlineOrTransient (mData->mMachineState), E_FAIL); 8752 8751 8753 8752 if (mData->mCurrentSnapshot.isNull()) … … 8813 8812 AutoWriteLock alock (this); 8814 8813 8815 ComAssertRet ( mData->mMachineState < MachineState_Running, E_FAIL);8814 ComAssertRet (!Global::IsOnlineOrTransient (mData->mMachineState), E_FAIL); 8816 8815 8817 8816 if (mData->mCurrentSnapshot.isNull()) … … 9509 9508 9510 9509 int opFlags = SaveSS_AddOp | SaveSS_CurrentId; 9511 if ( mSnapshotData.mLastState < MachineState_Running)9510 if (!Global::IsOnline (mSnapshotData.mLastState)) 9512 9511 { 9513 9512 /* the machine was powered off or saved when taking a snapshot, so … … 9522 9521 if (aSuccess && SUCCEEDED (rc)) 9523 9522 { 9524 bool online = mSnapshotData.mLastState >= MachineState_Running;9523 bool online = Global::IsOnline (mSnapshotData.mLastState); 9525 9524 9526 9525 /* associate old hard disks with the snapshot and do locking/unlocking*/ … … 9594 9593 HRESULT rc = S_OK; 9595 9594 9596 bool online = mSnapshotData.mLastState >= MachineState_Running;9595 bool online = Global::IsOnline (mSnapshotData.mLastState); 9597 9596 9598 9597 LogFlowThisFunc (("Creating differencing hard disks (online=%d)...\n", -
trunk/src/VBox/Main/USBControllerImpl.cpp
r15157 r15762 20 20 */ 21 21 22 23 24 22 #include "USBControllerImpl.h" 23 24 #include "Global.h" 25 25 #include "MachineImpl.h" 26 26 #include "VirtualBoxImpl.h" … … 456 456 457 457 /* notify the proxy (only when it makes sense) */ 458 if (filter->data().mActive && adep.machineState() >= MachineState_Running)458 if (filter->data().mActive && Global::IsOnline (adep.machineState())) 459 459 { 460 460 USBProxyService *service = mParent->virtualBox()->host()->usbProxyService(); … … 520 520 521 521 /* notify the proxy (only when it makes sense) */ 522 if (filter->data().mActive && adep.machineState() >= MachineState_Running)522 if (filter->data().mActive && Global::IsOnline (adep.machineState())) 523 523 { 524 524 USBProxyService *service = mParent->virtualBox()->host()->usbProxyService(); … … 846 846 /* notify the proxy (only when it makes sense) */ 847 847 if ((*it)->data().mActive && 848 adep.machineState() >= MachineState_Running && 849 adep.machineState() < MachineState_Discarding) 848 Global::IsOnline (adep.machineState())) 850 849 { 851 850 USBDeviceFilter *filter = *it; … … 860 859 } 861 860 862 if (adep.machineState() >= MachineState_Running && 863 adep.machineState() < MachineState_Discarding) 861 if (Global::IsOnline (adep.machineState())) 864 862 { 865 863 /* find all removed old filters (absent in the new list) … … 1034 1032 AssertComRCReturnVoid (adep.rc()); 1035 1033 /* Machine::copyFrom() may not be called when the VM is running */ 1036 AssertReturnVoid (adep.machineState() < MachineState_Running || 1037 adep.machineState() >= MachineState_Discarding); 1034 AssertReturnVoid (!Global::IsOnline (adep.machineState())); 1038 1035 1039 1036 /* peer is not modified, lock it for reading (aThat is "master" so locked … … 1083 1080 1084 1081 /* nothing to do if the machine isn't running */ 1085 if ( adep.machineState() < MachineState_Running)1082 if (!Global::IsOnline (adep.machineState())) 1086 1083 return S_OK; 1087 1084 -
trunk/src/VBox/Main/idl/VirtualBox.xidl
r15732 r15762 482 482 an offline state. This inconsistency may be removed in one of the future 483 483 versions of VirtualBox by adding a new state. 484 485 <note internal="yes"> 486 For whoever decides to touch this enum: In order to keep the 487 comparisons involving FirstOnline and LastOnline pseudo-states valid, 488 the numeric values of these states must be correspondingly updated if 489 needed: for any online VM state, the condition 490 <tt>FirstOnline <= state <= LastOnline</tt> must be 491 <tt>true</tt>. The same relates to transient states for which 492 the condition <tt>FirstOnline <= state <= LastOnline</tt> must be 493 <tt>true</tt>. 494 </note> 484 495 </desc> 485 496 … … 508 519 <note internal="yes"> 509 520 For whoever decides to touch this enum: In order to keep the 510 comparisons in the source code valid, this state must immediately521 comparisons in the old source code valid, this state must immediately 511 522 precede the Paused state. 512 523 </note> … … 518 529 <note internal="yes"> 519 530 For whoever decides to touch this enum: In order to keep the 520 comparisons in the source code valid, this state must immediately531 comparisons in the old source code valid, this state must immediately 521 532 follow the Running state. 522 533 </note> … … 567 578 <desc> 568 579 Pseudo-state: first online state (for use in relational expressions). 569 <note internal="yes">570 For whoever decides to touch this enum: In order to keep the571 comparisons involving FirstOnline and LastOnline pseudo-states valid,572 the numeric values of these states must be correspondingly updated if573 needed: for any online VM state, the condition574 <tt>FirstOnline <= state <= LastOnline</tt> must be575 <tt>true</tt>.576 </note>577 580 </desc> 578 581 </const> … … 580 583 <desc> 581 584 Pseudo-state: last online state (for use in relational expressions). 582 <note internal="yes"> 583 For whoever decides to touch this enum: In order to keep the 584 comparisons involving FirstOnline and LastOnline pseudo-states valid, 585 the numeric values of these states must be correspondingly updated if 586 needed: for any online VM state, the condition 587 <tt>FirstOnline <= state <= LastOnline</tt> must be 588 <tt>true</tt>. 589 </note> 585 </desc> 586 </const> 587 588 <const name="FirstTransient" value="7" wsmap="suppress"> <!-- Starting --> 589 <desc> 590 Pseudo-state: first transient state (for use in relational expressions). 591 </desc> 592 </const> 593 <const name="LastTransient" value="12" wsmap="suppress"> <!-- SettingUp --> 594 <desc> 595 Pseudo-state: last transient state (for use in relational expressions). 590 596 </desc> 591 597 </const> -
trunk/src/VBox/Main/include/Global.h
r15064 r15762 66 66 67 67 static const char *OSTypeId (VBOXOSTYPE aOSType); 68 69 /** 70 * Returns @c true if the given machine state is an online state. This is a 71 * recommended way to detect if the VM is online (being executed in a 72 * dedicated process) or not. Note that some online states are also 73 * transitional states (see #IsTransitional()). 74 */ 75 static bool IsOnline (MachineState_T aState) 76 { 77 return aState >= MachineState_FirstOnline && 78 aState <= MachineState_LastOnline; 79 } 80 81 /** 82 * Returns @c true if the given machine state is a transient state. This is 83 * a recommended way to detect if the VM is performing some potentially 84 * lengthy operation (such as starting, stopping, saving, discarding 85 * snapshot, etc.). Note some (but not all) transitional states are also 86 * online states (see #IsOnline()). 87 */ 88 static bool IsTransient (MachineState_T aState) 89 { 90 return aState >= MachineState_FirstTransient && 91 aState <= MachineState_LastTransient; 92 } 93 94 /** 95 * Shortcut to <tt>IsOnline (aState) || IsTransient (aState)</tt>. When it 96 * returns @false, the VM is turned off (no VM process) and not busy with 97 * another exclusive operation. 98 */ 99 static bool IsOnlineOrTransient (MachineState_T aState) 100 { 101 return IsOnline (aState) || IsTransient (aState); 102 } 103 104 /** 105 * Shortcut to <tt>IsOnline (aState) && !IsTransient (aState)</tt>. This is 106 * a recommended way to detect if the VM emulation thread is in action 107 * (either running, suspended, or stuck). When this method returns @false, 108 * then either the VM is not online or the emulation thread is being started 109 * or stopped, etc. 110 */ 111 static bool IsActive (MachineState_T aState) 112 { 113 return IsOnline (aState) && !IsTransient (aState); 114 } 68 115 }; 69 116
Note:
See TracChangeset
for help on using the changeset viewer.