test suite failure - more detail ...

Olivier Andrieu oliv__a at users.sourceforge.net
Thu Apr 15 09:34:28 EST 2004


 Havoc Pennington [Tue, 13 Apr 2004]:
 > On Tue, 2004-04-13 at 13:55, Havoc Pennington wrote:
 > > On Tue, 2004-04-13 at 08:10, Olivier Andrieu wrote:
 > > > 
 > > > Yes, except dbus_gproxy_new_for_service_owner doesn't do anything
 > > > right now and I'n not sure how it should be implemented. The
 > > > documentation mentions "making a round-trip request to the message bus
 > > > to get the current service owner" ; but what message should the client
 > > > send ? shouldn't there be some standardized message for this ?
 > > 
 > > Basically the bus should support a method GetServiceOwner I think.

OK, here is a patch implementing this method. new_for_service_owner()
uses it to obtain the base service and now `make check' passes !

It doesn't do the smart client-side tracking of the service ownership,
so new_for_service_owner always does a round-trip.

-- 
   Olivier
-------------- next part --------------
Index: test/glib/test-dbus-glib.c
===================================================================
RCS file: /cvs/dbus/dbus/test/glib/test-dbus-glib.c,v
retrieving revision 1.6
diff -u -r1.6 test-dbus-glib.c
--- a/test/glib/test-dbus-glib.c	13 Apr 2004 22:29:50 -0000	1.6
+++ b/test/glib/test-dbus-glib.c	14 Apr 2004 23:29:03 -0000
@@ -172,11 +172,20 @@
 
   /* Talk to the new service */
   
-  proxy = dbus_gproxy_new_for_service (connection,
-                                       "org.freedesktop.DBus.TestSuiteEchoService",
-                                       "/org/freedesktop/TestSuite",
-                                       "org.freedesktop.TestSuite");
+  proxy = dbus_gproxy_new_for_service_owner (connection,
+					     "org.freedesktop.DBus.TestSuiteEchoService",
+					     "/org/freedesktop/TestSuite",
+					     "org.freedesktop.TestSuite",
+					     &error);
   
+  if (proxy == NULL)
+    {
+      g_printerr ("Failed to create proxy for service owner: %s\n",
+                  error->message);
+      g_error_free (error);
+      exit (1);      
+    }
+
   call = dbus_gproxy_begin_call (proxy, "Echo",
                                  DBUS_TYPE_STRING,
                                  "my string hello",
Index: glib/dbus-gproxy.c
===================================================================
RCS file: /cvs/dbus/dbus/glib/dbus-gproxy.c,v
retrieving revision 1.8
diff -u -r1.8 dbus-gproxy.c
--- a/glib/dbus-gproxy.c	2 Dec 2003 10:44:21 -0000	1.8
+++ b/glib/dbus-gproxy.c	14 Apr 2004 23:29:04 -0000
@@ -932,12 +932,67 @@
                                    const char               *interface_name,
                                    GError                  **error)
 {
+  DBusGProxy *proxy;
+
+  DBusMessage *request, *reply;
+  DBusError derror;
+  char *base_service_name;
+
   g_return_val_if_fail (connection != NULL, NULL);
   g_return_val_if_fail (service_name != NULL, NULL);
   g_return_val_if_fail (path_name != NULL, NULL);
   g_return_val_if_fail (interface_name != NULL, NULL);
 
+  dbus_error_init (&derror);
+
+  proxy = NULL;
+  base_service_name = NULL;
+  reply = NULL;
+
+  request = dbus_message_new_method_call (DBUS_SERVICE_ORG_FREEDESKTOP_DBUS,
+					  DBUS_PATH_ORG_FREEDESKTOP_DBUS,
+					  DBUS_INTERFACE_ORG_FREEDESKTOP_DBUS,
+					  "GetServiceOwner");
+  if (request == NULL)
+    g_error ("Out of memory");
+  
+  if (! dbus_message_append_args (request, 
+				  DBUS_TYPE_STRING, service_name, 
+				  DBUS_TYPE_INVALID))
+    g_error ("Out of memory");
+
+  reply = dbus_connection_send_with_reply_and_block (connection, request,
+						     2000, &derror);
+  if (reply == NULL)
+    goto error;
+
+  if (dbus_set_error_from_message (&derror, reply))
+    goto error;
+
+  if (! dbus_message_get_args (reply, &derror, 
+			       DBUS_TYPE_STRING, &base_service_name, 
+			       DBUS_TYPE_INVALID))
+    goto error;
+      
+
+  proxy = dbus_gproxy_new (connection, base_service_name,
+                           path_name, interface_name);
+
+  goto out;
+
+ error:
+  g_assert (dbus_error_is_set (&derror));
+  dbus_set_g_error (error, &derror);
+  dbus_error_free (&derror);
 
+ out:
+  if (request)
+    dbus_message_unref (request);
+  if (reply)
+    dbus_message_unref (reply);
+  dbus_free (base_service_name);
+
+  return proxy;
 }
 
 /**
Index: doc/dbus-specification.xml
===================================================================
RCS file: /cvs/dbus/dbus/doc/dbus-specification.xml,v
retrieving revision 1.5
diff -u -r1.5 dbus-specification.xml
--- a/doc/dbus-specification.xml	16 Mar 2004 18:00:35 -0000	1.5
+++ b/doc/dbus-specification.xml	14 Apr 2004 23:29:10 -0000
@@ -2206,6 +2206,56 @@
 
       </sect3>
 
+      <sect3 id="bus-messages-get-service-owner">
+        <title><literal>org.freedesktop.DBus.GetServiceOwner</literal></title>
+        <para>
+          As a method:
+          <programlisting>
+            STRING GetServiceOwner (in STRING service_name)
+          </programlisting>
+          Message arguments:
+          <informaltable>
+            <tgroup cols="3">
+              <thead>
+                <row>
+                  <entry>Argument</entry>
+                  <entry>Type</entry>
+                  <entry>Description</entry>
+                </row>
+              </thead>
+              <tbody>
+                <row>
+                  <entry>0</entry>
+                  <entry>STRING</entry>
+                  <entry>Name of the service to query</entry>
+                </row>
+              </tbody>
+            </tgroup>
+          </informaltable>
+        Reply arguments:
+        <informaltable>
+          <tgroup cols="3">
+            <thead>
+              <row>
+                <entry>Argument</entry>
+                <entry>Type</entry>
+                <entry>Description</entry>
+              </row>
+            </thead>
+            <tbody>
+              <row>
+                <entry>0</entry>
+                <entry>STRING</entry>
+                <entry>Return value, a base service name</entry>
+              </row>
+            </tbody>
+          </tgroup>
+        </informaltable>
+        Returns the base service name of the primary owner of the
+        service in argument.
+       </para>
+      </sect3>
+
       <sect3 id="bus-messages-out-of-memory">
         <title><literal>org.freedesktop.DBus.Error.NoMemory</literal></title>
         <para>
Index: bus/driver.c
===================================================================
RCS file: /cvs/dbus/dbus/bus/driver.c,v
retrieving revision 1.46
diff -u -r1.46 driver.c
--- a/bus/driver.c	16 Mar 2004 18:00:34 -0000	1.46
+++ b/bus/driver.c	14 Apr 2004 23:29:13 -0000
@@ -756,6 +756,82 @@
   return FALSE;
 }
 
+static dbus_bool_t
+bus_driver_handle_get_service_owner (DBusConnection *connection,
+				     BusTransaction *transaction,
+				     DBusMessage    *message,
+				     DBusError      *error)
+{
+  char *text;
+  DBusString str;
+  BusRegistry *registry;
+  DBusConnection *service_connection;
+  BusService *service, *base_service;
+  DBusMessage *reply;
+  
+  _DBUS_ASSERT_ERROR_IS_CLEAR (error);
+
+  registry = bus_connection_get_registry (connection);
+
+  text = NULL;
+  reply = NULL;
+
+  if (! dbus_message_get_args (message, error,
+			       DBUS_TYPE_STRING, &text,
+			       DBUS_TYPE_INVALID))
+      goto failed;
+
+  _dbus_string_init_const (&str, text);
+  service = bus_registry_lookup (registry, &str);
+
+  if (service == NULL)
+    {
+      dbus_set_error (error, 
+		      DBUS_ERROR_SERVICE_DOES_NOT_EXIST,
+		      "Could not get owner of service '%s': no such service", text);
+      goto failed;
+    }
+
+  service_connection = bus_service_get_primary_owner (service);
+  _dbus_assert (service_connection);
+
+  base_service = bus_connection_get_base_service (service_connection);
+  if (base_service == NULL)
+    {
+      dbus_set_error (error,
+		      DBUS_ERROR_FAILED,
+		      "Could not determine base service for '%s'", text);
+      goto failed;
+    }
+
+  reply = dbus_message_new_method_return (message);
+  if (reply == NULL)
+    goto oom;
+
+  if (! dbus_message_append_args (reply, 
+				  DBUS_TYPE_STRING, bus_service_get_name (base_service),
+				  DBUS_TYPE_INVALID))
+    goto oom;
+  
+  if (! bus_transaction_send_from_driver (transaction, connection, reply))
+    goto oom;
+
+  dbus_message_unref (reply);
+  dbus_free (text);
+
+  return TRUE;
+
+ oom:
+  BUS_SET_OOM (error);
+
+ failed:
+  _DBUS_ASSERT_ERROR_IS_SET (error);
+  if (reply)
+    dbus_message_unref (reply);
+  dbus_free (text);
+  return FALSE;
+}
+
 /* For speed it might be useful to sort this in order of
  * frequency of use (but doesn't matter with only a few items
  * anyhow)
@@ -774,7 +850,8 @@
   { "ServiceExists", bus_driver_handle_service_exists },
   { "ListServices", bus_driver_handle_list_services },
   { "AddMatch", bus_driver_handle_add_match },
-  { "RemoveMatch", bus_driver_handle_remove_match }
+  { "RemoveMatch", bus_driver_handle_remove_match },
+  { "GetServiceOwner", bus_driver_handle_get_service_owner }
 };
 
 dbus_bool_t
Index: bus/connection.h
===================================================================
RCS file: /cvs/dbus/dbus/bus/connection.h,v
retrieving revision 1.19
diff -u -r1.19 connection.h
--- a/bus/connection.h	2 Dec 2003 10:44:21 -0000	1.19
+++ b/bus/connection.h	14 Apr 2004 23:29:13 -0000
@@ -94,6 +94,7 @@
                                                    BusService     *service);
 void        bus_connection_add_owned_service_link (DBusConnection *connection,
                                                    DBusList       *link);
+BusService *bus_connection_get_base_service       (DBusConnection *connection);
 int         bus_connection_get_n_services_owned   (DBusConnection *connection);
 
 /* called by driver.c */
Index: bus/connection.c
===================================================================
RCS file: /cvs/dbus/dbus/bus/connection.c,v
retrieving revision 1.53
diff -u -r1.53 connection.c
--- a/bus/connection.c	2 Dec 2003 10:44:21 -0000	1.53
+++ b/bus/connection.c	14 Apr 2004 23:29:24 -0000
@@ -1205,6 +1205,35 @@
   _dbus_assert (d->n_services_owned >= 0);
 }
 
+BusService *
+bus_connection_get_base_service (DBusConnection *connection)
+{
+  BusConnectionData *d;
+  DBusList *link;
+  BusService *base;
+
+  d = BUS_CONNECTION_DATA (connection);
+  _dbus_assert (d != NULL);
+
+  if (d->n_services_owned <= 0)
+    return NULL;
+
+  base = NULL;
+  link = d->services_owned;
+  while (link != NULL)
+    {
+      const char *name = bus_service_get_name (link->data);
+      if (name && *name == ':')
+	{
+	  base = link->data;
+	  break;
+	}
+      link = _dbus_list_get_next_link (&d->services_owned, link);
+    }
+  
+  return base;
+}
+
 int
 bus_connection_get_n_services_owned (DBusConnection *connection)
 {


More information about the dbus mailing list