dbus-cxx logo

dispatcher.h

Go to the documentation of this file.
00001 /***************************************************************************
00002  *   Copyright (C) 2007,2008,2009 by Rick L. Vinyard, Jr.                  *
00003  *   rvinyard@cs.nmsu.edu                                                  *
00004  *                                                                         *
00005  *   This file is part of the dbus-cxx library.                            *
00006  *                                                                         *
00007  *   The dbus-cxx library is free software; you can redistribute it and/or *
00008  *   modify it under the terms of the GNU General Public License           *
00009  *   version 3 as published by the Free Software Foundation.               *
00010  *                                                                         *
00011  *   The dbus-cxx library is distributed in the hope that it will be       *
00012  *   useful, but WITHOUT ANY WARRANTY; without even the implied warranty   *
00013  *   of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU   *
00014  *   General Public License for more details.                              *
00015  *                                                                         *
00016  *   You should have received a copy of the GNU General Public License     *
00017  *   along with this software. If not see <http://www.gnu.org/licenses/>.  *
00018  ***************************************************************************/
00019 #ifndef __DBUSXX_DISPATCHER_H
00020 #define __DBUSXX_DISPATCHER_H
00021 
00022 #include <map>
00023 #include <list>
00024 #include <set>
00025 
00026 #include <sys/select.h>
00027 
00028 #include <dbus/dbus.h>
00029 #include <dbus-cxx/connection.h>
00030 #include <dbus-cxx/watch.h>
00031 #include <dbus-cxx/timeout.h>
00032 
00033 namespace DBus
00034 {
00035 
00049   class Dispatcher
00050   {
00051     public:
00052 
00053       Dispatcher();
00054 
00055       virtual ~Dispatcher();
00056 
00059 
00060       Connection::pointer create_connection( DBusConnection* cobj = NULL, bool is_private=false );
00061 
00062       Connection::pointer create_connection( BusType type, bool is_private=false );
00063 
00064       Connection::pointer create_connection( const Connection& other );
00065 
00066       bool add_connection( Connection::pointer connection );
00067 
00069 
00070       bool start();
00071       
00072       bool stop();
00073       
00074       bool is_running();
00075 
00076       const struct timeval& responsiveness();
00077       
00078       void set_responsiveness( const struct timeval& r );
00079       
00080       void set_responsiveness( time_t sec, suseconds_t usec );
00081       
00082     protected:
00083       
00084       typedef std::list<Connection::pointer> Connections;
00085       Connections m_connections;
00086       
00087       bool m_running;
00088       
00089       pthread_t m_dispatch_thread;
00090       pthread_t m_watch_thread;
00091 
00092       pthread_mutex_t m_mutex_read_watches;
00093       std::map<int, Watch::pointer> m_read_watches;
00094       std::set<int> m_enabled_read_fds;
00095       fd_set m_read_fd_set;
00096       int m_maximum_read_fd;
00097 
00098       void build_read_fd_set();
00099       
00100       pthread_mutex_t m_mutex_write_watches;
00101       std::map<int, Watch::pointer> m_write_watches;
00102       std::set<int> m_enabled_write_fds;
00103       fd_set m_write_fd_set;
00104       int m_maximum_write_fd;
00105 
00106       void build_write_fd_set();
00107       
00108       fd_set m_exception_fd_set;
00109       
00110       pthread_mutex_t m_mutex_exception_fd_set;
00111       
00112       struct timeval m_responsiveness;
00113 
00121       unsigned int m_dispatch_loop_limit;
00122       
00123       bool m_initiate_processing;      
00124       pthread_cond_t m_cond_initiate_processing;
00125       pthread_mutex_t m_mutex_initiate_processing;
00126       
00127       void dispatch_thread_main();
00128       
00129       void watch_thread_main();
00130       
00137       static void* proxy_dispatch_thread_main(void*);
00138       
00145       static void* proxy_watch_thread_main(void*);
00146       
00147       bool on_add_watch(Watch::pointer);
00148       
00149       bool on_remove_watch(Watch::pointer);
00150       
00151       bool on_watch_toggled(Watch::pointer);
00152       
00153       bool on_add_timeout(Timeout::pointer);
00154       
00155       bool on_remove_timeout(Timeout::pointer);
00156       
00157       bool on_timeout_toggled(Timeout::pointer);
00158       
00159       void on_wakeup_main(Connection::pointer);
00160       
00161       void on_dispatch_status_changed(DispatchStatus, Connection::pointer);
00162   };
00163 
00164 }
00165 
00166 #endif

Generated on Thu May 28 16:50:50 2009 for dbus-cxx by doxygen 1.5.7.1