ecore-integration.cpp
Go to the documentation of this file.
00001 /* 00002 * 00003 * D-Bus++ - C++ bindings for D-Bus 00004 * 00005 * Copyright (C) 2005-2007 Paolo Durante <shackan@gmail.com> 00006 * 00007 * 00008 * This library is free software; you can redistribute it and/or 00009 * modify it under the terms of the GNU Lesser General Public 00010 * License as published by the Free Software Foundation; either 00011 * version 2.1 of the License, or (at your option) any later version. 00012 * 00013 * This library is distributed in the hope that it will be useful, 00014 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00015 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00016 * Lesser General Public License for more details. 00017 * 00018 * You should have received a copy of the GNU Lesser General Public 00019 * License along with this library; if not, write to the Free Software 00020 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00021 * 00022 */ 00023 00024 #ifdef HAVE_CONFIG_H 00025 #include <config.h> 00026 #endif 00027 00028 #include <dbus-c++/ecore-integration.h> 00029 00030 #include <dbus/dbus.h> // for DBUS_WATCH_* 00031 00032 using namespace DBus; 00033 00034 Dispatcher *gdispatcher = NULL; 00035 00036 Ecore::BusTimeout::BusTimeout(Timeout::Internal *ti) 00037 : Timeout(ti) 00038 { 00039 if (Timeout::enabled()) 00040 { 00041 _enable(); 00042 } 00043 } 00044 00045 Ecore::BusTimeout::~BusTimeout() 00046 { 00047 _disable(); 00048 } 00049 00050 void Ecore::BusTimeout::toggle() 00051 { 00052 debug_log("ecore: timeout %p toggled (%s)", this, Timeout::enabled() ? "on" : "off"); 00053 00054 if (Timeout::enabled()) 00055 { 00056 _enable(); 00057 } 00058 else 00059 { 00060 _disable(); 00061 } 00062 } 00063 00064 Eina_Bool Ecore::BusTimeout::timeout_handler(void *data) 00065 { 00066 Ecore::BusTimeout *t = reinterpret_cast<Ecore::BusTimeout *>(data); 00067 00068 debug_log("Ecore::BusTimeout::timeout_handler( void *data )"); 00069 00070 t->handle(); 00071 00072 return ECORE_CALLBACK_RENEW; 00073 } 00074 00075 void Ecore::BusTimeout::_enable() 00076 { 00077 debug_log("Ecore::BusTimeout::_enable()"); 00078 00079 _etimer = ecore_timer_add(((double)Timeout::interval()) / 1000, timeout_handler, this); 00080 } 00081 00082 void Ecore::BusTimeout::_disable() 00083 { 00084 debug_log("Ecore::BusTimeout::_disable()"); 00085 00086 ecore_timer_del(_etimer); 00087 } 00088 00089 Ecore::BusWatch::BusWatch(Watch::Internal *wi) 00090 : Watch(wi), fd_handler(NULL), _bd(NULL) 00091 { 00092 if (Watch::enabled()) 00093 { 00094 _enable(); 00095 } 00096 } 00097 00098 Ecore::BusWatch::~BusWatch() 00099 { 00100 _disable(); 00101 } 00102 00103 void Ecore::BusWatch::toggle() 00104 { 00105 debug_log("ecore: watch %p toggled (%s)", this, Watch::enabled() ? "on" : "off"); 00106 00107 if (Watch::enabled()) _enable(); 00108 else _disable(); 00109 } 00110 00111 Eina_Bool Ecore::BusWatch::watch_dispatch(void *data, Ecore_Fd_Handler *fdh) 00112 { 00113 Ecore::BusWatch *w = reinterpret_cast<Ecore::BusWatch *>(data); 00114 00115 debug_log("Ecore::BusWatch watch_handler"); 00116 00117 int flags = w->flags(); 00118 00119 if (w->flags() & DBUS_WATCH_READABLE) 00120 ecore_main_fd_handler_active_set(w->fd_handler, ECORE_FD_READ); 00121 if (w->flags() & DBUS_WATCH_WRITABLE) 00122 ecore_main_fd_handler_active_set(w->fd_handler, ECORE_FD_WRITE); 00123 00124 w->handle(flags); 00125 w->_bd->dispatch_pending(); 00126 00127 return 1; 00128 } 00129 00130 void Ecore::BusWatch::_enable() 00131 { 00132 debug_log("Ecore::BusWatch::_enable()"); 00133 00134 fd_handler = ecore_main_fd_handler_add(descriptor(), 00135 (Ecore_Fd_Handler_Flags)(ECORE_FD_READ | ECORE_FD_WRITE), 00136 watch_dispatch, this, 00137 NULL, NULL); 00138 } 00139 00140 void Ecore::BusWatch::_disable() 00141 { 00142 if (fd_handler) 00143 { 00144 ecore_main_fd_handler_del(fd_handler); 00145 fd_handler = NULL; 00146 } 00147 } 00148 00149 void Ecore::BusWatch::data(Ecore::BusDispatcher *bd) 00150 { 00151 _bd = bd; 00152 } 00153 00154 Ecore::BusDispatcher::BusDispatcher() 00155 { 00156 } 00157 00158 Eina_Bool Ecore::BusDispatcher::check(void *data, Ecore_Fd_Handler *fdh) 00159 { 00160 return 0; 00161 } 00162 00163 Timeout *Ecore::BusDispatcher::add_timeout(Timeout::Internal *wi) 00164 { 00165 Timeout *t = new Ecore::BusTimeout(wi); 00166 00167 debug_log("ecore: added timeout %p (%s)", t, t->enabled() ? "on" : "off"); 00168 00169 return t; 00170 } 00171 00172 void Ecore::BusDispatcher::rem_timeout(Timeout *t) 00173 { 00174 debug_log("ecore: removed timeout %p", t); 00175 00176 delete t; 00177 } 00178 00179 Watch *Ecore::BusDispatcher::add_watch(Watch::Internal *wi) 00180 { 00181 Ecore::BusWatch *w = new Ecore::BusWatch(wi); 00182 w->data(this); 00183 00184 debug_log("ecore: added watch %p (%s) fd=%d flags=%d", 00185 w, w->enabled() ? "on" : "off", w->descriptor(), w->flags() 00186 ); 00187 return w; 00188 } 00189 00190 void Ecore::BusDispatcher::rem_watch(Watch *w) 00191 { 00192 debug_log("ecore: removed watch %p", w); 00193 00194 delete w; 00195 }