[aravis] genicam: dump genicam xml in arv-show-devices.



commit 9cf36cb25c02ba246e4ee04fe0f70c2c9e2ba6fe
Author: Emmanuel Pacaud <emmanuel gnome org>
Date:   Mon Jan 17 17:43:10 2011 +0100

    genicam: dump genicam xml in arv-show-devices.
    
    Using --xml option in arv-show-devices, it's now possible to
    extract the genicam xml data. The output can be restricted to
    a given camera using the --name option.

 docs/reference/aravis/aravis-sections.txt |    4 +-
 src/arvdevice.c                           |   28 +++++++++++++++
 src/arvdevice.h                           |    2 +
 src/arvfakecamera.c                       |   16 ++++----
 src/arvfakecamera.h                       |    2 +-
 src/arvfakedevice.c                       |   22 ++++++++++--
 src/arvgvdevice.c                         |   41 +++++++++++++---------
 src/arvgvdevice.h                         |    1 -
 src/arvshowdevices.c                      |   53 +++++++++++++++++++++++++++-
 tests/fake.c                              |   10 +++---
 10 files changed, 139 insertions(+), 40 deletions(-)
---
diff --git a/docs/reference/aravis/aravis-sections.txt b/docs/reference/aravis/aravis-sections.txt
index 57ca32c..978de2b 100644
--- a/docs/reference/aravis/aravis-sections.txt
+++ b/docs/reference/aravis/aravis-sections.txt
@@ -141,6 +141,7 @@ arv_device_read_memory
 arv_device_write_memory
 arv_device_read_register
 arv_device_write_register
+arv_device_get_genicam_xml
 arv_device_get_genicam
 arv_device_execute_command
 arv_device_set_string_feature_value
@@ -393,7 +394,6 @@ ArvGvInterfaceClass
 <TITLE>ArvGvDevice</TITLE>
 ArvGvDevice
 arv_gv_device_new
-arv_gv_device_get_xml
 arv_gv_device_get_timestamp_tick_frequency
 <SUBSECTION Standard>
 ARV_GV_DEVICE
@@ -545,7 +545,7 @@ arv_fake_camera_set_fill_pattern
 arv_fake_camera_set_trigger_frequency
 arv_fake_device_get_fake_camera
 arv_set_fake_camera_genicam_filename
-arv_get_fake_camera_genicam_data
+arv_get_fake_camera_genicam_xml
 <SUBSECTION Standard>
 ARV_FAKE_CAMERA
 ARV_IS_FAKE_CAMERA
diff --git a/src/arvdevice.c b/src/arvdevice.c
index c4247d7..bd3e180 100644
--- a/src/arvdevice.c
+++ b/src/arvdevice.c
@@ -102,6 +102,32 @@ arv_device_get_genicam (ArvDevice *device)
 	return ARV_DEVICE_GET_CLASS (device)->get_genicam (device);
 }
 
+static const char *
+_get_genicam_xml (ArvDevice *device, size_t *size)
+{
+	*size = 0;
+
+	return NULL;
+}
+
+/**
+ * arv_device_get_xml:
+ * @device: a #ArvDevice
+ * @size: placeholder for the returned data size (bytes)
+ * Return value: a pointer to the Genicam XML data, owned by the device.
+ *
+ * Gets the Genicam XML data stored in the device memory.
+ **/
+
+const char *
+arv_device_get_genicam_xml (ArvDevice *device, size_t *size)
+{
+	g_return_val_if_fail (ARV_IS_DEVICE (device), NULL);
+	g_return_val_if_fail (size != NULL, NULL);
+
+	return ARV_DEVICE_GET_CLASS (device)->get_genicam_xml (device, size);
+}
+
 void
 arv_device_execute_command (ArvDevice *device, const char *feature)
 {
@@ -257,6 +283,8 @@ arv_device_class_init (ArvDeviceClass *device_class)
 	parent_class = g_type_class_peek_parent (device_class);
 
 	object_class->finalize = arv_device_finalize;
+
+	device_class->get_genicam_xml = _get_genicam_xml;
 }
 
 G_DEFINE_ABSTRACT_TYPE (ArvDevice, arv_device, G_TYPE_OBJECT)
