]> sigrok.org Git - libsigrok.git/blame - hwdriver.c
cem-dt-885x: Send last measurement at normal rate in hold mode
[libsigrok.git] / hwdriver.c
CommitLineData
a1bb33af 1/*
50985c20 2 * This file is part of the libsigrok project.
a1bb33af 3 *
13d8e03c 4 * Copyright (C) 2013 Bert Vermeulen <bert@biot.com>
a1bb33af
UH
5 *
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20#include <stdlib.h>
21#include <stdio.h>
22#include <sys/types.h>
23#include <dirent.h>
24#include <string.h>
25#include <glib.h>
545f9786 26#include "config.h" /* Needed for HAVE_LIBUSB_1_0 and others. */
45c59c8b
BV
27#include "libsigrok.h"
28#include "libsigrok-internal.h"
a1bb33af 29
29a27196
UH
30/* Message logging helpers with subsystem-specific prefix string. */
31#define LOG_PREFIX "hwdriver: "
32#define sr_log(l, s, args...) sr_log(l, LOG_PREFIX s, ## args)
33#define sr_spew(s, args...) sr_spew(LOG_PREFIX s, ## args)
34#define sr_dbg(s, args...) sr_dbg(LOG_PREFIX s, ## args)
35#define sr_info(s, args...) sr_info(LOG_PREFIX s, ## args)
36#define sr_warn(s, args...) sr_warn(LOG_PREFIX s, ## args)
37#define sr_err(s, args...) sr_err(LOG_PREFIX s, ## args)
bd36d826 38
393fb9cb
UH
39/**
40 * @file
41 *
42 * Hardware driver handling in libsigrok.
43 */
44
7b870c38
UH
45/**
46 * @defgroup grp_driver Hardware drivers
47 *
48 * Hardware driver handling in libsigrok.
49 *
50 * @{
51 */
8bfdc8c4 52
c89c1c9c 53static struct sr_config_info sr_config_info_data[] = {
1953564a 54 {SR_CONF_CONN, SR_T_CHAR, "conn",
083d64f9 55 "Connection", NULL},
1953564a 56 {SR_CONF_SERIALCOMM, SR_T_CHAR, "serialcomm",
083d64f9 57 "Serial communication", NULL},
1953564a 58 {SR_CONF_SAMPLERATE, SR_T_UINT64, "samplerate",
083d64f9 59 "Sample rate", NULL},
1953564a 60 {SR_CONF_CAPTURE_RATIO, SR_T_UINT64, "captureratio",
083d64f9 61 "Pre-trigger capture ratio", NULL},
1953564a 62 {SR_CONF_PATTERN_MODE, SR_T_CHAR, "pattern",
083d64f9 63 "Pattern generator mode", NULL},
8e34ca86
BV
64 {SR_CONF_TRIGGER_TYPE, SR_T_CHAR, "triggertype",
65 "Trigger types", NULL},
1953564a 66 {SR_CONF_RLE, SR_T_BOOL, "rle",
083d64f9 67 "Run Length Encoding", NULL},
1953564a 68 {SR_CONF_TRIGGER_SLOPE, SR_T_UINT64, "triggerslope",
083d64f9 69 "Trigger slope", NULL},
1953564a 70 {SR_CONF_TRIGGER_SOURCE, SR_T_CHAR, "triggersource",
083d64f9 71 "Trigger source", NULL},
1953564a 72 {SR_CONF_HORIZ_TRIGGERPOS, SR_T_FLOAT, "horiz_triggerpos",
083d64f9 73 "Horizontal trigger position", NULL},
1953564a 74 {SR_CONF_BUFFERSIZE, SR_T_UINT64, "buffersize",
083d64f9 75 "Buffer size", NULL},
1953564a 76 {SR_CONF_TIMEBASE, SR_T_RATIONAL_PERIOD, "timebase",
083d64f9 77 "Time base", NULL},
1953564a 78 {SR_CONF_FILTER, SR_T_CHAR, "filter",
083d64f9 79 "Filter targets", NULL},
1953564a 80 {SR_CONF_VDIV, SR_T_RATIONAL_VOLT, "vdiv",
083d64f9 81 "Volts/div", NULL},
1953564a 82 {SR_CONF_COUPLING, SR_T_CHAR, "coupling",
083d64f9 83 "Coupling", NULL},
e6551ea6
BV
84 {SR_CONF_DATALOG, SR_T_BOOL, "datalog",
85 "Datalog", NULL},
083d64f9 86 {0, 0, NULL, NULL, NULL},
a1bb33af
UH
87};
88
b4bd7088 89/** @cond PRIVATE */
20cbc785 90#ifdef HAVE_HW_BRYMEN_DMM
c5d6f5cc 91extern SR_PRIV struct sr_dev_driver brymen_bm857_driver_info;
20cbc785 92#endif
8fa9368e
BV
93#ifdef HAVE_HW_CEM_DT_885X
94extern SR_PRIV struct sr_dev_driver cem_dt_885x_driver_info;
95#endif
4d729ddc
BV
96#ifdef HAVE_HW_COLEAD_SLM
97extern SR_PRIV struct sr_dev_driver colead_slm_driver_info;
98#endif
9e165e74 99#ifdef HAVE_HW_DEMO
c09f0b57 100extern SR_PRIV struct sr_dev_driver demo_driver_info;
a61b0e6a 101#endif
16e76bae
MS
102#ifdef HAVE_HW_IKALOGIC_SCANALOGIC2
103extern SR_PRIV struct sr_dev_driver ikalogic_scanalogic2_driver_info;
104#endif
46697e38
BV
105#ifdef HAVE_HW_LASCAR_EL_USB
106extern SR_PRIV struct sr_dev_driver lascar_el_usb_driver_info;
107#endif
7ec5b549 108#ifdef HAVE_HW_MIC_985XX
6f3e5335 109extern SR_PRIV struct sr_dev_driver mic_98581_driver_info;
0cd8e231 110extern SR_PRIV struct sr_dev_driver mic_98583_driver_info;
7ec5b549 111#endif
7ab89f48
UH
112#ifdef HAVE_HW_NEXUS_OSCIPRIME
113extern SR_PRIV struct sr_dev_driver nexus_osciprime_driver_info;
114#endif
9e165e74 115#ifdef HAVE_HW_OLS
c09f0b57 116extern SR_PRIV struct sr_dev_driver ols_driver_info;
960a75e4 117#endif
f4816ac6
ML
118#ifdef HAVE_HW_RIGOL_DS1XX2
119extern SR_PRIV struct sr_dev_driver rigol_ds1xx2_driver_info;
120#endif
aa2af324
UH
121#ifdef HAVE_HW_TONDAJ_SL_814
122extern SR_PRIV struct sr_dev_driver tondaj_sl_814_driver_info;
123#endif
ac3898d2
BV
124#ifdef HAVE_HW_VICTOR_DMM
125extern SR_PRIV struct sr_dev_driver victor_dmm_driver_info;
126#endif
9e165e74 127#ifdef HAVE_HW_ZEROPLUS_LOGIC_CUBE
c09f0b57 128extern SR_PRIV struct sr_dev_driver zeroplus_logic_cube_driver_info;
960a75e4 129#endif
9e165e74 130#ifdef HAVE_HW_ASIX_SIGMA
c09f0b57 131extern SR_PRIV struct sr_dev_driver asix_sigma_driver_info;
5b907f9b 132#endif
9e165e74 133#ifdef HAVE_HW_CHRONOVU_LA8
c09f0b57 134extern SR_PRIV struct sr_dev_driver chronovu_la8_driver_info;
f4314d7e 135#endif
9e165e74 136#ifdef HAVE_HW_LINK_MSO19
7ab89f48
UH
137extern SR_PRIV struct sr_dev_driver link_mso19_driver_info;
138#endif
0254651d 139#ifdef HAVE_HW_ALSA
c09f0b57 140extern SR_PRIV struct sr_dev_driver alsa_driver_info;
6ed4f044 141#endif
9e165e74 142#ifdef HAVE_HW_FX2LAFW
c09f0b57 143extern SR_PRIV struct sr_dev_driver fx2lafw_driver_info;
f302a082 144#endif
3b533202 145#ifdef HAVE_HW_HANTEK_DSO
62bb8840 146extern SR_PRIV struct sr_dev_driver hantek_dso_driver_info;
3b533202 147#endif
e93cdf42
BV
148#ifdef HAVE_HW_AGILENT_DMM
149extern SR_PRIV struct sr_dev_driver agdmm_driver_info;
150#endif
e7edd64f
BV
151#ifdef HAVE_HW_FLUKE_DMM
152extern SR_PRIV struct sr_dev_driver flukedmm_driver_info;
153#endif
21a7f269 154#ifdef HAVE_HW_SERIAL_DMM
f086b830 155extern SR_PRIV struct sr_dev_driver digitek_dt4000zc_driver_info;
729b01f9 156extern SR_PRIV struct sr_dev_driver tekpower_tp4000zc_driver_info;
ce3777ad 157extern SR_PRIV struct sr_dev_driver metex_me31_driver_info;
f0ac4929 158extern SR_PRIV struct sr_dev_driver peaktech_3410_driver_info;
5887c9cc 159extern SR_PRIV struct sr_dev_driver mastech_mas345_driver_info;
6dca2f16 160extern SR_PRIV struct sr_dev_driver va_va18b_driver_info;
a53da082 161extern SR_PRIV struct sr_dev_driver metex_m3640d_driver_info;
a376ffea 162extern SR_PRIV struct sr_dev_driver peaktech_4370_driver_info;
d4bd66a0 163extern SR_PRIV struct sr_dev_driver pce_pce_dm32_driver_info;
d5ce233f 164extern SR_PRIV struct sr_dev_driver radioshack_22_168_driver_info;
3864648b 165extern SR_PRIV struct sr_dev_driver radioshack_22_805_driver_info;
21829e67 166extern SR_PRIV struct sr_dev_driver radioshack_22_812_driver_info;
c2fa697a 167extern SR_PRIV struct sr_dev_driver tecpel_dmm_8060_ser_driver_info;
b38e08fb 168extern SR_PRIV struct sr_dev_driver tecpel_dmm_8061_ser_driver_info;
40830061 169extern SR_PRIV struct sr_dev_driver voltcraft_vc820_ser_driver_info;
54d11221 170extern SR_PRIV struct sr_dev_driver voltcraft_vc840_ser_driver_info;
ae3a59de 171extern SR_PRIV struct sr_dev_driver uni_t_ut61d_ser_driver_info;
986fde75 172extern SR_PRIV struct sr_dev_driver uni_t_ut61e_ser_driver_info;
7dc55d93 173#endif
79081ec8 174#ifdef HAVE_HW_UNI_T_DMM
4554314c 175extern SR_PRIV struct sr_dev_driver tecpel_dmm_8060_driver_info;
b6bad47c 176extern SR_PRIV struct sr_dev_driver tecpel_dmm_8061_driver_info;
fdbcb86d 177extern SR_PRIV struct sr_dev_driver uni_t_ut61d_driver_info;
bbef5e32 178extern SR_PRIV struct sr_dev_driver uni_t_ut61e_driver_info;
fdbcb86d 179extern SR_PRIV struct sr_dev_driver voltcraft_vc820_driver_info;
695d0e1e 180extern SR_PRIV struct sr_dev_driver voltcraft_vc840_driver_info;
79081ec8 181#endif
b4bd7088 182/** @endcond */
6ed4f044 183
c09f0b57 184static struct sr_dev_driver *drivers_list[] = {
20cbc785 185#ifdef HAVE_HW_BRYMEN_DMM
c5d6f5cc 186 &brymen_bm857_driver_info,
20cbc785 187#endif
8fa9368e
BV
188#ifdef HAVE_HW_CEM_DT_885X
189 &cem_dt_885x_driver_info,
190#endif
4d729ddc
BV
191#ifdef HAVE_HW_COLEAD_SLM
192 &colead_slm_driver_info,
193#endif
9e165e74 194#ifdef HAVE_HW_DEMO
c09f0b57 195 &demo_driver_info,
a61b0e6a 196#endif
16e76bae
MS
197#ifdef HAVE_HW_IKALOGIC_SCANALOGIC2
198 &ikalogic_scanalogic2_driver_info,
199#endif
46697e38
BV
200#ifdef HAVE_HW_LASCAR_EL_USB
201 &lascar_el_usb_driver_info,
202#endif
7ec5b549 203#ifdef HAVE_HW_MIC_985XX
6f3e5335 204 &mic_98581_driver_info,
0cd8e231 205 &mic_98583_driver_info,
7ec5b549 206#endif
7ab89f48
UH
207#ifdef HAVE_HW_NEXUS_OSCIPRIME
208 &nexus_osciprime_driver_info,
209#endif
9e165e74 210#ifdef HAVE_HW_OLS
c09f0b57 211 &ols_driver_info,
960a75e4 212#endif
f4816ac6
ML
213#ifdef HAVE_HW_RIGOL_DS1XX2
214 &rigol_ds1xx2_driver_info,
215#endif
aa2af324
UH
216#ifdef HAVE_HW_TONDAJ_SL_814
217 &tondaj_sl_814_driver_info,
218#endif
ac3898d2
BV
219#ifdef HAVE_HW_VICTOR_DMM
220 &victor_dmm_driver_info,
221#endif
9e165e74 222#ifdef HAVE_HW_ZEROPLUS_LOGIC_CUBE
c09f0b57 223 &zeroplus_logic_cube_driver_info,
960a75e4 224#endif
9e165e74 225#ifdef HAVE_HW_ASIX_SIGMA
c09f0b57 226 &asix_sigma_driver_info,
5b907f9b 227#endif
9e165e74 228#ifdef HAVE_HW_CHRONOVU_LA8
c09f0b57 229 &chronovu_la8_driver_info,
f4314d7e 230#endif
9e165e74 231#ifdef HAVE_HW_LINK_MSO19
7ab89f48
UH
232 &link_mso19_driver_info,
233#endif
0254651d 234#ifdef HAVE_HW_ALSA
c09f0b57 235 &alsa_driver_info,
f302a082 236#endif
9e165e74 237#ifdef HAVE_HW_FX2LAFW
c09f0b57 238 &fx2lafw_driver_info,
3b533202
BV
239#endif
240#ifdef HAVE_HW_HANTEK_DSO
62bb8840 241 &hantek_dso_driver_info,
6ed4f044 242#endif
e93cdf42
BV
243#ifdef HAVE_HW_AGILENT_DMM
244 &agdmm_driver_info,
e7edd64f
BV
245#endif
246#ifdef HAVE_HW_FLUKE_DMM
247 &flukedmm_driver_info,
d375b3c3 248#endif
21a7f269 249#ifdef HAVE_HW_SERIAL_DMM
f086b830 250 &digitek_dt4000zc_driver_info,
729b01f9 251 &tekpower_tp4000zc_driver_info,
ce3777ad 252 &metex_me31_driver_info,
f0ac4929 253 &peaktech_3410_driver_info,
5887c9cc 254 &mastech_mas345_driver_info,
6dca2f16 255 &va_va18b_driver_info,
a53da082 256 &metex_m3640d_driver_info,
a376ffea 257 &peaktech_4370_driver_info,
d4bd66a0 258 &pce_pce_dm32_driver_info,
d5ce233f 259 &radioshack_22_168_driver_info,
3864648b 260 &radioshack_22_805_driver_info,
21829e67 261 &radioshack_22_812_driver_info,
c2fa697a 262 &tecpel_dmm_8060_ser_driver_info,
b38e08fb 263 &tecpel_dmm_8061_ser_driver_info,
40830061 264 &voltcraft_vc820_ser_driver_info,
54d11221 265 &voltcraft_vc840_ser_driver_info,
ae3a59de 266 &uni_t_ut61d_ser_driver_info,
986fde75 267 &uni_t_ut61e_ser_driver_info,
79081ec8
UH
268#endif
269#ifdef HAVE_HW_UNI_T_DMM
4554314c 270 &tecpel_dmm_8060_driver_info,
b6bad47c 271 &tecpel_dmm_8061_driver_info,
fdbcb86d 272 &uni_t_ut61d_driver_info,
bbef5e32 273 &uni_t_ut61e_driver_info,
fdbcb86d 274 &voltcraft_vc820_driver_info,
695d0e1e 275 &voltcraft_vc840_driver_info,
eb1f1eb4 276#endif
050e9219
UH
277 NULL,
278};
a1bb33af 279
a1645fcd 280/**
cfe064d8 281 * Return the list of supported hardware drivers.
a1645fcd 282 *
c09f0b57 283 * @return Pointer to the NULL-terminated list of hardware driver pointers.
a1645fcd 284 */
cfe064d8 285SR_API struct sr_dev_driver **sr_driver_list(void)
a1bb33af 286{
80bf0426 287
c09f0b57 288 return drivers_list;
a1bb33af
UH
289}
290
a1645fcd 291/**
c09f0b57 292 * Initialize a hardware driver.
a1645fcd 293 *
c0eea11c
UH
294 * This usually involves memory allocations and variable initializations
295 * within the driver, but _not_ scanning for attached devices.
296 * The API call sr_driver_scan() is used for that.
297 *
44fc870c 298 * @param ctx A libsigrok context object allocated by a previous call to
c0eea11c
UH
299 * sr_init(). Must not be NULL.
300 * @param driver The driver to initialize. This must be a pointer to one of
301 * the entries returned by sr_driver_list(). Must not be NULL.
a1645fcd 302 *
c0eea11c
UH
303 * @return SR_OK upon success, SR_ERR_ARG upon invalid parameters,
304 * SR_ERR_BUG upon internal errors, or another negative error code
305 * upon other errors.
a1645fcd 306 */
44fc870c 307SR_API int sr_driver_init(struct sr_context *ctx, struct sr_dev_driver *driver)
8722c31e 308{
c0eea11c
UH
309 int ret;
310
311 if (!ctx) {
312 sr_err("Invalid libsigrok context, can't initialize.");
313 return SR_ERR_ARG;
314 }
315
316 if (!driver) {
317 sr_err("Invalid driver, can't initialize.");
318 return SR_ERR_ARG;
319 }
8722c31e 320
c0eea11c
UH
321 sr_spew("Initializing driver '%s'.", driver->name);
322 if ((ret = driver->init(ctx)) < 0)
323 sr_err("Failed to initialize the driver: %d.", ret);
80bf0426 324
c0eea11c 325 return ret;
80bf0426
BV
326}
327
328/**
329 * Tell a hardware driver to scan for devices.
330 *
a5f2e707
BV
331 * In addition to the detection, the devices that are found are also
332 * initialized automatically. On some devices, this involves a firmware upload,
333 * or other such measures.
334 *
335 * The order in which the system is scanned for devices is not specified. The
336 * caller should not assume or rely on any specific order.
337 *
4b97c74e
UH
338 * Before calling sr_driver_scan(), the user must have previously initialized
339 * the driver by calling sr_driver_init().
80bf0426 340 *
4b97c74e
UH
341 * @param driver The driver that should scan. This must be a pointer to one of
342 * the entries returned by sr_driver_list(). Must not be NULL.
343 * @param options A list of 'struct sr_hwopt' options to pass to the driver's
344 * scanner. Can be NULL/empty.
345 *
346 * @return A GSList * of 'struct sr_dev_inst', or NULL if no devices were
347 * found (or errors were encountered). This list must be freed by the
348 * caller using g_slist_free(), but without freeing the data pointed
349 * to in the list.
80bf0426
BV
350 */
351SR_API GSList *sr_driver_scan(struct sr_dev_driver *driver, GSList *options)
352{
4b97c74e
UH
353 GSList *l;
354
355 if (!driver) {
356 sr_err("Invalid driver, can't scan for devices.");
357 return NULL;
358 }
359
360 if (!driver->priv) {
361 sr_err("Driver not initialized, can't scan for devices.");
362 return NULL;
363 }
364
365 l = driver->scan(options);
80bf0426 366
4b97c74e
UH
367 sr_spew("Scan of '%s' found %d devices.", driver->name,
368 g_slist_length(l));
80bf0426 369
4b97c74e 370 return l;
8722c31e
BV
371}
372
b4bd7088 373/** @private */
93a04e3b 374SR_PRIV void sr_hw_cleanup_all(void)
8722c31e 375{
050e9219 376 int i;
c09f0b57 377 struct sr_dev_driver **drivers;
8722c31e 378
cfe064d8 379 drivers = sr_driver_list();
c09f0b57
UH
380 for (i = 0; drivers[i]; i++) {
381 if (drivers[i]->cleanup)
382 drivers[i]->cleanup();
8722c31e 383 }
8722c31e
BV
384}
385
bc1c2f00
BV
386/** A floating reference can be passed in for data. */
387SR_PRIV struct sr_config *sr_config_new(int key, GVariant *data)
4c0e310c
BV
388{
389 struct sr_config *src;
390
391 if (!(src = g_try_malloc(sizeof(struct sr_config))))
392 return NULL;
393 src->key = key;
bc1c2f00 394 src->data = g_variant_ref_sink(data);
4c0e310c
BV
395
396 return src;
397}
398
722db131
BV
399SR_PRIV void sr_config_free(struct sr_config *src)
400{
401
402 if (!src || !src->data) {
403 sr_err("%s: invalid data!", __func__);
404 return;
405 }
406
407 g_variant_unref(src->data);
408 g_free(src);
409
410}
411
df123801
BV
412/**
413 * Returns information about the given driver or device instance.
414 *
415 * @param driver The sr_dev_driver struct to query.
cbadb856 416 * @param key The configuration key (SR_CONF_*).
bc1c2f00
BV
417 * @param data Pointer to a GVariant where the value will be stored. Must
418 * not be NULL. The caller is given ownership of the GVariant
419 * and must thus decrease the refcount after use. However if
420 * this function returns an error code, the field should be
421 * considered unused, and should not be unreferenced.
422 * @param sdi (optional) If the key is specific to a device, this must
423 * contain a pointer to the struct sr_dev_inst to be checked.
424 * Otherwise it must be NULL.
df123801
BV
425 *
426 * @return SR_OK upon success or SR_ERR in case of error. Note SR_ERR_ARG
cbadb856 427 * may be returned by the driver indicating it doesn't know that key,
df123801
BV
428 * but this is not to be flagged as an error by the caller; merely
429 * as an indication that it's not applicable.
430 */
9fd504b9 431SR_API int sr_config_get(const struct sr_dev_driver *driver, int key,
bc1c2f00 432 GVariant **data, const struct sr_dev_inst *sdi)
df123801
BV
433{
434 int ret;
435
cbadb856 436 if (!driver || !data)
df123801
BV
437 return SR_ERR;
438
6cefe516
BV
439 if (!driver->config_get)
440 return SR_ERR_ARG;
441
bc1c2f00
BV
442 if ((ret = driver->config_get(key, data, sdi)) == SR_OK) {
443 /* Got a floating reference from the driver. Sink it here,
444 * caller will need to unref when done with it. */
445 g_variant_ref_sink(*data);
446 }
df123801
BV
447
448 return ret;
449}
450
cbadb856
BV
451/**
452 * Set a configuration key in a device instance.
453 *
454 * @param sdi The device instance.
455 * @param key The configuration key (SR_CONF_*).
bc1c2f00
BV
456 * @param data The new value for the key, as a GVariant with GVariantType
457 * appropriate to that key. A floating reference can be passed
458 * in; its refcount will be sunk and unreferenced after use.
cbadb856
BV
459 *
460 * @return SR_OK upon success or SR_ERR in case of error. Note SR_ERR_ARG
461 * may be returned by the driver indicating it doesn't know that key,
462 * but this is not to be flagged as an error by the caller; merely
463 * as an indication that it's not applicable.
464 */
bc1c2f00 465SR_API int sr_config_set(const struct sr_dev_inst *sdi, int key, GVariant *data)
cbadb856
BV
466{
467 int ret;
468
bc1c2f00 469 g_variant_ref_sink(data);
cbadb856 470
bc1c2f00
BV
471 if (!sdi || !sdi->driver || !data)
472 ret = SR_ERR;
473 else if (!sdi->driver->config_set)
474 ret = SR_ERR_ARG;
475 else
476 ret = sdi->driver->config_set(key, data, sdi);
cbadb856 477
bc1c2f00 478 g_variant_unref(data);
cbadb856
BV
479
480 return ret;
481}
482
483/**
484 * List all possible values for a configuration key.
485 *
486 * @param driver The sr_dev_driver struct to query.
487 * @param key The configuration key (SR_CONF_*).
bc1c2f00
BV
488 * @param data A pointer to a GVariant where the list will be stored. The
489 * caller is given ownership of the GVariant and must thus
490 * unref the GVariant after use. However if this function
491 * returns an error code, the field should be considered
492 * unused, and should not be unreferenced.
493 * @param sdi (optional) If the key is specific to a device, this must
494 * contain a pointer to the struct sr_dev_inst to be checked.
cbadb856
BV
495 *
496 * @return SR_OK upon success or SR_ERR in case of error. Note SR_ERR_ARG
497 * may be returned by the driver indicating it doesn't know that key,
498 * but this is not to be flagged as an error by the caller; merely
499 * as an indication that it's not applicable.
500 */
4c961f5e 501SR_API int sr_config_list(const struct sr_dev_driver *driver, int key,
bc1c2f00 502 GVariant **data, const struct sr_dev_inst *sdi)
c5fb502f
BV
503{
504 int ret;
505
6cefe516 506 if (!driver || !data)
bc1c2f00 507 ret = SR_ERR;
d8284802 508 else if (!driver->config_list)
6cefe516 509 ret = SR_ERR_ARG;
bc1c2f00
BV
510 else if ((ret = driver->config_list(key, data, sdi)) == SR_OK)
511 g_variant_ref_sink(*data);
c5fb502f
BV
512
513 return ret;
514}
515
8bfdc8c4 516/**
cbadb856 517 * Get information about a configuration key.
a1645fcd 518 *
ca0938c5 519 * @param key The configuration key.
15cb43d6 520 *
c89c1c9c 521 * @return A pointer to a struct sr_config_info, or NULL if the key
15cb43d6
BV
522 * was not found.
523 */
c89c1c9c 524SR_API const struct sr_config_info *sr_config_info_get(int key)
15cb43d6
BV
525{
526 int i;
527
c89c1c9c
BV
528 for (i = 0; sr_config_info_data[i].key; i++) {
529 if (sr_config_info_data[i].key == key)
530 return &sr_config_info_data[i];
15cb43d6
BV
531 }
532
533 return NULL;
534}
535
536/**
cbadb856 537 * Get information about an configuration key, by name.
15cb43d6 538 *
cbadb856 539 * @param optname The configuration key.
a1645fcd 540 *
c89c1c9c 541 * @return A pointer to a struct sr_config_info, or NULL if the key
15cb43d6 542 * was not found.
a1645fcd 543 */
c89c1c9c 544SR_API const struct sr_config_info *sr_config_info_name_get(const char *optname)
a1bb33af 545{
a1bb33af
UH
546 int i;
547
c89c1c9c
BV
548 for (i = 0; sr_config_info_data[i].key; i++) {
549 if (!strcmp(sr_config_info_data[i].id, optname))
550 return &sr_config_info_data[i];
a1bb33af
UH
551 }
552
49d0ce50 553 return NULL;
a1bb33af
UH
554}
555
69cfcfc8 556/* Unnecessary level of indirection follows. */
544a4582 557
b4bd7088 558/** @private */
69cfcfc8 559SR_PRIV int sr_source_remove(int fd)
a1bb33af 560{
69cfcfc8 561 return sr_session_source_remove(fd);
a1bb33af
UH
562}
563
b4bd7088 564/** @private */
69cfcfc8
UH
565SR_PRIV int sr_source_add(int fd, int events, int timeout,
566 sr_receive_data_callback_t cb, void *cb_data)
a1bb33af 567{
69cfcfc8 568 return sr_session_source_add(fd, events, timeout, cb, cb_data);
a1bb33af 569}
7b870c38
UH
570
571/** @} */