From 67ecbc16f9f6d88c01c71ea14daaf796942ba4e8 Mon Sep 17 00:00:00 2001 From: Timo Lotterbach Date: Tue, 30 Oct 2012 05:19:22 -0700 Subject: [PATCH] DbusIpcModule: now using private dbus connection, improved receive filters - clients now open a private dbus bus connection to prevent side effects with other part of the application using dbus - sender dbus interface is used for filtering messages from LayerMangerService - removed filterDiscardUnexpected, breaks apps using multiple lib communciating over dbus Signed-off-by: Timo Lotterbach --- .../IpcModules/DbusIpcModule/src/callbacks.c | 68 ++++++++++------------ .../IpcModules/DbusIpcModule/src/initialization.c | 26 ++------- .../IpcModules/DbusIpcModule/src/message.c | 2 + 3 files changed, 39 insertions(+), 57 deletions(-) diff --git a/LayerManagerPlugins/IpcModules/DbusIpcModule/src/callbacks.c b/LayerManagerPlugins/IpcModules/DbusIpcModule/src/callbacks.c index ac552b4..baaab6c 100644 --- a/LayerManagerPlugins/IpcModules/DbusIpcModule/src/callbacks.c +++ b/LayerManagerPlugins/IpcModules/DbusIpcModule/src/callbacks.c @@ -16,6 +16,7 @@ * limitations under the License. * ****************************************************************************/ +#include "DBUSConfiguration.h" #include "callbacks.h" #include "common.h" #include "introspection.h" @@ -31,6 +32,16 @@ t_ilm_message createResponse(t_ilm_message); DBusHandlerResult filterLayerManagerNotifications(DBusConnection *connection, DBusMessage *message, void *data) { + const char* interfaceName = dbus_message_get_interface(message); + if (!interfaceName) + { + return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; + } + if (strcmp(ILM_INTERFACE_COMPOSITE_SERVICE, interfaceName)) // 0 == equals + { + return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; + } + DBusHandlerResult result = DBUS_HANDLER_RESULT_NOT_YET_HANDLED; int messageType = dbus_message_get_type(message); @@ -50,6 +61,16 @@ DBusHandlerResult filterLayerManagerNotifications(DBusConnection *connection, DB DBusHandlerResult filterLayerManagerCommands(DBusConnection *connection, DBusMessage *message, void *data) { + const char* interfaceName = dbus_message_get_interface(message); + if (!interfaceName) + { + return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; + } + if (strcmp(ILM_INTERFACE_COMPOSITE_SERVICE, interfaceName)) // 0 == equals + { + return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; + } + DBusHandlerResult result = DBUS_HANDLER_RESULT_NOT_YET_HANDLED; int messageType = dbus_message_get_type(message); @@ -70,6 +91,16 @@ DBusHandlerResult filterLayerManagerCommands(DBusConnection *connection, DBusMes DBusHandlerResult filterLayerManagerErrors(DBusConnection *connection, DBusMessage *message, void *data) { + const char* interfaceName = dbus_message_get_interface(message); + if (!interfaceName) + { + return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; + } + if (strcmp(ILM_INTERFACE_COMPOSITE_SERVICE, interfaceName)) // 0 == equals + { + return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; + } + DBusHandlerResult result = DBUS_HANDLER_RESULT_NOT_YET_HANDLED; int messageType = dbus_message_get_type(message); @@ -128,7 +159,6 @@ DBusHandlerResult filterNameAcquired(DBusConnection *connection, DBusMessage *me { gpIncomingMessage->pMessage = dbus_message_copy(message); gpIncomingMessage->type = IpcMessageTypeNone; - return DBUS_HANDLER_RESULT_HANDLED; } return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; @@ -156,7 +186,6 @@ DBusHandlerResult filterNameOwnerChanged(DBusConnection *connection, DBusMessage dbus_message_set_sender(gpIncomingMessage->pMessage, old); } - return DBUS_HANDLER_RESULT_HANDLED; } return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; @@ -191,41 +220,6 @@ DBusHandlerResult filterIntrospection(DBusConnection *connection, DBusMessage *m return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; } -DBusHandlerResult filterDiscardUnexpected(DBusConnection *connection, DBusMessage *message, void *data) -{ - gpIncomingMessage->pMessage = dbus_message_copy(message); - gpIncomingMessage->type = IpcMessageTypeNone; - - printf("---------------------------------\n"); - printf("discarded unexpected data:\n"); - printf("\tmember: %s\n", dbus_message_get_member(message)); - printf("\ttype: "); - switch (dbus_message_get_type(message)) - { - case DBUS_MESSAGE_TYPE_METHOD_CALL: - printf("method call\n"); - break; - case DBUS_MESSAGE_TYPE_METHOD_RETURN: - printf("method return\n"); - break; - case DBUS_MESSAGE_TYPE_ERROR: - printf("error: %s\n", dbus_message_get_error_name(message)); - break; - case DBUS_MESSAGE_TYPE_SIGNAL: - printf("signal\n"); - break; - default: - printf("unknown\n"); - break; - } - printf("\tsender: %s\n", dbus_message_get_sender(message)); - printf("\tdest: %s\n", dbus_message_get_destination(message)); - printf("\tpath: %s\n", dbus_message_get_path(message)); - printf("\tinterface: %s\n", dbus_message_get_interface(message)); - - return DBUS_HANDLER_RESULT_HANDLED; -} - //============================================================================= // watches //============================================================================= diff --git a/LayerManagerPlugins/IpcModules/DbusIpcModule/src/initialization.c b/LayerManagerPlugins/IpcModules/DbusIpcModule/src/initialization.c index 36675e3..9c8d0df 100644 --- a/LayerManagerPlugins/IpcModules/DbusIpcModule/src/initialization.c +++ b/LayerManagerPlugins/IpcModules/DbusIpcModule/src/initialization.c @@ -148,15 +148,6 @@ t_ilm_bool initServiceMode() exit(1); } - if (!dbus_connection_add_filter(gDbus.connection, - filterDiscardUnexpected, - NULL, - NULL)) - { - printf("Couldn't set up filter functions\n"); - exit(1); - } - if(!dbus_connection_set_watch_functions(gDbus.connection, addWatch, removeWatch, @@ -194,7 +185,7 @@ t_ilm_bool initClientMode() printf("DbusIpcmodule: using system bus\n"); } - gDbus.connection = dbus_bus_get(gDbus.type, &gDbus.error); + gDbus.connection = dbus_bus_get_private(gDbus.type, &gDbus.error); if (dbus_error_is_set(&gDbus.error) || !gDbus.connection) { @@ -250,15 +241,6 @@ t_ilm_bool initClientMode() exit(1); } - if (!dbus_connection_add_filter(gDbus.connection, - filterDiscardUnexpected, - NULL, - NULL)) - { - printf("Couldn't set up filter functions\n"); - exit(1); - } - if(!dbus_connection_set_watch_functions(gDbus.connection, addWatch, removeWatch, @@ -282,7 +264,6 @@ t_ilm_bool destroy() dbus_connection_set_watch_functions(gDbus.connection, NULL, NULL, NULL, 0, NULL); dbus_connection_remove_filter(gDbus.connection, filterNameAcquired, NULL); dbus_connection_remove_filter(gDbus.connection, filterLayerManagerCommands, NULL); - dbus_connection_remove_filter(gDbus.connection, filterDiscardUnexpected, NULL); if (gDbus.isClient) { @@ -355,6 +336,11 @@ t_ilm_bool destroyService() t_ilm_bool destroyClient() { + // private dbus connection must be closed + if (dbus_connection_get_is_connected(gDbus.connection)) + { + dbus_connection_close(gDbus.connection); + } dbus_connection_unref(gDbus.connection); dbus_error_free(&gDbus.error); return ILM_TRUE; diff --git a/LayerManagerPlugins/IpcModules/DbusIpcModule/src/message.c b/LayerManagerPlugins/IpcModules/DbusIpcModule/src/message.c index 5e03465..8de7721 100644 --- a/LayerManagerPlugins/IpcModules/DbusIpcModule/src/message.c +++ b/LayerManagerPlugins/IpcModules/DbusIpcModule/src/message.c @@ -147,6 +147,8 @@ t_ilm_bool sendToClients(t_ilm_message message, t_ilm_client_handle* receiverLis dbusmessage* messageToSend = (dbusmessage*)message; t_ilm_int serial = dbus_message_get_serial(messageToSend->pMessage); + dbus_message_set_path(messageToSend->pMessage, ILM_PATH_COMPOSITE_SERVICE); + dbus_message_set_interface(messageToSend->pMessage, ILM_INTERFACE_COMPOSITE_SERVICE); pthread_mutex_lock(&gDbus.mutex); dbus_bool_t success = dbus_connection_send(gDbus.connection, messageToSend->pMessage, &serial); pthread_mutex_unlock(&gDbus.mutex); -- 2.7.4