2005-04-09 Havoc Pennington <hp@redhat.com>
authorHavoc Pennington <hp@redhat.com>
Sat, 9 Apr 2005 23:50:58 +0000 (23:50 +0000)
committerHavoc Pennington <hp@redhat.com>
Sat, 9 Apr 2005 23:50:58 +0000 (23:50 +0000)
* 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

ChangeLog
dbus/dbus-connection.c
dbus/dbus-connection.h
dbus/dbus-message-util.c
dbus/dbus-server.c
glib/dbus-binding-tool-glib.c
glib/dbus-glib-tool.c

index 7001313..26017dc 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,16 @@
+2005-04-09  Havoc Pennington  <hp@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
+
 2005-04-05  David Zeuthen  <davidz@redhat.com>
 
        Fix https://bugs.freedesktop.org/show_bug.cgi?id=2889
index a08aa36..df8de93 100644 (file)
@@ -2520,6 +2520,28 @@ check_for_reply_unlocked (DBusConnection *connection,
 }
 
 /**
+ * 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 @@ _dbus_connection_block_pending_call (DBusPendingCall *pending)
            * 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 @@ dbus_connection_flush (DBusConnection *connection)
 }
 
 /**
+ * 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 0dc1b61..2c0b7f2 100644 (file)
@@ -99,6 +99,8 @@ dbus_bool_t        dbus_connection_get_is_authenticated         (DBusConnection
 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 e9540be..81034da 100644 (file)
@@ -715,7 +715,7 @@ verify_test_message (DBusMessage *message)
   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 @@ _dbus_message_test (const char *test_data_dir)
   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 0a3b522..d1ab496 100644 (file)
@@ -129,7 +129,7 @@ _dbus_server_init_base (DBusServer             *server,
 
   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,
index c78b9d5..75e2c73 100644 (file)
@@ -383,6 +383,9 @@ generate_glue (BaseInfo *base, DBusBindingToolCData *data, GError **error)
                  direction = 'O';
                  break;
                case ARG_INVALID:
+                default:
+                  g_assert_not_reached ();
+                  direction = 0; /* silence gcc */
                  break;
                }
              g_string_append_c (object_introspection_data_blob, direction);
index 85f78ed..1be0be7 100644 (file)
@@ -385,6 +385,7 @@ main (int argc, char **argv)
   else
     {
       channel = g_io_channel_unix_new (fileno (stdout));
+      output_file_tmp = NULL; /* silence gcc */
     }
   if (!g_io_channel_set_encoding (channel, NULL, &error))
     lose_gerror (_("Couldn't set channel encoding to NULL"), error);