[aravis] gv_device: add a "control-lost" signal.
- From: Emmanuel Pacaud <emmanuel src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [aravis] gv_device: add a "control-lost" signal.
- Date: Wed, 6 Jul 2011 09:37:40 +0000 (UTC)
commit 3b35a2915dd1421e07f7e183121280c7a10b0a9e
Author: Emmanuel Pacaud <emmanuel gnome org>
Date: Wed Jul 6 11:35:55 2011 +0200
gv_device: add a "control-lost" signal.
This signal is emited when control of a device is lost.
src/arvgvdevice.c | 33 ++++++++++++++++++++++++++++++++-
src/arvgvdevice.h | 3 +++
src/arvstream.h | 1 +
tests/arvcameratest.c | 12 ++++++++++++
4 files changed, 48 insertions(+), 1 deletions(-)
---
diff --git a/src/arvgvdevice.c b/src/arvgvdevice.c
index 748987f..e74325f 100644
--- a/src/arvgvdevice.c
+++ b/src/arvgvdevice.c
@@ -34,6 +34,13 @@
#include <string.h>
#include <stdlib.h>
+enum {
+ ARV_GV_DEVICE_SIGNAL_CONTROL_LOST,
+ ARV_GV_DEVICE_SIGNAL_LAST
+} ArvGvDeviceSignals;
+
+static guint arv_gv_device_signals[ARV_GV_DEVICE_SIGNAL_LAST] = {0};
+
static GObjectClass *parent_class = NULL;
static GRegex *arv_gv_device_url_regex = NULL;
@@ -324,6 +331,7 @@ _write_register (ArvGvDeviceIOData *io_data, guint32 address, guint32 value)
/* Heartbeat thread */
typedef struct {
+ ArvGvDevice *gv_device;
ArvGvDeviceIOData *io_data;
int period_us;
gboolean cancel;
@@ -351,6 +359,10 @@ arv_gv_device_heartbeat_thread (void *data)
if ((value & (ARV_GVBS_CONTROL_CHANNEL_PRIVILEGE_CONTROL |
ARV_GVBS_CONTROL_CHANNEL_PRIVILEGE_EXCLUSIVE)) == 0) {
arv_warning_device ("[GvDevice::Heartbeat] Control access lost");
+
+ g_signal_emit (thread_data->gv_device,
+ arv_gv_device_signals[ARV_GV_DEVICE_SIGNAL_CONTROL_LOST], 0);
+
io_data->is_controller = FALSE;
}
}
@@ -383,9 +395,10 @@ arv_gv_device_leave_control (ArvGvDevice *gv_device)
{
gboolean success;
+ gv_device->priv->io_data->is_controller = FALSE;
+
success = arv_device_write_register (ARV_DEVICE (gv_device),
ARV_GVBS_CONTROL_CHANNEL_PRIVILEGE_OFFSET, 0);
- gv_device->priv->io_data->is_controller = FALSE;
return success;
}
@@ -711,6 +724,7 @@ arv_gv_device_new (GInetAddress *interface_address, GInetAddress *device_address
arv_gv_device_take_control (gv_device);
heartbeat_data = g_new (ArvGvDeviceHeartbeatData, 1);
+ heartbeat_data->gv_device = gv_device;
heartbeat_data->io_data = io_data;
heartbeat_data->period_us = 1000000;
heartbeat_data->cancel = FALSE;
@@ -792,6 +806,23 @@ arv_gv_device_class_init (ArvGvDeviceClass *gv_device_class)
device_class->read_register = arv_gv_device_read_register;
device_class->write_register = arv_gv_device_write_register;
+ /**
+ * ArvGvDevice::control-lost:
+ * @gv_device:a #ArvGvDevice
+ *
+ * Signal that the control of the device is lost.
+ *
+ * This signal is emited from the heartbeat thread, so please take care to shared data access.
+ */
+
+ arv_gv_device_signals[ARV_GV_DEVICE_SIGNAL_CONTROL_LOST] =
+ g_signal_new ("control-lost",
+ G_TYPE_FROM_CLASS (gv_device_class),
+ G_SIGNAL_RUN_LAST,
+ G_STRUCT_OFFSET (ArvGvDeviceClass, control_lost),
+ NULL, NULL,
+ g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0, G_TYPE_NONE);
+
arv_gv_device_url_regex = g_regex_new ("^(local:|file:|http:)(.+\\.[^;]+);?([0-9:a-f]*)?;?([0-9:a-f]*)?$",
G_REGEX_CASELESS, 0, NULL);
}
diff --git a/src/arvgvdevice.h b/src/arvgvdevice.h
index 9281f67..190af79 100644
--- a/src/arvgvdevice.h
+++ b/src/arvgvdevice.h
@@ -54,6 +54,9 @@ struct _ArvGvDevice {
struct _ArvGvDeviceClass {
ArvDeviceClass parent_class;
+
+ /* signals */
+ void (*control_lost) (ArvGvDevice *gv_device);
};
GType arv_gv_device_get_type (void);
diff --git a/src/arvstream.h b/src/arvstream.h
index e1c2d2f..d1f539f 100644
--- a/src/arvstream.h
+++ b/src/arvstream.h
@@ -68,6 +68,7 @@ struct _ArvStreamClass {
void (*get_statistics) (ArvStream *stream, guint64 *n_completed_buffers,
guint64 *n_failures, guint64 *n_underruns);
+ /* signals */
void (*new_buffer) (ArvStream *stream);
};
diff --git a/tests/arvcameratest.c b/tests/arvcameratest.c
index 45db418..4e4dafa 100644
--- a/tests/arvcameratest.c
+++ b/tests/arvcameratest.c
@@ -141,6 +141,14 @@ emit_software_trigger (void *abstract_data)
return TRUE;
}
+static void
+control_lost_cb (ArvGvDevice *gv_device)
+{
+ g_printf ("Control lost\n");
+
+ cancel = TRUE;
+}
+
int
main (int argc, char **argv)
{
@@ -251,6 +259,10 @@ main (int argc, char **argv)
g_signal_connect (stream, "new-buffer", G_CALLBACK (new_buffer_cb), &data);
arv_stream_set_emit_signals (stream, TRUE);
+ if (ARV_IS_GV_DEVICE (arv_camera_get_device (camera)))
+ g_signal_connect (arv_camera_get_device (camera), "control-lost",
+ G_CALLBACK (control_lost_cb), NULL);
+
g_timeout_add_seconds (1, periodic_task_cb, &data);
data.main_loop = g_main_loop_new (NULL, FALSE);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]