1 /****************************************************************************
3 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/
6 ** This file is part of the QtDBus module of the Qt Toolkit.
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** GNU Lesser General Public License Usage
10 ** This file may be used under the terms of the GNU Lesser General Public
11 ** License version 2.1 as published by the Free Software Foundation and
12 ** appearing in the file LICENSE.LGPL included in the packaging of this
13 ** file. Please review the following information to ensure the GNU Lesser
14 ** General Public License version 2.1 requirements will be met:
15 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
17 ** In addition, as a special exception, Nokia gives you certain additional
18 ** rights. These rights are described in the Nokia Qt LGPL Exception
19 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
21 ** GNU General Public License Usage
22 ** Alternatively, this file may be used under the terms of the GNU General
23 ** Public License version 3.0 as published by the Free Software Foundation
24 ** and appearing in the file LICENSE.GPL included in the packaging of this
25 ** file. Please review the following information to ensure the GNU General
26 ** Public License version 3.0 requirements will be met:
27 ** http://www.gnu.org/copyleft/gpl.html.
30 ** Alternatively, this file may be used in accordance with the terms and
31 ** conditions contained in a signed written agreement between you and Nokia.
40 ****************************************************************************/
41 #ifndef QDBUSTHREADDEBUG_P_H
42 #define QDBUSTHREADDEBUG_P_H
48 // This file is not part of the Qt API. It exists purely as an
49 // implementation detail. This header file may change from version to
50 // version without notice, or even be removed.
55 #include <QtCore/qglobal.h>
59 #if !defined(QDBUS_THREAD_DEBUG) && defined(QT_BUILD_INTERNAL)
60 # define QDBUS_THREAD_DEBUG 1
63 #if QDBUS_THREAD_DEBUG
65 typedef void (*qdbusThreadDebugFunc)(int, int, QDBusConnectionPrivate *);
66 Q_DBUS_EXPORT void qdbusDefaultThreadDebug(int, int, QDBusConnectionPrivate *);
67 extern Q_DBUS_EXPORT qdbusThreadDebugFunc qdbusThreadDebug;
74 RegisterObjectAction = 2,
75 UnregisterObjectAction = 3,
76 ObjectRegisteredAtAction = 4,
78 CloseConnectionAction = 10,
79 ObjectDestroyedAction = 11,
80 RelaySignalAction = 12,
81 HandleObjectCallAction = 13,
82 HandleSignalAction = 14,
83 ConnectRelayAction = 15,
84 DisconnectRelayAction = 16,
85 FindMetaObject1Action = 17,
86 FindMetaObject2Action = 18,
87 RegisterServiceAction = 19,
88 UnregisterServiceAction = 20,
89 UpdateSignalHookOwnerAction = 21,
90 HandleObjectCallPostEventAction = 22,
91 HandleObjectCallSemaphoreAction = 23,
92 DoDispatchAction = 24,
93 SendWithReplyAsyncAction = 25,
94 MessageResultReceivedAction = 26,
95 ActivateSignalAction = 27,
96 PendingCallBlockAction = 28,
98 AddTimeoutAction = 50,
99 RealAddTimeoutAction = 51,
100 RemoveTimeoutAction = 52,
101 KillTimerAction = 58,
102 TimerEventAction = 59,
104 RemoveWatchAction = 61,
105 ToggleWatchAction = 62,
106 SocketReadAction = 63,
107 SocketWriteAction = 64
110 struct QDBusLockerBase
130 #if QDBUS_THREAD_DEBUG
131 static inline void reportThreadAction(int action, int condition, QDBusConnectionPrivate *ptr)
132 { if (qdbusThreadDebug) qdbusThreadDebug(action, condition, ptr); }
134 static inline void reportThreadAction(int, int, QDBusConnectionPrivate *) { }
138 struct QDBusReadLocker: QDBusLockerBase
140 QDBusConnectionPrivate *self;
142 inline QDBusReadLocker(ThreadAction a, QDBusConnectionPrivate *s)
145 reportThreadAction(action, BeforeLock, self);
146 self->lock.lockForRead();
147 reportThreadAction(action, AfterLock, self);
150 inline ~QDBusReadLocker()
152 reportThreadAction(action, BeforeUnlock, self);
154 reportThreadAction(action, AfterUnlock, self);
158 struct QDBusWriteLocker: QDBusLockerBase
160 QDBusConnectionPrivate *self;
162 inline QDBusWriteLocker(ThreadAction a, QDBusConnectionPrivate *s)
165 reportThreadAction(action, BeforeLock, self);
166 self->lock.lockForWrite();
167 reportThreadAction(action, AfterLock, self);
170 inline ~QDBusWriteLocker()
172 reportThreadAction(action, BeforeUnlock, self);
174 reportThreadAction(action, AfterUnlock, self);
178 struct QDBusMutexLocker: QDBusLockerBase
180 QDBusConnectionPrivate *self;
183 inline QDBusMutexLocker(ThreadAction a, QDBusConnectionPrivate *s,
185 : self(s), mutex(m), action(a)
187 reportThreadAction(action, BeforeLock, self);
189 reportThreadAction(action, AfterLock, self);
192 inline ~QDBusMutexLocker()
194 reportThreadAction(action, BeforeUnlock, self);
196 reportThreadAction(action, AfterUnlock, self);
200 struct QDBusDispatchLocker: QDBusMutexLocker
202 inline QDBusDispatchLocker(ThreadAction a, QDBusConnectionPrivate *s)
203 : QDBusMutexLocker(a, s, &s->dispatchLock)
207 struct QDBusWatchAndTimeoutLocker: QDBusMutexLocker
209 inline QDBusWatchAndTimeoutLocker(ThreadAction a, QDBusConnectionPrivate *s)
210 : QDBusMutexLocker(a, s, &s->watchAndTimeoutLock)
214 #if QDBUS_THREAD_DEBUG
215 # define SEM_ACQUIRE(action, sem) \
217 QDBusLockerBase::reportThreadAction(action, QDBusLockerBase::BeforeAcquire, this); \
219 QDBusLockerBase::reportThreadAction(action, QDBusLockerBase::AfterAcquire, this); \
222 # define SEM_RELEASE(action, sem) \
224 QDBusLockerBase::reportThreadAction(action, QDBusLockerBase::BeforeRelease, that); \
226 QDBusLockerBase::reportThreadAction(action, QDBusLockerBase::AfterRelease, that); \
230 # define SEM_ACQUIRE(action, sem) sem.acquire()
231 # define SEM_RELEASE(action, sem) sem.release()