[aravis] device: move the "control-lost" signal from GvDevice to Device.



commit 65adc59aab7ddfc23777ea158483612bbd83573c
Author: Emmanuel Pacaud <emmanuel gnome org>
Date:   Wed Jul 6 22:58:08 2011 +0200

    device: move the "control-lost" signal from GvDevice to Device.
    
    It probably make sense for other protocol than GigE Vision.

 docs/reference/aravis/aravis-sections.txt |    2 +
 src/arvdevice.c                           |   33 +++++++++++++++++
 src/arvdevice.h                           |    5 +++
 src/arvgvdevice.c                         |   57 +++++++++++------------------
 src/arvgvdevice.h                         |    4 +--
 tests/arvcameratest.c                     |    5 +--
 6 files changed, 65 insertions(+), 41 deletions(-)
---
diff --git a/docs/reference/aravis/aravis-sections.txt b/docs/reference/aravis/aravis-sections.txt
index cb56f92..0033184 100644
--- a/docs/reference/aravis/aravis-sections.txt
+++ b/docs/reference/aravis/aravis-sections.txt
@@ -167,6 +167,7 @@ arv_device_get_integer_feature_bounds
 arv_device_set_float_feature_value
 arv_device_get_float_feature_value
 arv_device_get_float_feature_bounds
+arv_device_emit_control_lost_signal
 <SUBSECTION Standard>
 ARV_DEVICE
 ARV_IS_DEVICE
@@ -430,6 +431,7 @@ ARV_GV_DEVICE_GET_CLASS
 ARV_GV_DEVICE_GVCP_N_RETRIES_DEFAULT
 ARV_GV_DEVICE_GVCP_TIMEOUT_MS_DEFAULT
 ARV_GV_DEVICE_GVSP_PACKET_SIZE_DEFAULT
+ARV_GV_DEVICE_HEARTBEAT_PERIOD_US
 ARV_GV_DEVICE_HEARTBEAT_RETRY_DELAY_US
 ARV_GV_DEVICE_BUFFER_SIZE
 ArvGvDeviceClass
diff --git a/src/arvdevice.c b/src/arvdevice.c
index 5929356..e418f9c 100644
--- a/src/arvdevice.c
+++ b/src/arvdevice.c
@@ -39,6 +39,13 @@
 #include <arvgcstring.h>
 #include <arvstream.h>
 
+enum {
+	ARV_DEVICE_SIGNAL_CONTROL_LOST,
+	ARV_DEVICE_SIGNAL_LAST
+} ArvDeviceSignals;
+
+static guint arv_device_signals[ARV_DEVICE_SIGNAL_LAST] = {0};
+
 static GObjectClass *parent_class = NULL;
 
 /**
@@ -287,6 +294,14 @@ arv_device_get_float_feature_bounds (ArvDevice *device, const char *feature, dou
 	}
 }
 
+void
+arv_device_emit_control_lost_signal (ArvDevice *device)
+{
+	g_return_if_fail (ARV_IS_DEVICE (device));
+
+	g_signal_emit (device, arv_device_signals[ARV_DEVICE_SIGNAL_CONTROL_LOST], 0);
+}
+
 static void
 arv_device_init (ArvDevice *device)
 {
@@ -308,6 +323,24 @@ arv_device_class_init (ArvDeviceClass *device_class)
 	object_class->finalize = arv_device_finalize;
 
 	device_class->get_genicam_xml = _get_genicam_xml;
+
+	/**
+	 * ArvDevice::control-lost:
+	 * @device:a #ArvDevice
+	 *
+	 * Signal that the control of the device is lost.
+	 *
+	 * This signal may be emited from a thread different than the main one,
+	 * so please take care to shared data access from the callback.
+	 */
+
+	arv_device_signals[ARV_DEVICE_SIGNAL_CONTROL_LOST] =
+		g_signal_new ("control-lost",
+			      G_TYPE_FROM_CLASS (device_class),
+			      G_SIGNAL_RUN_LAST,
+			      G_STRUCT_OFFSET (ArvDeviceClass, control_lost),
+			      NULL, NULL,
+			      g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0, G_TYPE_NONE);
 }
 
 G_DEFINE_ABSTRACT_TYPE (ArvDevice, arv_device, G_TYPE_OBJECT)
diff --git a/src/arvdevice.h b/src/arvdevice.h
index b92b456..02560eb 100644
--- a/src/arvdevice.h
+++ b/src/arvdevice.h
@@ -53,6 +53,9 @@ struct _ArvDeviceClass {
 	gboolean	(*write_memory)		(ArvDevice *device, guint32 address, guint32 size, void *buffer);
 	gboolean	(*read_register)	(ArvDevice *device, guint32 address, guint32 *value);
 	gboolean	(*write_register)	(ArvDevice *device, guint32 address, guint32 value);
+
+	/* signals */
+	void		(*control_lost)		(ArvDevice *device);
 };
 
 GType arv_device_get_type (void);
