api addition for activation

James Willcox jwillcox@cs.indiana.edu
12 May 2003 17:47:00 -0500


--=-VlUsNtBcVvHXFpcAs0Ew
Content-Type: multipart/mixed; boundary="=-MdCWC4ixyAt1m/rZGl+z"


--=-MdCWC4ixyAt1m/rZGl+z
Content-Type: text/plain
Content-Transfer-Encoding: quoted-printable

On Mon, 2003-05-12 at 16:53, Havoc Pennington wrote:
> On Sun, May 11, 2003 at 11:28:15PM -0500, James Willcox wrote:
> > Hi,
> >=20
> > Here's a small addition adding dbus_bus_activate_service().  It also
> > adds a servicedir tag to session.conf.in.  Ok to commit?
> >=20
> =20
> +  <servicedir>@prefix@/lib/dbus-1.0/services</servicedir>
> +
>=20
> This should be @libdir@/dbus-1.0 in case someone does --libdir
>=20
> Well, more specifically you have to do the EXPANDED_LIBDIR thing done=20
> in a couple other places.
>=20
> +  dbus_message_append_args (msg, DBUS_TYPE_STRING, service_name,
> +      			    DBUS_TYPE_UINT32, 0, 0);
>=20
> termination should be DBUS_TYPE_INVALID rather than 0 IMHO.
> There are probably existing places where this could be fixed.
> =20
> +dbus_bool_t     dbus_bus_activate_service (DBusConnection *connection,
> +					   const char     *service_name,
> +					   DBusError      *error);
>=20
> There's a uint32 out param for activate service that should probably
> be here.

Ok, fixed the above.  New patch attached.

Thanks,
James

--=-MdCWC4ixyAt1m/rZGl+z
Content-Disposition: attachment; filename=dbus_jwillcox_activate_service_v2.diff
Content-Transfer-Encoding: quoted-printable
Content-Type: text/x-patch; name=dbus_jwillcox_activate_service_v2.diff; charset=UTF-8

Index: ChangeLog
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
RCS file: /home/freedesktop/dbus/ChangeLog,v
retrieving revision 1.355
diff -u -r1.355 ChangeLog
--- ChangeLog	12 May 2003 02:44:44 -0000	1.355
+++ ChangeLog	12 May 2003 22:42:11 -0000
@@ -1,3 +1,22 @@
+2003-05-12  James Willcox  <jwillcox@gnome.org>
+
+	* configure.in:
+	* bus/activation.c: (bus_activation_service_created),
+	(bus_activation_activate_service):
+	* bus/driver.c: (bus_driver_send_service_deleted),
+	(bus_driver_send_service_created), (bus_driver_send_service_lost),
+	(bus_driver_send_service_acquired),
+	(bus_driver_send_welcome_message),
+	(bus_driver_handle_list_services):
+	* bus/session.conf.in:
+	* dbus/dbus-bus.c: (dbus_bus_acquire_service),
+	(dbus_bus_service_exists), (dbus_bus_activate_service):
+	* dbus/dbus-bus.h:
+
+	Add some convenience API which lets you activate a service, and did a
+	bunch of s/0/DBUS_TYPE_INVALID/ in calls to dbus_message_append_args()
+	and dbus_message_get_args()
+
 2003-05-11  Havoc Pennington  <hp@pobox.com>
=20
 	* dbus/dbus-marshal.c (_dbus_marshal_validate_arg): fix to avoid=20
Index: configure.in
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
RCS file: /home/freedesktop/dbus/configure.in,v
retrieving revision 1.59
diff -u -r1.59 configure.in
--- configure.in	11 May 2003 07:59:08 -0000	1.59
+++ configure.in	12 May 2003 22:42:18 -0000
@@ -630,6 +630,12 @@
 AC_SUBST(DBUS_SESSION_SOCKET_DIR)
