[aravis] arvtool: allow wildcard in device id.



commit 131aae50ac579fcc1e2e552f03f9f77e05aab6f7
Author: Emmanuel Pacaud <emmanuel gnome org>
Date:   Fri Feb 3 17:46:53 2012 +0100

    arvtool: allow wildcard in device id.

 src/arvtool.c |  275 +++++++++++++++++++++++++++-----------------------------
 1 files changed, 133 insertions(+), 142 deletions(-)
---
diff --git a/src/arvtool.c b/src/arvtool.c
index 2271dc9..0829bb8 100644
--- a/src/arvtool.c
+++ b/src/arvtool.c
@@ -3,41 +3,6 @@
 #include <string.h>
 #include <stdio.h>
 
-static char *arv_option_device_name = NULL;
-static char *arv_option_debug_domains = NULL;
-
-static const GOptionEntry arv_option_entries[] =
-{
-	{ "name",		'n', 0, G_OPTION_ARG_STRING,
-		&arv_option_device_name,	NULL, "<device_name>"},
-	{ "debug", 		'd', 0, G_OPTION_ARG_STRING,
-		&arv_option_debug_domains, 	NULL, "<category>[:<level>][,...]" },
-	{ NULL }
-};
-
-void
-arv_tool_show_devices (void)
-{
-	unsigned int n_devices;
-
-	arv_update_device_list ();
-	n_devices = arv_get_n_devices ();
-
-	if (n_devices < 1)
-		printf ("No device found\n");
-	else {
-		unsigned int i;
-
-		for (i = 0; i < n_devices; i++) {
-			const char *device_id;
-
-			device_id = arv_get_device_id (i);
-			if (device_id != NULL)
-				printf ("%s\n",  device_id);
-		}
-	}
-}
-
 static void
 arv_tool_list_features (ArvGc *genicam, const char *feature, gboolean show_description, int level)
 {
@@ -85,6 +50,116 @@ arv_tool_list_features (ArvGc *genicam, const char *feature, gboolean show_descr
 	}
 }
 
+static void
+arv_tool_execute_command (int argc, char **argv, const char *device_name)
+{
+	ArvDevice *device;
+	ArvGc *genicam;
+	const char *command = argv[1];
+
+	device = arv_open_device (device_name);
+	if (!ARV_IS_DEVICE (device)) {
+		if (device_name != NULL)
+			printf ("Device '%s' not found\n", device_name);
+		else
+			printf ("No device found\n");
+		return;
+	}
+
+	genicam = arv_device_get_genicam (device);
+
+	if (g_strcmp0 (command, "genicam") == 0) {
+		const char *xml;
+		size_t size;
+
+		xml = arv_device_get_genicam_xml (device, &size);
+		if (xml != NULL)
+			printf ("%*s\n", (int) size, xml);
+	} else if (g_strcmp0 (command, "features") == 0) {
+		arv_tool_list_features (genicam, "Root", FALSE, 0);
+	} else if (g_strcmp0 (command, "description") == 0) {
+		if (argc < 3)
+			arv_tool_list_features (genicam, "Root", TRUE, 0);
+		else {
+			int i;
+
+			for (i = 2; i < argc; i++) {
+				ArvGcNode *node;
+
+				node = arv_gc_get_node (genicam, argv[i]);
+				if (ARV_IS_GC_NODE (node)) {
+					const char *description;
+
+					printf ("%s: '%s'\n", arv_gc_node_get_node_name (node), argv[i]);
+
+					description = arv_gc_node_get_description (node);
+					if (description)
+						printf ("%s\n", description);
+				}
+			}
+		}
+	} else if (g_strcmp0 (command, "control") == 0) {
+		int i;
+
+		for (i = 2; i < argc; i++) {
+			ArvGcNode *feature;
+			char **tokens;
+
+			tokens = g_strsplit (argv[i], "=", 2);
+			feature = arv_device_get_feature (device, tokens[0]);
+			if (!ARV_IS_GC_NODE (feature))
+				if (g_strrstr (tokens[0], "R[") == tokens[0]) {
+					guint32 value;
+					guint32 address;
+
+					address = g_ascii_strtoll(&tokens[0][2], NULL, 0);
+
+					if (tokens[1] != NULL) {
+						arv_device_write_register (device,
+									   address,
+									   g_ascii_strtoll (tokens[1],
+											    NULL, 0));
+					}
+
+					arv_device_read_register (device, address, &value);
+
+					printf ("R[0x%08x] = 0x%08x\n",
+						address, value);
+				} else
+					printf ("Feature '%s' not found\n", tokens[0]);
+				else {
+					if (ARV_IS_GC_COMMAND (feature)) {
+						arv_gc_command_execute (ARV_GC_COMMAND (feature));
+						printf ("%s executed\n", tokens[0]);
+					} else {
+						if (tokens[1] != NULL)
+							arv_gc_node_set_value_from_string (feature, tokens[1]);
+
+						printf ("%s = %s\n", tokens[0],
+							arv_gc_node_get_value_as_string (feature));
+					}
+				}
+			g_strfreev (tokens);
+		}
+	} else {
+		printf ("Unkown command\n");
+	}
+
+	g_object_unref (device);
+}
+
+static char *arv_option_device_name = NULL;
+static char *arv_option_debug_domains = NULL;
+
+static const GOptionEntry arv_option_entries[] =
+{
+	{ "name",		'n', 0, G_OPTION_ARG_STRING,
+		&arv_option_device_name,	NULL, "<device_name>"},
+	{ "debug", 		'd', 0, G_OPTION_ARG_STRING,
+		&arv_option_debug_domains, 	NULL, "<category>[:<level>][,...]" },
+	{ NULL }
+};
+
 static const char
 description_content[] =
 "Command may be one of the following possibilities:\n"
