repair ecore mainloop dispatcher

This commit is contained in:
Andreas Volz 2011-03-10 12:44:39 +01:00
parent cdedb019b0
commit 987d0f72a4
5 changed files with 66 additions and 76 deletions

3
README
View file

@ -1,6 +1,7 @@
Debugging Debugging
--------- ---------
To compile debugging code configure the project with the --enable-debug option. Then at runtime you may export the environment variable "DBUSXX_VERBOSE" to any value. To compile debugging code configure the project with the --enable-debug option.
Then at runtime you may export the environment variable "DBUSXX_VERBOSE" to any value.
BUGS: BUGS:

View file

@ -69,16 +69,19 @@ private:
void toggle(); void toggle();
static Eina_Bool watch_handler_read ( void*, Ecore_Fd_Handler *fdh); static Eina_Bool watch_check ( void *data, Ecore_Fd_Handler *fdh);
static Eina_Bool watch_prepare ( void *data, Ecore_Fd_Handler *fdh);
static Eina_Bool watch_handler_error ( void*, Ecore_Fd_Handler *fdh); static Eina_Bool watch_dispatch ( void *data, Ecore_Fd_Handler *fdh);
void _enable(); void _enable();
void _disable(); void _disable();
void data (Ecore::BusDispatcher *bd);
private: private:
Ecore_Fd_Handler *fd_handler_read; Ecore_Fd_Handler *fd_handler;
Ecore::BusDispatcher *_bd;
friend class BusDispatcher; friend class BusDispatcher;
}; };
@ -86,9 +89,7 @@ friend class BusDispatcher;
class DXXAPI BusDispatcher : public Dispatcher class DXXAPI BusDispatcher : public Dispatcher
{ {
public: public:
BusDispatcher() {} BusDispatcher();
void attach();
void enter() {} void enter() {}
@ -102,8 +103,10 @@ public:
void rem_watch( Watch* ); void rem_watch( Watch* );
private: static Eina_Bool dispatch ( void *data, Ecore_Fd_Handler *fdh);
static Eina_Bool check ( void *data, Ecore_Fd_Handler *fdh);
private:
}; };
} /* namespace Ecore */ } /* namespace Ecore */

View file

@ -33,7 +33,7 @@
static void _debug_log_default(const char *format, ...) static void _debug_log_default(const char *format, ...)
{ {
#ifdef DEBUG //#ifdef DEBUG
static int debug_env = getenv("DBUSXX_VERBOSE") ? 1 : 0; static int debug_env = getenv("DBUSXX_VERBOSE") ? 1 : 0;
@ -49,7 +49,7 @@ static void _debug_log_default(const char *format, ...)
va_end(args); va_end(args);
} }
#endif//DEBUG //#endif//DEBUG
} }
DBus::LogFunction DBus::debug_log = _debug_log_default; DBus::LogFunction DBus::debug_log = _debug_log_default;

View file