=20
=20
+old_exec_prefix=3D${exec_prefix}
+test "x$exec_prefix" =3D xNONE && eval exec_prefix=3D${prefix}
+eval EXPANDED_LIBDIR=3D${libdir}
+exec_prefix=3D${old_exec_prefix}
+AC_SUBST(EXPANDED_LIBDIR)
+
 AC_OUTPUT([
 Doxyfile
 dbus/dbus-arch-deps.h
@@ -707,4 +713,4 @@
 fi
 if test x$enable_checks =3D xno; then
         echo "NOTE: building without checks for arguments passed to public=
 API makes it harder to debug apps using D-BUS, but will slightly decrease =
D-BUS library size and _very_ slightly improve performance."
-fi
\ No newline at end of file
+fi
Index: bus/activation.c
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
RCS file: /home/freedesktop/dbus/bus/activation.c,v
retrieving revision 1.26
diff -u -r1.26 activation.c
--- bus/activation.c	27 Apr 2003 06:25:42 -0000	1.26
+++ bus/activation.c	12 May 2003 22:42:21 -0000
@@ -595,7 +595,7 @@
=20
 	  if (!dbus_message_append_args (message,
 					 DBUS_TYPE_UINT32, DBUS_ACTIVATION_REPLY_ACTIVATED,
-					 0))
+					 DBUS_TYPE_INVALID))
 	    {
 	      dbus_message_unref (message);
 	      BUS_SET_OOM (error);
@@ -877,7 +877,7 @@
=20
       if (!dbus_message_append_args (message,
 				     DBUS_TYPE_UINT32, DBUS_ACTIVATION_REPLY_ALREADY_ACTIVE,=20
-				     0))
+				     DBUS_TYPE_INVALID))
 	{
           _dbus_verbose ("No memory to set args of reply to activate messa=
ge\n");
 	  BUS_SET_OOM (error);
Index: bus/driver.c
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
RCS file: /home/freedesktop/dbus/bus/driver.c,v
retrieving revision 1.40
diff -u -r1.40 driver.c
--- bus/driver.c	27 Apr 2003 06:25:42 -0000	1.40
+++ bus/driver.c	12 May 2003 22:42:21 -0000
@@ -60,7 +60,7 @@
   if (!dbus_message_set_sender (message, DBUS_SERVICE_DBUS) ||
       !dbus_message_append_args (message,
                                  DBUS_TYPE_STRING, service_name,
-                                 0))
+                                 DBUS_TYPE_INVALID))
     {
       dbus_message_unref (message);
       BUS_SET_OOM (error);
@@ -100,7 +100,7 @@
  =20
   if (!dbus_message_append_args (message,
                                  DBUS_TYPE_STRING, service_name,
-                                 0))
+                                 DBUS_TYPE_INVALID))
     {
       dbus_message_unref (message);
       BUS_SET_OOM (error);
@@ -133,7 +133,7 @@
  =20
   if (!dbus_message_append_args (message,
                                  DBUS_TYPE_STRING, service_name,
-                                 0))
+                                 DBUS_TYPE_INVALID))
     {
       dbus_message_unref (message);
       BUS_SET_OOM (error);
@@ -174,7 +174,7 @@
  =20
   if (!dbus_message_append_args (message,
                                  DBUS_TYPE_STRING, service_name,
-                                 0))
+                                 DBUS_TYPE_INVALID))
     {
       dbus_message_unref (message);
       BUS_SET_OOM (error);
@@ -352,7 +352,7 @@
  =20
   if (!dbus_message_append_args (welcome,
                                  DBUS_TYPE_STRING, name,
-                                 NULL))
+                                 DBUS_TYPE_INVALID))
     {
       dbus_message_unref (welcome);
       BUS_SET_OOM (error);
@@ -403,7 +403,7 @@
  =20
   if (!dbus_message_append_args (reply,
                                  DBUS_TYPE_ARRAY, DBUS_TYPE_STRING, servic=
es, len,
-                                 0))
+                                 DBUS_TYPE_INVALID))
     {
       dbus_free_string_array (services);
       dbus_message_unref (reply);
@@ -447,7 +447,7 @@
   if (!dbus_message_get_args (message, error,
                               DBUS_TYPE_STRING, &name,
                               DBUS_TYPE_UINT32, &flags,
-                              0))
+                              DBUS_TYPE_INVALID))
     return FALSE;
  =20
   _dbus_verbose ("Trying to own service %s with flags 0x%x\n", name, flags=
);
@@ -510,7 +510,7 @@
  =20
   if (!dbus_message_get_args (message, error,
                               DBUS_TYPE_STRING, &name,
-                              0))
+                              DBUS_TYPE_INVALID))
     return FALSE;
