commit 4c628e0fc31e5927d33b0b44836210a9d4f1470e Author: Vitali Lovich Date: Mon Sep 12 22:04:39 2011 -0700 Expose QWinEventNotifier as part of the public API Fix QTBUG-68 and QTBUG-17218 diff --git a/src/corelib/io/qprocess.cpp b/src/corelib/io/qprocess.cpp index e900663..e19fb4c 100644 --- a/src/corelib/io/qprocess.cpp +++ b/src/corelib/io/qprocess.cpp @@ -94,7 +94,7 @@ QT_END_NAMESPACE #include #ifdef Q_WS_WIN -#include +#include #endif #ifdef Q_OS_SYMBIAN diff --git a/src/corelib/io/qprocess_win.cpp b/src/corelib/io/qprocess_win.cpp index 510f723..f5c76d9 100644 --- a/src/corelib/io/qprocess_win.cpp +++ b/src/corelib/io/qprocess_win.cpp @@ -51,7 +51,7 @@ #include #include #include -#include +#include #include #include diff --git a/src/corelib/kernel/kernel.pri b/src/corelib/kernel/kernel.pri index a3628b1..593a09c 100644 --- a/src/corelib/kernel/kernel.pri +++ b/src/corelib/kernel/kernel.pri @@ -64,12 +64,12 @@ win32 { SOURCES += \ kernel/qeventdispatcher_win.cpp \ kernel/qcoreapplication_win.cpp \ - kernel/qwineventnotifier_p.cpp \ + kernel/qwineventnotifier.cpp \ kernel/qsharedmemory_win.cpp \ kernel/qsystemsemaphore_win.cpp HEADERS += \ kernel/qeventdispatcher_win_p.h \ - kernel/qwineventnotifier_p.h + kernel/qwineventnotifier.h } diff --git a/src/corelib/kernel/qeventdispatcher_win.cpp b/src/corelib/kernel/qeventdispatcher_win.cpp index 84663fa..209d29c 100644 --- a/src/corelib/kernel/qeventdispatcher_win.cpp +++ b/src/corelib/kernel/qeventdispatcher_win.cpp @@ -48,7 +48,7 @@ #include "qset.h" #include "qsocketnotifier.h" #include "qvarlengtharray.h" -#include "qwineventnotifier_p.h" +#include "qwineventnotifier.h" #include "qabstracteventdispatcher_p.h" #include "qcoreapplication_p.h" diff --git a/src/corelib/kernel/qwineventnotifier.cpp b/src/corelib/kernel/qwineventnotifier.cpp new file mode 100644 index 0000000..5ae878e --- /dev/null +++ b/src/corelib/kernel/qwineventnotifier.cpp @@ -0,0 +1,134 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtCore module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qwineventnotifier.h" + +#include "qeventdispatcher_win_p.h" +#include "qcoreapplication.h" + +#include + +QT_BEGIN_NAMESPACE + +/* + \class QWinEventNotifier + \brief The QWinEventNotifier class provides support for the Windows Wait functions. + + The QWinEventNotifier class makes it possible to use the wait + functions on windows in a asynchronous manner. With this class + you can register a HANDLE to an event and get notification when + that event becomes signalled. The state of the event is not modified + in the process so if it is a manual reset event you will need to + reset it after the notification. +*/ + + +QWinEventNotifier::QWinEventNotifier(QObject *parent) + : QObject(parent), handleToEvent(0), enabled(false) +{} + +QWinEventNotifier::QWinEventNotifier(HANDLE hEvent, QObject *parent) + : QObject(parent), handleToEvent(hEvent), enabled(false) +{ + Q_D(QObject); + QEventDispatcherWin32 *eventDispatcher = qobject_cast(d->threadData->eventDispatcher); + Q_ASSERT_X(eventDispatcher, "QWinEventNotifier::QWinEventNotifier()", + "Cannot create a win event notifier without a QEventDispatcherWin32"); + eventDispatcher->registerEventNotifier(this); + enabled = true; +} + +QWinEventNotifier::~QWinEventNotifier() +{ + setEnabled(false); +} + +void QWinEventNotifier::setHandle(HANDLE hEvent) +{ + setEnabled(false); + handleToEvent = hEvent; +} + +HANDLE QWinEventNotifier::handle() const +{ + return handleToEvent; +} + +bool QWinEventNotifier::isEnabled() const +{ + return enabled; +} + +void QWinEventNotifier::setEnabled(bool enable) +{ + if (enabled == enable) // no change + return; + enabled = enable; + + Q_D(QObject); + QEventDispatcherWin32 *eventDispatcher = qobject_cast(d->threadData->eventDispatcher); + if (!eventDispatcher) // perhaps application is shutting down + return; + + if (enabled) + eventDispatcher->registerEventNotifier(this); + else + eventDispatcher->unregisterEventNotifier(this); +} + +bool QWinEventNotifier::event(QEvent * e) +{ + if (e->type() == QEvent::ThreadChange) { + if (enabled) { + QMetaObject::invokeMethod(this, "setEnabled", Qt::QueuedConnection, + Q_ARG(bool, enabled)); + setEnabled(false); + } + } + QObject::event(e); // will activate filters + if (e->type() == QEvent::WinEventAct) { + emit activated(handleToEvent); + return true; + } + return false; +} + +QT_END_NAMESPACE diff --git a/src/corelib/kernel/qwineventnotifier.h b/src/corelib/kernel/qwineventnotifier.h new file mode 100644 index 0000000..cddd28e --- /dev/null +++ b/src/corelib/kernel/qwineventnotifier.h @@ -0,0 +1,89 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtCore module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QWINEVENTNOTIFIER_H +#define QWINEVENTNOTIFIER_H + +#include "QtCore/qobject.h" +#include "QtCore/qt_windows.h" + +QT_BEGIN_HEADER + +QT_BEGIN_NAMESPACE + +QT_MODULE(Core) + +class Q_CORE_EXPORT QWinEventNotifier : public QObject +{ + Q_OBJECT + Q_DECLARE_PRIVATE(QObject) + +public: + explicit QWinEventNotifier(QObject *parent = 0); + explicit QWinEventNotifier(HANDLE hEvent, QObject *parent = 0); + ~QWinEventNotifier(); + + void setHandle(HANDLE hEvent); + HANDLE handle() const; + + bool isEnabled() const; + +public Q_SLOTS: + void setEnabled(bool enable); + +Q_SIGNALS: + void activated(HANDLE hEvent); + +protected: + bool event(QEvent * e); + +private: + Q_DISABLE_COPY(QWinEventNotifier) + + HANDLE handleToEvent; + bool enabled; +}; + +QT_END_NAMESPACE + +QT_END_HEADER + +#endif // QWINEVENTNOTIFIER_H diff --git a/src/corelib/kernel/qwineventnotifier_p.cpp b/src/corelib/kernel/qwineventnotifier_p.cpp deleted file mode 100644 index 978f46f..0000000 --- a/src/corelib/kernel/qwineventnotifier_p.cpp +++ /dev/null @@ -1,134 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtCore module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qwineventnotifier_p.h" - -#include "qeventdispatcher_win_p.h" -#include "qcoreapplication.h" - -#include - -QT_BEGIN_NAMESPACE - -/* - \class QWinEventNotifier - \brief The QWinEventNotifier class provides support for the Windows Wait functions. - - The QWinEventNotifier class makes it possible to use the wait - functions on windows in a asynchronous manner. With this class - you can register a HANDLE to an event and get notification when - that event becomes signalled. The state of the event is not modified - in the process so if it is a manual reset event you will need to - reset it after the notification. -*/ - - -QWinEventNotifier::QWinEventNotifier(QObject *parent) - : QObject(parent), handleToEvent(0), enabled(false) -{} - -QWinEventNotifier::QWinEventNotifier(HANDLE hEvent, QObject *parent) - : QObject(parent), handleToEvent(hEvent), enabled(false) -{ - Q_D(QObject); - QEventDispatcherWin32 *eventDispatcher = qobject_cast(d->threadData->eventDispatcher); - Q_ASSERT_X(eventDispatcher, "QWinEventNotifier::QWinEventNotifier()", - "Cannot create a win event notifier without a QEventDispatcherWin32"); - eventDispatcher->registerEventNotifier(this); - enabled = true; -} - -QWinEventNotifier::~QWinEventNotifier() -{ - setEnabled(false); -} - -void QWinEventNotifier::setHandle(HANDLE hEvent) -{ - setEnabled(false); - handleToEvent = hEvent; -} - -HANDLE QWinEventNotifier::handle() const -{ - return handleToEvent; -} - -bool QWinEventNotifier::isEnabled() const -{ - return enabled; -} - -void QWinEventNotifier::setEnabled(bool enable) -{ - if (enabled == enable) // no change - return; - enabled = enable; - - Q_D(QObject); - QEventDispatcherWin32 *eventDispatcher = qobject_cast(d->threadData->eventDispatcher); - if (!eventDispatcher) // perhaps application is shutting down - return; - - if (enabled) - eventDispatcher->registerEventNotifier(this); - else - eventDispatcher->unregisterEventNotifier(this); -} - -bool QWinEventNotifier::event(QEvent * e) -{ - if (e->type() == QEvent::ThreadChange) { - if (enabled) { - QMetaObject::invokeMethod(this, "setEnabled", Qt::QueuedConnection, - Q_ARG(bool, enabled)); - setEnabled(false); - } - } - QObject::event(e); // will activate filters - if (e->type() == QEvent::WinEventAct) { - emit activated(handleToEvent); - return true; - } - return false; -} - -QT_END_NAMESPACE diff --git a/src/corelib/kernel/qwineventnotifier_p.h b/src/corelib/kernel/qwineventnotifier_p.h deleted file mode 100644 index f369e39..0000000 --- a/src/corelib/kernel/qwineventnotifier_p.h +++ /dev/null @@ -1,94 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtCore module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QWINEVENTNOTIFIER_P_H -#define QWINEVENTNOTIFIER_P_H - -// -// W A R N I N G -// ------------- -// -// This file is not part of the Qt API. It exists for the convenience -// of other Qt classes. This header file may change from version to -// version without notice, or even be removed. -// -// We mean it. -// - -#include "QtCore/qobject.h" -#include "QtCore/qt_windows.h" - -QT_BEGIN_NAMESPACE - -class Q_CORE_EXPORT QWinEventNotifier : public QObject -{ - Q_OBJECT - Q_DECLARE_PRIVATE(QObject) - -public: - explicit QWinEventNotifier(QObject *parent = 0); - explicit QWinEventNotifier(HANDLE hEvent, QObject *parent = 0); - ~QWinEventNotifier(); - - void setHandle(HANDLE hEvent); - HANDLE handle() const; - - bool isEnabled() const; - -public Q_SLOTS: - void setEnabled(bool enable); - -Q_SIGNALS: - void activated(HANDLE hEvent); - -protected: - bool event(QEvent * e); - -private: - Q_DISABLE_COPY(QWinEventNotifier) - - HANDLE handleToEvent; - bool enabled; -}; - -QT_END_NAMESPACE - -#endif // QWINEVENTNOTIFIER_P_H diff --git a/src/network/socket/qlocalserver_p.h b/src/network/socket/qlocalserver_p.h index 67b7000..ed699fc 100644 --- a/src/network/socket/qlocalserver_p.h +++ b/src/network/socket/qlocalserver_p.h @@ -63,7 +63,7 @@ # include #elif defined(Q_OS_WIN) # include -# include +# include #else # include # include diff --git a/src/network/socket/qlocalsocket_p.h b/src/network/socket/qlocalsocket_p.h index 2671258..a0749fd 100644 --- a/src/network/socket/qlocalsocket_p.h +++ b/src/network/socket/qlocalsocket_p.h @@ -65,7 +65,7 @@ #elif defined(Q_OS_WIN) # include "private/qwindowspipewriter_p.h" # include "private/qringbuffer_p.h" -# include +# include #else # include "private/qabstractsocketengine_p.h" # include diff --git a/tests/auto/qwineventnotifier/tst_qwineventnotifier.cpp b/tests/auto/qwineventnotifier/tst_qwineventnotifier.cpp index cbe62f6..ba403dc 100644 --- a/tests/auto/qwineventnotifier/tst_qwineventnotifier.cpp +++ b/tests/auto/qwineventnotifier/tst_qwineventnotifier.cpp @@ -43,7 +43,7 @@ #include #ifdef Q_OS_WIN -#include +#include #include