edbus: Handle 'unref signal handler inside of own callback' with ref and unref

This way is much simpler and doesn't generate many events when main loop
is quit inside of a signal handler callback.

Patch by: José Roberto de Souza  <zehortigoza@profusion.mobi>



SVN revision: 80683
This commit is contained in:
José Roberto de Souza 2012-12-11 19:49:42 +00:00 committed by Lucas De Marchi
parent 7115dfa939
commit d5dab6de7b
3 changed files with 10 additions and 20 deletions

View File

@ -824,6 +824,7 @@ cb_signal_dispatcher(EDBus_Connection *conn, DBusMessage *msg)
char *arg_msg;
EDBus_Message *edbus_msg;
Signal_Argument *arg;
Eina_Inlist *safe_list;
edbus_msg = edbus_message_new(EINA_FALSE);
EINA_SAFETY_ON_NULL_RETURN(edbus_msg);
@ -831,10 +832,12 @@ cb_signal_dispatcher(EDBus_Connection *conn, DBusMessage *msg)
edbus_msg->dbus_msg = dbus_message_ref(msg);
dbus_message_iter_init(edbus_msg->dbus_msg,
&edbus_msg->iterator->dbus_iterator);
conn->running_signal = EINA_TRUE;
edbus_connection_ref(conn);
EINA_INLIST_FOREACH(conn->signal_handlers, sh)
{
sh->refcount++;
if (sh->dangling) continue;
if (sh->sender)
{
if (sh->bus)
@ -877,8 +880,11 @@ next_sh:
type = 0;
}
EINA_INLIST_FOREACH_SAFE(conn->signal_handlers, safe_list, sh)
edbus_signal_handler_unref(sh);
edbus_message_unref(edbus_msg);
conn->running_signal = EINA_FALSE;
edbus_connection_unref(conn);
}
static DBusHandlerResult

View File

@ -59,7 +59,6 @@ struct _EDBus_Connection
Eina_Inlist *fd_handlers;
Eina_Inlist *timeouts;
Ecore_Idler *idler;
Eina_Bool running_signal;
EDBus_Connection_Context_Event event_handlers[EDBUS_CONNECTION_EVENT_LAST];
Eina_Inlist *root_objs;//service_object
};

View File

@ -206,14 +206,6 @@ cleanup_create_strbuf:
return NULL;
}
static Eina_Bool
signal_handler_deleter(void *data)
{
EDBus_Signal_Handler *handler = data;
_edbus_signal_handler_del(handler);
return ECORE_CALLBACK_CANCEL;
}
static void
_edbus_signal_handler_clean(EDBus_Signal_Handler *handler)
{
@ -221,10 +213,6 @@ _edbus_signal_handler_clean(EDBus_Signal_Handler *handler)
if (handler->dangling) return;
edbus_connection_signal_handler_del(handler->conn, handler);
if (handler->bus)
edbus_connection_name_owner_monitor(handler->conn, handler->bus,
EINA_FALSE);
dbus_error_init(&err);
dbus_bus_remove_match(handler->conn->dbus_conn,
eina_strbuf_string_get(handler->match), &err);
@ -239,6 +227,7 @@ _edbus_signal_handler_del(EDBus_Signal_Handler *handler)
DBG("handler %p, refcount=%d, conn=%p %s",
handler, handler->refcount, handler->conn, handler->sender);
edbus_cbs_free_dispatch(&(handler->cbs_free), handler);
edbus_connection_signal_handler_del(handler->conn, handler);
EINA_MAGIC_SET(handler, EINA_MAGIC_NONE);
/* after cbs_free dispatch these shouldn't exit, error if they do */
@ -277,11 +266,7 @@ edbus_signal_handler_unref(EDBus_Signal_Handler *handler)
if (handler->refcount > 0) return;
_edbus_signal_handler_clean(handler);
if (handler->conn->running_signal)
ecore_idler_add(signal_handler_deleter, handler);
else
_edbus_signal_handler_del(handler);
_edbus_signal_handler_del(handler);
}
EAPI void