@@ -108,8 +183,12 @@ description_content[] =
 int
 main (int argc, char **argv)
 {
+	GPatternSpec *pattern;
 	GOptionContext *context;
 	GError *error = NULL;
+	unsigned int n_devices;
+	unsigned int i;
+	unsigned int count = 0;
 
 	g_thread_init (NULL);
 	g_type_init ();
@@ -130,121 +209,33 @@ main (int argc, char **argv)
 
 	arv_debug_enable (arv_option_debug_domains);
 
-	if (argc < 2) {
-		if (arv_option_device_name != NULL) {
-			ArvDevice *device;
+	arv_update_device_list ();
+	n_devices = arv_get_n_devices ();
 
-			device = arv_open_device (arv_option_device_name);
-			if (!ARV_IS_DEVICE (device)) {
-				printf ("Device '%s' not found\n", arv_option_device_name);
+	if (arv_option_device_name != NULL)
+		pattern = g_pattern_spec_new (arv_option_device_name);
+	else
+		pattern = g_pattern_spec_new ("*");
 
-				arv_shutdown ();
+	for (i = 0; i < n_devices; i++) {
+		const char *device_id;
 
-				return EXIT_FAILURE;
-			}
-			printf ("%s found\n", arv_option_device_name);
+		device_id = arv_get_device_id (i);
 
-			g_object_unref (device);
-		} else
-			arv_tool_show_devices ();
-	} else {
-		ArvDevice *device;
-		ArvGc *genicam;
-		const char *command = argv[1];
-
-		device = arv_open_device (arv_option_device_name);
-		if (!ARV_IS_DEVICE (device)) {
-			if (arv_option_device_name != NULL)
-				printf ("Device '%s' not found\n", arv_option_device_name);
+		if (g_pattern_match_string (pattern, device_id)) {
+			if (argc >= 2)
+				arv_tool_execute_command (argc, argv, device_id);
 			else
-				printf ("No device found\n");
-
-			arv_shutdown ();
-
-			return EXIT_FAILURE;
-		}
-		genicam = arv_device_get_genicam (device);
-
-		if (g_strcmp0 (command, "genicam") == 0) {
-			const char *xml;
-			size_t size;
-
-			xml = arv_device_get_genicam_xml (device, &size);
-			if (xml != NULL)
-				printf ("%*s\n", (int) size, xml);
-		} else if (g_strcmp0 (command, "features") == 0) {
-			arv_tool_list_features (genicam, "Root", FALSE, 0);
-		} else if (g_strcmp0 (command, "description") == 0) {
-			if (argc < 3)
-				arv_tool_list_features (genicam, "Root", TRUE, 0);
-			else {
-				int i;
-
-				for (i = 2; i < argc; i++) {
-					ArvGcNode *node;
-
-					node = arv_gc_get_node (genicam, argv[i]);
-					if (ARV_IS_GC_NODE (node)) {
-						const char *description;
-
-						printf ("%s: '%s'\n", arv_gc_node_get_node_name (node), argv[i]);
-
-						description = arv_gc_node_get_description (node);
-						if (description)
-							printf ("%s\n", description);
-					}
-				}
-			}
-		} else if (g_strcmp0 (command, "control") == 0) {
-			int i;
-
-			for (i = 2; i < argc; i++) {
-				ArvGcNode *feature;
-				char **tokens;
-
-				tokens = g_strsplit (argv[i], "=", 2);
-				feature = arv_device_get_feature (device, tokens[0]);
-				if (!ARV_IS_GC_NODE (feature))
-					if (g_strrstr (tokens[0], "R[") == tokens[0]) {
-						guint32 value;
-						guint32 address;
-
-						address = g_ascii_strtoll(&tokens[0][2], NULL, 0);
-
-						if (tokens[1] != NULL) {
-							arv_device_write_register (device,
-										   address,
-										   g_ascii_strtoll (tokens[1],
-												    NULL, 0));
-						}
-
-						arv_device_read_register (device, address, &value);
-
-						printf ("R[0x%08x] = 0x%08x\n",
-							address, value);
-					} else
-						printf ("Feature '%s' not found\n", tokens[0]);
-					else {
-						if (ARV_IS_GC_COMMAND (feature)) {
-							arv_gc_command_execute (ARV_GC_COMMAND (feature));
-							printf ("%s executed\n", tokens[0]);
-						} else {
-							if (tokens[1] != NULL)
-								arv_gc_node_set_value_from_string (feature, tokens[1]);
-
-							printf ("%s = %s\n", tokens[0],
-								arv_gc_node_get_value_as_string (feature));
-						}
-					}
-				g_strfreev (tokens);
-			}
-		} else {
-			printf ("Unkown command\n");
-			arv_shutdown ();
-			return EXIT_FAILURE;
+				printf ("%s\n", device_id);
+			count++;
 		}
 	}
 
+	if (count == 0)
+		printf ("No device found\n");
+
+	g_pattern_spec_free (pattern);
+
 	arv_shutdown ();
 
 	return EXIT_SUCCESS;



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]