@@ -85,6 +88,8 @@ double		arv_device_get_float_feature_value	(ArvDevice *device, const char *featu
 void 		arv_device_get_float_feature_bounds 	(ArvDevice *device, const char *feature,
 							 double *min, double *max);
 
+void 		arv_device_emit_control_lost_signal 	(ArvDevice *device);
+
 G_END_DECLS
 
 #endif
diff --git a/src/arvgvdevice.c b/src/arvgvdevice.c
index 2942749..a933d69 100644
--- a/src/arvgvdevice.c
+++ b/src/arvgvdevice.c
@@ -34,13 +34,6 @@
 #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;
 
@@ -342,8 +335,11 @@ arv_gv_device_heartbeat_thread (void *data)
 {
 	ArvGvDeviceHeartbeatData *thread_data = data;
 	ArvGvDeviceIOData *io_data = thread_data->io_data;
+	GTimer *timer;
 	guint32 value;
 
+	timer = g_timer_new ();
+
 	do {
 		g_usleep (thread_data->period_us);
 
@@ -354,28 +350,36 @@ arv_gv_device_heartbeat_thread (void *data)
 			 * timeout value, which is interresting, as doing this we could get an error
 			 * ack packet which will indicate we lost the control access. */
 
-			while (!_read_register (io_data, ARV_GVBS_CONTROL_CHANNEL_PRIVILEGE_OFFSET, &value)) {
+			g_timer_start (timer);
+
+			while (!_read_register (io_data, ARV_GVBS_CONTROL_CHANNEL_PRIVILEGE_OFFSET, &value) &&
+			       g_timer_elapsed (timer, NULL) < 5.0 /* FIXME */ &&
+			       !thread_data->cancel) {
 				g_usleep (ARV_GV_DEVICE_HEARTBEAT_RETRY_DELAY_US);
 				counter++;
 			}
 
-			arv_log_device ("[GvDevice::Heartbeat] Ack value = %d", value);
+			if (!thread_data->cancel) {
+				arv_log_device ("[GvDevice::Heartbeat] Ack value = %d", value);
 
-			if (counter > 1)
-				arv_log_device ("[GvDevice::Heartbeat] Tried %u times", counter);
+				if (counter > 1)
+					arv_log_device ("[GvDevice::Heartbeat] Tried %u times", counter);
 
-			if ((value & (ARV_GVBS_CONTROL_CHANNEL_PRIVILEGE_CONTROL |
-				      ARV_GVBS_CONTROL_CHANNEL_PRIVILEGE_EXCLUSIVE)) == 0) {
-				arv_warning_device ("[GvDevice::Heartbeat] Control access lost");
+				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);
+					arv_device_emit_control_lost_signal (ARV_DEVICE (thread_data->gv_device));
 
+					io_data->is_controller = FALSE;
+				}
+			} else
 				io_data->is_controller = FALSE;
-			}
 		}
 	} while (!thread_data->cancel);
 
+	g_timer_destroy (timer);
+
 	return NULL;
 }
 
@@ -734,7 +738,7 @@ arv_gv_device_new (GInetAddress *interface_address, GInetAddress *device_address
 	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->period_us = ARV_GV_DEVICE_HEARTBEAT_PERIOD_US;
 	heartbeat_data->cancel = FALSE;
 
 	gv_device->priv->heartbeat_data = heartbeat_data;
@@ -814,23 +818,6 @@ 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 36a9978..9277e5b 100644
--- a/src/arvgvdevice.h
+++ b/src/arvgvdevice.h
@@ -31,6 +31,7 @@ G_BEGIN_DECLS
 
 #define	ARV_GV_DEVICE_GVCP_N_RETRIES_DEFAULT	5
 #define	ARV_GV_DEVICE_GVCP_TIMEOUT_MS_DEFAULT	500
+#define	ARV_GV_DEVICE_HEARTBEAT_PERIOD_US	1000000
 #define	ARV_GV_DEVICE_HEARTBEAT_RETRY_DELAY_US	10000
 
 #define ARV_GV_DEVICE_GVSP_PACKET_SIZE_DEFAULT	1500
@@ -55,9 +56,6 @@ struct _ArvGvDevice {
 
 struct _ArvGvDeviceClass {
 	ArvDeviceClass parent_class;
-
-	/* signals */
-	void		(*control_lost)		(ArvGvDevice *gv_device);
 };
 
 GType arv_gv_device_get_type (void);
diff --git a/tests/arvcameratest.c b/tests/arvcameratest.c
index 4e4dafa..d03b0e5 100644
--- a/tests/arvcameratest.c
+++ b/tests/arvcameratest.c
@@ -259,9 +259,8 @@ 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_signal_connect (arv_camera_get_device (camera), "control-lost",
+					  G_CALLBACK (control_lost_cb), NULL);
 
 			g_timeout_add_seconds (1, periodic_task_cb, &data);
 



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