Main Page | Modules | Namespace List | Class Hierarchy | Data Structures | Directories | File List | Namespace Members | Data Fields | Related Pages

dbus-qthread.cpp

00001 /* -*- mode: C; c-file-style: "gnu" -*- */
00002 /* dbus-qthread.cpp  Qt threads integration
00003  *
00004  * Copyright (C) 2002  Zack Rusin <zack@kde.org>
00005  *
00006  * Licensed under the Academic Free License version 2.0
00007  *
00008  * This program is free software; you can redistribute it and/or modify
00009  * it under the terms of the GNU General Public License as published by
00010  * the Free Software Foundation; either version 2 of the License, or
00011  * (at your option) any later version.
00012  *
00013  * This program is distributed in the hope that it will be useful,
00014  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00015  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00016  * GNU General Public License for more details.
00017  *
00018  * You should have received a copy of the GNU General Public License
00019  * along with this program; if not, write to the Free Software
00020  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00021  *
00022  */
00023 
00024 #include <dbus/dbus.h>
00025 #include <qmutex.h>
00026 
00027 #if defined(QT_THREAD_SUPPORT)
00028 
00029 static DBusMutex * dbus_qmutex_new    (void);
00030 static void        dbus_qmutex_free   (DBusMutex *mutex);
00031 static dbus_bool_t dbus_qmutex_lock   (DBusMutex *mutex);
00032 static dbus_bool_t dbus_qmutex_unlock (DBusMutex *mutex);
00033 
00034 static DBusCondVar*dbus_qcondvar_new          (void);
00035 static void        dbus_qcondvar_free         (DBusCondVar *cond);
00036 static void        dbus_qcondvar_wait         (DBusCondVar *cond,
00037                                                DBusMutex   *mutex);
00038 static dbus_bool_t dbus_qcondvar_wait_timeout (DBusCondVar *cond,
00039                                                DBusMutex   *mutex.
00040                                                int          timeout_msec);
00041 static void        dbus_qcondvar_wake_one     (DBusCondVar *cond);
00042 static void        dbus_qcondvar_wake_all     (DBusCondVar *cond);
00043 
00044 
00045 static const DBusThreadFunctions functions =
00046 {
00047   DBUS_THREAD_FUNCTIONS_NEW_MASK |
00048   DBUS_THREAD_FUNCTIONS_FREE_MASK |
00049   DBUS_THREAD_FUNCTIONS_LOCK_MASK |
00050   DBUS_THREAD_FUNCTIONS_UNLOCK_MASK |
00051   DBUS_THREAD_FUNCTIONS_CONDVAR_NEW_MASK |
00052   DBUS_THREAD_FUNCTIONS_CONDVAR_FREE_MASK |
00053   DBUS_THREAD_FUNCTIONS_CONDVAR_WAIT_MASK |
00054   DBUS_THREAD_FUNCTIONS_CONDVAR_WAIT_TIMEOUT_MASK |
00055   DBUS_THREAD_FUNCTIONS_CONDVAR_WAKE_ONE_MASK|
00056   DBUS_THREAD_FUNCTIONS_CONDVAR_WAKE_ALL_MASK,
00057   dbus_qmutex_new,
00058   dbus_qmutex_free,
00059   dbus_qmutex_lock,
00060   dbus_qmutex_unlock
00061   dbus_qcondvar_new,
00062   dbus_qcondvar_free,
00063   dbus_qcondvar_wait,
00064   dbus_qcondvar_wait_timeout,
00065   dbus_qcondvar_wake_one,
00066   dbus_qcondvar_wake_all
00067 };
00068 
00069 static DBusMutex *
00070 dbus_qmutex_new (void)
00071 {
00072   QMutex *mutex;
00073   mutex = new QMutex;
00074   return static_cast<DBusMutex*>( mutex );
00075 }
00076 
00077 static void
00078 dbus_qmutex_free (DBusMutex *mutex)
00079 {
00080   QMutex * qmutex = static_cast<QMutex*>(mutex);
00081   delete mutex;
00082 }
00083 
00084 static dbus_bool_t
00085 dbus_qmutex_lock   (DBusMutex *mutex)
00086 {
00087   QMutex *qmutex = static_cast<QMutex*>(mutex);
00088   qmutex->lock();
00089   return TRUE;
00090 }
00091 
00092 static dbus_bool_t
00093 dbus_qmutex_unlock (DBusMutex *mutex)
00094 {
00095   QMutex *qmutex = static_cast<QMutex*>(mutex);
00096   qmutex->unlock();
00097   return TRUE;
00098 }
00099 
00100 static DBusCondVar*
00101 dbus_qcondvar_new (void)
00102 {
00103   QWaitCondition *cond;
00104   cond = new QWaitCondition;
00105   return static_cast<DBusCondVar*>( cond );
00106 }
00107 
00108 static void
00109 dbus_qcondvar_free (DBusCondVar *cond)
00110 {
00111   QWaitCondition *qcond = static_cast<QWaitCondition*>(cond);
00112   delete qcond;
00113 }
00114 
00115 static void
00116 dbus_qcondvar_wait (DBusCondVar *cond,
00117                     DBusMutex   *mutex)
00118 {
00119   QWaitCondition *qcond = static_cast<QWaitCondition*>(cond);
00120   QMutex *qmutex = static_cast<QMutex*>(mutex);
00121 
00122   qcond->wait (qmutex);
00123 }
00124 
00125 static dbus_bool_t
00126 dbus_gcondvar_wait_timeout (DBusCondVar *cond,
00127                             DBusMutex   *mutex,
00128                             int         timeout_msec)
00129 {
00130   QWaitCondition *qcond = static_cast<QWaitCondition*>(cond);
00131   QMutex *qmutex = static_cast<QMutex*>(mutex);
00132 
00133   return qcond->wait (qmutex, timout_msec);
00134 }
00135 
00136 static void
00137 dbus_qcondvar_wake_one (DBusCondVar *cond)
00138 {
00139   QWaitCondition *qcond = static_cast<QWaitCondition*>(cond);
00140 
00141   qcond->wakeOne (qmutex);
00142 }
00143 
00144 static void
00145 dbus_qcondvar_wake_all (DBusCondVar *cond)
00146 {
00147   QWaitCondition *qcond = static_cast<QWaitCondition*>(cond);
00148 
00149   qcond->wakeAll (qmutex);
00150 }
00151 
00152 extern "C" {
00153 
00154 void
00155 dbus_qthread_init (void)
00156 {
00157   //Do we want to do anything else here?
00158   dbus_threads_init (&functions);
00159 }
00160 
00161 }
00162 
00163 #endif // QT_THREAD_SUPPORT

Generated on Tue Sep 13 01:28:07 2005 for D-BUS by  doxygen 1.4.4