summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHavoc Pennington <hp@redhat.com>2003-08-31 03:25:24 +0000
committerHavoc Pennington <hp@redhat.com>2003-08-31 03:25:24 +0000
commit1dd3f1788f1b4c9af2f4fa744abdb7892d0a14b9 (patch)
tree9f928baa3e6205394044ce5f0c6f1aa3933bdf4f
parent5fd1e389e1c1c12ad4a55c2af6abdc8e7a2f6d41 (diff)
downloaddbus-1dd3f1788f1b4c9af2f4fa744abdb7892d0a14b9.tar.gz
2003-08-30 Havoc Pennington <hp@pobox.com>
* dbus/dbus-connection.c: purge DBusMessageHandler * dbus/dbus-message-handler.c: remove DBusMessageHandler, just use callbacks everywhere
-rw-r--r--ChangeLog7
-rw-r--r--bus/dispatch.c62
-rw-r--r--bus/test.c51
-rw-r--r--dbus/Makefile.am2
-rw-r--r--dbus/dbus-connection-internal.h9
-rw-r--r--dbus/dbus-connection.c203
-rw-r--r--dbus/dbus-connection.h21
-rw-r--r--dbus/dbus-internals.h3
-rw-r--r--dbus/dbus-message-handler.c363
-rw-r--r--dbus/dbus-message-handler.h59
-rw-r--r--dbus/dbus-test.c6
-rw-r--r--dbus/dbus-test.h1
-rw-r--r--dbus/dbus-threads.c1
-rw-r--r--dbus/dbus.h1
-rw-r--r--glib/test-profile.c23
-rw-r--r--glib/test-thread-server.c52
-rw-r--r--test/test-service.c15
-rw-r--r--tools/dbus-monitor.c11
18 files changed, 184 insertions, 706 deletions
diff --git a/ChangeLog b/ChangeLog
index a31c1680..4930c689 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,12 @@
2003-08-30 Havoc Pennington <hp@pobox.com>
+ * dbus/dbus-connection.c: purge DBusMessageHandler
+
+ * dbus/dbus-message-handler.c: remove DBusMessageHandler, just
+ use callbacks everywhere
+
+2003-08-30 Havoc Pennington <hp@pobox.com>
+
* test/data/valid-config-files/system.d/test.conf: change to
root for the user so warnings don't get printed
diff --git a/bus/dispatch.c b/bus/dispatch.c
index 2f2e9e9d..7bdda0d4 100644
--- a/bus/dispatch.c
+++ b/bus/dispatch.c
@@ -32,8 +32,6 @@
#include <dbus/dbus-internals.h>
#include <string.h>
-static dbus_int32_t message_handler_slot = -1;
-
typedef struct
{
BusContext *context;
@@ -316,61 +314,21 @@ bus_dispatch (DBusConnection *connection,
}
static DBusHandlerResult
-bus_dispatch_message_handler (DBusMessageHandler *handler,
- DBusConnection *connection,
- DBusMessage *message,
- void *user_data)
+bus_dispatch_message_filter (DBusConnection *connection,
+ DBusMessage *message,
+ void *user_data)
{
return bus_dispatch (connection, message);
}
-static void
-free_message_handler (void *data)
-{
- DBusMessageHandler *handler = data;
-
- _dbus_assert (message_handler_slot >= 0);
-
- dbus_message_handler_unref (handler);
- dbus_connection_free_data_slot (&message_handler_slot);
-}
-
dbus_bool_t
bus_dispatch_add_connection (DBusConnection *connection)
-{
- DBusMessageHandler *handler;
-
- if (!dbus_connection_allocate_data_slot (&message_handler_slot))
+{
+ if (!dbus_connection_add_filter (connection,
+ bus_dispatch_message_filter,
+ NULL, NULL))
return FALSE;
- handler = dbus_message_handler_new (bus_dispatch_message_handler, NULL, NULL);
- if (handler == NULL)
- {
- dbus_connection_free_data_slot (&message_handler_slot);
- return FALSE;
- }
-
- if (!dbus_connection_add_filter (connection, handler))
- {
- dbus_message_handler_unref (handler);
- dbus_connection_free_data_slot (&message_handler_slot);
-
- return FALSE;
- }
-
- _dbus_assert (message_handler_slot >= 0);
-
- if (!dbus_connection_set_data (connection,
- message_handler_slot,
- handler,
- free_message_handler))
- {
- dbus_message_handler_unref (handler);
- dbus_connection_free_data_slot (&message_handler_slot);
-
- return FALSE;
- }
-
return TRUE;
}
@@ -380,9 +338,9 @@ bus_dispatch_remove_connection (DBusConnection *connection)
/* Here we tell the bus driver that we want to get off. */
bus_driver_remove_connection (connection);
- dbus_connection_set_data (connection,
- message_handler_slot,
- NULL, NULL);
+ dbus_connection_remove_filter (connection,
+ bus_dispatch_message_filter,
+ NULL);
}
#ifdef DBUS_BUILD_TESTS
diff --git a/bus/test.c b/bus/test.c
index 1f13e4b6..b48ba0fe 100644
--- a/bus/test.c
+++ b/bus/test.c
@@ -102,10 +102,9 @@ remove_client_timeout (DBusTimeout *timeout,
}
static DBusHandlerResult
-client_disconnect_handler (DBusMessageHandler *handler,
- DBusConnection *connection,
- DBusMessage *message,
- void *user_data)
+client_disconnect_filter (DBusConnection *connection,
+ DBusMessage *message,
+ void *user_data)
{
if (!dbus_message_is_signal (message,
DBUS_INTERFACE_ORG_FREEDESKTOP_LOCAL,
@@ -128,35 +127,15 @@ client_disconnect_handler (DBusMessageHandler *handler,
return DBUS_HANDLER_RESULT_HANDLED;
}
-static dbus_int32_t handler_slot = -1;
-
-static void
-free_handler (void *data)
-{
- DBusMessageHandler *handler = data;
-
- dbus_message_handler_unref (handler);
- dbus_connection_free_data_slot (&handler_slot);
-}
-
dbus_bool_t
bus_setup_debug_client (DBusConnection *connection)
{
- DBusMessageHandler *disconnect_handler;
- dbus_bool_t retval;
-
- disconnect_handler = dbus_message_handler_new (client_disconnect_handler,
- NULL, NULL);
-
- if (disconnect_handler == NULL)
- return FALSE;
+ dbus_bool_t retval;
if (!dbus_connection_add_filter (connection,
- disconnect_handler))
- {
- dbus_message_handler_unref (disconnect_handler);
- return FALSE;
- }
+ client_disconnect_filter,
+ NULL, NULL))
+ return FALSE;
retval = FALSE;
@@ -184,25 +163,15 @@ bus_setup_debug_client (DBusConnection *connection)
if (!_dbus_list_append (&clients, connection))
goto out;
-
- if (!dbus_connection_allocate_data_slot (&handler_slot))
- goto out;
-
- /* Set up handler to be destroyed */
- if (!dbus_connection_set_data (connection, handler_slot,
- disconnect_handler,
- free_handler))
- {
- dbus_connection_free_data_slot (&handler_slot);
- goto out;
- }
retval = TRUE;
out:
if (!retval)
{
- dbus_message_handler_unref (disconnect_handler); /* unregisters it */
+ dbus_connection_remove_filter (connection,
+ client_disconnect_filter,
+ NULL);
dbus_connection_set_watch_functions (connection,
NULL, NULL, NULL, NULL, NULL);
diff --git a/dbus/Makefile.am b/dbus/Makefile.am
index f8509cce..f377b2a8 100644
--- a/dbus/Makefile.am
+++ b/dbus/Makefile.am
@@ -16,7 +16,6 @@ dbusinclude_HEADERS= \
dbus-macros.h \
dbus-memory.h \
dbus-message.h \
- dbus-message-handler.h \
dbus-pending-call.h \
dbus-protocol.h \
dbus-server.h \
@@ -41,7 +40,6 @@ DBUS_LIB_SOURCES= \
dbus-keyring.c \
dbus-keyring.h \
dbus-message.c \
- dbus-message-handler.c \
dbus-message-internal.h \
dbus-object-tree.c \
dbus-object-tree.h \
diff --git a/dbus/dbus-connection-internal.h b/dbus/dbus-connection-internal.h
index 93b1b4a3..5a04dece 100644
--- a/dbus/dbus-connection-internal.h
+++ b/dbus/dbus-connection-internal.h
@@ -77,15 +77,6 @@ void _dbus_connection_do_iteration (DBusConnection
unsigned int flags,
int timeout_milliseconds);
void _dbus_connection_notify_disconnected (DBusConnection *connection);
-void _dbus_connection_handler_destroyed_locked (DBusConnection *connection,
- DBusMessageHandler *handler);
-dbus_bool_t _dbus_message_handler_add_connection (DBusMessageHandler *handler,
- DBusConnection *connection);
-void _dbus_message_handler_remove_connection (DBusMessageHandler *handler,
- DBusConnection *connection);
-DBusHandlerResult _dbus_message_handler_handle_message (DBusMessageHandler *handler,
- DBusConnection *connection,
- DBusMessage *message);
DBusPendingCall* _dbus_pending_call_new (DBusConnection *connection,
int timeout_milliseconds,
diff --git a/dbus/dbus-connection.c b/dbus/dbus-connection.c
index 86678673..608634d2 100644
--- a/dbus/dbus-connection.c
+++ b/dbus/dbus-connection.c
@@ -31,7 +31,6 @@
#include "dbus-list.h"
#include "dbus-hash.h"
#include "dbus-message-internal.h"
-#include "dbus-message-handler.h"
#include "dbus-threads.h"
#include "dbus-protocol.h"
#include "dbus-dataslot.h"
@@ -125,6 +124,16 @@
* @{
*/
+typedef struct DBusMessageFilter DBusMessageFilter;
+
+struct DBusMessageFilter
+{
+ DBusAtomic refcount;
+ DBusHandleMessageFunction function;
+ void *user_data;
+ DBusFreeFunction free_user_data_function;
+};
+
static dbus_bool_t _dbus_modify_sigpipe = TRUE;
/**
@@ -189,6 +198,26 @@ static void _dbus_connection_update_dispatch_status_and_unlock (DB
DBusDispatchStatus new_status);
static void _dbus_connection_last_unref (DBusConnection *connection);
+static void
+_dbus_message_filter_ref (DBusMessageFilter *filter)
+{
+ _dbus_assert (filter->refcount.value > 0);
+ _dbus_atomic_inc (&filter->refcount);
+}
+
+static void
+_dbus_message_filter_unref (DBusMessageFilter *filter)
+{
+ _dbus_assert (filter->refcount.value > 0);
+
+ if (_dbus_atomic_dec (&filter->refcount) == 1)
+ {
+ if (filter->free_user_data_function)
+ (* filter->free_user_data_function) (filter->user_data);
+
+ dbus_free (filter);
+ }
+}
/**
* Acquires the connection lock.
@@ -978,40 +1007,6 @@ _dbus_connection_get_next_client_serial (DBusConnection *connection)
}
/**
- * Used to notify a connection when a DBusMessageHandler is
- * destroyed, so the connection can drop any reference
- * to the handler. This is a private function, but still
- * takes the connection lock. Don't call it with the lock held.
- *
- * @todo needs to check in pending_replies too.
- *
- * @param connection the connection
- * @param handler the handler
- */
-void
-_dbus_connection_handler_destroyed_locked (DBusConnection *connection,
- DBusMessageHandler *handler)
-{
- DBusList *link;
-
- CONNECTION_LOCK (connection);
-
- link = _dbus_list_get_first_link (&connection->filter_list);
- while (link != NULL)
- {
- DBusMessageHandler *h = link->data;
- DBusList *next = _dbus_list_get_next_link (&connection->filter_list, link);
-
- if (h == handler)
- _dbus_list_remove_link (&connection->filter_list,
- link);
-
- link = next;
- }
- CONNECTION_UNLOCK (connection);
-}
-
-/**
* A callback for use with dbus_watch_new() to create a DBusWatch.
*
* @todo This is basically a hack - we could delete _dbus_transport_handle_watch()
@@ -1173,18 +1168,22 @@ _dbus_connection_last_unref (DBusConnection *connection)
connection->timeouts = NULL;
_dbus_data_slot_list_free (&connection->slot_list);
- /* ---- Done with stuff that invokes application callbacks */
link = _dbus_list_get_first_link (&connection->filter_list);
while (link != NULL)
{
- DBusMessageHandler *h = link->data;
+ DBusMessageFilter *filter = link->data;
DBusList *next = _dbus_list_get_next_link (&connection->filter_list, link);
-
- _dbus_message_handler_remove_connection (h, connection);
+
+ filter->function = NULL;
+ _dbus_message_filter_unref (filter); /* calls app callback */
+ link->data = NULL;
link = next;
}
+ _dbus_list_clear (&connection->filter_list);
+
+ /* ---- Done with stuff that invokes application callbacks */
_dbus_object_tree_unref (connection->objects);
@@ -2456,7 +2455,7 @@ dbus_connection_dispatch (DBusConnection *connection)
}
_dbus_list_foreach (&filter_list_copy,
- (DBusForeachFunction)dbus_message_handler_ref,
+ (DBusForeachFunction)_dbus_message_filter_ref,
NULL);
/* We're still protected from dispatch() reentrancy here
@@ -2467,12 +2466,11 @@ dbus_connection_dispatch (DBusConnection *connection)
link = _dbus_list_get_first_link (&filter_list_copy);
while (link != NULL)
{
- DBusMessageHandler *handler = link->data;
+ DBusMessageFilter *filter = link->data;
DBusList *next = _dbus_list_get_next_link (&filter_list_copy, link);
_dbus_verbose (" running filter on message %p\n", message);
- result = _dbus_message_handler_handle_message (handler, connection,
- message);
+ result = (* filter->function) (connection, message, filter->user_data);
if (result != DBUS_HANDLER_RESULT_NOT_YET_HANDLED)
break;
@@ -2481,7 +2479,7 @@ dbus_connection_dispatch (DBusConnection *connection)
}
_dbus_list_foreach (&filter_list_copy,
- (DBusForeachFunction)dbus_message_handler_unref,
+ (DBusForeachFunction)_dbus_message_filter_unref,
NULL);
_dbus_list_clear (&filter_list_copy);
@@ -2928,83 +2926,126 @@ dbus_connection_set_unix_user_function (DBusConnection *connection,
}
/**
- * Adds a message filter. Filters are handlers that are run on
- * all incoming messages, prior to the objects
- * registered with dbus_connection_register_object().
- * Filters are run in the order that they were added.
- * The same handler can be added as a filter more than once, in
- * which case it will be run more than once.
- * Filters added during a filter callback won't be run on the
- * message being processed.
- *
- * The connection does NOT add a reference to the message handler;
- * instead, if the message handler is finalized, the connection simply
- * forgets about it. Thus the caller of this function must keep a
- * reference to the message handler.
+ * Adds a message filter. Filters are handlers that are run on all
+ * incoming messages, prior to the objects registered with
+ * dbus_connection_register_object_path(). Filters are run in the
+ * order that they were added. The same handler can be added as a
+ * filter more than once, in which case it will be run more than once.
+ * Filters added during a filter callback won't be run on the message
+ * being processed.
*
* @todo we don't run filters on messages while blocking without
* entering the main loop, since filters are run as part of
* dbus_connection_dispatch().
*
* @param connection the connection
- * @param handler the handler
+ * @param function function to handle messages
+ * @param user_data user data to pass to the function
+ * @param free_data_function function to use for freeing user data
* @returns #TRUE on success, #FALSE if not enough memory.
*/
dbus_bool_t
-dbus_connection_add_filter (DBusConnection *connection,
- DBusMessageHandler *handler)
+dbus_connection_add_filter (DBusConnection *connection,
+ DBusHandleMessageFunction function,
+ void *user_data,
+ DBusFreeFunction free_data_function)
{
+ DBusMessageFilter *filter;
+
_dbus_return_val_if_fail (connection != NULL, FALSE);
- _dbus_return_val_if_fail (handler != NULL, FALSE);
+ _dbus_return_val_if_fail (function != NULL, FALSE);
+
+ filter = dbus_new0 (DBusMessageFilter, 1);
+ if (filter == NULL)
+ return FALSE;
+ filter->refcount.value = 1;
+
CONNECTION_LOCK (connection);
- if (!_dbus_message_handler_add_connection (handler, connection))
- {
- CONNECTION_UNLOCK (connection);
- return FALSE;
- }
if (!_dbus_list_append (&connection->filter_list,
- handler))
+ filter))
{
- _dbus_message_handler_remove_connection (handler, connection);
+ _dbus_message_filter_unref (filter);
CONNECTION_UNLOCK (connection);
return FALSE;
}
+ /* Fill in filter after all memory allocated,
+ * so we don't run the free_user_data_function
+ * if the add_filter() fails
+ */
+
+ filter->function = function;
+ filter->user_data = user_data;
+ filter->free_user_data_function = free_data_function;
+
CONNECTION_UNLOCK (connection);
return TRUE;
}
/**
* Removes a previously-added message filter. It is a programming
- * error to call this function for a handler that has not
- * been added as a filter. If the given handler was added
- * more than once, only one instance of it will be removed
- * (the most recently-added instance).
+ * error to call this function for a handler that has not been added
+ * as a filter. If the given handler was added more than once, only
+ * one instance of it will be removed (the most recently-added
+ * instance).
*
* @param connection the connection
* @param handler the handler to remove
*
*/
void
-dbus_connection_remove_filter (DBusConnection *connection,
- DBusMessageHandler *handler)
+dbus_connection_remove_filter (DBusConnection *connection,
+ DBusHandleMessageFunction function,
+ void *user_data)
{
+ DBusList *link;
+ DBusMessageFilter *filter;
+
_dbus_return_if_fail (connection != NULL);
- _dbus_return_if_fail (handler != NULL);
+ _dbus_return_if_fail (function != NULL);
CONNECTION_LOCK (connection);
- if (!_dbus_list_remove_last (&connection->filter_list, handler))
+
+ filter = NULL;
+
+ link = _dbus_list_get_last_link (&connection->filter_list);
+ while (link != NULL)
{
- _dbus_warn ("Tried to remove a DBusConnection filter that had not been added\n");
- CONNECTION_UNLOCK (connection);
- return;
+ filter = link->data;
+
+ if (filter->function == function &&
+ filter->user_data == user_data)
+ {
+ _dbus_list_remove_link (&connection->filter_list, link);
+ filter->function = NULL;
+
+ break;
+ }
+
+ link = _dbus_list_get_prev_link (&connection->filter_list, link);
}
+
+ CONNECTION_UNLOCK (connection);
- _dbus_message_handler_remove_connection (handler, connection);
+#ifndef DBUS_DISABLE_CHECKS
+ if (filter == NULL)
+ {
+ _dbus_warn ("Attempt to remove filter function %p user data %p, but no such filter has been added\n",
+ function, user_data);
+ return;
+ }
+#endif
+
+ /* Call application code */
+ if (filter->free_user_data_function)
+ (* filter->free_user_data_function) (filter->user_data);
- CONNECTION_UNLOCK (connection);
+ filter->free_user_data_function = NULL;
+ filter->user_data = NULL;
+
+ _dbus_message_filter_unref (filter);
}
/**
diff --git a/dbus/dbus-connection.h b/dbus/dbus-connection.h
index 0b346530..c5dee7f0 100644
--- a/dbus/dbus-connection.h
+++ b/dbus/dbus-connection.h
@@ -35,7 +35,6 @@ DBUS_BEGIN_DECLS;
typedef struct DBusWatch DBusWatch;
typedef struct DBusTimeout DBusTimeout;
-typedef struct DBusMessageHandler DBusMessageHandler;
typedef struct DBusPreallocatedSend DBusPreallocatedSend;
typedef struct DBusPendingCall DBusPendingCall;
typedef struct DBusConnection DBusConnection;
@@ -89,6 +88,11 @@ typedef dbus_bool_t (* DBusAllowUnixUserFunction) (DBusConnection *connection,
typedef void (* DBusPendingCallNotifyFunction) (DBusPendingCall *pending,
void *user_data);
+
+typedef DBusHandlerResult (* DBusHandleMessageFunction) (DBusConnection *connection,
+ DBusMessage *message,
+ void *user_data);
+
DBusConnection* dbus_connection_open (const char *address,
DBusError *error);
void dbus_connection_ref (DBusConnection *connection);
@@ -162,11 +166,16 @@ void dbus_timeout_set_data (DBusTimeout *timeout,
dbus_bool_t dbus_timeout_handle (DBusTimeout *timeout);
dbus_bool_t dbus_timeout_get_enabled (DBusTimeout *timeout);
-/* Handlers */
-dbus_bool_t dbus_connection_add_filter (DBusConnection *connection,
- DBusMessageHandler *handler);
-void dbus_connection_remove_filter (DBusConnection *connection,
- DBusMessageHandler *handler);
+/* Filters */
+
+dbus_bool_t dbus_connection_add_filter (DBusConnection *connection,
+ DBusHandleMessageFunction function,
+ void *user_data,
+ DBusFreeFunction free_data_function);
+void dbus_connection_remove_filter (DBusConnection *connection,
+ DBusHandleMessageFunction function,
+ void *user_data);
+
/* Other */
dbus_bool_t dbus_connection_allocate_data_slot (dbus_int32_t *slot_p);
diff --git a/dbus/dbus-internals.h b/dbus/dbus-internals.h
index a0c5b194..06a011e3 100644
--- a/dbus/dbus-internals.h
+++ b/dbus/dbus-internals.h
@@ -233,11 +233,10 @@ _DBUS_DECLARE_GLOBAL_LOCK (connection_slots);
_DBUS_DECLARE_GLOBAL_LOCK (server_slots);
_DBUS_DECLARE_GLOBAL_LOCK (message_slots);
_DBUS_DECLARE_GLOBAL_LOCK (atomic);
-_DBUS_DECLARE_GLOBAL_LOCK (message_handler);
_DBUS_DECLARE_GLOBAL_LOCK (bus);
_DBUS_DECLARE_GLOBAL_LOCK (shutdown_funcs);
_DBUS_DECLARE_GLOBAL_LOCK (system_users);
-#define _DBUS_N_GLOBAL_LOCKS (9)
+#define _DBUS_N_GLOBAL_LOCKS (8)
dbus_bool_t _dbus_threads_init_debug (void);
diff --git a/dbus/dbus-message-handler.c b/dbus/dbus-message-handler.c
deleted file mode 100644
index 2e8a8b64..00000000
--- a/dbus/dbus-message-handler.c
+++ /dev/null
@@ -1,363 +0,0 @@
-/* -*- mode: C; c-file-style: "gnu" -*- */
-/* dbus-message-handler.c Sender/receiver of messages.
- *
- * Copyright (C) 2002, 2003 Red Hat Inc.
- *
- * Licensed under the Academic Free License version 1.2
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- *
- */
-
-#include "dbus-internals.h"
-#include "dbus-message-handler.h"
-#include "dbus-list.h"
-#include "dbus-threads.h"
-#include "dbus-test.h"
-#include "dbus-connection-internal.h"
-
-/**
- * @defgroup DBusMessageHandlerInternals DBusMessageHandler implementation details
- * @ingroup DBusInternals
- * @brief DBusMessageHandler private implementation details.
- *
- * The guts of DBusMessageHandler and its methods.
- *
- * @{
- */
-
-_DBUS_DEFINE_GLOBAL_LOCK (message_handler);
-
-/**
- * @brief Internals of DBusMessageHandler
- *
- * Object that can send and receive messages.
- */
-struct DBusMessageHandler
-{
- DBusAtomic refcount; /**< reference count */
-
- DBusHandleMessageFunction function; /**< handler function */
- void *user_data; /**< user data for function */
- DBusFreeFunction free_user_data; /**< free the user data */
-
- DBusList *connections; /**< connections we're registered with */
-};
-
-/**
- * Add this connection to the list used by this message handler.
- * When the message handler goes away, the connection
- * will be notified.
- *
- * @param handler the message handler
- * @param connection the connection
- * @returns #FALSE if not enough memory
- */
-dbus_bool_t
-_dbus_message_handler_add_connection (DBusMessageHandler *handler,
- DBusConnection *connection)
-{
- dbus_bool_t res;
-
- _DBUS_LOCK (message_handler);
- /* This is a bit wasteful - we just put the connection in the list
- * once per time it's added. :-/
- */
- if (!_dbus_list_prepend (&handler->connections, connection))
- res = FALSE;
- else
- res = TRUE;
-
- _DBUS_UNLOCK (message_handler);
-
- return res;
-}
-
-/**
- * Reverses the effect of _dbus_message_handler_add_connection().
- * @param handler the message handler
- * @param connection the connection
- */
-void
-_dbus_message_handler_remove_connection (DBusMessageHandler *handler,
- DBusConnection *connection)
-{
- _DBUS_LOCK (message_handler);
- if (!_dbus_list_remove (&handler->connections, connection))
- _dbus_warn ("Function _dbus_message_handler_remove_connection() called when the connection hadn't been added\n");
- _DBUS_UNLOCK (message_handler);
-}
-
-
-/**
- * Handles the given message, by dispatching the handler function
- * for this DBusMessageHandler, if any.
- *
- * @param handler the handler
- * @param connection the connection that received the message
- * @param message the message
- *
- * @returns what to do with the message
- */
-DBusHandlerResult
-_dbus_message_handler_handle_message (DBusMessageHandler *handler,
- DBusConnection *connection,
- DBusMessage *message)
-{
- DBusHandleMessageFunction function;
- void *user_data;
-
- _DBUS_LOCK (message_handler);
- function = handler->function;
- user_data = handler->user_data;
- _DBUS_UNLOCK (message_handler);
-
- /* This function doesn't ref handler/connection/message
- * since that's done in dbus_connection_dispatch().
- */
- if (function != NULL)
- return (* function) (handler, connection, message, user_data);
- else
- return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
-}
-
-/** @} */
-
-/**
- * @defgroup DBusMessageHandler DBusMessageHandler
- * @ingroup DBus
- * @brief Message processor
- *
- * A DBusMessageHandler is an object that can send and receive
- * messages. Typically the handler is registered with one or
- * more DBusConnection objects and processes some types of
- * messages received from the connection.
- *
- * @{
- */
-
-/**
- * @typedef DBusMessageHandler
- *
- * Opaque data type representing a message handler.
- */
-
-/**
- * Creates a new message handler. The handler function
- * may be #NULL for a no-op handler or a handler to
- * be assigned a function later.
- *
- * @param function function to call to handle a message
- * @param user_data data to pass to the function
- * @param free_user_data function to call to free the user data
- * @returns a new DBusMessageHandler or #NULL if no memory.
- */
-DBusMessageHandler*
-dbus_message_handler_new (DBusHandleMessageFunction function,
- void *user_data,
- DBusFreeFunction free_user_data)
-{
- DBusMessageHandler *handler;
-
- handler = dbus_new (DBusMessageHandler, 1);
-
- if (handler == NULL)
- return NULL;
-
- handler->refcount.value = 1;
- handler->function = function;
- handler->user_data = user_data;
- handler->free_user_data = free_user_data;
- handler->connections = NULL;
-
- return handler;
-}
-
-/**
- * Increments the reference count on a message handler.
- *
- * @param handler the handler
- */
-void
-dbus_message_handler_ref (DBusMessageHandler *handler)
-{
- _dbus_return_if_fail (handler != NULL);
-
- _dbus_atomic_inc (&handler->refcount);
-}
-
-/**
- * Decrements the reference count on a message handler,
- * freeing the handler if the count reaches 0.
- *
- * @param handler the handler
- */
-void
-dbus_message_handler_unref (DBusMessageHandler *handler)
-{
- dbus_bool_t last_unref;
-
- _dbus_return_if_fail (handler != NULL);
-
- last_unref = (_dbus_atomic_dec (&handler->refcount) == 1);
-
- if (last_unref)
- {
- DBusList *link;
-
- if (handler->free_user_data)
- (* handler->free_user_data) (handler->user_data);
-
- link = _dbus_list_get_first_link (&handler->connections);
- while (link != NULL)
- {
- DBusConnection *connection = link->data;
-
- _dbus_connection_handler_destroyed_locked (connection, handler);
-
- link = _dbus_list_get_next_link (&handler->connections, link);
- }
-
- _dbus_list_clear (&handler->connections);
-
- dbus_free (handler);
- }
-}
-
-/**
- * Gets the user data for the handler (the same user data
- * passed to the handler function.)
- *
- * @param handler the handler
- * @returns the user data
- */
-void*
-dbus_message_handler_get_data (DBusMessageHandler *handler)
-{
- void* user_data;
-
- _dbus_return_val_if_fail (handler != NULL, NULL);
-
- _DBUS_LOCK (message_handler);
- user_data = handler->user_data;
- _DBUS_UNLOCK (message_handler);
- return user_data;
-}
-
-/**
- * Sets the user data for the handler (the same user data
- * to be passed to the handler function). Frees any previously-existing
- * user data with the previous free_user_data function.
- *
- * @param handler the handler
- * @param user_data the user data
- * @param free_user_data free function for the data
- */
-void
-dbus_message_handler_set_data (DBusMessageHandler *handler,
- void *user_data,
- DBusFreeFunction free_user_data)
-{
- DBusFreeFunction old_free_func;
- void *old_user_data;
-
- _dbus_return_if_fail (handler != NULL);
-
- _DBUS_LOCK (message_handler);
- old_free_func = handler->free_user_data;
- old_user_data = handler->user_data;
-
- handler->user_data = user_data;
- handler->free_user_data = free_user_data;
- _DBUS_UNLOCK (message_handler);
-
- if (old_free_func)
- (* old_free_func) (old_user_data);
-
-}
-
-/**
- * Sets the handler function. Call dbus_message_handler_set_data()
- * to set the user data for the function.
- *
- * @param handler the handler
- * @param function the function
- */
-void
-dbus_message_handler_set_function (DBusMessageHandler *handler,
- DBusHandleMessageFunction function)
-{
- _dbus_return_if_fail (handler != NULL);
-
- _DBUS_LOCK (message_handler);
- handler->function = function;
- _DBUS_UNLOCK (message_handler);
-}
-
-/** @} */
-
-#ifdef DBUS_BUILD_TESTS
-static DBusHandlerResult
-test_handler (DBusMessageHandler *handler,
- DBusConnection *connection,
- DBusMessage *message,
- void *user_data)
-{
- return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
-}
-
-static void
-free_test_data (void *data)
-{
- /* does nothing */
-}
-
-/**
- * @ingroup DBusMessageHandlerInternals
- * Unit test for DBusMessageHandler.
- *
- * @returns #TRUE on success.
- */
-dbus_bool_t
-_dbus_message_handler_test (const char *test_data_dir)
-{
- DBusMessageHandler *handler;
-
-#define TEST_DATA ((void*) 0xcafebabe)
-
- handler = dbus_message_handler_new (test_handler,
- TEST_DATA,
- free_test_data);
-
- _dbus_assert (handler != NULL);
- _dbus_assert (handler->function == test_handler);
-
- if (dbus_message_handler_get_data (handler) != TEST_DATA)
- _dbus_assert_not_reached ("got wrong data");
-
- dbus_message_handler_set_data (handler, NULL, NULL);
- if (dbus_message_handler_get_data (handler) != NULL)
- _dbus_assert_not_reached ("got wrong data after set");
-
- dbus_message_handler_set_function (handler, NULL);
- _dbus_assert (handler->function == NULL);
-
- dbus_message_handler_ref (handler);
- dbus_message_handler_unref (handler);
- dbus_message_handler_unref (handler);
-
- return TRUE;
-}
-#endif /* DBUS_BUILD_TESTS */
diff --git a/dbus/dbus-message-handler.h b/dbus/dbus-message-handler.h
deleted file mode 100644
index dac015ac..00000000
--- a/dbus/dbus-message-handler.h
+++ /dev/null
@@ -1,59 +0,0 @@
-/* -*- mode: C; c-file-style: "gnu" -*- */
-/* dbus-message-handler.h Sender/receiver of messages.
- *
- * Copyright (C) 2002 Red Hat Inc.
- *
- * Licensed under the Academic Free License version 1.2
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- *
- */
-#if !defined (DBUS_INSIDE_DBUS_H) && !defined (DBUS_COMPILATION)
-#error "Only <dbus/dbus.h> can be included directly, this file may disappear or change contents."
-#endif
-
-#ifndef DBUS_MESSAGE_HANDLER_H
-#define DBUS_MESSAGE_HANDLER_H
-
-#include <dbus/dbus-macros.h>
-#include <dbus/dbus-types.h>
-#include <dbus/dbus-connection.h>
-
-DBUS_BEGIN_DECLS;
-
-typedef DBusHandlerResult (* DBusHandleMessageFunction) (DBusMessageHandler *handler,
- DBusConnection *connection,
- DBusMessage *message,
- void *user_data);
-
-DBusMessageHandler* dbus_message_handler_new (DBusHandleMessageFunction function,
- void *user_data,
- DBusFreeFunction free_user_data);
-
-
-void dbus_message_handler_ref (DBusMessageHandler *handler);
-void dbus_message_handler_unref (DBusMessageHandler *handler);
-
-
-void* dbus_message_handler_get_data (DBusMessageHandler *handler);
-void dbus_message_handler_set_data (DBusMessageHandler *handler,
- void *data,
- DBusFreeFunction free_user_data);
-void dbus_message_handler_set_function (DBusMessageHandler *handler,
- DBusHandleMessageFunction function);
-
-DBUS_END_DECLS;
-
-#endif /* DBUS_MESSAGE_HANDLER_H */
diff --git a/dbus/dbus-test.c b/dbus/dbus-test.c
index 774a3138..b7a09a0e 100644
--- a/dbus/dbus-test.c
+++ b/dbus/dbus-test.c
@@ -135,12 +135,6 @@ dbus_internal_do_not_use_run_tests (const char *test_data_dir)
die ("messages");
check_memleaks ();
-
- printf ("%s: running message handler tests\n", "dbus-test");
- if (!_dbus_message_handler_test (test_data_dir))
- die ("message handler");
-
- check_memleaks ();
printf ("%s: running hash table tests\n", "dbus-test");
if (!_dbus_hash_test ())
diff --git a/dbus/dbus-test.h b/dbus/dbus-test.h
index cbbc8638..02b2c279 100644
--- a/dbus/dbus-test.h
+++ b/dbus/dbus-test.h
@@ -43,7 +43,6 @@ dbus_bool_t _dbus_mem_pool_test (void);
dbus_bool_t _dbus_string_test (void);
dbus_bool_t _dbus_address_test (void);
dbus_bool_t _dbus_message_test (const char *test_data_dir);
-dbus_bool_t _dbus_message_handler_test (const char *test_data_dir);
dbus_bool_t _dbus_auth_test (const char *test_data_dir);
dbus_bool_t _dbus_md5_test (void);
dbus_bool_t _dbus_sha_test (const char *test_data_dir);
diff --git a/dbus/dbus-threads.c b/dbus/dbus-threads.c
index b604a397..c5ce638f 100644
--- a/dbus/dbus-threads.c
+++ b/dbus/dbus-threads.c
@@ -226,7 +226,6 @@ init_global_locks (void)
LOCK_ADDR (server_slots),
LOCK_ADDR (message_slots),
LOCK_ADDR (atomic),
- LOCK_ADDR (message_handler),
LOCK_ADDR (bus),
LOCK_ADDR (shutdown_funcs),
LOCK_ADDR (system_users)
diff --git a/dbus/dbus.h b/dbus/dbus.h
index 051cb5fa..99eee18c 100644
--- a/dbus/dbus.h
+++ b/dbus/dbus.h
@@ -37,7 +37,6 @@
#include <dbus/dbus-errors.h>
#include <dbus/dbus-macros.h>
#include <dbus/dbus-message.h>
-#include <dbus/dbus-message-handler.h>
#include <dbus/dbus-pending-call.h>
#include <dbus/dbus-protocol.h>
#include <dbus/dbus-server.h>
diff --git a/glib/test-profile.c b/glib/test-profile.c
index 3eac1618..6d9d8e7f 100644
--- a/glib/test-profile.c
+++ b/glib/test-profile.c
@@ -63,8 +63,7 @@ send_echo_message (DBusConnection *connection)
}
static DBusHandlerResult
-client_filter (DBusMessageHandler *handler,
- DBusConnection *connection,
+client_filter (DBusConnection *connection,
DBusMessage *message,
void *user_data)
{
@@ -99,7 +98,6 @@ thread_func (void *data)
DBusError error;
GMainContext *context;
GMainLoop *loop;
- DBusMessageHandler *handler;
DBusConnection *connection;
int iterations;
@@ -116,14 +114,9 @@ thread_func (void *data)
iterations = 1;
- handler = dbus_message_handler_new (client_filter,
- &iterations, NULL);
-
if (!dbus_connection_add_filter (connection,
- handler))
+ client_filter, &iterations, NULL))
g_error ("no memory");
-
- /* FIXME we leak the handler */
context = g_main_context_new ();
loop = g_main_loop_new (context, FALSE);
@@ -145,8 +138,7 @@ thread_func (void *data)
}
static DBusHandlerResult
-server_filter (DBusMessageHandler *handler,
- DBusConnection *connection,
+server_filter (DBusConnection *connection,
DBusMessage *message,
void *user_data)
{
@@ -172,17 +164,12 @@ static void
new_connection_callback (DBusServer *server,
DBusConnection *new_connection,
void *user_data)
-{
- DBusMessageHandler *handler;
-
+{
dbus_connection_ref (new_connection);
dbus_connection_setup_with_g_main (new_connection, NULL);
-
- handler = dbus_message_handler_new (server_filter,
- NULL, NULL);
if (!dbus_connection_add_filter (new_connection,
- handler))
+ server_filter, NULL, NULL))
g_error ("no memory");
diff --git a/glib/test-thread-server.c b/glib/test-thread-server.c
index 33652f8c..8898ca7f 100644
--- a/glib/test-thread-server.c
+++ b/glib/test-thread-server.c
@@ -25,13 +25,8 @@ thread_test_data_free (ThreadTestData *data)
g_free (data);
}
-static DBusMessageHandler *disconnect_handler;
-static DBusMessageHandler *filter_handler;
-static dbus_int32_t handler_slot = -1;
-
static DBusHandlerResult
-handle_test_message (DBusMessageHandler *handler,
- DBusConnection *connection,
+filter_test_message (DBusConnection *connection,
DBusMessage *message,
void *user_data)
{
@@ -132,17 +127,7 @@ handle_test_message (DBusMessageHandler *handler,
}
static DBusHandlerResult
-handle_filter (DBusMessageHandler *handler,
- DBusConnection *connection,
- DBusMessage *message,
- void *user_data)
-{
- return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
-}
-
-static DBusHandlerResult
-handle_disconnect (DBusMessageHandler *handler,
- DBusConnection *connection,
+filter_disconnect (DBusConnection *connection,
DBusMessage *message,
void *user_data)
{
@@ -161,7 +146,6 @@ new_connection_callback (DBusServer *server,
DBusConnection *new_connection,
void *user_data)
{
- DBusMessageHandler *test_message_handler;
ThreadTestData * data;
g_print ("new_connection_callback\n");
@@ -171,26 +155,13 @@ new_connection_callback (DBusServer *server,
data = thread_test_data_new ();
- test_message_handler =
- dbus_message_handler_new (handle_test_message,
- data, (DBusFreeFunction)thread_test_data_free);
-
if (!dbus_connection_add_filter (new_connection,
- test_message_handler))
- goto nomem;
-
- if (!dbus_connection_set_data (new_connection,
- handler_slot,
- test_message_handler,
- (DBusFreeFunction)dbus_message_handler_unref))
+ filter_test_message, data,
+ (DBusFreeFunction) thread_test_data_free))
goto nomem;
if (!dbus_connection_add_filter (new_connection,
- disconnect_handler))
- goto nomem;
-
- if (!dbus_connection_add_filter (new_connection,
- filter_handler))
+ filter_disconnect, NULL, NULL))
goto nomem;
return;
@@ -224,19 +195,6 @@ main (int argc, char *argv[])
dbus_error_free (&error);
return 1;
}
-
- if (!dbus_connection_allocate_data_slot (&handler_slot))
- g_error ("no memory for data slot");
-
- filter_handler =
- dbus_message_handler_new (handle_filter, NULL, NULL);
- if (filter_handler == NULL)
- g_error ("no memory for handler");
-
- disconnect_handler =
- dbus_message_handler_new (handle_disconnect, NULL, NULL);
- if (disconnect_handler == NULL)
- g_error ("no memory for handler");
dbus_server_set_new_connection_function (server,
new_connection_callback,
diff --git a/test/test-service.c b/test/test-service.c
index 533f94ae..f22b1753 100644
--- a/test/test-service.c
+++ b/test/test-service.c
@@ -72,8 +72,7 @@ handle_echo (DBusConnection *connection,
}
static DBusHandlerResult
-filter_func (DBusMessageHandler *handler,
- DBusConnection *connection,
+filter_func (DBusConnection *connection,
DBusMessage *message,
void *user_data)
{
@@ -104,7 +103,6 @@ main (int argc,
{
DBusConnection *connection;
DBusError error;
- DBusMessageHandler *handler;
int result;
dbus_error_init (&error);
@@ -124,11 +122,8 @@ main (int argc,
if (!test_connection_setup (loop, connection))
die ("No memory\n");
- handler = dbus_message_handler_new (filter_func, NULL, NULL);
- if (handler == NULL)
- die ("No memory");
-
- if (!dbus_connection_add_filter (connection, handler))
+ if (!dbus_connection_add_filter (connection,
+ filter_func, NULL, NULL))
die ("No memory");
result = dbus_bus_acquire_service (connection, "org.freedesktop.DBus.TestSuiteEchoService",
@@ -145,10 +140,10 @@ main (int argc,
_dbus_loop_run (loop);
test_connection_shutdown (loop, connection);
+
+ dbus_connection_remove_filter (connection, filter_func, NULL);
dbus_connection_unref (connection);
-
- dbus_message_handler_unref (handler);
_dbus_loop_unref (loop);
loop = NULL;
diff --git a/tools/dbus-monitor.c b/tools/dbus-monitor.c
index c7293abb..23ee346a 100644
--- a/tools/dbus-monitor.c
+++ b/tools/dbus-monitor.c
@@ -30,10 +30,9 @@
#include "dbus-print-message.h"
static DBusHandlerResult
-handler_func (DBusMessageHandler *handler,
- DBusConnection *connection,
- DBusMessage *message,
- void *user_data)
+filter_func (DBusConnection *connection,
+ DBusMessage *message,
+ void *user_data)
{
print_message (message);
@@ -58,7 +57,6 @@ main (int argc, char *argv[])
DBusConnection *connection;
DBusError error;
DBusBusType type = DBUS_BUS_SESSION;
- DBusMessageHandler *handler;
GMainLoop *loop;
int i;
@@ -96,8 +94,7 @@ main (int argc, char *argv[])
dbus_connection_setup_with_g_main (connection, NULL);
- handler = dbus_message_handler_new (handler_func, NULL, NULL);
- dbus_connection_add_filter (connection, handler);
+ dbus_connection_add_filter (connection, filter_func, NULL, NULL);
g_main_loop_run (loop);