VirtualBox

source: vbox/trunk/src/VBox/Frontends/VirtualBox/src/globals/UIVirtualBoxEventHandler.cpp

Last change on this file was 103771, checked in by vboxsync, 2 months ago

FE/Qt: UICommon: Switching dependency from UICommon to UIGlobalSession whenever is possible.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 17.3 KB
Line 
1/* $Id: UIVirtualBoxEventHandler.cpp 103771 2024-03-11 15:16:04Z vboxsync $ */
2/** @file
3 * VBox Qt GUI - UIVirtualBoxEventHandler 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 "UIExtraDataManager.h"
30#include "UIGlobalSession.h"
31#include "UIMainEventListener.h"
32#include "UIVirtualBoxEventHandler.h"
33
34/* COM includes: */
35#include "CEventListener.h"
36#include "CEventSource.h"
37#include "CVirtualBox.h"
38
39
40/** Private QObject extension providing UIVirtualBoxEventHandler with CVirtualBox event-source. */
41class UIVirtualBoxEventHandlerProxy : public QObject
42{
43 Q_OBJECT;
44
45signals:
46
47 /** Notifies about @a state change event for the machine with @a uId. */
48 void sigMachineStateChange(const QUuid &uId, const KMachineState state);
49 /** Notifies about data change event for the machine with @a uId. */
50 void sigMachineDataChange(const QUuid &uId);
51 /** Notifies about machine with @a uId was @a fRegistered. */
52 void sigMachineRegistered(const QUuid &uId, const bool fRegistered);
53 /** Notifies about machine with @a uId has groups changed. */
54 void sigMachineGroupsChange(const QUuid &uId);
55 /** Notifies about @a state change event for the session of the machine with @a uId. */
56 void sigSessionStateChange(const QUuid &uId, const KSessionState state);
57 /** Notifies about snapshot with @a uSnapshotId was taken for the machine with @a uId. */
58 void sigSnapshotTake(const QUuid &uId, const QUuid &uSnapshotId);
59 /** Notifies about snapshot with @a uSnapshotId was deleted for the machine with @a uId. */
60 void sigSnapshotDelete(const QUuid &uId, const QUuid &uSnapshotId);
61 /** Notifies about snapshot with @a uSnapshotId was changed for the machine with @a uId. */
62 void sigSnapshotChange(const QUuid &uId, const QUuid &uSnapshotId);
63 /** Notifies about snapshot with @a uSnapshotId was restored for the machine with @a uId. */
64 void sigSnapshotRestore(const QUuid &uId, const QUuid &uSnapshotId);
65 /** Notifies about request to uninstall cloud provider with @a uId. */
66 void sigCloudProviderUninstall(const QUuid &uId);
67 /** Notifies about cloud provider list changed. */
68 void sigCloudProviderListChanged();
69 /** Notifies about cloud profile with specified @a strName of provider with specified @a uProviderId is @a fRegistered. */
70 void sigCloudProfileRegistered(const QUuid &uProviderId, const QString &strName, bool fRegistered);
71 /** Notifies about cloud profile with specified @a strName of provider with specified @a uProviderId is changed. */
72 void sigCloudProfileChanged(const QUuid &uProviderId, const QString &strName);
73
74 /** Notifies about storage controller change.
75 * @param uMachineId Brings the ID of machine corresponding controller belongs to.
76 * @param strControllerName Brings the name of controller this event is related to. */
77 void sigStorageControllerChange(const QUuid &uMachineId, const QString &strControllerName);
78 /** Notifies about storage device change.
79 * @param comAttachment Brings corresponding attachment.
80 * @param fRemoved Brings whether medium is removed or added.
81 * @param fSilent Brings whether this change has gone silent for guest. */
82 void sigStorageDeviceChange(CMediumAttachment comAttachment, bool fRemoved, bool fSilent);
83 /** Notifies about storage medium @a comAttachment state change. */
84 void sigMediumChange(CMediumAttachment comAttachment);
85 /** Notifies about storage @a comMedium config change. */
86 void sigMediumConfigChange(CMedium comMedium);
87 /** Notifies about storage medium is (un)registered.
88 * @param uMediumId Brings corresponding medium ID.
89 * @param enmMediumType Brings corresponding medium type.
90 * @param fRegistered Brings whether medium is registered or unregistered. */
91 void sigMediumRegistered(const QUuid &uMediumId, KDeviceType enmMediumType, bool fRegistered);
92 /** Notifies extension pack. install.
93 * @param strName Passes extension pack name. */
94 void sigExtensionPackInstalled(const QString &strName);
95 /** Notifies extension pack. unnstall.
96 * @param strName Passes extension pack name. */
97 void sigExtensionPackUninstalled(const QString &strName);
98
99public:
100
101 /** Constructs event proxy object on the basis of passed @a pParent. */
102 UIVirtualBoxEventHandlerProxy(QObject *pParent);
103 /** Destructs event proxy object. */
104 ~UIVirtualBoxEventHandlerProxy();
105
106protected:
107
108 /** @name Prepare/Cleanup cascade.
109 * @{ */
110 /** Prepares all. */
111 void prepare();
112 /** Prepares listener. */
113 void prepareListener();
114 /** Prepares connections. */
115 void prepareConnections();
116
117 /** Cleanups connections. */
118 void cleanupConnections();
119 /** Cleanups listener. */
120 void cleanupListener();
121 /** Cleanups all. */
122 void cleanup();
123 /** @} */
124
125private:
126
127 /** Holds the COM event source instance. */
128 CEventSource m_comEventSource;
129
130 /** Holds the Qt event listener instance. */
131 ComObjPtr<UIMainEventListenerImpl> m_pQtListener;
132 /** Holds the COM event listener instance. */
133 CEventListener m_comEventListener;
134};
135
136
137/*********************************************************************************************************************************
138* Class UIVirtualBoxEventHandlerProxy implementation. *
139*********************************************************************************************************************************/
140
141UIVirtualBoxEventHandlerProxy::UIVirtualBoxEventHandlerProxy(QObject *pParent)
142 : QObject(pParent)
143{
144 /* Prepare: */
145 prepare();
146}
147
148UIVirtualBoxEventHandlerProxy::~UIVirtualBoxEventHandlerProxy()
149{
150 /* Cleanup: */
151 cleanup();
152}
153
154void UIVirtualBoxEventHandlerProxy::prepare()
155{
156 /* Prepare: */
157 prepareListener();
158 prepareConnections();
159}
160
161void UIVirtualBoxEventHandlerProxy::prepareListener()
162{
163 /* Create Main event listener instance: */
164 m_pQtListener.createObject();
165 m_pQtListener->init(new UIMainEventListener, this);
166 m_comEventListener = CEventListener(m_pQtListener);
167
168 /* Get VirtualBox: */
169 const CVirtualBox comVBox = gpGlobalSession->virtualBox();
170 /* Get VirtualBox event source: */
171 m_comEventSource = comVBox.GetEventSource();
172 Assert(comVBox.isOk());
173
174 /* Enumerate all the required event-types: */
175 QVector<KVBoxEventType> eventTypes;
176 eventTypes
177 << KVBoxEventType_OnMachineStateChanged
178 << KVBoxEventType_OnMachineDataChanged
179 << KVBoxEventType_OnMachineRegistered
180 << KVBoxEventType_OnMachineGroupsChanged
181 << KVBoxEventType_OnSessionStateChanged
182 << KVBoxEventType_OnSnapshotTaken
183 << KVBoxEventType_OnSnapshotDeleted
184 << KVBoxEventType_OnSnapshotChanged
185 << KVBoxEventType_OnSnapshotRestored
186 << KVBoxEventType_OnCloudProviderListChanged
187 << KVBoxEventType_OnCloudProviderUninstall
188 << KVBoxEventType_OnCloudProfileRegistered
189 << KVBoxEventType_OnCloudProfileChanged
190 << KVBoxEventType_OnStorageControllerChanged
191 << KVBoxEventType_OnStorageDeviceChanged
192 << KVBoxEventType_OnMediumChanged
193 << KVBoxEventType_OnMediumConfigChanged
194 << KVBoxEventType_OnMediumRegistered
195 << KVBoxEventType_OnExtPackInstalled;
196
197 /* Register event listener for event source aggregator: */
198 m_comEventSource.RegisterListener(m_comEventListener, eventTypes, FALSE /* active? */);
199 Assert(m_comEventSource.isOk());
200
201 /* Register event sources in their listeners as well: */
202 m_pQtListener->getWrapped()->registerSource(m_comEventSource, m_comEventListener);
203}
204
205void UIVirtualBoxEventHandlerProxy::prepareConnections()
206{
207 /* Create direct (sync) connections for signals of main event listener.
208 * Keep in mind that the abstract Qt4 connection notation should be used here. */
209 connect(m_pQtListener->getWrapped(), SIGNAL(sigMachineStateChange(QUuid, KMachineState)),
210 this, SIGNAL(sigMachineStateChange(QUuid, KMachineState)),
211 Qt::DirectConnection);
212 connect(m_pQtListener->getWrapped(), SIGNAL(sigMachineDataChange(QUuid)),
213 this, SIGNAL(sigMachineDataChange(QUuid)),
214 Qt::DirectConnection);
215 connect(m_pQtListener->getWrapped(), SIGNAL(sigMachineRegistered(QUuid, bool)),
216 this, SIGNAL(sigMachineRegistered(QUuid, bool)),
217 Qt::DirectConnection);
218 connect(m_pQtListener->getWrapped(), SIGNAL(sigMachineGroupsChange(QUuid)),
219 this, SIGNAL(sigMachineGroupsChange(QUuid)),
220 Qt::DirectConnection);
221 connect(m_pQtListener->getWrapped(), SIGNAL(sigSessionStateChange(QUuid, KSessionState)),
222 this, SIGNAL(sigSessionStateChange(QUuid, KSessionState)),
223 Qt::DirectConnection);
224 connect(m_pQtListener->getWrapped(), SIGNAL(sigSnapshotTake(QUuid, QUuid)),
225 this, SIGNAL(sigSnapshotTake(QUuid, QUuid)),
226 Qt::DirectConnection);
227 connect(m_pQtListener->getWrapped(), SIGNAL(sigSnapshotDelete(QUuid, QUuid)),
228 this, SIGNAL(sigSnapshotDelete(QUuid, QUuid)),
229 Qt::DirectConnection);
230 connect(m_pQtListener->getWrapped(), SIGNAL(sigSnapshotChange(QUuid, QUuid)),
231 this, SIGNAL(sigSnapshotChange(QUuid, QUuid)),
232 Qt::DirectConnection);
233 connect(m_pQtListener->getWrapped(), SIGNAL(sigSnapshotRestore(QUuid, QUuid)),
234 this, SIGNAL(sigSnapshotRestore(QUuid, QUuid)),
235 Qt::DirectConnection);
236 connect(m_pQtListener->getWrapped(), SIGNAL(sigCloudProviderListChanged()),
237 this, SIGNAL(sigCloudProviderListChanged()),
238 Qt::DirectConnection);
239 connect(m_pQtListener->getWrapped(), SIGNAL(sigCloudProviderUninstall(QUuid)),
240 this, SIGNAL(sigCloudProviderUninstall(QUuid)),
241 Qt::DirectConnection);
242 connect(m_pQtListener->getWrapped(), SIGNAL(sigCloudProfileRegistered(QUuid, QString, bool)),
243 this, SIGNAL(sigCloudProfileRegistered(QUuid, QString, bool)),
244 Qt::DirectConnection);
245 connect(m_pQtListener->getWrapped(), SIGNAL(sigCloudProfileChanged(QUuid, QString)),
246 this, SIGNAL(sigCloudProfileChanged(QUuid, QString)),
247 Qt::DirectConnection);
248 connect(m_pQtListener->getWrapped(), SIGNAL(sigStorageControllerChange(QUuid, QString)),
249 this, SIGNAL(sigStorageControllerChange(QUuid, QString)),
250 Qt::DirectConnection);
251 connect(m_pQtListener->getWrapped(), SIGNAL(sigStorageDeviceChange(CMediumAttachment, bool, bool)),
252 this, SIGNAL(sigStorageDeviceChange(CMediumAttachment, bool, bool)),
253 Qt::DirectConnection);
254 connect(m_pQtListener->getWrapped(), SIGNAL(sigMediumChange(CMediumAttachment)),
255 this, SIGNAL(sigMediumChange(CMediumAttachment)),
256 Qt::DirectConnection);
257 connect(m_pQtListener->getWrapped(), SIGNAL(sigMediumConfigChange(CMedium)),
258 this, SIGNAL(sigMediumConfigChange(CMedium)),
259 Qt::DirectConnection);
260 connect(m_pQtListener->getWrapped(), SIGNAL(sigMediumRegistered(QUuid, KDeviceType, bool)),
261 this, SIGNAL(sigMediumRegistered(QUuid, KDeviceType, bool)),
262 Qt::DirectConnection);
263 connect(m_pQtListener->getWrapped(), SIGNAL(sigExtensionPackInstalled(QString)),
264 this, SIGNAL(sigExtensionPackInstalled(QString)),
265 Qt::DirectConnection);
266 connect(m_pQtListener->getWrapped(), SIGNAL(sigExtensionPackUninstalled(QString)),
267 this, SIGNAL(sigExtensionPackUninstalled(QString)),
268 Qt::DirectConnection);
269}
270
271void UIVirtualBoxEventHandlerProxy::cleanupConnections()
272{
273 /* Nothing for now. */
274}
275
276void UIVirtualBoxEventHandlerProxy::cleanupListener()
277{
278 /* Unregister everything: */
279 m_pQtListener->getWrapped()->unregisterSources();
280
281 /* Unregister event listener for event source aggregator: */
282 m_comEventSource.UnregisterListener(m_comEventListener);
283 m_comEventSource.detach();
284}
285
286void UIVirtualBoxEventHandlerProxy::cleanup()
287{
288 /* Cleanup: */
289 cleanupConnections();
290 cleanupListener();
291}
292
293
294/*********************************************************************************************************************************
295* Class UIVirtualBoxEventHandler implementation. *
296*********************************************************************************************************************************/
297
298/* static */
299UIVirtualBoxEventHandler *UIVirtualBoxEventHandler::s_pInstance = 0;
300
301/* static */
302UIVirtualBoxEventHandler *UIVirtualBoxEventHandler::instance()
303{
304 if (!s_pInstance)
305 s_pInstance = new UIVirtualBoxEventHandler;
306 return s_pInstance;
307}
308
309/* static */
310void UIVirtualBoxEventHandler::destroy()
311{
312 if (s_pInstance)
313 {
314 delete s_pInstance;
315 s_pInstance = 0;
316 }
317}
318
319UIVirtualBoxEventHandler::UIVirtualBoxEventHandler()
320 : m_pProxy(new UIVirtualBoxEventHandlerProxy(this))
321{
322 /* Prepare: */
323 prepare();
324}
325
326void UIVirtualBoxEventHandler::prepare()
327{
328 /* Prepare connections: */
329 prepareConnections();
330}
331
332void UIVirtualBoxEventHandler::prepareConnections()
333{
334 /* Create queued (async) connections for signals of event proxy object.
335 * Keep in mind that the abstract Qt4 connection notation should be used here. */
336 connect(m_pProxy, SIGNAL(sigMachineStateChange(QUuid, KMachineState)),
337 this, SIGNAL(sigMachineStateChange(QUuid, KMachineState)),
338 Qt::QueuedConnection);
339 connect(m_pProxy, SIGNAL(sigMachineDataChange(QUuid)),
340 this, SIGNAL(sigMachineDataChange(QUuid)),
341 Qt::QueuedConnection);
342 connect(m_pProxy, SIGNAL(sigMachineRegistered(QUuid, bool)),
343 this, SIGNAL(sigMachineRegistered(QUuid, bool)),
344 Qt::QueuedConnection);
345 connect(m_pProxy, SIGNAL(sigMachineGroupsChange(QUuid)),
346 this, SIGNAL(sigMachineGroupsChange(QUuid)),
347 Qt::QueuedConnection);
348 connect(m_pProxy, SIGNAL(sigSessionStateChange(QUuid, KSessionState)),
349 this, SIGNAL(sigSessionStateChange(QUuid, KSessionState)),
350 Qt::QueuedConnection);
351 connect(m_pProxy, SIGNAL(sigSnapshotTake(QUuid, QUuid)),
352 this, SIGNAL(sigSnapshotTake(QUuid, QUuid)),
353 Qt::QueuedConnection);
354 connect(m_pProxy, SIGNAL(sigSnapshotDelete(QUuid, QUuid)),
355 this, SIGNAL(sigSnapshotDelete(QUuid, QUuid)),
356 Qt::QueuedConnection);
357 connect(m_pProxy, SIGNAL(sigSnapshotChange(QUuid, QUuid)),
358 this, SIGNAL(sigSnapshotChange(QUuid, QUuid)),
359 Qt::QueuedConnection);
360 connect(m_pProxy, SIGNAL(sigSnapshotRestore(QUuid, QUuid)),
361 this, SIGNAL(sigSnapshotRestore(QUuid, QUuid)),
362 Qt::QueuedConnection);
363 connect(m_pProxy, SIGNAL(sigCloudProviderListChanged()),
364 this, SIGNAL(sigCloudProviderListChanged()),
365 Qt::QueuedConnection);
366 connect(m_pProxy, SIGNAL(sigCloudProviderUninstall(QUuid)),
367 this, SIGNAL(sigCloudProviderUninstall(QUuid)),
368 Qt::BlockingQueuedConnection);
369 connect(m_pProxy, SIGNAL(sigCloudProfileRegistered(QUuid, QString, bool)),
370 this, SIGNAL(sigCloudProfileRegistered(QUuid, QString, bool)),
371 Qt::QueuedConnection);
372 connect(m_pProxy, SIGNAL(sigCloudProfileChanged(QUuid, QString)),
373 this, SIGNAL(sigCloudProfileChanged(QUuid, QString)),
374 Qt::QueuedConnection);
375 connect(m_pProxy, SIGNAL(sigStorageControllerChange(QUuid, QString)),
376 this, SIGNAL(sigStorageControllerChange(QUuid, QString)),
377 Qt::QueuedConnection);
378 connect(m_pProxy, SIGNAL(sigStorageDeviceChange(CMediumAttachment, bool, bool)),
379 this, SIGNAL(sigStorageDeviceChange(CMediumAttachment, bool, bool)),
380 Qt::QueuedConnection);
381 connect(m_pProxy, SIGNAL(sigMediumChange(CMediumAttachment)),
382 this, SIGNAL(sigMediumChange(CMediumAttachment)),
383 Qt::QueuedConnection);
384 connect(m_pProxy, SIGNAL(sigMediumConfigChange(CMedium)),
385 this, SIGNAL(sigMediumConfigChange(CMedium)),
386 Qt::QueuedConnection);
387 connect(m_pProxy, SIGNAL(sigMediumRegistered(QUuid, KDeviceType, bool)),
388 this, SIGNAL(sigMediumRegistered(QUuid, KDeviceType, bool)),
389 Qt::QueuedConnection);
390 connect(m_pProxy, SIGNAL(sigExtensionPackInstalled(QString)),
391 this, SIGNAL(sigExtensionPackInstalled(QString)),
392 Qt::QueuedConnection);
393 connect(m_pProxy, SIGNAL(sigExtensionPackUninstalled(QString)),
394 this, SIGNAL(sigExtensionPackUninstalled(QString)),
395 Qt::QueuedConnection);
396}
397
398
399#include "UIVirtualBoxEventHandler.moc"
Note: See TracBrowser for help on using the repository browser.

© 2023 Oracle
ContactPrivacy policyTerms of Use