VirtualBox

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


Ignore:
Timestamp:
Feb 17, 2020 10:12:35 AM (5 years ago)
Author:
vboxsync
Message:

FE/Qt: bugref:9653: VirtualBox Manager: Acquire current cloud machine state async way; Moreover, periodically, which resolves the need of state update when pause/resume issued.

Location:
trunk/src/VBox/Frontends/VirtualBox
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VirtualBox/Makefile.kmk

    r83052 r83094  
    956956VirtualBox_QT_MOCSRCS = \
    957957        src/hostnetwork/UIHostNetworkManager.cpp \
     958        src/manager/UIVirtualMachineItemCloud.cpp \
    958959        src/manager/UIWelcomePane.cpp \
    959960        src/snapshots/UISnapshotDetailsWidget.cpp \
  • trunk/src/VBox/Frontends/VirtualBox/src/globals/UITask.h

    r83008 r83094  
    4747        Type_DetailsPopulation     = 2,
    4848        Type_CloudAcquireInstances = 3,
     49        Type_GetCloudInstanceState = 4,
    4950    };
    5051
  • trunk/src/VBox/Frontends/VirtualBox/src/manager/UIVirtualBoxManagerWidget.cpp

    r83064 r83094  
    284284}
    285285
     286void UIVirtualBoxManagerWidget::sltHandleCloudMachineStateChange(const QString &strId)
     287{
     288    /* Acquire current item: */
     289    UIVirtualMachineItem *pItem = currentItem();
     290
     291    /* repeat the task only if we are still on the same item: */
     292    if (pItem && pItem->id() == strId)
     293        pItem->toCloud()->updateStateAsync(true /* delayed? */);
     294
     295    /* Pass the signal further: */
     296    emit sigCloudMachineStateChange(strId);
     297}
     298
    286299void UIVirtualBoxManagerWidget::sltHandleToolMenuRequested(UIToolClass enmClass, const QPoint &position)
    287300{
     
    373386                /* Configure Chooser-pane: */
    374387                connect(m_pPaneChooser, &UIChooser::sigCloudMachineStateChange,
    375                         this, &UIVirtualBoxManagerWidget::sigCloudMachineStateChange);
     388                        this, &UIVirtualBoxManagerWidget::sltHandleCloudMachineStateChange);
    376389                /* Add into splitter: */
    377390                m_pSplitter->addWidget(m_pPaneChooser);
     
    757770        /* Update current cloud machine state: */
    758771        if (pItem->itemType() == UIVirtualMachineItem::ItemType_CloudReal)
    759             pItem->toCloud()->updateState(this);
     772            pItem->toCloud()->updateStateAsync(false /* delayed? */);
    760773    }
    761774    else
  • trunk/src/VBox/Frontends/VirtualBox/src/manager/UIVirtualBoxManagerWidget.h

    r83064 r83094  
    157157          * @param  enmDirection  Brings which direction was animation finished for. */
    158158        void sltHandleSlidingAnimationComplete(SlidingDirection enmDirection);
     159
     160        /** Handles state change for cloud machine with specified @a strMachineId. */
     161        void sltHandleCloudMachineStateChange(const QString &strId);
    159162    /** @} */
    160163
  • trunk/src/VBox/Frontends/VirtualBox/src/manager/UIVirtualMachineItemCloud.cpp

    r83076 r83094  
    1616 */
    1717
     18/* Qt includes: */
     19#include <QTimer>
     20
    1821/* GUI includes: */
    1922#include "UICloudMachine.h"
     
    2225#include "UIIconPool.h"
    2326#include "UIMessageCenter.h"
     27#include "UITask.h"
     28#include "UIThreadPool.h"
    2429#include "UIVirtualMachineItemCloud.h"
    2530
     
    4550/* Using across module: */
    4651using namespace GetInstanceInfo;
     52
     53
     54/** UITask extension used to get cloud instance state async way. */
     55class UITaskGetCloudInstanceState : public UITask
     56{
     57    Q_OBJECT;
     58
     59public:
     60
     61    /** Constructs task taking @a comCloudClient and @a strId as data.
     62      * @param  comCloudClient  Brings the cloud client object.
     63      * @param  strId           Brings the cloud VM id. */
     64    UITaskGetCloudInstanceState(const CCloudClient &comCloudClient, const QString &strId);
     65
     66    /** Returns the task result. */
     67    QString result() const;
     68
     69protected:
     70
     71    /** Contains the task body. */
     72    virtual void run() /* override */;
     73
     74private:
     75
     76    /** Holds the mutex to access result. */
     77    mutable QMutex  m_mutex;
     78
     79    /** Holds the cloud client object. */
     80    CCloudClient  m_comCloudClient;
     81    /** Holds the cloud VM id. */
     82    QString       m_strId;
     83
     84    /** Holds the error info object. */
     85    CVirtualBoxErrorInfo  m_comErrorInfo;
     86
     87    /** Holds the task result. */
     88    QString  m_strResult;
     89};
    4790
    4891
     
    139182
    140183/*********************************************************************************************************************************
     184*   Class UITaskGetCloudInstanceState implementation.                                                                            *
     185*********************************************************************************************************************************/
     186
     187UITaskGetCloudInstanceState::UITaskGetCloudInstanceState(const CCloudClient &comCloudClient, const QString &strId)
     188    : UITask(Type_GetCloudInstanceState)
     189    , m_comCloudClient(comCloudClient)
     190    , m_strId(strId)
     191{
     192}
     193
     194QString UITaskGetCloudInstanceState::result() const
     195{
     196    m_mutex.lock();
     197    const QString strResult = m_strResult;
     198    m_mutex.unlock();
     199    return strResult;
     200}
     201
     202void UITaskGetCloudInstanceState::run()
     203{
     204    m_mutex.lock();
     205    m_strResult = getInstanceInfo(KVirtualSystemDescriptionType_CloudInstanceState, m_comCloudClient, m_strId);
     206    m_mutex.unlock();
     207}
     208
     209
     210/*********************************************************************************************************************************
    141211*   Class UIVirtualMachineItemCloud implementation.                                                                              *
    142212*********************************************************************************************************************************/
     
    177247    /* Update state: */
    178248    updateState(strState);
     249}
     250
     251void UIVirtualMachineItemCloud::updateStateAsync(bool fDelayed)
     252{
     253    QTimer::singleShot(fDelayed ? 10000 : 0, this, SLOT(sltCreateGetCloudInstanceStateTask()));
    179254}
    180255
     
    397472}
    398473
     474void UIVirtualMachineItemCloud::sltCreateGetCloudInstanceStateTask()
     475{
     476    /* Make sure item is of real cloud type and is initialized: */
     477    AssertReturnVoid(itemType() == ItemType_CloudReal);
     478    AssertPtrReturnVoid(m_pCloudMachine);
     479
     480    /* Create and start task to acquire state async way: */
     481    UITask *pTask = new UITaskGetCloudInstanceState(m_pCloudMachine->client(), m_strId);
     482    connect(pTask, &UITask::sigComplete,
     483            this, &UIVirtualMachineItemCloud::sltHandleGetCloudInstanceStateDone);
     484    uiCommon().threadPool()->enqueueTask(pTask);
     485}
     486
     487void UIVirtualMachineItemCloud::sltHandleGetCloudInstanceStateDone(UITask *pTask)
     488{
     489    /* Skip unrelated tasks: */
     490    if (!pTask || pTask->type() != UITask::Type_GetCloudInstanceState)
     491        return;
     492
     493    /* Cast task to corresponding sub-class: */
     494    UITaskGetCloudInstanceState *pStateTask = static_cast<UITaskGetCloudInstanceState*>(pTask);
     495
     496    /* Update state: */
     497    updateState(pStateTask->result());
     498}
     499
    399500void UIVirtualMachineItemCloud::updateState(const QString &strState)
    400501{
     
    415516    emit sigStateChange();
    416517}
     518
     519
     520#include "UIVirtualMachineItemCloud.moc"
  • trunk/src/VBox/Frontends/VirtualBox/src/manager/UIVirtualMachineItemCloud.h

    r83076 r83094  
    2727/* Forward declarations: */
    2828class UICloudMachine;
     29class UITask;
    2930
    3031/** UIVirtualMachineItem sub-class used as cloud Virtual Machine item interface. */
     
    6566          * @param  pWidget  Brings parent widget to show messages according to. */
    6667        void updateState(QWidget *pParent);
     68
     69        /** Updates cloud VM state async way, @a fDelayed if requested or instant otherwise. */
     70        void updateStateAsync(bool fDelayed);
    6771
    6872        /** Puts cloud VM on pause.
     
    114118    /** @} */
    115119
     120private slots:
     121
     122        /** Create cloud VM state acquire task. */
     123        void sltCreateGetCloudInstanceStateTask();
     124        /** Handles signal about cloud VM state acquire task is done. */
     125        void sltHandleGetCloudInstanceStateDone(UITask *pTask);
     126
    116127private:
    117128
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