Index: activation.c =================================================================== RCS file: /cvs/dbus/dbus/bus/activation.c,v retrieving revision 1.41 diff -u -u -r1.41 activation.c --- activation.c 22 Nov 2005 20:37:00 -0000 1.41 +++ activation.c 6 Jul 2006 16:40:56 -0000 @@ -1565,6 +1565,51 @@ return TRUE; } +dbus_bool_t +bus_activation_list_services (BusActivation *activation, + char ***listp, + int *array_len) +{ + int i, j, len; + char **retval; + DBusHashIter iter; + + len = _dbus_hash_table_get_n_entries (activation->entries); + retval = dbus_new (char *, len + 1); + + if (retval == NULL) + return FALSE; + + _dbus_hash_iter_init (activation->entries, &iter); + i = 0; + while (_dbus_hash_iter_next (&iter)) + { + BusActivationEntry *entry = _dbus_hash_iter_get_value (&iter); + + retval[i] = _dbus_strdup (entry->name); + if (retval[i] == NULL) + goto error; + + i++; + } + + retval[i] = NULL; + + if (array_len) + *array_len = len; + + *listp = retval; + return TRUE; + + error: + for (j = 0; j < i; j++) + dbus_free (retval[i]); + dbus_free (retval); + + return FALSE; +} + + #ifdef DBUS_BUILD_TESTS #include Index: activation.h =================================================================== RCS file: /cvs/dbus/dbus/bus/activation.h,v retrieving revision 1.13 diff -u -u -r1.13 activation.h --- activation.h 10 Aug 2004 03:06:59 -0000 1.13 +++ activation.h 6 Jul 2006 16:40:56 -0000 @@ -45,6 +45,9 @@ const char *service_name, BusTransaction *transaction, DBusError *error); +dbus_bool_t bus_activation_list_services (BusActivation *registry, + char ***listp, + int *array_len); dbus_bool_t bus_activation_send_pending_auto_activation_messages (BusActivation *activation, BusService *service, Index: driver.c =================================================================== RCS file: /cvs/dbus/dbus/bus/driver.c,v retrieving revision 1.76 diff -u -u -r1.76 driver.c --- driver.c 22 Nov 2005 20:37:00 -0000 1.76 +++ driver.c 6 Jul 2006 16:40:56 -0000 @@ -436,16 +436,108 @@ ++i; } + dbus_free_string_array (services); + if (!dbus_message_iter_close_container (&iter, &sub)) { - dbus_free_string_array (services); dbus_message_unref (reply); BUS_SET_OOM (error); return FALSE; } + if (!bus_transaction_send_from_driver (transaction, connection, reply)) + { + dbus_message_unref (reply); + BUS_SET_OOM (error); + return FALSE; + } + else + { + dbus_message_unref (reply); + return TRUE; + } +} + +static dbus_bool_t +bus_driver_handle_list_activatable_services (DBusConnection *connection, + BusTransaction *transaction, + DBusMessage *message, + DBusError *error) +{ + DBusMessage *reply; + int len; + char **services; + BusActivation *activation; + int i; + DBusMessageIter iter; + DBusMessageIter sub; + + _DBUS_ASSERT_ERROR_IS_CLEAR (error); + + activation = bus_connection_get_activation (connection); + + reply = dbus_message_new_method_return (message); + if (reply == NULL) + { + BUS_SET_OOM (error); + return FALSE; + } + + if (!bus_activation_list_services (activation, &services, &len)) + { + dbus_message_unref (reply); + BUS_SET_OOM (error); + return FALSE; + } + + dbus_message_iter_init_append (reply, &iter); + + if (!dbus_message_iter_open_container (&iter, DBUS_TYPE_ARRAY, + DBUS_TYPE_STRING_AS_STRING, + &sub)) + { + dbus_free_string_array (services); + dbus_message_unref (reply); + BUS_SET_OOM (error); + return FALSE; + } + + { + /* Include the bus driver in the list */ + const char *v_STRING = DBUS_SERVICE_DBUS; + if (!dbus_message_iter_append_basic (&sub, DBUS_TYPE_STRING, + &v_STRING)) + { + dbus_free_string_array (services); + dbus_message_unref (reply); + BUS_SET_OOM (error); + return FALSE; + } + } + + i = 0; + while (i < len) + { + if (!dbus_message_iter_append_basic (&sub, DBUS_TYPE_STRING, + &services[i])) + { + dbus_free_string_array (services); + dbus_message_unref (reply); + BUS_SET_OOM (error); + return FALSE; + } + ++i; + } + dbus_free_string_array (services); - + + if (!dbus_message_iter_close_container (&iter, &sub)) + { + dbus_message_unref (reply); + BUS_SET_OOM (error); + return FALSE; + } + if (!bus_transaction_send_from_driver (transaction, connection, reply)) { dbus_message_unref (reply); @@ -1328,6 +1420,10 @@ "", DBUS_TYPE_ARRAY_AS_STRING DBUS_TYPE_STRING_AS_STRING, bus_driver_handle_list_services }, + { "ListServices", + "", + DBUS_TYPE_ARRAY_AS_STRING DBUS_TYPE_STRING_AS_STRING, + bus_driver_handle_list_activatable_services }, { "AddMatch", DBUS_TYPE_STRING_AS_STRING, "",