# DBus-C++

## Desktop Communication Bus System

libdbus-c-- Documentation 0.9.0

- Files
- Data Structures
- Globals
- Main Page

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
28#include <dbus-c++/ecore-integration.h>
29
30#include <dbus/dbus.h> // for DBUS_WATCH_*
31
32 using namespace DBus;
33
34 Dispatcher *gdispatcher = NULL;
35
36 Ecore::BusTimeout::BusTimeout(Timeout::Internal *ti)
37 : Timeout(ti)
38{
39 if (Timeout::enabled())
40 {
41 _enable();
42 }
43}
44
45 Ecore::BusTimeout::~BusTimeout()
46{
47 _disable();
48}
49
50 void Ecore::BusTimeout::toggle()
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
64Eina_Bool Ecore::BusTimeout::timeout_handler(void *data)
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
75 void Ecore::BusTimeout::_enable()
76{
77 debug_log("Ecore::BusTimeout::_enable()");
78
79 _etimer = ecore_timer_add(((double)Timeout::interval()) / 1000, timeout_handler, this);
80}
81
82 void Ecore::BusTimeout::_disable()
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
98 Ecore::BusWatch::~BusWatch()
99{
100 _disable();
101}
102
103 void Ecore::BusWatch::toggle()
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
111Eina_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
130 void Ecore::BusWatch::_enable()
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
140 void Ecore::BusWatch::_disable()
141{
142 if (fd_handler)
143 {
144 ecore_main_fd_handler_del(fd_handler);
145 fd_handler = NULL;
146 }
147}
148
149 void Ecore::BusWatch::data(Ecore::BusDispatcher *bd)
150{
151 _bd = bd;
152}
153
154 Ecore::BusDispatcher::BusDispatcher()
155{
156}
157
158Eina_Bool Ecore::BusDispatcher::check(void *data, Ecore_Fd_Handler *fdh)
159{
160 return 0;
161}
162
163 Timeout *Ecore::BusDispatcher::add_timeout(Timeout::Internal *wi)
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
172 void Ecore::BusDispatcher::rem_timeout(Timeout *t)
173{
174 debug_log("ecore: removed timeout %p", t);
175
176 delete t;
177}
178
179 Watch *Ecore::BusDispatcher::add_watch(Watch::Internal *wi)
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
190 void Ecore::BusDispatcher::rem_watch(Watch *w)
191{
192 debug_log("ecore: removed watch %p", w);
193
194 delete w;
195}
DBus::Dispatcher
Definition dispatcher.h:152
DBus::Dispatcher::dispatch_pending
void dispatch_pending()
Definition dispatcher.cpp:182
DBus::Ecore::BusDispatcher
Definition ecore-integration.h:92
DBus::Ecore::BusDispatcher::rem_watch
void rem_watch(Watch *)
Definition ecore-integration.cpp:190
DBus::Ecore::BusDispatcher::check
static Eina_Bool check(void *data, Ecore_Fd_Handler *fdh)
Definition ecore-integration.cpp:158
DBus::Ecore::BusDispatcher::add_timeout
Timeout * add_timeout(Timeout::Internal *)
Definition ecore-integration.cpp:163
DBus::Ecore::BusDispatcher::BusDispatcher
BusDispatcher()
Definition ecore-integration.cpp:154
DBus::Ecore::BusDispatcher::add_watch
Watch * add_watch(Watch::Internal *)
Definition ecore-integration.cpp:179
DBus::Ecore::BusDispatcher::rem_timeout
void rem_timeout(Timeout *)
Definition ecore-integration.cpp:172
DBus::Ecore::BusTimeout
Definition ecore-integration.h:43
DBus::Ecore::BusTimeout::~BusTimeout
~BusTimeout()
Definition ecore-integration.cpp:45
DBus::Ecore::BusTimeout::_disable
void _disable()
Definition ecore-integration.cpp:82
DBus::Ecore::BusTimeout::toggle
void toggle()
Definition ecore-integration.cpp:50
DBus::Ecore::BusTimeout::BusTimeout
BusTimeout(Timeout::Internal *)
Definition ecore-integration.cpp:36
DBus::Ecore::BusTimeout::_etimer
Ecore_Timer * _etimer
Definition ecore-integration.h:59
DBus::Ecore::BusTimeout::_enable
void _enable()
Definition ecore-integration.cpp:75
DBus::Ecore::BusTimeout::timeout_handler
static Eina_Bool timeout_handler(void *)
Definition ecore-integration.cpp:64
DBus::Ecore::BusWatch
Definition ecore-integration.h:65
DBus::Ecore::BusWatch::toggle
void toggle()
Definition ecore-integration.cpp:103
DBus::Ecore::BusWatch::data
void data(Ecore::BusDispatcher *bd)
Definition ecore-integration.cpp:149
DBus::Ecore::BusWatch::_bd
Ecore::BusDispatcher * _bd
Definition ecore-integration.h:86
DBus::Ecore::BusWatch::BusWatch
BusWatch(Watch::Internal *)
Definition ecore-integration.cpp:89
DBus::Ecore::BusWatch::_enable
void _enable()
Definition ecore-integration.cpp:130
DBus::Ecore::BusWatch::watch_dispatch
static Eina_Bool watch_dispatch(void *data, Ecore_Fd_Handler *fdh)
Definition ecore-integration.cpp:111
DBus::Ecore::BusWatch::~BusWatch
~BusWatch()
Definition ecore-integration.cpp:98
DBus::Ecore::BusWatch::_disable
void _disable()
Definition ecore-integration.cpp:140
DBus::Ecore::BusWatch::fd_handler
Ecore_Fd_Handler * fd_handler
Definition ecore-integration.h:85
DBus::Timeout
Definition dispatcher.h:36
DBus::Timeout::enabled
bool enabled() const
Definition dispatcher.cpp:51
DBus::Timeout::interval
int interval() const
Gets the timeout interval.
Definition dispatcher.cpp:46
DBus::Timeout::handle
bool handle()
Calls the timeout handler for this timeout.
Definition dispatcher.cpp:56
DBus::Timeout::Timeout
Timeout(Internal *i)
DBus::Watch
Definition dispatcher.h:87
DBus::Watch::enabled
bool enabled() const
Definition dispatcher.cpp:91
DBus::Watch::flags
int flags() const
Gets flags from DBusWatchFlags indicating what conditions should be monitored on the file descriptor.
Definition dispatcher.cpp:86
DBus::Watch::Watch
Watch(Internal *i)
DBus::Watch::handle
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
DBus::Watch::descriptor
int descriptor() const
A main loop could poll this descriptor to integrate dbus-c++.
Definition dispatcher.cpp:70
gdispatcher
Dispatcher * gdispatcher
Definition ecore-integration.cpp:34
ecore-integration.h
DBus
Definition connection_p.h:42
DBus::debug_log
DXXAPI LogFunction debug_log
Definition debug.cpp:55