summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTimo Dritschler <timo.dritschler@kit.edu>2014-07-18 16:58:24 +0200
committerTimo Dritschler <timo.dritschler@kit.edu>2014-12-10 17:52:09 +0100
commitf59c4874a69dfc3777196f4291802b6ab839a35c (patch)
tree80468bfa6764b4ca3d30d8e6566e917efed39aad
parent0ab10b321fe3881808d63b010eee29e4dec9cba7 (diff)
downloaduca-f59c4874a69dfc3777196f4291802b6ab839a35c.tar.gz
uca-f59c4874a69dfc3777196f4291802b6ab839a35c.tar.bz2
uca-f59c4874a69dfc3777196f4291802b6ab839a35c.tar.xz
uca-f59c4874a69dfc3777196f4291802b6ab839a35c.zip
Added new get_camerah (Get Camera Hash) interface to Pugin Manager
Added unit-test to test/test-mock for the new get_camerah interface
-rw-r--r--src/uca-plugin-manager.c77
-rw-r--r--src/uca-plugin-manager.h4
-rw-r--r--test/test-mock.c36
3 files changed, 117 insertions, 0 deletions
diff --git a/src/uca-plugin-manager.c b/src/uca-plugin-manager.c
index 97d6f8e..704c398 100644
--- a/src/uca-plugin-manager.c
+++ b/src/uca-plugin-manager.c
@@ -254,6 +254,83 @@ get_camera_type (UcaPluginManagerPrivate *priv,
}
/**
+ * transform_hash_entry_to_gparameter: (skip)
+ * @key: #gpointer to the key value of the hash entry
+ * @value: #gpointer to the value of the hash entry
+ * @parameter: (out caller-allocates): Pointer to the #GParameter where key and value
+ * should be filled into
+ *
+ * Takes a Key/Value pair from a #GHashTable and puts its values into the given
+ * #GParameter.
+ * Note that this function uses g_strdup() to set the #GParameters name value. This
+ * needs to be cleaned up by the caller using g_free()
+ *
+ * Since: 1.7
+ */
+typedef struct
+{
+ GParameter *p;
+ guint idx;
+} ParamArray;
+
+
+static void
+transform_hash_entry_to_gparameter (gpointer key,
+ gpointer value,
+ ParamArray *params)
+{
+ GParameter *parameter = &(params->p[params->idx]);
+
+ parameter->value = *((GValue*)value);
+ parameter->name = g_strdup ((const gchar*)key);
+ params->idx++;
+}
+
+/**
+ * uca_plugin_manager_get_camerah:
+ * @manager: A #UcaPluginManager
+ * @name: Name of the camera module, that maps to libuca<name>.so
+ * @parameters: (element-type utf8 GValue) (transfer none) (allow-none): a pointer to a #GHashTable containing parameters or %NULL
+ * @error: (allow-none): Location for a #GError or %NULL
+ *
+ * Create a new camera instance with camera @name.
+ *
+ * Returns: (transfer full): A new #UcaCamera object.
+ * Since: 1.7
+ */
+UcaCamera *
+uca_plugin_manager_get_camerah (UcaPluginManager *manager,
+ const gchar *name,
+ GHashTable *parameters,
+ GError **error)
+{
+ //No parameters. Just create the camera
+ if (!parameters)
+ return uca_plugin_manager_get_camera (manager, name, error, NULL);
+
+ //If we reach this point, we have parameters. Construct GParameters for them and
+ //use uca_plugin_manager_get_camerav to create the camera
+ guint n_parameters = g_hash_table_size (parameters);
+ ParamArray params;
+ params.p = g_malloc0 (sizeof(GParameter) * n_parameters);
+ params.idx = 0;
+
+ g_hash_table_foreach (parameters, (GHFunc) transform_hash_entry_to_gparameter, &params);
+
+ UcaCamera *camera = uca_plugin_manager_get_camerav(manager, name, n_parameters, params.p, error);
+
+ //Free the g_strcpy-ed names
+ for (guint i = 0; i < params.idx; i++)
+ {
+ GParameter *parameter = &(params.p[i]);
+ g_free ((gpointer)(parameter->name));
+ }
+ g_free (params.p);
+
+ return camera;
+}
+
+/**
* uca_plugin_manager_get_camerav:
* @manager: A #UcaPluginManager
* @name: Name of the camera module, that maps to libuca<name>.so
diff --git a/src/uca-plugin-manager.h b/src/uca-plugin-manager.h
index 10fe9d1..6e84a85 100644
--- a/src/uca-plugin-manager.h
+++ b/src/uca-plugin-manager.h
@@ -55,6 +55,10 @@ 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_camerah (UcaPluginManager *manager,
+ const gchar *name,
+ GHashTable *parameters,
+ GError **error);
UcaCamera *uca_plugin_manager_get_camerav (UcaPluginManager *manager,
const gchar *name,
guint n_parameters,
diff --git a/test/test-mock.c b/test/test-mock.c
index 8edcf8f..5573666 100644
--- a/test/test-mock.c
+++ b/test/test-mock.c
@@ -291,6 +291,41 @@ test_can_be_written (Fixture *fixture, gconstpointer data)
g_assert_no_error (error);
}
+static void
+test_factory_hashtable (Fixture *fixture, gconstpointer data)
+{
+ GError *error = NULL;
+
+ guint checkvalue = 42;
+
+ gchar *foo = "roi-width";
+ gchar *bar = "roi-height";
+ GValue baz = G_VALUE_INIT;
+ g_value_init(&baz, G_TYPE_UINT);
+ g_value_set_uint(&baz, checkvalue);
+
+ GHashTable *ght = g_hash_table_new (NULL, NULL);
+ g_hash_table_insert(ght, foo, &baz);
+ g_hash_table_insert(ght, bar, &baz);
+
+ UcaCamera *camera = uca_plugin_manager_get_camerah (fixture->manager,
+ "mock", ght, &error);
+ g_hash_table_destroy(ght);
+
+ g_assert (error == NULL);
+ g_assert (camera);
+
+ guint roi_width = 0;
+ g_object_get (G_OBJECT (camera), "roi-width", &roi_width, NULL);
+ g_assert (roi_width == checkvalue);
+
+ guint roi_height = 0;
+ g_object_get (G_OBJECT (camera), "roi-height", &roi_height, NULL);
+ g_assert (roi_height == checkvalue);
+
+ g_object_unref(camera);
+}
+
int main (int argc, char *argv[])
{
gsize n_tests;
@@ -308,6 +343,7 @@ int main (int argc, char *argv[])
}
tests[] = {
{"/factory", test_factory},
+ {"/factory/hashtable", test_factory_hashtable},
{"/signal", test_signal},
{"/recording", test_recording},
{"/recording/signal", test_recording_signal},