diff options
author | Alex Trotsenko <alex1973tr@gmail.com> | 2019-11-09 17:48:01 +0200 |
---|---|---|
committer | Alex Trotsenko <alex1973tr@gmail.com> | 2019-11-13 17:22:04 +0200 |
commit | 4e0d5498eb7ba401e6697182ce74b34d439ecf76 (patch) | |
tree | 5d5f3baa293990ee886dba4647bc1378b8be735b | |
parent | 79a1fc0e0106d125b467b603087137fdff5401f4 (diff) |
QEventDispatcherWin32: unify input checks in {un}register...()
The event manager has a family of the functions for registering
sockets notifiers, event notifiers, and timers. To ensure
efficient debugging, it would be useful to have one approach
regarding input parameters validation for the entire set of
that functions. Based on registerSocketNotifier() implementation,
this patch offers the same debugging principles for
QWinEventNotifier and QTimer. Some debug messages have also
been refined.
Change-Id: I1418ef43c51f7b794462b5e9c8a849633e0c60f9
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
-rw-r--r-- | src/corelib/kernel/qeventdispatcher_win.cpp | 36 |
1 files changed, 18 insertions, 18 deletions
diff --git a/src/corelib/kernel/qeventdispatcher_win.cpp b/src/corelib/kernel/qeventdispatcher_win.cpp index 87623f304a..517ba17fb2 100644 --- a/src/corelib/kernel/qeventdispatcher_win.cpp +++ b/src/corelib/kernel/qeventdispatcher_win.cpp @@ -636,11 +636,11 @@ void QEventDispatcherWin32::registerSocketNotifier(QSocketNotifier *notifier) int type = notifier->type(); #ifndef QT_NO_DEBUG if (sockfd < 0) { - qWarning("QSocketNotifier: Internal error"); + qWarning("QEventDispatcherWin32::registerSocketNotifier: invalid socket identifier"); return; } if (notifier->thread() != thread() || thread() != QThread::currentThread()) { - qWarning("QSocketNotifier: socket notifiers cannot be enabled from another thread"); + qWarning("QEventDispatcherWin32: socket notifiers cannot be enabled from another thread"); return; } #endif @@ -697,11 +697,11 @@ void QEventDispatcherWin32::unregisterSocketNotifier(QSocketNotifier *notifier) #ifndef QT_NO_DEBUG int sockfd = notifier->socket(); if (sockfd < 0) { - qWarning("QSocketNotifier: Internal error"); + qWarning("QEventDispatcherWin32::unregisterSocketNotifier: invalid socket identifier"); return; } if (notifier->thread() != thread() || thread() != QThread::currentThread()) { - qWarning("QSocketNotifier: socket notifiers cannot be disabled from another thread"); + qWarning("QEventDispatcherWin32: socket notifiers cannot be disabled from another thread"); return; } #endif @@ -783,8 +783,7 @@ bool QEventDispatcherWin32::unregisterTimer(int timerId) qWarning("QEventDispatcherWin32::unregisterTimer: invalid argument"); return false; } - QThread *currentThread = QThread::currentThread(); - if (thread() != currentThread) { + if (thread() != QThread::currentThread()) { qWarning("QEventDispatcherWin32::unregisterTimer: timers cannot be stopped from another thread"); return false; } @@ -811,8 +810,7 @@ bool QEventDispatcherWin32::unregisterTimers(QObject *object) qWarning("QEventDispatcherWin32::unregisterTimers: invalid argument"); return false; } - QThread *currentThread = QThread::currentThread(); - if (object->thread() != thread() || thread() != currentThread) { + if (object->thread() != thread() || thread() != QThread::currentThread()) { qWarning("QEventDispatcherWin32::unregisterTimers: timers cannot be stopped from another thread"); return false; } @@ -837,10 +835,12 @@ bool QEventDispatcherWin32::unregisterTimers(QObject *object) QList<QEventDispatcherWin32::TimerInfo> QEventDispatcherWin32::registeredTimers(QObject *object) const { +#ifndef QT_NO_DEBUG if (!object) { qWarning("QEventDispatcherWin32:registeredTimers: invalid argument"); return QList<TimerInfo>(); } +#endif Q_D(const QEventDispatcherWin32); QList<TimerInfo> list; @@ -853,13 +853,13 @@ QEventDispatcherWin32::registeredTimers(QObject *object) const bool QEventDispatcherWin32::registerEventNotifier(QWinEventNotifier *notifier) { - if (!notifier) { - qWarning("QWinEventNotifier: Internal error"); - return false; - } else if (notifier->thread() != thread() || thread() != QThread::currentThread()) { - qWarning("QWinEventNotifier: event notifiers cannot be enabled from another thread"); + Q_ASSERT(notifier); +#ifndef QT_NO_DEBUG + if (notifier->thread() != thread() || thread() != QThread::currentThread()) { + qWarning("QEventDispatcherWin32: event notifiers cannot be enabled from another thread"); return false; } +#endif Q_D(QEventDispatcherWin32); @@ -877,13 +877,13 @@ bool QEventDispatcherWin32::registerEventNotifier(QWinEventNotifier *notifier) void QEventDispatcherWin32::unregisterEventNotifier(QWinEventNotifier *notifier) { - if (!notifier) { - qWarning("QWinEventNotifier: Internal error"); - return; - } else if (notifier->thread() != thread() || thread() != QThread::currentThread()) { - qWarning("QWinEventNotifier: event notifiers cannot be disabled from another thread"); + Q_ASSERT(notifier); +#ifndef QT_NO_DEBUG + if (notifier->thread() != thread() || thread() != QThread::currentThread()) { + qWarning("QEventDispatcherWin32: event notifiers cannot be disabled from another thread"); return; } +#endif Q_D(QEventDispatcherWin32); |