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 
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 
91 
92 private:
93 
94  bool _enabled;
95 
96  int _interval;
97  bool _repeat;
98 
99  double _expiration;
100 
101  void *_data;
102 
104 
105  friend class DefaultMainLoop;
106 };
107 
108 typedef std::list< DefaultTimeout *> DefaultTimeouts;
109 
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 
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 
157 private:
158 
159  bool _enabled;
160 
161  int _fd;
162  int _flags;
163  int _state;
164 
165  void *_data;
166 
168 
169  friend class DefaultMainLoop;
170 };
171 
172 typedef std::list< DefaultWatch *> DefaultWatches;
173 
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 
201 {
202 public:
203 
204  DefaultMainLoop();
205 
206  virtual ~DefaultMainLoop();
207 
208  virtual void dispatch();
209 
210  int _fdunlock[2];
211 private:
212 
215 
218 
219  friend class DefaultTimeout;
220  friend class DefaultWatch;
221 };
222 
223 } /* namespace DBus */
224 
225 #endif//__DBUSXX_EVENTLOOP_H
void flags(int f)
Definition: eventloop.h:136
std::list< DefaultTimeout * > DefaultTimeouts
Definition: eventloop.h:108
void enabled(bool e)
Definition: eventloop.h:122
void interval(int i)
Definition: eventloop.h:67
void repeat(bool r)
Definition: eventloop.h:76
std::list< DefaultWatch * > DefaultWatches
Definition: eventloop.h:172
#define DXXAPI
Definition: api.h:36
Slot< void, DefaultWatch & > ready
Definition: eventloop.h:155
Slot< void, DefaultTimeout & > expired
Definition: eventloop.h:90
void data(void *d)
Definition: eventloop.h:150
DefaultMainLoop * _disp
Definition: eventloop.h:167
void data(void *d)
Definition: eventloop.h:85
DefaultMainLoop * _disp
Definition: eventloop.h:103
DefaultMutex _mutex_w
Definition: eventloop.h:216
DefaultTimeouts _timeouts
Definition: eventloop.h:214
DefaultMutex _mutex_t
Definition: eventloop.h:213
void enabled(bool e)
Definition: eventloop.h:58
DefaultWatches _watches
Definition: eventloop.h:217
pthread_mutex_t _mutex
Definition: eventloop.h:197