This is a multi-part message in MIME format.
Hi,
This is my first post here, hi everybody.
In my project I need to get list all available services, not only
already activated but also which are waiting to be activated when
necessary.
org.freedesktop.DBus.ListServices() show only activated service, because
I get no other possibility to gather information about services which
are available but not activated at the moment I wrote a patch for
"ListServices" which make return list with both activated and not yet
activated services.
What do you think about such solution. Or maybe there is other way to
get all available services but I miss it ?
Regards
--
Marcin Krzyżanowski
? dbus-all-services.patch
Index: bus/activation.c
===================================================================
RCS file: /cvs/dbus/dbus/bus/activation.c,v
retrieving revision 1.36
diff -u -r1.36 activation.c
--- bus/activation.c 10 Aug 2004 03:06:59 -0000 1.36
+++ bus/activation.c 5 Nov 2004 09:58:01 -0000
@@ -1543,6 +1543,25 @@
return TRUE;
}
+DBusList*
+bus_activation_get_activations(BusActivation *activation)
+{
+ DBusList *entries_list = NULL;
+ DBusHashIter iter;
+
+ _dbus_assert (activation);
+
+ _dbus_hash_iter_init (activation->entries, &iter);
+ while (_dbus_hash_iter_next (&iter))
+ {
+ BusActivationEntry *entry = _dbus_hash_iter_get_value (&iter);
+ _dbus_list_append (&entries_list,_dbus_strdup(entry->name));
+ }
+
+ return entries_list;
+}
+
+
#ifdef DBUS_BUILD_TESTS
#include <stdio.h>
Index: bus/activation.h
===================================================================
RCS file: /cvs/dbus/dbus/bus/activation.h,v
retrieving revision 1.13
diff -u -r1.13 activation.h
--- bus/activation.h 10 Aug 2004 03:06:59 -0000 1.13
+++ bus/activation.h 5 Nov 2004 09:58:01 -0000
@@ -26,6 +26,7 @@
#include <dbus/dbus.h>
#include <dbus/dbus-list.h>
+#include <dbus/dbus-hash.h>
#include "bus.h"
BusActivation* bus_activation_new (BusContext *context,
@@ -45,6 +46,7 @@
const char *service_name,
BusTransaction *transaction,
DBusError *error);
+DBusList* bus_activation_get_activations(BusActivation *activation);
dbus_bool_t bus_activation_send_pending_auto_activation_messages
(BusActivation *activation,
BusService
*service,
Index: bus/services.c
===================================================================
RCS file: /cvs/dbus/dbus/bus/services.c,v
retrieving revision 1.25
diff -u -r1.25 services.c
--- bus/services.c 29 Oct 2004 18:13:53 -0000 1.25
+++ bus/services.c 5 Nov 2004 09:58:01 -0000
@@ -223,24 +223,57 @@
int i, j, len;
char **retval;
DBusHashIter iter;
-
- len = _dbus_hash_table_get_n_entries (registry->service_hash);
- retval = dbus_new (char *, len + 1);
-
- if (retval == NULL)
+ DBusHashTable *services_table = NULL;
+ BusActivation *activation = bus_context_get_activation (registry->context);
+ DBusList *activations_list = bus_activation_get_activations(activation);
+ DBusList *link,*next;
+
+ /* hash tale for output with unique keys and so with unique data about
services */
+ services_table = _dbus_hash_table_new(DBUS_HASH_STRING,
+ (DBusFreeFunction)dbus_free,
+ (DBusFreeFunction)dbus_free);
+
+ if (services_table == NULL)
return FALSE;
+ /* iter every registry->service_hash */
_dbus_hash_iter_init (registry->service_hash, &iter);
- i = 0;
while (_dbus_hash_iter_next (&iter))
{
BusService *service = _dbus_hash_iter_get_value (&iter);
+
_dbus_hash_table_insert_string(services_table,_dbus_strdup(service->name),NULL);
+ }
+
+ /* iter activations_list List of services which may be activated
+ but don't have to be active right now */
+ link = _dbus_list_get_first_link (&activations_list);
+ while (link != NULL)
+ {
+ next = _dbus_list_get_next_link (&activations_list, link);
+
_dbus_hash_table_insert_string(services_table,_dbus_strdup(link->data),NULL);
+ dbus_free(link->data);
+ link = next;
+ }
+
+ /* iterate services_table and create return data */
+ len = _dbus_hash_table_get_n_entries (services_table);
- retval[i] = _dbus_strdup (service->name);
+ retval = dbus_new (char *, len + 1);
+
+ if (retval == NULL)
+ return FALSE;
+
+ /* iter every services_table */
+ _dbus_hash_iter_init (services_table, &iter);
+ i = 0;
+ while (_dbus_hash_iter_next (&iter))
+ {
+ const char *service = _dbus_hash_iter_get_string_key (&iter);
+ retval[i] = _dbus_strdup (service);
if (retval[i] == NULL)
goto error;
- i++;
+ i++;
}
retval[i] = NULL;
@@ -249,12 +282,16 @@
*array_len = len;
*listp = retval;
+ _dbus_hash_table_unref(services_table);
+ _dbus_list_clear(&activations_list);
return TRUE;
error:
for (j = 0; j < i; j++)
dbus_free (retval[i]);
dbus_free (retval);
+ _dbus_hash_table_unref(services_table);
+ _dbus_list_clear(&activations_list);
return FALSE;
}
|