From 85bb97ca9ba14da9753b9b318a54e362772eea98 Mon Sep 17 00:00:00 2001 From: Matthias Vogelgesang Date: Fri, 13 Oct 2017 17:16:04 +0200 Subject: Fix #81: send SIGUSR1 to externally trigger mock --- plugins/mock/uca-mock-camera.c | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) (limited to 'plugins') diff --git a/plugins/mock/uca-mock-camera.c b/plugins/mock/uca-mock-camera.c index d886378..49e1dcd 100644 --- a/plugins/mock/uca-mock-camera.c +++ b/plugins/mock/uca-mock-camera.c @@ -19,6 +19,7 @@ #include #include #include +#include #include "uca-mock-camera.h" #define UCA_MOCK_CAMERA_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE((obj), UCA_TYPE_MOCK_CAMERA, UcaMockCameraPrivate)) @@ -52,6 +53,9 @@ static const gint mock_overrideables[] = { static GParamSpec *mock_properties[N_PROPERTIES] = { NULL, }; +static GMutex signal_mutex; +static GCond signal_cond; + struct _UcaMockCameraPrivate { guint width; guint height; @@ -257,6 +261,14 @@ mock_grab_func(gpointer data) return NULL; } +static void +handle_sigusr1 (int signum) +{ + g_mutex_lock (&signal_mutex); + g_cond_signal (&signal_cond); + g_mutex_unlock (&signal_mutex); +} + static void uca_mock_camera_start_recording(UcaCamera *camera, GError **error) { @@ -265,12 +277,12 @@ uca_mock_camera_start_recording(UcaCamera *camera, GError **error) g_return_if_fail(UCA_IS_MOCK_CAMERA(camera)); priv = UCA_MOCK_CAMERA_GET_PRIVATE(camera); + signal (SIGUSR1, handle_sigusr1); + /* TODO: check that roi_x + roi_width < priv->width */ priv->dummy_data = (guint8 *) g_malloc0(priv->roi_width * priv->roi_height * priv->bytes); - g_object_get(G_OBJECT(camera), - "transfer-asynchronously", &transfer_async, - NULL); + g_object_get(G_OBJECT(camera), "transfer-asynchronously", &transfer_async, NULL); /* * In case asynchronous transfer is requested, we start a new thread that @@ -343,6 +355,13 @@ uca_mock_camera_grab (UcaCamera *camera, gpointer data, GError **error) if (trigger_source == UCA_CAMERA_TRIGGER_SOURCE_SOFTWARE) g_free (g_async_queue_pop (priv->trigger_queue)); + if (trigger_source == UCA_CAMERA_TRIGGER_SOURCE_EXTERNAL) { + /* wait for signal to arrive */ + g_mutex_lock (&signal_mutex); + g_cond_wait (&signal_cond, &signal_mutex); + g_mutex_unlock (&signal_mutex); + } + g_usleep (G_USEC_PER_SEC * exposure_time); if (priv->fill_data) { -- cgit v1.2.3