eventloop-integration.h

Go to the documentation of this file.
00001 /*
00002  *
00003  *  D-Bus++ - C++ bindings for D-Bus
00004  *
00005  *  Copyright (C) 2005-2007  Paolo Durante <shackan@gmail.com>
00006  *
00007  *
00008  *  This library is free software; you can redistribute it and/or
00009  *  modify it under the terms of the GNU Lesser General Public
00010  *  License as published by the Free Software Foundation; either
00011  *  version 2.1 of the License, or (at your option) any later version.
00012  *
00013  *  This library is distributed in the hope that it will be useful,
00014  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00015  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00016  *  Lesser General Public License for more details.
00017  *
00018  *  You should have received a copy of the GNU Lesser General Public
00019  *  License along with this library; if not, write to the Free Software
00020  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00021  *
00022  */
00023 
00024 
00025 #ifndef __DBUSXX_EVENTLOOP_INTEGRATION_H
00026 #define __DBUSXX_EVENTLOOP_INTEGRATION_H
00027 
00028 #include <errno.h>
00029 #include "api.h"
00030 #include "dispatcher.h"
00031 #include "util.h"
00032 #include "eventloop.h"
00033 
00034 namespace DBus
00035 {
00036 
00037 /*
00038  * Glue between the event loop and the DBus library
00039  */
00040 
00041 class BusDispatcher;
00042 class Pipe;
00043 
00044 class DXXAPI BusTimeout : public Timeout, public DefaultTimeout
00045 {
00046   BusTimeout(Timeout::Internal *, BusDispatcher *);
00047 
00048   void toggle();
00049 
00050   friend class BusDispatcher;
00051 };
00052 
00053 class DXXAPI BusWatch : public Watch, public DefaultWatch
00054 {
00055   BusWatch(Watch::Internal *, BusDispatcher *);
00056 
00057   void toggle();
00058 
00059   friend class BusDispatcher;
00060 };
00061 
00062 class DXXAPI BusDispatcher : public Dispatcher, public DefaultMainLoop
00063 {
00064 public:
00065   BusDispatcher();
00066 
00067   ~BusDispatcher() {}
00068 
00069   virtual void enter();
00070 
00071   virtual void leave();
00072 
00073   virtual Pipe *add_pipe(void(*handler)(const void *data, void *buffer, unsigned int nbyte), const void *data);
00074 
00075   virtual void del_pipe(Pipe *pipe);
00076 
00077   virtual void do_iteration();
00078 
00079   virtual Timeout *add_timeout(Timeout::Internal *);
00080 
00081   virtual void rem_timeout(Timeout *);
00082 
00083   virtual Watch *add_watch(Watch::Internal *);
00084 
00085   virtual void rem_watch(Watch *);
00086 
00087   void watch_ready(DefaultWatch &);
00088 
00089   void timeout_expired(DefaultTimeout &);
00090 
00091 private:
00092   bool _running;
00093   int _pipe[2];
00094   std::list <Pipe *> pipe_list;
00095 };
00096 
00097 } /* namespace DBus */
00098 
00099 #endif//__DBUSXX_EVENTLOOP_INTEGRATION_H