diff options
author | pdurante <pdurante@30a43799-04e7-0310-8b2b-ea0d24f86d0e> | 2006-09-05 13:36:22 +0000 |
---|---|---|
committer | pdurante <pdurante@30a43799-04e7-0310-8b2b-ea0d24f86d0e> | 2006-09-05 13:36:22 +0000 |
commit | acfeb85b879556475d1495c4c5979b1e2aa9ee8e (patch) | |
tree | 613d5da9a9536e5266342745180ac41d75e2ad7f /include/dbus-c++/eventloop.h | |
download | dbus-c++-acfeb85b879556475d1495c4c5979b1e2aa9ee8e.tar.gz |
imported D-Bus C++ library
git-svn-id: http://dev.openwengo.org/svn/openwengo/wengophone-ng/branches/wengophone-dbus-api/libs/dbus@7382 30a43799-04e7-0310-8b2b-ea0d24f86d0e
Diffstat (limited to 'include/dbus-c++/eventloop.h')
-rw-r--r-- | include/dbus-c++/eventloop.h | 197 |
1 files changed, 197 insertions, 0 deletions
diff --git a/include/dbus-c++/eventloop.h b/include/dbus-c++/eventloop.h new file mode 100644 index 0000000..4fa22e2 --- /dev/null +++ b/include/dbus-c++/eventloop.h @@ -0,0 +1,197 @@ +/* + * + * D-Bus++ - C++ bindings for DBus + * + * Copyright (C) 2005-2006 Paolo Durante <shackan@gmail.com> + * + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + */ + + +#ifndef __DBUSXX_EVENTLOOP_H +#define __DBUSXX_EVENTLOOP_H + +#include <list> + +#include "dispatcher.h" +#include "util.h" + +namespace DBus { + +class EepleMainLoop; + +class EepleTimeout +{ +public: + + EepleTimeout( int interval, bool repeat, EepleMainLoop* ); + + virtual ~EepleTimeout(); + + bool enabled(){ return _enabled; } + void enabled(bool e){ _enabled = e; } + + int interval(){ return _interval; } + void interval(int i){ _interval = i; } + + bool repeat(){ return _repeat; } + void repeat(bool r){ _repeat = r; } + + void* data(){ return _data; } + void data(void* d){ _data = d; } + + Slot<void, EepleTimeout&> expired; + +private: + + bool _enabled; + + int _interval; + bool _repeat; + + double _expiration; + + void* _data; + + EepleMainLoop* _disp; + +friend class EepleMainLoop; +}; + +typedef std::list< EepleTimeout* > Timeouts; + +class EepleWatch +{ +public: + + EepleWatch( int fd, int flags, EepleMainLoop* ); + + virtual ~EepleWatch(); + + bool enabled(){ return _enabled; } + void enabled(bool e){ _enabled = e; } + + int descriptor(){ return _fd; } + + int flags(){ return _flags; } + void flags( int f ){ _flags = f; } + + int state(){ return _state; } + + void* data(){ return _data; } + void data(void* d){ _data = d; } + + Slot<void, EepleWatch&> ready; + +private: + + bool _enabled; + + int _fd; + int _flags; + int _state; + + void* _data; + + EepleMainLoop* _disp; + +friend class EepleMainLoop; +}; + +typedef std::list< EepleWatch* > Watches; + +class EepleMainLoop +{ +public: + + EepleMainLoop(); + + virtual ~EepleMainLoop(); + + virtual void dispatch(); + +private: + + Timeouts _timeouts; + Watches _watches; + +friend class EepleTimeout; +friend class EepleWatch; +}; + +/* the classes below are those you are going to implement if you + * want to use another event loop (Qt, Glib, boost, whatever). + * + * Don't forget to set 'default_dispatcher' accordingly! + */ + +class BusDispatcher; + +class BusTimeout : public Timeout, public EepleTimeout +{ + BusTimeout( Timeout::Internal*, BusDispatcher* ); + + void toggle(); + +friend class BusDispatcher; +}; + +class BusWatch : public Watch, public EepleWatch +{ + BusWatch( Watch::Internal*, BusDispatcher* ); + + void toggle(); + +friend class BusDispatcher; +}; + +class BusDispatcher : public Dispatcher, public EepleMainLoop +{ +public: + + BusDispatcher() : _running(false) + {} + + ~BusDispatcher() + {} + + virtual void enter(); + + virtual void leave(); + + virtual void do_iteration(); + + virtual Timeout* add_timeout( Timeout::Internal* ); + + virtual void rem_timeout( Timeout* ); + + virtual Watch* add_watch( Watch::Internal* ); + + virtual void rem_watch( Watch* ); + + void watch_ready( EepleWatch& ); + + void timeout_expired( EepleTimeout& ); + +private: + + bool _running; +}; + +} /* namespace DBus */ + +#endif//__DBUSXX_EVENTLOOP_H |