summaryrefslogtreecommitdiffstats
path: root/plugins/mock/uca-mock-camera.c
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/mock/uca-mock-camera.c')
-rw-r--r--plugins/mock/uca-mock-camera.c93
1 files changed, 68 insertions, 25 deletions
diff --git a/plugins/mock/uca-mock-camera.c b/plugins/mock/uca-mock-camera.c
index bf3124e..675d5ec 100644
--- a/plugins/mock/uca-mock-camera.c
+++ b/plugins/mock/uca-mock-camera.c
@@ -16,12 +16,17 @@
Franklin St, Fifth Floor, Boston, MA 02110, USA */
#include <gmodule.h>
+#include <gio/gio.h>
#include <string.h>
#include "uca-mock-camera.h"
#define UCA_MOCK_CAMERA_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE((obj), UCA_TYPE_MOCK_CAMERA, UcaMockCameraPrivate))
-G_DEFINE_TYPE(UcaMockCamera, uca_mock_camera, UCA_TYPE_CAMERA)
+static void uca_mock_initable_iface_init (GInitableIface *iface);
+
+G_DEFINE_TYPE_WITH_CODE (UcaMockCamera, uca_mock_camera, UCA_TYPE_CAMERA,
+ G_IMPLEMENT_INTERFACE (G_TYPE_INITABLE,
+ uca_mock_initable_iface_init))
enum {
PROP_FRAMERATE = N_BASE_PROPERTIES,
@@ -38,6 +43,7 @@ static const gint mock_overrideables[] = {
PROP_SENSOR_VERTICAL_BINNING,
PROP_SENSOR_VERTICAL_BINNINGS,
PROP_EXPOSURE_TIME,
+ PROP_TRIGGER_MODE,
PROP_ROI_X,
PROP_ROI_Y,
PROP_ROI_WIDTH,
@@ -53,6 +59,8 @@ static const gint mock_overrideables[] = {
static GParamSpec *mock_properties[N_PROPERTIES] = { NULL, };
struct _UcaMockCameraPrivate {
+ UcaCameraTrigger trigger;
+
guint width;
guint height;
guint roi_x, roi_y, roi_width, roi_height;
@@ -134,7 +142,8 @@ static const char g_digits[10][20] = {
static const guint DIGIT_WIDTH = 4;
static const guint DIGIT_HEIGHT = 5;
-static void print_number(gchar *buffer, guint number, guint x, guint y, guint width)
+static void
+print_number(gchar *buffer, guint number, guint x, guint y, guint width)
{
for (int i = 0; i < DIGIT_WIDTH; i++) {
for (int j = 0; j < DIGIT_HEIGHT; j++) {
@@ -143,7 +152,8 @@ static void print_number(gchar *buffer, guint number, guint x, guint y, guint wi
}
}
-static void print_current_frame(UcaMockCameraPrivate *priv, gchar *buffer)
+static void
+print_current_frame(UcaMockCameraPrivate *priv, gchar *buffer)
{
guint number = priv->current_frame;
guint divisor = 10000000;
@@ -157,7 +167,8 @@ static void print_current_frame(UcaMockCameraPrivate *priv, gchar *buffer)
}
}
-static gpointer mock_grab_func(gpointer data)
+static gpointer
+mock_grab_func(gpointer data)
{
UcaMockCamera *mock_camera = UCA_MOCK_CAMERA(data);
g_return_val_if_fail(UCA_IS_MOCK_CAMERA(mock_camera), NULL);
@@ -174,7 +185,8 @@ static gpointer mock_grab_func(gpointer data)
return NULL;
}
-static void uca_mock_camera_start_recording(UcaCamera *camera, GError **error)
+static void
+uca_mock_camera_start_recording(UcaCamera *camera, GError **error)
{
gboolean transfer_async = FALSE;
UcaMockCameraPrivate *priv;
@@ -204,7 +216,8 @@ static void uca_mock_camera_start_recording(UcaCamera *camera, GError **error)
}
}
-static void uca_mock_camera_stop_recording(UcaCamera *camera, GError **error)
+static void
+uca_mock_camera_stop_recording(UcaCamera *camera, GError **error)
{
gboolean transfer_async = FALSE;
UcaMockCameraPrivate *priv;
@@ -224,22 +237,27 @@ static void uca_mock_camera_stop_recording(UcaCamera *camera, GError **error)
}
}
-static void uca_mock_camera_grab(UcaCamera *camera, gpointer *data, GError **error)
+static void
+uca_mock_camera_trigger (UcaCamera *camera, GError **error)
{
- g_return_if_fail(UCA_IS_MOCK_CAMERA(camera));
- g_return_if_fail(data != NULL);
+}
- UcaMockCameraPrivate *priv = UCA_MOCK_CAMERA_GET_PRIVATE(camera);
+static gboolean
+uca_mock_camera_grab (UcaCamera *camera, gpointer data, GError **error)
+{
+ g_return_val_if_fail (UCA_IS_MOCK_CAMERA(camera), FALSE);
- if (*data == NULL)
- *data = g_malloc0(priv->width * priv->height);
+ UcaMockCameraPrivate *priv = UCA_MOCK_CAMERA_GET_PRIVATE (camera);
- g_memmove(*data, priv->dummy_data, priv->width * priv->height);
- print_current_frame(priv, *data);
+ g_memmove (data, priv->dummy_data, priv->roi_width * priv->roi_height);
+ print_current_frame (priv, data);
priv->current_frame++;
+
+ return TRUE;
}
-static void uca_mock_camera_set_property(GObject *object, guint property_id, const GValue *value, GParamSpec *pspec)
+static void
+uca_mock_camera_set_property (GObject *object, guint property_id, const GValue *value, GParamSpec *pspec)
{
g_return_if_fail(UCA_IS_MOCK_CAMERA(object));
UcaMockCameraPrivate *priv = UCA_MOCK_CAMERA_GET_PRIVATE(object);
@@ -263,13 +281,17 @@ static void uca_mock_camera_set_property(GObject *object, guint property_id, con
case PROP_ROI_HEIGHT:
priv->roi_height = g_value_get_uint(value);
break;
+ case PROP_TRIGGER_MODE:
+ priv->trigger = g_value_get_enum (value);
+ break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID(object, property_id, pspec);
return;
}
}
-static void uca_mock_camera_get_property(GObject *object, guint property_id, GValue *value, GParamSpec *pspec)
+static void
+uca_mock_camera_get_property(GObject *object, guint property_id, GValue *value, GParamSpec *pspec)
{
UcaMockCameraPrivate *priv = UCA_MOCK_CAMERA_GET_PRIVATE(object);
@@ -331,13 +353,17 @@ static void uca_mock_camera_get_property(GObject *object, guint property_id, GVa
case PROP_FRAMERATE:
g_value_set_float(value, priv->frame_rate);
break;
+ case PROP_TRIGGER_MODE:
+ g_value_set_enum (value, priv->trigger);
+ break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID(object, property_id, pspec);
break;
}
}
-static void uca_mock_camera_finalize(GObject *object)
+static void
+uca_mock_camera_finalize(GObject *object)
{
UcaMockCameraPrivate *priv = UCA_MOCK_CAMERA_GET_PRIVATE(object);
@@ -352,7 +378,23 @@ static void uca_mock_camera_finalize(GObject *object)
G_OBJECT_CLASS(uca_mock_camera_parent_class)->finalize(object);
}
-static void uca_mock_camera_class_init(UcaMockCameraClass *klass)
+static gboolean
+ufo_mock_camera_initable_init (GInitable *initable,
+ GCancellable *cancellable,
+ GError **error)
+{
+ g_return_val_if_fail (UCA_IS_MOCK_CAMERA (initable), FALSE);
+ return TRUE;
+}
+
+static void
+uca_mock_initable_iface_init (GInitableIface *iface)
+{
+ iface->init = ufo_mock_camera_initable_init;
+}
+
+static void
+uca_mock_camera_class_init(UcaMockCameraClass *klass)
{
GObjectClass *gobject_class = G_OBJECT_CLASS(klass);
gobject_class->set_property = uca_mock_camera_set_property;
@@ -363,6 +405,7 @@ static void uca_mock_camera_class_init(UcaMockCameraClass *klass)
camera_class->start_recording = uca_mock_camera_start_recording;
camera_class->stop_recording = uca_mock_camera_stop_recording;
camera_class->grab = uca_mock_camera_grab;
+ camera_class->trigger = uca_mock_camera_trigger;
for (guint i = 0; mock_overrideables[i] != 0; i++)
g_object_class_override_property(gobject_class, mock_overrideables[i], uca_camera_props[mock_overrideables[i]]);
@@ -380,13 +423,14 @@ static void uca_mock_camera_class_init(UcaMockCameraClass *klass)
g_type_class_add_private(klass, sizeof(UcaMockCameraPrivate));
}
-static void uca_mock_camera_init(UcaMockCamera *self)
+static void
+uca_mock_camera_init(UcaMockCamera *self)
{
self->priv = UCA_MOCK_CAMERA_GET_PRIVATE(self);
self->priv->roi_x = 0;
self->priv->roi_y = 0;
- self->priv->width = self->priv->roi_width = 640;
- self->priv->height = self->priv->roi_height = 480;
+ self->priv->width = self->priv->roi_width = 2016;
+ self->priv->height = self->priv->roi_height = 2016;
self->priv->frame_rate = self->priv->max_frame_rate = 100000.0f;
self->priv->grab_thread = NULL;
self->priv->current_frame = 0;
@@ -401,9 +445,8 @@ static void uca_mock_camera_init(UcaMockCamera *self)
uca_camera_register_unit (UCA_CAMERA (self), "frame-rate", UCA_UNIT_COUNT);
}
-G_MODULE_EXPORT UcaCamera *
-uca_camera_impl_new (GError **error)
+G_MODULE_EXPORT GType
+uca_camera_get_type (void)
{
- UcaCamera *camera = UCA_CAMERA (g_object_new (UCA_TYPE_MOCK_CAMERA, NULL));
- return camera;
+ return UCA_TYPE_MOCK_CAMERA;
}