diff options
author | Matthias Vogelgesang <matthias.vogelgesang@kit.edu> | 2012-03-02 10:31:40 +0100 |
---|---|---|
committer | Matthias Vogelgesang <matthias.vogelgesang@kit.edu> | 2012-03-02 10:31:40 +0100 |
commit | a8436e9b42a1b5a2b30b13a13496539fc23f480e (patch) | |
tree | b757c3a60b00ea3affd0ba10a92d9457194e4121 /src/uca-camera.c | |
parent | e26a093b4036083f13265bcbde5eae442d502377 (diff) | |
download | libuca-a8436e9b42a1b5a2b30b13a13496539fc23f480e.tar.gz libuca-a8436e9b42a1b5a2b30b13a13496539fc23f480e.tar.bz2 libuca-a8436e9b42a1b5a2b30b13a13496539fc23f480e.tar.xz libuca-a8436e9b42a1b5a2b30b13a13496539fc23f480e.zip |
Make UcaCamera a base class not an interface
Diffstat (limited to 'src/uca-camera.c')
-rw-r--r-- | src/uca-camera.c | 88 |
1 files changed, 72 insertions, 16 deletions
diff --git a/src/uca-camera.c b/src/uca-camera.c index cb7890b..d8c1a25 100644 --- a/src/uca-camera.c +++ b/src/uca-camera.c @@ -18,7 +18,19 @@ #include <glib.h> #include "uca-camera.h" -G_DEFINE_INTERFACE(UcaCamera, uca_camera, G_TYPE_OBJECT) +#define UCA_CAMERA_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE((obj), UCA_TYPE_CAMERA, UcaCameraPrivate)) + +G_DEFINE_TYPE(UcaCamera, uca_camera, G_TYPE_OBJECT) + +/** + * UcaCameraError: + * @UCA_CAMERA_ERROR_RECORDING: Camera is already recording + * @UCA_CAMERA_ERROR_NOT_RECORDING: Camera is not recording + */ +GQuark uca_camera_error_quark() +{ + return g_quark_from_static_string("uca-camera-error-quark"); +} enum { PROP_0 = 0, @@ -30,10 +42,26 @@ enum { N_PROPERTIES }; +struct _UcaCameraPrivate { + gboolean recording; +}; + static GParamSpec *uca_camera_properties[N_PROPERTIES] = { NULL, }; -static void uca_camera_default_init(UcaCameraInterface *klass) +static void uca_camera_set_property(GObject *object, guint property_id, const GValue *value, GParamSpec *pspec) +{ +} + +static void uca_camera_get_property(GObject *object, guint property_id, GValue *value, GParamSpec *pspec) +{ +} + +static void uca_camera_class_init(UcaCameraClass *klass) { + GObjectClass *gobject_class = G_OBJECT_CLASS(klass); + gobject_class->set_property = uca_camera_set_property; + gobject_class->get_property = uca_camera_get_property; + klass->start_recording = NULL; klass->stop_recording = NULL; klass->grab = NULL; @@ -73,43 +101,71 @@ static void uca_camera_default_init(UcaCameraInterface *klass) 1, G_MAXUINT, 1, G_PARAM_READWRITE); - for (int i = PROP_0 + 1; i < N_PROPERTIES; i++) - g_object_interface_install_property(klass, uca_camera_properties[i]); + for (guint id = PROP_0 + 1; id < N_PROPERTIES; id++) + g_object_class_install_property(gobject_class, id, uca_camera_properties[id]); + + g_type_class_add_private(klass, sizeof(UcaCameraPrivate)); +} + +static void uca_camera_init(UcaCamera *camera) +{ + camera->priv = UCA_CAMERA_GET_PRIVATE(camera); + camera->priv->recording = FALSE; } void uca_camera_start_recording(UcaCamera *camera, GError **error) { g_return_if_fail(UCA_IS_CAMERA(camera)); - UcaCameraInterface *iface = UCA_CAMERA_GET_INTERFACE(camera); + UcaCameraClass *klass = UCA_CAMERA_GET_CLASS(camera); + + g_return_if_fail(klass != NULL); + g_return_if_fail(klass->start_recording != NULL); - g_return_if_fail(iface != NULL); - g_return_if_fail(iface->start_recording != NULL); + if (camera->priv->recording) { + g_set_error(error, UCA_CAMERA_ERROR, UCA_CAMERA_ERROR_RECORDING, + "Camera is already recording"); + return; + } - (*iface->start_recording)(camera, error); + camera->priv->recording = TRUE; + (*klass->start_recording)(camera, error); } void uca_camera_stop_recording(UcaCamera *camera, GError **error) { g_return_if_fail(UCA_IS_CAMERA(camera)); - UcaCameraInterface *iface = UCA_CAMERA_GET_INTERFACE(camera); + UcaCameraClass *klass = UCA_CAMERA_GET_CLASS(camera); - g_return_if_fail(iface != NULL); - g_return_if_fail(iface->start_recording != NULL); + g_return_if_fail(klass != NULL); + g_return_if_fail(klass->stop_recording != NULL); - (*iface->stop_recording)(camera, error); + if (!camera->priv->recording) { + g_set_error(error, UCA_CAMERA_ERROR, UCA_CAMERA_ERROR_NOT_RECORDING, + "Camera is not recording"); + return; + } + + camera->priv->recording = FALSE; + (*klass->stop_recording)(camera, error); } void uca_camera_grab(UcaCamera *camera, gchar *data, GError **error) { g_return_if_fail(UCA_IS_CAMERA(camera)); - UcaCameraInterface *iface = UCA_CAMERA_GET_INTERFACE(camera); + UcaCameraClass *klass = UCA_CAMERA_GET_CLASS(camera); + + g_return_if_fail(klass != NULL); + g_return_if_fail(klass->grab != NULL); - g_return_if_fail(iface != NULL); - g_return_if_fail(iface->start_recording != NULL); + if (!camera->priv->recording) { + g_set_error(error, UCA_CAMERA_ERROR, UCA_CAMERA_ERROR_NOT_RECORDING, + "Camera is not recording"); + return; + } - (*iface->grab)(camera, data, error); + (*klass->grab)(camera, data, error); } |