Free memory with dbus_free instead of free. Account for NULL signatures.
[dbus-cxx-async.git] / src / dispatcher_p.h
bloba3c088c088a61a506b4c9ce01578a7f131b37cdf
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_DISPATCHER_P_H
26 #define __DBUSXX_DISPATCHER_P_H
28 #ifdef HAVE_CONFIG_H
29 #include <config.h>
30 #endif
32 #include <set>
33 #include <dbus-c++/dispatcher.h>
35 #include <dbus/dbus.h>
37 #include "internalerror.h"
39 namespace DBus {
41 class DBUSXXAPILOCAL DispatcherCache
43 public:
44 typedef std::set<Dispatcher*> Collection;
46 static RefPtrI<DispatcherCache> getInstance()
48 static RefPtrI<DispatcherCache> _cache(new DispatcherCache());
50 return _cache;
53 static void lock()
55 getGuard()->lock();
58 static void unlock()
60 getGuard()->unlock();
63 void insert(Dispatcher* d)
65 _instances.insert(d);
68 void erase(Dispatcher* d)
70 _instances.erase(d);
73 bool exists(Dispatcher* d) const
75 return _instances.find(d) != _instances.end();
78 Collection::size_type size() const
80 return _instances.size();
83 private:
85 static RefPtrI<SimpleMutex> getGuard()
87 static RefPtrI<SimpleMutex> _guard(new SimpleMutex());
89 return _guard;
92 DispatcherCache() : _instances() {}
93 ~DispatcherCache() {}
95 Collection _instances;
97 template<typename> friend class RefPtrI;
101 struct DBUSXXAPILOCAL Dispatcher::Private
103 static dbus_bool_t on_add_watch(DBusWatch *watch, void *data);
105 static void on_rem_watch(DBusWatch *watch, void *data);
107 static void on_toggle_watch(DBusWatch *watch, void *data);
109 static dbus_bool_t on_add_timeout(DBusTimeout *timeout, void *data);
111 static void on_rem_timeout(DBusTimeout *timeout, void *data);
113 static void on_toggle_timeout(DBusTimeout *timeout, void *data);
116 } /* namespace DBus */
118 #endif//__DBUSXX_DISPATCHER_P_H