diff options
| author | Matthias Vogelgesang <matthias.vogelgesang@kit.edu> | 2012-03-05 17:20:27 +0100 | 
|---|---|---|
| committer | Matthias Vogelgesang <matthias.vogelgesang@kit.edu> | 2012-03-05 17:20:27 +0100 | 
| commit | 03739354e074c547d99a6992a7774c3643d17da1 (patch) | |
| tree | 37091acf1b6101493f9243fbd5b5201be951fdce | |
| parent | 0483c86add2f496021560b82476d22e2497006be (diff) | |
| download | uca-03739354e074c547d99a6992a7774c3643d17da1.tar.gz uca-03739354e074c547d99a6992a7774c3643d17da1.tar.bz2 uca-03739354e074c547d99a6992a7774c3643d17da1.tar.xz uca-03739354e074c547d99a6992a7774c3643d17da1.zip | |
Add factory method to create new cameras
| -rw-r--r-- | src/CMakeLists.txt | 12 | ||||
| -rw-r--r-- | src/config.h.in | 8 | ||||
| -rw-r--r-- | src/uca-camera.c | 72 | ||||
| -rw-r--r-- | src/uca-camera.h | 4 | ||||
| -rw-r--r-- | test/test-gobject.c | 16 | ||||
| -rw-r--r-- | test/test-mock.c | 9 | 
6 files changed, 92 insertions, 29 deletions
| diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index b3650f6..6b413dd 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -24,7 +24,6 @@ find_package(ClSerMe4)  # --- Miscellanous packages  find_package(PkgConfig) -find_package(Threads)  pkg_check_modules(GLIB2 glib-2.0>=2.24 REQUIRED)  pkg_check_modules(GOBJECT2 gobject-2.0>=2.24 REQUIRED) @@ -34,7 +33,7 @@ set(uca_LIBS      ${GOBJECT2_LIBRARIES})  # --- Build options ----------------------------------------------------------- -option(HAVE_DUMMY_CAMERA "Camera: Dummy" OFF) +option(HAVE_MOCK_CAMERA "Camera: Dummy" OFF)  # --- Add sources if camera/framegrabber access sources are available --------- @@ -81,18 +80,11 @@ if (IPE_FOUND)      endif()  endif() -if (HAVE_DUMMY_CAMERA) +if (HAVE_MOCK_CAMERA)      set(uca_SRCS ${uca_SRCS} cameras/uca-mock-camera.c)      set(uca_HDRS ${uca_HDRS} cameras/uca-mock-camera.h)  endif() -if (Threads_FOUND) -    set(HAVE_PTHREADS TRUE) - -    set(uca_LIBS -        ${uca_LIBS} -        ${CMAKE_THREAD_LIBS_INIT}) -endif()  # --- Configure step  configure_file(${CMAKE_CURRENT_SOURCE_DIR}/config.h.in diff --git a/src/config.h.in b/src/config.h.in index 40a61f8..6a6b6b4 100644 --- a/src/config.h.in +++ b/src/config.h.in @@ -1,12 +1,6 @@ - -#cmakedefine HAVE_ME4 -  #cmakedefine HAVE_PCO_CL  #cmakedefine HAVE_PHOTON_FOCUS  #cmakedefine HAVE_PHOTRON_FASTCAM  #cmakedefine HAVE_IPE_CAMERA -#cmakedefine HAVE_DUMMY_CAMERA -#cmakedefine HAVE_SIMPLE_CAMERA - -#cmakedefine HAVE_PTHREADS +#cmakedefine HAVE_MOCK_CAMERA diff --git a/src/uca-camera.c b/src/uca-camera.c index ac04b86..f7f980a 100644 --- a/src/uca-camera.c +++ b/src/uca-camera.c @@ -16,14 +16,24 @@     Franklin St, Fifth Floor, Boston, MA 02110, USA */  #include <glib.h> +#include "config.h"  #include "uca-camera.h" +#ifdef HAVE_PCO_CL +#include "cameras/uca-pco-camera.h" +#endif + +#ifdef HAVE_MOCK_CAMERA +#include "cameras/uca-mock-camera.h" +#endif +  #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_NOT_FOUND: Camera type is unknown   * @UCA_CAMERA_ERROR_RECORDING: Camera is already recording   * @UCA_CAMERA_ERROR_NOT_RECORDING: Camera is not recording   * @UCA_CAMERA_ERROR_NO_GRAB_FUNC: No grab callback was set @@ -33,6 +43,16 @@ GQuark uca_camera_error_quark()      return g_quark_from_static_string("uca-camera-error-quark");  } +static gchar *uca_camera_types[] = { +#ifdef HAVE_PCO_CL +        "pco", +#endif +#ifdef HAVE_MOCK_CAMERA +        "mock", +#endif +        NULL  +}; +  enum {      LAST_SIGNAL  }; @@ -222,6 +242,58 @@ static void uca_camera_init(UcaCamera *camera)  }  /** + * uca_camera_get_types: + * + * Enumerate all camera types that can be instantiated with uca_camera_new(). + * + * Returns: An array of strings with camera types. The list should be freed with + * g_strfreev(). + */ +gchar **uca_camera_get_types() +{ +    return g_strdupv(uca_camera_types); +} + +/** + * uca_camera_new: + * @param type: Type name of the camera + * @error: Location to store an error or %NULL + * + * Factory method for instantiating cameras by names listed in + * uca_camera_get_type(). + * + * Returns: A new #UcaCamera of the correct type or %NULL if type was not found + */ +UcaCamera *uca_camera_new(const gchar *type, GError **error) +{ +    UcaCamera *camera = NULL; +    GError *tmp_error = NULL; + +#ifdef HAVE_MOCK_CAMERA +    if (!g_strcmp0(type, "mock")) +        camera = UCA_CAMERA(uca_mock_camera_new(&tmp_error)); +#endif + +#ifdef HAVE_PCO_CL +    if (!g_strcmp0(type, "pco")) +        camera = UCA_CAMERA(uca_pco_camera_new(&tmp_error)); +#endif + +    if (tmp_error != NULL) { +        g_propagate_error(error, tmp_error); +        return NULL; +    } + +    if ((tmp_error == NULL) && (camera == NULL)) { +        g_set_error(error, UCA_CAMERA_ERROR, UCA_CAMERA_ERROR_NOT_FOUND, +                "Camera type %s not found", type);     +        return NULL; +    } + +    return camera; +} + +/**   * uca_camera_start_recording:   * @camera: A #UcaCamera object   * @error: Location to store a #UcaCameraError error or %NULL diff --git a/src/uca-camera.h b/src/uca-camera.h index 0370466..44770f1 100644 --- a/src/uca-camera.h +++ b/src/uca-camera.h @@ -29,6 +29,7 @@  #define UCA_CAMERA_ERROR uca_camera_error_quark()  typedef enum { +    UCA_CAMERA_ERROR_NOT_FOUND,      UCA_CAMERA_ERROR_RECORDING,      UCA_CAMERA_ERROR_NOT_RECORDING,      UCA_CAMERA_ERROR_NO_GRAB_FUNC @@ -74,6 +75,9 @@ struct _UcaCameraClass {      void (*recording_stopped) (UcaCamera *camera);  }; +gchar **uca_camera_get_types(); +UcaCamera *uca_camera_new(const gchar *type, GError **error); +  void uca_camera_start_recording(UcaCamera *camera, GError **error);  void uca_camera_stop_recording(UcaCamera *camera, GError **error);  void uca_camera_grab(UcaCamera *camera, gpointer data, GError **error); diff --git a/test/test-gobject.c b/test/test-gobject.c index 3ff77bf..e8b14a8 100644 --- a/test/test-gobject.c +++ b/test/test-gobject.c @@ -6,19 +6,11 @@ int main(int argc, char **argv)  {      g_type_init(); -    GError *error = NULL; -    UcaMockCamera *cam = uca_mock_camera_new(&error); +    gchar **types = uca_camera_get_types(); -    if (cam == NULL) { -        g_error("Camera could not be initialized\n"); +    for (guint i = 0; i < g_strv_length(types); i++) { +        g_print("Camera: %s\n", types[i]);      } -    guint width, height; -    g_object_get(cam, -            "sensor-width", &width, -            "sensor-height", &height, -            NULL); -    g_print("resolution %ix%i\n", width, height); - -    g_object_unref(cam); +    g_strfreev(types);  } diff --git a/test/test-mock.c b/test/test-mock.c index 5340166..a9284cf 100644 --- a/test/test-mock.c +++ b/test/test-mock.c @@ -26,6 +26,14 @@ static void on_property_change(gpointer instance, GParamSpec *pspec, gpointer us      *success = TRUE;  } +static void test_factory() +{ +    GError *error = NULL; +    UcaCamera *camera = uca_camera_new("fox994m3a0yxmy", &error); +    g_assert_error(error, UCA_CAMERA_ERROR, UCA_CAMERA_ERROR_NOT_FOUND); +    g_assert(camera == NULL); +} +  static void test_recording(Fixture *fixture, gconstpointer data)  {      GError *error = NULL; @@ -150,6 +158,7 @@ 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_func("/factory", test_factory);      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); | 
