VirtualBox

source: vbox/trunk/src/VBox/Frontends/VirtualBox/src/globals/UIVirtualBoxClientEventHandler.cpp@ 102493

Last change on this file since 102493 was 98103, checked in by vboxsync, 20 months ago

Copyright year updates by scm.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 6.6 KB
Line 
1/* $Id: UIVirtualBoxClientEventHandler.cpp 98103 2023-01-17 14:15:46Z vboxsync $ */
2/** @file
3 * VBox Qt GUI - UIVirtualBoxClientEventHandler class implementation.
4 */
5
6/*
7 * Copyright (C) 2010-2023 Oracle and/or its affiliates.
8 *
9 * This file is part of VirtualBox base platform packages, as
10 * available from https://www.virtualbox.org.
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation, in version 3 of the
15 * License.
16 *
17 * This program is distributed in the hope that it will be useful, but
18 * WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 * General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, see <https://www.gnu.org/licenses>.
24 *
25 * SPDX-License-Identifier: GPL-3.0-only
26 */
27
28/* GUI includes: */
29#include "UICommon.h"
30#include "UIExtraDataManager.h"
31#include "UIMainEventListener.h"
32#include "UIVirtualBoxClientEventHandler.h"
33
34/* COM includes: */
35#include "CEventListener.h"
36#include "CEventSource.h"
37#include "CVirtualBoxClient.h"
38
39
40/** Private QObject extension providing UIVirtualBoxClientEventHandler with CVirtualBoxClient event-source. */
41class UIVirtualBoxClientEventHandlerProxy : public QObject
42{
43 Q_OBJECT;
44
45signals:
46
47 /** Notifies about the VBoxSVC become @a fAvailable. */
48 void sigVBoxSVCAvailabilityChange(bool fAvailable);
49
50public:
51
52 /** Constructs event proxy object on the basis of passed @a pParent. */
53 UIVirtualBoxClientEventHandlerProxy(QObject *pParent);
54 /** Destructs event proxy object. */
55 ~UIVirtualBoxClientEventHandlerProxy();
56
57protected:
58
59 /** @name Prepare/Cleanup cascade.
60 * @{ */
61 /** Prepares all. */
62 void prepare();
63 /** Prepares listener. */
64 void prepareListener();
65 /** Prepares connections. */
66 void prepareConnections();
67
68 /** Cleanups connections. */
69 void cleanupConnections();
70 /** Cleanups listener. */
71 void cleanupListener();
72 /** Cleanups all. */
73 void cleanup();
74 /** @} */
75
76private:
77
78 /** Holds the COM event source instance. */
79 CEventSource m_comEventSource;
80
81 /** Holds the Qt event listener instance. */
82 ComObjPtr<UIMainEventListenerImpl> m_pQtListener;
83 /** Holds the COM event listener instance. */
84 CEventListener m_comEventListener;
85};
86
87
88/*********************************************************************************************************************************
89* Class UIVirtualBoxClientEventHandlerProxy implementation. *
90*********************************************************************************************************************************/
91
92UIVirtualBoxClientEventHandlerProxy::UIVirtualBoxClientEventHandlerProxy(QObject *pParent)
93 : QObject(pParent)
94{
95 /* Prepare: */
96 prepare();
97}
98
99UIVirtualBoxClientEventHandlerProxy::~UIVirtualBoxClientEventHandlerProxy()
100{
101 /* Cleanup: */
102 cleanup();
103}
104
105void UIVirtualBoxClientEventHandlerProxy::prepare()
106{
107 /* Prepare: */
108 prepareListener();
109 prepareConnections();
110}
111
112void UIVirtualBoxClientEventHandlerProxy::prepareListener()
113{
114 /* Create Main event listener instance: */
115 m_pQtListener.createObject();
116 m_pQtListener->init(new UIMainEventListener, this);
117 m_comEventListener = CEventListener(m_pQtListener);
118
119 /* Get VirtualBoxClient: */
120 const CVirtualBoxClient comVBoxClient = uiCommon().virtualBoxClient();
121 AssertWrapperOk(comVBoxClient);
122 /* Get VirtualBoxClient event source: */
123 m_comEventSource = comVBoxClient.GetEventSource();
124 AssertWrapperOk(m_comEventSource);
125
126 /* Enumerate all the required event-types: */
127 QVector<KVBoxEventType> eventTypes;
128 eventTypes
129 << KVBoxEventType_OnVBoxSVCAvailabilityChanged;
130
131 /* Register event listener for event source aggregator: */
132 m_comEventSource.RegisterListener(m_comEventListener, eventTypes, FALSE /* active? */);
133 AssertWrapperOk(m_comEventSource);
134
135 /* Register event sources in their listeners as well: */
136 m_pQtListener->getWrapped()->registerSource(m_comEventSource, m_comEventListener);
137}
138
139void UIVirtualBoxClientEventHandlerProxy::prepareConnections()
140{
141 /* Create direct (sync) connections for signals of main event listener.
142 * Keep in mind that the abstract Qt4 connection notation should be used here. */
143 connect(m_pQtListener->getWrapped(), SIGNAL(sigVBoxSVCAvailabilityChange(bool)),
144 this, SIGNAL(sigVBoxSVCAvailabilityChange(bool)),
145 Qt::DirectConnection);
146}
147
148void UIVirtualBoxClientEventHandlerProxy::cleanupConnections()
149{
150 /* Nothing for now. */
151}
152
153void UIVirtualBoxClientEventHandlerProxy::cleanupListener()
154{
155 /* Unregister everything: */
156 m_pQtListener->getWrapped()->unregisterSources();
157
158 /* Unregister event listener for event source aggregator: */
159 m_comEventSource.UnregisterListener(m_comEventListener);
160 m_comEventSource.detach();
161}
162
163void UIVirtualBoxClientEventHandlerProxy::cleanup()
164{
165 /* Cleanup: */
166 cleanupConnections();
167 cleanupListener();
168}
169
170
171/*********************************************************************************************************************************
172* Class UIVirtualBoxClientEventHandler implementation. *
173*********************************************************************************************************************************/
174
175/* static */
176UIVirtualBoxClientEventHandler *UIVirtualBoxClientEventHandler::s_pInstance = 0;
177
178/* static */
179UIVirtualBoxClientEventHandler *UIVirtualBoxClientEventHandler::instance()
180{
181 if (!s_pInstance)
182 s_pInstance = new UIVirtualBoxClientEventHandler;
183 return s_pInstance;
184}
185
186/* static */
187void UIVirtualBoxClientEventHandler::destroy()
188{
189 if (s_pInstance)
190 {
191 delete s_pInstance;
192 s_pInstance = 0;
193 }
194}
195
196UIVirtualBoxClientEventHandler::UIVirtualBoxClientEventHandler()
197 : m_pProxy(new UIVirtualBoxClientEventHandlerProxy(this))
198{
199 /* Prepare: */
200 prepare();
201}
202
203void UIVirtualBoxClientEventHandler::prepare()
204{
205 /* Prepare connections: */
206 prepareConnections();
207}
208
209void UIVirtualBoxClientEventHandler::prepareConnections()
210{
211 /* Create queued (async) connections for signals of event proxy object.
212 * Keep in mind that the abstract Qt4 connection notation should be used here. */
213 connect(m_pProxy, SIGNAL(sigVBoxSVCAvailabilityChange(bool)),
214 this, SIGNAL(sigVBoxSVCAvailabilityChange(bool)),
215 Qt::QueuedConnection);
216}
217
218
219#include "UIVirtualBoxClientEventHandler.moc"
220
Note: See TracBrowser for help on using the repository browser.

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