VirtualBox

Ignore:
Timestamp:
Sep 21, 2020 2:36:27 PM (4 years ago)
Author:
vboxsync
Message:

FE/Qt: bugref:9653: UIVirtualMachineItemCloud: Allow to wait for a cloud machine refresh task completeness in a blocking call (which doesn't block event porocessing ofc).

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

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VirtualBox/src/manager/UIVirtualMachineItemCloud.cpp

    r84610 r86201  
    1717
    1818/* Qt includes: */
     19#include <QPointer>
    1920#include <QTimer>
    2021
     
    4041    , m_enmFakeCloudItemState(enmState)
    4142    , m_pTask(0)
     43    , m_pEventLoop(0)
    4244{
    4345    recache();
     
    5052    , m_enmFakeCloudItemState(UIFakeCloudVirtualMachineItemState_NotApplicable)
    5153    , m_pTask(0)
     54    , m_pEventLoop(0)
    5255{
    5356    recache();
     
    7376{
    7477    QTimer::singleShot(fDelayed ? 10000 : 0, this, SLOT(sltCreateGetCloudInstanceInfoTask()));
     78}
     79
     80void UIVirtualMachineItemCloud::waitForAsyncInfoUpdateFinished()
     81{
     82    /* Make sure task is really created: */
     83    if (!m_pTask)
     84        return;
     85
     86    /* Cancel the task: */
     87    m_pTask->cancel();
     88
     89    /* We are creating a locally-scoped event-loop object,
     90     * but holding a pointer to it for a control needs: */
     91    QEventLoop eventLoop;
     92    m_pEventLoop = &eventLoop;
     93
     94    /* Guard ourself for the case
     95     * we self-destroyed in our event-loop: */
     96    QPointer<UIVirtualMachineItemCloud> guard = this;
     97
     98    /* Start the blocking event-loop: */
     99    eventLoop.exec();
     100
     101    /* Event-loop object unblocked,
     102     * Are we still valid? */
     103    if (guard.isNull())
     104        return;
     105
     106    /* Cleanup the pointer finally: */
     107    m_pEventLoop = 0;
    75108}
    76109
     
    301334    recache();
    302335
    303     /* Notify listeners finally: */
    304     emit sigStateChange();
    305 }
     336    /* Exit from the event-loop if there is any: */
     337    if (m_pEventLoop)
     338        m_pEventLoop->exit();
     339    /* Notify listeners otherwise: */
     340    else
     341        emit sigStateChange();
     342}
  • trunk/src/VBox/Frontends/VirtualBox/src/manager/UIVirtualMachineItemCloud.h

    r84610 r86201  
    3131/* Forward declarations: */
    3232class UITask;
     33class UITaskCloudRefreshMachineInfo;
    3334
    3435/** UIVirtualMachineItem sub-class used as cloud Virtual Machine item interface. */
     
    7475        /** Updates cloud VM info async way, @a fDelayed if requested or instant otherwise. */
    7576        void updateInfoAsync(bool fDelayed);
     77        /** Makes sure async info update is finished.
     78          * @note  This method creates own event-loop to avoid blocking calling thread event processing,
     79          *        so it's safe to call it from the GUI thread, ofc the method itself will be blocked. */
     80        void waitForAsyncInfoUpdateFinished();
    7681    /** @} */
    7782
     
    142147
    143148        /** Holds the info acquire task instance. */
    144         UITask *m_pTask;
     149        UITaskCloudRefreshMachineInfo *m_pTask;
     150        /** Holds the task waiting loop instance. */
     151        QEventLoop                    *m_pEventLoop;
    145152    /** @} */
    146153};
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