diff options
author | Matthias Vogelgesang <matthias.vogelgesang@gmail.com> | 2012-04-19 16:45:11 +0200 |
---|---|---|
committer | Matthias Vogelgesang <matthias.vogelgesang@gmail.com> | 2012-04-19 16:45:11 +0200 |
commit | 42e3c64fa57039d7673c61f909b5fd40a437bdfd (patch) | |
tree | b9552183c0b1f56aa98395ac760e5d0ec79b2b0e | |
parent | e23aff7cfa16d7d3446f59e9100341f060a08e11 (diff) | |
download | libuca-42e3c64fa57039d7673c61f909b5fd40a437bdfd.tar.gz libuca-42e3c64fa57039d7673c61f909b5fd40a437bdfd.tar.bz2 libuca-42e3c64fa57039d7673c61f909b5fd40a437bdfd.tar.xz libuca-42e3c64fa57039d7673c61f909b5fd40a437bdfd.zip |
Export base properties and string array
The benefits are two-fold: Camera implementations "know" which base properties
exist without looking into the implementation source. Moreover, they can re-use
the property strings rather than stating them over and over again. These change
should reduce potential c&p errors.
-rw-r--r-- | src/cameras/uca-mock-camera.c | 35 | ||||
-rw-r--r-- | src/cameras/uca-pco-camera.c | 36 | ||||
-rw-r--r-- | src/cameras/uca-ufo-camera.c | 30 | ||||
-rw-r--r-- | src/uca-camera.c | 103 | ||||
-rw-r--r-- | src/uca-camera.h | 27 | ||||
-rw-r--r-- | test/CMakeLists.txt | 14 | ||||
-rw-r--r-- | test/test-all.c | 2 |
7 files changed, 117 insertions, 130 deletions
diff --git a/src/cameras/uca-mock-camera.c b/src/cameras/uca-mock-camera.c index 17a722f..97614a1 100644 --- a/src/cameras/uca-mock-camera.c +++ b/src/cameras/uca-mock-camera.c @@ -23,7 +23,11 @@ G_DEFINE_TYPE(UcaMockCamera, uca_mock_camera, UCA_TYPE_CAMERA) enum { - PROP_0, + PROP_FRAMERATE = N_BASE_PROPERTIES, + N_PROPERTIES +}; + +static const gint mock_overrideables[] = { PROP_SENSOR_WIDTH, PROP_SENSOR_HEIGHT, PROP_SENSOR_BITDEPTH, @@ -39,28 +43,7 @@ enum { PROP_SENSOR_MAX_FRAME_RATE, PROP_HAS_STREAMING, PROP_HAS_CAMRAM_RECORDING, - N_INTERFACE_PROPERTIES, - - PROP_FRAMERATE, - N_PROPERTIES -}; - -static const gchar *mock_overrideables[N_PROPERTIES] = { - "sensor-width", - "sensor-height", - "sensor-bitdepth", - "sensor-horizontal-binning", - "sensor-horizontal-binnings", - "sensor-vertical-binning", - "sensor-vertical-binnings", - "exposure-time", - "roi-x", - "roi-y", - "roi-width", - "roi-height", - "max-frame-rate", - "has-streaming", - "has-camram-recording" + 0, }; static GParamSpec *mock_properties[N_PROPERTIES] = { NULL, }; @@ -357,8 +340,8 @@ static void uca_mock_camera_class_init(UcaMockCameraClass *klass) camera_class->stop_recording = uca_mock_camera_stop_recording; camera_class->grab = uca_mock_camera_grab; - for (guint id = PROP_0 + 1; id < N_INTERFACE_PROPERTIES; id++) - g_object_class_override_property(gobject_class, id, mock_overrideables[id-1]); + 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]]); mock_properties[PROP_FRAMERATE] = g_param_spec_float("frame-rate", @@ -367,7 +350,7 @@ static void uca_mock_camera_class_init(UcaMockCameraClass *klass) 1.0f, 100.0f, 100.0f, G_PARAM_READWRITE); - for (guint id = N_INTERFACE_PROPERTIES + 1; id < N_PROPERTIES; id++) + for (guint id = N_BASE_PROPERTIES; id < N_PROPERTIES; id++) g_object_class_install_property(gobject_class, id, mock_properties[id]); g_type_class_add_private(klass, sizeof(UcaMockCameraPrivate)); diff --git a/src/cameras/uca-pco-camera.c b/src/cameras/uca-pco-camera.c index a2eb259..b808766 100644 --- a/src/cameras/uca-pco-camera.c +++ b/src/cameras/uca-pco-camera.c @@ -70,7 +70,12 @@ GQuark uca_pco_camera_error_quark() } enum { - PROP_0, + PROP_NAME = N_BASE_PROPERTIES, + PROP_COOLING_POINT, + N_PROPERTIES +}; + +static gint base_overrideables[] = { PROP_SENSOR_WIDTH, PROP_SENSOR_HEIGHT, PROP_SENSOR_BITDEPTH, @@ -85,28 +90,7 @@ enum { PROP_ROI_HEIGHT, PROP_HAS_STREAMING, PROP_HAS_CAMRAM_RECORDING, - N_INTERFACE_PROPERTIES, - - PROP_NAME, - PROP_COOLING_POINT, - N_PROPERTIES -}; - -static const gchar *base_overrideables[N_PROPERTIES] = { - "sensor-width", - "sensor-height", - "sensor-bitdepth", - "sensor-horizontal-binning", - "sensor-horizontal-binnings", - "sensor-vertical-binning", - "sensor-vertical-binnings", - "max-frame-rate", - "roi-x", - "roi-y", - "roi-width", - "roi-height", - "has-streaming", - "has-camram-recording" + 0 }; static GParamSpec *pco_properties[N_PROPERTIES] = { NULL, }; @@ -572,8 +556,8 @@ static void uca_pco_camera_class_init(UcaPcoCameraClass *klass) camera_class->start_readout = uca_pco_camera_start_readout; camera_class->grab = uca_pco_camera_grab; - for (guint id = PROP_0 + 1; id < N_INTERFACE_PROPERTIES; id++) - g_object_class_override_property(gobject_class, id, base_overrideables[id-1]); + for (guint i = 0; base_overrideables[i] != 0; i++) + g_object_class_override_property(gobject_class, base_overrideables[i], uca_camera_props[base_overrideables[i]]); pco_properties[PROP_NAME] = g_param_spec_string("name", @@ -592,7 +576,7 @@ static void uca_pco_camera_class_init(UcaPcoCameraClass *klass) "Cooling point of the camera", 0, 10, 5, G_PARAM_READWRITE); - for (guint id = N_INTERFACE_PROPERTIES + 1; id < N_PROPERTIES; id++) + for (guint id = N_BASE_PROPERTIES; id < N_PROPERTIES; id++) g_object_class_install_property(gobject_class, id, pco_properties[id]); g_type_class_add_private(klass, sizeof(UcaPcoCameraPrivate)); diff --git a/src/cameras/uca-ufo-camera.c b/src/cameras/uca-ufo-camera.c index f40227b..e7a138d 100644 --- a/src/cameras/uca-ufo-camera.c +++ b/src/cameras/uca-ufo-camera.c @@ -54,7 +54,11 @@ GQuark uca_ufo_camera_error_quark() } enum { - PROP_0, + PROP_NAME = N_BASE_PROPERTIES, + N_PROPERTIES +}; + +static gint base_overrideables[] = { PROP_SENSOR_WIDTH, PROP_SENSOR_HEIGHT, PROP_SENSOR_BITDEPTH, @@ -65,23 +69,7 @@ enum { PROP_ROI_HEIGHT, PROP_HAS_STREAMING, PROP_HAS_CAMRAM_RECORDING, - N_INTERFACE_PROPERTIES, - - PROP_NAME, - N_PROPERTIES -}; - -static const gchar *base_overrideables[N_PROPERTIES] = { - "sensor-width", - "sensor-height", - "sensor-bitdepth", - "exposure-time", - "roi-x", - "roi-y", - "roi-width", - "roi-height", - "has-streaming", - "has-camram-recording" + 0, }; static GParamSpec *ufo_properties[N_PROPERTIES] = { NULL, }; @@ -308,8 +296,8 @@ static void uca_ufo_camera_class_init(UcaUfoCameraClass *klass) camera_class->start_readout = uca_ufo_camera_start_readout; camera_class->grab = uca_ufo_camera_grab; - for (guint id = PROP_0 + 1; id < N_INTERFACE_PROPERTIES; id++) - g_object_class_override_property(gobject_class, id, base_overrideables[id-1]); + for (guint i = 0; base_overrideables[i] != 0; i++) + g_object_class_override_property(gobject_class, base_overrideables[i], uca_camera_props[base_overrideables[i]]); ufo_properties[PROP_NAME] = g_param_spec_string("name", @@ -317,7 +305,7 @@ static void uca_ufo_camera_class_init(UcaUfoCameraClass *klass) "Name of the camera", "", G_PARAM_READABLE); - for (guint id = N_INTERFACE_PROPERTIES + 1; id < N_PROPERTIES; id++) + for (guint id = N_BASE_PROPERTIES; id < N_PROPERTIES; id++) g_object_class_install_property(gobject_class, id, ufo_properties[id]); g_type_class_add_private(klass, sizeof(UcaUfoCameraPrivate)); diff --git a/src/uca-camera.c b/src/uca-camera.c index bcfe828..4ae4610 100644 --- a/src/uca-camera.c +++ b/src/uca-camera.c @@ -61,37 +61,40 @@ enum { LAST_SIGNAL }; -enum { - PROP_0 = 0, - PROP_SENSOR_WIDTH, - PROP_SENSOR_HEIGHT, - PROP_SENSOR_BITDEPTH, - PROP_SENSOR_HORIZONTAL_BINNING, - PROP_SENSOR_HORIZONTAL_BINNINGS, - PROP_SENSOR_VERTICAL_BINNING, - PROP_SENSOR_VERTICAL_BINNINGS, - PROP_SENSOR_MAX_FRAME_RATE, - PROP_EXPOSURE_TIME, - PROP_ROI_X, - PROP_ROI_Y, - PROP_ROI_WIDTH, - PROP_ROI_HEIGHT, - PROP_HAS_STREAMING, - PROP_HAS_CAMRAM_RECORDING, - PROP_TRANSFER_ASYNCHRONOUSLY, - PROP_IS_RECORDING, - PROP_IS_READOUT, - N_PROPERTIES +/* + * These strings must UNDER ALL CIRCUMSTANCES match the property id's in the + * public header! Everyone relies on this relationship. + */ +const gchar *uca_camera_props[N_BASE_PROPERTIES] = { + NULL, + "sensor-width", + "sensor-height", + "sensor-bitdepth", + "sensor-horizontal-binning", + "sensor-horizontal-binnings", + "sensor-vertical-binning", + "sensor-vertical-binnings", + "sensor-max-frame-rate", + "exposure-time", + "roi-x", + "roi-y", + "roi-width", + "roi-height", + "has-streaming", + "has-camram-recording", + "transfer-asynchronously", + "is-recording", + "is-readout" }; +static GParamSpec *camera_properties[N_BASE_PROPERTIES] = { NULL, }; + struct _UcaCameraPrivate { gboolean is_recording; gboolean is_readout; gboolean transfer_async; }; -static GParamSpec *camera_properties[N_PROPERTIES] = { NULL, }; - /* static guint camera_signals[LAST_SIGNAL] = { 0 }; */ static void uca_camera_set_property(GObject *object, guint property_id, const GValue *value, GParamSpec *pspec) @@ -146,135 +149,135 @@ static void uca_camera_class_init(UcaCameraClass *klass) klass->grab = NULL; camera_properties[PROP_SENSOR_WIDTH] = - g_param_spec_uint("sensor-width", + g_param_spec_uint(uca_camera_props[PROP_SENSOR_WIDTH], "Width of sensor", "Width of the sensor in pixels", 1, G_MAXUINT, 1, G_PARAM_READABLE); camera_properties[PROP_SENSOR_HEIGHT] = - g_param_spec_uint("sensor-height", + g_param_spec_uint(uca_camera_props[PROP_SENSOR_HEIGHT], "Height of sensor", "Height of the sensor in pixels", 1, G_MAXUINT, 1, G_PARAM_READABLE); camera_properties[PROP_SENSOR_BITDEPTH] = - g_param_spec_uint("sensor-bitdepth", + g_param_spec_uint(uca_camera_props[PROP_SENSOR_BITDEPTH], "Number of bits per pixel", "Number of bits per pixel", 1, 32, 1, G_PARAM_READABLE); camera_properties[PROP_SENSOR_HORIZONTAL_BINNING] = - g_param_spec_uint("sensor-horizontal-binning", + g_param_spec_uint(uca_camera_props[PROP_SENSOR_HORIZONTAL_BINNING], "Horizontal binning", "Number of sensor ADCs that are combined to one pixel in horizontal direction", 1, G_MAXUINT, 1, G_PARAM_READWRITE); camera_properties[PROP_SENSOR_HORIZONTAL_BINNINGS] = - g_param_spec_value_array("sensor-horizontal-binnings", + g_param_spec_value_array(uca_camera_props[PROP_SENSOR_HORIZONTAL_BINNINGS], "Array of possible binnings", "Array of possible binnings in horizontal direction", g_param_spec_uint( - "sensor-horizontal-binning", + uca_camera_props[PROP_SENSOR_HORIZONTAL_BINNING], "Number of ADCs", "Number of ADCs that make up one pixel", 1, G_MAXUINT, 1, G_PARAM_READABLE), G_PARAM_READABLE); camera_properties[PROP_SENSOR_VERTICAL_BINNING] = - g_param_spec_uint("sensor-vertical-binning", + g_param_spec_uint(uca_camera_props[PROP_SENSOR_VERTICAL_BINNING], "Vertical binning", "Number of sensor ADCs that are combined to one pixel in vertical direction", 1, G_MAXUINT, 1, G_PARAM_READWRITE); camera_properties[PROP_SENSOR_VERTICAL_BINNINGS] = - g_param_spec_value_array("sensor-vertical-binnings", + g_param_spec_value_array(uca_camera_props[PROP_SENSOR_VERTICAL_BINNINGS], "Array of possible binnings", "Array of possible binnings in vertical direction", g_param_spec_uint( - "sensor-vertical-binning", + uca_camera_props[PROP_SENSOR_VERTICAL_BINNING], "Number of ADCs", "Number of ADCs that make up one pixel", 1, G_MAXUINT, 1, G_PARAM_READABLE), G_PARAM_READABLE); + camera_properties[PROP_SENSOR_MAX_FRAME_RATE] = + g_param_spec_float(uca_camera_props[PROP_SENSOR_MAX_FRAME_RATE], + "Maximum frame rate", + "Maximum frame rate at full frame resolution", + 0.0f, G_MAXFLOAT, 1.0f, + G_PARAM_READABLE); + camera_properties[PROP_ROI_X] = - g_param_spec_uint("roi-x", + g_param_spec_uint(uca_camera_props[PROP_ROI_X], "Horizontal coordinate", "Horizontal coordinate", 1, G_MAXUINT, 1, G_PARAM_READABLE); camera_properties[PROP_ROI_Y] = - g_param_spec_uint("roi-y", + g_param_spec_uint(uca_camera_props[PROP_ROI_Y], "Vertical coordinate", "Vertical coordinate", 1, G_MAXUINT, 1, G_PARAM_READABLE); camera_properties[PROP_ROI_WIDTH] = - g_param_spec_uint("roi-width", + g_param_spec_uint(uca_camera_props[PROP_ROI_WIDTH], "Width", "Width of the region of interest", 1, G_MAXUINT, 1, G_PARAM_READABLE); camera_properties[PROP_ROI_HEIGHT] = - g_param_spec_uint("roi-height", + g_param_spec_uint(uca_camera_props[PROP_ROI_HEIGHT], "Height", "Height of the region of interest", 1, G_MAXUINT, 1, G_PARAM_READABLE); camera_properties[PROP_EXPOSURE_TIME] = - g_param_spec_double("exposure-time", + g_param_spec_double(uca_camera_props[PROP_EXPOSURE_TIME], "Exposure time in seconds", "Exposure time in seconds", 0.0, G_MAXDOUBLE, 1.0, G_PARAM_READWRITE); - camera_properties[PROP_SENSOR_MAX_FRAME_RATE] = - g_param_spec_float("max-frame-rate", - "Maximum frame rate", - "Maximum frame rate at full frame resolution", - 0.0f, G_MAXFLOAT, 1.0f, - G_PARAM_READABLE); - camera_properties[PROP_HAS_STREAMING] = - g_param_spec_boolean("has-streaming", + g_param_spec_boolean(uca_camera_props[PROP_HAS_STREAMING], "Streaming capability", "Is the camera able to stream the data", TRUE, G_PARAM_READABLE); camera_properties[PROP_HAS_CAMRAM_RECORDING] = - g_param_spec_boolean("has-camram-recording", + g_param_spec_boolean(uca_camera_props[PROP_HAS_CAMRAM_RECORDING], "Cam-RAM capability", "Is the camera able to record the data in-camera", FALSE, G_PARAM_READABLE); camera_properties[PROP_TRANSFER_ASYNCHRONOUSLY] = - g_param_spec_boolean("transfer-asynchronously", + g_param_spec_boolean(uca_camera_props[PROP_TRANSFER_ASYNCHRONOUSLY], "Specify whether data should be transfered asynchronously", "Specify whether data should be transfered asynchronously using a specified callback", FALSE, G_PARAM_READWRITE); camera_properties[PROP_IS_RECORDING] = - g_param_spec_boolean("is-recording", + g_param_spec_boolean(uca_camera_props[PROP_IS_RECORDING], "Is camera recording", "Is the camera currently recording", FALSE, G_PARAM_READABLE); camera_properties[PROP_IS_READOUT] = - g_param_spec_boolean("is-readout", + g_param_spec_boolean(uca_camera_props[PROP_IS_READOUT], "Is camera in readout mode", "Is camera in readout mode", FALSE, G_PARAM_READABLE); - for (guint id = PROP_0 + 1; id < N_PROPERTIES; id++) + for (guint id = PROP_0 + 1; id < N_BASE_PROPERTIES; id++) g_object_class_install_property(gobject_class, id, camera_properties[id]); g_type_class_add_private(klass, sizeof(UcaCameraPrivate)); diff --git a/src/uca-camera.h b/src/uca-camera.h index c755fe6..c50ca85 100644 --- a/src/uca-camera.h +++ b/src/uca-camera.h @@ -44,6 +44,33 @@ typedef struct _UcaCamera UcaCamera; typedef struct _UcaCameraClass UcaCameraClass; typedef struct _UcaCameraPrivate UcaCameraPrivate; +enum { + PROP_0 = 0, + PROP_SENSOR_WIDTH, + PROP_SENSOR_HEIGHT, + PROP_SENSOR_BITDEPTH, + PROP_SENSOR_HORIZONTAL_BINNING, + PROP_SENSOR_HORIZONTAL_BINNINGS, + PROP_SENSOR_VERTICAL_BINNING, + PROP_SENSOR_VERTICAL_BINNINGS, + PROP_SENSOR_MAX_FRAME_RATE, + PROP_EXPOSURE_TIME, + PROP_ROI_X, + PROP_ROI_Y, + PROP_ROI_WIDTH, + PROP_ROI_HEIGHT, + PROP_HAS_STREAMING, + PROP_HAS_CAMRAM_RECORDING, + + /* These properties are handled internally */ + PROP_TRANSFER_ASYNCHRONOUSLY, + PROP_IS_RECORDING, + PROP_IS_READOUT, + N_BASE_PROPERTIES +}; + +const gchar *uca_camera_props[N_BASE_PROPERTIES]; + /** * UcaCameraGrabFunc: * @data: a pointer to the raw data diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 7d438b6..7380179 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -43,12 +43,14 @@ include_directories( ${CMAKE_CURRENT_SOURCE_DIR}/../src/cameras ) -add_executable(test-mock test-mock.c) -target_link_libraries(test-mock - uca-gobject - ${GLIB2_LIBRARIES} - ${GOBJECT2_LIBRARIES} - ) +if (HAVE_MOCK_CAMERA) + add_executable(test-mock test-mock.c) + target_link_libraries(test-mock + uca-gobject + ${GLIB2_LIBRARIES} + ${GOBJECT2_LIBRARIES} + ) +endif() add_executable(test-all test-all.c) target_link_libraries(test-all diff --git a/test/test-all.c b/test/test-all.c index 941c0cd..37af97d 100644 --- a/test/test-all.c +++ b/test/test-all.c @@ -75,7 +75,7 @@ static void test_recording_async(Fixture *fixture, gconstpointer data) gfloat max_frame_rate = 1.0f; g_object_get(G_OBJECT(camera), - "max-frame-rate", &max_frame_rate, + "sensor-max-frame-rate", &max_frame_rate, NULL); g_assert(max_frame_rate != 0.0f); |