summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAnders Carlsson <andersca@codefactory.se>2003-01-28 14:26:49 +0000
committerAnders Carlsson <andersca@codefactory.se>2003-01-28 14:26:49 +0000
commitdec1fa3bd5f106ba5b2c749372231e3dd4bf9e7b (patch)
tree9a579d3d5b908ee5712249b4de696b89a72ffca7
parentbec3c093cab742a953e39f1726c37345873990dc (diff)
2003-01-28 Anders Carlsson <set EMAIL_ADDRESS environment variable>
* dbus/dbus-connection-internal.h: * dbus/dbus-connection.c: (_dbus_connection_add_timeout), (_dbus_connection_remove_timeout): Add functions for adding and removing timeouts. * dbus/dbus-message.c: (dbus_message_new_from_message): Add new function that takes a message and creates an exact copy of it, but with the refcount set to 1. (check_message_handling): Fix build error. * dbus/dbus-server-protected.h: * dbus/dbus-server.c: (_dbus_server_init_base), (_dbus_server_finalize_base), (_dbus_server_add_timeout), (dbus_server_set_timeout_functions): (_dbus_server_remove_timeout): New functions so that a server can add and remove timeouts. (dbus_server_listen): Add commented out call to dbus_server_debug_new. * dbus/dbus-timeout.c: (_dbus_timeout_new): Actually set the handler, doh. * dbus/dbus-transport.c: (_dbus_transport_open): Add commented out call to dbus_transport_debug_client_new. * dbus/Makefile.am: Add dbus-transport-debug.[ch] and dbus-server-debug.[ch]
-rw-r--r--dbus/Makefile.am4
-rw-r--r--dbus/dbus-connection-internal.h4
-rw-r--r--dbus/dbus-connection.c36
-rw-r--r--dbus/dbus-message.c56
-rw-r--r--dbus/dbus-server-debug.c222
-rw-r--r--dbus/dbus-server-debug.h41
-rw-r--r--dbus/dbus-server-protected.h23
-rw-r--r--dbus/dbus-server.c57
-rw-r--r--dbus/dbus-timeout.c1
-rw-r--r--dbus/dbus-transport-debug.c312
-rw-r--r--dbus/dbus-transport-debug.h36
-rw-r--r--dbus/dbus-transport.c9
12 files changed, 786 insertions, 15 deletions
diff --git a/dbus/Makefile.am b/dbus/Makefile.am
index 322f86a7..b97ed6b9 100644
--- a/dbus/Makefile.am
+++ b/dbus/Makefile.am
@@ -32,6 +32,8 @@ libdbus_1_la_SOURCES= \
dbus-resources.h \
dbus-server.c \
dbus-server-protected.h \
+ dbus-server-debug.c \
+ dbus-server-debug.h \
dbus-server-unix.c \
dbus-server-unix.h \
dbus-test.c \
@@ -41,6 +43,8 @@ libdbus_1_la_SOURCES= \
dbus-threads.c \
dbus-transport.c \
dbus-transport.h \
+ dbus-transport-debug.c \
+ dbus-transport-debug.h \
dbus-transport-protected.h \
dbus-transport-unix.c \
dbus-transport-unix.h \
diff --git a/dbus/dbus-connection-internal.h b/dbus/dbus-connection-internal.h
index 6ad51191..ae94961b 100644
--- a/dbus/dbus-connection-internal.h
+++ b/dbus/dbus-connection-internal.h
@@ -50,6 +50,10 @@ dbus_bool_t _dbus_connection_add_watch (DBusConnection *connect
DBusWatch *watch);
void _dbus_connection_remove_watch (DBusConnection *connection,
DBusWatch *watch);
+dbus_bool_t _dbus_connection_add_timeout (DBusConnection *connection,
+ DBusTimeout *timeout);
+void _dbus_connection_remove_timeout (DBusConnection *connection,
+ DBusTimeout *timeout);
DBusConnection* _dbus_connection_new_for_transport (DBusTransport *transport);
void _dbus_connection_do_iteration (DBusConnection *connection,
diff --git a/dbus/dbus-connection.c b/dbus/dbus-connection.c
index be7384b2..4054f45f 100644
--- a/dbus/dbus-connection.c
+++ b/dbus/dbus-connection.c
@@ -223,6 +223,26 @@ _dbus_connection_remove_watch (DBusConnection *connection,
watch);
}
+dbus_bool_t
+_dbus_connection_add_timeout (DBusConnection *connection,
+ DBusTimeout *timeout)
+{
+ if (connection->timeouts) /* null during finalize */
+ return _dbus_timeout_list_add_timeout (connection->timeouts,
+ timeout);
+ else
+ return FALSE;
+}
+
+void
+_dbus_connection_remove_timeout (DBusConnection *connection,
+ DBusTimeout *timeout)
+{
+ if (connection->timeouts) /* null during finalize */
+ _dbus_timeout_list_remove_timeout (connection->timeouts,
+ timeout);
+}
+
/**
* Tells the connection that the transport has been disconnected.
* Results in calling the application disconnect callback.
@@ -498,7 +518,7 @@ dbus_connection_unref (DBusConnection *connection)
{
_dbus_assert (connection != NULL);
_dbus_assert (connection->refcount > 0);
-
+
connection->refcount -= 1;
if (connection->refcount == 0)
{
@@ -518,13 +538,13 @@ dbus_connection_unref (DBusConnection *connection)
_dbus_counter_unref (connection->connection_counter);
connection->connection_counter = NULL;
}
-
+
_dbus_watch_list_free (connection->watches);
connection->watches = NULL;
-
+
_dbus_timeout_list_free (connection->timeouts);
connection->timeouts = NULL;
-
+
_dbus_connection_free_data_slots (connection);
_dbus_hash_iter_init (connection->handler_table, &iter);
@@ -1036,8 +1056,14 @@ dbus_connection_set_watch_functions (DBusConnection *connection,
* The DBusTimeout can be queried for the timer interval using
* dbus_timeout_get_interval.
*
- * Once a timeout occurs, dbus_timeout_handle should be call to invoke
+ * Once a timeout occurs, dbus_timeout_handle should be called to invoke
* the timeout's callback.
+ *
+ * @param connection the connection.
+ * @param add_function function to add a timeout.
+ * @param remove_function function to remove a timeout.
+ * @param data data to pass to add_function and remove_function.
+ * @param free_data_function function to be called to free the data.
*/
void
dbus_connection_set_timeout_functions (DBusConnection *connection,
diff --git a/dbus/dbus-message.c b/dbus/dbus-message.c
index 08dc45e5..95baa7b2 100644
--- a/dbus/dbus-message.c
+++ b/dbus/dbus-message.c
@@ -721,6 +721,60 @@ dbus_message_new_reply (const char *name,
return message;
}
+DBusMessage *
+dbus_message_new_from_message (const DBusMessage *message)
+{
+ DBusMessage *retval;
+ int i;
+
+ retval = dbus_new0 (DBusMessage, 1);
+ if (retval == NULL)
+ return NULL;
+
+ retval->refcount = 1;
+ retval->byte_order = message->byte_order;
+
+ if (!_dbus_string_init (&retval->header, _DBUS_INT_MAX))
+ {
+ dbus_free (retval);
+ return NULL;
+ }
+
+ if (!_dbus_string_init (&retval->body, _DBUS_INT_MAX))
+ {
+ _dbus_string_free (&retval->header);
+ dbus_free (retval);
+ return NULL;
+ }
+
+ if (!_dbus_string_copy (&message->header, 0,
+ &retval->header, 0))
+ {
+ _dbus_string_free (&retval->header);
+ _dbus_string_free (&retval->body);
+ dbus_free (retval);
+
+ return NULL;
+ }
+
+ if (!_dbus_string_copy (&message->body, 0,
+ &retval->body, 0))
+ {
+ _dbus_string_free (&retval->header);
+ _dbus_string_free (&retval->body);
+ dbus_free (retval);
+
+ return NULL;
+ }
+
+ for (i = 0; i < FIELD_LAST; i++)
+ {
+ retval->header_fields[i].offset = message->header_fields[i].offset;
+ }
+
+ return retval;
+}
+
/**
* Increments the reference count of a DBusMessage.
@@ -2043,7 +2097,7 @@ check_message_handling (DBusMessage *message)
iter = NULL;
client_serial = _dbus_message_get_client_serial (message);
- _dbus_message_set_client_serial (message);
+ _dbus_message_set_client_serial (message, client_serial);
if (client_serial != _dbus_message_get_client_serial (message))
{
diff --git a/dbus/dbus-server-debug.c b/dbus/dbus-server-debug.c
new file mode 100644
index 00000000..b2e8c004
--- /dev/null
+++ b/dbus/dbus-server-debug.c
@@ -0,0 +1,222 @@
+/* -*- mode: C; c-file-style: "gnu" -*- */
+/* dbus-server-debug.h In-proc debug server implementation
+ *
+ * Copyright (C) 2003 CodeFactory AB
+ *
+ * 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-server-debug.h"
+#include "dbus-transport-debug.h"
+#include "dbus-connection-internal.h"
+#include "dbus-hash.h"
+
+#ifdef DBUS_BUILD_TESTS
+
+#define DEFAULT_INTERVAL 10
+
+typedef struct DBusServerDebug DBusServerDebug;
+
+/**
+ * Implementation details of DBusServerDebug. All members
+ * are private.
+ */
+struct DBusServerDebug
+{
+ DBusServer base; /**< Parent class members. */
+
+ char *name; /**< Server name. */
+};
+
+static DBusHashTable *server_hash;
+
+static void
+debug_finalize (DBusServer *server)
+{
+}
+
+static void
+debug_handle_watch (DBusServer *server,
+ DBusWatch *watch,
+ unsigned int flags)
+{
+}
+
+static void
+debug_disconnect (DBusServer *server)
+{
+}
+
+static DBusServerVTable debug_vtable = {
+ debug_finalize,
+ debug_handle_watch,
+ debug_disconnect
+};
+
+DBusServer*
+_dbus_server_debug_lookup (const char *server_name)
+{
+ if (!server_hash)
+ return NULL;
+
+ return _dbus_hash_table_lookup_string (server_hash, server_name);
+}
+
+DBusServer*
+_dbus_server_debug_new (const char *server_name,
+ DBusResultCode *result)
+{
+ DBusServerDebug *debug_server;
+
+ if (!server_hash)
+ {
+ server_hash = _dbus_hash_table_new (DBUS_HASH_STRING, NULL, NULL);
+
+ if (!server_hash)
+ {
+ dbus_set_result (result, DBUS_RESULT_NO_MEMORY);
+ return NULL;
+ }
+ }
+
+ if (_dbus_hash_table_lookup_string (server_hash, server_name) != NULL)
+ {
+ dbus_set_result (result, DBUS_RESULT_ADDRESS_IN_USE);
+ return NULL;
+ }
+
+ debug_server = dbus_new0 (DBusServerDebug, 1);
+
+ if (debug_server == NULL)
+ return NULL;
+
+ debug_server->name = _dbus_strdup (server_name);
+ if (debug_server->name == NULL)
+ {
+ dbus_free (debug_server->name);
+ dbus_free (debug_server);
+
+ dbus_set_result (result, DBUS_RESULT_NO_MEMORY);
+ }
+
+ if (!_dbus_server_init_base (&debug_server->base,
+ &debug_vtable))
+ {
+ dbus_free (debug_server->name);
+ dbus_free (debug_server);
+
+ dbus_set_result (result, DBUS_RESULT_NO_MEMORY);
+
+ return NULL;
+ }
+
+ if (!_dbus_hash_table_insert_string (server_hash,
+ debug_server->name,
+ debug_server))
+ {
+ _dbus_server_finalize_base (&debug_server->base);
+ dbus_free (debug_server->name);
+ dbus_free (debug_server);
+
+ dbus_set_result (result, DBUS_RESULT_NO_MEMORY);
+
+ return NULL;
+ }
+
+ dbus_set_result (result, DBUS_RESULT_SUCCESS);
+
+ return (DBusServer *)debug_server;
+}
+
+typedef struct
+{
+ DBusServer *server;
+ DBusTransport *transport;
+
+} ServerAndTransport;
+
+static void
+handle_new_client (void *data)
+{
+ ServerAndTransport *st = data;
+ DBusTransport *transport;
+ DBusConnection *connection;
+
+ transport = _dbus_transport_debug_server_new (st->transport);
+ if (transport == NULL)
+ {
+ return;
+ }
+
+ connection = _dbus_connection_new_for_transport (transport);
+ _dbus_transport_unref (transport);
+
+ if (connection == NULL)
+ return;
+
+ /* See if someone wants to handle this new connection,
+ * self-referencing for paranoia
+ */
+ if (st->server->new_connection_function)
+ {
+ dbus_server_ref (st->server);
+
+ (* st->server->new_connection_function) (st->server, connection,
+ st->server->new_connection_data);
+ dbus_server_unref (st->server);
+ }
+
+ /* If no one grabbed a reference, the connection will die. */
+ dbus_connection_unref (connection);
+}
+
+dbus_bool_t
+_dbus_server_debug_accept_transport (DBusServer *server,
+ DBusTransport *transport)
+{
+ DBusTimeout *timeout;
+ ServerAndTransport *st;
+
+ st = dbus_new (ServerAndTransport, 1);
+ if (st == NULL)
+ return FALSE;
+
+ st->transport = transport;
+ st->server = server;
+
+ timeout = _dbus_timeout_new (DEFAULT_INTERVAL, handle_new_client, st, dbus_free);
+
+ if (timeout == NULL)
+ {
+ dbus_free (st);
+ return FALSE;
+ }
+
+ if (!_dbus_server_add_timeout (server, timeout))
+ {
+ _dbus_timeout_unref (timeout);
+
+ return FALSE;
+ }
+
+ return TRUE;
+}
+
+#endif /* DBUS_BUILD_TESTS */
+
diff --git a/dbus/dbus-server-debug.h b/dbus/dbus-server-debug.h
new file mode 100644
index 00000000..6fff20c0
--- /dev/null
+++ b/dbus/dbus-server-debug.h
@@ -0,0 +1,41 @@
+/* -*- mode: C; c-file-style: "gnu" -*- */
+/* dbus-server-debug.h In-proc debug server implementation
+ *
+ * Copyright (C) 2003 CodeFactory AB
+ *
+ * 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
+ *
+ */
+#ifndef DBUS_SERVER_DEBUG_H
+#define DBUS_SERVER_DEBUG_H
+
+#include <dbus/dbus-internals.h>
+#include <dbus/dbus-server-protected.h>
+#include <dbus/dbus-transport.h>
+
+DBUS_BEGIN_DECLS;
+
+DBusServer* _dbus_server_debug_new (const char *server_name,
+ DBusResultCode *result);
+DBusServer* _dbus_server_debug_lookup (const char *server_name);
+dbus_bool_t _dbus_server_debug_accept_transport (DBusServer *server,
+ DBusTransport *transport);
+
+
+DBUS_END_DECLS;
+
+#endif /* DBUS_SERVER_DEBUG_H */
diff --git a/dbus/dbus-server-protected.h b/dbus/dbus-server-protected.h
index 5e1ad55e..f155bbb8 100644
--- a/dbus/dbus-server-protected.h
+++ b/dbus/dbus-server-protected.h
@@ -25,6 +25,7 @@
#include <dbus/dbus-internals.h>
#include <dbus/dbus-server.h>
+#include <dbus/dbus-timeout.h>
#include <dbus/dbus-watch.h>
#include <dbus/dbus-resources.h>
@@ -53,7 +54,8 @@ struct DBusServer
int refcount; /**< Reference count. */
const DBusServerVTable *vtable; /**< Virtual methods for this instance. */
DBusWatchList *watches; /**< Our watches */
-
+ DBusTimeoutList *timeouts; /**< Our timeouts */
+
DBusCounter *connection_counter; /**< Number of non-finalized DBusConnection
* to this server
*/
@@ -72,13 +74,18 @@ struct DBusServer
unsigned int disconnected : 1; /**< TRUE if we are disconnected. */
};
-dbus_bool_t _dbus_server_init_base (DBusServer *server,
- const DBusServerVTable *vtable);
-void _dbus_server_finalize_base (DBusServer *server);
-dbus_bool_t _dbus_server_add_watch (DBusServer *server,
- DBusWatch *watch);
-void _dbus_server_remove_watch (DBusServer *server,
- DBusWatch *watch);
+dbus_bool_t _dbus_server_init_base (DBusServer *server,
+ const DBusServerVTable *vtable);
+void _dbus_server_finalize_base (DBusServer *server);
+dbus_bool_t _dbus_server_add_watch (DBusServer *server,
+ DBusWatch *watch);
+void _dbus_server_remove_watch (DBusServer *server,
+ DBusWatch *watch);
+dbus_bool_t _dbus_server_add_timeout (DBusServer *server,
+ DBusTimeout *timeout);
+void _dbus_server_remove_timeout (DBusServer *server,
+ DBusTimeout *timeout);
+
DBUS_END_DECLS;
diff --git a/dbus/dbus-server.c b/dbus/dbus-server.c
index 83b1f578..1407c477 100644
--- a/dbus/dbus-server.c
+++ b/dbus/dbus-server.c
@@ -22,6 +22,9 @@
*/
#include "dbus-server.h"
#include "dbus-server-unix.h"
+#ifdef DBUS_BUILD_TESTS
+#include "dbus-server-debug.h"
+#endif
/**
* @defgroup DBusServer DBusServer
@@ -61,11 +64,22 @@ _dbus_server_init_base (DBusServer *server,
if (server->watches == NULL)
return FALSE;
+ server->timeouts = _dbus_timeout_list_new ();
+ if (server->timeouts == NULL)
+ {
+ _dbus_watch_list_free (server->watches);
+ server->watches = NULL;
+ return FALSE;
+ }
+
server->connection_counter = _dbus_counter_new ();
if (server->connection_counter == NULL)
{
_dbus_watch_list_free (server->watches);
server->watches = NULL;
+ _dbus_timeout_list_free (server->timeouts);
+ server->timeouts = NULL;
+
return FALSE;
}
@@ -89,6 +103,7 @@ _dbus_server_finalize_base (DBusServer *server)
dbus_server_disconnect (server);
_dbus_watch_list_free (server->watches);
+ _dbus_timeout_list_free (server->timeouts);
_dbus_counter_unref (server->connection_counter);
}
@@ -119,6 +134,19 @@ _dbus_server_remove_watch (DBusServer *server,
_dbus_watch_list_remove_watch (server->watches, watch);
}
+dbus_bool_t
+_dbus_server_add_timeout (DBusServer *server,
+ DBusTimeout *timeout)
+{
+ return _dbus_timeout_list_add_timeout (server->timeouts, timeout);
+}
+
+void
+_dbus_server_remove_timeout (DBusServer *server,
+ DBusTimeout *timeout)
+{
+ _dbus_timeout_list_remove_timeout (server->timeouts, timeout);
+}
/** @} */
@@ -160,8 +188,12 @@ dbus_server_listen (const char *address,
{
DBusServer *server;
+#if 1
/* For now just pretend the address is a unix domain socket path */
server = _dbus_server_new_for_domain_socket (address, result);
+#else
+ server = _dbus_server_debug_new (address, result);
+#endif
return server;
}
@@ -286,6 +318,31 @@ dbus_server_set_watch_functions (DBusServer *server,
}
/**
+ * Sets the timeout functions for the connection. These functions are
+ * responsible for making the application's main loop aware of timeouts.
+ *
+ * This function behaves exactly like dbus_connection_set_timeout_functions();
+ * see the documentation for that routine.
+ *
+ * @param server the server.
+ * @param add_function function to add a timeout.
+ * @param remove_function function to remove a timeout.
+ * @param data data to pass to add_function and remove_function.
+ * @param free_data_function function to be called to free the data.
+ */
+void
+dbus_server_set_timeout_functions (DBusServer *server,
+ DBusAddTimeoutFunction add_function,
+ DBusRemoveTimeoutFunction remove_function,
+ void *data,
+ DBusFreeFunction free_data_function)
+{
+ _dbus_timeout_list_set_functions (server->timeouts,
+ add_function, remove_function,
+ data, free_data_function);
+}
+
+/**
* Called to notify the server when a previously-added watch
* is ready for reading or writing, or has an exception such
* as a hangup.
diff --git a/dbus/dbus-timeout.c b/dbus/dbus-timeout.c
index 9aefbb40..379aeee3 100644
--- a/dbus/dbus-timeout.c
+++ b/dbus/dbus-timeout.c
@@ -66,6 +66,7 @@ _dbus_timeout_new (int interval,
timeout->refcount = 1;
timeout->interval = interval;
+ timeout->handler = handler;
timeout->handler_data = data;
timeout->free_handler_data_function = free_data_function;
diff --git a/dbus/dbus-transport-debug.c b/dbus/dbus-transport-debug.c
new file mode 100644
index 00000000..3277094f
--- /dev/null
+++ b/dbus/dbus-transport-debug.c
@@ -0,0 +1,312 @@
+/* -*- mode: C; c-file-style: "gnu" -*- */
+/* dbus-transport-debug.c In-proc debug subclass of DBusTransport
+ *
+ * Copyright (C) 2003 CodeFactory AB
+ *
+ * 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-connection-internal.h"
+#include "dbus-transport-protected.h"
+#include "dbus-transport-debug.h"
+#include "dbus-server-debug.h"
+#include "dbus-list.h"
+
+#ifdef DBUS_BUILD_TESTS
+
+
+#define DEFAULT_INTERVAL 10
+
+typedef struct DBusTransportDebug DBusTransportDebug;
+
+struct DBusTransportDebug
+{
+ DBusTransport base; /**< Parent instance */
+
+ DBusTimeout *write_timeout;
+ DBusTimeout *read_timeout;
+
+ DBusTransport *other_end;
+};
+
+static void
+debug_finalize (DBusTransport *transport)
+{
+ _dbus_transport_finalize_base (transport);
+
+ dbus_free (transport);
+}
+
+static void
+do_reading (DBusTransport *transport)
+{
+ printf ("in do reading!\n");
+
+ if (transport->disconnected)
+ return;
+
+ /* Now dispatch the messages */
+ while (dbus_connection_dispatch_message (transport->connection));
+}
+
+static void
+check_read_timeout (DBusTransport *transport)
+{
+ DBusTransportDebug *debug_transport = (DBusTransportDebug*) transport;
+ dbus_bool_t need_read_timeout;
+
+ if (transport->connection == NULL)
+ return;
+
+ _dbus_transport_ref (transport);
+
+ need_read_timeout = dbus_connection_get_n_messages (transport->connection) > 0;
+
+ if (transport->disconnected)
+ need_read_timeout = FALSE;
+
+ if (need_read_timeout &&
+ debug_transport->read_timeout == NULL)
+ {
+ debug_transport->read_timeout =
+ _dbus_timeout_new (DEFAULT_INTERVAL, (DBusTimeoutHandler)do_reading,
+ transport, NULL);
+
+ if (debug_transport->read_timeout == NULL)
+ goto out;
+
+ if (!_dbus_connection_add_timeout (transport->connection,
+ debug_transport->read_timeout))
+ {
+ _dbus_timeout_unref (debug_transport->read_timeout);
+ debug_transport->read_timeout = NULL;
+
+ goto out;
+ }
+ }
+ else if (!need_read_timeout &&
+ debug_transport->read_timeout != NULL)
+ {
+ _dbus_connection_remove_timeout (transport->connection,
+ debug_transport->read_timeout);
+ _dbus_timeout_unref (debug_transport->read_timeout);
+ debug_transport->read_timeout = NULL;
+ }
+
+ out:
+ _dbus_transport_unref (transport);
+}
+
+static void
+do_writing (DBusTransport *transport)
+{
+ if (transport->disconnected)
+ return;
+
+ while (!transport->disconnected &&
+ _dbus_connection_have_messages_to_send (transport->connection))
+ {
+ DBusMessage *message, *copy;
+
+ message = _dbus_connection_get_message_to_send (transport->connection);
+ _dbus_message_lock (message);
+
+ copy = dbus_message_new_from_message (message);
+
+ _dbus_connection_message_sent (transport->connection,
+ message);
+
+ _dbus_connection_queue_received_message (((DBusTransportDebug *)transport)->other_end->connection,
+ copy);
+
+ }
+
+ check_read_timeout (((DBusTransportDebug *)transport)->other_end);
+}
+
+static void
+check_write_timeout (DBusTransport *transport)
+{
+ DBusTransportDebug *debug_transport = (DBusTransportDebug *)transport;
+ dbus_bool_t need_write_timeout;
+
+ if (transport->connection == NULL)
+ return;
+
+ _dbus_transport_ref (transport);
+
+ need_write_timeout = transport->messages_need_sending;
+
+ if (transport->disconnected)
+ need_write_timeout = FALSE;
+
+ if (need_write_timeout &&
+ debug_transport->write_timeout == NULL)
+ {
+ debug_transport->write_timeout =
+ _dbus_timeout_new (DEFAULT_INTERVAL, (DBusTimeoutHandler)do_writing,
+ transport, NULL);
+
+ if (debug_transport->write_timeout == NULL)
+ goto out;
+
+ if (!_dbus_connection_add_timeout (transport->connection,
+ debug_transport->write_timeout))
+ {
+ _dbus_timeout_unref (debug_transport->write_timeout);
+ debug_transport->write_timeout = NULL;
+ }
+ }
+ else if (!need_write_timeout &&
+ debug_transport->write_timeout != NULL)
+ {
+ _dbus_connection_remove_timeout (transport->connection,
+ debug_transport->write_timeout);
+ _dbus_timeout_unref (debug_transport->write_timeout);
+ debug_transport->write_timeout = NULL;
+ }
+
+ out:
+ _dbus_transport_unref (transport);
+}
+
+static void
+debug_handle_watch (DBusTransport *transport,
+ DBusWatch *watch,
+ unsigned int flags)
+{
+}
+
+static void
+debug_disconnect (DBusTransport *transport)
+{
+}
+
+static void
+debug_connection_set (DBusTransport *transport)
+{
+}
+
+static void
+debug_messages_pending (DBusTransport *transport,
+ int messages_pending)
+{
+ check_write_timeout (transport);
+ printf ("messages pending!: %d\n", messages_pending);
+}
+
+static void
+debug_do_iteration (DBusTransport *transport,
+ unsigned int flags,
+ int timeout_milliseconds)
+{
+ printf ("do iteration: %d %d!!\n", transport->is_server,
+ flags);
+}
+
+static void
+debug_live_messages_changed (DBusTransport *transport)
+{
+}
+
+static DBusTransportVTable debug_vtable = {
+ debug_finalize,
+ debug_handle_watch,
+ debug_disconnect,
+ debug_connection_set,
+ debug_messages_pending,
+ debug_do_iteration,
+ debug_live_messages_changed
+};
+
+DBusTransport*
+_dbus_transport_debug_server_new (DBusTransport *client)
+{
+ DBusTransportDebug *debug_transport;
+
+ debug_transport = dbus_new0 (DBusTransportDebug, 1);
+
+ if (debug_transport == NULL)
+ return NULL;
+
+ if (!_dbus_transport_init_base (&debug_transport->base,
+ &debug_vtable,
+ TRUE))
+ {
+ dbus_free (debug_transport);
+ return NULL;
+ }
+
+ debug_transport->base.authenticated = TRUE;
+
+ /* Connect the two transports */
+ debug_transport->other_end = client;
+ ((DBusTransportDebug *)client)->other_end = (DBusTransport *)debug_transport;
+
+ return (DBusTransport *)debug_transport;
+}
+
+DBusTransport*
+_dbus_transport_debug_client_new (const char *server_name,
+ DBusResultCode *result)
+{
+ DBusServer *debug_server;
+ DBusTransportDebug *debug_transport;
+
+ debug_server = _dbus_server_debug_lookup (server_name);
+
+ if (!debug_server)
+ {
+ dbus_set_result (result, DBUS_RESULT_NO_SERVER);
+ return NULL;
+ }
+
+ debug_transport = dbus_new0 (DBusTransportDebug, 1);
+ if (debug_transport == NULL)
+ {
+ dbus_set_result (result, DBUS_RESULT_NO_MEMORY);
+ return NULL;
+ }
+
+ if (!_dbus_transport_init_base (&debug_transport->base,
+ &debug_vtable,
+ FALSE))
+ {
+ dbus_free (debug_transport);
+ dbus_set_result (result, DBUS_RESULT_NO_MEMORY);
+ return NULL;
+ }
+
+ if (!_dbus_server_debug_accept_transport (debug_server, (DBusTransport *)debug_transport))
+ {
+ _dbus_transport_finalize_base (&debug_transport->base);
+
+ dbus_free (debug_transport);
+ dbus_set_result (result, DBUS_RESULT_IO_ERROR);
+ return NULL;
+
+ }
+
+ /* FIXME: Prolly wrong to do this. */
+ debug_transport->base.authenticated = TRUE;
+
+ return (DBusTransport *)debug_transport;
+}
+
+#endif /* DBUS_BUILD_TESTS */
diff --git a/dbus/dbus-transport-debug.h b/dbus/dbus-transport-debug.h
new file mode 100644
index 00000000..fd4a945c
--- /dev/null
+++ b/dbus/dbus-transport-debug.h
@@ -0,0 +1,36 @@
+/* -*- mode: C; c-file-style: "gnu" -*- */
+/* dbus-transport-debug.h Debug in-proc subclass of DBusTransport
+ *
+ * Copyright (C) 2003 CodeFactory AB
+ *
+ * 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
+ *
+ */
+#ifndef DBUS_TRANSPORT_DEBUG_H
+#define DBUS_TRANSPORT_DEBUG_H
+
+#include <dbus/dbus-transport.h>
+
+DBUS_BEGIN_DECLS;
+
+DBusTransport* _dbus_transport_debug_server_new (DBusTransport *client);
+DBusTransport* _dbus_transport_debug_client_new (const char *server_name,
+ DBusResultCode *result);
+
+DBUS_END_DECLS;
+
+#endif /* DBUS_TRANSPORT_DEBUG_H */
diff --git a/dbus/dbus-transport.c b/dbus/dbus-transport.c
index 9b367dcd..d1f31702 100644
--- a/dbus/dbus-transport.c
+++ b/dbus/dbus-transport.c
@@ -26,6 +26,9 @@
#include "dbus-connection-internal.h"
#include "dbus-watch.h"
#include "dbus-auth.h"
+#ifdef DBUS_BUILD_TESTS
+#include "dbus-transport-debug.h"
+#endif
/**
* @defgroup DBusTransport DBusTransport object
@@ -197,11 +200,15 @@ _dbus_transport_open (const char *address,
* appropriate transport.
*/
+#if 1
/* Pretend it's just a unix domain socket name for now */
transport = _dbus_transport_new_for_domain_socket (address,
FALSE,
result);
-
+#else
+ transport = _dbus_transport_debug_client_new (address,
+ result);
+#endif
return transport;
}