3 * D-Bus++ - C++ bindings for D-Bus
5 * Copyright (C) 2005-2009 Paolo Durante <shackan@gmail.com>
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
13 * This library 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 GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25 #ifndef __DBUSXX_DISPATCHER_H
26 #define __DBUSXX_DISPATCHER_H
29 #include "connection.h"
30 #include "eventloop.h"
34 class DBUSXXAPI Timeout
50 virtual void toggle() = 0;
54 DBUSXXAPILOCAL
Timeout(const Timeout
&);
71 int descriptor() const;
77 bool handle(int flags
);
79 virtual void toggle() = 0;
83 DBUSXXAPILOCAL
Watch(const Watch
&);
90 class DBUSXXAPI Dispatcher
: public Synchronized
94 virtual ~Dispatcher();
96 void queue_connection(Connection::Private
*);
98 void dispatch_pending();
99 bool has_something_to_dispatch();
101 virtual void enter() = 0;
103 virtual void leave() = 0;
105 virtual Timeout
*add_timeout(Timeout::Internal
*) = 0;
107 virtual void rem_timeout(Timeout
*) = 0;
109 virtual Watch
*add_watch(Watch::Internal
*) = 0;
111 virtual void rem_watch(Watch
*) = 0;
117 Connection::PrivatePList _pending_queue
;
120 /* classes for multithreading support
123 class DBUSXXAPI Mutex
129 virtual void lock() = 0;
131 virtual void unlock() = 0;
140 class DBUSXXAPI CondVar
144 virtual ~CondVar() {}
146 virtual void wait(Mutex
*) = 0;
148 virtual bool wait_timeout(Mutex
*, int timeout
) = 0;
150 virtual void wake_one() = 0;
152 virtual void wake_all() = 0;
161 typedef Mutex
*(*MutexNewFn
)();
162 typedef void (*MutexUnlockFn
)(Mutex
*mx
);
164 #ifndef DBUS_HAS_RECURSIVE_MUTEX
165 typedef bool (*MutexFreeFn
)(Mutex
*mx
);
166 typedef bool (*MutexLockFn
)(Mutex
*mx
);
168 typedef void (*MutexFreeFn
)(Mutex
*mx
);
169 typedef void (*MutexLockFn
)(Mutex
*mx
);
170 #endif//DBUS_HAS_RECURSIVE_MUTEX
172 typedef CondVar
*(*CondVarNewFn
)();
173 typedef void (*CondVarFreeFn
)(CondVar
*cv
);
174 typedef void (*CondVarWaitFn
)(CondVar
*cv
, Mutex
*mx
);
175 typedef bool (*CondVarWaitTimeoutFn
)(CondVar
*cv
, Mutex
*mx
, int timeout
);
176 typedef void (*CondVarWakeOneFn
)(CondVar
*cv
);
177 typedef void (*CondVarWakeAllFn
)(CondVar
*cv
);
179 void DBUSXXAPI
_init_threading();
181 void DBUSXXAPI
_init_threading(
182 MutexNewFn
, MutexFreeFn
, MutexLockFn
, MutexUnlockFn
,
183 CondVarNewFn
, CondVarFreeFn
, CondVarWaitFn
, CondVarWaitTimeoutFn
, CondVarWakeOneFn
, CondVarWakeAllFn
186 template<class Mx
, class Cv
>
192 mutex_new
, mutex_free
, mutex_lock
, mutex_unlock
,
193 condvar_new
, condvar_free
, condvar_wait
, condvar_wait_timeout
, condvar_wake_one
, condvar_wake_all
197 static Mutex
*mutex_new()
202 static void mutex_free(Mutex
*mx
)
207 static void mutex_lock(Mutex
*mx
)
212 static void mutex_unlock(Mutex
*mx
)
217 static CondVar
*condvar_new()
222 static void condvar_free(CondVar
*cv
)
227 static void condvar_wait(CondVar
*cv
, Mutex
*mx
)
232 static bool condvar_wait_timeout(CondVar
*cv
, Mutex
*mx
, int timeout
)
234 return cv
->wait_timeout(mx
, timeout
);
237 static void condvar_wake_one(CondVar
*cv
)
242 static void condvar_wake_all(CondVar
*cv
)
248 } /* namespace DBus */
250 #endif//__DBUSXX_DISPATCHER_H