# DBus-C++

## Desktop Communication Bus System

libdbus-c-- Documentation 0.9.0

- Files
- Data Structures
- Globals
- Main Page

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
34 namespace 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
44 class DefaultMainLoop;
45
46 class DXXAPI DefaultTimeout
47{
48 public:
49
50 DefaultTimeout(int interval, bool repeat, DefaultMainLoop *);
51
52 virtual ~DefaultTimeout();
53
54 bool enabled()
55 {
56 return _enabled;
57 }
58 void enabled(bool e)
59 {
60 _enabled = e;
61 }
62
63 int interval()
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
90 Slot<void, DefaultTimeout &> expired;
91
92 private:
93
94 bool _enabled;
95
96 int _interval;
97 bool _repeat;
98
99 double _expiration;
100
101 void *_data;
102
103 DefaultMainLoop *_disp;
104
105 friend class DefaultMainLoop;
106};
107
108 typedef std::list< DefaultTimeout *> DefaultTimeouts;
109
110 class DXXAPI DefaultWatch
111{
112 public:
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
127 int descriptor()
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
155 Slot<void, DefaultWatch &> ready;
156
157 private:
158
159 bool _enabled;
160
161 int _fd;
162 int _flags;
163 int _state;
164
165 void *_data;
166
167 DefaultMainLoop *_disp;
168
169 friend class DefaultMainLoop;
170};
171
172 typedef std::list< DefaultWatch *> DefaultWatches;
173
174 class DXXAPI DefaultMutex
175{
176 public:
177
181 DefaultMutex();
182
187 DefaultMutex(bool recursive);
188
189 ~DefaultMutex();
190
191 void lock();
192
193 void unlock();
194
195 private:
196
197 pthread_mutex_t _mutex;
198};
199
200 class DXXAPI DefaultMainLoop
201{
202 public:
203
204 DefaultMainLoop();
205
206 virtual ~DefaultMainLoop();
207
208 virtual void dispatch();
209
210 int _fdunlock[2];
211 private:
212
213 DefaultMutex _mutex_t;
214 DefaultTimeouts _timeouts;
215
216 DefaultMutex _mutex_w;
217 DefaultWatches _watches;
218
219 friend class DefaultTimeout;
220 friend class DefaultWatch;
221};
222
223} /* namespace DBus */
224
225#endif//__DBUSXX_EVENTLOOP_H
api.h
DXXAPI
#define DXXAPI
Definition api.h:36
DBus::DefaultMainLoop
Definition eventloop.h:201
DBus::DefaultMainLoop::DefaultWatch
friend class DefaultWatch
Definition eventloop.h:220
DBus::DefaultMainLoop::_fdunlock
int _fdunlock[2]
Definition eventloop.h:210
DBus::DefaultMainLoop::_timeouts
DefaultTimeouts _timeouts
Definition eventloop.h:214
DBus::DefaultMainLoop::dispatch
virtual void dispatch()
Definition eventloop.cpp:149
DBus::DefaultMainLoop::_mutex_t
DefaultMutex _mutex_t
Definition eventloop.h:213
DBus::DefaultMainLoop::_mutex_w
DefaultMutex _mutex_w
Definition eventloop.h:216
DBus::DefaultMainLoop::DefaultTimeout
friend class DefaultTimeout
Definition eventloop.h:219
DBus::DefaultMainLoop::_watches
DefaultWatches _watches
Definition eventloop.h:217
DBus::DefaultMainLoop::DefaultMainLoop
DefaultMainLoop()
Definition eventloop.cpp:112
DBus::DefaultMutex
Definition eventloop.h:175
DBus::DefaultMutex::lock
void lock()
Definition eventloop.cpp:102
DBus::DefaultMutex::unlock
void unlock()
Definition eventloop.cpp:107
DBus::DefaultMutex::_mutex
pthread_mutex_t _mutex
Definition eventloop.h:197
DBus::DefaultMutex::DefaultMutex
DefaultMutex()
Definition eventloop.cpp:79
DBus::DefaultTimeout::DefaultMainLoop
friend class DefaultMainLoop
Definition eventloop.h:105
DBus::DefaultTimeout::enabled
void enabled(bool e)
Definition eventloop.h:58
DBus::DefaultTimeout::_expiration
double _expiration
Definition eventloop.h:99
DBus::DefaultTimeout::_repeat
bool _repeat
Definition eventloop.h:97
DBus::DefaultTimeout::interval
void interval(int i)
Definition eventloop.h:67
DBus::DefaultTimeout::_disp
DefaultMainLoop * _disp
Definition eventloop.h:103
DBus::DefaultTimeout::_enabled
bool _enabled
Definition eventloop.h:94
DBus::DefaultTimeout::repeat
void repeat(bool r)
Definition eventloop.h:76
DBus::DefaultTimeout::DefaultTimeout
DefaultTimeout(int interval, bool repeat, DefaultMainLoop *)
Definition eventloop.cpp:44
DBus::DefaultTimeout::expired
Slot< void, DefaultTimeout & > expired
Definition eventloop.h:90
DBus::DefaultTimeout::_data
void * _data
Definition eventloop.h:101
DBus::DefaultTimeout::interval
int interval()
Definition eventloop.h:63
DBus::DefaultTimeout::repeat
bool repeat()
Definition eventloop.h:72
DBus::DefaultTimeout::data
void data(void *d)
Definition eventloop.h:85
DBus::DefaultTimeout::enabled
bool enabled()
Definition eventloop.h:54
DBus::DefaultTimeout::data
void * data()
Definition eventloop.h:81
DBus::DefaultTimeout::_interval
int _interval
Definition eventloop.h:96
DBus::DefaultWatch::state
int state()
Definition eventloop.h:141
DBus::DefaultWatch::flags
void flags(int f)
Definition eventloop.h:136
DBus::DefaultWatch::DefaultMainLoop
friend class DefaultMainLoop
Definition eventloop.h:169
DBus::DefaultWatch::_disp
DefaultMainLoop * _disp
Definition eventloop.h:167
DBus::DefaultWatch::_state
int _state
Definition eventloop.h:163
DBus::DefaultWatch::_data
void * _data
Definition eventloop.h:165
DBus::DefaultWatch::data
void data(void *d)
Definition eventloop.h:150
DBus::DefaultWatch::ready
Slot< void, DefaultWatch & > ready
Definition eventloop.h:155
DBus::DefaultWatch::_enabled
bool _enabled
Definition eventloop.h:159
DBus::DefaultWatch::descriptor
int descriptor()
Definition eventloop.h:127
DBus::DefaultWatch::_fd
int _fd
Definition eventloop.h:161
DBus::DefaultWatch::DefaultWatch
DefaultWatch(int fd, int flags, DefaultMainLoop *)
Definition eventloop.cpp:64
DBus::DefaultWatch::data
void * data()
Definition eventloop.h:146
DBus::DefaultWatch::enabled
bool enabled()
Definition eventloop.h:118
DBus::DefaultWatch::enabled
void enabled(bool e)
Definition eventloop.h:122
DBus::DefaultWatch::flags
int flags()
Definition eventloop.h:132
DBus::DefaultWatch::_flags
int _flags
Definition eventloop.h:162
DBus::Slot
Definition util.h:226
DBus
Definition connection_p.h:42
DBus::DefaultTimeouts
std::list< DefaultTimeout * > DefaultTimeouts
Definition eventloop.h:108
DBus::DefaultWatches
std::list< DefaultWatch * > DefaultWatches
Definition eventloop.h:172
util.h