VirtualBox

Changeset 60227 in vbox


Ignore:
Timestamp:
Mar 28, 2016 5:38:54 PM (9 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
106261
Message:

FE/Qt: ​​​bugref:8308: Event handlers rework/cleanup (part 06): Heavy encapsulation rework for the private event-handling parts which helps to avoid some of includes and to have common signal rules for all the event handlers we have.

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

Legend:

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

    r60129 r60227  
    537537        src/runtime/UIActionPoolRuntime.cpp \
    538538        src/runtime/UIAddDiskEncryptionPasswordDialog.cpp \
     539        src/runtime/UIConsoleEventHandler.cpp \
    539540        src/runtime/UIFrameBuffer.cpp \
    540541        src/runtime/UIIndicatorsPool.cpp \
    541542        src/runtime/UIStatusBarEditorWindow.cpp \
    542543        src/selector/UIActionPoolSelector.cpp \
     544        src/selector/UIVirtualBoxEventHandler.cpp \
    543545        src/selector/UIVMDesktop.cpp \
    544546        src/settings/machine/UIMachineSettingsStorage.cpp \
  • trunk/src/VBox/Frontends/VirtualBox/src/extradata/UIExtraDataManager.cpp

    r60222 r60227  
    6161/* COM includes: */
    6262# include "COMEnums.h"
     63# include "CEventListener.h"
    6364# include "CEventSource.h"
    6465# include "CVirtualBox.h"
     
    9293public:
    9394
    94     /** Constructs private proxy on the basis of passed @a pParent. */
     95    /** Constructs event proxy object on the basis of passed @a pParent. */
    9596    UIExtraDataEventHandler(QObject *pParent);
    96 
    97 public slots:
     97    /** Destructs event proxy object. */
     98    ~UIExtraDataEventHandler();
     99
     100protected slots:
    98101
    99102    /** Preprocess 'extra-data can change' event: */
     
    102105    void sltPreprocessExtraDataChange(QString strMachineID, QString strKey, QString strValue);
    103106
     107protected:
     108
     109    /** @name Prepare/Cleanup cascade.
     110      * @{ */
     111        /** Prepares all. */
     112        void prepare();
     113        /** Prepares listener. */
     114        void prepareListener();
     115        /** Prepares connections. */
     116        void prepareConnections();
     117
     118        /** Cleanups connections. */
     119        void cleanupConnections();
     120        /** Cleanups listener. */
     121        void cleanupListener();
     122        /** Cleanups all. */
     123        void cleanup();
     124    /** @} */
     125
    104126private:
     127
     128    /** Holds the Qt event listener instance. */
     129    ComObjPtr<UIMainEventListenerImpl> m_pQtListener;
     130    /** Holds the COM event listener instance. */
     131    CEventListener m_comEventListener;
    105132
    106133    /** Protects sltPreprocessExtraDataChange. */
     
    111138    : QObject(pParent)
    112139{
     140    /* Prepare: */
     141    prepare();
     142}
     143
     144UIExtraDataEventHandler::~UIExtraDataEventHandler()
     145{
     146    /* Cleanup: */
     147    cleanup();
     148}
     149
     150void UIExtraDataEventHandler::prepare()
     151{
     152    /* Prepare: */
     153    prepareListener();
     154    prepareConnections();
     155}
     156
     157void UIExtraDataEventHandler::prepareListener()
     158{
     159    /* Create event listener instance: */
     160    m_pQtListener.createObject();
     161    m_pQtListener->init(new UIMainEventListener, this);
     162    m_comEventListener = CEventListener(m_pQtListener);
     163
     164    /* Get VirtualBox: */
     165    const CVirtualBox vbox = vboxGlobal().virtualBox();
     166    AssertWrapperOk(vbox);
     167    /* Get event-source: */
     168    CEventSource eventSourceVirtualBox = vbox.GetEventSource();
     169    AssertWrapperOk(eventSourceVirtualBox);
     170    /* Register listener for expected event-types: */
     171    QVector<KVBoxEventType> vboxEvents;
     172    vboxEvents
     173        << KVBoxEventType_OnExtraDataCanChange
     174        << KVBoxEventType_OnExtraDataChanged;
     175    eventSourceVirtualBox.RegisterListener(m_comEventListener, vboxEvents, TRUE);
     176    AssertWrapperOk(eventSourceVirtualBox);
     177}
     178
     179void UIExtraDataEventHandler::prepareConnections()
     180{
     181    /* Create direct (sync) connections for signals of main listener: */
     182    connect(m_pQtListener->getWrapped(), SIGNAL(sigExtraDataCanChange(QString, QString, QString, bool&, QString&)),
     183            this, SLOT(sltPreprocessExtraDataCanChange(QString, QString, QString, bool&, QString&)),
     184            Qt::DirectConnection);
     185    connect(m_pQtListener->getWrapped(), SIGNAL(sigExtraDataChange(QString, QString, QString)),
     186            this, SLOT(sltPreprocessExtraDataChange(QString, QString, QString)),
     187            Qt::DirectConnection);
     188}
     189
     190void UIExtraDataEventHandler::cleanupConnections()
     191{
     192    /* Nothing for now. */
     193}
     194
     195void UIExtraDataEventHandler::cleanupListener()
     196{
     197    /* Make sure VBoxSVC is available: */
     198    if (!vboxGlobal().isVBoxSVCAvailable())
     199        return;
     200
     201    /* Unregister Main event-listener: */
     202    const CVirtualBox vbox = vboxGlobal().virtualBox();
     203    AssertWrapperOk(vbox);
     204    /* Get event-source: */
     205    CEventSource eventSourceVirtualBox = vbox.GetEventSource();
     206    AssertWrapperOk(eventSourceVirtualBox);
     207    /* Unregister listener: */
     208    eventSourceVirtualBox.UnregisterListener(m_comEventListener);
     209}
     210
     211void UIExtraDataEventHandler::cleanup()
     212{
     213    /* Cleanup: */
     214    cleanupConnections();
     215    cleanupListener();
    113216}
    114217
     
    39974100    AssertPtrReturnVoid(m_pHandler);
    39984101    {
    3999         /* Create queued (async) connections to signals of private proxy: */
     4102        /* Create queued (async) connections for signals of event proxy object: */
    40004103        connect(m_pHandler, SIGNAL(sigExtraDataChange(QString, QString, QString)),
    40014104                this, SLOT(sltExtraDataChange(QString, QString, QString)),
    40024105                Qt::QueuedConnection);
    4003 
    4004         /* Prepare Main event-listener: */
    4005         prepareMainEventListener();
    4006     }
    4007 }
    4008 
    4009 void UIExtraDataManager::prepareMainEventListener()
    4010 {
    4011     /* Register Main event-listener:  */
    4012     const CVirtualBox vbox = vboxGlobal().virtualBox();
    4013     ComObjPtr<UIMainEventListenerImpl> pListener;
    4014     pListener.createObject();
    4015     pListener->init(new UIMainEventListener, this);
    4016     m_listener = CEventListener(pListener);
    4017     QVector<KVBoxEventType> events;
    4018     events
    4019         << KVBoxEventType_OnExtraDataCanChange
    4020         << KVBoxEventType_OnExtraDataChanged;
    4021     vbox.GetEventSource().RegisterListener(m_listener, events, TRUE);
    4022     AssertWrapperOk(vbox);
    4023 
    4024     /* This is a vetoable event, so we have to respond to the event and have to use a direct connection therefor: */
    4025     connect(pListener->getWrapped(), SIGNAL(sigExtraDataCanChange(QString, QString, QString, bool&, QString&)),
    4026             m_pHandler, SLOT(sltPreprocessExtraDataCanChange(QString, QString, QString, bool&, QString&)),
    4027             Qt::DirectConnection);
    4028     /* Use a direct connection to the helper class: */
    4029     connect(pListener->getWrapped(), SIGNAL(sigExtraDataChange(QString, QString, QString)),
    4030             m_pHandler, SLOT(sltPreprocessExtraDataChange(QString, QString, QString)),
    4031             Qt::DirectConnection);
     4106    }
    40324107}
    40334108
     
    40384113}
    40394114#endif /* DEBUG */
    4040 
    4041 void UIExtraDataManager::cleanupMainEventListener()
    4042 {
    4043     /* Make sure VBoxSVC is available: */
    4044     if (!vboxGlobal().isVBoxSVCAvailable())
    4045         return;
    4046 
    4047     /* Unregister Main event-listener: */
    4048     const CVirtualBox vbox = vboxGlobal().virtualBox();
    4049     vbox.GetEventSource().UnregisterListener(m_listener);
    4050 }
    40514115
    40524116void UIExtraDataManager::cleanup()
     
    40564120    cleanupWindow();
    40574121#endif /* DEBUG */
    4058     /* Cleanup Main event-listener: */
    4059     cleanupMainEventListener();
    40604122}
    40614123
  • trunk/src/VBox/Frontends/VirtualBox/src/extradata/UIExtraDataManager.h

    r60183 r60227  
    2828/* GUI includes: */
    2929#include "UIExtraDataDefs.h"
    30 
    31 /* COM includes: */
    32 #include "CEventListener.h"
    3330
    3431/* Forward declarations: */
     
    571568    /** Prepare extra-data event-handler. */
    572569    void prepareExtraDataEventHandler();
    573     /** Prepare Main event-listener. */
    574     void prepareMainEventListener();
    575570#ifdef DEBUG
    576571    // /** Prepare window. */
     
    580575    void cleanupWindow();
    581576#endif /* DEBUG */
    582     /** Cleanup Main event-listener. */
    583     void cleanupMainEventListener();
    584577    // /** Cleanup extra-data event-handler. */
    585578    // void cleanupExtraDataEventHandler();
     
    625618    static UIExtraDataManager *m_spInstance;
    626619
    627     /** Holds main event-listener instance. */
    628     CEventListener m_listener;
    629620    /** Holds extra-data event-handler instance. */
    630621    UIExtraDataEventHandler *m_pHandler;
  • trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIConsoleEventHandler.cpp

    r60226 r60227  
    2222/* GUI includes: */
    2323# include "UIConsoleEventHandler.h"
     24# include "UIMainEventListener.h"
    2425# include "VBoxGlobal.h"
    2526# include "UISession.h"
     
    2930
    3031/* COM includes: */
     32# include "CEventListener.h"
     33# include "CEventSource.h"
    3134# include "CConsole.h"
    32 # include "CEventSource.h"
    3335
    3436#endif /* !VBOX_WITH_PRECOMPILED_HEADERS */
    3537
    3638
    37 /* static */
    38 UIConsoleEventHandler *UIConsoleEventHandler::m_spInstance = 0;
    39 
    40 /* static */
    41 void UIConsoleEventHandler::create(UISession *pSession)
    42 {
    43     if (!m_spInstance)
    44         m_spInstance = new UIConsoleEventHandler(pSession);
    45 }
    46 
    47 /* static */
    48 void UIConsoleEventHandler::destroy()
    49 {
    50     if (m_spInstance)
    51     {
    52         delete m_spInstance;
    53         m_spInstance = 0;
    54     }
    55 }
    56 
    57 UIConsoleEventHandler::UIConsoleEventHandler(UISession *pSession)
    58     : m_pSession(pSession)
     39/** Private QObject extension
     40  * providing UIConsoleEventHandler with the CConsole event-source. */
     41class UIConsoleEventHandlerProxy : public QObject
     42{
     43    Q_OBJECT;
     44
     45signals:
     46
     47    /** Notifies about mouse pointer become @a fVisible and his shape changed to @a fAlpha, @a hotCorner, @a size and @a shape. */
     48    void sigMousePointerShapeChange(bool fVisible, bool fAlpha, QPoint hotCorner, QSize size, QVector<uint8_t> shape);
     49    /** Notifies about mouse capability change to @a fSupportsAbsolute, @a fSupportsRelative, @a fSupportsMultiTouch and @a fNeedsHostCursor. */
     50    void sigMouseCapabilityChange(bool fSupportsAbsolute, bool fSupportsRelative, bool fSupportsMultiTouch, bool fNeedsHostCursor);
     51    /** Notifies about keyboard LEDs change for @a fNumLock, @a fCapsLock and @a fScrollLock. */
     52    void sigKeyboardLedsChangeEvent(bool fNumLock, bool fCapsLock, bool fScrollLock);
     53    /** Notifies about machine @a state change. */
     54    void sigStateChange(KMachineState state);
     55    /** Notifies about guest additions state change. */
     56    void sigAdditionsChange();
     57    /** Notifies about network @a adapter state change. */
     58    void sigNetworkAdapterChange(CNetworkAdapter adapter);
     59    /** Notifies about storage device change for @a attachment, which was @a fRemoved and it was @a fSilent for guest. */
     60    void sigStorageDeviceChange(CMediumAttachment attachment, bool fRemoved, bool fSilent);
     61    /** Notifies about storage medium @a attachment state change. */
     62    void sigMediumChange(CMediumAttachment attachment);
     63    /** Notifies about VRDE device state change. */
     64    void sigVRDEChange();
     65    /** Notifies about Video Capture device state change. */
     66    void sigVideoCaptureChange();
     67    /** Notifies about USB controller state change. */
     68    void sigUSBControllerChange();
     69    /** Notifies about USB @a device state change to @a fAttached, holding additional @a error information. */
     70    void sigUSBDeviceStateChange(CUSBDevice device, bool fAttached, CVirtualBoxErrorInfo error);
     71    /** Notifies about shared folder state change. */
     72    void sigSharedFolderChange();
     73    /** Notifies about CPU execution-cap change. */
     74    void sigCPUExecutionCapChange();
     75    /** Notifies about guest-screen configuration change of @a type for @a uScreenId with @a screenGeo. */
     76    void sigGuestMonitorChange(KGuestMonitorChangedEventType type, ulong uScreenId, QRect screenGeo);
     77    /** Notifies about Runtime error with @a strErrorId which is @a fFatal and have @a strMessage. */
     78    void sigRuntimeError(bool fFatal, QString strErrorId, QString strMessage);
     79#ifdef RT_OS_DARWIN
     80    /** Notifies about VM window should be shown. */
     81    void sigShowWindow();
     82#endif /* RT_OS_DARWIN */
     83
     84public:
     85
     86    /** Constructs event proxy object on the basis of passed @a pParent and @a pSession. */
     87    UIConsoleEventHandlerProxy(QObject *pParent, UISession *pSession);
     88    /** Destructs event proxy object. */
     89    ~UIConsoleEventHandlerProxy();
     90
     91protected:
     92
     93    /** @name Prepare/Cleanup cascade.
     94      * @{ */
     95        /** Prepares all. */
     96        void prepare();
     97        /** Prepares listener. */
     98        void prepareListener();
     99        /** Prepares connections. */
     100        void prepareConnections();
     101
     102        /** Cleanups connections. */
     103        void cleanupConnections();
     104        /** Cleanups listener. */
     105        void cleanupListener();
     106        /** Cleanups all. */
     107        void cleanup();
     108    /** @} */
     109
     110private slots:
     111
     112    /** @name Slots for waitable signals.
     113      * @{ */
     114        /** Returns whether VM window can be shown. */
     115        void sltCanShowWindow(bool &fVeto, QString &strReason);
     116        /** Shows VM window if possible. */
     117        void sltShowWindow(qint64 &winId);
     118    /** @} */
     119
     120private:
     121
     122    /** Holds the UI session reference. */
     123    UISession *m_pSession;
     124
     125    /** Holds the Qt event listener instance. */
     126    ComObjPtr<UIMainEventListenerImpl> m_pQtListener;
     127    /** Holds the COM event listener instance. */
     128    CEventListener m_comEventListener;
     129};
     130
     131
     132/*********************************************************************************************************************************
     133*   Class UIConsoleEventHandlerProxy implementation.                                                                             *
     134*********************************************************************************************************************************/
     135
     136UIConsoleEventHandlerProxy::UIConsoleEventHandlerProxy(QObject *pParent, UISession *pSession)
     137    : QObject(pParent)
     138    , m_pSession(pSession)
    59139{
    60140    /* Prepare: */
     
    62142}
    63143
    64 UIConsoleEventHandler::~UIConsoleEventHandler()
     144UIConsoleEventHandlerProxy::~UIConsoleEventHandlerProxy()
    65145{
    66146    /* Cleanup: */
     
    68148}
    69149
    70 void UIConsoleEventHandler::prepare()
     150void UIConsoleEventHandlerProxy::prepare()
    71151{
    72152    /* Prepare: */
     
    75155}
    76156
    77 void UIConsoleEventHandler::prepareListener()
     157void UIConsoleEventHandlerProxy::prepareListener()
    78158{
    79159    /* Make sure session is passed: */
     
    116196}
    117197
    118 void UIConsoleEventHandler::prepareConnections()
    119 {
    120     /* Create queued (async) connections for non-waitable signals: */
     198void UIConsoleEventHandlerProxy::prepareConnections()
     199{
     200    /* Create direct (sync) connections for signals of main listener: */
    121201    connect(m_pQtListener->getWrapped(), SIGNAL(sigMousePointerShapeChange(bool, bool, QPoint, QSize, QVector<uint8_t>)),
    122202            this, SIGNAL(sigMousePointerShapeChange(bool, bool, QPoint, QSize, QVector<uint8_t>)),
    123             Qt::QueuedConnection);
     203            Qt::DirectConnection);
    124204    connect(m_pQtListener->getWrapped(), SIGNAL(sigMouseCapabilityChange(bool, bool, bool, bool)),
    125205            this, SIGNAL(sigMouseCapabilityChange(bool, bool, bool, bool)),
    126             Qt::QueuedConnection);
     206            Qt::DirectConnection);
    127207    connect(m_pQtListener->getWrapped(), SIGNAL(sigKeyboardLedsChangeEvent(bool, bool, bool)),
    128208            this, SIGNAL(sigKeyboardLedsChangeEvent(bool, bool, bool)),
    129             Qt::QueuedConnection);
     209            Qt::DirectConnection);
    130210    connect(m_pQtListener->getWrapped(), SIGNAL(sigStateChange(KMachineState)),
    131211            this, SIGNAL(sigStateChange(KMachineState)),
    132             Qt::QueuedConnection);
     212            Qt::DirectConnection);
    133213    connect(m_pQtListener->getWrapped(), SIGNAL(sigAdditionsChange()),
    134214            this, SIGNAL(sigAdditionsChange()),
    135             Qt::QueuedConnection);
     215            Qt::DirectConnection);
    136216    connect(m_pQtListener->getWrapped(), SIGNAL(sigNetworkAdapterChange(CNetworkAdapter)),
    137217            this, SIGNAL(sigNetworkAdapterChange(CNetworkAdapter)),
    138             Qt::QueuedConnection);
     218            Qt::DirectConnection);
    139219    connect(m_pQtListener->getWrapped(), SIGNAL(sigStorageDeviceChange(CMediumAttachment, bool, bool)),
    140220            this, SIGNAL(sigStorageDeviceChange(CMediumAttachment, bool, bool)),
    141             Qt::QueuedConnection);
     221            Qt::DirectConnection);
    142222    connect(m_pQtListener->getWrapped(), SIGNAL(sigMediumChange(CMediumAttachment)),
    143223            this, SIGNAL(sigMediumChange(CMediumAttachment)),
    144             Qt::QueuedConnection);
     224            Qt::DirectConnection);
    145225    connect(m_pQtListener->getWrapped(), SIGNAL(sigVRDEChange()),
    146226            this, SIGNAL(sigVRDEChange()),
    147             Qt::QueuedConnection);
     227            Qt::DirectConnection);
    148228    connect(m_pQtListener->getWrapped(), SIGNAL(sigVideoCaptureChange()),
    149229            this, SIGNAL(sigVideoCaptureChange()),
    150             Qt::QueuedConnection);
     230            Qt::DirectConnection);
    151231    connect(m_pQtListener->getWrapped(), SIGNAL(sigUSBControllerChange()),
    152232            this, SIGNAL(sigUSBControllerChange()),
    153             Qt::QueuedConnection);
     233            Qt::DirectConnection);
    154234    connect(m_pQtListener->getWrapped(), SIGNAL(sigUSBDeviceStateChange(CUSBDevice, bool, CVirtualBoxErrorInfo)),
    155235            this, SIGNAL(sigUSBDeviceStateChange(CUSBDevice, bool, CVirtualBoxErrorInfo)),
    156             Qt::QueuedConnection);
     236            Qt::DirectConnection);
    157237    connect(m_pQtListener->getWrapped(), SIGNAL(sigSharedFolderChange()),
    158238            this, SIGNAL(sigSharedFolderChange()),
    159             Qt::QueuedConnection);
     239            Qt::DirectConnection);
    160240    connect(m_pQtListener->getWrapped(), SIGNAL(sigCPUExecutionCapChange()),
    161241            this, SIGNAL(sigCPUExecutionCapChange()),
    162             Qt::QueuedConnection);
     242            Qt::DirectConnection);
    163243    connect(m_pQtListener->getWrapped(), SIGNAL(sigGuestMonitorChange(KGuestMonitorChangedEventType, ulong, QRect)),
    164244            this, SIGNAL(sigGuestMonitorChange(KGuestMonitorChangedEventType, ulong, QRect)),
    165             Qt::QueuedConnection);
     245            Qt::DirectConnection);
    166246    connect(m_pQtListener->getWrapped(), SIGNAL(sigRuntimeError(bool, QString, QString)),
    167247            this, SIGNAL(sigRuntimeError(bool, QString, QString)),
    168             Qt::QueuedConnection);
    169 
    170     /* Create direct (sync) connections for waitable signals: */
     248            Qt::DirectConnection);
    171249    connect(m_pQtListener->getWrapped(), SIGNAL(sigCanShowWindow(bool &, QString &)),
    172250            this, SLOT(sltCanShowWindow(bool &, QString &)),
     
    177255}
    178256
    179 void UIConsoleEventHandler::cleanupConnections()
     257void UIConsoleEventHandlerProxy::cleanupConnections()
    180258{
    181259    /* Nothing for now. */
    182260}
    183261
    184 void UIConsoleEventHandler::cleanupListener()
     262void UIConsoleEventHandlerProxy::cleanupListener()
    185263{
    186264    /* Make sure session is passed: */
     
    198276}
    199277
    200 void UIConsoleEventHandler::cleanup()
     278void UIConsoleEventHandlerProxy::cleanup()
    201279{
    202280    /* Cleanup: */
     
    205283}
    206284
    207 void UIConsoleEventHandler::sltCanShowWindow(bool & /* fVeto */, QString & /* strReason */)
     285void UIConsoleEventHandlerProxy::sltCanShowWindow(bool & /* fVeto */, QString & /* strReason */)
    208286{
    209287    /* Nothing for now. */
    210288}
    211289
    212 void UIConsoleEventHandler::sltShowWindow(qint64 &winId)
     290void UIConsoleEventHandlerProxy::sltShowWindow(qint64 &winId)
    213291{
    214292#ifdef Q_WS_MAC
     
    228306}
    229307
     308
     309/*********************************************************************************************************************************
     310*   Class UIConsoleEventHandler implementation.                                                                                  *
     311*********************************************************************************************************************************/
     312
     313/* static */
     314UIConsoleEventHandler *UIConsoleEventHandler::m_spInstance = 0;
     315
     316/* static */
     317void UIConsoleEventHandler::create(UISession *pSession)
     318{
     319    if (!m_spInstance)
     320        m_spInstance = new UIConsoleEventHandler(pSession);
     321}
     322
     323/* static */
     324void UIConsoleEventHandler::destroy()
     325{
     326    if (m_spInstance)
     327    {
     328        delete m_spInstance;
     329        m_spInstance = 0;
     330    }
     331}
     332
     333UIConsoleEventHandler::UIConsoleEventHandler(UISession *pSession)
     334    : m_pProxy(new UIConsoleEventHandlerProxy(this, pSession))
     335{
     336    /* Prepare: */
     337    prepare();
     338}
     339
     340void UIConsoleEventHandler::prepare()
     341{
     342    /* Prepare: */
     343    prepareConnections();
     344}
     345
     346void UIConsoleEventHandler::prepareConnections()
     347{
     348    /* Create queued (async) connections for signals of event proxy object: */
     349    connect(m_pProxy, SIGNAL(sigMousePointerShapeChange(bool, bool, QPoint, QSize, QVector<uint8_t>)),
     350            this, SIGNAL(sigMousePointerShapeChange(bool, bool, QPoint, QSize, QVector<uint8_t>)),
     351            Qt::QueuedConnection);
     352    connect(m_pProxy, SIGNAL(sigMouseCapabilityChange(bool, bool, bool, bool)),
     353            this, SIGNAL(sigMouseCapabilityChange(bool, bool, bool, bool)),
     354            Qt::QueuedConnection);
     355    connect(m_pProxy, SIGNAL(sigKeyboardLedsChangeEvent(bool, bool, bool)),
     356            this, SIGNAL(sigKeyboardLedsChangeEvent(bool, bool, bool)),
     357            Qt::QueuedConnection);
     358    connect(m_pProxy, SIGNAL(sigStateChange(KMachineState)),
     359            this, SIGNAL(sigStateChange(KMachineState)),
     360            Qt::QueuedConnection);
     361    connect(m_pProxy, SIGNAL(sigAdditionsChange()),
     362            this, SIGNAL(sigAdditionsChange()),
     363            Qt::QueuedConnection);
     364    connect(m_pProxy, SIGNAL(sigNetworkAdapterChange(CNetworkAdapter)),
     365            this, SIGNAL(sigNetworkAdapterChange(CNetworkAdapter)),
     366            Qt::QueuedConnection);
     367    connect(m_pProxy, SIGNAL(sigStorageDeviceChange(CMediumAttachment, bool, bool)),
     368            this, SIGNAL(sigStorageDeviceChange(CMediumAttachment, bool, bool)),
     369            Qt::QueuedConnection);
     370    connect(m_pProxy, SIGNAL(sigMediumChange(CMediumAttachment)),
     371            this, SIGNAL(sigMediumChange(CMediumAttachment)),
     372            Qt::QueuedConnection);
     373    connect(m_pProxy, SIGNAL(sigVRDEChange()),
     374            this, SIGNAL(sigVRDEChange()),
     375            Qt::QueuedConnection);
     376    connect(m_pProxy, SIGNAL(sigVideoCaptureChange()),
     377            this, SIGNAL(sigVideoCaptureChange()),
     378            Qt::QueuedConnection);
     379    connect(m_pProxy, SIGNAL(sigUSBControllerChange()),
     380            this, SIGNAL(sigUSBControllerChange()),
     381            Qt::QueuedConnection);
     382    connect(m_pProxy, SIGNAL(sigUSBDeviceStateChange(CUSBDevice, bool, CVirtualBoxErrorInfo)),
     383            this, SIGNAL(sigUSBDeviceStateChange(CUSBDevice, bool, CVirtualBoxErrorInfo)),
     384            Qt::QueuedConnection);
     385    connect(m_pProxy, SIGNAL(sigSharedFolderChange()),
     386            this, SIGNAL(sigSharedFolderChange()),
     387            Qt::QueuedConnection);
     388    connect(m_pProxy, SIGNAL(sigCPUExecutionCapChange()),
     389            this, SIGNAL(sigCPUExecutionCapChange()),
     390            Qt::QueuedConnection);
     391    connect(m_pProxy, SIGNAL(sigGuestMonitorChange(KGuestMonitorChangedEventType, ulong, QRect)),
     392            this, SIGNAL(sigGuestMonitorChange(KGuestMonitorChangedEventType, ulong, QRect)),
     393            Qt::QueuedConnection);
     394    connect(m_pProxy, SIGNAL(sigRuntimeError(bool, QString, QString)),
     395            this, SIGNAL(sigRuntimeError(bool, QString, QString)),
     396            Qt::QueuedConnection);
     397#ifdef RT_OS_DARWIN
     398    connect(m_pProxy, SIGNAL(sigShowWindow(qint64 &)),
     399            this, SIGNAL(sigShowWindow(qint64 &)),
     400            Qt::QueuedConnection);
     401#endif /* RT_OS_DARWIN */
     402}
     403
     404#include "UIConsoleEventHandler.moc"
     405
  • trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIConsoleEventHandler.h

    r60225 r60227  
    2222#include <QObject>
    2323
    24 /* GUI includes: */
    25 #include "UIMainEventListener.h"
    26 
    2724/* COM includes: */
    2825#include "COMEnums.h"
    29 #include "CEventListener.h"
    3026#include "CVirtualBoxErrorInfo.h"
    3127#include "CMediumAttachment.h"
     
    3430
    3531/* Forward declarations: */
     32class UIConsoleEventHandlerProxy;
    3633class UISession;
    3734
     
    9592    /** Constructs console event handler for passed @a pSession. */
    9693    UIConsoleEventHandler(UISession *pSession);
    97     /** Destructs console event handler. */
    98     ~UIConsoleEventHandler();
    9994
    100     /** @name Prepare/Cleanup cascade.
     95    /** @name Prepare cascade.
    10196      * @{ */
    10297        /** Prepares all. */
    10398        void prepare();
    104         /** Prepares listener. */
    105         void prepareListener();
    10699        /** Prepares connections. */
    107100        void prepareConnections();
    108 
    109         /** Cleanups connections. */
    110         void cleanupConnections();
    111         /** Cleanups listener. */
    112         void cleanupListener();
    113         /** Cleanups all. */
    114         void cleanup();
    115101    /** @} */
    116 
    117 private slots:
    118 
    119     /** Returns whether VM window can be shown. */
    120     void sltCanShowWindow(bool &fVeto, QString &strReason);
    121     /** Shows VM window if possible. */
    122     void sltShowWindow(qint64 &winId);
    123102
    124103private:
     
    127106    static UIConsoleEventHandler *m_spInstance;
    128107
    129     /** Holds the Qt event listener instance. */
    130     ComObjPtr<UIMainEventListenerImpl> m_pQtListener;
    131     /** Holds the COM event listener instance. */
    132     CEventListener m_comEventListener;
    133 
    134     /** Holds the UI session reference. */
    135     UISession *m_pSession;
     108    /** Holds the console event proxy instance. */
     109    UIConsoleEventHandlerProxy *m_pProxy;
    136110};
    137111
  • trunk/src/VBox/Frontends/VirtualBox/src/selector/UIVirtualBoxEventHandler.cpp

    r60225 r60227  
    2222/* GUI includes: */
    2323# include "UIVirtualBoxEventHandler.h"
     24# include "UIMainEventListener.h"
    2425# include "VBoxGlobal.h"
    2526
    2627/* COM includes: */
     28# include "CEventListener.h"
    2729# include "CEventSource.h"
     30# include "CVirtualBox.h"
     31# include "CVirtualBoxClient.h"
    2832
    2933#endif /* !VBOX_WITH_PRECOMPILED_HEADERS */
    3034
    3135
    32 /* static */
    33 UIVirtualBoxEventHandler *UIVirtualBoxEventHandler::m_spInstance = 0;
    34 
    35 /* static */
    36 UIVirtualBoxEventHandler* UIVirtualBoxEventHandler::instance()
    37 {
    38     if (!m_spInstance)
    39         m_spInstance = new UIVirtualBoxEventHandler;
    40     return m_spInstance;
    41 }
    42 
    43 /* static */
    44 void UIVirtualBoxEventHandler::destroy()
    45 {
    46     if (m_spInstance)
    47     {
    48         delete m_spInstance;
    49         m_spInstance = 0;
    50     }
    51 }
    52 
    53 UIVirtualBoxEventHandler::UIVirtualBoxEventHandler()
     36/** Private QObject extension
     37  * providing UIVirtualBoxEventHandler with the CVirtualBoxClient and CVirtualBox event-sources. */
     38class UIVirtualBoxEventHandlerProxy : public QObject
     39{
     40    Q_OBJECT;
     41
     42signals:
     43
     44    /** Notifies about the VBoxSVC become @a fAvailable. */
     45    void sigVBoxSVCAvailabilityChange(bool fAvailable);
     46
     47    /** Notifies about @a state change event for the machine with @a strId. */
     48    void sigMachineStateChange(QString strId, KMachineState state);
     49    /** Notifies about data change event for the machine with @a strId. */
     50    void sigMachineDataChange(QString strId);
     51    /** Notifies about machine with @a strId was @a fRegistered. */
     52    void sigMachineRegistered(QString strId, bool fRegistered);
     53    /** Notifies about @a state change event for the session of the machine with @a strId. */
     54    void sigSessionStateChange(QString strId, KSessionState state);
     55    /** Notifies about snapshot with @a strSnapshotId was taken for the machine with @a strId. */
     56    void sigSnapshotTake(QString strId, QString strSnapshotId);
     57    /** Notifies about snapshot with @a strSnapshotId was deleted for the machine with @a strId. */
     58    void sigSnapshotDelete(QString strId, QString strSnapshotId);
     59    /** Notifies about snapshot with @a strSnapshotId was changed for the machine with @a strId. */
     60    void sigSnapshotChange(QString strId, QString strSnapshotId);
     61    /** Notifies about snapshot with @a strSnapshotId was restored for the machine with @a strId. */
     62    void sigSnapshotRestore(QString strId, QString strSnapshotId);
     63
     64public:
     65
     66    /** Constructs event proxy object on the basis of passed @a pParent. */
     67    UIVirtualBoxEventHandlerProxy(QObject *pParent);
     68    /** Destructs event proxy object. */
     69    ~UIVirtualBoxEventHandlerProxy();
     70
     71protected:
     72
     73    /** @name Prepare/Cleanup cascade.
     74      * @{ */
     75        /** Prepares all. */
     76        void prepare();
     77        /** Prepares listener. */
     78        void prepareListener();
     79        /** Prepares connections. */
     80        void prepareConnections();
     81
     82        /** Cleanups connections. */
     83        void cleanupConnections();
     84        /** Cleanups listener. */
     85        void cleanupListener();
     86        /** Cleanups all. */
     87        void cleanup();
     88    /** @} */
     89
     90private:
     91
     92    /** Holds the Qt event listener instance. */
     93    ComObjPtr<UIMainEventListenerImpl> m_pQtListener;
     94    /** Holds the COM event listener instance. */
     95    CEventListener m_comEventListener;
     96};
     97
     98
     99/*********************************************************************************************************************************
     100*   Class UIVirtualBoxEventHandlerProxy implementation.                                                                          *
     101*********************************************************************************************************************************/
     102
     103UIVirtualBoxEventHandlerProxy::UIVirtualBoxEventHandlerProxy(QObject *pParent)
     104    : QObject(pParent)
    54105{
    55106    /* Prepare: */
     
    57108}
    58109
    59 UIVirtualBoxEventHandler::~UIVirtualBoxEventHandler()
     110UIVirtualBoxEventHandlerProxy::~UIVirtualBoxEventHandlerProxy()
    60111{
    61112    /* Cleanup: */
     
    63114}
    64115
    65 void UIVirtualBoxEventHandler::prepare()
     116void UIVirtualBoxEventHandlerProxy::prepare()
    66117{
    67118    /* Prepare: */
     
    70121}
    71122
    72 void UIVirtualBoxEventHandler::prepareListener()
     123void UIVirtualBoxEventHandlerProxy::prepareListener()
    73124{
    74125    /* Create Main event listener instance: */
     
    111162}
    112163
    113 void UIVirtualBoxEventHandler::prepareConnections()
    114 {
    115     /* Create queued (async) connections for non-waitable signals: */
     164void UIVirtualBoxEventHandlerProxy::prepareConnections()
     165{
     166    /* Create direct (sync) connections for signals of main listener: */
    116167    connect(m_pQtListener->getWrapped(), SIGNAL(sigVBoxSVCAvailabilityChange(bool)),
    117168            this, SIGNAL(sigVBoxSVCAvailabilityChange(bool)),
    118             Qt::QueuedConnection);
     169            Qt::DirectConnection);
    119170    connect(m_pQtListener->getWrapped(), SIGNAL(sigMachineStateChange(QString, KMachineState)),
    120171            this, SIGNAL(sigMachineStateChange(QString, KMachineState)),
    121             Qt::QueuedConnection);
     172            Qt::DirectConnection);
    122173    connect(m_pQtListener->getWrapped(), SIGNAL(sigMachineDataChange(QString)),
    123174            this, SIGNAL(sigMachineDataChange(QString)),
    124             Qt::QueuedConnection);
     175            Qt::DirectConnection);
    125176    connect(m_pQtListener->getWrapped(), SIGNAL(sigMachineRegistered(QString, bool)),
    126177            this, SIGNAL(sigMachineRegistered(QString, bool)),
    127             Qt::QueuedConnection);
     178            Qt::DirectConnection);
    128179    connect(m_pQtListener->getWrapped(), SIGNAL(sigSessionStateChange(QString, KSessionState)),
    129180            this, SIGNAL(sigSessionStateChange(QString, KSessionState)),
    130             Qt::QueuedConnection);
     181            Qt::DirectConnection);
    131182    connect(m_pQtListener->getWrapped(), SIGNAL(sigSnapshotTake(QString, QString)),
    132183            this, SIGNAL(sigSnapshotTake(QString, QString)),
    133             Qt::QueuedConnection);
     184            Qt::DirectConnection);
    134185    connect(m_pQtListener->getWrapped(), SIGNAL(sigSnapshotDelete(QString, QString)),
    135186            this, SIGNAL(sigSnapshotDelete(QString, QString)),
    136             Qt::QueuedConnection);
     187            Qt::DirectConnection);
    137188    connect(m_pQtListener->getWrapped(), SIGNAL(sigSnapshotChange(QString, QString)),
    138189            this, SIGNAL(sigSnapshotChange(QString, QString)),
    139             Qt::QueuedConnection);
     190            Qt::DirectConnection);
    140191    connect(m_pQtListener->getWrapped(), SIGNAL(sigSnapshotRestore(QString, QString)),
    141192            this, SIGNAL(sigSnapshotRestore(QString, QString)),
    142             Qt::QueuedConnection);
    143 }
    144 
    145 void UIVirtualBoxEventHandler::cleanupConnections()
     193            Qt::DirectConnection);
     194}
     195
     196void UIVirtualBoxEventHandlerProxy::cleanupConnections()
    146197{
    147198    /* Nothing for now. */
    148199}
    149200
    150 void UIVirtualBoxEventHandler::cleanupListener()
     201void UIVirtualBoxEventHandlerProxy::cleanupListener()
    151202{
    152203    /* Get VirtualBox: */
     
    169220}
    170221
    171 void UIVirtualBoxEventHandler::cleanup()
     222void UIVirtualBoxEventHandlerProxy::cleanup()
    172223{
    173224    /* Cleanup: */
     
    176227}
    177228
     229
     230/*********************************************************************************************************************************
     231*   Class UIVirtualBoxEventHandler implementation.                                                                               *
     232*********************************************************************************************************************************/
     233
     234/* static */
     235UIVirtualBoxEventHandler *UIVirtualBoxEventHandler::m_spInstance = 0;
     236
     237/* static */
     238UIVirtualBoxEventHandler* UIVirtualBoxEventHandler::instance()
     239{
     240    if (!m_spInstance)
     241        m_spInstance = new UIVirtualBoxEventHandler;
     242    return m_spInstance;
     243}
     244
     245/* static */
     246void UIVirtualBoxEventHandler::destroy()
     247{
     248    if (m_spInstance)
     249    {
     250        delete m_spInstance;
     251        m_spInstance = 0;
     252    }
     253}
     254
     255UIVirtualBoxEventHandler::UIVirtualBoxEventHandler()
     256    : m_pProxy(new UIVirtualBoxEventHandlerProxy(this))
     257{
     258    /* Prepare: */
     259    prepare();
     260}
     261
     262void UIVirtualBoxEventHandler::prepare()
     263{
     264    /* Prepare: */
     265    prepareConnections();
     266}
     267
     268void UIVirtualBoxEventHandler::prepareConnections()
     269{
     270    /* Create queued (async) connections for signals of event proxy object: */
     271    connect(m_pProxy, SIGNAL(sigVBoxSVCAvailabilityChange(bool)),
     272            this, SIGNAL(sigVBoxSVCAvailabilityChange(bool)),
     273            Qt::QueuedConnection);
     274    connect(m_pProxy, SIGNAL(sigMachineStateChange(QString, KMachineState)),
     275            this, SIGNAL(sigMachineStateChange(QString, KMachineState)),
     276            Qt::QueuedConnection);
     277    connect(m_pProxy, SIGNAL(sigMachineDataChange(QString)),
     278            this, SIGNAL(sigMachineDataChange(QString)),
     279            Qt::QueuedConnection);
     280    connect(m_pProxy, SIGNAL(sigMachineRegistered(QString, bool)),
     281            this, SIGNAL(sigMachineRegistered(QString, bool)),
     282            Qt::QueuedConnection);
     283    connect(m_pProxy, SIGNAL(sigSessionStateChange(QString, KSessionState)),
     284            this, SIGNAL(sigSessionStateChange(QString, KSessionState)),
     285            Qt::QueuedConnection);
     286    connect(m_pProxy, SIGNAL(sigSnapshotTake(QString, QString)),
     287            this, SIGNAL(sigSnapshotTake(QString, QString)),
     288            Qt::QueuedConnection);
     289    connect(m_pProxy, SIGNAL(sigSnapshotDelete(QString, QString)),
     290            this, SIGNAL(sigSnapshotDelete(QString, QString)),
     291            Qt::QueuedConnection);
     292    connect(m_pProxy, SIGNAL(sigSnapshotChange(QString, QString)),
     293            this, SIGNAL(sigSnapshotChange(QString, QString)),
     294            Qt::QueuedConnection);
     295    connect(m_pProxy, SIGNAL(sigSnapshotRestore(QString, QString)),
     296            this, SIGNAL(sigSnapshotRestore(QString, QString)),
     297            Qt::QueuedConnection);
     298}
     299
     300#include "UIVirtualBoxEventHandler.moc"
     301
  • trunk/src/VBox/Frontends/VirtualBox/src/selector/UIVirtualBoxEventHandler.h

    r60225 r60227  
    2222#include <QObject>
    2323
    24 /* GUI includes: */
    25 #include "UIMainEventListener.h"
    26 
    2724/* COM includes: */
    2825#include "COMEnums.h"
    29 #include "CEventListener.h"
     26
     27/* Forward declarations: */
     28class UIVirtualBoxEventHandlerProxy;
    3029
    3130
     
    6968    /** Constructs VirtualBox event handler. */
    7069    UIVirtualBoxEventHandler();
    71     /** Destructs VirtualBox event handler. */
    72     ~UIVirtualBoxEventHandler();
    7370
    74     /** @name Prepare/Cleanup cascade.
     71    /** @name Prepare cascade.
    7572      * @{ */
    7673        /** Prepares all. */
    7774        void prepare();
    78         /** Prepares listener. */
    79         void prepareListener();
    8075        /** Prepares connections. */
    8176        void prepareConnections();
    82 
    83         /** Cleanups connections. */
    84         void cleanupConnections();
    85         /** Cleanups listener. */
    86         void cleanupListener();
    87         /** Cleanups all. */
    88         void cleanup();
    8977    /** @} */
    9078
     
    9482    static UIVirtualBoxEventHandler *m_spInstance;
    9583
    96     /** Holds the Qt event listener instance. */
    97     ComObjPtr<UIMainEventListenerImpl> m_pQtListener;
    98     /** Holds the COM event listener instance. */
    99     CEventListener m_comEventListener;
     84    /** Holds the VirtualBox event proxy instance. */
     85    UIVirtualBoxEventHandlerProxy *m_pProxy;
    10086};
    10187
Note: See TracChangeset for help on using the changeset viewer.

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