dbus/dbus dbus-connection.c, 1.103, 1.104 dbus-connection.h, 1.35,
1.36 dbus-message-util.c, 1.8, 1.9 dbus-server.c, 1.41, 1.42
Havoc Pennington
hp at freedesktop.org
Sat Apr 9 16:51:00 PDT 2005
Update of /cvs/dbus/dbus/dbus
In directory gabe:/tmp/cvs-serv3903/dbus
Modified Files:
dbus-connection.c dbus-connection.h dbus-message-util.c
dbus-server.c
Log Message:
2005-04-09 Havoc Pennington <hp at redhat.com>
* dbus/dbus-message-util.c (_dbus_message_test): fix signedness warning
* glib/dbus-glib-tool.c (main): fix warning
* glib/dbus-binding-tool-glib.c (generate_glue): fix warning
* dbus/dbus-connection.c (dbus_connection_read_write_dispatch):
add a new function that can be used in simple applications that
don't have a main loop and are willing to block
Index: dbus-connection.c
===================================================================
RCS file: /cvs/dbus/dbus/dbus/dbus-connection.c,v
retrieving revision 1.103
retrieving revision 1.104
diff -u -d -r1.103 -r1.104
--- dbus-connection.c 11 Mar 2005 17:43:22 -0000 1.103
+++ dbus-connection.c 9 Apr 2005 23:50:58 -0000 1.104
@@ -2520,6 +2520,28 @@
}
/**
+ * When a function that blocks has been called with a timeout, and we
+ * run out of memory, the time to wait for memory is based on the
+ * timeout. If the caller was willing to block a long time we wait a
+ * relatively long time for memory, if they were only willing to block
+ * briefly then we retry for memory at a rapid rate.
+ *
+ * @timeout_milliseconds the timeout requested for blocking
+ */
+static void
+_dbus_memory_pause_based_on_timeout (int timeout_milliseconds)
+{
+ if (timeout_milliseconds == -1)
+ _dbus_sleep_milliseconds (1000);
+ else if (timeout_milliseconds < 100)
+ ; /* just busy loop */
+ else if (timeout_milliseconds <= 1000)
+ _dbus_sleep_milliseconds (timeout_milliseconds / 3);
+ else
+ _dbus_sleep_milliseconds (1000);
+}
+
+/**
* Blocks until a pending call times out or gets a reply.
*
* Does not re-enter the main loop or run filter/path-registered
@@ -2663,13 +2685,8 @@
* it.
*/
_dbus_verbose ("dbus_connection_send_with_reply_and_block() waiting for more memory\n");
-
- if (timeout_milliseconds < 100)
- ; /* just busy loop */
- else if (timeout_milliseconds <= 1000)
- _dbus_sleep_milliseconds (timeout_milliseconds / 3);
- else
- _dbus_sleep_milliseconds (1000);
+
+ _dbus_memory_pause_based_on_timeout (timeout_milliseconds);
}
else
{
@@ -2804,6 +2821,81 @@
}
/**
+ * This function is intended for use with applications that don't want
+ * to write a main loop and deal with #DBusWatch and #DBusTimeout. An
+ * example usage would be:
+ *
+ * @code
+ * while (dbus_connection_read_write_dispatch (connection, -1))
+ * ; // empty loop body
+ * @endcode
+ *
+ * In this usage you would normally have set up a filter function to look
+ * at each message as it is dispatched. The loop terminates when the last
+ * message from the connection (the disconnected signal) is processed.
+ *
+ * If there are messages to dispatch, this function will
+ * dbus_connection_dispatch() once, and return. If there are no
+ * messages to dispatch, this function will block until it can read or
+ * write, then read or write, then return.
+ *
+ * The way to think of this function is that it either makes some sort
+ * of progress, or it blocks.
+ *
+ * The return value indicates whether the disconnect message has been
+ * processed, NOT whether the connection is connected. This is
+ * important because even after disconnecting, you want to process any
+ * messages you received prior to the disconnect.
+ *
+ * @param connection the connection
+ * @param timeout_milliseconds max time to block or -1 for infinite
+ * @returns #TRUE if the disconnect message has not been processed
+ */
+dbus_bool_t
+dbus_connection_read_write_dispatch (DBusConnection *connection,
+ int timeout_milliseconds)
+{
+ DBusDispatchStatus dstatus;
+ dbus_bool_t dispatched_disconnected;
+
+ _dbus_return_val_if_fail (connection != NULL, FALSE);
+ _dbus_return_val_if_fail (timeout_milliseconds >= 0 || timeout_milliseconds == -1, FALSE);
+ dstatus = dbus_connection_get_dispatch_status (connection);
+
+ if (dstatus == DBUS_DISPATCH_DATA_REMAINS)
+ {
+ _dbus_verbose ("doing dispatch in %s\n", _DBUS_FUNCTION_NAME);
+ dbus_connection_dispatch (connection);
+ CONNECTION_LOCK (connection);
+ }
+ else if (dstatus == DBUS_DISPATCH_NEED_MEMORY)
+ {
+ _dbus_verbose ("pausing for memory in %s\n", _DBUS_FUNCTION_NAME);
+ _dbus_memory_pause_based_on_timeout (timeout_milliseconds);
+ CONNECTION_LOCK (connection);
+ }
+ else
+ {
+ CONNECTION_LOCK (connection);
+ if (_dbus_connection_get_is_connected_unlocked (connection))
+ {
+ _dbus_verbose ("doing iteration in %s\n", _DBUS_FUNCTION_NAME);
+ _dbus_connection_do_iteration_unlocked (connection,
+ DBUS_ITERATION_DO_READING |
+ DBUS_ITERATION_DO_WRITING |
+ DBUS_ITERATION_BLOCK,
+ timeout_milliseconds);
+ }
+ }
+
+ HAVE_LOCK_CHECK (connection);
+ dispatched_disconnected = connection->n_incoming == 0 &&
+ connection->disconnect_message_link == NULL;
+ CONNECTION_UNLOCK (connection);
+ return !dispatched_disconnected; /* TRUE if we have not processed disconnected */
+}
+
+/**
* Returns the first-received message from the incoming message queue,
* leaving it in the queue. If the queue is empty, returns #NULL.
*
Index: dbus-connection.h
===================================================================
RCS file: /cvs/dbus/dbus/dbus/dbus-connection.h,v
retrieving revision 1.35
retrieving revision 1.36
diff -u -d -r1.35 -r1.36
--- dbus-connection.h 26 Feb 2005 06:37:46 -0000 1.35
+++ dbus-connection.h 9 Apr 2005 23:50:58 -0000 1.36
@@ -99,6 +99,8 @@
void dbus_connection_set_exit_on_disconnect (DBusConnection *connection,
dbus_bool_t exit_on_disconnect);
void dbus_connection_flush (DBusConnection *connection);
+dbus_bool_t dbus_connection_read_write_dispatch (DBusConnection *connection,
+ int timeout_milliseconds);
DBusMessage* dbus_connection_borrow_message (DBusConnection *connection);
void dbus_connection_return_message (DBusConnection *connection,
DBusMessage *message);
Index: dbus-message-util.c
===================================================================
RCS file: /cvs/dbus/dbus/dbus/dbus-message-util.c,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -d -r1.8 -r1.9
--- dbus-message-util.c 10 Feb 2005 23:17:27 -0000 1.8
+++ dbus-message-util.c 9 Apr 2005 23:50:58 -0000 1.9
@@ -715,7 +715,7 @@
double v_DOUBLE;
dbus_bool_t our_bool;
unsigned char our_byte_1, our_byte_2;
- const dbus_int32_t *our_uint32_array = (void*)0xdeadbeef;
+ const dbus_uint32_t *our_uint32_array = (void*)0xdeadbeef;
int our_uint32_array_len;
dbus_int32_t *our_int32_array = (void*)0xdeadbeef;
int our_int32_array_len;
@@ -911,14 +911,14 @@
const char *name2;
const dbus_uint32_t our_uint32_array[] =
{ 0x12345678, 0x23456781, 0x34567812, 0x45678123 };
- const dbus_uint32_t our_int32_array[] =
+ const dbus_int32_t our_int32_array[] =
{ 0x12345678, -0x23456781, 0x34567812, -0x45678123 };
const dbus_uint32_t *v_ARRAY_UINT32 = our_uint32_array;
const dbus_int32_t *v_ARRAY_INT32 = our_int32_array;
#ifdef DBUS_HAVE_INT64
const dbus_uint64_t our_uint64_array[] =
{ 0x12345678, 0x23456781, 0x34567812, 0x45678123 };
- const dbus_uint64_t our_int64_array[] =
+ const dbus_int64_t our_int64_array[] =
{ 0x12345678, -0x23456781, 0x34567812, -0x45678123 };
const dbus_uint64_t *v_ARRAY_UINT64 = our_uint64_array;
const dbus_int64_t *v_ARRAY_INT64 = our_int64_array;
Index: dbus-server.c
===================================================================
RCS file: /cvs/dbus/dbus/dbus/dbus-server.c,v
retrieving revision 1.41
retrieving revision 1.42
diff -u -d -r1.41 -r1.42
--- dbus-server.c 26 Feb 2005 06:37:46 -0000 1.41
+++ dbus-server.c 9 Apr 2005 23:50:58 -0000 1.42
@@ -129,7 +129,7 @@
init_guid (&server->guid);
- _dbus_string_init_const_len (&guid_raw, server->guid.as_bytes,
+ _dbus_string_init_const_len (&guid_raw, (signed char*) server->guid.as_bytes,
sizeof (server->guid.as_bytes));
if (!_dbus_string_hex_encode (&guid_raw, 0,
&server->guid_hex,
More information about the dbus-commit
mailing list