VirtualBox

Changeset 52898 in vbox for trunk


Ignore:
Timestamp:
Sep 30, 2014 2:53:05 PM (10 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
96328
Message:

FE/Qt: Runtime UI: Console event listener: Refactoring.

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

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIConsoleEventHandler.cpp

    r52894 r52898  
    55
    66/*
    7  * Copyright (C) 2010-2013 Oracle Corporation
     7 * Copyright (C) 2010-2014 Oracle Corporation
    88 *
    99 * This file is part of VirtualBox Open Source Edition (OSE), as
     
    4343{
    4444    if (!m_pInstance)
     45    {
    4546        m_pInstance = new UIConsoleEventHandler(pSession);
     47        m_pInstance->prepare();
     48    }
    4649    return m_pInstance;
    4750}
     
    5255    if (m_pInstance)
    5356    {
     57        m_pInstance->cleanup();
    5458        delete m_pInstance;
    5559        m_pInstance = 0;
    56     }
    57 }
    58 
    59 UIConsoleEventHandler::UIConsoleEventHandler(UISession *pSession)
    60   : m_pSession(pSession)
    61 {
    62     Assert(pSession);
    63 
    64 //    RTPrintf("Self add: %RTthrd\n", RTThreadSelf());
    65     ComObjPtr<UIMainEventListenerImpl> pListener;
    66     pListener.createObject();
    67     pListener->init(new UIMainEventListener(), this);
    68     m_mainEventListener = CEventListener(pListener);
    69     QVector<KVBoxEventType> events;
    70     events
    71         << KVBoxEventType_OnMousePointerShapeChanged
    72         << KVBoxEventType_OnMouseCapabilityChanged
    73         << KVBoxEventType_OnKeyboardLedsChanged
    74         << KVBoxEventType_OnStateChanged
    75         << KVBoxEventType_OnAdditionsStateChanged
    76         << KVBoxEventType_OnNetworkAdapterChanged
    77         << KVBoxEventType_OnMediumChanged
    78         << KVBoxEventType_OnVRDEServerChanged
    79         << KVBoxEventType_OnVRDEServerInfoChanged
    80         << KVBoxEventType_OnVideoCaptureChanged
    81         << KVBoxEventType_OnUSBControllerChanged
    82         << KVBoxEventType_OnUSBDeviceStateChanged
    83         << KVBoxEventType_OnSharedFolderChanged
    84         << KVBoxEventType_OnRuntimeError
    85         << KVBoxEventType_OnCanShowWindow
    86         << KVBoxEventType_OnShowWindow
    87         << KVBoxEventType_OnCPUExecutionCapChanged
    88         << KVBoxEventType_OnGuestMonitorChanged;
    89 
    90     const CConsole &console = m_pSession->session().GetConsole();
    91     console.GetEventSource().RegisterListener(m_mainEventListener, events, TRUE);
    92     AssertWrapperOk(console);
    93 
    94     connect(pListener->getWrapped(), SIGNAL(sigMousePointerShapeChange(bool, bool, QPoint, QSize, QVector<uint8_t>)),
    95             this, SIGNAL(sigMousePointerShapeChange(bool, bool, QPoint, QSize, QVector<uint8_t>)),
    96             Qt::QueuedConnection);
    97 
    98     connect(pListener->getWrapped(), SIGNAL(sigMouseCapabilityChange(bool, bool, bool, bool)),
    99             this, SIGNAL(sigMouseCapabilityChange(bool, bool, bool, bool)),
    100             Qt::QueuedConnection);
    101 
    102     connect(pListener->getWrapped(), SIGNAL(sigKeyboardLedsChangeEvent(bool, bool, bool)),
    103             this, SIGNAL(sigKeyboardLedsChangeEvent(bool, bool, bool)),
    104             Qt::QueuedConnection);
    105 
    106     connect(pListener->getWrapped(), SIGNAL(sigStateChange(KMachineState)),
    107             this, SIGNAL(sigStateChange(KMachineState)),
    108             Qt::QueuedConnection);
    109 
    110     connect(pListener->getWrapped(), SIGNAL(sigAdditionsChange()),
    111             this, SIGNAL(sigAdditionsChange()),
    112             Qt::QueuedConnection);
    113 
    114     connect(pListener->getWrapped(), SIGNAL(sigNetworkAdapterChange(CNetworkAdapter)),
    115             this, SIGNAL(sigNetworkAdapterChange(CNetworkAdapter)),
    116             Qt::QueuedConnection);
    117 
    118     connect(pListener->getWrapped(), SIGNAL(sigMediumChange(CMediumAttachment)),
    119             this, SIGNAL(sigMediumChange(CMediumAttachment)),
    120             Qt::QueuedConnection);
    121 
    122     connect(pListener->getWrapped(), SIGNAL(sigVRDEChange()),
    123             this, SIGNAL(sigVRDEChange()),
    124             Qt::QueuedConnection);
    125 
    126     connect(pListener->getWrapped(), SIGNAL(sigVideoCaptureChange()),
    127             this, SIGNAL(sigVideoCaptureChange()),
    128             Qt::QueuedConnection);
    129 
    130     connect(pListener->getWrapped(), SIGNAL(sigUSBControllerChange()),
    131             this, SIGNAL(sigUSBControllerChange()),
    132             Qt::QueuedConnection);
    133 
    134     connect(pListener->getWrapped(), SIGNAL(sigUSBDeviceStateChange(CUSBDevice, bool, CVirtualBoxErrorInfo)),
    135             this, SIGNAL(sigUSBDeviceStateChange(CUSBDevice, bool, CVirtualBoxErrorInfo)),
    136             Qt::QueuedConnection);
    137 
    138     connect(pListener->getWrapped(), SIGNAL(sigSharedFolderChange()),
    139             this, SIGNAL(sigSharedFolderChange()),
    140             Qt::QueuedConnection);
    141 
    142     connect(pListener->getWrapped(), SIGNAL(sigRuntimeError(bool, QString, QString)),
    143             this, SIGNAL(sigRuntimeError(bool, QString, QString)),
    144             Qt::QueuedConnection);
    145 
    146     /* This is a vetoable event, so we have to respond to the event and have to
    147      * use a direct connection therefor. */
    148     connect(pListener->getWrapped(), SIGNAL(sigCanShowWindow(bool&, QString&)),
    149             this, SLOT(sltCanShowWindow(bool&, QString&)),
    150             Qt::DirectConnection);
    151 
    152     /* This returns a winId, so we have to respond to the event and have to use
    153      * a direct connection therefor. */
    154     connect(pListener->getWrapped(), SIGNAL(sigShowWindow(LONG64&)),
    155             this, SLOT(sltShowWindow(LONG64&)),
    156             Qt::DirectConnection);
    157 
    158     connect(pListener->getWrapped(), SIGNAL(sigCPUExecutionCapChange()),
    159             this, SIGNAL(sigCPUExecutionCapChange()),
    160             Qt::QueuedConnection);
    161 
    162     connect(pListener->getWrapped(), SIGNAL(sigGuestMonitorChange(KGuestMonitorChangedEventType, ulong, QRect)),
    163             this, SIGNAL(sigGuestMonitorChange(KGuestMonitorChangedEventType, ulong, QRect)),
    164             Qt::QueuedConnection);
    165 }
    166 
    167 UIConsoleEventHandler::~UIConsoleEventHandler()
    168 {
    169     const CConsole &console = m_pSession->session().GetConsole();
    170     if (!console.isNull())
    171     {
    172         CEventSource eventSource = console.GetEventSource();
    173         if (!eventSource.isNull())
    174             eventSource.UnregisterListener(m_mainEventListener);
    17560    }
    17661}
     
    20388}
    20489
     90UIConsoleEventHandler::UIConsoleEventHandler(UISession *pSession)
     91    : m_pSession(pSession)
     92{
     93}
     94
     95void UIConsoleEventHandler::prepare()
     96{
     97    /* Make sure session is passed: */
     98    AssertPtrReturnVoid(m_pSession);
     99
     100    /* Create Main-event listener instance: */
     101    ComObjPtr<UIMainEventListenerImpl> pListener;
     102    pListener.createObject();
     103    pListener->init(new UIMainEventListener, this);
     104    m_mainEventListener = CEventListener(pListener);
     105
     106    /* Get console: */
     107    const CConsole console = m_pSession->session().GetConsole();
     108    AssertReturnVoid(!console.isNull() && console.isOk());
     109    /* Get event-source: */
     110    CEventSource eventSource = console.GetEventSource();
     111    AssertReturnVoid(!eventSource.isNull() && eventSource.isOk());
     112    /* Register listener for expected event-types: */
     113    QVector<KVBoxEventType> events;
     114    events
     115        << KVBoxEventType_OnMousePointerShapeChanged
     116        << KVBoxEventType_OnMouseCapabilityChanged
     117        << KVBoxEventType_OnKeyboardLedsChanged
     118        << KVBoxEventType_OnStateChanged
     119        << KVBoxEventType_OnAdditionsStateChanged
     120        << KVBoxEventType_OnNetworkAdapterChanged
     121        << KVBoxEventType_OnMediumChanged
     122        << KVBoxEventType_OnVRDEServerChanged
     123        << KVBoxEventType_OnVRDEServerInfoChanged
     124        << KVBoxEventType_OnVideoCaptureChanged
     125        << KVBoxEventType_OnUSBControllerChanged
     126        << KVBoxEventType_OnUSBDeviceStateChanged
     127        << KVBoxEventType_OnSharedFolderChanged
     128        << KVBoxEventType_OnCPUExecutionCapChanged
     129        << KVBoxEventType_OnGuestMonitorChanged
     130        << KVBoxEventType_OnRuntimeError
     131        << KVBoxEventType_OnCanShowWindow
     132        << KVBoxEventType_OnShowWindow;
     133    eventSource.RegisterListener(m_mainEventListener, events, TRUE);
     134
     135
     136    /* Prepare connections: */
     137    connect(pListener->getWrapped(), SIGNAL(sigMousePointerShapeChange(bool, bool, QPoint, QSize, QVector<uint8_t>)),
     138            this, SIGNAL(sigMousePointerShapeChange(bool, bool, QPoint, QSize, QVector<uint8_t>)),
     139            Qt::QueuedConnection);
     140    connect(pListener->getWrapped(), SIGNAL(sigMouseCapabilityChange(bool, bool, bool, bool)),
     141            this, SIGNAL(sigMouseCapabilityChange(bool, bool, bool, bool)),
     142            Qt::QueuedConnection);
     143    connect(pListener->getWrapped(), SIGNAL(sigKeyboardLedsChangeEvent(bool, bool, bool)),
     144            this, SIGNAL(sigKeyboardLedsChangeEvent(bool, bool, bool)),
     145            Qt::QueuedConnection);
     146    connect(pListener->getWrapped(), SIGNAL(sigStateChange(KMachineState)),
     147            this, SIGNAL(sigStateChange(KMachineState)),
     148            Qt::QueuedConnection);
     149    connect(pListener->getWrapped(), SIGNAL(sigAdditionsChange()),
     150            this, SIGNAL(sigAdditionsChange()),
     151            Qt::QueuedConnection);
     152    connect(pListener->getWrapped(), SIGNAL(sigNetworkAdapterChange(CNetworkAdapter)),
     153            this, SIGNAL(sigNetworkAdapterChange(CNetworkAdapter)),
     154            Qt::QueuedConnection);
     155    connect(pListener->getWrapped(), SIGNAL(sigMediumChange(CMediumAttachment)),
     156            this, SIGNAL(sigMediumChange(CMediumAttachment)),
     157            Qt::QueuedConnection);
     158    connect(pListener->getWrapped(), SIGNAL(sigVRDEChange()),
     159            this, SIGNAL(sigVRDEChange()),
     160            Qt::QueuedConnection);
     161    connect(pListener->getWrapped(), SIGNAL(sigVideoCaptureChange()),
     162            this, SIGNAL(sigVideoCaptureChange()),
     163            Qt::QueuedConnection);
     164    connect(pListener->getWrapped(), SIGNAL(sigUSBControllerChange()),
     165            this, SIGNAL(sigUSBControllerChange()),
     166            Qt::QueuedConnection);
     167    connect(pListener->getWrapped(), SIGNAL(sigUSBDeviceStateChange(CUSBDevice, bool, CVirtualBoxErrorInfo)),
     168            this, SIGNAL(sigUSBDeviceStateChange(CUSBDevice, bool, CVirtualBoxErrorInfo)),
     169            Qt::QueuedConnection);
     170    connect(pListener->getWrapped(), SIGNAL(sigSharedFolderChange()),
     171            this, SIGNAL(sigSharedFolderChange()),
     172            Qt::QueuedConnection);
     173    connect(pListener->getWrapped(), SIGNAL(sigCPUExecutionCapChange()),
     174            this, SIGNAL(sigCPUExecutionCapChange()),
     175            Qt::QueuedConnection);
     176    connect(pListener->getWrapped(), SIGNAL(sigGuestMonitorChange(KGuestMonitorChangedEventType, ulong, QRect)),
     177            this, SIGNAL(sigGuestMonitorChange(KGuestMonitorChangedEventType, ulong, QRect)),
     178            Qt::QueuedConnection);
     179
     180    connect(pListener->getWrapped(), SIGNAL(sigRuntimeError(bool, QString, QString)),
     181            this, SIGNAL(sigRuntimeError(bool, QString, QString)),
     182            Qt::QueuedConnection);
     183
     184    /* This is a vetoable event, so we have to respond to the event and have to
     185     * use a direct connection therefor. */
     186    connect(pListener->getWrapped(), SIGNAL(sigCanShowWindow(bool&, QString&)),
     187            this, SLOT(sltCanShowWindow(bool&, QString&)),
     188            Qt::DirectConnection);
     189    /* This returns a winId, so we have to respond to the event and have to use
     190     * a direct connection therefor. */
     191    connect(pListener->getWrapped(), SIGNAL(sigShowWindow(LONG64&)),
     192            this, SLOT(sltShowWindow(LONG64&)),
     193            Qt::DirectConnection);
     194}
     195
     196void UIConsoleEventHandler::cleanup()
     197{
     198    /* Get console: */
     199    const CConsole console = m_pSession->session().GetConsole();
     200    if (console.isNull() || !console.isOk())
     201        return;
     202    /* Get event-source: */
     203    CEventSource eventSource = console.GetEventSource();
     204    AssertReturnVoid(!eventSource.isNull() || eventSource.isOk());
     205    /* Unregister listener: */
     206    eventSource.UnregisterListener(m_mainEventListener);
     207}
     208
  • trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIConsoleEventHandler.h

    r52727 r52898  
    44
    55/*
    6  * Copyright (C) 2010-2013 Oracle Corporation
     6 * Copyright (C) 2010-2014 Oracle Corporation
    77 *
    88 * This file is part of VirtualBox Open Source Edition (OSE), as
     
    1515 */
    1616
    17 #ifndef __UIConsoleEventHandler_h__
    18 #define __UIConsoleEventHandler_h__
     17#ifndef ___UIConsoleEventHandler_h___
     18#define ___UIConsoleEventHandler_h___
    1919
    2020/* COM includes: */
    2121#include "COMEnums.h"
     22#include "CEventListener.h"
    2223#include "CVirtualBoxErrorInfo.h"
    23 #include "CEventListener.h"
    2424#include "CMediumAttachment.h"
    2525#include "CNetworkAdapter.h"
     
    2929class UISession;
    3030
     31/** Console event handler. */
    3132class UIConsoleEventHandler: public QObject
    3233{
    3334    Q_OBJECT;
    3435
     36signals:
     37
     38    /** Notifies about mouse pointer shape change. */
     39    void sigMousePointerShapeChange(bool fVisible, bool fAlpha, QPoint hotCorner, QSize size, QVector<uint8_t> shape);
     40    /** Notifies about mouse capability change. */
     41    void sigMouseCapabilityChange(bool fSupportsAbsolute, bool fSupportsRelative, bool fSupportsMultiTouch, bool fNeedsHostCursor);
     42    /** Notifies about keyboard LEDs change. */
     43    void sigKeyboardLedsChangeEvent(bool fNumLock, bool fCapsLock, bool fScrollLock);
     44    /** Notifies about machine state change. */
     45    void sigStateChange(KMachineState state);
     46    /** Notifies about guest additions state change. */
     47    void sigAdditionsChange();
     48    /** Notifies about network adapter state change. */
     49    void sigNetworkAdapterChange(CNetworkAdapter adapter);
     50    /** Notifies about storage medium state change. */
     51    void sigMediumChange(CMediumAttachment attachment);
     52    /** Notifies about VRDE device state change. */
     53    void sigVRDEChange();
     54    /** Notifies about Video Capture device state change. */
     55    void sigVideoCaptureChange();
     56    /** Notifies about USB controller state change. */
     57    void sigUSBControllerChange();
     58    /** Notifies about USB device state change. */
     59    void sigUSBDeviceStateChange(CUSBDevice device, bool fAttached, CVirtualBoxErrorInfo error);
     60    /** Notifies about shared folder state change. */
     61    void sigSharedFolderChange();
     62    /** Notifies about CPU execution-cap change. */
     63    void sigCPUExecutionCapChange();
     64    /** Notifies about guest-screen configuration change. */
     65    void sigGuestMonitorChange(KGuestMonitorChangedEventType changeType, ulong uScreenId, QRect screenGeo);
     66    /** Notifies about Runtime error. */
     67    void sigRuntimeError(bool fFatal, QString strId, QString strMessage);
     68#ifdef RT_OS_DARWIN
     69    /** Notifies about VM window should be shown. */
     70    void sigShowWindow();
     71#endif /* RT_OS_DARWIN */
     72
    3573public:
     74
     75    /** Static instance factory. */
    3676    static UIConsoleEventHandler* instance(UISession *pSession = 0);
     77    /** Static instance destructor. */
    3778    static void destroy();
    3879
    39 signals:
    40     void sigMousePointerShapeChange(bool fVisible, bool fAlpha, QPoint hotCorner, QSize size, QVector<uint8_t> shape);
    41     void sigMouseCapabilityChange(bool fSupportsAbsolute, bool fSupportsRelative, bool fSupportsMultiTouch, bool fNeedsHostCursor);
    42     void sigKeyboardLedsChangeEvent(bool fNumLock, bool fCapsLock, bool fScrollLock);
    43     void sigStateChange(KMachineState state);
    44     void sigAdditionsChange();
    45     void sigNetworkAdapterChange(CNetworkAdapter adapter);
    46     void sigMediumChange(CMediumAttachment attachment);
    47     void sigVRDEChange();
    48     void sigVideoCaptureChange();
    49     void sigUSBControllerChange();
    50     void sigUSBDeviceStateChange(CUSBDevice device, bool fAttached, CVirtualBoxErrorInfo error);
    51     void sigSharedFolderChange();
    52     void sigRuntimeError(bool fFatal, QString strId, QString strMessage);
    53 #ifdef RT_OS_DARWIN
    54     void sigShowWindow();
    55 #endif /* RT_OS_DARWIN */
    56     void sigCPUExecutionCapChange();
    57     void sigGuestMonitorChange(KGuestMonitorChangedEventType changeType, ulong uScreenId, QRect screenGeo);
     80private slots:
    5881
    59 private slots:
     82    /** Returns whether VM window can be shown. */
    6083    void sltCanShowWindow(bool &fVeto, QString &strReason);
     84    /** Shows VM window if possible. */
    6185    void sltShowWindow(LONG64 &winId);
    6286
    6387private:
     88
     89    /** Constructor: */
    6490    UIConsoleEventHandler(UISession *pSession);
    65     ~UIConsoleEventHandler();
    6691
     92    /** Prepare routine. */
     93    void prepare();
     94    /** Cleanup routine. */
     95    void cleanup();
     96
     97    /** Holds the static instance. */
    6798    static UIConsoleEventHandler *m_pInstance;
     99
     100    /** Holds the UI session reference. */
    68101    UISession *m_pSession;
     102
     103    /** Holds the main event listener instance. */
    69104    CEventListener m_mainEventListener;
    70105};
     
    72107#define gConsoleEvents UIConsoleEventHandler::instance()
    73108
    74 #endif /* !__UIConsoleEventHandler_h__ */
    75 
     109#endif /* !___UIConsoleEventHandler_h___ */
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