Enlightenment CVS committal Author : rephorm Project : e17 Module : proto
Dir : e17/proto/e_dbus/src/lib/dbus Modified Files: .cvsignore E_DBus.h e_dbus.c e_dbus_interfaces.c e_dbus_message.c e_dbus_methods.c e_dbus_object.c e_dbus_signal.c Added Files: e_dbus_private.h Log Message: use E_DBus_Connection in the api instead of DBusConnection add refcount of E_DBus_Connection share connections to the system/session bus (e_dbus_bus_get() will return a ref if it is has one) =================================================================== RCS file: /cvs/e/e17/proto/e_dbus/src/lib/dbus/.cvsignore,v retrieving revision 1.2 retrieving revision 1.3 diff -u -3 -r1.2 -r1.3 --- .cvsignore 15 Mar 2007 09:04:47 -0000 1.2 +++ .cvsignore 22 Mar 2007 01:44:12 -0000 1.3 @@ -3,6 +3,7 @@ Makefile.in .libs e_dbus.lo +e_dbus_interfaces.lo e_dbus_message.lo e_dbus_methods.lo e_dbus_object.lo =================================================================== RCS file: /cvs/e/e17/proto/e_dbus/src/lib/dbus/E_DBus.h,v retrieving revision 1.3 retrieving revision 1.4 diff -u -3 -r1.3 -r1.4 --- E_DBus.h 20 Mar 2007 06:34:13 -0000 1.3 +++ E_DBus.h 22 Mar 2007 01:44:12 -0000 1.4 @@ -25,13 +25,15 @@ /* setting up the connection */ -DBusConnection *e_dbus_bus_get(DBusBusType type); -void e_dbus_connection_close(DBusConnection *conn); +E_DBus_Connection *e_dbus_bus_get(DBusBusType type); -int e_dbus_connection_setup(DBusConnection *conn); +void e_dbus_connection_ref(E_DBus_Connection *conn); +void e_dbus_connection_unref(E_DBus_Connection *conn); + +E_DBus_Connection *e_dbus_connection_setup(DBusConnection *conn); /* receiving method calls */ -E_DBus_Object *e_dbus_object_add(DBusConnection *conn, const char *object_path, void *data); +E_DBus_Object *e_dbus_object_add(E_DBus_Connection *conn, const char *object_path, void *data); void e_dbus_object_free(E_DBus_Object *obj); int e_dbus_object_method_add(E_DBus_Object *obj, const char *interface, const char *member, const char *signature, const char *reply_signature, E_DBus_Object_Method_Cb func); @@ -39,55 +41,55 @@ /* sending method calls */ -DBusPendingCall *e_dbus_message_send(DBusConnection *conn, DBusMessage *msg, E_DBus_Method_Return_Cb cb_return, int timeout, void *data); +DBusPendingCall *e_dbus_message_send(E_DBus_Connection *conn, DBusMessage *msg, E_DBus_Method_Return_Cb cb_return, int timeout, void *data); /* signal receiving */ int e_dbus_signal_init(void); void e_dbus_signal_shutdown(void); -E_DBus_Signal_Handler *e_dbus_signal_handler_add(DBusConnection *conn, const char *sender, const char *path, const char *interface, const char *member, E_DBus_Signal_Cb cb_signal, void *data); +E_DBus_Signal_Handler *e_dbus_signal_handler_add(E_DBus_Connection *conn, const char *sender, const char *path, const char *interface, const char *member, E_DBus_Signal_Cb cb_signal, void *data); /* standard dbus method calls */ -void e_dbus_request_name(DBusConnection *conn, const char *name, +void e_dbus_request_name(E_DBus_Connection *conn, const char *name, unsigned int flags, E_DBus_Method_Return_Cb cb_return, void *data); -void e_dbus_release_name(DBusConnection *conn, const char *name, +void e_dbus_release_name(E_DBus_Connection *conn, const char *name, E_DBus_Method_Return_Cb cb_return, void *data); -void e_dbus_get_name_owner(DBusConnection *conn, const char *name, +void e_dbus_get_name_owner(E_DBus_Connection *conn, const char *name, E_DBus_Method_Return_Cb cb_return, void *data); -void e_dbus_list_names(DBusConnection *conn, +void e_dbus_list_names(E_DBus_Connection *conn, E_DBus_Method_Return_Cb cb_return, void *data); -void e_dbus_list_activatable_names(DBusConnection *conn, +void e_dbus_list_activatable_names(E_DBus_Connection *conn, E_DBus_Method_Return_Cb cb_return, void *data); -void e_dbus_name_has_owner(DBusConnection *conn, const char *name, +void e_dbus_name_has_owner(E_DBus_Connection *conn, const char *name, E_DBus_Method_Return_Cb cb_return, void *data); -void e_dbus_start_service_by_name(DBusConnection *conn, const char *name, +void e_dbus_start_service_by_name(E_DBus_Connection *conn, const char *name, E_DBus_Method_Return_Cb cb_return, void *data); /* standard methods calls on objects */ -void e_dbus_peer_ping(DBusConnection *conn, const char *destination, +void e_dbus_peer_ping(E_DBus_Connection *conn, const char *destination, const char *path, E_DBus_Method_Return_Cb cb_return, void *data); -void e_dbus_peer_get_machine_id(DBusConnection *conn, +void e_dbus_peer_get_machine_id(E_DBus_Connection *conn, const char *destination, const char *path, E_DBus_Method_Return_Cb cb_return, void *data); -void e_dbus_properties_get(DBusConnection *conn, const char *destination, +void e_dbus_properties_get(E_DBus_Connection *conn, const char *destination, const char *path, const char *interface, const char *property, E_DBus_Method_Return_Cb cb_return, void *data); -void e_dbus_properties_set(DBusConnection *conn, const char *destination, +void e_dbus_properties_set(E_DBus_Connection *conn, const char *destination, const char *path, const char *interface, const char *property, int value_type, void *value, E_DBus_Method_Return_Cb cb_return, =================================================================== RCS file: /cvs/e/e17/proto/e_dbus/src/lib/dbus/e_dbus.c,v retrieving revision 1.2 retrieving revision 1.3 diff -u -3 -r1.2 -r1.3 --- e_dbus.c 15 Mar 2007 09:18:54 -0000 1.2 +++ e_dbus.c 22 Mar 2007 01:44:12 -0000 1.3 @@ -1,4 +1,5 @@ #include "E_DBus.h" +#include "e_dbus_private.h" #include <stdbool.h> #include <unistd.h> @@ -23,21 +24,11 @@ static int init = 0; int E_DBUS_EVENT_SIGNAL = 0; +static E_DBus_Connection *shared_connections[2] = {NULL, NULL}; + typedef struct E_DBus_Handler_Data E_DBus_Handler_Data; typedef struct E_DBus_Timeout_Data E_DBus_Timeout_Data; -struct E_DBus_Connection -{ - DBusConnection *conn; - char *conn_name; - - Ecore_List *fd_handlers; - Ecore_List *timeouts; - - Ecore_Idler *idler; - - int refcount; -}; struct E_DBus_Handler_Data { @@ -167,6 +158,9 @@ ecore_timer_del(timer); ecore_list_destroy(cd->timeouts); + if (cd->shared_type != -1) + shared_connections[cd->shared_type] = NULL; + free(cd); } @@ -401,12 +395,23 @@ * Retrieve a connection to the bus and integrate it with the ecore main loop. * @param type the type of bus to connect to, e.g. DBUS_BUS_SYSTEM or DBUS_BUS_SESSION */ -DBusConnection * +E_DBus_Connection * e_dbus_bus_get(DBusBusType type) { DBusError err; + E_DBus_Connection *econn; DBusConnection *conn; + /* each app only needs a single connection to either bus */ + if (type == DBUS_BUS_SYSTEM || type == DBUS_BUS_SESSION) + { + if (shared_connections[type]) + { + e_dbus_connection_ref(shared_connections[type]); + return shared_connections[type]; + } + } + dbus_error_init(&err); conn = dbus_bus_get_private(type, &err); @@ -417,15 +422,22 @@ return NULL; } - if (!e_dbus_connection_setup(conn)) + econn = e_dbus_connection_setup(conn); + if (!econn) { fprintf(stderr, "Error setting up dbus connection.\n"); + dbus_connection_close(conn); dbus_connection_unref(conn); return NULL; } + if (type == DBUS_BUS_SYSTEM || type == DBUS_BUS_SESSION) + { + econn->shared_type = type; + shared_connections[type] = econn; + } dbus_error_free(&err); - return conn; + return econn; } /** @@ -433,13 +445,14 @@ * * @param conn - a dbus connection */ -int +E_DBus_Connection * e_dbus_connection_setup(DBusConnection *conn) { - E_DBus_Connection *cd; + E_DBus_Connection *cd = NULL; cd = calloc(1, sizeof(E_DBus_Connection)); - if (!cd) return 0; + if (!cd) return NULL; + cd->shared_type = -1; cd->conn = conn; cd->fd_handlers = ecore_list_new(); @@ -472,7 +485,7 @@ cb_dispatch_status(cd->conn, dbus_connection_get_dispatch_status(cd->conn), cd); - return 1; + return cd; } @@ -481,31 +494,48 @@ * @param conn the connection to close */ void -e_dbus_connection_close(DBusConnection *conn) +e_dbus_connection_close(E_DBus_Connection *conn) { - E_DBus_Connection *cd; - cd = dbus_connection_get_data(conn, connection_slot); - DEBUG(5, "_e_dbus_connection_close\n"); dbus_connection_free_data_slot(&connection_slot); - dbus_connection_remove_filter(cd->conn, e_dbus_filter, NULL); - dbus_connection_set_watch_functions (conn, + dbus_connection_remove_filter(conn->conn, e_dbus_filter, NULL); + dbus_connection_set_watch_functions (conn->conn, NULL, NULL, NULL, NULL, NULL); - dbus_connection_set_timeout_functions (conn, + dbus_connection_set_timeout_functions (conn->conn, NULL, NULL, NULL, NULL, NULL); - dbus_connection_set_dispatch_status_function (conn, NULL, NULL, NULL); + dbus_connection_set_dispatch_status_function (conn->conn, NULL, NULL, NULL); + + dbus_connection_close(conn->conn); + dbus_connection_unref(conn->conn); + + // Note: the E_DBus_Connection gets freed when the dbus_connection is cleaned up by the previous unref +} - dbus_connection_close(conn); - dbus_connection_unref(conn); +void +e_dbus_connection_ref(E_DBus_Connection *conn) +{ + conn->refcount++; +} + +void +e_dbus_connection_unref(E_DBus_Connection *conn) +{ + if (--(conn->refcount) == 0) e_dbus_connection_close(conn); +} + +DBusConnection * +e_dbus_connection_dbus_connection_get(E_DBus_Connection *conn) +{ + return conn->conn; } /** =================================================================== RCS file: /cvs/e/e17/proto/e_dbus/src/lib/dbus/e_dbus_interfaces.c,v retrieving revision 1.2 retrieving revision 1.3 diff -u -3 -r1.2 -r1.3 --- e_dbus_interfaces.c 20 Mar 2007 06:34:13 -0000 1.2 +++ e_dbus_interfaces.c 22 Mar 2007 01:44:12 -0000 1.3 @@ -1,4 +1,5 @@ #include "E_DBus.h" +#include "e_dbus_private.h" /** * This file contains wrappers around the standard interfaces that @@ -6,7 +7,7 @@ */ void -e_dbus_peer_ping(DBusConnection*conn, const char *destination, const char *path, E_DBus_Method_Return_Cb cb_return, void *data) +e_dbus_peer_ping(E_DBus_Connection*conn, const char *destination, const char *path, E_DBus_Method_Return_Cb cb_return, void *data) { DBusMessage *msg; @@ -15,7 +16,7 @@ } void -e_dbus_peer_get_machine_id(DBusConnection*conn, const char *destination, const char *path, E_DBus_Method_Return_Cb cb_return, void *data) +e_dbus_peer_get_machine_id(E_DBus_Connection*conn, const char *destination, const char *path, E_DBus_Method_Return_Cb cb_return, void *data) { DBusMessage *msg; @@ -36,7 +37,7 @@ * @param data data to pass to the callbacks */ void -e_dbus_properties_get(DBusConnection*conn, const char *destination, const char *path, const char *interface, const char *property, E_DBus_Method_Return_Cb cb_return, void *data) +e_dbus_properties_get(E_DBus_Connection*conn, const char *destination, const char *path, const char *interface, const char *property, E_DBus_Method_Return_Cb cb_return, void *data) { DBusMessage *msg; @@ -59,7 +60,7 @@ * @param data data to pass to the callbacks */ void -e_dbus_properties_set(DBusConnection*conn, const char *destination, const char *path, const char *interface, const char *property, int value_type, void *value, E_DBus_Method_Return_Cb cb_return, void *data) +e_dbus_properties_set(E_DBus_Connection*conn, const char *destination, const char *path, const char *interface, const char *property, int value_type, void *value, E_DBus_Method_Return_Cb cb_return, void *data) { DBusMessage *msg; DBusMessageIter iter, sub; =================================================================== RCS file: /cvs/e/e17/proto/e_dbus/src/lib/dbus/e_dbus_message.c,v retrieving revision 1.2 retrieving revision 1.3 diff -u -3 -r1.2 -r1.3 --- e_dbus_message.c 20 Mar 2007 06:34:13 -0000 1.2 +++ e_dbus_message.c 22 Mar 2007 01:44:12 -0000 1.3 @@ -1,5 +1,6 @@ #include <stdlib.h> #include "E_DBus.h" +#include "e_dbus_private.h" typedef struct E_DBus_Pending_Call_Data E_DBus_Pending_Call_Data; struct E_DBus_Pending_Call_Data @@ -62,11 +63,11 @@ * @return a DBusPendingCall that can be used to cancel the current call */ DBusPendingCall * -e_dbus_message_send(DBusConnection *conn, DBusMessage *msg, E_DBus_Method_Return_Cb cb_return, int timeout, void *data) +e_dbus_message_send(E_DBus_Connection *conn, DBusMessage *msg, E_DBus_Method_Return_Cb cb_return, int timeout, void *data) { DBusPendingCall *pending; - if (!dbus_connection_send_with_reply(conn, msg, &pending, timeout)) + if (!dbus_connection_send_with_reply(conn->conn, msg, &pending, timeout)) return NULL; if (cb_return) =================================================================== RCS file: /cvs/e/e17/proto/e_dbus/src/lib/dbus/e_dbus_methods.c,v retrieving revision 1.3 retrieving revision 1.4 diff -u -3 -r1.3 -r1.4 --- e_dbus_methods.c 20 Mar 2007 06:34:13 -0000 1.3 +++ e_dbus_methods.c 22 Mar 2007 01:44:12 -0000 1.4 @@ -1,7 +1,8 @@ #include "E_DBus.h" +#include "e_dbus_private.h" void -e_dbus_request_name(DBusConnection *conn, const char *name, unsigned int flags, E_DBus_Method_Return_Cb cb_return, void *data) +e_dbus_request_name(E_DBus_Connection *conn, const char *name, unsigned int flags, E_DBus_Method_Return_Cb cb_return, void *data) { DBusMessage *msg; dbus_uint32_t u_flags; @@ -14,7 +15,7 @@ } void -e_dbus_release_name(DBusConnection *conn, const char *name, E_DBus_Method_Return_Cb cb_return, void *data) +e_dbus_release_name(E_DBus_Connection *conn, const char *name, E_DBus_Method_Return_Cb cb_return, void *data) { DBusMessage *msg; @@ -25,7 +26,7 @@ void -e_dbus_get_name_owner(DBusConnection *conn, const char *name, E_DBus_Method_Return_Cb cb_return, void *data) +e_dbus_get_name_owner(E_DBus_Connection *conn, const char *name, E_DBus_Method_Return_Cb cb_return, void *data) { DBusMessage *msg; @@ -35,7 +36,7 @@ } void -e_dbus_list_names(DBusConnection *conn, E_DBus_Method_Return_Cb cb_return, void *data) +e_dbus_list_names(E_DBus_Connection *conn, E_DBus_Method_Return_Cb cb_return, void *data) { DBusMessage *msg; @@ -45,7 +46,7 @@ void -e_dbus_list_activatable_names(DBusConnection *conn, E_DBus_Method_Return_Cb cb_return, void *data) +e_dbus_list_activatable_names(E_DBus_Connection *conn, E_DBus_Method_Return_Cb cb_return, void *data) { DBusMessage *msg; @@ -54,7 +55,7 @@ } void -e_dbus_name_has_owner(DBusConnection *conn, const char *name, E_DBus_Method_Return_Cb cb_return, void *data) +e_dbus_name_has_owner(E_DBus_Connection *conn, const char *name, E_DBus_Method_Return_Cb cb_return, void *data) { DBusMessage *msg; @@ -65,7 +66,7 @@ void -e_dbus_start_service_by_name(DBusConnection *conn, const char *name, E_DBus_Method_Return_Cb cb_return, void *data) +e_dbus_start_service_by_name(E_DBus_Connection *conn, const char *name, E_DBus_Method_Return_Cb cb_return, void *data) { DBusMessage *msg; =================================================================== RCS file: /cvs/e/e17/proto/e_dbus/src/lib/dbus/e_dbus_object.c,v retrieving revision 1.2 retrieving revision 1.3 diff -u -3 -r1.2 -r1.3 --- e_dbus_object.c 15 Mar 2007 09:18:54 -0000 1.2 +++ e_dbus_object.c 22 Mar 2007 01:44:12 -0000 1.3 @@ -1,4 +1,5 @@ #include "E_DBus.h" +#include "e_dbus_private.h" #include <Ecore_Data.h> #include <stdio.h> #include <stdlib.h> @@ -35,7 +36,7 @@ struct E_DBus_Object { - DBusConnection *conn; + E_DBus_Connection *conn; char *path; Ecore_List *methods; @@ -61,9 +62,8 @@ buf = e_dbus_object_introspect(obj); if (!buf) { - ret = dbus_message_new_error(msg, "org.e.NotIntrospectable", "This object does not provide introspection data"); + ret = dbus_message_new_error(msg, "org.enlightenment.NotIntrospectable", "This object does not provide introspection data"); return ret; - /* XXX send an error */ } xml = ecore_strbuf_string_get(buf); @@ -95,21 +95,21 @@ * @param data custom data to set on the object (obj->data XXX this needs an api) */ E_DBus_Object * -e_dbus_object_add(DBusConnection *conn, const char *object_path, void *data) +e_dbus_object_add(E_DBus_Connection *conn, const char *object_path, void *data) { E_DBus_Object *obj; obj = calloc(1, sizeof(E_DBus_Object)); if (!obj) return NULL; - if (!dbus_connection_register_object_path(conn, object_path, &vtable, obj)) + if (!dbus_connection_register_object_path(conn->conn, object_path, &vtable, obj)) { free(obj); return NULL; } obj->conn = conn; - dbus_connection_ref(conn); + e_dbus_connection_ref(conn); obj->path = strdup(object_path); obj->data = data; obj->methods = ecore_list_new(); @@ -131,8 +131,8 @@ if (!obj) return; DEBUG(5, "e_dbus_object_free\n"); - dbus_connection_unregister_object_path(obj->conn, obj->path); - dbus_connection_unref(obj->conn); + dbus_connection_unregister_object_path(obj->conn->conn, obj->path); + e_dbus_connection_unref(obj->conn); if (obj->path) free(obj->path); ecore_list_destroy(obj->methods); @@ -270,7 +270,7 @@ ecore_strbuf_append(buf, obj->path); ecore_strbuf_append(buf, "\">\n"); level++; - /* XXX currently assumes methods grouped by interface. should probably sort first */ + /* XXX currently assumes methods grouped by interface. should probably sort first -- or better, actually group them by interface */ ecore_list_goto_first(obj->methods); while ((method = ecore_list_next(obj->methods))) { =================================================================== RCS file: /cvs/e/e17/proto/e_dbus/src/lib/dbus/e_dbus_signal.c,v retrieving revision 1.3 retrieving revision 1.4 diff -u -3 -r1.3 -r1.4 --- e_dbus_signal.c 20 Mar 2007 06:34:13 -0000 1.3 +++ e_dbus_signal.c 22 Mar 2007 01:44:13 -0000 1.4 @@ -4,6 +4,7 @@ #include <Ecore.h> #include <Ecore_Data.h> #include "E_DBus.h" +#include "e_dbus_private.h" #include "dbus/dbus.h" static Ecore_List *signal_handlers = NULL; @@ -122,7 +123,7 @@ * @param data custom data to pass in to the callback */ E_DBus_Signal_Handler * -e_dbus_signal_handler_add(DBusConnection *conn, const char *sender, const char *path, const char *interface, const char *member, E_DBus_Signal_Cb cb_signal, void *data) +e_dbus_signal_handler_add(E_DBus_Connection *conn, const char *sender, const char *path, const char *interface, const char *member, E_DBus_Signal_Cb cb_signal, void *data) { E_DBus_Signal_Handler *sh; char match[DBUS_MAXIMUM_MATCH_RULE_LENGTH]; @@ -159,7 +160,7 @@ sh->data = data; dbus_error_init(&err); - dbus_bus_add_match(conn, match, NULL); + dbus_bus_add_match(conn->conn, match, NULL); ecore_list_append(signal_handlers, sh); /* if we have a sender, and it is not a unique name, we need to know the unique name to match since signals will have the name owner as ther sender. */ ------------------------------------------------------------------------- Take Surveys. Earn Cash. Influence the Future of IT Join SourceForge.net's Techsay panel and you'll get the chance to share your opinions on IT & business topics through brief surveys-and earn cash http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV _______________________________________________ enlightenment-cvs mailing list enlightenment-cvs@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/enlightenment-cvs