VirtualBox

Changeset 49589 in vbox for trunk/src/VBox/Frontends


Ignore:
Timestamp:
Nov 20, 2013 5:08:55 PM (11 years ago)
Author:
vboxsync
Message:

FE/Qt: Medium enumeration mechanism: Separate handling for machine registration/unregistration routines (it involves all the used mediums, not only attached to current state).

Location:
trunk/src/VBox/Frontends/VirtualBox/src/medium
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VirtualBox/src/medium/UIMediumEnumerator.cpp

    r49557 r49589  
    7070    /* Prepare Main event handlers: */
    7171    connect(gVBoxEvents, SIGNAL(sigMachineDataChange(QString)), this, SLOT(sltHandleMachineUpdate(QString)));
    72     connect(gVBoxEvents, SIGNAL(sigMachineRegistered(QString, bool)), this, SLOT(sltHandleMachineUpdate(QString)));
    7372    connect(gVBoxEvents, SIGNAL(sigSnapshotChange(QString, QString)), this, SLOT(sltHandleMachineUpdate(QString)));
     73    connect(gVBoxEvents, SIGNAL(sigMachineRegistered(QString, bool)), this, SLOT(sltHandleMachineRegistration(QString, bool)));
    7474
    7575    /* Prepare thread-pool: */
     
    170170void UIMediumEnumerator::sltHandleMachineUpdate(QString strMachineID)
    171171{
    172     LogRel(("UIMediumEnumerator: Machine event received, ID = %s\n", strMachineID.toAscii().constData()));
     172    LogRel(("UIMediumEnumerator: Machine (or snapshot) event received, ID = %s\n",
     173            strMachineID.toAscii().constData()));
    173174
    174175    /* Compose a map of previous usage: */
     
    192193        {
    193194            CMedium cmedium = attachment.GetMedium();
    194             if (cmedium.isNull())
    195                 continue;
    196             QString strMediumID = cmedium.GetId();
    197             newMediumMap.insert(strMediumID, cmedium);
    198             newUsage << strMediumID;
     195            if (!cmedium.isNull())
     196            {
     197                const QString &strMediumID = cmedium.GetId();
     198                newMediumMap.insert(strMediumID, cmedium);
     199                newUsage << strMediumID;
     200            }
    199201        }
    200202    }
     
    214216
    215217    /* For each of excluded items: */
    216     foreach (const QString &strExcludedMediumKey, excludedList)
     218    foreach (const QString &strExcludedMediumID, excludedList)
    217219    {
    218220        /* Make sure this medium still in our map: */
    219         if (!m_mediums.contains(strExcludedMediumKey))
     221        if (!m_mediums.contains(strExcludedMediumID))
    220222            continue;
    221223
    222224        /* Get excluded UIMedium: */
    223         const UIMedium &uimedium = m_mediums[strExcludedMediumKey];
     225        const UIMedium &uimedium = m_mediums[strExcludedMediumID];
    224226
    225227        /* Delete UIMedium if CMedium was closed already: */
     
    228230        {
    229231            /* Delete this medium: */
    230             m_mediums.remove(strExcludedMediumKey);
    231             LogRel(("UIMediumEnumerator:  Medium with key={%s} closed and deleted (before enumeration).\n", strExcludedMediumKey.toAscii().constData()));
     232            m_mediums.remove(strExcludedMediumID);
     233            LogRel(("UIMediumEnumerator:  Medium with key={%s} closed and deleted (before enumeration).\n", strExcludedMediumID.toAscii().constData()));
    232234            /* And notify listener about delete: */
    233             emit sigMediumDeleted(strExcludedMediumKey);
     235            emit sigMediumDeleted(strExcludedMediumID);
    234236            continue;
    235237        }
    236238
    237         /* Enumerate UIMedium if CMedium still exists: */
     239        /* Enumerate UIMedium: */
    238240        createMediumEnumerationTask(uimedium);
    239241    }
     
    245247        if (!m_mediums.contains(strIncludedMediumID))
    246248        {
     249            /* Insert medium: */
    247250            const CMedium &cmedium = newMediumMap[strIncludedMediumID];
    248251            UIMedium uimedium(cmedium, UIMediumDefs::mediumTypeToLocal(cmedium.GetDeviceType()));
    249             createMedium(uimedium);
    250         }
    251 
    252         /* Enumerate UIMedium in any case: */
     252            m_mediums[strIncludedMediumID] = uimedium;
     253            LogRel(("UIMediumEnumerator:  Medium with key={%s} created and inserted.\n", strIncludedMediumID.toAscii().constData()));
     254            /* And notify listener about creation: */
     255            emit sigMediumCreated(strIncludedMediumID);
     256        }
     257
     258        /* Enumerate UIMedium: */
    253259        createMediumEnumerationTask(m_mediums[strIncludedMediumID]);
    254260    }
    255261
    256     LogRel(("UIMediumEnumerator: Machine event processed, ID = %s\n", strMachineID.toAscii().constData()));
     262    LogRel(("UIMediumEnumerator: Machine (or snapshot) event processed, ID = %s\n",
     263            strMachineID.toAscii().constData()));
     264}
     265
     266void UIMediumEnumerator::sltHandleMachineRegistration(QString strMachineID, bool fRegistered)
     267{
     268    LogRel(("UIMediumEnumerator: Machine %s event received, ID = %s\n",
     269            fRegistered ? "registration" : "unregistration",
     270            strMachineID.toAscii().constData()));
     271
     272    /* Was machine registered? */
     273    if (fRegistered)
     274    {
     275        /* Compose a map of current usage: */
     276        QStringList usage;
     277        QMap<QString, CMedium> mediumMap;
     278        CMachine machine = vboxGlobal().virtualBox().FindMachine(strMachineID);
     279        if (!machine.isNull())
     280        {
     281            foreach (const CMediumAttachment &attachment, machine.GetMediumAttachments())
     282            {
     283                CMedium cmedium = attachment.GetMedium();
     284                if (!cmedium.isNull())
     285                {
     286                    const QString &strMediumID = cmedium.GetId();
     287                    mediumMap.insert(strMediumID, cmedium);
     288                    usage << strMediumID;
     289                }
     290            }
     291        }
     292        LogRel(("UIMediumEnumerator:  Usage: %s\n", usage.isEmpty() ? "<empty>" : usage.join(", ").toAscii().constData()));
     293
     294        /* For each of related items: */
     295        foreach (const QString &strMediumID, usage)
     296        {
     297            /* Create UIMedium if it is not in our map: */
     298            if (!m_mediums.contains(strMediumID))
     299            {
     300                /* Insert medium: */
     301                const CMedium &cmedium = mediumMap[strMediumID];
     302                UIMedium uimedium(cmedium, UIMediumDefs::mediumTypeToLocal(cmedium.GetDeviceType()));
     303                m_mediums[strMediumID] = uimedium;
     304                LogRel(("UIMediumEnumerator:  Medium with key={%s} created and inserted.\n", strMediumID.toAscii().constData()));
     305                /* And notify listener about creation: */
     306                emit sigMediumCreated(strMediumID);
     307            }
     308
     309            /* Enumerate UIMedium: */
     310            createMediumEnumerationTask(m_mediums[strMediumID]);
     311        }
     312    }
     313
     314    /* Was machine unregistered? */
     315    else
     316    {
     317        /* Compose a map of previous usage: */
     318        QStringList usage;
     319        foreach (const QString &strMediumID, mediumIDs())
     320        {
     321            const UIMedium &uimedium = m_mediums[strMediumID];
     322            const QList<QString> &machineIDs = uimedium.machineIds();
     323            if (machineIDs.contains(strMachineID))
     324                usage << strMediumID;
     325        }
     326        LogRel(("UIMediumEnumerator:  Usage: %s\n", usage.isEmpty() ? "<empty>" : usage.join(", ").toAscii().constData()));
     327
     328        /* For each of related items: */
     329        foreach (const QString &strMediumID, usage)
     330        {
     331            /* Make sure this medium still in our map: */
     332            if (!m_mediums.contains(strMediumID))
     333                continue;
     334
     335            /* Get excluded UIMedium: */
     336            const UIMedium &uimedium = m_mediums[strMediumID];
     337
     338            /* Delete UIMedium if CMedium was closed already: */
     339            CMedium cmedium = uimedium.medium();
     340            if (cmedium.GetId().isNull() || !cmedium.isOk())
     341            {
     342                /* Delete this medium: */
     343                m_mediums.remove(strMediumID);
     344                LogRel(("UIMediumEnumerator:  Medium with key={%s} closed and deleted (before enumeration).\n", strMediumID.toAscii().constData()));
     345                /* And notify listener about delete: */
     346                emit sigMediumDeleted(strMediumID);
     347                continue;
     348            }
     349
     350            /* Enumerate UIMedium: */
     351            createMediumEnumerationTask(uimedium);
     352        }
     353    }
     354
     355    LogRel(("UIMediumEnumerator: Machine %s event processed, ID = %s\n",
     356            fRegistered ? "registration" : "unregistration",
     357            strMachineID.toAscii().constData()));
    257358}
    258359
  • trunk/src/VBox/Frontends/VirtualBox/src/medium/UIMediumEnumerator.h

    r49553 r49589  
    6363private slots:
    6464
    65     /* Handler: Machine stuff: */
     65    /** Handles machine-data-change and snapshot-change events. */
    6666    void sltHandleMachineUpdate(QString strMachineID);
     67    /** Handles machine-[un]registration events. */
     68    void sltHandleMachineRegistration(QString strMachineID, bool fRegistered);
    6769
    6870    /* Handler: Medium-enumeration stuff: */
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