dbus-cxx logo

dispatcher.h

Go to the documentation of this file.
00001 /***************************************************************************
00002  *   Copyright (C) 2007,2008,2009,2010 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 #include <map>
00020 #include <list>
00021 #include <set>
00022 
00023 #include <sys/select.h>
00024 
00025 #include <dbus/dbus.h>
00026 #include <dbus-cxx/connection.h>
00027 #include <dbus-cxx/watch.h>
00028 #include <dbus-cxx/timeout.h>
00029 
00030 #ifndef DBUSCXX_DISPATCHER_H
00031 #define DBUSCXX_DISPATCHER_H
00032 
00033 namespace DBus
00034 {
00035 
00049   class Dispatcher
00050   {
00051     protected:
00052 
00053       Dispatcher(bool is_running=true);
00054 
00055     public:
00056       
00057       typedef DBusCxxPointer<Dispatcher> pointer;
00058 
00059       typedef DBusCxxPointer<const Dispatcher> const_pointer;
00060 
00061       static pointer create( bool is_running=true );
00062 
00063       virtual ~Dispatcher();
00064       
00067 
00068       Connection::pointer create_connection( DBusConnection* cobj = NULL, bool is_private=false );
00069 
00070       Connection::pointer create_connection( BusType type, bool is_private=false );
00071 
00072       Connection::pointer create_connection( const Connection& other );
00073 
00074       bool add_connection( Connection::pointer connection );
00075 
00077 
00078       bool start();
00079       
00080       bool stop();
00081       
00082       bool is_running();
00083 
00084       const struct timeval& responsiveness();
00085       
00086       void set_responsiveness( const struct timeval& r );
00087       
00088       void set_responsiveness( time_t sec, suseconds_t usec );
00089       
00090     protected:
00091       
00092       typedef std::list<Connection::pointer> Connections;
00093       Connections m_connections;
00094       
00095       bool m_running;
00096       
00097       pthread_t m_dispatch_thread;
00098       pthread_t m_watch_thread;
00099 
00100       pthread_mutex_t m_mutex_read_watches;
00101       std::map<int, Watch::pointer> m_read_watches;
00102       std::set<int> m_enabled_read_fds;
00103       fd_set m_read_fd_set;
00104       int m_maximum_read_fd;
00105 
00106       void build_read_fd_set();
00107       
00108       pthread_mutex_t m_mutex_write_watches;
00109       std::map<int, Watch::pointer> m_write_watches;
00110       std::set<int> m_enabled_write_fds;
00111       fd_set m_write_fd_set;
00112       int m_maximum_write_fd;
00113 
00114       void build_write_fd_set();
00115       
00116       fd_set m_exception_fd_set;
00117       
00118       pthread_mutex_t m_mutex_exception_fd_set;
00119       
00120       struct timeval m_responsiveness;
00121 
00129       unsigned int m_dispatch_loop_limit;
00130       
00131       bool m_initiate_processing;      
00132       pthread_cond_t m_cond_initiate_processing;
00133       pthread_mutex_t m_mutex_initiate_processing;
00134       
00135       virtual void dispatch_thread_main();
00136       
00137       void watch_thread_main();
00138       
00145       static void* proxy_dispatch_thread_main(void*);
00146       
00153       static void* proxy_watch_thread_main(void*);
00154       
00155       bool on_add_watch(Watch::pointer);
00156       
00157       bool on_remove_watch(Watch::pointer);
00158       
00159       bool on_watch_toggled(Watch::pointer);
00160       
00161       bool on_add_timeout(Timeout::pointer);
00162       
00163       bool on_remove_timeout(Timeout::pointer);
00164       
00165       bool on_timeout_toggled(Timeout::pointer);
00166       
00167       void on_wakeup_main(Connection::pointer);
00168       
00169       void on_dispatch_status_changed(DispatchStatus, Connection::pointer);
00170   };
00171 
00172 }
00173 
00174 #endif
00175 

Generated on Thu Mar 18 09:30:54 2010 for dbus-cxx by doxygen 1.6.1