[aravis] interface: introduce arv_interface_get_device_physical_id.



commit a65e639db37c90b9eedccaa43b4c862bc5d33be4
Author: Luca Barbato <lu_zero gentoo org>
Date:   Fri Jan 27 21:36:30 2012 +0100

    interface: introduce arv_interface_get_device_physical_id.
    
    And update accordingly fake and gv interfaces.

 src/arvfakeinterface.c |    8 ++++++--
 src/arvgvinterface.c   |    4 +++-
 src/arvinterface.c     |   31 ++++++++++++++++++++++++++++---
 src/arvinterface.h     |    1 +
 4 files changed, 38 insertions(+), 6 deletions(-)
---
diff --git a/src/arvfakeinterface.c b/src/arvfakeinterface.c
index 00a7bde..47d7301 100644
--- a/src/arvfakeinterface.c
+++ b/src/arvfakeinterface.c
@@ -30,6 +30,7 @@
 #include <arvdebug.h>
 
 #define ARV_FAKE_DEVICE_ID "Fake_1"
+#define ARV_FAKE_PHYSICAL_ID "Fake_1"
 
 static GObjectClass *parent_class = NULL;
 
@@ -40,10 +41,11 @@ struct _ArvFakeInterfacePrivate {
 static void
 arv_fake_interface_update_device_list (ArvInterface *interface, GArray *device_ids)
 {
-	char *device_id;
+	char **device_id = g_new0 (char*, 2 + 1);
 
 	g_array_set_size (device_ids, 0);
-	device_id = g_strdup (ARV_FAKE_DEVICE_ID);
+	device_id[0] = g_strdup (ARV_FAKE_DEVICE_ID);
+	device_id[1] = g_strdup (ARV_FAKE_PHYSICAL_ID);
 	g_array_append_val (device_ids, device_id);
 }
 
@@ -52,6 +54,8 @@ arv_fake_interface_open_device (ArvInterface *interface, const char *device_id)
 {
 	if (g_strcmp0 (device_id, ARV_FAKE_DEVICE_ID) == 0)
 		return arv_fake_device_new ("1");
+	if (g_strcmp0 (device_id, ARV_FAKE_PHYSICAL_ID) == 0)
+		return arv_fake_device_new ("1");
 
 	return NULL;
 }
diff --git a/src/arvgvinterface.c b/src/arvgvinterface.c
index e256d5b..4be7050 100644
--- a/src/arvgvinterface.c
+++ b/src/arvgvinterface.c
@@ -314,7 +314,9 @@ arv_gv_interface_update_device_list (ArvInterface *interface, GArray *device_ids
 
 	g_hash_table_iter_init (&iter, gv_interface->priv->devices);
 	while (g_hash_table_iter_next (&iter, &key, &value)) {
-		char *device_id = g_strdup (key);
+		char **device_id = g_new0 (char*, 2 + 1);
+		device_id[0] = g_strdup (key);
+                device_id[1] = g_strdup (((ArvGvInterfaceDeviceInfos *)value)->mac_string);
 		g_array_append_val (device_ids, device_id);
 	}
 }
diff --git a/src/arvinterface.c b/src/arvinterface.c
index 13e8320..dd642f3 100644
--- a/src/arvinterface.c
+++ b/src/arvinterface.c
@@ -93,10 +93,35 @@ arv_interface_get_device_id (ArvInterface *interface, unsigned int index)
 	if (index >= interface->priv->device_ids->len)
 		return NULL;
 
-	return g_array_index (interface->priv->device_ids, char *, index);
+	return g_array_index (interface->priv->device_ids, char **, index)[0];
 }
 
 /**
+ * arv_interface_get_device_physical_id
+ * @interface: a #ArvInterface
+ * @index: device index
+ * Return value: a physical device id
+ *
+ * Queries the physical device id corresponding to index such
+ * as the MAC address for Ethernet based devices, bus id for PCI,
+ * USB or Firewire based devices.
+ *
+ * Prior to this call the @arv_interface_update_device_list
+ * function must be called.
+ **/
+
+const char *
+arv_interface_get_device_physical_id (ArvInterface *interface, unsigned int index)
+{
+	g_return_val_if_fail (ARV_IS_INTERFACE (interface), 0);
+	g_return_val_if_fail (interface->priv->device_ids != NULL, 0);
+
+	if (index >= interface->priv->device_ids->len)
+		return NULL;
+
+	return g_array_index (interface->priv->device_ids, char **, index)[1];
+}
+/**
  * arv_interface_open_device
  * @interface: a #ArvInterface
  * @device_id: (allow-none): device unique id
@@ -127,7 +152,7 @@ arv_interface_init (ArvInterface *interface)
 {
 	interface->priv = G_TYPE_INSTANCE_GET_PRIVATE (interface, ARV_TYPE_INTERFACE, ArvInterfacePrivate);
 
-	interface->priv->device_ids = g_array_new (FALSE, TRUE, sizeof (char *));
+	interface->priv->device_ids = g_array_new (FALSE, TRUE, sizeof (char **));
 }
 
 static void
@@ -139,7 +164,7 @@ arv_interface_finalize (GObject *object)
 	parent_class->finalize (object);
 
 	for (i = 0; i < interface->priv->device_ids->len; i++)
-		g_free (g_array_index (interface->priv->device_ids, char *, i));
+		g_strfreev (g_array_index (interface->priv->device_ids, char **, i));
 	g_array_free (interface->priv->device_ids, TRUE);
 	interface->priv->device_ids = NULL;
 }
diff --git a/src/arvinterface.h b/src/arvinterface.h
index 48fead8..976d174 100644
--- a/src/arvinterface.h
+++ b/src/arvinterface.h
@@ -55,6 +55,7 @@ GType arv_interface_get_type (void);
 void 			arv_interface_update_device_list 	(ArvInterface *interface);
 unsigned int 		arv_interface_get_n_devices 		(ArvInterface *interface);
 const char * 		arv_interface_get_device_id 		(ArvInterface *interface, unsigned int index);
+const char * 		arv_interface_get_device_physical_id 	(ArvInterface *interface, unsigned int index);
 ArvDevice * 		arv_interface_open_device 		(ArvInterface *interface, const char *device_id);
 
 G_END_DECLS



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