- device = NULL;
- device_num = strtol(devicestring, &tmp, 10);
- if (tmp != devicestring) {
- /* argument is numeric, meaning a device ID. Make all driver
- * plugins scan for devices.
- */
- num_devices = num_real_devices();
- if (device_num < 0 || device_num >= num_devices)
- return NULL;
-
- device_cnt = 0;
- devices = sr_device_list();
- for (l = devices; l; l = l->next) {
- d = l->data;
- if (strstr(d->plugin->name, "demo"))
- continue;
- if (device_cnt == device_num) {
- if (device_num == device_cnt) {
- device = d;
- break;
- }
- }
- device_cnt++;
- }
- } else {
- /* select device by driver -- only initialize that driver,
- * no need to let them all scan
- */
- device = NULL;
- plugins = sr_list_hwplugins();
- for (p = plugins; p; p = p->next) {
- plugin = p->data;
- if (strcmp(plugin->name, devicestring))
- continue;
- num_devices = sr_init_hwplugins(plugin);
- if (num_devices == 1) {
- devices = sr_device_list();
- device = devices->data;
- } else if (num_devices > 1) {
- printf("driver '%s' found %d devices, select by ID instead.\n",
- devicestring, num_devices);
+ hash = g_hash_table_new_full(g_str_hash, g_str_equal, g_free,
+ (GDestroyNotify)g_variant_unref);
+ for (i = 0; opts[i]; i++) {
+ if (!(s = g_hash_table_lookup(genargs, opts[i]->id)))
+ continue;
+ if (g_variant_is_of_type(opts[i]->def, G_VARIANT_TYPE_UINT32)) {
+ gvar = g_variant_new_uint32(strtoul(s, NULL, 10));
+ g_hash_table_insert(hash, g_strdup(opts[i]->id),
+ g_variant_ref_sink(gvar));
+ } else if (g_variant_is_of_type(opts[i]->def, G_VARIANT_TYPE_INT32)) {
+ gvar = g_variant_new_int32(strtoul(s, NULL, 10));
+ g_hash_table_insert(hash, g_strdup(opts[i]->id),
+ g_variant_ref_sink(gvar));
+ } else if (g_variant_is_of_type(opts[i]->def, G_VARIANT_TYPE_UINT64)) {
+ gvar = g_variant_new_uint64(strtoul(s, NULL, 10));
+ g_hash_table_insert(hash, g_strdup(opts[i]->id),
+ g_variant_ref_sink(gvar));
+ } else if (g_variant_is_of_type(opts[i]->def, G_VARIANT_TYPE_DOUBLE)) {
+ gvar = g_variant_new_double(strtod(s, NULL));
+ g_hash_table_insert(hash, g_strdup(opts[i]->id),
+ g_variant_ref_sink(gvar));
+ } else if (g_variant_is_of_type(opts[i]->def, G_VARIANT_TYPE_STRING)) {
+ gvar = g_variant_new_string(s);
+ g_hash_table_insert(hash, g_strdup(opts[i]->id),
+ g_variant_ref_sink(gvar));
+ } else if (g_variant_is_of_type(opts[i]->def, G_VARIANT_TYPE_BOOLEAN)) {
+ b = TRUE;
+ if (0 == strcmp(s, "false") || 0 == strcmp(s, "no")) {
+ b = FALSE;
+ } else if (!(0 == strcmp(s, "true") || 0 == strcmp(s, "yes"))) {
+ g_critical("Unable to convert '%s' to boolean!", s);