summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthias Vogelgesang <matthias.vogelgesang@kit.edu>2014-08-08 10:08:52 +0200
committerMatthias Vogelgesang <matthias.vogelgesang@kit.edu>2014-08-13 14:50:05 +0200
commita389a30e57a038dcfc83dc2814d56a4a1c9a6084 (patch)
tree4ac0ac99502280cbed19c64c4040d60d960a253f
parentdfa5d1b2fe44226092f87362ba1558df41efa4d6 (diff)
downloaduca-a389a30e57a038dcfc83dc2814d56a4a1c9a6084.tar.gz
uca-a389a30e57a038dcfc83dc2814d56a4a1c9a6084.tar.bz2
uca-a389a30e57a038dcfc83dc2814d56a4a1c9a6084.tar.xz
uca-a389a30e57a038dcfc83dc2814d56a4a1c9a6084.zip
Fix #41: add write accessibility API
-rw-r--r--src/uca-camera.c55
-rw-r--r--src/uca-camera.h9
-rw-r--r--test/test-mock.c31
3 files changed, 94 insertions, 1 deletions
diff --git a/src/uca-camera.c b/src/uca-camera.c
index 46e7cb7..fce3d12 100644
--- a/src/uca-camera.c
+++ b/src/uca-camera.c
@@ -76,6 +76,11 @@ GQuark uca_unit_quark ()
return g_quark_from_static_string ("uca-unit-quark");
}
+GQuark uca_writable_quark ()
+{
+ return g_quark_from_static_string ("uca-writable-quark");
+}
+
enum {
LAST_SIGNAL
};
@@ -1050,3 +1055,53 @@ uca_camera_get_unit (UcaCamera *camera,
return data == NULL ? UCA_UNIT_NA : GPOINTER_TO_INT (data);
}
+/**
+ * uca_camera_set_writable:
+ * @camera: A #UcaCamera object
+ * @prop_name: Name of property
+ * @writable: %TRUE if property can be written during acquisition
+ *
+ * Sets a flag that defines if @prop_name can be written during an acquisition.
+ *
+ * Since: 1.6
+ */
+void
+uca_camera_set_writable (UcaCamera *camera,
+ const gchar *prop_name,
+ gboolean writable)
+{
+ GParamSpec *pspec;
+
+ pspec = get_param_spec_by_name (camera, prop_name);
+
+ if (pspec != NULL) {
+ if (g_param_spec_get_qdata (pspec, UCA_WRITABLE_QUARK) != NULL)
+ g_warning ("::%s is already fixed", pspec->name);
+ else
+ g_param_spec_set_qdata (pspec, UCA_WRITABLE_QUARK, GINT_TO_POINTER (writable));
+ }
+}
+
+/**
+ * uca_camera_is_writable_during_acquisition:
+ * @camera: A #UcaCamera object
+ * @prop_name: Name of property
+ *
+ * Check if @prop_name can be written at run-time. This is %FALSE if the
+ * property is read-only, if uca_camera_set_writable() has not been called or
+ * uca_camera_set_writable() was called with %FALSE.
+ *
+ * Returns: %TRUE if the property can be written at acquisition time.
+ * Since: 1.6
+ */
+gboolean
+uca_camera_is_writable_during_acquisition (UcaCamera *camera,
+ const gchar *prop_name)
+{
+ GParamSpec *pspec;
+
+ pspec = get_param_spec_by_name (camera, prop_name);
+
+ return (pspec->flags & G_PARAM_WRITABLE) &&
+ g_param_spec_get_qdata (pspec, UCA_WRITABLE_QUARK);
+}
diff --git a/src/uca-camera.h b/src/uca-camera.h
index f4030d6..d958870 100644
--- a/src/uca-camera.h
+++ b/src/uca-camera.h
@@ -31,9 +31,11 @@ G_BEGIN_DECLS
#define UCA_CAMERA_ERROR uca_camera_error_quark()
#define UCA_UNIT_QUARK uca_unit_quark()
+#define UCA_WRITABLE_QUARK uca_writable_quark()
GQuark uca_camera_error_quark(void);
GQuark uca_unit_quark(void);
+GQuark uca_writable_quark(void);
typedef enum {
UCA_CAMERA_ERROR_NOT_FOUND,
@@ -162,6 +164,13 @@ void uca_camera_register_unit (UcaCamera *camera,
UcaUnit unit);
UcaUnit uca_camera_get_unit (UcaCamera *camera,
const gchar *prop_name);
+void uca_camera_set_writable (UcaCamera *camera,
+ const gchar *prop_name,
+ gboolean writable);
+gboolean uca_camera_is_writable_during_acquisition
+ (UcaCamera *camera,
+ const gchar *prop_name);
+
GType uca_camera_get_type(void);
diff --git a/test/test-mock.c b/test/test-mock.c
index 16ef30c..c0acc9c 100644
--- a/test/test-mock.c
+++ b/test/test-mock.c
@@ -225,6 +225,34 @@ test_overwriting_units (Fixture *fixture, gconstpointer data)
uca_camera_register_unit (fixture->camera, "sensor-width", UCA_UNIT_PIXEL);
}
+static void
+test_can_be_written (Fixture *fixture, gconstpointer data)
+{
+ GError *error = NULL;
+
+ /* read-only cannot ever be written */
+ g_assert (!uca_camera_is_writable_during_acquisition (fixture->camera, "name"));
+
+ /* unset properties cannot be written */
+ g_assert (!uca_camera_is_writable_during_acquisition (fixture->camera, "roi-width"));
+
+ /* check trivial cases */
+ uca_camera_set_writable (fixture->camera, "roi-width", TRUE);
+ g_assert (uca_camera_is_writable_during_acquisition (fixture->camera, "roi-width"));
+
+ uca_camera_set_writable (fixture->camera, "roi-height", FALSE);
+ g_assert (!uca_camera_is_writable_during_acquisition (fixture->camera, "roi-height"));
+
+ /* Now, do a real test */
+ uca_camera_set_writable (fixture->camera, "roi-height", TRUE);
+ uca_camera_start_recording (fixture->camera, &error);
+ g_assert_no_error (error);
+
+ g_object_set (fixture->camera, "roi-height", 128, NULL);
+ uca_camera_stop_recording (fixture->camera, &error);
+ g_assert_no_error (error);
+}
+
int main (int argc, char *argv[])
{
gsize n_tests;
@@ -251,7 +279,8 @@ int main (int argc, char *argv[])
{"/properties/binnings", test_binnings_properties},
{"/properties/frames-per-second", test_fps_property},
{"/properties/units", test_property_units},
- {"/properties/units/overwrite", test_overwriting_units}
+ {"/properties/units/overwrite", test_overwriting_units},
+ {"/properties/can-be-written", test_can_be_written},
};
n_tests = sizeof(tests) / sizeof(tests[0]);