[gnome-builder/wip/libide: 42/153] libide: add ide-list-devices test program
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder/wip/libide: 42/153] libide: add ide-list-devices test program
- Date: Fri, 13 Feb 2015 20:03:42 +0000 (UTC)
commit 977157f6d0539fe14c416cf09f9cc1df29943b86
Author: Christian Hergert <christian hergert me>
Date: Sun Feb 8 13:37:24 2015 -0800
libide: add ide-list-devices test program
This simple helper program will list the devices that have been discovered
on the local system.
.gitignore | 1 +
tools/Makefile.am | 15 ++++--
tools/ide-list-devices.c | 125 ++++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 136 insertions(+), 5 deletions(-)
---
diff --git a/.gitignore b/.gitignore
index 5e71c0f..aec3388 100644
--- a/.gitignore
+++ b/.gitignore
@@ -22,6 +22,7 @@ config.status
configure
gnome-builder
ide-build
+ide-list-devices
ide-list-files
intltool-extract.in
intltool-merge.in
diff --git a/tools/Makefile.am b/tools/Makefile.am
index aac32a1..e94784d 100644
--- a/tools/Makefile.am
+++ b/tools/Makefile.am
@@ -1,10 +1,15 @@
-noinst_PROGRAMS += ide-list-files
-ide_list_files_SOURCES = tools/ide-list-files.c
-ide_list_files_CFLAGS = $(libide_la_CFLAGS)
-ide_list_files_LDADD = libide.la
-
noinst_PROGRAMS += ide-build
ide_build_SOURCES = tools/ide-build.c
ide_build_CFLAGS = $(libide_la_CFLAGS)
ide_build_LDADD = libide.la
+
+noinst_PROGRAMS += ide-list-devices
+ide_list_devices_SOURCES = tools/ide-list-devices.c
+ide_list_devices_CFLAGS = $(libide_la_CFLAGS)
+ide_list_devices_LDADD = libide.la
+
+noinst_PROGRAMS += ide-list-files
+ide_list_files_SOURCES = tools/ide-list-files.c
+ide_list_files_CFLAGS = $(libide_la_CFLAGS)
+ide_list_files_LDADD = libide.la
diff --git a/tools/ide-list-devices.c b/tools/ide-list-devices.c
new file mode 100644
index 0000000..1402dd3
--- /dev/null
+++ b/tools/ide-list-devices.c
@@ -0,0 +1,125 @@
+/* ide-list-devices.c
+ *
+ * Copyright (C) 2015 Christian Hergert <christian hergert me>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
+#include <glib.h>
+#include <glib/gi18n.h>
+#include <ide.h>
+#include <stdlib.h>
+
+static GMainLoop *gMainLoop;
+static gint gExitCode = EXIT_SUCCESS;
+
+static void
+quit (gint exit_code)
+{
+ gExitCode = exit_code;
+ g_main_loop_quit (gMainLoop);
+}
+
+static void
+settled_cb (IdeDeviceManager *device_manager,
+ GParamSpec *pspec,
+ gpointer user_data)
+{
+ GPtrArray *devices;
+ guint i;
+
+ if (!ide_device_manager_get_settled (device_manager))
+ return;
+
+ devices = ide_device_manager_get_devices (device_manager);
+ for (i = 0; i < devices->len; i++)
+ {
+ IdeDevice *device = g_ptr_array_index (devices, i);
+ const gchar *device_id = ide_device_get_id (device);
+ const gchar *display_name = ide_device_get_display_name (device);
+ const gchar *system_type = ide_device_get_system_type (device);
+
+ g_print (" %s \"%s\" (%s)\n", device_id, display_name, system_type);
+ }
+ g_ptr_array_unref (devices);
+
+ quit (EXIT_SUCCESS);
+}
+
+static void
+context_cb (GObject *object,
+ GAsyncResult *result,
+ gpointer user_data)
+{
+ g_autoptr(IdeContext) context = NULL;
+ g_autoptr(GError) error = NULL;
+ IdeDeviceManager *device_manager;
+ IdeProjectItem *root;
+ IdeProject *project;
+
+ context = ide_context_new_finish (result, &error);
+
+ if (!context)
+ {
+ g_printerr ("%s\n", error->message);
+ quit (EXIT_FAILURE);
+ return;
+ }
+
+ device_manager = ide_context_get_device_manager (context);
+
+ if (!ide_device_manager_get_settled (device_manager))
+ g_signal_connect (device_manager, "notify::settled",
+ G_CALLBACK (settled_cb), NULL);
+ else
+ settled_cb (device_manager, NULL, NULL);
+}
+
+gint
+main (gint argc,
+ gchar *argv[])
+{
+ g_autoptr(GOptionContext) context = NULL;
+ g_autoptr(GError) error = NULL;
+ g_autoptr(GFile) project_file = NULL;
+ const gchar *project_path = ".";
+
+ ide_set_program_name ("gnome-builder");
+ g_set_prgname ("ide-list-devices");
+
+ context = g_option_context_new (_("- List devices found on the system."));
+
+ if (!g_option_context_parse (context, &argc, &argv, &error))
+ {
+ g_printerr ("%s\n", error->message);
+ return EXIT_FAILURE;
+ }
+
+ gMainLoop = g_main_loop_new (NULL, FALSE);
+
+ if (argc > 1)
+ project_path = argv [1];
+ project_file = g_file_new_for_path (project_path);
+
+ ide_context_new_async (project_file, NULL, context_cb, NULL);
+
+ g_main_loop_run (gMainLoop);
+ g_clear_pointer (&gMainLoop, g_main_loop_unref);
+
+ return gExitCode;
+}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]