VirtualBox

Changeset 47995 in vbox


Ignore:
Timestamp:
Aug 22, 2013 2:55:34 PM (11 years ago)
Author:
vboxsync
Message:

FE/Qt: 6909: Medium-enumeration cleanup (first steps).

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  
    266266    , mSelectorWnd (NULL)
    267267    , m_pVirtualMachine(0)
    268     , mMediaEnumThread (NULL)
     268    , m_pMediumEnumerationThread(0)
    269269    , mIsKWinManaged (false)
    270270#if defined(DEBUG_bird)
     
    957957}
    958958
    959 /**
    960  * Searches for the given hard disk in the list of known media descriptors and
    961  * calls UIMedium::details() on the found descriptor.
    962  *
    963  * If the requested hard disk is not found (for example, it's a new hard disk
    964  * for a new VM created outside our UI), then media enumeration is requested and
    965  * the search is repeated. We assume that the second attempt always succeeds and
    966  * assert otherwise.
    967  *
    968  * @note Technically, the second attempt may fail if, for example, the new hard
    969  *       passed to this method disk gets removed before #startEnumeratingMedia()
    970  *       succeeds. This (unexpected object uninitialization) is a generic
    971  *       problem though and needs to be addressed using exceptions (see also the
    972  *       @todo in UIMedium::details()).
    973  */
    974959QString VBoxGlobal::details (const CMedium &aMedium, bool aPredictDiff, bool fUseHtml /* = true */)
    975960{
     
    980965    {
    981966        /* Medium may be new and not already in the media list, request refresh */
    982         startEnumeratingMedia(true /*fReallyNecessary*/);
     967        startEnumeratingMedia();
    983968        if (!findMedium (cmedium, medium))
    984969            /* Medium might be deleted already, return null string */
     
    16601645}
    16611646
    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 {
     1647static void addNullMediumToList(VBoxMediaList &mediums, VBoxMediaList::iterator where)
     1648{
     1649   /* Append the NULL medium to the medium list: */
    16681650    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
     1654static 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: */
    16901669        VBoxMediaList::iterator jt = first;
    1691         for (; jt != aWhere; ++ jt)
    1692             if ((*jt).name().localeAwareCompare (medium.name()) > 0)
     1670        for (; jt != where; ++ jt)
     1671            if ((*jt).name().localeAwareCompare(medium.name()) > 0)
    16931672                break;
    16941673
    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: */
    16981677        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
     1682static 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;
    17131689
    17141690    /* First pass: Add siblings sorted */
    1715     for (CMediumVector::ConstIterator it = aVector.begin(); it != aVector.end(); ++ it)
    1716     {
    1717         CMedium cmedium (*it);
    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: */
    17211697        VBoxMediaList::iterator jt = first;
    1722         for (; jt != aWhere; ++ jt)
    1723             if ((*jt).name().localeAwareCompare (medium.name()) > 0)
     1698        for (; jt != where; ++ jt)
     1699            if ((*jt).name().localeAwareCompare(medium.name()) > 0)
    17241700                break;
    17251701
    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: */
    17291705        if (jt == first)
    1730             -- first;
    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;)
    17351711    {
    17361712        CMediumVector children = (*it).medium().GetChildren();
    17371713        UIMedium *parent = &(*it);
    17381714
    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
     1720void 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)
    17831727        return;
    17841728
     
    17931737
    17941738    /* Developer doesn't want any unnecessary media caching! */
    1795     if (!fReallyNecessary && !agressiveCaching())
     1739    if (!fForceStart && !agressiveCaching())
    17961740        return;
    17971741
    17981742    /* composes a list of all currently known media & their children */
    1799     mMediaList.clear();
    1800     addNullMediumToList (mMediaList, mMediaList.end());
    1801     addHardDisksToList (mVBox.GetHardDisks(), mMediaList, mMediaList.end());
    1802     addMediumsToList (mHost.GetDVDDrives(), mMediaList, mMediaList.end(), UIMediumType_DVD);
    1803     addMediumsToList (mVBox.GetDVDImages(), mMediaList, mMediaList.end(), UIMediumType_DVD);
    1804     addMediumsToList (mHost.GetFloppyDrives(), mMediaList, mMediaList.end(), UIMediumType_Floppy);
    1805     addMediumsToList (mVBox.GetFloppyImages(), mMediaList, 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);
    18061750
    18071751    /* enumeration thread class */
     
    18521796    };
    18531797
    1854     mMediaEnumThread = new MediaEnumThread (mMediaList);
    1855     AssertReturnVoid (mMediaEnumThread);
    1856 
    1857     /* emit mediumEnumStarted() after we set mMediaEnumThread to != NULL
    1858      * 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: */
    18591803    emit mediumEnumStarted();
    18601804
    1861     mMediaEnumThread->start();
     1805    m_pMediumEnumerationThread->start();
    18621806}
    18631807
     
    19021846void VBoxGlobal::addMedium (const UIMedium &aMedium)
    19031847{
    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();
    19071849
    19081850    if (aMedium.type() == UIMediumType_HardDisk)
    19091851    {
    1910         VBoxMediaList::iterator itParent = mMediaList.end();
    1911 
    1912         for (; it != mMediaList.end(); ++ it)
     1852        VBoxMediaList::iterator itParent = m_mediums.end();
     1853
     1854        for (; it != m_mediums.end(); ++ it)
    19131855        {
    19141856            /* skip null medium that come first */
     
    19181860                break;
    19191861
    1920             if (aMedium.parent() != NULL && itParent == mMediaList.end())
     1862            if (aMedium.parent() != NULL && itParent == m_mediums.end())
    19211863            {
    19221864                if (&*it == aMedium.parent())
     
    19371879        }
    19381880
    1939         AssertReturnVoid (aMedium.parent() == NULL || itParent != mMediaList.end());
     1881        AssertReturnVoid (aMedium.parent() == NULL || itParent != m_mediums.end());
    19401882    }
    19411883    else
    19421884    {
    1943         for (; it != mMediaList.end(); ++ it)
     1885        for (; it != m_mediums.end(); ++ it)
    19441886        {
    19451887            /* skip null medium that come first */
     
    19621904    }
    19631905
    1964     it = mMediaList.insert (it, aMedium);
     1906    it = m_mediums.insert (it, aMedium);
    19651907
    19661908    emit mediumAdded (*it);
     
    19761918{
    19771919    VBoxMediaList::Iterator it;
    1978     for (it = mMediaList.begin(); it != mMediaList.end(); ++ it)
     1920    for (it = m_mediums.begin(); it != m_mediums.end(); ++ it)
    19791921        if ((*it).id() == aMedium.id())
    19801922            break;
    19811923
    1982     AssertReturnVoid (it != mMediaList.end());
     1924    AssertReturnVoid (it != m_mediums.end());
    19831925
    19841926    if (&*it != &aMedium)
     
    19971939{
    19981940    VBoxMediaList::Iterator it;
    1999     for (it = mMediaList.begin(); it != mMediaList.end(); ++ it)
     1941    for (it = m_mediums.begin(); it != m_mediums.end(); ++ it)
    20001942        if ((*it).id() == aId)
    20011943            break;
    20021944
    2003     AssertReturnVoid (it != mMediaList.end());
     1945    AssertReturnVoid (it != m_mediums.end());
    20041946
    20051947#if DEBUG
     
    20081950        VBoxMediaList::Iterator jt = it;
    20091951        ++ jt;
    2010         AssertReturnVoid (jt == mMediaList.end() || (*jt).parent() != &*it);
     1952        AssertReturnVoid (jt == m_mediums.end() || (*jt).parent() != &*it);
    20111953    }
    20121954#endif
     
    20161958    /* remove the medium from the list to keep it in sync with the server "for
    20171959     * free" when the medium is deleted from one of our UIs */
    2018     mMediaList.erase (it);
     1960    m_mediums.erase (it);
    20191961
    20201962    emit mediumRemoved (aType, aId);
     
    20361978bool VBoxGlobal::findMedium (const CMedium &aObj, UIMedium &aMedium) const
    20371979{
    2038     for (VBoxMediaList::ConstIterator it = mMediaList.begin(); it != mMediaList.end(); ++ it)
     1980    for (VBoxMediaList::ConstIterator it = m_mediums.begin(); it != m_mediums.end(); ++ it)
    20391981    {
    20401982        if (((*it).medium().isNull() && aObj.isNull()) ||
     
    20551997UIMedium VBoxGlobal::findMedium (const QString &aMediumId) const
    20561998{
    2057     for (VBoxMediaList::ConstIterator it = mMediaList.begin(); it != mMediaList.end(); ++ it)
     1999    for (VBoxMediaList::ConstIterator it = m_mediums.begin(); it != m_mediums.end(); ++ it)
    20582000        if ((*it).id() == aMediumId)
    20592001            return *it;
     
    22732215
    22742216    /* refresh media properties since they contain some translations too  */
    2275     for (VBoxMediaList::iterator it = mMediaList.begin();
    2276          it != mMediaList.end(); ++ it)
     2217    for (VBoxMediaList::iterator it = m_mediums.begin();
     2218         it != m_mediums.end(); ++ it)
    22772219        it->refresh();
    22782220
     
    40914033                    !ev->mMedium.result().isOk())
    40924034                    msgCenter().cannotGetMediaAccessibility (ev->mMedium);
    4093                 Assert (ev->mIterator != mMediaList.end());
     4035                Assert (ev->mIterator != m_mediums.end());
    40944036                *(ev->mIterator) = ev->mMedium;
    40954037                emit mediumEnumerated (*ev->mIterator);
     
    40984040            {
    40994041                /* the thread has posted the last message, wait for termination */
    4100                 mMediaEnumThread->wait();
    4101                 delete mMediaEnumThread;
    4102                 mMediaEnumThread = 0;
    4103                 emit mediumEnumFinished (mMediaList);
     4042                m_pMediumEnumerationThread->wait();
     4043                delete m_pMediumEnumerationThread;
     4044                m_pMediumEnumerationThread = 0;
     4045                emit mediumEnumFinished (m_mediums);
    41044046            }
    41054047
     
    46274569     * but this method should be run anyway just to enumerate null UIMedium object,
    46284570     * used by some VBox smart widgets, like VBoxMediaComboBox: */
    4629     vboxGlobal().startEnumeratingMedia(false /*fReallyNecessary*/);
     4571    if (agressiveCaching())
     4572        startEnumeratingMedia();
    46304573
    46314574    /* Prepare global settings change handler: */
     
    46834626
    46844627    /* Cleanup medium enumeration thread: */
    4685     if (mMediaEnumThread)
    4686     {
    4687         mMediaEnumThread->wait();
    4688         delete mMediaEnumThread;
    4689         mMediaEnumThread = 0;
     4628    if (m_pMediumEnumerationThread)
     4629    {
     4630        m_pMediumEnumerationThread->wait();
     4631        delete m_pMediumEnumerationThread;
     4632        m_pMediumEnumerationThread = 0;
    46904633    }
    46914634
     
    47054648
    47064649    /* media list contains a lot of CUUnknown, release them */
    4707     mMediaList.clear();
     4650    m_mediums.clear();
    47084651    /* the last steps to ensure we don't use COM any more */
    47094652    mHost.detach();
  • trunk/src/VBox/Frontends/VirtualBox/src/globals/VBoxGlobal.h

    r47831 r47995  
    124124    const QRect availableGeometry(int iScreen = 0) const;
    125125
    126     bool agressiveCaching() const { return mAgressiveCaching; }
    127126    bool shouldRestoreCurrentSnapshot() const { return mRestoreCurrentSnapshot; }
    128127    bool isPatmDisabled() const { return mDisablePatm; }
     
    241240    CSession openExistingSession(const QString &aId) { return openSession(aId, KLockType_Shared); }
    242241
    243     void startEnumeratingMedia(bool fReallyNecessary);
    244 
    245242    void reloadProxySettings();
    246243
    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 &currentMediaList() 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 &currentMediaList() const { return m_mediums; }
    260249
    261250    void addMedium (const UIMedium &);
     
    395384signals:
    396385
    397     /**
    398      * Emitted at the beginning of the enumeration process started by
    399      * #startEnumeratingMedia().
    400      */
     386    /* Notifiers: Medium-enumeration stuff: */
    401387    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);
    415390
    416391    /** Emitted when a new media is added using #addMedia(). */
     
    469444    bool mShowStartVMErrors;
    470445
    471     QThread *mMediaEnumThread;
    472     VBoxMediaList mMediaList;
     446    QThread *m_pMediumEnumerationThread;
     447    VBoxMediaList m_mediums;
    473448
    474449    RenderMode vm_render_mode;
  • trunk/src/VBox/Frontends/VirtualBox/src/medium/UIMediumManager.cpp

    r47952 r47995  
    511511
    512512    if (aRefresh && !vboxGlobal().isMediaEnumerationStarted())
    513         vboxGlobal().startEnumeratingMedia(true /*fReallyNecessary*/);
     513        vboxGlobal().startEnumeratingMedia();
    514514    else
    515515    {
     
    616616{
    617617    /* Start enumerating media */
    618     vboxGlobal().startEnumeratingMedia(true /*fReallyNecessary*/);
     618    vboxGlobal().startEnumeratingMedia();
    619619}
    620620
  • trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIMachine.cpp

    r47831 r47995  
    382382    qApp->setQuitOnLastWindowClosed(false);
    383383
    384     /* Cache IMedium data: */
    385     vboxGlobal().startEnumeratingMedia(false /*fReallyNecessary*/);
     384    /* Cache medium data only if really necessary: */
     385    vboxGlobal().startEnumeratingMedia(false /* force start */);
    386386
    387387    /* Load machine settings: */
  • trunk/src/VBox/Frontends/VirtualBox/src/settings/machine/UIMachineSettingsStorage.cpp

    r47944 r47995  
    17351735     * lasted point, where we can start. The rest of the media checking is done
    17361736     * in a background thread. */
    1737     vboxGlobal().startEnumeratingMedia(true /*fReallyNecessary*/);
     1737    vboxGlobal().startEnumeratingMedia();
    17381738
    17391739    /* Initialize pixmap pool */
  • trunk/src/VBox/Frontends/VirtualBox/src/widgets/VBoxMediaComboBox.cpp

    r47831 r47995  
    9090{
    9191    if (!vboxGlobal().isMediaEnumerationStarted())
    92         vboxGlobal().startEnumeratingMedia(true /*fReallyNecessary*/);
     92        vboxGlobal().startEnumeratingMedia();
    9393    else
    9494        refresh();
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette