eventloop.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_EVENTLOOP_H
26#define __DBUSXX_EVENTLOOP_H
27
28#include <pthread.h>
29#include <list>
30
31#include "api.h"
32#include "util.h"
33
34namespace DBus
35{
36
37/*
38 * these Default *classes implement a very simple event loop which
39 * is used here as the default main loop, if you want to hook
40 * a different one use the Bus *classes in eventloop-integration.h
41 * or the Glib::Bus *classes as a reference
42 */
43
44class DefaultMainLoop;
45
47{
48public:
49
51
52 virtual ~DefaultTimeout();
53
54 bool enabled()
55 {
56 return _enabled;
57 }
58 void enabled(bool e)
59 {
60 _enabled = e;
61 }
62
64 {
65 return _interval;
66 }
67 void interval(int i)
68 {
69 _interval = i;
70 }
71
72 bool repeat()
73 {
74 return _repeat;
75 }
76 void repeat(bool r)
77 {
78 _repeat = r;
79 }
80
81 void *data()
82 {
83 return _data;
84 }
85 void data(void *d)
86 {
87 _data = d;
88 }
89
91
92private:
93
95
97 bool _repeat;
98
100
101 void *_data;
102
104
105 friend class DefaultMainLoop;
106};
107
108typedef std::list< DefaultTimeout *> DefaultTimeouts;
109
111{
112public:
113
114 DefaultWatch(int fd, int flags, DefaultMainLoop *);
115
116 virtual ~DefaultWatch();
117
118 bool enabled()
119 {
120 return _enabled;
121 }
122 void enabled(bool e)
123 {
124 _enabled = e;
125 }
126
128 {
129 return _fd;
130 }
131
132 int flags()
133 {
134 return _flags;
135 }
136 void flags(int f)
137 {
138 _flags = f;
139 }
140
141 int state()
142 {
143 return _state;
144 }
145
146 void *data()
147 {
148 return _data;
149 }
150 void data(void *d)
151 {
152 _data = d;
153 }
154
156
157private:
158
160
161 int _fd;
164
165 void *_data;
166
168
169 friend class DefaultMainLoop;
170};
171
172typedef std::list< DefaultWatch *> DefaultWatches;
173
175{
176public:
177
181 DefaultMutex();
182
187 DefaultMutex(bool recursive);
188
190
191 void lock();
192
193 void unlock();
194
195private:
196
197 pthread_mutex_t _mutex;
198};
199
201{
202public:
203
205
206 virtual ~DefaultMainLoop();
207
208 virtual void dispatch();
209
210 int _fdunlock[2];
211private:
212
215
218
219 friend class DefaultTimeout;
220 friend class DefaultWatch;
221};
222
223} /* namespace DBus */
224
225#endif//__DBUSXX_EVENTLOOP_H
#define DXXAPI
Definition api.h:36
friend class DefaultWatch
Definition eventloop.h:220
DefaultTimeouts _timeouts
Definition eventloop.h:214
virtual void dispatch()
DefaultMutex _mutex_t
Definition eventloop.h:213
DefaultMutex _mutex_w
Definition eventloop.h:216
friend class DefaultTimeout
Definition eventloop.h:219
DefaultWatches _watches
Definition eventloop.h:217
pthread_mutex_t _mutex
Definition eventloop.h:197
friend class DefaultMainLoop
Definition eventloop.h:105
void enabled(bool e)
Definition eventloop.h:58
void interval(int i)
Definition eventloop.h:67
DefaultMainLoop * _disp
Definition eventloop.h:103
void repeat(bool r)
Definition eventloop.h:76
DefaultTimeout(int interval, bool repeat, DefaultMainLoop *)
Definition eventloop.cpp:44
Slot< void, DefaultTimeout & > expired
Definition eventloop.h:90
void data(void *d)
Definition eventloop.h:85
void flags(int f)
Definition eventloop.h:136
friend class DefaultMainLoop
Definition eventloop.h:169
DefaultMainLoop * _disp
Definition eventloop.h:167
void data(void *d)
Definition eventloop.h:150
Slot< void, DefaultWatch & > ready
Definition eventloop.h:155
DefaultWatch(int fd, int flags, DefaultMainLoop *)
Definition eventloop.cpp:64
void enabled(bool e)
Definition eventloop.h:122
std::list< DefaultTimeout * > DefaultTimeouts
Definition eventloop.h:108
std::list< DefaultWatch * > DefaultWatches
Definition eventloop.h:172