Free memory with dbus_free instead of free. Account for NULL signatures.
[dbus-cxx-async.git] / include / dbus-c++ / eventloop.h
blob098e82f36a413d87cb943bf274683c7db428e912
1 /*
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_EVENTLOOP_H
26 #define __DBUSXX_EVENTLOOP_H
28 #include <pthread.h>
29 #include <list>
30 #include <stdint.h>
32 #include "api.h"
33 #include "util.h"
35 namespace DBus {
38 * these Simple *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
44 class SimpleMainLoop;
46 class DBUSXXAPI SimpleTimeout
48 public:
50 SimpleTimeout(int interval, bool repeat, SimpleMainLoop *);
52 virtual ~SimpleTimeout();
54 bool enabled(){ return _enabled; }
55 void enabled(bool e){ _enabled = e; }
57 int interval(){ return _interval; }
58 void interval(int i){ _interval = i; }
60 bool repeat(){ return _repeat; }
61 void repeat(bool r){ _repeat = r; }
63 void *data(){ return _data; }
64 void data(void *d){ _data = d; }
66 Slot<void, SimpleTimeout &> expired;
68 private:
70 bool _enabled;
72 int _interval;
73 bool _repeat;
75 double _expiration;
77 void *_data;
79 SimpleMainLoop *_disp;
81 friend class SimpleMainLoop;
84 typedef std::list< SimpleTimeout *> SimpleTimeouts;
86 class DBUSXXAPI SimpleWatch
88 public:
90 SimpleWatch(int fd, int flags, SimpleMainLoop *);
92 virtual ~SimpleWatch();
94 bool enabled(){ return _enabled; }
95 void enabled(bool e){ _enabled = e; }
97 int descriptor(){ return _fd; }
99 int flags(){ return _flags; }
100 void flags(int f){ _flags = f; }
102 int state(){ return _state; }
104 void *data(){ return _data; }
105 void data(void *d){ _data = d; }
107 Slot<void, SimpleWatch &> ready;
109 private:
111 bool _enabled;
113 int _fd;
114 int _flags;
115 int _state;
117 void *_data;
119 SimpleMainLoop *_disp;
121 friend class SimpleMainLoop;
124 typedef std::list< SimpleWatch *> SimpleWatches;
126 class DBUSXXAPI SimpleMutex
128 public:
130 SimpleMutex();
132 ~SimpleMutex();
134 void lock();
136 void unlock();
138 private:
140 pthread_mutex_t _mutex;
143 class DBUSXXAPI SimpleMainLoop
145 public:
147 SimpleMainLoop(int32_t pollTimeout);
149 virtual ~SimpleMainLoop();
151 virtual void dispatch();
153 private:
155 SimpleMutex _mutex_t;
156 SimpleTimeouts _timeouts;
158 SimpleMutex _mutex_w;
159 SimpleWatches _watches;
160 int32_t _pollTimeout;
162 friend class SimpleTimeout;
163 friend class SimpleWatch;
166 } /* namespace DBus */
168 #endif//__DBUSXX_EVENTLOOP_H