ecore-integration.cpp
Go to the documentation of this file.
1 /*
2  *
3  * D-Bus++ - C++ bindings for D-Bus
4  *
5  * Copyright (C) 2005-2007 Paolo Durante <shackan@gmail.com>
6  *
7  *
8  * This library is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Lesser General Public
10  * License as published by the Free Software Foundation; either
11  * version 2.1 of the License, or (at your option) any later version.
12  *
13  * This library is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  * Lesser General Public License for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with this library; if not, write to the Free Software
20  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21  *
22  */
23 
24 #ifdef HAVE_CONFIG_H
25 #include <config.h>
26 #endif
27 
29 
30 #include <dbus/dbus.h> // for DBUS_WATCH_*
31 
32 using namespace DBus;
33 
35 
36 Ecore::BusTimeout::BusTimeout(Timeout::Internal *ti)
37  : Timeout(ti)
38 {
39  if (Timeout::enabled())
40  {
41  _enable();
42  }
43 }
44 
46 {
47  _disable();
48 }
49 
51 {
52  debug_log("ecore: timeout %p toggled (%s)", this, Timeout::enabled() ? "on" : "off");
53 
54  if (Timeout::enabled())
55  {
56  _enable();
57  }
58  else
59  {
60  _disable();
61  }
62 }
63 
65 {
66  Ecore::BusTimeout *t = reinterpret_cast<Ecore::BusTimeout *>(data);
67 
68  debug_log("Ecore::BusTimeout::timeout_handler( void *data )");
69 
70  t->handle();
71 
72  return ECORE_CALLBACK_RENEW;
73 }
74 
76 {
77  debug_log("Ecore::BusTimeout::_enable()");
78 
79  _etimer = ecore_timer_add(((double)Timeout::interval()) / 1000, timeout_handler, this);
80 }
81 
83 {
84  debug_log("Ecore::BusTimeout::_disable()");
85 
86  ecore_timer_del(_etimer);
87 }
88 
89 Ecore::BusWatch::BusWatch(Watch::Internal *wi)
90  : Watch(wi), fd_handler(NULL), _bd(NULL)
91 {
92  if (Watch::enabled())
93  {
94  _enable();
95  }
96 }
97 
99 {
100  _disable();
101 }
102 
104 {
105  debug_log("ecore: watch %p toggled (%s)", this, Watch::enabled() ? "on" : "off");
106 
107  if (Watch::enabled()) _enable();
108  else _disable();
109 }
110 
111 Eina_Bool Ecore::BusWatch::watch_dispatch(void *data, Ecore_Fd_Handler *fdh)
112 {
113  Ecore::BusWatch *w = reinterpret_cast<Ecore::BusWatch *>(data);
114 
115  debug_log("Ecore::BusWatch watch_handler");
116 
117  int flags = w->flags();
118 
119  if (w->flags() & DBUS_WATCH_READABLE)
120  ecore_main_fd_handler_active_set(w->fd_handler, ECORE_FD_READ);
121  if (w->flags() & DBUS_WATCH_WRITABLE)
122  ecore_main_fd_handler_active_set(w->fd_handler, ECORE_FD_WRITE);
123 
124  w->handle(flags);
125  w->_bd->dispatch_pending();
126 
127  return 1;
128 }
129 
131 {
132  debug_log("Ecore::BusWatch::_enable()");
133 
134  fd_handler = ecore_main_fd_handler_add(descriptor(),
135  (Ecore_Fd_Handler_Flags)(ECORE_FD_READ | ECORE_FD_WRITE),
136  watch_dispatch, this,
137  NULL, NULL);
138 }
139 
141 {
142  if (fd_handler)
143  {
144  ecore_main_fd_handler_del(fd_handler);
145  fd_handler = NULL;
146  }
147 }
148 
150 {
151  _bd = bd;
152 }
153 
155 {
156 }
157 
158 Eina_Bool Ecore::BusDispatcher::check(void *data, Ecore_Fd_Handler *fdh)
159 {
160  return 0;
161 }
162 
164 {
165  Timeout *t = new Ecore::BusTimeout(wi);
166 
167  debug_log("ecore: added timeout %p (%s)", t, t->enabled() ? "on" : "off");
168 
169  return t;
170 }
171 
173 {
174  debug_log("ecore: removed timeout %p", t);
175 
176  delete t;
177 }
178 
180 {
181  Ecore::BusWatch *w = new Ecore::BusWatch(wi);
182  w->data(this);
183 
184  debug_log("ecore: added watch %p (%s) fd=%d flags=%d",
185  w, w->enabled() ? "on" : "off", w->descriptor(), w->flags()
186  );
187  return w;
188 }
189 
191 {
192  debug_log("ecore: removed watch %p", w);
193 
194  delete w;
195 }
bool enabled() const
Definition: dispatcher.cpp:51
Ecore::BusDispatcher * _bd
void dispatch_pending()
Definition: dispatcher.cpp:182
static Eina_Bool watch_dispatch(void *data, Ecore_Fd_Handler *fdh)
bool enabled() const
Definition: dispatcher.cpp:91
static gboolean watch_dispatch(GSource *source, GSourceFunc callback, gpointer data)
Ecore_Fd_Handler * fd_handler
bool handle(int flags)
Called to notify the D-Bus library when a previously-added watch is ready for reading or writing,...
Definition: dispatcher.cpp:96
int flags() const
Gets flags from DBusWatchFlags indicating what conditions should be monitored on the file descriptor.
Definition: dispatcher.cpp:86
BusTimeout(Timeout::Internal *)
Dispatcher * gdispatcher
DXXAPI LogFunction debug_log
Definition: debug.cpp:55
BusWatch(Watch::Internal *)
bool handle()
Calls the timeout handler for this timeout.
Definition: dispatcher.cpp:56
Timeout * add_timeout(Timeout::Internal *)
static Eina_Bool check(void *data, Ecore_Fd_Handler *fdh)
int descriptor() const
A main loop could poll this descriptor to integrate dbus-c++.
Definition: dispatcher.cpp:70
Watch * add_watch(Watch::Internal *)
int interval() const
Gets the timeout interval.
Definition: dispatcher.cpp:46
static Eina_Bool timeout_handler(void *)
void data(Ecore::BusDispatcher *bd)