@ -31,10 +31,15 @@
using namespace DBus; using namespace DBus;
Dispatcher *gdispatcher = NULL;
Ecore::BusTimeout::BusTimeout( Timeout::Internal* ti) Ecore::BusTimeout::BusTimeout( Timeout::Internal* ti)
: Timeout(ti) : Timeout(ti)
{ {
_enable(); if (Timeout::enabled())
{
_enable();
}
} }
Ecore::BusTimeout::~BusTimeout() Ecore::BusTimeout::~BusTimeout()
@ -46,8 +51,14 @@ void Ecore::BusTimeout::toggle()
{ {
debug_log("ecore: timeout %p toggled (%s)", this, Timeout::enabled() ? "on":"off"); debug_log("ecore: timeout %p toggled (%s)", this, Timeout::enabled() ? "on":"off");
if(Timeout::enabled()) _enable(); if(Timeout::enabled())
else _disable(); {
_enable();
}
else
{
_disable();
}
} }
Eina_Bool Ecore::BusTimeout::timeout_handler( void *data ) Eina_Bool Ecore::BusTimeout::timeout_handler( void *data )
@ -58,7 +69,7 @@ Eina_Bool Ecore::BusTimeout::timeout_handler( void *data )
t->handle(); t->handle();
return 1; // 1 -> reshedule in ecore for next timer interval return ECORE_CALLBACK_RENEW;
} }
void Ecore::BusTimeout::_enable() void Ecore::BusTimeout::_enable()
@ -75,32 +86,8 @@ void Ecore::BusTimeout::_disable()
ecore_timer_del (_etimer); ecore_timer_del (_etimer);
} }
/*static bool watch_prepare( int *timeout )
{
debug_log("ecore: watch_prepare");
*timeout = -1;
return false;
}*/
/*static bool watch_check( )
{
debug_log("ecore: watch_check");
return true;
}*/
static bool watch_dispatch( void *data )
{
debug_log("ecore: watch_dispatch");
bool cb = true;
DBus::default_dispatcher->dispatch_pending(); //TODO: won't work in case of multiple dispatchers
return cb;
}
Ecore::BusWatch::BusWatch( Watch::Internal* wi) Ecore::BusWatch::BusWatch( Watch::Internal* wi)
: Watch(wi), fd_handler_read (NULL) : Watch(wi), fd_handler (NULL), _bd (NULL)
{ {
if (Watch::enabled()) if (Watch::enabled())
{ {
@ -121,58 +108,56 @@ void Ecore::BusWatch::toggle()
else _disable(); else _disable();
} }
Eina_Bool Ecore::BusWatch::watch_handler_read( void *data, Ecore_Fd_Handler *fdh ) Eina_Bool Ecore::BusWatch::watch_dispatch( void *data, Ecore_Fd_Handler *fdh )
{ {
Ecore::BusWatch* w = reinterpret_cast<Ecore::BusWatch*>(data); Ecore::BusWatch* w = reinterpret_cast<Ecore::BusWatch*>(data);
debug_log("ecore: watch_handler_read"); debug_log("Ecore::BusWatch watch_handler_read");
int flags = DBUS_WATCH_READABLE; int flags = flags;
watch_dispatch(NULL); if (w->flags() & DBUS_WATCH_READABLE)
ecore_main_fd_handler_active_set(w->fd_handler, ECORE_FD_READ);
if (w->flags() & DBUS_WATCH_WRITABLE)
ecore_main_fd_handler_active_set(w->fd_handler, ECORE_FD_WRITE);
w->handle(flags); w->handle(flags);
w->_bd->dispatch_pending();
return 1; return 1;
} }
/*Eina_Bool Ecore::BusWatch::watch_handler_error( void *data, Ecore_Fd_Handler *fdh )
{
//Ecore::BusWatch* w = reinterpret_cast<Ecore::BusWatch*>(data);
debug_log("ecore: watch_handler_error");
//int flags = DBUS_WATCH_ERROR;
watch_dispatch(NULL);
return 1;
}*/
void Ecore::BusWatch::_enable() void Ecore::BusWatch::_enable()
{ {
debug_log("Ecore::BusWatch::_enable()"); debug_log("Ecore::BusWatch::_enable()");
fd_handler_read = ecore_main_fd_handler_add (Watch::descriptor(), fd_handler = ecore_main_fd_handler_add (descriptor(),
ECORE_FD_READ, (Ecore_Fd_Handler_Flags) (ECORE_FD_READ | ECORE_FD_WRITE),
watch_handler_read, watch_dispatch, this,
this, NULL, NULL);
NULL, NULL);
ecore_main_fd_handler_active_set(fd_handler_read, ECORE_FD_READ);
} }
void Ecore::BusWatch::_disable() void Ecore::BusWatch::_disable()
{ {
if (fd_handler_read) if (fd_handler)
{ {
ecore_main_fd_handler_del (fd_handler_read); ecore_main_fd_handler_del (fd_handler);
fd_handler_read = NULL; fd_handler = NULL;
} }
} }
void Ecore::BusDispatcher::attach( ) void Ecore::BusWatch::data (Ecore::BusDispatcher *bd)
{ {
_bd = bd;
}
Ecore::BusDispatcher::BusDispatcher()
{
}
Eina_Bool Ecore::BusDispatcher::check ( void *data, Ecore_Fd_Handler *fdh)
{
return 0;
} }
Timeout* Ecore::BusDispatcher::add_timeout( Timeout::Internal* wi ) Timeout* Ecore::BusDispatcher::add_timeout( Timeout::Internal* wi )
@ -193,7 +178,8 @@ void Ecore::BusDispatcher::rem_timeout( Timeout* t )
Watch* Ecore::BusDispatcher::add_watch( Watch::Internal* wi ) Watch* Ecore::BusDispatcher::add_watch( Watch::Internal* wi )
{ {
Watch* w = new Ecore::BusWatch(wi); Ecore::BusWatch* w = new Ecore::BusWatch(wi);
w->data (this);
debug_log("ecore: added watch %p (%s) fd=%d flags=%d", debug_log("ecore: added watch %p (%s) fd=%d flags=%d",
w, w->enabled() ? "on":"off", w->descriptor(), w->flags() w, w->enabled() ? "on":"off", w->descriptor(), w->flags()

View file

@ -87,7 +87,7 @@ struct BusSource
static gboolean watch_prepare(GSource *source, gint *timeout) static gboolean watch_prepare(GSource *source, gint *timeout)
{ {
//debug_log("glib: watch_prepare"); debug_log("glib: watch_prepare");
*timeout = -1; *timeout = -1;
return FALSE; return FALSE;
@ -95,7 +95,7 @@ static gboolean watch_prepare(GSource *source, gint *timeout)
static gboolean watch_check(GSource *source) static gboolean watch_check(GSource *source)
{ {
//debug_log("glib: watch_check"); debug_log("glib: watch_check");
BusSource *io = (BusSource *)source; BusSource *io = (BusSource *)source;
return io->poll.revents ? TRUE : FALSE; return io->poll.revents ? TRUE : FALSE;