diff options
| -rw-r--r-- | src/uca-camera.c | 99 | ||||
| -rw-r--r-- | src/uca-camera.h | 9 | ||||
| -rw-r--r-- | test/test-mock.c | 68 | 
3 files changed, 143 insertions, 33 deletions
diff --git a/src/uca-camera.c b/src/uca-camera.c index 27af765..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  }; @@ -980,6 +985,26 @@ uca_camera_grab (UcaCamera *camera, gpointer data, GError **error)      return result;  } +static GParamSpec * +get_param_spec_by_name (UcaCamera *camera, +                        const gchar *prop_name) +{ +    UcaCameraClass *klass; +    GObjectClass *oclass; +    GParamSpec *pspec; + +    klass  = UCA_CAMERA_GET_CLASS (camera); +    oclass = G_OBJECT_CLASS (klass); +    pspec  = g_object_class_find_property (oclass, prop_name); + +    if (pspec == NULL) { +        g_warning ("Camera does not have property `%s'", prop_name); +        return NULL; +    } + +    return pspec; +} +  /**   * uca_camera_register_unit:   * @camera: A #UcaCamera object @@ -995,20 +1020,12 @@ uca_camera_register_unit (UcaCamera *camera,                            const gchar *prop_name,                            UcaUnit unit)  { -    UcaCameraClass *klass; -    GObjectClass *oclass;      GParamSpec *pspec; -    klass  = UCA_CAMERA_GET_CLASS (camera); -    oclass = G_OBJECT_CLASS (klass); -    pspec  = g_object_class_find_property (oclass, prop_name); +    pspec = get_param_spec_by_name (camera, prop_name); -    if (pspec == NULL) { -        g_warning ("Camera does not have property `%s'", prop_name); -        return; -    } - -    uca_camera_set_property_unit (pspec, unit); +    if (pspec != NULL) +        uca_camera_set_property_unit (pspec, unit);  }  /** @@ -1026,21 +1043,65 @@ UcaUnit  uca_camera_get_unit (UcaCamera *camera,                       const gchar *prop_name)  { -    UcaCameraClass *klass; -    GObjectClass *oclass;      GParamSpec *pspec;      gpointer data; -    klass  = UCA_CAMERA_GET_CLASS (camera); -    oclass = G_OBJECT_CLASS (klass); -    pspec  = g_object_class_find_property (oclass, prop_name); +    pspec  = get_param_spec_by_name (camera, prop_name); -    if (pspec == NULL) { -        g_warning ("Camera does not have property `%s'", prop_name); +    if (pspec == NULL)          return UCA_UNIT_NA; -    }      data = g_param_spec_get_qdata (pspec, UCA_UNIT_QUARK);      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 d1dcf3a..c0acc9c 100644 --- a/test/test-mock.c +++ b/test/test-mock.c @@ -215,9 +215,7 @@ test_signal (Fixture *fixture, gconstpointer data)      UcaCamera *camera = UCA_CAMERA (fixture->camera);      gboolean success = FALSE;      g_signal_connect (camera, "notify::frames-per-second", (GCallback) on_property_change, &success); -    g_object_set (G_OBJECT (camera), -            "frames-per-second", 30.0, -            NULL); +    g_object_set (G_OBJECT (camera), "frames-per-second", 30.0, NULL);      g_assert (success == TRUE);  } @@ -227,8 +225,38 @@ 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; +  #if !(GLIB_CHECK_VERSION (2, 36, 0))      g_type_init ();  #endif @@ -236,17 +264,29 @@ int main (int argc, char *argv[])      g_test_init (&argc, &argv, NULL);      g_test_bug_base ("http://ufo.kit.edu/ufo/ticket"); -    g_test_add ("/factory", Fixture, NULL, fixture_setup, test_factory, fixture_teardown); -    g_test_add ("/recording", Fixture, NULL, fixture_setup, test_recording, fixture_teardown); -    g_test_add ("/recording/signal", Fixture, NULL, fixture_setup, test_recording_signal, fixture_teardown); -    g_test_add ("/recording/asynchronous", Fixture, NULL, fixture_setup, test_recording_async, fixture_teardown); -    g_test_add ("/properties/base", Fixture, NULL, fixture_setup, test_base_properties, fixture_teardown); -    g_test_add ("/properties/recording", Fixture, NULL, fixture_setup, test_recording_property, fixture_teardown); -    g_test_add ("/properties/binnings", Fixture, NULL, fixture_setup, test_binnings_properties, fixture_teardown); -    g_test_add ("/properties/frames-per-second", Fixture, NULL, fixture_setup, test_fps_property, fixture_teardown); -    g_test_add ("/properties/units", Fixture, NULL, fixture_setup, test_property_units, fixture_teardown); -    g_test_add ("/properties/units/overwrite", Fixture, NULL, fixture_setup, test_overwriting_units, fixture_teardown); -    g_test_add ("/signal", Fixture, NULL, fixture_setup, test_signal, fixture_teardown); +    struct { +        const gchar *name; +        void (*test_func) (Fixture *fixture, gconstpointer data); +    } +    tests[] = { +        {"/factory", test_factory}, +        {"/signal", test_signal}, +        {"/recording", test_recording}, +        {"/recording/signal", test_recording_signal}, +        {"/recording/asynchronous", test_recording_async}, +        {"/properties/base", test_base_properties}, +        {"/properties/recording", test_recording_property}, +        {"/properties/binnings", test_binnings_properties}, +        {"/properties/frames-per-second", test_fps_property}, +        {"/properties/units", test_property_units}, +        {"/properties/units/overwrite", test_overwriting_units}, +        {"/properties/can-be-written", test_can_be_written}, +    }; + +    n_tests = sizeof(tests) / sizeof(tests[0]); + +    for (gsize i = 0; i < n_tests; i++) +        g_test_add (tests[i].name, Fixture, NULL, fixture_setup, tests[i].test_func, fixture_teardown);      return g_test_run ();  }  | 