diff --git a/src/arvdevice.h b/src/arvdevice.h
index 32250b0..228d6fb 100644
--- a/src/arvdevice.h
+++ b/src/arvdevice.h
@@ -46,6 +46,7 @@ struct _ArvDeviceClass {
 
 	ArvStream *	(*create_stream)	(ArvDevice *device, ArvStreamCallback callback, void *user_data);
 
+	const char *	(*get_genicam_xml)	(ArvDevice *device, size_t *size);
 	ArvGc *		(*get_genicam)		(ArvDevice *device);
 
 	gboolean	(*read_memory)		(ArvDevice *device, guint32 address, guint32 size, void *buffer);
@@ -64,6 +65,7 @@ gboolean	arv_device_write_memory	 	(ArvDevice *device, guint32 address, guint32
 gboolean 	arv_device_read_register	(ArvDevice *device, guint32 address, guint32 *value);
 gboolean	arv_device_write_register 	(ArvDevice *device, guint32 address, guint32 value);
 
+const char * 	arv_device_get_genicam_xml 		(ArvDevice *device, size_t *size);
 ArvGc *		arv_device_get_genicam			(ArvDevice *device);
 
 void 		arv_device_execute_command 		(ArvDevice *device, const char *feature);
diff --git a/src/arvfakecamera.c b/src/arvfakecamera.c
index f0ebdbd..fc30f11 100644
--- a/src/arvfakecamera.c
+++ b/src/arvfakecamera.c
@@ -43,8 +43,8 @@ static GObjectClass *parent_class = NULL;
 
 struct _ArvFakeCameraPrivate {
 	void *memory;
-	const void *genicam_data;
-	size_t genicam_data_size;
+	const void *genicam_xml;
+	size_t genicam_xml_size;
 
 	guint32 frame_id;
 	double trigger_frequency;
@@ -78,9 +78,9 @@ arv_fake_camera_read_memory (ArvFakeCamera *camera, guint32 address, guint32 siz
 	}
 
 	address -= ARV_FAKE_CAMERA_MEMORY_SIZE;
-	read_size = MIN (address + size, camera->priv->genicam_data_size) - address;
+	read_size = MIN (address + size, camera->priv->genicam_xml_size) - address;
 
-	memcpy (buffer, camera->priv->genicam_data + address, read_size);
+	memcpy (buffer, camera->priv->genicam_xml + address, read_size);
 
 	return TRUE;
 }
@@ -89,7 +89,7 @@ gboolean
 arv_fake_camera_write_memory (ArvFakeCamera *camera, guint32 address, guint32 size, const void *buffer)
 {
 	g_return_val_if_fail (ARV_IS_FAKE_CAMERA (camera), FALSE);
-	g_return_val_if_fail (address + size < ARV_FAKE_CAMERA_MEMORY_SIZE + camera->priv->genicam_data_size, FALSE);
+	g_return_val_if_fail (address + size < ARV_FAKE_CAMERA_MEMORY_SIZE + camera->priv->genicam_xml_size, FALSE);
 	g_return_val_if_fail (buffer != NULL, FALSE);
 	g_return_val_if_fail (size > 0, FALSE);
 
@@ -342,7 +342,7 @@ arv_set_fake_camera_genicam_filename (const char *filename)
 }
 
 const char *
-arv_get_fake_camera_genicam_data (size_t *size)
+arv_get_fake_camera_genicam_xml (size_t *size)
 {
 	static GMappedFile *genicam_file = NULL;
 	static GStaticMutex mutex = G_STATIC_MUTEX_INIT;
@@ -400,7 +400,7 @@ arv_fake_camera_new (const char *serial_number)
 	fake_camera->priv->fill_pattern = arv_fake_camera_diagonal_ramp;
 	fake_camera->priv->fill_pattern_data = NULL;
 
-	fake_camera->priv->genicam_data = arv_get_fake_camera_genicam_data (&fake_camera->priv->genicam_data_size);
+	fake_camera->priv->genicam_xml = arv_get_fake_camera_genicam_xml (&fake_camera->priv->genicam_xml_size);
 	fake_camera->priv->memory = memory;
 
 	strcpy (memory + ARV_GVBS_MANUFACTURER_NAME, "Aravis");
@@ -411,7 +411,7 @@ arv_fake_camera_new (const char *serial_number)
 	xml_url = g_strdup_printf ("Local:arv-fake-camera-%s.xml;%x;%x",
 				   PACKAGE_VERSION,
 				   ARV_FAKE_CAMERA_MEMORY_SIZE,
-				   (unsigned int) fake_camera->priv->genicam_data_size);
+				   (unsigned int) fake_camera->priv->genicam_xml_size);
 	strcpy (memory + ARV_GVBS_FIRST_XML_URL, xml_url);
 	g_free (xml_url);
 
diff --git a/src/arvfakecamera.h b/src/arvfakecamera.h
index dc87600..fe1aa34 100644
--- a/src/arvfakecamera.h
+++ b/src/arvfakecamera.h
@@ -127,7 +127,7 @@ void		arv_fake_camera_set_fill_pattern	(ArvFakeCamera *camera,
 void 		arv_fake_camera_set_trigger_frequency 	(ArvFakeCamera *camera, double frequency);
 
 void 		arv_set_fake_camera_genicam_filename 	(const char *filename);
-const char *	arv_get_fake_camera_genicam_data	(size_t *size);
+const char *	arv_get_fake_camera_genicam_xml		(size_t *size);
 
 G_END_DECLS
 
diff --git a/src/arvfakedevice.c b/src/arvfakedevice.c
index 6f47ced..9070de6 100644
--- a/src/arvfakedevice.c
+++ b/src/arvfakedevice.c
@@ -35,6 +35,9 @@ static GObjectClass *parent_class = NULL;
 struct _ArvFakeDevicePrivate {
 	ArvFakeCamera *camera;
 	ArvGc *genicam;
+
+	const char *genicam_xml;
+	size_t genicam_xml_size;
 };
 
 /* ArvFakeDevice implemenation */
@@ -52,6 +55,16 @@ arv_fake_device_create_stream (ArvDevice *device, ArvStreamCallback callback, vo
 	return stream;
 }
 
+static const char *
+arv_fake_device_get_genicam_xml (ArvDevice *device, size_t *size)
+{
+	ArvFakeDevice *fake_device = ARV_FAKE_DEVICE (device);
+
+	*size = fake_device->priv->genicam_xml_size;
+
+	return fake_device->priv->genicam_xml;
+}
+
 static ArvGc *
 arv_fake_device_get_genicam (ArvDevice *device)
 {
@@ -96,8 +109,6 @@ ArvDevice *
 arv_fake_device_new (const char *serial_number)
 {
 	ArvFakeDevice *fake_device;
-	const void *genicam_data;
-	size_t genicam_data_size;
 
 	g_return_val_if_fail (serial_number != NULL, NULL);
 
@@ -105,8 +116,10 @@ arv_fake_device_new (const char *serial_number)
 
 	fake_device->priv->camera = arv_fake_camera_new (serial_number);
 
-	genicam_data = arv_get_fake_camera_genicam_data (&genicam_data_size);
-	fake_device->priv->genicam = arv_gc_new (ARV_DEVICE (fake_device), genicam_data, genicam_data_size);
+	fake_device->priv->genicam_xml = arv_get_fake_camera_genicam_xml (&fake_device->priv->genicam_xml_size);
+	fake_device->priv->genicam = arv_gc_new (ARV_DEVICE (fake_device),
+						 fake_device->priv->genicam_xml,
+						 fake_device->priv->genicam_xml_size);
 
 	return ARV_DEVICE (fake_device);
 }
@@ -141,6 +154,7 @@ arv_fake_device_class_init (ArvFakeDeviceClass *fake_device_class)
 	object_class->finalize = arv_fake_device_finalize;
 
 	device_class->create_stream = arv_fake_device_create_stream;
+	device_class->get_genicam_xml = arv_fake_device_get_genicam_xml;
 	device_class->get_genicam = arv_fake_device_get_genicam;
 	device_class->read_memory = arv_fake_device_read_memory;
 	device_class->write_memory = arv_fake_device_write_memory;
diff --git a/src/arvgvdevice.c b/src/arvgvdevice.c
index 76cded8..195f6d4 100644
--- a/src/arvgvdevice.c
+++ b/src/arvgvdevice.c
@@ -46,6 +46,9 @@ struct _ArvGvDevicePrivate {
 	void *heartbeat_data;
 
 	ArvGc *genicam;
+
+	char *genicam_xml;
+	size_t genicam_xml_size;
 };
 
 /* Shared data (main thread - heartbeat) */
@@ -415,40 +418,39 @@ _load_genicam (ArvGvDevice *gv_device, guint32 address, size_t  *size)
 	return genicam;
 }
 
-/**
- * arv_gv_device_get_xml:
- * @gv_device: a #ArvGvDevice
- * @size: placeholder for the returned data size (bytes)
- * Return value: a newly allocated buffer with the Genicam xml data.
- *
- * Gets the Genicam data stored in the device memory. The buffer must be freed after use using g_free.
- **/
-
-char *
-arv_gv_device_get_xml (ArvGvDevice *gv_device, size_t *size)
+static const char *
+arv_gv_device_get_genicam_xml (ArvDevice *device, size_t *size)
 {
 	char *xml;
 
-	g_return_val_if_fail (ARV_IS_GV_DEVICE (gv_device), NULL);
+	ArvGvDevice *gv_device = ARV_GV_DEVICE (device);
+
+	if (gv_device->priv->genicam_xml != NULL) {
+		*size = gv_device->priv->genicam_xml_size;
+		return gv_device->priv->genicam_xml;
+	}
+
+	*size = 0;
 
 	xml = _load_genicam (gv_device, ARV_GVBS_FIRST_XML_URL, size);
 	if (xml == NULL)
 		xml = _load_genicam (gv_device, ARV_GVBS_SECOND_XML_URL, size);
 
+	gv_device->priv->genicam_xml = xml;
+	gv_device->priv->genicam_xml_size = *size;
+
 	return xml;
 }
 
 static void
 arv_gv_device_load_genicam (ArvGvDevice *gv_device)
 {
-	char *genicam;
+	const char *genicam;
 	size_t size;
 
-	genicam = arv_gv_device_get_xml (gv_device, &size);
-	if (genicam != NULL) {
+	genicam = arv_gv_device_get_genicam_xml (ARV_DEVICE (gv_device), &size);
+	if (genicam != NULL)
 		gv_device->priv->genicam = arv_gc_new (ARV_DEVICE (gv_device), genicam, size);
-		g_free (genicam);
-	}
 }
 
 /* ArvDevice implemenation */
@@ -609,6 +611,8 @@ arv_gv_device_init (ArvGvDevice *gv_device)
 	gv_device->priv = G_TYPE_INSTANCE_GET_PRIVATE (gv_device, ARV_TYPE_GV_DEVICE, ArvGvDevicePrivate);
 
 	gv_device->priv->genicam = NULL;
+	gv_device->priv->genicam_xml = NULL;
+	gv_device->priv->genicam_xml_size = 0;
 }
 
 static void
@@ -644,6 +648,8 @@ arv_gv_device_finalize (GObject *object)
 	if (gv_device->priv->genicam != NULL)
 		g_object_unref (gv_device->priv->genicam);
 
+	g_free (gv_device->priv->genicam_xml);
+
 	parent_class->finalize (object);
 }
 
@@ -660,6 +666,7 @@ arv_gv_device_class_init (ArvGvDeviceClass *gv_device_class)
 	object_class->finalize = arv_gv_device_finalize;
 
 	device_class->create_stream = arv_gv_device_create_stream;
+	device_class->get_genicam_xml = arv_gv_device_get_genicam_xml;
 	device_class->get_genicam = arv_gv_device_get_genicam;
 	device_class->read_memory = arv_gv_device_read_memory;
 	device_class->write_memory = arv_gv_device_write_memory;
diff --git a/src/arvgvdevice.h b/src/arvgvdevice.h
index bc7ca4f..e67bb39 100644
--- a/src/arvgvdevice.h
+++ b/src/arvgvdevice.h
@@ -57,7 +57,6 @@ struct _ArvGvDeviceClass {
 GType arv_gv_device_get_type (void);
 
 ArvDevice * 	arv_gv_device_new 	(GInetAddress *interface_address, GInetAddress *device_address);
-char *		arv_gv_device_get_xml 	(ArvGvDevice *gv_device, size_t *size);
 
 guint64 	arv_gv_device_get_timestamp_tick_frequency 	(ArvGvDevice *gv_device);
 
diff --git a/src/arvshowdevices.c b/src/arvshowdevices.c
index 5c75a69..3e8c9fb 100644
--- a/src/arvshowdevices.c
+++ b/src/arvshowdevices.c
@@ -2,13 +2,43 @@
 #include <stdlib.h>
 #include <stdio.h>
 
+static char *arv_option_camera_name = NULL;
+static gboolean arv_option_show_xml = FALSE;
+static char *arv_option_debug_domains = NULL;
+
+static const GOptionEntry arv_option_entries[] =
+{
+	{ "name",		'n', 0, G_OPTION_ARG_STRING,
+		&arv_option_camera_name,"Camera name", NULL},
+	{ "xml",		'x', 0, G_OPTION_ARG_NONE,
+		&arv_option_show_xml,	"Show XML", NULL},
+	{ "debug", 		'd', 0, G_OPTION_ARG_STRING,
+		&arv_option_debug_domains, 	"Debug domains", NULL },
+	{ NULL }
+};
+
 int
 main (int argc, char **argv)
 {
 	unsigned int n_devices;
+	GOptionContext *context;
+	GError *error = NULL;
 
+	g_thread_init (NULL);
 	g_type_init ();
 
+	context = g_option_context_new (NULL);
+	g_option_context_add_main_entries (context, arv_option_entries, NULL);
+
+	if (!g_option_context_parse (context, &argc, &argv, &error)) {
+		g_option_context_free (context);
+		g_print ("Option parsing failed: %s\n", error->message);
+		g_error_free (error);
+		return EXIT_FAILURE;
+	}
+
+	g_option_context_free (context);
+
 	arv_update_device_list ();
 	n_devices = arv_get_n_devices ();
 	if (n_devices < 1)
@@ -20,8 +50,27 @@ main (int argc, char **argv)
 			const char *device_id;
 
 			device_id = arv_get_device_id (i);
-			if (device_id != NULL)
-				printf ("%s\n",  device_id);
+			if (arv_option_camera_name == NULL ||
+			    g_strcmp0 (device_id, arv_option_camera_name) == 0) {
+				if (device_id != NULL)
+					printf ("%s\n",  device_id);
+
+				if (arv_option_show_xml) {
+					ArvDevice *device;
+
+					device = arv_open_device (device_id);
+					if (ARV_IS_DEVICE (device)) {
+						const char *xml;
+						size_t size;
+
+						xml = arv_device_get_genicam_xml (device, &size);
+						if (xml != NULL)
+							printf ("%*s\n", (int) size, xml);
+					}
+
+					g_object_unref (device);
+				}
+			}
 		}
 	}
 
diff --git a/tests/fake.c b/tests/fake.c
index c6b3855..4d3ad3a 100644
--- a/tests/fake.c
+++ b/tests/fake.c
@@ -4,15 +4,15 @@
 static void
 load_fake_camera_genicam_test (void)
 {
-	const char *genicam_data;
+	const char *genicam_xml;
 	size_t size;
 
-	genicam_data = arv_get_fake_camera_genicam_data (&size);
-	g_assert (genicam_data != NULL);
+	genicam_xml = arv_get_fake_camera_genicam_xml (&size);
+	g_assert (genicam_xml != NULL);
 	g_assert (size != 0);
 
-	genicam_data = arv_get_fake_camera_genicam_data (NULL);
-	g_assert (genicam_data != NULL);
+	genicam_xml = arv_get_fake_camera_genicam_xml (NULL);
+	g_assert (genicam_xml != NULL);
 }
 
 static void



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