diff options
author | Matthias Vogelgesang <matthias.vogelgesang@kit.edu> | 2016-04-01 16:23:27 +0200 |
---|---|---|
committer | Matthias Vogelgesang <matthias.vogelgesang@kit.edu> | 2016-04-01 16:23:27 +0200 |
commit | b83e7a311580e9c0ed7bd58637b01c10d4b4f8a3 (patch) | |
tree | 03305140e9fb17885b83c25bfd91081119ece146 /bin/tools/common.c | |
parent | fa3f523af9ac95945af59bdaa729d71d79327a76 (diff) | |
download | uca-b83e7a311580e9c0ed7bd58637b01c10d4b4f8a3.tar.gz uca-b83e7a311580e9c0ed7bd58637b01c10d4b4f8a3.tar.bz2 uca-b83e7a311580e9c0ed7bd58637b01c10d4b4f8a3.tar.xz uca-b83e7a311580e9c0ed7bd58637b01c10d4b4f8a3.zip |
cli: pass -p/--property assignment to constructor
Diffstat (limited to 'bin/tools/common.c')
-rw-r--r-- | bin/tools/common.c | 54 |
1 files changed, 53 insertions, 1 deletions
diff --git a/bin/tools/common.c b/bin/tools/common.c index 3721ff0..8de5e87 100644 --- a/bin/tools/common.c +++ b/bin/tools/common.c @@ -17,6 +17,7 @@ #include "common.h" +static gchar **uca_prop_assignment_array = NULL; static gchar * get_camera_list (UcaPluginManager *manager) @@ -48,14 +49,65 @@ get_camera_list (UcaPluginManager *manager) } GOptionContext * -uca_option_context_new (UcaPluginManager *manager) +uca_common_context_new (UcaPluginManager *manager) { GOptionContext *context; + GOptionGroup *common; gchar *camera_list; + static GOptionEntry entries[] = { + { "prop", 'p', 0, G_OPTION_ARG_STRING_ARRAY, &uca_prop_assignment_array, "Property assignment via `name=value'", NULL }, + { NULL } + }; + camera_list = get_camera_list (manager); context = g_option_context_new (camera_list); g_free (camera_list); + common = g_option_group_new ("properties", "Property options", "Show help for property assignment", NULL, NULL); + g_option_group_add_entries (common, entries); + g_option_context_add_group (context, common); + return context; } + +UcaCamera * +uca_common_get_camera (UcaPluginManager *manager, const gchar *name, GError **error) +{ + UcaCamera *camera; + GParameter *params; + guint n_props; + + n_props = g_strv_length (uca_prop_assignment_array); + params = g_new0 (GParameter, n_props); + + for (guint i = 0; i < n_props; i++) { + gchar **split; + + split = g_strsplit (uca_prop_assignment_array[i], "=", 2); + + if (g_strv_length (split) < 2) + goto cleanup; + + params[i].name = g_strdup (split[0]); + + /* We cannot check the type before instantiation, classic chicken-egg + * situation ... so, let's try string. */ + g_value_init (¶ms[i].value, G_TYPE_STRING); + g_value_set_string (¶ms[i].value, split[1]); + +cleanup: + g_strfreev (split); + } + + camera = uca_plugin_manager_get_camerav (manager, name, n_props, params, error); + + for (guint i = 0; i < n_props; i++) { + /* cast is legit, because we created the string */ + g_free ((gchar *) params[i].name); + } + + g_free (params); + + return camera; +} |