print_names (GDBusConnection *c,
gboolean include_unique_names)
{
- GVariant *result;
+ gchar **list_names;
GError *error;
- GVariantIter *iter;
- gchar *str;
+ guint cnt;
GHashTable *name_set;
GList *keys;
GList *l;
name_set = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL);
error = NULL;
- result = g_dbus_connection_call_sync (c,
- "org.freedesktop.DBus",
- "/org/freedesktop/DBus",
- "org.freedesktop.DBus",
- "ListNames",
- NULL,
- G_VARIANT_TYPE ("(as)"),
- G_DBUS_CALL_FLAGS_NONE,
- 3000, /* 3 secs */
- NULL,
- &error);
- if (result == NULL)
+ cnt = 0;
+ list_names = g_dbus_get_list_names (c, &error);
+ if (list_names == NULL)
{
g_printerr (_("Error: %s\n"), error->message);
g_error_free (error);
goto out;
}
- g_variant_get (result, "(as)", &iter);
- while (g_variant_iter_loop (iter, "s", &str))
- g_hash_table_insert (name_set, g_strdup (str), NULL);
- g_variant_iter_free (iter);
- g_variant_unref (result);
+
+ while (list_names[cnt])
+ g_hash_table_insert (name_set, g_strdup (list_names[cnt++]), NULL);
+ g_strfreev(list_names);
error = NULL;
- result = g_dbus_connection_call_sync (c,
- "org.freedesktop.DBus",
- "/org/freedesktop/DBus",
- "org.freedesktop.DBus",
- "ListActivatableNames",
- NULL,
- G_VARIANT_TYPE ("(as)"),
- G_DBUS_CALL_FLAGS_NONE,
- 3000, /* 3 secs */
- NULL,
- &error);
- if (result == NULL)
+ cnt = 0;
+ list_names = g_dbus_get_list_activatable_names (c, &error);
+ if (list_names == NULL)
{
g_printerr (_("Error: %s\n"), error->message);
g_error_free (error);
goto out;
}
- g_variant_get (result, "(as)", &iter);
- while (g_variant_iter_loop (iter, "s", &str))
- g_hash_table_insert (name_set, g_strdup (str), NULL);
- g_variant_iter_free (iter);
- g_variant_unref (result);
+
+ while (list_names[cnt])
+ g_hash_table_insert (name_set, g_strdup (list_names[cnt++]), NULL);
+ g_strfreev(list_names);
keys = g_hash_table_get_keys (name_set);
keys = g_list_sort (keys, (GCompareFunc) g_strcmp0);
static gboolean opt_connection_system = FALSE;
static gboolean opt_connection_session = FALSE;
+static gboolean opt_connection_user = FALSE;
+static gboolean opt_connection_machine = FALSE;
static gchar *opt_connection_address = NULL;
static const GOptionEntry connection_entries[] =
{
{ "system", 'y', 0, G_OPTION_ARG_NONE, &opt_connection_system, N_("Connect to the system bus"), NULL},
{ "session", 'e', 0, G_OPTION_ARG_NONE, &opt_connection_session, N_("Connect to the session bus"), NULL},
+ { "machine", 'm', 0, G_OPTION_ARG_NONE, &opt_connection_machine, N_("Connect to the machine bus"), NULL},
+ { "user", 'u', 0, G_OPTION_ARG_NONE, &opt_connection_user, N_("Connect to the user bus"), NULL},
{ "address", 'a', 0, G_OPTION_ARG_STRING, &opt_connection_address, N_("Connect to given D-Bus address"), NULL},
{ NULL }
};
connection_get_dbus_connection (GError **error)
{
GDBusConnection *c;
+ guint count;
c = NULL;
+ count = !!opt_connection_system +
+ !!opt_connection_session +
+ !!opt_connection_machine +
+ !!opt_connection_user +
+ !!opt_connection_address;
+
/* First, ensure we have exactly one connect */
- if (!opt_connection_system && !opt_connection_session && opt_connection_address == NULL)
+ if (count == 0)
{
g_set_error (error,
G_IO_ERROR,
_("No connection endpoint specified"));
goto out;
}
- else if ((opt_connection_system && (opt_connection_session || opt_connection_address != NULL)) ||
- (opt_connection_session && (opt_connection_system || opt_connection_address != NULL)) ||
- (opt_connection_address != NULL && (opt_connection_system || opt_connection_session)))
+ else if (count > 1)
{
g_set_error (error,
G_IO_ERROR,
{
c = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, error);
}
+ else if (opt_connection_machine)
+ {
+ c = g_bus_get_sync (G_BUS_TYPE_MACHINE, NULL, error);
+ }
+ else if (opt_connection_user)
+ {
+ c = g_bus_get_sync (G_BUS_TYPE_USER, NULL, error);
+ }
else if (opt_connection_address != NULL)
{
c = g_dbus_connection_new_for_address_sync (opt_connection_address,
}
else
{
- g_print ("--system \n--session \n--address \n");
+ g_print ("--system \n--session \n--machine \n--user \n--address \n");
}
}
else
}
else
{
- g_print ("--system \n--session \n--address \n");
+ g_print ("--system \n--session \n--machine \n--user \n--address \n");
}
}
else
}
else
{
- g_print ("--system \n--session \n--address \n");
+ g_print ("--system \n--session \n--machine \n--user \n--address \n");
}
}
else
gchar *s;
GError *error;
GDBusConnection *c;
- GVariant *result;
- GDBusNodeInfo *node;
gboolean complete_names;
gboolean complete_paths;
GMainLoop *loop;
ret = FALSE;
c = NULL;
- node = NULL;
- result = NULL;
modify_argv0_for_command (argc, argv, "monitor");
}
else
{
- g_print ("--system \n--session \n--address \n");
+ g_print ("--system \n--session \n--machine \n--user \n--address \n");
}
}
else
ret = TRUE;
out:
- if (node != NULL)
- g_dbus_node_info_unref (node);
- if (result != NULL)
- g_variant_unref (result);
if (c != NULL)
g_object_unref (c);
g_option_context_free (o);