=20
   retval =3D FALSE;
@@ -567,7 +567,7 @@
   if (!dbus_message_get_args (message, error,
                               DBUS_TYPE_STRING, &name,
                               DBUS_TYPE_UINT32, &flags,
-                              0))
+                              DBUS_TYPE_INVALID))
     {
       _DBUS_ASSERT_ERROR_IS_SET (error);
       _dbus_verbose ("No memory to get arguments to ActivateService\n");
Index: bus/session.conf.in
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
RCS file: /home/freedesktop/dbus/bus/session.conf.in,v
retrieving revision 1.4
diff -u -r1.4 session.conf.in
--- bus/session.conf.in	14 Apr 2003 02:29:21 -0000	1.4
+++ bus/session.conf.in	12 May 2003 22:42:23 -0000
@@ -10,6 +10,8 @@
=20
   <listen>unix:tmpdir=3D@DBUS_SESSION_SOCKET_DIR@</listen>
=20
+  <servicedir>@EXPANDED_LIBDIR@/dbus-1.0/services</servicedir>
+
   <policy context=3D"default">
     <!-- Allow everything -->
     <allow send=3D"*"/>
Index: dbus/dbus-bus.c
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
RCS file: /home/freedesktop/dbus/dbus/dbus-bus.c,v
retrieving revision 1.20
diff -u -r1.20 dbus-bus.c
--- dbus/dbus-bus.c	24 Apr 2003 19:18:22 -0000	1.20
+++ dbus/dbus-bus.c	12 May 2003 22:42:28 -0000
@@ -465,7 +465,7 @@
     goto out;
   else if (!dbus_message_get_args (reply, error,
                                    DBUS_TYPE_STRING, &name,
-                                   0))
+                                   DBUS_TYPE_INVALID))
     goto out;
  =20
   bd->base_service =3D name;
@@ -576,7 +576,7 @@
   if (!dbus_message_append_args (message,
 				 DBUS_TYPE_STRING, service_name,
 				 DBUS_TYPE_UINT32, flags,
-				 0))
+				 DBUS_TYPE_INVALID))
     {
       dbus_message_unref (message);
       _DBUS_SET_OOM (error);
@@ -603,7 +603,7 @@
  =20
   if (!dbus_message_get_args (reply, error,
                               DBUS_TYPE_UINT32, &service_result,
-                              0))
+                              DBUS_TYPE_INVALID))
     {
       _DBUS_ASSERT_ERROR_IS_SET (error);
       dbus_message_unref (reply);
@@ -647,7 +647,7 @@
  =20
   if (!dbus_message_append_args (message,
 				 DBUS_TYPE_STRING, service_name,
-				 0))
+				 DBUS_TYPE_INVALID))
     {
       dbus_message_unref (message);
       _DBUS_SET_OOM (error);
@@ -665,7 +665,7 @@
=20
   if (!dbus_message_get_args (reply, error,
                               DBUS_TYPE_UINT32, &exists,
-                              0))
+                              DBUS_TYPE_INVALID))
     {
       _DBUS_ASSERT_ERROR_IS_SET (error);
       return FALSE;
@@ -673,5 +673,53 @@
  =20
   return (exists !=3D FALSE);
 }
