diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/CMakeLists.txt | 5 | ||||
-rw-r--r-- | src/libuca.pc.in | 1 | ||||
-rw-r--r-- | src/scangobj.sh.in | 2 | ||||
-rw-r--r-- | src/uca-camera.c | 38 | ||||
-rw-r--r-- | src/uca-camera.h | 9 | ||||
-rw-r--r-- | src/uca-plugin-manager.c | 125 | ||||
-rw-r--r-- | src/uca-plugin-manager.h | 9 | ||||
-rw-r--r-- | src/uca.types.in | 3 |
8 files changed, 135 insertions, 57 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index fcacfa0..c3a037f 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -85,6 +85,9 @@ if (INTROSPECTION_SCANNER AND INTROSPECTION_COMPILER) list(APPEND _gir_input "${CMAKE_CURRENT_SOURCE_DIR}/${_src}") endforeach() + list(APPEND _gir_input "${CMAKE_CURRENT_BINARY_DIR}/uca-enums.h") + list(APPEND _gir_input "${CMAKE_CURRENT_BINARY_DIR}/uca-enums.c") + add_custom_command(OUTPUT ${GIR_XML} COMMAND ${INTROSPECTION_SCANNER} --namespace=Uca @@ -199,7 +202,7 @@ install(TARGETS uca COMPONENT libraries) install(FILES ${CMAKE_CURRENT_BINARY_DIR}/libuca.pc - DESTINATION lib/pkgconfig + DESTINATION ${LIB_INSTALL_DIR}/pkgconfig COMPONENT libraries) install(FILES ${uca_HDRS} diff --git a/src/libuca.pc.in b/src/libuca.pc.in index 6401368..3ca4dbe 100644 --- a/src/libuca.pc.in +++ b/src/libuca.pc.in @@ -11,3 +11,4 @@ Description: @UCA_DESCRIPTION@ Version: @VERSION@ Libs: -L${libdir} -luca Cflags: -I${includedir_old} -I${includedir_new} +Requires: glib-2.0 gobject-2.0 diff --git a/src/scangobj.sh.in b/src/scangobj.sh.in index 65766b6..088d67e 100644 --- a/src/scangobj.sh.in +++ b/src/scangobj.sh.in @@ -1 +1 @@ -LD_LIBRARY_PATH=${CMAKE_CURRENT_BINARY_DIR}:/opt/pylon/lib64:/opt/pylon/genicam/bin/Linux64_x64 CC=gcc CFLAGS="${GTK_DOC_CFLAGS}" LDFLAGS="${GTK_DOC_LDFLAGS} -L${CMAKE_CURRENT_BINARY_DIR} -L${CMAKE_CURRENT_BINARY_DIR} -luca `pkg-config --libs gtk+-2.0`" gtkdoc-scangobj --module=uca +LD_LIBRARY_PATH=${CMAKE_CURRENT_BINARY_DIR}:/opt/pylon/lib64:/opt/pylon/genicam/bin/Linux64_x64 CC=gcc CFLAGS="${GTK_DOC_CFLAGS}" LDFLAGS="${GTK_DOC_LDFLAGS} -L${CMAKE_CURRENT_BINARY_DIR} -luca `pkg-config --libs gtk+-2.0`" gtkdoc-scangobj --module=uca diff --git a/src/uca-camera.c b/src/uca-camera.c index 8905a95..5073a57 100644 --- a/src/uca-camera.c +++ b/src/uca-camera.c @@ -116,6 +116,7 @@ struct _UcaCameraPrivate { gboolean is_recording; gboolean is_readout; gboolean transfer_async; + UcaCameraTrigger trigger; }; static void @@ -148,6 +149,10 @@ uca_camera_set_property (GObject *object, guint property_id, const GValue *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); } @@ -172,7 +177,7 @@ uca_camera_get_property(GObject *object, guint property_id, GValue *value, GPara break; case PROP_TRIGGER_MODE: - g_value_set_enum (value, UCA_CAMERA_TRIGGER_AUTO); + g_value_set_enum (value, priv->trigger); break; case PROP_FRAMES_PER_SECOND: @@ -403,6 +408,7 @@ uca_camera_init (UcaCamera *camera) camera->priv->is_recording = FALSE; camera->priv->is_readout = FALSE; camera->priv->transfer_async = FALSE; + camera->priv->trigger = UCA_CAMERA_TRIGGER_AUTO; uca_camera_set_property_unit (camera_properties[PROP_SENSOR_WIDTH], UCA_UNIT_PIXEL); uca_camera_set_property_unit (camera_properties[PROP_SENSOR_HEIGHT], UCA_UNIT_PIXEL); @@ -669,34 +675,31 @@ uca_camera_trigger (UcaCamera *camera, GError **error) /** * uca_camera_grab: * @camera: A #UcaCamera object - * @data: Pointer to pointer to the data. Must not be %NULL. + * @data: (type gulong): Pointer to suitably sized data buffer. Must not be + * %NULL. * @error: Location to store a #UcaCameraError error or %NULL * - * Grab a frame a single frame and store the result in @data. If the pointer - * pointing to the data is %NULL, memory will be allocated otherwise it will be - * used to store the frame. If memory is allocated by uca_camera_grab() it must - * be freed by the caller. + * Grab a frame a single frame and store the result in @data. * * You must have called uca_camera_start_recording() before, otherwise you will * get a #UCA_CAMERA_ERROR_NOT_RECORDING error. - * - * If *data is %NULL after returning from uca_camera_grab() and error is also - * %NULL, the data stream has ended. For example, with cameras that support - * in-camera memory, all frames have been transfered. */ -void -uca_camera_grab (UcaCamera *camera, gpointer *data, GError **error) +gboolean +uca_camera_grab (UcaCamera *camera, gpointer data, GError **error) { UcaCameraClass *klass; + gboolean result; + + /* FIXME: this prevents accessing two independent cameras simultanously. */ static GStaticMutex mutex = G_STATIC_MUTEX_INIT; - g_return_if_fail (UCA_IS_CAMERA(camera)); + g_return_val_if_fail (UCA_IS_CAMERA(camera), FALSE); klass = UCA_CAMERA_GET_CLASS (camera); - g_return_if_fail (klass != NULL); - g_return_if_fail (klass->grab != NULL); - g_return_if_fail (data != NULL); + g_return_val_if_fail (klass != NULL, FALSE); + g_return_val_if_fail (klass->grab != NULL, FALSE); + g_return_val_if_fail (data != NULL, FALSE); g_static_mutex_lock (&mutex); @@ -704,11 +707,12 @@ uca_camera_grab (UcaCamera *camera, gpointer *data, GError **error) g_set_error (error, UCA_CAMERA_ERROR, UCA_CAMERA_ERROR_NOT_RECORDING, "Camera is neither recording nor in readout mode"); else { g_static_mutex_lock (&access_lock); - (*klass->grab) (camera, data, error); + result = (*klass->grab) (camera, data, error); g_static_mutex_unlock (&access_lock); } g_static_mutex_unlock (&mutex); + return result; } /** diff --git a/src/uca-camera.h b/src/uca-camera.h index 87996c6..f6fdace 100644 --- a/src/uca-camera.h +++ b/src/uca-camera.h @@ -129,7 +129,7 @@ struct _UcaCameraClass { void (*start_readout) (UcaCamera *camera, GError **error); void (*stop_readout) (UcaCamera *camera, GError **error); void (*trigger) (UcaCamera *camera, GError **error); - void (*grab) (UcaCamera *camera, gpointer *data, GError **error); + gboolean (*grab) (UcaCamera *camera, gpointer data, GError **error); void (*recording_started) (UcaCamera *camera); void (*recording_stopped) (UcaCamera *camera); @@ -147,9 +147,10 @@ void uca_camera_stop_readout (UcaCamera *camera, GError **error); void uca_camera_trigger (UcaCamera *camera, GError **error); -void uca_camera_grab (UcaCamera *camera, - gpointer *data, - GError **error); +gboolean uca_camera_grab (UcaCamera *camera, + gpointer data, + GError **error) + __attribute__((nonnull (2))); void uca_camera_set_grab_func (UcaCamera *camera, UcaCameraGrabFunc func, gpointer user_data); diff --git a/src/uca-plugin-manager.c b/src/uca-plugin-manager.c index e99f478..5013981 100644 --- a/src/uca-plugin-manager.c +++ b/src/uca-plugin-manager.c @@ -32,6 +32,7 @@ * * @Since: 1.1 */ +#include <gio/gio.h> #include <gmodule.h> #include "uca-plugin-manager.h" @@ -45,7 +46,7 @@ struct _UcaPluginManagerPrivate { static const gchar *MODULE_PATTERN = "libuca([A-Za-z]+)"; -typedef UcaCamera * (*GetCameraFunc) (GError **error); +typedef GType (*GetTypeFunc) (void); /** * UcaPluginManagerError: @@ -208,39 +209,22 @@ find_camera_module_path (GList *search_paths, const gchar *name) return result; } -/** - * uca_plugin_manager_get_camera: - * @manager: A #UcaPluginManager - * @name: Name of the camera module, that maps to libuca<name>.so - * @error: Location for a #GError - * - * Create a new camera instance with camera @name. - * - * Returns: (transfer full): A new #UcaCamera object. - */ -UcaCamera * -uca_plugin_manager_get_camera (UcaPluginManager *manager, - const gchar *name, - GError **error) +static GType +get_camera_type (UcaPluginManagerPrivate *priv, + const gchar *name, + GError **error) { - UcaPluginManagerPrivate *priv; - UcaCamera *camera; GModule *module; - GetCameraFunc *func; gchar *module_path; - GError *tmp_error = NULL; + GetTypeFunc *func; + const gchar *symbol_name = "uca_camera_get_type"; - const gchar *symbol_name = "uca_camera_impl_new"; - - g_return_val_if_fail (UCA_IS_PLUGIN_MANAGER (manager) && (name != NULL), NULL); - - priv = manager->priv; module_path = find_camera_module_path (priv->search_paths, name); if (module_path == NULL) { g_set_error (error, UCA_PLUGIN_MANAGER_ERROR, UCA_PLUGIN_MANAGER_ERROR_MODULE_NOT_FOUND, - "Camera module `%s' not found", name); - return NULL; + "Camera module `%s' not found", name); + return G_TYPE_NONE; } module = g_module_open (module_path, G_MODULE_BIND_LAZY); @@ -249,10 +233,10 @@ uca_plugin_manager_get_camera (UcaPluginManager *manager, if (!module) { g_set_error (error, UCA_PLUGIN_MANAGER_ERROR, UCA_PLUGIN_MANAGER_ERROR_MODULE_OPEN, "Camera module `%s' could not be opened: %s", name, g_module_error ()); - return NULL; + return G_TYPE_NONE; } - func = g_malloc0 (sizeof (GetCameraFunc)); + func = g_malloc0 (sizeof (GetTypeFunc)); if (!g_module_symbol (module, symbol_name, (gpointer *) func)) { g_set_error (error, UCA_PLUGIN_MANAGER_ERROR, UCA_PLUGIN_MANAGER_ERROR_SYMBOL_NOT_FOUND, @@ -262,15 +246,90 @@ uca_plugin_manager_get_camera (UcaPluginManager *manager, if (!g_module_close (module)) g_warning ("%s", g_module_error ()); - return NULL; + return G_TYPE_NONE; } - camera = (*func) (&tmp_error); + return (*func) (); +} - if (tmp_error != NULL) { - g_propagate_error (error, tmp_error); +/** + * uca_plugin_manager_get_camerav: + * @manager: A #UcaPluginManager + * @name: Name of the camera module, that maps to libuca<name>.so + * @n_parameters: number of parameters in @parameters + * @parameters: (array length=n_parameters): the parameters to use to construct + * the camera + * @error: Location for a #GError or %NULL + * + * Create a new camera instance with camera @name. + * + * Returns: (transfer full): A new #UcaCamera object. + * @Since: 1.2 + */ +UcaCamera * +uca_plugin_manager_get_camerav (UcaPluginManager *manager, + const gchar *name, + guint n_parameters, + GParameter *parameters, + GError **error) +{ + UcaPluginManagerPrivate *priv; + UcaCamera *camera; + GType type; + + g_return_val_if_fail (UCA_IS_PLUGIN_MANAGER (manager) && (name != NULL), NULL); + + priv = manager->priv; + type = get_camera_type (priv, name, error); + + if (type == G_TYPE_NONE) return NULL; - } + + camera = (UcaCamera *) g_initable_newv (type, n_parameters, parameters, + NULL, error); + + return camera; +} + +/** + * uca_plugin_manager_get_camera: (skip) + * @manager: A #UcaPluginManager + * @name: Name of the camera module, that maps to libuca<name>.so + * @error: Location for a #GError + * @first_prop_name: (allow-none): name of the first property, or %NULL if no + * properties + * @...: value of the first property, followed by and other property value + * pairs, and ended by %NULL. + * + * Create a new camera instance with camera @name. + * + * Returns: (transfer full): A new #UcaCamera object. + * @Since: 1.2: Pass construction properties. + */ +UcaCamera * +uca_plugin_manager_get_camera (UcaPluginManager *manager, + const gchar *name, + GError **error, + const gchar *first_prop_name, + ...) +{ + UcaPluginManagerPrivate *priv; + UcaCamera *camera; + GType type; + va_list var_args; + + g_return_val_if_fail (UCA_IS_PLUGIN_MANAGER (manager) && (name != NULL), NULL); + + priv = manager->priv; + type = get_camera_type (priv, name, error); + + if (type == G_TYPE_NONE) + return NULL; + + va_start (var_args, first_prop_name); + camera = (UcaCamera *) g_initable_new (type, NULL, error, + first_prop_name, var_args); + va_end (var_args); return camera; } diff --git a/src/uca-plugin-manager.h b/src/uca-plugin-manager.h index 6c3ab4e..10fe9d1 100644 --- a/src/uca-plugin-manager.h +++ b/src/uca-plugin-manager.h @@ -55,9 +55,16 @@ void uca_plugin_manager_add_path (UcaPluginManager *manager const gchar *path); GList *uca_plugin_manager_get_available_cameras (UcaPluginManager *manager); -UcaCamera *uca_plugin_manager_get_camera (UcaPluginManager *manager, +UcaCamera *uca_plugin_manager_get_camerav (UcaPluginManager *manager, const gchar *name, + guint n_parameters, + GParameter *parameters, GError **error); +UcaCamera *uca_plugin_manager_get_camera (UcaPluginManager *manager, + const gchar *name, + GError **error, + const gchar *first_prop_name, + ...); GType uca_plugin_manager_get_type (void); G_END_DECLS diff --git a/src/uca.types.in b/src/uca.types.in index 7526948..76acc2b 100644 --- a/src/uca.types.in +++ b/src/uca.types.in @@ -1,2 +1,5 @@ uca_camera_get_type +uca_camera_error_get_type +uca_camera_trigger_get_type uca_plugin_manager_get_type +uca_unit_get_type |