2002-12-28 Kristian Rietveld <kris@gtk.org>
[platform/upstream/dbus.git] / qt / dbus-qthread.cc
1 /* -*- mode: C; c-file-style: "gnu" -*- */
2 /* dbus-qthread.c  Qt threads integration
3  *
4  * Copyright (C) 2002  Zack Rusin <zack@kde.org>
5  *
6  * Licensed under the Academic Free License version 1.2
7  *
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.
12  *
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.
17  *
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
21  *
22  */
23
24 #include <qmutex.h>
25 #include <dbus/dbus.h>
26
27 static DBusMutex * dbus_qmutex_new    (void);
28 static void        dbus_qmutex_free   (DBusMutex *mutex);
29 static dbus_bool_t dbus_qmutex_lock   (DBusMutex *mutex);
30 static dbus_bool_t dbus_qmutex_unlock (DBusMutex *mutex);
31
32
33 static const DBusThreadFunctions functions =
34 {
35   DBUS_THREAD_FUNCTIONS_NEW_MASK |
36   DBUS_THREAD_FUNCTIONS_FREE_MASK |
37   DBUS_THREAD_FUNCTIONS_LOCK_MASK |
38   DBUS_THREAD_FUNCTIONS_UNLOCK_MASK,
39   dbus_qmutex_new,
40   dbus_qmutex_free,
41   dbus_qmutex_lock,
42   dbus_qmutex_unlock
43 };
44
45 static DBusMutex *
46 dbus_qmutex_new (void)
47 {
48   QMutex *mutex;
49   mutex = new QMutex;
50   return static_cast<DBusMutex*>( mutex );
51 }
52
53 static void
54 dbus_qmutex_free (DBusMutex *mutex)
55 {
56   QMutex * qmutex = static_cast<QMutex*>(mutex);
57   delete mutex;
58 }
59
60 static dbus_bool_t
61 dbus_qmutex_lock   (DBusMutex *mutex)
62 {
63   QMutex *qmutex = static_cast<QMutex*>(mutex);
64   qmutex->lock();
65   return TRUE;
66 }
67
68 static dbus_bool_t
69 dbus_qmutex_unlock (DBusMutex *mutex)
70 {
71   QMutex *qmutex = static_cast<QMutex*>(mutex);
72   qmutex->unlock();
73   return TRUE;
74 }
75
76 extern "C" {
77
78 void
79 dbus_qthread_init (void)
80 {
81   //Do we want to do anything else here?
82   dbus_threads_init (&functions);
83 }
84
85 }