DBus-C++
Desktop Communication Bus System
Summary
Download
Tracker
Mailing Lists
Wiki
libdbus-c++ Documentation
0.9.0
Files
Data Structures
Globals
Main Page
include
dbus-c++
dispatcher.h
Go to the documentation of this file.
1
/*
2
*
3
* D-Bus++ - C++ bindings for D-Bus
4
*
5
* Copyright (C) 2005-2007 Paolo Durante <shackan@gmail.com>
6
*
7
*
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.
12
*
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.
17
*
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
21
*
22
*/
23
24
25
#ifndef __DBUSXX_DISPATCHER_H
26
#define __DBUSXX_DISPATCHER_H
27
28
#include "
api.h
"
29
#include "
connection.h
"
30
#include "
eventloop.h
"
31
32
namespace
DBus
33
{
34
35
class
DXXAPI
Timeout
36
{
37
public
:
38
39
class
Internal;
40
41
Timeout
(Internal *i);
42
43
virtual
~Timeout
() {}
44
57
int
interval()
const
;
58
59
bool
enabled()
const
;
60
73
bool
handle();
74
75
virtual
void
toggle() = 0;
76
77
private
:
78
79
DXXAPILOCAL
Timeout
(
const
Timeout
&);
80
81
private
:
82
83
Internal *
_int
;
84
};
85
86
class
DXXAPI
Watch
87
{
88
public
:
89
90
class
Internal;
91
92
Watch
(Internal *i);
93
94
virtual
~Watch
() {}
95
104
int
descriptor()
const
;
105
116
int
flags()
const
;
117
118
bool
enabled()
const
;
119
138
bool
handle(
int
flags);
139
140
virtual
void
toggle() = 0;
141
142
private
:
143
144
DXXAPILOCAL
Watch
(
const
Watch
&);
145
146
private
:
147
148
Internal *
_int
;
149
};
150
151
class
DXXAPI
Dispatcher
152
{
153
public
:
154
155
virtual
~
Dispatcher
()
156
{}
157
158
void
queue_connection(
Connection::Private
*);
159
160
void
dispatch_pending();
161
bool
has_something_to_dispatch();
162
163
virtual
void
enter() = 0;
164
165
virtual
void
leave() = 0;
166
167
virtual
Timeout
*add_timeout(Timeout::Internal *) = 0;
168
169
virtual
void
rem_timeout(
Timeout
*) = 0;
170
171
virtual
Watch
*add_watch(Watch::Internal *) = 0;
172
173
virtual
void
rem_watch(
Watch
*) = 0;
174
175
struct
Private;
176
177
private
:
178
void
dispatch_pending(
Connection::PrivatePList
&pending_queue);
179
180
DefaultMutex
_mutex_p
;
181
DefaultMutex
_mutex_p_copy
;
182
183
Connection::PrivatePList
_pending_queue
;
184
};
185
186
extern
DXXAPI
Dispatcher
*
default_dispatcher
;
187
188
/* classes for multithreading support
189
*/
190
191
class
DXXAPI
Mutex
192
{
193
public
:
194
195
virtual
~Mutex
() {}
196
197
virtual
void
lock() = 0;
198
199
virtual
void
unlock() = 0;
200
201
struct
Internal;
202
203
protected
:
204
205
Internal *
_int
;
206
};
207
208
class
DXXAPI
CondVar
209
{
210
public
:
211
212
virtual
~CondVar
() {}
213
214
virtual
void
wait(
Mutex
*) = 0;
215
216
virtual
bool
wait_timeout(
Mutex
*,
int
timeout) = 0;
217
218
virtual
void
wake_one() = 0;
219
220
virtual
void
wake_all() = 0;
221
222
struct
Internal;
223
224
protected
:
225
226
Internal *
_int
;
227
};
228
229
typedef
Mutex
*(*MutexNewFn)();
230
typedef
void (*
MutexUnlockFn
)(
Mutex
*mx);
231
232
#ifndef DBUS_HAS_RECURSIVE_MUTEX
233
typedef
bool (*
MutexFreeFn
)(
Mutex
*mx);
234
typedef
bool (*
MutexLockFn
)(
Mutex
*mx);
235
#else
236
typedef
void (*
MutexFreeFn
)(
Mutex
*mx);
237
typedef
void (*
MutexLockFn
)(
Mutex
*mx);
238
#endif//DBUS_HAS_RECURSIVE_MUTEX
239
240
typedef
CondVar
*(*CondVarNewFn)();
241
typedef
void (*
CondVarFreeFn
)(
CondVar
*cv);
242
typedef
void (*
CondVarWaitFn
)(
CondVar
*cv,
Mutex
*mx);
243
typedef
bool (*
CondVarWaitTimeoutFn
)(
CondVar
*cv,
Mutex
*mx,
int
timeout);
244
typedef
void (*
CondVarWakeOneFn
)(
CondVar
*cv);
245
typedef
void (*
CondVarWakeAllFn
)(
CondVar
*cv);
246
247
void
DXXAPI
_init_threading
();
248
249
void
DXXAPI
_init_threading
(
250
MutexNewFn
,
MutexFreeFn
,
MutexLockFn
,
MutexUnlockFn
,
251
CondVarNewFn
,
CondVarFreeFn
,
CondVarWaitFn
,
CondVarWaitTimeoutFn
,
CondVarWakeOneFn
,
CondVarWakeAllFn
252
);
253
254
template
<
class
Mx,
class
Cv>
255
struct
Threading
256
{
257
static
void
init
()
258
{
259
_init_threading
(
260
mutex_new
,
mutex_free
,
mutex_lock
,
mutex_unlock
,
261
condvar_new
,
condvar_free
,
condvar_wait
,
condvar_wait_timeout
,
condvar_wake_one
,
condvar_wake_all
262
);
263
}
264
265
static
Mutex
*
mutex_new
()
266
{
267
return
new
Mx;
268
}
269
270
static
void
mutex_free
(
Mutex
*mx)
271
{
272
delete
mx;
273
}
274
275
static
void
mutex_lock
(
Mutex
*mx)
276
{
277
mx->
lock
();
278
}
279
280
static
void
mutex_unlock
(
Mutex
*mx)
281
{
282
mx->
unlock
();
283
}
284
285
static
CondVar
*
condvar_new
()
286
{
287
return
new
Cv;
288
}
289
290
static
void
condvar_free
(
CondVar
*cv)
291
{
292
delete
cv;
293
}
294
295
static
void
condvar_wait
(
CondVar
*cv,
Mutex
*mx)
296
{
297
cv->
wait
(mx);
298
}
299
300
static
bool
condvar_wait_timeout
(
CondVar
*cv,
Mutex
*mx,
int
timeout)
301
{
302
return
cv->
wait_timeout
(mx, timeout);
303
}
304
305
static
void
condvar_wake_one
(
CondVar
*cv)
306
{
307
cv->
wake_one
();
308
}
309
310
static
void
condvar_wake_all
(
CondVar
*cv)
311
{
312
cv->
wake_all
();
313
}
314
};
315
316
}
/* namespace DBus */
317
318
#endif//__DBUSXX_DISPATCHER_H