dbus-cxx logo
dispatcher.h
Go to the documentation of this file.
1 /***************************************************************************
2  * Copyright (C) 2007,2008,2009,2010 by Rick L. Vinyard, Jr. *
3  * rvinyard@cs.nmsu.edu *
4  * *
5  * This file is part of the dbus-cxx library. *
6  * *
7  * The dbus-cxx library is free software; you can redistribute it and/or *
8  * modify it under the terms of the GNU General Public License *
9  * version 3 as published by the Free Software Foundation. *
10  * *
11  * The dbus-cxx library is distributed in the hope that it will be *
12  * useful, but WITHOUT ANY WARRANTY; without even the implied warranty *
13  * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
14  * General Public License for more details. *
15  * *
16  * You should have received a copy of the GNU General Public License *
17  * along with this software. If not see <http://www.gnu.org/licenses/>. *
18  ***************************************************************************/
19 #include <map>
20 #include <list>
21 #include <set>
22 #include <thread>
23 #include <mutex>
24 
25 #include <poll.h>
26 
27 #include <dbus/dbus.h>
28 #include <dbus-cxx/connection.h>
29 #include <dbus-cxx/watch.h>
30 #include <dbus-cxx/timeout.h>
31 
32 #ifndef DBUSCXX_DISPATCHER_H
33 #define DBUSCXX_DISPATCHER_H
34 
35 namespace DBus
36 {
37 
51  class Dispatcher
52  {
53  protected:
54 
55  Dispatcher(bool is_running=true);
56 
57  public:
58 
59  typedef DBusCxxPointer<Dispatcher> pointer;
60 
61  typedef DBusCxxPointer<const Dispatcher> const_pointer;
62 
63  static pointer create( bool is_running=true );
64 
65  virtual ~Dispatcher();
66 
69 
70  Connection::pointer create_connection( DBusConnection* cobj = NULL, bool is_private=false );
71 
72  Connection::pointer create_connection( BusType type, bool is_private=false );
73 
75 
76  bool add_connection( Connection::pointer connection );
77 
79 
80  bool start();
81 
82  bool stop();
83 
84  bool is_running();
85 
86  protected:
87 
88  typedef std::list<Connection::pointer> Connections;
89  Connections m_connections;
90 
91  bool m_running;
92 
93  std::thread* m_dispatch_thread;
94 
95  std::mutex m_mutex_watches;
96  std::list<Watch::pointer> m_watches;
97  std::map<int,Watch::pointer> m_watches_map;
98 
100  std::vector<int> m_exception_fd_set;
101 
102  /* socketpair for telling the thread to process data */
103  int process_fd[ 2 ];
104 
112  unsigned int m_dispatch_loop_limit;
113 
114  virtual void dispatch_thread_main();
115 
117 
119 
121 
123 
125 
127 
129 
131 
132  void wakeup_thread();
133 
137  void add_read_and_write_watches( std::vector<struct pollfd>* fds );
138 
142  void handle_read_and_write_watches( std::vector<struct pollfd>* fds );
143 
147  void dispatch_connections();
148  };
149 
150 }
151 
152 #endif
153 
std::mutex m_mutex_watches
Definition: dispatcher.h:95
bool on_remove_watch(Watch::pointer)
Definition: dispatcher.cpp:275
void on_wakeup_main(Connection::pointer)
Definition: dispatcher.cpp:326
DBusCxxPointer< Dispatcher > pointer
Definition: dispatcher.h:59
BusType
Definition: enums.h:26
DBusCxxPointer< Timeout > pointer
Definition: timeout.h:47
bool on_timeout_toggled(Timeout::pointer)
Definition: dispatcher.cpp:318
Definition: accumulators.h:24
Connection::pointer create_connection(DBusConnection *cobj=NULL, bool is_private=false)
Definition: dispatcher.cpp:58
Connection point to the DBus.
Definition: connection.h:61
DBusCxxPointer< Connection > pointer
Definition: connection.h:81
bool is_running()
Definition: dispatcher.cpp:144
std::thread * m_dispatch_thread
Definition: dispatcher.h:93
DispatchStatus
Definition: enums.h:80
void on_watch_toggled(Watch::pointer)
Definition: dispatcher.cpp:291
std::map< int, Watch::pointer > m_watches_map
Definition: dispatcher.h:97
DBusCxxPointer< Watch > pointer
Definition: watch.h:45
static pointer create(bool is_running=true)
Definition: dispatcher.cpp:48
bool stop()
Definition: dispatcher.cpp:126
void add_read_and_write_watches(std::vector< struct pollfd > *fds)
Add all read and write watch FDs to the given vector to watch.
Definition: dispatcher.cpp:185
bool m_running
Definition: dispatcher.h:91
bool start()
Definition: dispatcher.cpp:113
void wakeup_thread()
Definition: dispatcher.cpp:344
std::list< Connection::pointer > Connections
Definition: dispatcher.h:88
void dispatch_connections()
Dispatch all of our connections.
Definition: dispatcher.cpp:225
bool add_connection(Connection::pointer connection)
Definition: dispatcher.cpp:79
Type type(uint8_t)
Definition: types.h:38
int process_fd[2]
Definition: dispatcher.h:103
Handles multi-threaded dispatching of one or more connections.
Definition: dispatcher.h:51
void on_dispatch_status_changed(DispatchStatus, Connection::pointer)
Definition: dispatcher.cpp:333
void handle_read_and_write_watches(std::vector< struct pollfd > *fds)
Handle all of the read and write watches if the given FD needs to be serviced.
Definition: dispatcher.cpp:202
bool on_add_timeout(Timeout::pointer)
Definition: dispatcher.cpp:302
virtual void dispatch_thread_main()
Definition: dispatcher.cpp:149
bool on_remove_timeout(Timeout::pointer)
Definition: dispatcher.cpp:310
std::mutex m_mutex_exception_fd_set
Definition: dispatcher.h:99
std::vector< int > m_exception_fd_set
Definition: dispatcher.h:100
bool on_add_watch(Watch::pointer)
Definition: dispatcher.cpp:260
virtual ~Dispatcher()
Definition: dispatcher.cpp:53
DBusCxxPointer< const Dispatcher > const_pointer
Definition: dispatcher.h:61
unsigned int m_dispatch_loop_limit
This is the maximum number of dispatches that will occur for a connection in one iteration of the dis...
Definition: dispatcher.h:112
Dispatcher(bool is_running=true)
Definition: dispatcher.cpp:35
Connections m_connections
Definition: dispatcher.h:89
std::list< Watch::pointer > m_watches
Definition: dispatcher.h:96

Generated on Sun Mar 19 2017 14:54:27 for dbus-cxx by doxygen 1.8.8