+
+/**
+ * Activates a given service
+ *
+ * @param connection the connection
+ * @param service_name the service name
+ * @param flags the flags
+ * @param error location to store any errors
+ * @returns #TRUE if the activation succeeded, #FALSE if not
+ *
+ * @todo document what the flags do
+ */
+dbus_bool_t
+dbus_bus_activate_service (DBusConnection *connection,
+			   const char     *service_name,
+			   dbus_uint32_t   flags,
+			   DBusError      *error)
+{
+  DBusMessage *msg;
+  DBusMessage *reply;
+  dbus_bool_t ret =3D TRUE;
+
+  msg =3D dbus_message_new (DBUS_MESSAGE_ACTIVATE_SERVICE,
+      			  DBUS_SERVICE_DBUS);
+
+  dbus_message_append_args (msg, DBUS_TYPE_STRING, service_name,
+      			    DBUS_TYPE_UINT32, flags, DBUS_TYPE_INVALID);
+
+  reply =3D dbus_connection_send_with_reply_and_block (connection, msg,
+      						     -1, error);
+  dbus_message_unref (msg);
+
+  if (reply =3D=3D NULL)
+    {
+      _DBUS_ASSERT_ERROR_IS_SET (error);
+      return FALSE;
+    }
+
+  if (dbus_set_error_from_message (error, reply))
+    {
+      _DBUS_ASSERT_ERROR_IS_SET (error);
+      ret =3D FALSE;
+    }
+ =20
+  dbus_message_unref (reply);
+  return ret;
+}
+
=20
 /** @} */
Index: dbus/dbus-bus.h
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
RCS file: /home/freedesktop/dbus/dbus/dbus-bus.h,v
retrieving revision 1.6
diff -u -r1.6 dbus-bus.h
--- dbus/dbus-bus.h	3 Apr 2003 05:22:48 -0000	1.6
+++ dbus/dbus-bus.h	12 May 2003 22:42:28 -0000
@@ -53,6 +53,11 @@
 					   const char     *service_name,
 					   DBusError      *error);
=20
+dbus_bool_t     dbus_bus_activate_service (DBusConnection *connection,
+					   const char     *service_name,
+					   dbus_uint32_t   flags,
+					   DBusError      *error);
+
 DBUS_END_DECLS;
=20
 #endif /* DBUS_BUS_H */
Index: dbus/dbus-message.c
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
RCS file: /home/freedesktop/dbus/dbus/dbus-message.c,v
retrieving revision 1.98
diff -u -r1.98 dbus-message.c
--- dbus/dbus-message.c	12 May 2003 02:44:44 -0000	1.98
+++ dbus/dbus-message.c	12 May 2003 22:42:35 -0000
@@ -1229,7 +1229,7 @@
  * followed by the value to add.  Array values are specified by an int
  * typecode followed by a pointer to the array followed by an int
  * giving the length of the array.  The argument list must be
- * terminated with DBUS_TYPE_INVALID.
+ * terminated with #DBUS_TYPE_INVALID.
  *
  * This function doesn't support dicts or non-fundamental arrays.
  *
@@ -1421,7 +1421,7 @@
  * Gets arguments from a message given a variable argument list.
  * The variable argument list should contain the type of the
  * argumen followed by a pointer to where the value should be
- * stored. The list is terminated with 0.
+ * stored. The list is terminated with #DBUS_TYPE_INVALID.
  *
  * @param message the message
  * @param error error to be filled in on failure

--=-MdCWC4ixyAt1m/rZGl+z--

--=-VlUsNtBcVvHXFpcAs0Ew
Content-Type: application/pgp-signature; name=signature.asc
Content-Description: This is a digitally signed message part

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.1 (GNU/Linux)

iD8DBQA+wCRkHcA+jblZuh8RAnUCAKDJUFBSOMRkBu2GpPokwZ5NnXjl3wCgzxv+
8Vp7MrwHvzxVrnkCq7zAKSY=
=Z/DR
-----END PGP SIGNATURE-----

--=-VlUsNtBcVvHXFpcAs0Ew--