Changeset 60250 in vbox for trunk/src/VBox/Frontends/VirtualBox
- Timestamp:
- Mar 29, 2016 7:23:26 PM (9 years ago)
- Location:
- trunk/src/VBox/Frontends/VirtualBox
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VirtualBox/Makefile.kmk
r60227 r60250 532 532 src/globals/UIActionPool.cpp \ 533 533 src/globals/UIDesktopWidgetWatchdog.cpp \ 534 src/globals/UIMainEventListener.cpp \ 534 535 src/globals/UIThreadPool.cpp \ 535 536 src/medium/UIMediumEnumerator.cpp \ … … 542 543 src/runtime/UIStatusBarEditorWindow.cpp \ 543 544 src/selector/UIActionPoolSelector.cpp \ 544 545 src/selector/UIVirtualBoxEventHandler.cpp \ 545 546 src/selector/UIVMDesktop.cpp \ 546 547 src/settings/machine/UIMachineSettingsStorage.cpp \ -
trunk/src/VBox/Frontends/VirtualBox/src/globals/UIMainEventListener.cpp
r58947 r60250 5 5 6 6 /* 7 * Copyright (C) 2010-201 5Oracle Corporation7 * Copyright (C) 2010-2016 Oracle Corporation 8 8 * 9 9 * This file is part of VirtualBox Open Source Edition (OSE), as … … 20 20 #else /* !VBOX_WITH_PRECOMPILED_HEADERS */ 21 21 22 /* Qt includes: */ 23 # include <QThread> 24 22 25 /* GUI includes: */ 23 26 # include "UIMainEventListener.h" … … 27 30 # include "COMEnums.h" 28 31 # include "CEvent.h" 32 # include "CEventSource.h" 33 # include "CEventListener.h" 29 34 # include "CVBoxSVCAvailabilityChangedEvent.h" 30 35 # include "CVirtualBoxErrorInfo.h" … … 54 59 #endif /* !VBOX_WITH_PRECOMPILED_HEADERS */ 55 60 61 62 /** Private QThread extension allowing to listen for Main events in separate thread. 63 * This thread listens for a Main events infinitely unless creator calls for #setShutdown. */ 64 class UIMainEventListeningThread : public QThread 65 { 66 Q_OBJECT; 67 68 public: 69 70 /** Constructs Main events listener thread redirecting events from @a source to @a listener. */ 71 UIMainEventListeningThread(const CEventSource &source, const CEventListener &listener); 72 /** Destructs Main events listener thread. */ 73 ~UIMainEventListeningThread(); 74 75 protected: 76 77 /** Contains the thread excution body. */ 78 virtual void run() /* override */; 79 80 /** Returns whether the thread asked to shutdown prematurely. */ 81 bool isShutdown() const; 82 /** Defines whether the thread asked to @a fShutdown prematurely. */ 83 void setShutdown(bool fShutdown); 84 85 private: 86 87 /** Holds the Main event source reference. */ 88 CEventSource m_source; 89 /** Holds the Main event listener reference. */ 90 CEventListener m_listener; 91 92 /** Holds the mutex instance which protects thread access. */ 93 mutable QMutex m_mutex; 94 /** Holds whether the thread asked to shutdown prematurely. */ 95 bool m_fShutdown; 96 }; 97 98 99 /********************************************************************************************************************************* 100 * Class UIMainEventListeningThread implementation. * 101 *********************************************************************************************************************************/ 102 103 UIMainEventListeningThread::UIMainEventListeningThread(const CEventSource &source, const CEventListener &listener) 104 : m_source(source) 105 , m_listener(listener) 106 , m_fShutdown(false) 107 { 108 } 109 110 UIMainEventListeningThread::~UIMainEventListeningThread() 111 { 112 /* Make a request to shutdown: */ 113 setShutdown(true); 114 115 /* And wait 30 seconds for run() to finish: */ 116 wait(30000); 117 } 118 119 void UIMainEventListeningThread::run() 120 { 121 /* Initialize COM: */ 122 COMBase::InitializeCOM(false); 123 124 /* Copy source wrapper to this thread: */ 125 CEventSource source = m_source; 126 /* Copy listener wrapper to this thread: */ 127 CEventListener listener = m_listener; 128 129 /* While we are not in shutdown: */ 130 while (!isShutdown()) 131 { 132 /* Fetch the event from the queue: */ 133 CEvent event = source.GetEvent(listener, 50); 134 if (!event.isNull()) 135 { 136 /* Process the event and tell the listener: */ 137 listener.HandleEvent(event); 138 if (event.GetWaitable()) 139 source.EventProcessed(listener, event); 140 } 141 } 142 143 /* Cleanup COM: */ 144 COMBase::CleanupCOM(); 145 } 146 147 bool UIMainEventListeningThread::isShutdown() const 148 { 149 m_mutex.lock(); 150 bool fShutdown = m_fShutdown; 151 m_mutex.unlock(); 152 return fShutdown; 153 } 154 155 void UIMainEventListeningThread::setShutdown(bool fShutdown) 156 { 157 m_mutex.lock(); 158 m_fShutdown = fShutdown; 159 m_mutex.unlock(); 160 } 161 162 163 /********************************************************************************************************************************* 164 * Class UIMainEventListener implementation. * 165 *********************************************************************************************************************************/ 166 56 167 UIMainEventListener::UIMainEventListener() 57 168 { … … 67 178 } 68 179 180 void UIMainEventListener::registerSource(const CEventSource &source, const CEventListener &listener) 181 { 182 /* Create thread for passed source: */ 183 m_threads << new UIMainEventListeningThread(source, listener); 184 /* And start it: */ 185 m_threads.last()->start(); 186 } 187 188 void UIMainEventListener::unregisterSources() 189 { 190 /* Wipe out the threads: */ 191 qDeleteAll(m_threads); 192 } 193 69 194 STDMETHODIMP UIMainEventListener::HandleEvent(VBoxEventType_T /* type */, IEvent *pEvent) 70 195 { … … 283 408 } 284 409 410 #include "UIMainEventListener.moc" 411 -
trunk/src/VBox/Frontends/VirtualBox/src/globals/UIMainEventListener.h
r58947 r60250 5 5 6 6 /* 7 * Copyright (C) 2010-201 5Oracle Corporation7 * Copyright (C) 2010-2016 Oracle Corporation 8 8 * 9 9 * This file is part of VirtualBox Open Source Edition (OSE), as … … 21 21 /* Qt includes: */ 22 22 #include <QObject> 23 #include <QList> 23 24 24 25 /* COM includes: */ … … 31 32 /* Other VBox includes: */ 32 33 #include <VBox/com/listeners.h> 34 35 /* Forward declarations: */ 36 class UIMainEventListeningThread; 37 class CEventListener; 38 class CEventSource; 33 39 34 40 … … 116 122 public: 117 123 118 /** Construct or. */124 /** Constructs main event listener. */ 119 125 UIMainEventListener(); 120 126 … … 124 130 void uninit() {} 125 131 132 /** Registers event @a source for passive event @a listener. */ 133 void registerSource(const CEventSource &source, const CEventListener &listener); 134 /** Unregisters event sources. */ 135 void unregisterSources(); 136 126 137 /** Main event handler routine. */ 127 138 STDMETHOD(HandleEvent)(VBoxEventType_T enmType, IEvent *pEvent); 139 140 /** Holds the list of threads handling passive event listening. */ 141 QList<UIMainEventListeningThread*> m_threads; 128 142 }; 129 143 … … 132 146 133 147 #endif /* !___UIMainEventListener_h___ */ 148
Note:
See TracChangeset
for help on using the changeset viewer.