From 3c8076fa53dd089ef7fdbea01c6c265fe0605364 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Roberto=20de=20Souza?= Date: Tue, 11 Dec 2012 19:50:20 +0000 Subject: [PATCH] edbus: Add edbus_private_connection_get() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Patch by: José Roberto de Souza SVN revision: 80691 --- legacy/edbus/src/lib/edbus_connection.h | 16 +++++++- legacy/edbus/src/lib/edbus_core.c | 54 ++++++++++++++++--------- 2 files changed, 48 insertions(+), 22 deletions(-) diff --git a/legacy/edbus/src/lib/edbus_connection.h b/legacy/edbus/src/lib/edbus_connection.h index 811854db72..928b137a4f 100644 --- a/legacy/edbus/src/lib/edbus_connection.h +++ b/legacy/edbus/src/lib/edbus_connection.h @@ -18,8 +18,9 @@ typedef enum #define EDBUS_TIMEOUT_INFINITE ((int) 0x7fffffff) /** - * @brief Establish a connection to bus and integrate it with the ecore main - * loop. + * Establish a connection to bus and integrate it with the ecore main + * loop, if already exist a connection of given type return it and increase + * reference. * * @param type type of connection e.g EDBUS_CONNECTION_TYPE_SESSION, * EDBUS_CONNECTION_TYPE_SYSTEM or EDBUS_CONNECTION_TYPE_STARTER @@ -28,6 +29,17 @@ typedef enum */ EAPI EDBus_Connection *edbus_connection_get(EDBus_Connection_Type type); +/** + * Always create and establish a new connection to bus and integrate it with + * the ecore main loop. + * + * @param type type of connection e.g EDBUS_CONNECTION_TYPE_SESSION, + * EDBUS_CONNECTION_TYPE_SYSTEM or EDBUS_CONNECTION_TYPE_STARTER + * + * @return connection with bus + */ +EAPI EDBus_Connection *edbus_private_connection_get(EDBus_Connection_Type type); + /** * @brief Increment connection reference count. * diff --git a/legacy/edbus/src/lib/edbus_core.c b/legacy/edbus/src/lib/edbus_core.c index c7618bbe4f..cfbba04457 100644 --- a/legacy/edbus/src/lib/edbus_core.c +++ b/legacy/edbus/src/lib/edbus_core.c @@ -921,25 +921,14 @@ edbus_connection_setup(EDBus_Connection *conn) conn); } -EAPI EDBus_Connection * -edbus_connection_get(EDBus_Connection_Type type) +static EDBus_Connection * +_connection_get(EDBus_Connection_Type type) { EDBus_Connection *conn; DBusError err; - DBG("Getting connection with type %d", type); - - if ((type < EDBUS_CONNECTION_TYPE_SESSION) || - (type > EDBUS_CONNECTION_TYPE_STARTER)) - return NULL; - - conn = shared_connections[type - 1]; - if (conn) - { - DBG("Connection with type %d exists at %p; reffing and returning", - type, conn); - return edbus_connection_ref(conn); - } + EINA_SAFETY_ON_FALSE_RETURN_VAL((type < EDBUS_CONNECTION_TYPE_LAST) && + (type > EDBUS_CONNECTION_TYPE_UNKNOWN), NULL); conn = calloc(1, sizeof(EDBus_Connection)); EINA_SAFETY_ON_NULL_RETURN_VAL(conn, NULL); @@ -952,20 +941,44 @@ edbus_connection_get(EDBus_Connection_Type type) ERR("Error connecting to bus: %s", err.message); return NULL; } + edbus_connection_setup(conn); - conn->type = type; - shared_connections[type - 1] = conn; - conn->refcount = 1; EINA_MAGIC_SET(conn, EDBUS_CONNECTION_MAGIC); - conn->names = eina_hash_string_superfast_new(NULL); DBG("Returned new connection at %p", conn); return conn; } +EAPI EDBus_Connection * +edbus_private_connection_get(EDBus_Connection_Type type) +{ + return _connection_get(type); +} + +EAPI EDBus_Connection * +edbus_connection_get(EDBus_Connection_Type type) +{ + EDBus_Connection *conn; + + DBG("Getting connection with type %d", type); + conn = shared_connections[type - 1]; + if (conn) + { + DBG("Connection with type %d exists at %p; reffing and returning", + type, conn); + return edbus_connection_ref(conn); + } + + conn = _connection_get(type); + EINA_SAFETY_ON_NULL_RETURN_VAL(conn, NULL); + shared_connections[type - 1] = conn; + + return conn; +} + EAPI EDBus_Connection * edbus_connection_ref(EDBus_Connection *conn) { @@ -1072,7 +1085,8 @@ _edbus_connection_unref(EDBus_Connection *conn) edbus_data_del_all(&conn->data); if (conn->idler) ecore_idler_del(conn->idler); - shared_connections[conn->type - 1] = NULL; + if (shared_connections[conn->type - 1] == conn) + shared_connections[conn->type - 1] = NULL; free(conn); }