[gnome-bluetooth] Add a --dump-devices option to the properties
- From: Bastien Nocera <hadess src gnome org>
- To: svn-commits-list gnome org
- Subject: [gnome-bluetooth] Add a --dump-devices option to the properties
- Date: Thu, 4 Jun 2009 16:17:17 -0400 (EDT)
commit aa58e7a43606295a8d311c4d778a9ba51de69b3f
Author: Bastien Nocera <hadess hadess net>
Date: Thu Jun 4 21:14:33 2009 +0100
Add a --dump-devices option to the properties
Makes a useful option for debugging, dumps a list of adapters,
and each of the devices associated to it.
---
properties/main.c | 110 +++++++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 110 insertions(+), 0 deletions(-)
diff --git a/properties/main.c b/properties/main.c
index 84b3177..205aa2d 100644
--- a/properties/main.c
+++ b/properties/main.c
@@ -30,6 +30,7 @@
#include <gtk/gtk.h>
#include <unique/uniqueapp.h>
+#include "bluetooth-client.h"
#include "gconf-bridge.h"
#include "general.h"
#include "adapter.h"
@@ -185,7 +186,111 @@ message_received_cb (UniqueApp *app,
return UNIQUE_RESPONSE_OK;
}
+static void
+services_foreach (const char *service, gpointer _value, GString *str)
+{
+ gboolean value = GPOINTER_TO_INT (_value);
+ g_string_append_printf (str, "%s (%s) ", service, value ? "connected" : "not connected");
+}
+
+#define BOOL_STR(x) (x ? "True" : "False")
+
+static void
+dump_device (GtkTreeModel *model, GtkTreeIter *iter, gboolean is_adapter)
+{
+ char *address, *alias, *icon, **uuids;
+ gboolean is_default, paired, trusted, connected, discovering, powered;
+ GHashTable *services;
+ guint type;
+
+ gtk_tree_model_get (model, iter,
+ BLUETOOTH_COLUMN_ADDRESS, &address,
+ BLUETOOTH_COLUMN_ALIAS, &alias,
+ BLUETOOTH_COLUMN_TYPE, &type,
+ BLUETOOTH_COLUMN_ICON, &icon,
+ BLUETOOTH_COLUMN_DEFAULT, &is_default,
+ BLUETOOTH_COLUMN_PAIRED, &paired,
+ BLUETOOTH_COLUMN_TRUSTED, &trusted,
+ BLUETOOTH_COLUMN_CONNECTED, &connected,
+ BLUETOOTH_COLUMN_DISCOVERING, &discovering,
+ BLUETOOTH_COLUMN_POWERED, &powered,
+ BLUETOOTH_COLUMN_SERVICES, &services,
+ BLUETOOTH_COLUMN_UUIDS, &uuids,
+ -1);
+
+ if (is_adapter != FALSE) {
+ /* Adapter */
+ g_print ("Adapter: %s (%s)\n", alias, address);
+ if (is_default)
+ g_print ("\tDefault adapter\n");
+ if (discovering)
+ g_print ("\tDiscovery in progress\n");
+ g_print ("\t%s\n", powered ? "Is discovering" : "Not discovering");
+ } else {
+ /* Device */
+ g_print ("Device: %s (%s)\n", alias, address);
+ g_print ("\tType: %s Icon: %s\n", bluetooth_type_to_string (type), icon);
+ g_print ("\tPaired: %s Trusted: %s Connected: %s\n", BOOL_STR(paired), BOOL_STR(trusted), BOOL_STR(connected));
+ if (services != NULL) {
+ GString *str;
+
+ str = g_string_new (NULL);
+ g_hash_table_foreach (services, (GHFunc) services_foreach, str);
+ g_print ("\tServices: %s\n", str->str);
+ g_string_free (str, TRUE);
+ }
+ if (uuids != NULL) {
+ guint i;
+ g_print ("\tUUIDs: ");
+ for (i = 0; uuids[i] != NULL; i++)
+ g_print ("%s ", uuids[i]);
+ g_print ("\n");
+ }
+ }
+ g_print ("\n");
+
+ g_free (alias);
+ g_free (address);
+ g_free (icon);
+ if (services != NULL)
+ g_hash_table_unref (services);
+ g_strfreev (uuids);
+
+ if (is_adapter != FALSE) {
+ GtkTreeIter child;
+
+ if (gtk_tree_model_iter_children (model, &child, iter) == FALSE)
+ return;
+ dump_device (model, &child, FALSE);
+ while (gtk_tree_model_iter_next (model, &child))
+ dump_device (model, &child, FALSE);
+ }
+}
+
+static void
+dump_devices (void)
+{
+ BluetoothClient *client;
+ GtkTreeModel *model;
+ GtkTreeIter iter;
+
+ client = bluetooth_client_new ();
+ model = bluetooth_client_get_model (client);
+
+ if (gtk_tree_model_get_iter_first (model, &iter) == FALSE) {
+ g_print ("No known devices\n");
+ g_print ("Is bluetoothd running, and a Bluetooth adapter enabled?\n");
+ return;
+ }
+ dump_device (model, &iter, TRUE);
+ while (gtk_tree_model_iter_next (model, &iter))
+ dump_device (model, &iter, TRUE);
+}
+
+static gboolean option_dump = FALSE;
+
static GOptionEntry options[] = {
+ { "dump-devices", 'd', 0, G_OPTION_ARG_NONE, &option_dump, N_("Output a list of currently known devices"), NULL },
{ NULL },
};
@@ -211,6 +316,11 @@ int main(int argc, char *argv[])
return 1;
}
+ if (option_dump != FALSE) {
+ dump_devices ();
+ return 0;
+ }
+
app = unique_app_new ("org.gnome.Bluetooth.properties", NULL);
if (unique_app_is_running (app)) {
unique_app_send_message (app, UNIQUE_ACTIVATE, NULL);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]