[aravis] Add a new arv-show-devices utility.
- From: Emmanuel Pacaud <emmanuel src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [aravis] Add a new arv-show-devices utility.
- Date: Mon, 27 Sep 2010 12:19:12 +0000 (UTC)
commit f02e035efbab3581f54b6fe7e79767d5eebcd119
Author: Emmanuel Pacaud <emmanuel gnome org>
Date: Mon Sep 27 14:18:02 2010 +0200
Add a new arv-show-devices utility.
This utility lists all the available devices on all available interfaces.
.gitignore | 1 +
docs/reference/aravis/aravis-sections.txt | 10 +++-
src/.gitignore | 1 +
src/Makefile.am | 5 +-
src/arvfakeinterface.c | 15 ++++-
src/arvgvinterface.c | 24 ++++++--
src/arvinterface.c | 88 +++++++++++++++++++++++++--
src/arvinterface.h | 9 ++-
src/arvshowdevices.c | 24 ++++++++
src/arvsystem.c | 91 ++++++++++++++++++++++++++---
src/arvsystem.h | 7 ++
11 files changed, 247 insertions(+), 28 deletions(-)
---
diff --git a/.gitignore b/.gitignore
index 4912cd3..348083d 100644
--- a/.gitignore
+++ b/.gitignore
@@ -35,3 +35,4 @@ test-report.*
perf-report.*
gtk-doc.make
gtk-doc.m4
+massif.out.*
diff --git a/docs/reference/aravis/aravis-sections.txt b/docs/reference/aravis/aravis-sections.txt
index 5a71433..60649a2 100644
--- a/docs/reference/aravis/aravis-sections.txt
+++ b/docs/reference/aravis/aravis-sections.txt
@@ -68,7 +68,15 @@ ArvBufferClass
<FILE>arvinterface</FILE>
<TITLE>ArvInterface</TITLE>
ArvInterface
+arv_get_device_id
+arv_get_interface_id
+arv_get_n_devices
+arv_get_n_interfaces
+arv_update_device_list
+arv_create_device
arv_interface_update_device_list
+arv_interface_get_device_id
+arv_interface_get_n_devices
arv_interface_create_device
<SUBSECTION Standard>
ARV_INTERFACE
@@ -80,6 +88,7 @@ ARV_IS_INTERFACE_CLASS
ARV_INTERFACE_GET_CLASS
<SUBSECTION Private>
ArvInterfaceClass
+ArvInterfacePrivate
</SECTION>
<SECTION>
@@ -125,7 +134,6 @@ ArvGcPortClass
<FILE>arvdevice</FILE>
<TITLE>ArvDevice</TITLE>
ArvDevice
-arv_create_device
arv_device_create_stream
arv_device_read_memory
arv_device_write_memory
diff --git a/src/.gitignore b/src/.gitignore
index c687532..85aedbd 100644
--- a/src/.gitignore
+++ b/src/.gitignore
@@ -1,4 +1,5 @@
arv-fake-gv-camera
+arv-show-devices
arvenumtypes.c
arvenumtypes.h
arvconfig.h
diff --git a/src/Makefile.am b/src/Makefile.am
index 97c24bc..00f4c31 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -120,11 +120,14 @@ arvenumtypes.h: arvenumtypes.h.template $(ARAVIS_HDRS) $(GLIB_MKENUMS)
arvenumtypes.c: arvenumtypes.c.template $(ARAVIS_HDRS) $(GLIB_MKENUMS)
$(AM_V_GEN) (cd $(srcdir) && $(GLIB_MKENUMS) --template arvenumtypes.c.template $(libaravis_la_HEADERS)) > $@
-bin_PROGRAMS = arv-fake-gv-camera
+bin_PROGRAMS = arv-fake-gv-camera arv-show-devices
arv_fake_gv_camera_SOURCES = arvfakegvcamera.c
arv_fake_gv_camera_LDADD = $(ARAVIS_LIBS) libaravis.la
+arv_show_devices_SOURCES = arvshowdevices.c
+arv_show_devices_LDADD = $(ARAVIS_LIBS) libaravis.la
+
CLEANFILES = $(BUILT_SOURCES)
if HAVE_INTROSPECTION
diff --git a/src/arvfakeinterface.c b/src/arvfakeinterface.c
index 42686c6..e99688a 100644
--- a/src/arvfakeinterface.c
+++ b/src/arvfakeinterface.c
@@ -29,6 +29,8 @@
#include <arvfakedevice.h>
#include <arvdebug.h>
+#define ARV_FAKE_DEVICE_ID "Fake_1"
+
static GObjectClass *parent_class = NULL;
struct _ArvFakeInterfacePrivate {
@@ -36,14 +38,19 @@ struct _ArvFakeInterfacePrivate {
};
static void
-arv_fake_interface_update_device_list (ArvInterface *interface)
+arv_fake_interface_update_device_list (ArvInterface *interface, GArray *device_ids)
{
+ char *device_id;
+
+ g_array_set_size (device_ids, 0);
+ device_id = g_strdup (ARV_FAKE_DEVICE_ID);
+ g_array_append_val (device_ids, device_id);
}
static ArvDevice *
-arv_fake_interface_new_device (ArvInterface *interface, const char *name)
+arv_fake_interface_create_device (ArvInterface *interface, const char *name)
{
- if (g_strcmp0 (name, "Fake_1") == 0)
+ if (g_strcmp0 (name, ARV_FAKE_DEVICE_ID) == 0)
return arv_fake_device_new ("1");
return NULL;
@@ -101,7 +108,7 @@ arv_fake_interface_class_init (ArvFakeInterfaceClass *fake_interface_class)
object_class->finalize = arv_fake_interface_finalize;
interface_class->update_device_list = arv_fake_interface_update_device_list;
- interface_class->new_device = arv_fake_interface_new_device;
+ interface_class->create_device = arv_fake_interface_create_device;
}
G_DEFINE_TYPE (ArvFakeInterface, arv_fake_interface, ARV_TYPE_INTERFACE)
diff --git a/src/arvgvinterface.c b/src/arvgvinterface.c
index 1ce4a64..b1da82e 100644
--- a/src/arvgvinterface.c
+++ b/src/arvgvinterface.c
@@ -279,14 +279,28 @@ arv_gv_interface_receive_hello_packet (ArvGvInterface *gv_interface)
}
static void
-arv_gv_interface_update_device_list (ArvInterface *interface)
+arv_gv_interface_update_device_list (ArvInterface *interface, GArray *device_ids)
{
- arv_gv_interface_send_discover_packet (ARV_GV_INTERFACE (interface));
- arv_gv_interface_receive_hello_packet (ARV_GV_INTERFACE (interface));
+ ArvGvInterface *gv_interface;
+ GHashTableIter iter;
+ gpointer key, value;
+
+ gv_interface = ARV_GV_INTERFACE (interface);
+
+ arv_gv_interface_send_discover_packet (gv_interface);
+ arv_gv_interface_receive_hello_packet (gv_interface);
+
+ g_array_set_size (device_ids, 0);
+
+ 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);
+ g_array_append_val (device_ids, device_id);
+ }
}
static ArvDevice *
-arv_gv_interface_new_device (ArvInterface *interface, const char *name)
+arv_gv_interface_create_device (ArvInterface *interface, const char *name)
{
ArvGvInterface *gv_interface;
ArvDevice *device = NULL;
@@ -372,7 +386,7 @@ arv_gv_interface_class_init (ArvGvInterfaceClass *gv_interface_class)
object_class->finalize = arv_gv_interface_finalize;
interface_class->update_device_list = arv_gv_interface_update_device_list;
- interface_class->new_device = arv_gv_interface_new_device;
+ interface_class->create_device = arv_gv_interface_create_device;
}
G_DEFINE_TYPE (ArvGvInterface, arv_gv_interface, ARV_TYPE_INTERFACE)
diff --git a/src/arvinterface.c b/src/arvinterface.c
index 20199ca..559d8eb 100644
--- a/src/arvinterface.c
+++ b/src/arvinterface.c
@@ -26,7 +26,7 @@
*
* #ArvCamera is an abstract base class for camera discovery. It maintains a
* list of the available devices and help to instantiate the corresponding
- * #ArvDevice object. If user already knows he name of the device, it should
+ * #ArvDevice object. If user already knows he name of the device, he should
* not worry about this class and just use arv_camera_new() or
* arv_create_device().
*/
@@ -35,14 +35,75 @@
static GObjectClass *parent_class = NULL;
+struct _ArvInterfacePrivate {
+ GArray *device_ids;
+};
+
+/**
+ * arv_interface_update_device_list
+ * @interface: a #ArvInterface
+ *
+ * Updates the internal list of available devices. This may change the
+ * connection between a list index and a device ID.
+ **/
+
void
arv_interface_update_device_list (ArvInterface *interface)
{
g_return_if_fail (ARV_IS_INTERFACE (interface));
- ARV_INTERFACE_GET_CLASS (interface)->update_device_list (interface);
+ ARV_INTERFACE_GET_CLASS (interface)->update_device_list (interface, interface->priv->device_ids);
+}
+
+/**
+ * arv_interface_get_n_devices
+ * @interface: a #ArvInterface
+ * Return value: the number of available devices
+ *
+ * Queries the number of available devices on this interface. Prior to this
+ * call the @arv_interface_update_device_list function must be called. The list content will not
+ * change until the next call of the update function.
+ **/
+
+unsigned int
+arv_interface_get_n_devices (ArvInterface *interface)
+{
+ g_return_val_if_fail (ARV_IS_INTERFACE (interface), 0);
+ g_return_val_if_fail (interface->priv->device_ids != NULL, 0);
+
+ return interface->priv->device_ids->len;
+}
+
+/**
+ * arv_interface_get_device_id
+ * @interface: a #ArvInterface
+ * @index: device index
+ * Return value: a unique device id
+ *
+ * Queries the unique device id corresponding to index. Prior to this
+ * call the @arv_interface_update_device_list function must be called.
+ **/
+
+const char *
+arv_interface_get_device_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);
}
+/**
+ * arv_interface_create_device
+ * @interface: a #ArvInterface
+ * @name: device unique id or name
+ *
+ * Creates a new #ArvDevice object corresponding to the given name.
+ **/
+
ArvDevice *
arv_interface_create_device (ArvInterface *interface, const char *name)
{
@@ -50,33 +111,46 @@ arv_interface_create_device (ArvInterface *interface, const char *name)
g_return_val_if_fail (ARV_IS_INTERFACE (interface), NULL);
- device = ARV_INTERFACE_GET_CLASS (interface)->new_device (interface, name);
+ device = ARV_INTERFACE_GET_CLASS (interface)->create_device (interface, name);
if (device != NULL)
return device;
arv_interface_update_device_list (interface);
- return ARV_INTERFACE_GET_CLASS (interface)->new_device (interface, name);
+ return ARV_INTERFACE_GET_CLASS (interface)->create_device (interface, name);
}
static void
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 *));
}
static void
arv_interface_finalize (GObject *object)
{
+ ArvInterface *interface = ARV_INTERFACE (object);
+ unsigned int i;
+
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_array_free (interface->priv->device_ids, TRUE);
+ interface->priv->device_ids = NULL;
}
static void
-arv_interface_class_init (ArvInterfaceClass *node_class)
+arv_interface_class_init (ArvInterfaceClass *interface_class)
{
- GObjectClass *object_class = G_OBJECT_CLASS (node_class);
+ GObjectClass *object_class = G_OBJECT_CLASS (interface_class);
+
+ g_type_class_add_private (interface_class, sizeof (ArvInterfacePrivate));
- parent_class = g_type_class_peek_parent (node_class);
+ parent_class = g_type_class_peek_parent (interface_class);
object_class->finalize = arv_interface_finalize;
}
diff --git a/src/arvinterface.h b/src/arvinterface.h
index caff81b..efc7f5f 100644
--- a/src/arvinterface.h
+++ b/src/arvinterface.h
@@ -34,22 +34,27 @@ G_BEGIN_DECLS
#define ARV_IS_INTERFACE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), ARV_TYPE_INTERFACE))
#define ARV_INTERFACE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), ARV_TYPE_INTERFACE, ArvInterfaceClass))
+typedef struct _ArvInterfacePrivate ArvInterfacePrivate;
typedef struct _ArvInterfaceClass ArvInterfaceClass;
struct _ArvInterface {
GObject object;
+
+ ArvInterfacePrivate *priv;
};
struct _ArvInterfaceClass {
GObjectClass parent_class;
- void (*update_device_list) (ArvInterface *interface);
- ArvDevice * (*new_device) (ArvInterface *interface, const char *name);
+ void (*update_device_list) (ArvInterface *interface, GArray *device_ids);
+ ArvDevice * (*create_device) (ArvInterface *interface, const char *name);
};
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);
ArvDevice * arv_interface_create_device (ArvInterface *interface, const char *name);
G_END_DECLS
diff --git a/src/arvshowdevices.c b/src/arvshowdevices.c
new file mode 100644
index 0000000..c5ffff7
--- /dev/null
+++ b/src/arvshowdevices.c
@@ -0,0 +1,24 @@
+#include <arv.h>
+#include <stdlib.h>
+#include <stdio.h>
+
+int
+main (int argc, char **argv)
+{
+ unsigned int n_devices;
+
+ g_type_init ();
+
+ 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++)
+ printf ("%s\n", (char *) arv_get_device_id (i));
+ }
+
+ return EXIT_SUCCESS;
+}
diff --git a/src/arvsystem.c b/src/arvsystem.c
index 41eef6c..365e67a 100644
--- a/src/arvsystem.c
+++ b/src/arvsystem.c
@@ -25,21 +25,96 @@
#include <arvfakeinterface.h>
#include <arvdevice.h>
+typedef struct {
+ const char *interface_id;
+ ArvInterface * (*get_interface_instance) (void);
+} ArvInterfaceInfos;
+
+ArvInterfaceInfos interfaces[] = {
+ {"Fake", arv_fake_interface_get_instance},
+ {"GigE-Vision", arv_gv_interface_get_instance}
+};
+
+unsigned int
+arv_get_n_interfaces (void)
+{
+ return G_N_ELEMENTS (interfaces);
+}
+
+const char *
+arv_get_interface_id (unsigned int index)
+{
+ if (index >= G_N_ELEMENTS (interfaces))
+ return NULL;
+
+ return interfaces[index].interface_id;
+}
+
+void
+arv_update_device_list (void)
+{
+ unsigned int i;
+
+ for (i = 0; i < G_N_ELEMENTS (interfaces); i++) {
+ ArvInterface *interface;
+
+ interface = interfaces[i].get_interface_instance ();
+ arv_interface_update_device_list (interface);
+ }
+}
+
+unsigned int
+arv_get_n_devices (void)
+{
+ unsigned int n_devices = 0;
+ unsigned int i;
+
+ for (i = 0; i < G_N_ELEMENTS (interfaces); i++) {
+ ArvInterface *interface;
+
+ interface = interfaces[i].get_interface_instance ();
+ n_devices += arv_interface_get_n_devices (interface);
+ }
+
+ return n_devices;
+}
+
+const char *
+arv_get_device_id (unsigned int index)
+{
+ unsigned int offset = 0;
+ unsigned int i;
+
+ for (i = 0; i < G_N_ELEMENTS (interfaces); i++) {
+ ArvInterface *interface;
+ unsigned int n_devices;
+
+ interface = interfaces[i].get_interface_instance ();
+ n_devices = arv_interface_get_n_devices (interface);
+
+ if (index - offset <= n_devices)
+ return arv_interface_get_device_id (interface, index - offset);
+
+ offset += n_devices;
+ }
+
+ return NULL;
+}
+
ArvDevice *
arv_create_device (const char *name)
{
- ArvInterface *interface;
- ArvDevice *device;
+ unsigned int i;
- interface = arv_fake_interface_get_instance ();
- device = arv_interface_create_device (interface, name);
- if (device != NULL)
- return device;
+ for (i = 0; i < G_N_ELEMENTS (interfaces); i++) {
+ ArvInterface *interface;
+ ArvDevice *device;
- interface = arv_gv_interface_get_instance ();
- device = arv_interface_create_device (interface, name);
+ interface = interfaces[i].get_interface_instance ();
+ device = arv_interface_create_device (interface, name);
if (device != NULL)
return device;
+ }
return NULL;
}
diff --git a/src/arvsystem.h b/src/arvsystem.h
index 128522b..9667020 100644
--- a/src/arvsystem.h
+++ b/src/arvsystem.h
@@ -27,6 +27,13 @@
G_BEGIN_DECLS
+unsigned int arv_get_n_interfaces (void);
+const char * arv_get_interface_id (unsigned int index);
+
+void arv_update_device_list (void);
+unsigned int arv_get_n_devices (void);
+const char * arv_get_device_id (unsigned int index);
+
ArvDevice * arv_create_device (const char *name);
G_END_DECLS
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]