eldbus: Handle correclty the last unref of a object path or conn in service callback
authorJosé Roberto de Souza <jose.souza@intel.com>
Mon, 26 Aug 2013 19:11:31 +0000 (16:11 -0300)
committerEduardo Lima (Etrunko) <eduardo.lima@intel.com>
Fri, 11 Oct 2013 19:52:41 +0000 (16:52 -0300)
This allow user remove the last reference of service object path or last
last reference of connection be removed inside of a method callback.

src/lib/eldbus_service.c

index 490b045..4c793c8 100644 (file)
@@ -1264,16 +1264,17 @@ _object_unregister(DBusConnection *conn EINA_UNUSED, void *user_data)
 }
 
 static DBusHandlerResult
-_object_handler(DBusConnection *conn EINA_UNUSED, DBusMessage *msg, void *user_data)
+_object_handler(DBusConnection *dbus_conn EINA_UNUSED, DBusMessage *msg, void *user_data)
 {
    Eldbus_Service_Object *obj;
    Eldbus_Service_Interface *iface;
    const Eldbus_Method *method;
-   Eldbus_Message *eldbus_msg;
-   Eldbus_Message *reply;
+   Eldbus_Message *eldbus_msg, *reply;
+   Eldbus_Connection *conn;
 
    obj = user_data;
    if (!obj) return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+   conn = obj->conn;
 
    DBG("Connection@%p Got message:\n"
           "  Type: %s\n"
@@ -1299,6 +1300,9 @@ _object_handler(DBusConnection *conn EINA_UNUSED, DBusMessage *msg, void *user_d
    dbus_message_ref(eldbus_msg->dbus_msg);
    dbus_message_iter_init(eldbus_msg->dbus_msg, &eldbus_msg->iterator->dbus_iterator);
 
+   eldbus_init();
+   eldbus_connection_ref(conn);
+
    if (!_have_signature(method->in, eldbus_msg))
      reply = eldbus_message_error_new(eldbus_msg, DBUS_ERROR_INVALID_SIGNATURE,
                                       "See introspectable to know the expected signature");
@@ -1318,7 +1322,10 @@ _object_handler(DBusConnection *conn EINA_UNUSED, DBusMessage *msg, void *user_d
 
    eldbus_message_unref(eldbus_msg);
    if (reply)
-     _eldbus_connection_send(obj->conn, reply, NULL, NULL, -1);
+     _eldbus_connection_send(conn, reply, NULL, NULL, -1);
+
+   eldbus_connection_unref(conn);
+   eldbus_shutdown();
 
    return DBUS_HANDLER_RESULT_HANDLED;
 }