1 /* -*- mode: C; c-file-style: "gnu" -*- */
2 /* dbus-qthread.cpp Qt threads integration
4 * Copyright (C) 2002 Zack Rusin <zack@kde.org>
6 * Licensed under the Academic Free License version 1.2
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 #include <dbus/dbus.h>
27 #if defined(QT_THREAD_SUPPORT)
29 static DBusMutex * dbus_qmutex_new (void);
30 static void dbus_qmutex_free (DBusMutex *mutex);
31 static dbus_bool_t dbus_qmutex_lock (DBusMutex *mutex);
32 static dbus_bool_t dbus_qmutex_unlock (DBusMutex *mutex);
34 static DBusCondVar*dbus_qcondvar_new (void);
35 static void dbus_qcondvar_free (DBusCondVar *cond);
36 static void dbus_qcondvar_wait (DBusCondVar *cond,
38 static dbus_bool_t dbus_qcondvar_wait_timeout (DBusCondVar *cond,
41 static void dbus_qcondvar_wake_one (DBusCondVar *cond);
42 static void dbus_qcondvar_wake_all (DBusCondVar *cond);
45 static const DBusThreadFunctions functions =
47 DBUS_THREAD_FUNCTIONS_NEW_MASK |
48 DBUS_THREAD_FUNCTIONS_FREE_MASK |
49 DBUS_THREAD_FUNCTIONS_LOCK_MASK |
50 DBUS_THREAD_FUNCTIONS_UNLOCK_MASK |
51 DBUS_THREAD_FUNCTIONS_CONDVAR_NEW_MASK |
52 DBUS_THREAD_FUNCTIONS_CONDVAR_FREE_MASK |
53 DBUS_THREAD_FUNCTIONS_CONDVAR_WAIT_MASK |
54 DBUS_THREAD_FUNCTIONS_CONDVAR_WAIT_TIMEOUT_MASK |
55 DBUS_THREAD_FUNCTIONS_CONDVAR_WAKE_ONE_MASK|
56 DBUS_THREAD_FUNCTIONS_CONDVAR_WAKE_ALL_MASK,
64 dbus_qcondvar_wait_timeout,
65 dbus_qcondvar_wake_one,
66 dbus_qcondvar_wake_all
70 dbus_qmutex_new (void)
74 return static_cast<DBusMutex*>( mutex );
78 dbus_qmutex_free (DBusMutex *mutex)
80 QMutex * qmutex = static_cast<QMutex*>(mutex);
85 dbus_qmutex_lock (DBusMutex *mutex)
87 QMutex *qmutex = static_cast<QMutex*>(mutex);
93 dbus_qmutex_unlock (DBusMutex *mutex)
95 QMutex *qmutex = static_cast<QMutex*>(mutex);
101 dbus_qcondvar_new (void)
103 QWaitCondition *cond;
104 cond = new QWaitCondition;
105 return static_cast<DBusCondVar*>( cond );
109 dbus_qcondvar_free (DBusCondVar *cond)
111 QWaitCondition *qcond = static_cast<QWaitCondition*>(cond);
116 dbus_qcondvar_wait (DBusCondVar *cond,
119 QWaitCondition *qcond = static_cast<QWaitCondition*>(cond);
120 QMutex *qmutex = static_cast<QMutex*>(mutex);
122 qcond->wait (qmutex);
126 dbus_gcondvar_wait_timeout (DBusCondVar *cond,
130 QWaitCondition *qcond = static_cast<QWaitCondition*>(cond);
131 QMutex *qmutex = static_cast<QMutex*>(mutex);
133 return qcond->wait (qmutex, timout_msec);
137 dbus_qcondvar_wake_one (DBusCondVar *cond)
139 QWaitCondition *qcond = static_cast<QWaitCondition*>(cond);
141 qcond->wakeOne (qmutex);
145 dbus_qcondvar_wake_all (DBusCondVar *cond)
147 QWaitCondition *qcond = static_cast<QWaitCondition*>(cond);
149 qcond->wakeAll (qmutex);
155 dbus_qthread_init (void)
157 //Do we want to do anything else here?
158 dbus_threads_init (&functions);
163 #endif // QT_THREAD_SUPPORT