Changeset 47995 in vbox
- Timestamp:
- Aug 22, 2013 2:55:34 PM (11 years ago)
- Location:
- trunk/src/VBox/Frontends/VirtualBox/src
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VirtualBox/src/globals/VBoxGlobal.cpp
r47831 r47995 266 266 , mSelectorWnd (NULL) 267 267 , m_pVirtualMachine(0) 268 , m MediaEnumThread (NULL)268 , m_pMediumEnumerationThread(0) 269 269 , mIsKWinManaged (false) 270 270 #if defined(DEBUG_bird) … … 957 957 } 958 958 959 /**960 * Searches for the given hard disk in the list of known media descriptors and961 * calls UIMedium::details() on the found descriptor.962 *963 * If the requested hard disk is not found (for example, it's a new hard disk964 * for a new VM created outside our UI), then media enumeration is requested and965 * the search is repeated. We assume that the second attempt always succeeds and966 * assert otherwise.967 *968 * @note Technically, the second attempt may fail if, for example, the new hard969 * passed to this method disk gets removed before #startEnumeratingMedia()970 * succeeds. This (unexpected object uninitialization) is a generic971 * problem though and needs to be addressed using exceptions (see also the972 * @todo in UIMedium::details()).973 */974 959 QString VBoxGlobal::details (const CMedium &aMedium, bool aPredictDiff, bool fUseHtml /* = true */) 975 960 { … … 980 965 { 981 966 /* Medium may be new and not already in the media list, request refresh */ 982 startEnumeratingMedia( true /*fReallyNecessary*/);967 startEnumeratingMedia(); 983 968 if (!findMedium (cmedium, medium)) 984 969 /* Medium might be deleted already, return null string */ … … 1660 1645 } 1661 1646 1662 /** 1663 * Appends the NULL medium to the media list. 1664 * For using with VBoxGlobal::startEnumeratingMedia() only. 1665 */ 1666 static void addNullMediumToList (VBoxMediaList &aList, VBoxMediaList::iterator aWhere) 1667 { 1647 static void addNullMediumToList(VBoxMediaList &mediums, VBoxMediaList::iterator where) 1648 { 1649 /* Append the NULL medium to the medium list: */ 1668 1650 UIMedium medium; 1669 aList.insert (aWhere, medium); 1670 } 1671 1672 /** 1673 * Appends the given list of mediums to the media list. 1674 * For using with VBoxGlobal::startEnumeratingMedia() only. 1675 */ 1676 static void addMediumsToList (const CMediumVector &aVector, 1677 VBoxMediaList &aList, 1678 VBoxMediaList::iterator aWhere, 1679 UIMediumType aType, 1680 UIMedium *aParent = 0) 1681 { 1682 VBoxMediaList::iterator first = aWhere; 1683 1684 for (CMediumVector::ConstIterator it = aVector.begin(); it != aVector.end(); ++ it) 1685 { 1686 CMedium cmedium (*it); 1687 UIMedium medium (cmedium, aType, aParent); 1688 1689 /* Search for a proper alphabetic position */ 1651 mediums.insert(where, medium); 1652 } 1653 1654 static void addMediumsToList(const CMediumVector &inputMediums, 1655 VBoxMediaList &outputMediums, 1656 VBoxMediaList::iterator where, 1657 UIMediumType mediumType, 1658 UIMedium *pParent = 0) 1659 { 1660 /* Appends the given list of input-mediums to the output-mediums: */ 1661 VBoxMediaList::iterator first = where; 1662 1663 for (CMediumVector::ConstIterator it = inputMediums.begin(); it != inputMediums.end(); ++it) 1664 { 1665 CMedium cmedium(*it); 1666 UIMedium medium(cmedium, mediumType, pParent); 1667 1668 /* Search for a proper alphabetic position: */ 1690 1669 VBoxMediaList::iterator jt = first; 1691 for (; jt != aWhere; ++ jt)1692 if ((*jt).name().localeAwareCompare 1670 for (; jt != where; ++ jt) 1671 if ((*jt).name().localeAwareCompare(medium.name()) > 0) 1693 1672 break; 1694 1673 1695 aList.insert(jt, medium);1696 1697 /* Adjust the first item if inserted before it */1674 outputMediums.insert(jt, medium); 1675 1676 /* Adjust the first item if inserted before it: */ 1698 1677 if (jt == first) 1699 -- first; 1700 } 1701 } 1702 1703 /** 1704 * Appends the given list of hard disks and all their children to the media list. 1705 * For using with VBoxGlobal::startEnumeratingMedia() only. 1706 */ 1707 static void addHardDisksToList (const CMediumVector &aVector, 1708 VBoxMediaList &aList, 1709 VBoxMediaList::iterator aWhere, 1710 UIMedium *aParent = 0) 1711 { 1712 VBoxMediaList::iterator first = aWhere; 1678 --first; 1679 } 1680 } 1681 1682 static void addHardDisksToList(const CMediumVector &inputMediums, 1683 VBoxMediaList &outputMediums, 1684 VBoxMediaList::iterator where, 1685 UIMedium *pParent = 0) 1686 { 1687 /* Appends the given list of input-hard-disks and all their children to the output-mediums: */ 1688 VBoxMediaList::iterator first = where; 1713 1689 1714 1690 /* First pass: Add siblings sorted */ 1715 for (CMediumVector::ConstIterator it = aVector.begin(); it != aVector.end(); ++it)1716 { 1717 CMedium cmedium 1718 UIMedium medium (cmedium, UIMediumType_HardDisk, aParent);1719 1720 /* Search for a proper alphabetic position */1691 for (CMediumVector::ConstIterator it = inputMediums.begin(); it != inputMediums.end(); ++it) 1692 { 1693 CMedium cmedium(*it); 1694 UIMedium medium(cmedium, UIMediumType_HardDisk, pParent); 1695 1696 /* Search for a proper alphabetic position: */ 1721 1697 VBoxMediaList::iterator jt = first; 1722 for (; jt != aWhere; ++ jt)1723 if ((*jt).name().localeAwareCompare 1698 for (; jt != where; ++ jt) 1699 if ((*jt).name().localeAwareCompare(medium.name()) > 0) 1724 1700 break; 1725 1701 1726 aList.insert(jt, medium);1727 1728 /* Adjust the first item if inserted before it */1702 outputMediums.insert(jt, medium); 1703 1704 /* Adjust the first item if inserted before it: */ 1729 1705 if (jt == first) 1730 -- 1731 } 1732 1733 /* Second pass: Add children */1734 for (VBoxMediaList::iterator it = first; it != aWhere;)1706 --first; 1707 } 1708 1709 /* Second pass: Add children: */ 1710 for (VBoxMediaList::iterator it = first; it != where;) 1735 1711 { 1736 1712 CMediumVector children = (*it).medium().GetChildren(); 1737 1713 UIMedium *parent = &(*it); 1738 1714 1739 ++ it; /* go to the next sibling before inserting children */ 1740 addHardDisksToList (children, aList, it, parent); 1741 } 1742 } 1743 1744 /** 1745 * Starts a thread that asynchronously enumerates all currently registered 1746 * media. 1747 * 1748 * Before the enumeration is started, the current media list (a list returned by 1749 * #currentMediaList()) is populated with all registered media and the 1750 * #mediumEnumStarted() signal is emitted. The enumeration thread then walks this 1751 * list, checks for media accessibility and emits #mediumEnumerated() signals of 1752 * each checked medium. When all media are checked, the enumeration thread is 1753 * stopped and the #mediumEnumFinished() signal is emitted. 1754 * 1755 * If the enumeration is already in progress, no new thread is started. 1756 * 1757 * The media list returned by #currentMediaList() is always sorted 1758 * alphabetically by the location attribute and comes in the following order: 1759 * <ol> 1760 * <li>All hard disks. If a hard disk has children, these children 1761 * (alphabetically sorted) immediately follow their parent and therefore 1762 * appear before its next sibling hard disk.</li> 1763 * <li>All CD/DVD images.</li> 1764 * <li>All Floppy images.</li> 1765 * </ol> 1766 * 1767 * Note that #mediumEnumerated() signals are emitted in the same order as 1768 * described above. 1769 * 1770 * @param fReallyNecessary Whether the caller actually needs the media info 1771 * now, or is just trying to be nice and start the 1772 * IPC storm... er... caching process early. 1773 * 1774 * @sa #currentMediaList() 1775 * @sa #isMediaEnumerationStarted() 1776 */ 1777 void VBoxGlobal::startEnumeratingMedia(bool fReallyNecessary) 1778 { 1779 AssertReturnVoid (mValid); 1780 1781 /* check if already started but not yet finished */ 1782 if (mMediaEnumThread != NULL) 1715 ++it; /* go to the next sibling before inserting children */ 1716 addHardDisksToList(children, outputMediums, it, parent); 1717 } 1718 } 1719 1720 void VBoxGlobal::startEnumeratingMedia(bool fForceStart /*= true*/) 1721 { 1722 /* Make sure VBoxGlobal is already valid: */ 1723 AssertReturnVoid(mValid); 1724 1725 /* Make sure enumeration is not already started: */ 1726 if (m_pMediumEnumerationThread) 1783 1727 return; 1784 1728 … … 1793 1737 1794 1738 /* Developer doesn't want any unnecessary media caching! */ 1795 if (!f ReallyNecessary&& !agressiveCaching())1739 if (!fForceStart && !agressiveCaching()) 1796 1740 return; 1797 1741 1798 1742 /* composes a list of all currently known media & their children */ 1799 m MediaList.clear();1800 addNullMediumToList (m MediaList, mMediaList.end());1801 addHardDisksToList (mVBox.GetHardDisks(), m MediaList, mMediaList.end());1802 addMediumsToList (mHost.GetDVDDrives(), m MediaList, mMediaList.end(), UIMediumType_DVD);1803 addMediumsToList (mVBox.GetDVDImages(), m MediaList, mMediaList.end(), UIMediumType_DVD);1804 addMediumsToList (mHost.GetFloppyDrives(), m MediaList, mMediaList.end(), UIMediumType_Floppy);1805 addMediumsToList (mVBox.GetFloppyImages(), m MediaList, mMediaList.end(), UIMediumType_Floppy);1743 m_mediums.clear(); 1744 addNullMediumToList (m_mediums, m_mediums.end()); 1745 addHardDisksToList (mVBox.GetHardDisks(), m_mediums, m_mediums.end()); 1746 addMediumsToList (mHost.GetDVDDrives(), m_mediums, m_mediums.end(), UIMediumType_DVD); 1747 addMediumsToList (mVBox.GetDVDImages(), m_mediums, m_mediums.end(), UIMediumType_DVD); 1748 addMediumsToList (mHost.GetFloppyDrives(), m_mediums, m_mediums.end(), UIMediumType_Floppy); 1749 addMediumsToList (mVBox.GetFloppyImages(), m_mediums, m_mediums.end(), UIMediumType_Floppy); 1806 1750 1807 1751 /* enumeration thread class */ … … 1852 1796 }; 1853 1797 1854 m MediaEnumThread = new MediaEnumThread (mMediaList);1855 AssertReturnVoid (mMediaEnumThread);1856 1857 /* emit mediumEnumStarted() after we set mMediaEnumThread to != NULL1858 * to cause isMediaEnumerationStarted() to return TRUE from slots */1798 m_pMediumEnumerationThread = new MediaEnumThread(m_mediums); 1799 AssertReturnVoid(m_pMediumEnumerationThread); 1800 1801 /* Emit mediumEnumStarted() after we set m_pMediumEnumerationThread to != NULL 1802 * to cause isMediaEnumerationStarted() to return TRUE from slots: */ 1859 1803 emit mediumEnumStarted(); 1860 1804 1861 m MediaEnumThread->start();1805 m_pMediumEnumerationThread->start(); 1862 1806 } 1863 1807 … … 1902 1846 void VBoxGlobal::addMedium (const UIMedium &aMedium) 1903 1847 { 1904 /* Note that we maintain the same order here as #startEnumeratingMedia() */ 1905 1906 VBoxMediaList::iterator it = mMediaList.begin(); 1848 VBoxMediaList::iterator it = m_mediums.begin(); 1907 1849 1908 1850 if (aMedium.type() == UIMediumType_HardDisk) 1909 1851 { 1910 VBoxMediaList::iterator itParent = m MediaList.end();1911 1912 for (; it != m MediaList.end(); ++ it)1852 VBoxMediaList::iterator itParent = m_mediums.end(); 1853 1854 for (; it != m_mediums.end(); ++ it) 1913 1855 { 1914 1856 /* skip null medium that come first */ … … 1918 1860 break; 1919 1861 1920 if (aMedium.parent() != NULL && itParent == m MediaList.end())1862 if (aMedium.parent() != NULL && itParent == m_mediums.end()) 1921 1863 { 1922 1864 if (&*it == aMedium.parent()) … … 1937 1879 } 1938 1880 1939 AssertReturnVoid (aMedium.parent() == NULL || itParent != m MediaList.end());1881 AssertReturnVoid (aMedium.parent() == NULL || itParent != m_mediums.end()); 1940 1882 } 1941 1883 else 1942 1884 { 1943 for (; it != m MediaList.end(); ++ it)1885 for (; it != m_mediums.end(); ++ it) 1944 1886 { 1945 1887 /* skip null medium that come first */ … … 1962 1904 } 1963 1905 1964 it = m MediaList.insert (it, aMedium);1906 it = m_mediums.insert (it, aMedium); 1965 1907 1966 1908 emit mediumAdded (*it); … … 1976 1918 { 1977 1919 VBoxMediaList::Iterator it; 1978 for (it = m MediaList.begin(); it != mMediaList.end(); ++ it)1920 for (it = m_mediums.begin(); it != m_mediums.end(); ++ it) 1979 1921 if ((*it).id() == aMedium.id()) 1980 1922 break; 1981 1923 1982 AssertReturnVoid (it != m MediaList.end());1924 AssertReturnVoid (it != m_mediums.end()); 1983 1925 1984 1926 if (&*it != &aMedium) … … 1997 1939 { 1998 1940 VBoxMediaList::Iterator it; 1999 for (it = m MediaList.begin(); it != mMediaList.end(); ++ it)1941 for (it = m_mediums.begin(); it != m_mediums.end(); ++ it) 2000 1942 if ((*it).id() == aId) 2001 1943 break; 2002 1944 2003 AssertReturnVoid (it != m MediaList.end());1945 AssertReturnVoid (it != m_mediums.end()); 2004 1946 2005 1947 #if DEBUG … … 2008 1950 VBoxMediaList::Iterator jt = it; 2009 1951 ++ jt; 2010 AssertReturnVoid (jt == m MediaList.end() || (*jt).parent() != &*it);1952 AssertReturnVoid (jt == m_mediums.end() || (*jt).parent() != &*it); 2011 1953 } 2012 1954 #endif … … 2016 1958 /* remove the medium from the list to keep it in sync with the server "for 2017 1959 * free" when the medium is deleted from one of our UIs */ 2018 m MediaList.erase (it);1960 m_mediums.erase (it); 2019 1961 2020 1962 emit mediumRemoved (aType, aId); … … 2036 1978 bool VBoxGlobal::findMedium (const CMedium &aObj, UIMedium &aMedium) const 2037 1979 { 2038 for (VBoxMediaList::ConstIterator it = m MediaList.begin(); it != mMediaList.end(); ++ it)1980 for (VBoxMediaList::ConstIterator it = m_mediums.begin(); it != m_mediums.end(); ++ it) 2039 1981 { 2040 1982 if (((*it).medium().isNull() && aObj.isNull()) || … … 2055 1997 UIMedium VBoxGlobal::findMedium (const QString &aMediumId) const 2056 1998 { 2057 for (VBoxMediaList::ConstIterator it = m MediaList.begin(); it != mMediaList.end(); ++ it)1999 for (VBoxMediaList::ConstIterator it = m_mediums.begin(); it != m_mediums.end(); ++ it) 2058 2000 if ((*it).id() == aMediumId) 2059 2001 return *it; … … 2273 2215 2274 2216 /* refresh media properties since they contain some translations too */ 2275 for (VBoxMediaList::iterator it = m MediaList.begin();2276 it != m MediaList.end(); ++ it)2217 for (VBoxMediaList::iterator it = m_mediums.begin(); 2218 it != m_mediums.end(); ++ it) 2277 2219 it->refresh(); 2278 2220 … … 4091 4033 !ev->mMedium.result().isOk()) 4092 4034 msgCenter().cannotGetMediaAccessibility (ev->mMedium); 4093 Assert (ev->mIterator != m MediaList.end());4035 Assert (ev->mIterator != m_mediums.end()); 4094 4036 *(ev->mIterator) = ev->mMedium; 4095 4037 emit mediumEnumerated (*ev->mIterator); … … 4098 4040 { 4099 4041 /* the thread has posted the last message, wait for termination */ 4100 m MediaEnumThread->wait();4101 delete m MediaEnumThread;4102 m MediaEnumThread = 0;4103 emit mediumEnumFinished (m MediaList);4042 m_pMediumEnumerationThread->wait(); 4043 delete m_pMediumEnumerationThread; 4044 m_pMediumEnumerationThread = 0; 4045 emit mediumEnumFinished (m_mediums); 4104 4046 } 4105 4047 … … 4627 4569 * but this method should be run anyway just to enumerate null UIMedium object, 4628 4570 * used by some VBox smart widgets, like VBoxMediaComboBox: */ 4629 vboxGlobal().startEnumeratingMedia(false /*fReallyNecessary*/); 4571 if (agressiveCaching()) 4572 startEnumeratingMedia(); 4630 4573 4631 4574 /* Prepare global settings change handler: */ … … 4683 4626 4684 4627 /* Cleanup medium enumeration thread: */ 4685 if (m MediaEnumThread)4686 { 4687 m MediaEnumThread->wait();4688 delete m MediaEnumThread;4689 m MediaEnumThread = 0;4628 if (m_pMediumEnumerationThread) 4629 { 4630 m_pMediumEnumerationThread->wait(); 4631 delete m_pMediumEnumerationThread; 4632 m_pMediumEnumerationThread = 0; 4690 4633 } 4691 4634 … … 4705 4648 4706 4649 /* media list contains a lot of CUUnknown, release them */ 4707 m MediaList.clear();4650 m_mediums.clear(); 4708 4651 /* the last steps to ensure we don't use COM any more */ 4709 4652 mHost.detach(); -
trunk/src/VBox/Frontends/VirtualBox/src/globals/VBoxGlobal.h
r47831 r47995 124 124 const QRect availableGeometry(int iScreen = 0) const; 125 125 126 bool agressiveCaching() const { return mAgressiveCaching; }127 126 bool shouldRestoreCurrentSnapshot() const { return mRestoreCurrentSnapshot; } 128 127 bool isPatmDisabled() const { return mDisablePatm; } … … 241 240 CSession openExistingSession(const QString &aId) { return openSession(aId, KLockType_Shared); } 242 241 243 void startEnumeratingMedia(bool fReallyNecessary);244 245 242 void reloadProxySettings(); 246 243 247 /** 248 * Returns a list of all currently registered media. This list is used to 249 * globally track the accessibility state of all media on a dedicated thread. 250 * 251 * Note that the media list is initially empty (i.e. before the enumeration 252 * process is started for the first time using #startEnumeratingMedia()). 253 * See #startEnumeratingMedia() for more information about how meida are 254 * sorted in the returned list. 255 */ 256 const VBoxMediaList ¤tMediaList() const { return mMediaList; } 257 258 /** Returns true if the media enumeration is in progress. */ 259 bool isMediaEnumerationStarted() const { return mMediaEnumThread != NULL; } 244 /* API: Medium-enumeration stuff: */ 245 void startEnumeratingMedia(bool fForceStart = true); 246 bool agressiveCaching() const { return mAgressiveCaching; } 247 bool isMediaEnumerationStarted() const { return !!m_pMediumEnumerationThread; } 248 const VBoxMediaList ¤tMediaList() const { return m_mediums; } 260 249 261 250 void addMedium (const UIMedium &); … … 395 384 signals: 396 385 397 /** 398 * Emitted at the beginning of the enumeration process started by 399 * #startEnumeratingMedia(). 400 */ 386 /* Notifiers: Medium-enumeration stuff: */ 401 387 void mediumEnumStarted(); 402 403 /** 404 * Emitted when a new medium item from the list has updated its 405 * accessibility state. 406 */ 407 void mediumEnumerated (const UIMedium &aMedum); 408 409 /** 410 * Emitted at the end of the enumeration process started by 411 * #startEnumeratingMedia(). The @a aList argument is passed for 412 * convenience, it is exactly the same as returned by #currentMediaList(). 413 */ 414 void mediumEnumFinished (const VBoxMediaList &aList); 388 void mediumEnumerated(const UIMedium &medum); 389 void mediumEnumFinished(const VBoxMediaList &mediums); 415 390 416 391 /** Emitted when a new media is added using #addMedia(). */ … … 469 444 bool mShowStartVMErrors; 470 445 471 QThread *m MediaEnumThread;472 VBoxMediaList m MediaList;446 QThread *m_pMediumEnumerationThread; 447 VBoxMediaList m_mediums; 473 448 474 449 RenderMode vm_render_mode; -
trunk/src/VBox/Frontends/VirtualBox/src/medium/UIMediumManager.cpp
r47952 r47995 511 511 512 512 if (aRefresh && !vboxGlobal().isMediaEnumerationStarted()) 513 vboxGlobal().startEnumeratingMedia( true /*fReallyNecessary*/);513 vboxGlobal().startEnumeratingMedia(); 514 514 else 515 515 { … … 616 616 { 617 617 /* Start enumerating media */ 618 vboxGlobal().startEnumeratingMedia( true /*fReallyNecessary*/);618 vboxGlobal().startEnumeratingMedia(); 619 619 } 620 620 -
trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIMachine.cpp
r47831 r47995 382 382 qApp->setQuitOnLastWindowClosed(false); 383 383 384 /* Cache IMedium data: */385 vboxGlobal().startEnumeratingMedia(false /* fReallyNecessary*/);384 /* Cache medium data only if really necessary: */ 385 vboxGlobal().startEnumeratingMedia(false /* force start */); 386 386 387 387 /* Load machine settings: */ -
trunk/src/VBox/Frontends/VirtualBox/src/settings/machine/UIMachineSettingsStorage.cpp
r47944 r47995 1735 1735 * lasted point, where we can start. The rest of the media checking is done 1736 1736 * in a background thread. */ 1737 vboxGlobal().startEnumeratingMedia( true /*fReallyNecessary*/);1737 vboxGlobal().startEnumeratingMedia(); 1738 1738 1739 1739 /* Initialize pixmap pool */ -
trunk/src/VBox/Frontends/VirtualBox/src/widgets/VBoxMediaComboBox.cpp
r47831 r47995 90 90 { 91 91 if (!vboxGlobal().isMediaEnumerationStarted()) 92 vboxGlobal().startEnumeratingMedia( true /*fReallyNecessary*/);92 vboxGlobal().startEnumeratingMedia(); 93 93 else 94 94 refresh();
Note:
See TracChangeset
for help on using the changeset viewer.