Original DBUS bindings for TQt
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

165 lines
4.1KB

  1. /* -*- mode: C; c-file-style: "gnu" -*- */
  2. /* dbus-qthread.cpp TQt threads integration
  3. *
  4. * Copyright (C) 2002 Zack Rusin <zack@kde.org>
  5. *
  6. * Licensed under the Academic Free License version 2.0
  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. #include <dbus/dbus.h>
  24. #include <tqmutex.h>
  25. //#if defined(TQT_THREAD_SUPPORT)
  26. #if 0
  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. static DBusCondVar*dbus_qcondvar_new (void);
  32. static void dbus_qcondvar_free (DBusCondVar *cond);
  33. static void dbus_qcondvar_wait (DBusCondVar *cond,
  34. DBusMutex *mutex);
  35. static dbus_bool_t dbus_qcondvar_wait_timeout (DBusCondVar *cond,
  36. DBusMutex *mutex,
  37. int timeout_msec);
  38. static void dbus_qcondvar_wake_one (DBusCondVar *cond);
  39. static void dbus_qcondvar_wake_all (DBusCondVar *cond);
  40. static const DBusThreadFunctions functions =
  41. {
  42. DBUS_THREAD_FUNCTIONS_NEW_MASK |
  43. DBUS_THREAD_FUNCTIONS_FREE_MASK |
  44. DBUS_THREAD_FUNCTIONS_LOCK_MASK |
  45. DBUS_THREAD_FUNCTIONS_UNLOCK_MASK |
  46. DBUS_THREAD_FUNCTIONS_CONDVAR_NEW_MASK |
  47. DBUS_THREAD_FUNCTIONS_CONDVAR_FREE_MASK |
  48. DBUS_THREAD_FUNCTIONS_CONDVAR_WAIT_MASK |
  49. DBUS_THREAD_FUNCTIONS_CONDVAR_WAIT_TIMEOUT_MASK |
  50. DBUS_THREAD_FUNCTIONS_CONDVAR_WAKE_ONE_MASK|
  51. DBUS_THREAD_FUNCTIONS_CONDVAR_WAKE_ALL_MASK,
  52. dbus_qmutex_new,
  53. dbus_qmutex_free,
  54. dbus_qmutex_lock,
  55. dbus_qmutex_unlock
  56. dbus_qcondvar_new,
  57. dbus_qcondvar_free,
  58. dbus_qcondvar_wait,
  59. dbus_qcondvar_wait_timeout,
  60. dbus_qcondvar_wake_one,
  61. dbus_qcondvar_wake_all
  62. };
  63. static DBusMutex *
  64. dbus_qmutex_new (void)
  65. {
  66. TQMutex *mutex;
  67. mutex = new TQMutex;
  68. return static_cast<DBusMutex*>( mutex );
  69. }
  70. static void
  71. dbus_qmutex_free (DBusMutex *mutex)
  72. {
  73. TQMutex * qmutex = static_cast<TQMutex*>(mutex);
  74. delete mutex;
  75. }
  76. static dbus_bool_t
  77. dbus_qmutex_lock (DBusMutex *mutex)
  78. {
  79. TQMutex *qmutex = static_cast<TQMutex*>(mutex);
  80. qmutex->lock();
  81. return TRUE;
  82. }
  83. static dbus_bool_t
  84. dbus_qmutex_unlock (DBusMutex *mutex)
  85. {
  86. TQMutex *qmutex = static_cast<TQMutex*>(mutex);
  87. qmutex->unlock();
  88. return TRUE;
  89. }
  90. static DBusCondVar*
  91. dbus_qcondvar_new (void)
  92. {
  93. TQWaitCondition *cond;
  94. cond = new TQWaitCondition;
  95. return static_cast<DBusCondVar*>( cond );
  96. }
  97. static void
  98. dbus_qcondvar_free (DBusCondVar *cond)
  99. {
  100. TQWaitCondition *qcond = static_cast<TQWaitCondition*>(cond);
  101. delete qcond;
  102. }
  103. static void
  104. dbus_qcondvar_wait (DBusCondVar *cond,
  105. DBusMutex *mutex)
  106. {
  107. TQWaitCondition *qcond = static_cast<TQWaitCondition*>(cond);
  108. TQMutex *qmutex = static_cast<TQMutex*>(mutex);
  109. qcond->wait (qmutex);
  110. }
  111. static dbus_bool_t
  112. dbus_gcondvar_wait_timeout (DBusCondVar *cond,
  113. DBusMutex *mutex,
  114. int timeout_msec)
  115. {
  116. TQWaitCondition *qcond = static_cast<TQWaitCondition*>(cond);
  117. TQMutex *qmutex = static_cast<TQMutex*>(mutex);
  118. return qcond->wait (qmutex, timout_msec);
  119. }
  120. static void
  121. dbus_qcondvar_wake_one (DBusCondVar *cond)
  122. {
  123. TQWaitCondition *qcond = static_cast<TQWaitCondition*>(cond);
  124. qcond->wakeOne (qmutex);
  125. }
  126. static void
  127. dbus_qcondvar_wake_all (DBusCondVar *cond)
  128. {
  129. TQWaitCondition *qcond = static_cast<TQWaitCondition*>(cond);
  130. qcond->wakeAll (qmutex);
  131. }
  132. extern "C" {
  133. void
  134. dbus_qthread_init (void)
  135. {
  136. //Do we want to do anything else here?
  137. dbus_threads_init (&functions);
  138. }
  139. }
  140. #endif // TQT_THREAD_SUPPORT