[aravis] Add arv_interface_get_device_address
- From: Emmanuel Pacaud <emmanuel src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [aravis] Add arv_interface_get_device_address
- Date: Fri, 8 Jun 2012 14:43:06 +0000 (UTC)
commit b32c0c04f0db27cde5569893129e01c5b8a75884
Author: John Stowers <john stowers gmail com>
Date: Wed Jun 6 23:24:13 2012 +0200
Add arv_interface_get_device_address
Returns the IP address of the detected camera. Useful when
constructing manual devices using arv_gv_device_new
https://bugzilla.gnome.org/show_bug.cgi?id=677709
Signed-off-by: Emmanuel Pacaud <emmanuel gnome org>
src/arvfakeinterface.c | 2 ++
src/arvgvinterface.c | 22 ++++++++++++++++++----
src/arvinterface.c | 29 +++++++++++++++++++++++++++++
src/arvinterface.h | 2 ++
4 files changed, 51 insertions(+), 4 deletions(-)
---
diff --git a/src/arvfakeinterface.c b/src/arvfakeinterface.c
index c13a209..52819a0 100644
--- a/src/arvfakeinterface.c
+++ b/src/arvfakeinterface.c
@@ -31,6 +31,7 @@
#define ARV_FAKE_DEVICE_ID "Fake_1"
#define ARV_FAKE_PHYSICAL_ID "Fake_1"
+#define ARV_FAKE_ADDRESS "0.0.0.0"
static GObjectClass *parent_class = NULL;
@@ -49,6 +50,7 @@ arv_fake_interface_update_device_list (ArvInterface *interface, GArray *device_i
ids->device = g_strdup (ARV_FAKE_DEVICE_ID);
ids->physical = g_strdup (ARV_FAKE_PHYSICAL_ID);
+ ids->address = g_strdup (ARV_FAKE_ADDRESS);
g_array_append_val (device_ids, ids);
}
diff --git a/src/arvgvinterface.c b/src/arvgvinterface.c
index f3ed551..a23dff6 100644
--- a/src/arvgvinterface.c
+++ b/src/arvgvinterface.c
@@ -300,6 +300,18 @@ arv_gv_interface_receive_hello_packet (ArvGvInterface *gv_interface)
} while (1);
}
+static GInetAddress *
+_device_infos_to_ginetaddress (ArvGvInterfaceDeviceInfos *device_infos)
+{
+ GInetAddress *device_address;
+
+ device_address = g_inet_address_new_from_bytes
+ (&device_infos->discovery_data[ARV_GVBS_CURRENT_IP_ADDRESS_OFFSET],
+ G_SOCKET_FAMILY_IPV4);
+
+ return device_address;
+}
+
static void
arv_gv_interface_update_device_list (ArvInterface *interface, GArray *device_ids)
{
@@ -317,12 +329,16 @@ 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)) {
ArvInterfaceDeviceIds *ids;
+ GInetAddress *device_address;
ArvGvInterfaceDeviceInfos *infos = value;
ids = g_new0 (ArvInterfaceDeviceIds, 1);
ids->device = g_strdup (key);
- ids->physical = g_strdup (infos->mac_string);
+ ids->physical = g_strdup (infos->mac_string);
+ device_address = _device_infos_to_ginetaddress (infos);
+ ids->address = g_inet_address_to_string (device_address);
+ g_object_unref (device_address);
g_array_append_val (device_ids, ids);
}
@@ -354,9 +370,7 @@ arv_gv_interface_open_device (ArvInterface *interface, const char *device_id)
if (device_infos == NULL)
return NULL;
- device_address = g_inet_address_new_from_bytes
- (&device_infos->discovery_data[ARV_GVBS_CURRENT_IP_ADDRESS_OFFSET],
- G_SOCKET_FAMILY_IPV4);
+ device_address = _device_infos_to_ginetaddress (device_infos);
device = arv_gv_device_new (device_infos->interface_address, device_address);
g_object_unref (device_address);
diff --git a/src/arvinterface.c b/src/arvinterface.c
index f4378a1..1d618d3 100644
--- a/src/arvinterface.c
+++ b/src/arvinterface.c
@@ -47,6 +47,7 @@ arv_interface_clear_device_ids (ArvInterface *interface)
for (i = 0; i < interface->priv->device_ids->len; i++) {
g_free (g_array_index (interface->priv->device_ids, ArvInterfaceDeviceIds *, i)->device);
g_free (g_array_index (interface->priv->device_ids, ArvInterfaceDeviceIds *, i)->physical);
+ g_free (g_array_index (interface->priv->device_ids, ArvInterfaceDeviceIds *, i)->address);
}
g_array_set_size (interface->priv->device_ids, 0);
}
@@ -135,6 +136,34 @@ arv_interface_get_device_physical_id (ArvInterface *interface, unsigned int inde
return g_array_index (interface->priv->device_ids, ArvInterfaceDeviceIds *, index)->physical;
}
+
+/**
+ * arv_interface_get_device_address
+ * @interface: a #ArvInterface
+ * @index: device index
+ * Return value: the device address
+ *
+ * Returns the device address (IP address in the case of an ethernet camera). Useful
+ * for constructing manual connections to devices using @arv_gv_device_new
+ *
+ * Prior to this call the @arv_interface_update_device_list
+ * function must be called.
+ *
+ * since: 0.1.14
+ **/
+
+const char *
+arv_interface_get_device_address (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, ArvInterfaceDeviceIds *, index)->address;
+}
+
/**
* arv_interface_open_device
* @interface: a #ArvInterface
diff --git a/src/arvinterface.h b/src/arvinterface.h
index f75f7eb..cbc27d4 100644
--- a/src/arvinterface.h
+++ b/src/arvinterface.h
@@ -31,6 +31,7 @@ G_BEGIN_DECLS
typedef struct {
char *device;
char *physical;
+ char *address;
} ArvInterfaceDeviceIds;
#define ARV_TYPE_INTERFACE (arv_interface_get_type ())
@@ -62,6 +63,7 @@ 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);
+const char * arv_interface_get_device_address (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]