VirtualBox

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

Last change on this file since 102493 was 100737, checked in by vboxsync, 14 months ago

API/FE/Qt: bugref:10466. bugref:10465. Adding a new event to signal successful uninstallation of extension pack. And GUI side of the code to handl this event.

  • 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 100737 2023-07-30 09:48:13Z 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 "UICommon.h"
30#include "UIExtraDataManager.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 = uiCommon().virtualBox();
170 AssertWrapperOk(comVBox);
171 /* Get VirtualBox event source: */
172 m_comEventSource = comVBox.GetEventSource();
173 AssertWrapperOk(m_comEventSource);
174
175 /* Enumerate all the required event-types: */
176 QVector<KVBoxEventType> eventTypes;
177 eventTypes
178 << KVBoxEventType_OnMachineStateChanged
179 << KVBoxEventType_OnMachineDataChanged
180 << KVBoxEventType_OnMachineRegistered
181 << KVBoxEventType_OnMachineGroupsChanged
182 << KVBoxEventType_OnSessionStateChanged
183 << KVBoxEventType_OnSnapshotTaken
184 << KVBoxEventType_OnSnapshotDeleted
185 << KVBoxEventType_OnSnapshotChanged
186 << KVBoxEventType_OnSnapshotRestored
187 << KVBoxEventType_OnCloudProviderListChanged
188 << KVBoxEventType_OnCloudProviderUninstall
189 << KVBoxEventType_OnCloudProfileRegistered
190 << KVBoxEventType_OnCloudProfileChanged
191 << KVBoxEventType_OnStorageControllerChanged
192 << KVBoxEventType_OnStorageDeviceChanged
193 << KVBoxEventType_OnMediumChanged
194 << KVBoxEventType_OnMediumConfigChanged
195 << KVBoxEventType_OnMediumRegistered
196 << KVBoxEventType_OnExtPackInstalled;
197
198 /* Register event listener for event source aggregator: */
199 m_comEventSource.RegisterListener(m_comEventListener, eventTypes, FALSE /* active? */);
200 AssertWrapperOk(m_comEventSource);
201
202 /* Register event sources in their listeners as well: */
203 m_pQtListener->getWrapped()->registerSource(m_comEventSource, m_comEventListener);
204}
205
206void UIVirtualBoxEventHandlerProxy::prepareConnections()
207{
208 /* Create direct (sync) connections for signals of main event listener.
209 * Keep in mind that the abstract Qt4 connection notation should be used here. */
210 connect(m_pQtListener->getWrapped(), SIGNAL(sigMachineStateChange(QUuid, KMachineState)),
211 this, SIGNAL(sigMachineStateChange(QUuid, KMachineState)),
212 Qt::DirectConnection);
213 connect(m_pQtListener->getWrapped(), SIGNAL(sigMachineDataChange(QUuid)),
214 this, SIGNAL(sigMachineDataChange(QUuid)),
215 Qt::DirectConnection);
216 connect(m_pQtListener->getWrapped(), SIGNAL(sigMachineRegistered(QUuid, bool)),
217 this, SIGNAL(sigMachineRegistered(QUuid, bool)),
218 Qt::DirectConnection);
219 connect(m_pQtListener->getWrapped(), SIGNAL(sigMachineGroupsChange(QUuid)),
220 this, SIGNAL(sigMachineGroupsChange(QUuid)),
221 Qt::DirectConnection);
222 connect(m_pQtListener->getWrapped(), SIGNAL(sigSessionStateChange(QUuid, KSessionState)),
223 this, SIGNAL(sigSessionStateChange(QUuid, KSessionState)),
224 Qt::DirectConnection);
225 connect(m_pQtListener->getWrapped(), SIGNAL(sigSnapshotTake(QUuid, QUuid)),
226 this, SIGNAL(sigSnapshotTake(QUuid, QUuid)),
227 Qt::DirectConnection);
228 connect(m_pQtListener->getWrapped(), SIGNAL(sigSnapshotDelete(QUuid, QUuid)),
229 this, SIGNAL(sigSnapshotDelete(QUuid, QUuid)),
230 Qt::DirectConnection);
231 connect(m_pQtListener->getWrapped(), SIGNAL(sigSnapshotChange(QUuid, QUuid)),
232 this, SIGNAL(sigSnapshotChange(QUuid, QUuid)),
233 Qt::DirectConnection);
234 connect(m_pQtListener->getWrapped(), SIGNAL(sigSnapshotRestore(QUuid, QUuid)),
235 this, SIGNAL(sigSnapshotRestore(QUuid, QUuid)),
236 Qt::DirectConnection);
237 connect(m_pQtListener->getWrapped(), SIGNAL(sigCloudProviderListChanged()),
238 this, SIGNAL(sigCloudProviderListChanged()),
239 Qt::DirectConnection);
240 connect(m_pQtListener->getWrapped(), SIGNAL(sigCloudProviderUninstall(QUuid)),
241 this, SIGNAL(sigCloudProviderUninstall(QUuid)),
242 Qt::DirectConnection);
243 connect(m_pQtListener->getWrapped(), SIGNAL(sigCloudProfileRegistered(QUuid, QString, bool)),
244 this, SIGNAL(sigCloudProfileRegistered(QUuid, QString, bool)),
245 Qt::DirectConnection);
246 connect(m_pQtListener->getWrapped(), SIGNAL(sigCloudProfileChanged(QUuid, QString)),
247 this, SIGNAL(sigCloudProfileChanged(QUuid, QString)),
248 Qt::DirectConnection);
249 connect(m_pQtListener->getWrapped(), SIGNAL(sigStorageControllerChange(QUuid, QString)),
250 this, SIGNAL(sigStorageControllerChange(QUuid, QString)),
251 Qt::DirectConnection);
252 connect(m_pQtListener->getWrapped(), SIGNAL(sigStorageDeviceChange(CMediumAttachment, bool, bool)),
253 this, SIGNAL(sigStorageDeviceChange(CMediumAttachment, bool, bool)),
254 Qt::DirectConnection);
255 connect(m_pQtListener->getWrapped(), SIGNAL(sigMediumChange(CMediumAttachment)),
256 this, SIGNAL(sigMediumChange(CMediumAttachment)),
257 Qt::DirectConnection);
258 connect(m_pQtListener->getWrapped(), SIGNAL(sigMediumConfigChange(CMedium)),
259 this, SIGNAL(sigMediumConfigChange(CMedium)),
260 Qt::DirectConnection);
261 connect(m_pQtListener->getWrapped(), SIGNAL(sigMediumRegistered(QUuid, KDeviceType, bool)),
262 this, SIGNAL(sigMediumRegistered(QUuid, KDeviceType, bool)),
263 Qt::DirectConnection);
264 connect(m_pQtListener->getWrapped(), SIGNAL(sigExtensionPackInstalled(QString)),
265 this, SIGNAL(sigExtensionPackInstalled(QString)),
266 Qt::DirectConnection);
267 connect(m_pQtListener->getWrapped(), SIGNAL(sigExtensionPackUninstalled(QString)),
268 this, SIGNAL(sigExtensionPackUninstalled(QString)),
269 Qt::DirectConnection);
270}
271
272void UIVirtualBoxEventHandlerProxy::cleanupConnections()
273{
274 /* Nothing for now. */
275}
276
277void UIVirtualBoxEventHandlerProxy::cleanupListener()
278{
279 /* Unregister everything: */
280 m_pQtListener->getWrapped()->unregisterSources();
281
282 /* Unregister event listener for event source aggregator: */
283 m_comEventSource.UnregisterListener(m_comEventListener);
284 m_comEventSource.detach();
285}
286
287void UIVirtualBoxEventHandlerProxy::cleanup()
288{
289 /* Cleanup: */
290 cleanupConnections();
291 cleanupListener();
292}
293
294
295/*********************************************************************************************************************************
296* Class UIVirtualBoxEventHandler implementation. *
297*********************************************************************************************************************************/
298
299/* static */
300UIVirtualBoxEventHandler *UIVirtualBoxEventHandler::s_pInstance = 0;
301
302/* static */
303UIVirtualBoxEventHandler *UIVirtualBoxEventHandler::instance()
304{
305 if (!s_pInstance)
306 s_pInstance = new UIVirtualBoxEventHandler;
307 return s_pInstance;
308}
309
310/* static */
311void UIVirtualBoxEventHandler::destroy()
312{
313 if (s_pInstance)
314 {
315 delete s_pInstance;
316 s_pInstance = 0;
317 }
318}
319
320UIVirtualBoxEventHandler::UIVirtualBoxEventHandler()
321 : m_pProxy(new UIVirtualBoxEventHandlerProxy(this))
322{
323 /* Prepare: */
324 prepare();
325}
326
327void UIVirtualBoxEventHandler::prepare()
328{
329 /* Prepare connections: */
330 prepareConnections();
331}
332
333void UIVirtualBoxEventHandler::prepareConnections()
334{
335 /* Create queued (async) connections for signals of event proxy object.
336 * Keep in mind that the abstract Qt4 connection notation should be used here. */
337 connect(m_pProxy, SIGNAL(sigMachineStateChange(QUuid, KMachineState)),
338 this, SIGNAL(sigMachineStateChange(QUuid, KMachineState)),
339 Qt::QueuedConnection);
340 connect(m_pProxy, SIGNAL(sigMachineDataChange(QUuid)),
341 this, SIGNAL(sigMachineDataChange(QUuid)),
342 Qt::QueuedConnection);
343 connect(m_pProxy, SIGNAL(sigMachineRegistered(QUuid, bool)),
344 this, SIGNAL(sigMachineRegistered(QUuid, bool)),
345 Qt::QueuedConnection);
346 connect(m_pProxy, SIGNAL(sigMachineGroupsChange(QUuid)),
347 this, SIGNAL(sigMachineGroupsChange(QUuid)),
348 Qt::QueuedConnection);
349 connect(m_pProxy, SIGNAL(sigSessionStateChange(QUuid, KSessionState)),
350 this, SIGNAL(sigSessionStateChange(QUuid, KSessionState)),
351 Qt::QueuedConnection);
352 connect(m_pProxy, SIGNAL(sigSnapshotTake(QUuid, QUuid)),
353 this, SIGNAL(sigSnapshotTake(QUuid, QUuid)),
354 Qt::QueuedConnection);
355 connect(m_pProxy, SIGNAL(sigSnapshotDelete(QUuid, QUuid)),
356 this, SIGNAL(sigSnapshotDelete(QUuid, QUuid)),
357 Qt::QueuedConnection);
358 connect(m_pProxy, SIGNAL(sigSnapshotChange(QUuid, QUuid)),
359 this, SIGNAL(sigSnapshotChange(QUuid, QUuid)),
360 Qt::QueuedConnection);
361 connect(m_pProxy, SIGNAL(sigSnapshotRestore(QUuid, QUuid)),
362 this, SIGNAL(sigSnapshotRestore(QUuid, QUuid)),
363 Qt::QueuedConnection);
364 connect(m_pProxy, SIGNAL(sigCloudProviderListChanged()),
365 this, SIGNAL(sigCloudProviderListChanged()),
366 Qt::QueuedConnection);
367 connect(m_pProxy, SIGNAL(sigCloudProviderUninstall(QUuid)),
368 this, SIGNAL(sigCloudProviderUninstall(QUuid)),
369 Qt::BlockingQueuedConnection);
370 connect(m_pProxy, SIGNAL(sigCloudProfileRegistered(QUuid, QString, bool)),
371 this, SIGNAL(sigCloudProfileRegistered(QUuid, QString, bool)),
372 Qt::QueuedConnection);
373 connect(m_pProxy, SIGNAL(sigCloudProfileChanged(QUuid, QString)),
374 this, SIGNAL(sigCloudProfileChanged(QUuid, QString)),
375 Qt::QueuedConnection);
376 connect(m_pProxy, SIGNAL(sigStorageControllerChange(QUuid, QString)),
377 this, SIGNAL(sigStorageControllerChange(QUuid, QString)),
378 Qt::QueuedConnection);
379 connect(m_pProxy, SIGNAL(sigStorageDeviceChange(CMediumAttachment, bool, bool)),
380 this, SIGNAL(sigStorageDeviceChange(CMediumAttachment, bool, bool)),
381 Qt::QueuedConnection);
382 connect(m_pProxy, SIGNAL(sigMediumChange(CMediumAttachment)),
383 this, SIGNAL(sigMediumChange(CMediumAttachment)),
384 Qt::QueuedConnection);
385 connect(m_pProxy, SIGNAL(sigMediumConfigChange(CMedium)),
386 this, SIGNAL(sigMediumConfigChange(CMedium)),
387 Qt::QueuedConnection);
388 connect(m_pProxy, SIGNAL(sigMediumRegistered(QUuid, KDeviceType, bool)),
389 this, SIGNAL(sigMediumRegistered(QUuid, KDeviceType, bool)),
390 Qt::QueuedConnection);
391 connect(m_pProxy, SIGNAL(sigExtensionPackInstalled(QString)),
392 this, SIGNAL(sigExtensionPackInstalled(QString)),
393 Qt::QueuedConnection);
394 connect(m_pProxy, SIGNAL(sigExtensionPackUninstalled(QString)),
395 this, SIGNAL(sigExtensionPackUninstalled(QString)),
396 Qt::QueuedConnection);
397}
398
399
400#include "UIVirtualBoxEventHandler.moc"
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle
ContactPrivacy/Do Not Sell My InfoTerms of Use