Uwe Hermann | a1bb33a | 2010-04-02 20:18:27 +0200 | [diff] [blame] | 1 | /* |
Uwe Hermann | 50985c2 | 2013-04-23 22:24:30 +0200 | [diff] [blame] | 2 | * This file is part of the libsigrok project. |
Uwe Hermann | a1bb33a | 2010-04-02 20:18:27 +0200 | [diff] [blame] | 3 | * |
Bert Vermeulen | 13d8e03 | 2013-03-24 11:21:00 +0100 | [diff] [blame] | 4 | * Copyright (C) 2013 Bert Vermeulen <bert@biot.com> |
Uwe Hermann | a1bb33a | 2010-04-02 20:18:27 +0200 | [diff] [blame] | 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> |
Uwe Hermann | 545f978 | 2012-10-24 00:41:21 +0200 | [diff] [blame] | 26 | #include "config.h" /* Needed for HAVE_LIBUSB_1_0 and others. */ |
Bert Vermeulen | 45c59c8 | 2012-07-05 00:55:07 +0200 | [diff] [blame] | 27 | #include "libsigrok.h" |
| 28 | #include "libsigrok-internal.h" |
Uwe Hermann | a1bb33a | 2010-04-02 20:18:27 +0200 | [diff] [blame] | 29 | |
Uwe Hermann | 2ad1deb | 2014-04-25 18:40:59 +0200 | [diff] [blame] | 30 | /** @cond PRIVATE */ |
Martin Ling | 3544f84 | 2013-12-23 03:38:35 +0000 | [diff] [blame] | 31 | #define LOG_PREFIX "hwdriver" |
Uwe Hermann | 2ad1deb | 2014-04-25 18:40:59 +0200 | [diff] [blame] | 32 | /** @endcond */ |
Uwe Hermann | bd36d82 | 2013-01-29 12:55:00 +0100 | [diff] [blame] | 33 | |
Bert Vermeulen | 5d8c55f | 2014-07-11 02:14:14 +0200 | [diff] [blame] | 34 | extern SR_PRIV struct sr_dev_driver *drivers_list[]; |
| 35 | |
Uwe Hermann | 7b870c3 | 2012-10-21 16:13:36 +0200 | [diff] [blame] | 36 | /** |
Uwe Hermann | 393fb9c | 2012-10-22 00:30:12 +0200 | [diff] [blame] | 37 | * @file |
| 38 | * |
| 39 | * Hardware driver handling in libsigrok. |
| 40 | */ |
| 41 | |
| 42 | /** |
Uwe Hermann | 7b870c3 | 2012-10-21 16:13:36 +0200 | [diff] [blame] | 43 | * @defgroup grp_driver Hardware drivers |
| 44 | * |
| 45 | * Hardware driver handling in libsigrok. |
| 46 | * |
| 47 | * @{ |
| 48 | */ |
Bert Vermeulen | 8bfdc8c | 2012-07-12 20:54:45 +0200 | [diff] [blame] | 49 | |
Bert Vermeulen | c89c1c9 | 2013-01-21 21:58:19 +0100 | [diff] [blame] | 50 | static struct sr_config_info sr_config_info_data[] = { |
Uwe Hermann | ace218f | 2014-05-06 20:18:54 +0200 | [diff] [blame] | 51 | {SR_CONF_CONN, SR_T_STRING, "conn", |
Bert Vermeulen | 083d64f | 2013-01-20 16:35:25 +0100 | [diff] [blame] | 52 | "Connection", NULL}, |
Uwe Hermann | ace218f | 2014-05-06 20:18:54 +0200 | [diff] [blame] | 53 | {SR_CONF_SERIALCOMM, SR_T_STRING, "serialcomm", |
Bert Vermeulen | 083d64f | 2013-01-20 16:35:25 +0100 | [diff] [blame] | 54 | "Serial communication", NULL}, |
Bert Vermeulen | 1953564 | 2013-01-21 23:22:47 +0100 | [diff] [blame] | 55 | {SR_CONF_SAMPLERATE, SR_T_UINT64, "samplerate", |
Bert Vermeulen | 083d64f | 2013-01-20 16:35:25 +0100 | [diff] [blame] | 56 | "Sample rate", NULL}, |
Bert Vermeulen | 1953564 | 2013-01-21 23:22:47 +0100 | [diff] [blame] | 57 | {SR_CONF_CAPTURE_RATIO, SR_T_UINT64, "captureratio", |
Bert Vermeulen | 083d64f | 2013-01-20 16:35:25 +0100 | [diff] [blame] | 58 | "Pre-trigger capture ratio", NULL}, |
Uwe Hermann | ace218f | 2014-05-06 20:18:54 +0200 | [diff] [blame] | 59 | {SR_CONF_PATTERN_MODE, SR_T_STRING, "pattern", |
Bert Vermeulen | 2438b73 | 2014-01-15 01:51:04 +0100 | [diff] [blame] | 60 | "Pattern", NULL}, |
Bert Vermeulen | 795c9de | 2014-05-27 23:55:26 +0200 | [diff] [blame] | 61 | {SR_CONF_TRIGGER_MATCH, SR_T_INT32, "triggermatch", |
| 62 | "Trigger matches", NULL}, |
Matt Ranostay | eb1b610 | 2013-08-24 22:01:15 -0700 | [diff] [blame] | 63 | {SR_CONF_EXTERNAL_CLOCK, SR_T_BOOL, "external_clock", |
| 64 | "External clock mode", NULL}, |
Matt Ranostay | 7b0a57f | 2013-08-27 21:19:56 -0700 | [diff] [blame] | 65 | {SR_CONF_SWAP, SR_T_BOOL, "swap", |
| 66 | "Swap channel order", NULL}, |
Bert Vermeulen | 1953564 | 2013-01-21 23:22:47 +0100 | [diff] [blame] | 67 | {SR_CONF_RLE, SR_T_BOOL, "rle", |
Bert Vermeulen | 083d64f | 2013-01-20 16:35:25 +0100 | [diff] [blame] | 68 | "Run Length Encoding", NULL}, |
Uwe Hermann | ace218f | 2014-05-06 20:18:54 +0200 | [diff] [blame] | 69 | {SR_CONF_TRIGGER_SLOPE, SR_T_STRING, "triggerslope", |
Bert Vermeulen | 083d64f | 2013-01-20 16:35:25 +0100 | [diff] [blame] | 70 | "Trigger slope", NULL}, |
Uwe Hermann | ace218f | 2014-05-06 20:18:54 +0200 | [diff] [blame] | 71 | {SR_CONF_TRIGGER_SOURCE, SR_T_STRING, "triggersource", |
Bert Vermeulen | 083d64f | 2013-01-20 16:35:25 +0100 | [diff] [blame] | 72 | "Trigger source", NULL}, |
Bert Vermeulen | 1953564 | 2013-01-21 23:22:47 +0100 | [diff] [blame] | 73 | {SR_CONF_HORIZ_TRIGGERPOS, SR_T_FLOAT, "horiz_triggerpos", |
Bert Vermeulen | 083d64f | 2013-01-20 16:35:25 +0100 | [diff] [blame] | 74 | "Horizontal trigger position", NULL}, |
Bert Vermeulen | 1953564 | 2013-01-21 23:22:47 +0100 | [diff] [blame] | 75 | {SR_CONF_BUFFERSIZE, SR_T_UINT64, "buffersize", |
Bert Vermeulen | 083d64f | 2013-01-20 16:35:25 +0100 | [diff] [blame] | 76 | "Buffer size", NULL}, |
Bert Vermeulen | 1953564 | 2013-01-21 23:22:47 +0100 | [diff] [blame] | 77 | {SR_CONF_TIMEBASE, SR_T_RATIONAL_PERIOD, "timebase", |
Bert Vermeulen | 083d64f | 2013-01-20 16:35:25 +0100 | [diff] [blame] | 78 | "Time base", NULL}, |
Uwe Hermann | ace218f | 2014-05-06 20:18:54 +0200 | [diff] [blame] | 79 | {SR_CONF_FILTER, SR_T_STRING, "filter", |
Bert Vermeulen | 083d64f | 2013-01-20 16:35:25 +0100 | [diff] [blame] | 80 | "Filter targets", NULL}, |
Bert Vermeulen | 1953564 | 2013-01-21 23:22:47 +0100 | [diff] [blame] | 81 | {SR_CONF_VDIV, SR_T_RATIONAL_VOLT, "vdiv", |
Bert Vermeulen | 083d64f | 2013-01-20 16:35:25 +0100 | [diff] [blame] | 82 | "Volts/div", NULL}, |
Uwe Hermann | ace218f | 2014-05-06 20:18:54 +0200 | [diff] [blame] | 83 | {SR_CONF_COUPLING, SR_T_STRING, "coupling", |
Bert Vermeulen | 083d64f | 2013-01-20 16:35:25 +0100 | [diff] [blame] | 84 | "Coupling", NULL}, |
Bert Vermeulen | e6551ea | 2013-03-11 16:35:18 +0100 | [diff] [blame] | 85 | {SR_CONF_DATALOG, SR_T_BOOL, "datalog", |
| 86 | "Datalog", NULL}, |
Uwe Hermann | ace218f | 2014-05-06 20:18:54 +0200 | [diff] [blame] | 87 | {SR_CONF_SPL_WEIGHT_FREQ, SR_T_STRING, "spl_weight_freq", |
Bert Vermeulen | fd8854c | 2013-06-15 12:09:31 +0200 | [diff] [blame] | 88 | "Sound pressure level frequency weighting", NULL}, |
Uwe Hermann | ace218f | 2014-05-06 20:18:54 +0200 | [diff] [blame] | 89 | {SR_CONF_SPL_WEIGHT_TIME, SR_T_STRING, "spl_weight_time", |
Bert Vermeulen | fd8854c | 2013-06-15 12:09:31 +0200 | [diff] [blame] | 90 | "Sound pressure level time weighting", NULL}, |
Bert Vermeulen | 9fd6bc2 | 2013-06-16 12:12:20 +0200 | [diff] [blame] | 91 | {SR_CONF_HOLD_MAX, SR_T_BOOL, "hold_max", |
| 92 | "Hold max", NULL}, |
| 93 | {SR_CONF_HOLD_MIN, SR_T_BOOL, "hold_min", |
| 94 | "Hold min", NULL}, |
Bert Vermeulen | 8417eba | 2013-06-17 01:25:41 +0200 | [diff] [blame] | 95 | {SR_CONF_SPL_MEASUREMENT_RANGE, SR_T_UINT64_RANGE, "spl_meas_range", |
| 96 | "Sound pressure level measurement range", NULL}, |
Marcus Comstedt | db11d7d | 2013-08-04 16:20:07 +0200 | [diff] [blame] | 97 | {SR_CONF_VOLTAGE_THRESHOLD, SR_T_DOUBLE_RANGE, "voltage_threshold", |
| 98 | "Voltage threshold", NULL }, |
Bert Vermeulen | 32de50b | 2013-06-17 11:54:37 +0200 | [diff] [blame] | 99 | {SR_CONF_POWER_OFF, SR_T_BOOL, "power_off", |
| 100 | "Power off", NULL}, |
Uwe Hermann | ace218f | 2014-05-06 20:18:54 +0200 | [diff] [blame] | 101 | {SR_CONF_DATA_SOURCE, SR_T_STRING, "data_source", |
Bert Vermeulen | 6caeef6 | 2013-06-19 12:18:00 +0200 | [diff] [blame] | 102 | "Data source", NULL}, |
Uwe Hermann | fca75cb | 2014-03-24 16:11:45 +0100 | [diff] [blame] | 103 | {SR_CONF_NUM_LOGIC_CHANNELS, SR_T_INT32, "logic_channels", |
| 104 | "Number of logic channels", NULL}, |
| 105 | {SR_CONF_NUM_ANALOG_CHANNELS, SR_T_INT32, "analog_channels", |
| 106 | "Number of analog channels", NULL}, |
Bert Vermeulen | 471607f | 2014-01-08 21:15:45 +0100 | [diff] [blame] | 107 | {SR_CONF_OUTPUT_VOLTAGE, SR_T_FLOAT, "output_voltage", |
| 108 | "Current output voltage", NULL}, |
Bert Vermeulen | ae431bc | 2014-10-16 13:22:51 +0200 | [diff] [blame] | 109 | {SR_CONF_OUTPUT_VOLTAGE_TARGET, SR_T_FLOAT, "output_voltage_target", |
Bert Vermeulen | ca95e90 | 2014-10-15 12:03:00 +0200 | [diff] [blame] | 110 | "Output voltage target", NULL}, |
Bert Vermeulen | 471607f | 2014-01-08 21:15:45 +0100 | [diff] [blame] | 111 | {SR_CONF_OUTPUT_CURRENT, SR_T_FLOAT, "output_current", |
| 112 | "Current output current", NULL}, |
Bert Vermeulen | ae431bc | 2014-10-16 13:22:51 +0200 | [diff] [blame] | 113 | {SR_CONF_OUTPUT_CURRENT_LIMIT, SR_T_FLOAT, "output_current_limit", |
Bert Vermeulen | ca95e90 | 2014-10-15 12:03:00 +0200 | [diff] [blame] | 114 | "Output current limit", NULL}, |
Bert Vermeulen | 471607f | 2014-01-08 21:15:45 +0100 | [diff] [blame] | 115 | {SR_CONF_OUTPUT_ENABLED, SR_T_BOOL, "output_enabled", |
| 116 | "Output enabled", NULL}, |
Bert Vermeulen | a1eaa9e | 2014-09-05 02:47:22 +0200 | [diff] [blame] | 117 | {SR_CONF_OUTPUT_CHANNEL_CONFIG, SR_T_STRING, "output_channel_config", |
Bert Vermeulen | 471607f | 2014-01-08 21:15:45 +0100 | [diff] [blame] | 118 | "Output channel modes", NULL}, |
Bert Vermeulen | a1eaa9e | 2014-09-05 02:47:22 +0200 | [diff] [blame] | 119 | {SR_CONF_OVER_VOLTAGE_PROTECTION_ENABLED, SR_T_BOOL, "ovp_enabled", |
| 120 | "Over-voltage protection enabled", NULL}, |
| 121 | {SR_CONF_OVER_VOLTAGE_PROTECTION_ACTIVE, SR_T_BOOL, "ovp_active", |
| 122 | "Over-voltage protection active", NULL}, |
| 123 | {SR_CONF_OVER_VOLTAGE_PROTECTION_THRESHOLD, SR_T_FLOAT, "ovp_threshold", |
| 124 | "Over-voltage protection threshold", NULL}, |
| 125 | {SR_CONF_OVER_CURRENT_PROTECTION_ENABLED, SR_T_BOOL, "ocp_enabled", |
| 126 | "Over-current protection enabled", NULL}, |
| 127 | {SR_CONF_OVER_CURRENT_PROTECTION_ACTIVE, SR_T_BOOL, "ocp_active", |
| 128 | "Over-current protection active", NULL}, |
| 129 | {SR_CONF_OVER_CURRENT_PROTECTION_THRESHOLD, SR_T_FLOAT, "ocp_threshold", |
| 130 | "Over-current protection threshold", NULL}, |
Bert Vermeulen | f0de2dd | 2014-01-19 17:18:59 +0100 | [diff] [blame] | 131 | {SR_CONF_LIMIT_SAMPLES, SR_T_UINT64, "limit_samples", |
| 132 | "Sample limit", NULL}, |
Uwe Hermann | ace218f | 2014-05-06 20:18:54 +0200 | [diff] [blame] | 133 | {SR_CONF_CLOCK_EDGE, SR_T_STRING, "clock_edge", |
Daniel Elstner | 860bc59 | 2014-01-29 20:53:51 +0100 | [diff] [blame] | 134 | "Clock edge", NULL}, |
Bert Vermeulen | cff7d8d | 2014-07-27 23:59:49 +0200 | [diff] [blame] | 135 | {SR_CONF_AMPLITUDE, SR_T_FLOAT, "amplitude", |
| 136 | "Amplitude", NULL}, |
Bert Vermeulen | a1eaa9e | 2014-09-05 02:47:22 +0200 | [diff] [blame] | 137 | {SR_CONF_OVER_TEMPERATURE_PROTECTION, SR_T_BOOL, "otp", |
| 138 | "Over-temperature protection", NULL}, |
| 139 | {SR_CONF_OUTPUT_REGULATION, SR_T_STRING, "output_regulation", |
| 140 | "Output channel regulation", NULL}, |
Bert Vermeulen | 083d64f | 2013-01-20 16:35:25 +0100 | [diff] [blame] | 141 | {0, 0, NULL, NULL, NULL}, |
Uwe Hermann | a1bb33a | 2010-04-02 20:18:27 +0200 | [diff] [blame] | 142 | }; |
| 143 | |
Martin Ling | 13fef1e | 2014-09-14 04:47:12 +0100 | [diff] [blame] | 144 | SR_PRIV const GVariantType *sr_variant_type_get(int datatype) |
| 145 | { |
| 146 | switch (datatype) { |
| 147 | case SR_T_INT32: |
| 148 | return G_VARIANT_TYPE_INT32; |
| 149 | case SR_T_UINT64: |
| 150 | return G_VARIANT_TYPE_UINT64; |
| 151 | case SR_T_STRING: |
| 152 | return G_VARIANT_TYPE_STRING; |
| 153 | case SR_T_BOOL: |
| 154 | return G_VARIANT_TYPE_BOOLEAN; |
| 155 | case SR_T_FLOAT: |
| 156 | return G_VARIANT_TYPE_DOUBLE; |
| 157 | case SR_T_RATIONAL_PERIOD: |
| 158 | case SR_T_RATIONAL_VOLT: |
| 159 | case SR_T_UINT64_RANGE: |
| 160 | case SR_T_DOUBLE_RANGE: |
| 161 | return G_VARIANT_TYPE_TUPLE; |
| 162 | case SR_T_KEYVALUE: |
| 163 | return G_VARIANT_TYPE_DICTIONARY; |
| 164 | default: |
| 165 | return NULL; |
| 166 | } |
| 167 | } |
| 168 | |
Bert Vermeulen | 584560f | 2014-09-16 17:49:20 +0200 | [diff] [blame] | 169 | SR_PRIV int sr_variant_type_check(uint32_t key, GVariant *value) |
Martin Ling | 13fef1e | 2014-09-14 04:47:12 +0100 | [diff] [blame] | 170 | { |
| 171 | const struct sr_config_info *info; |
| 172 | const GVariantType *type, *expected; |
| 173 | info = sr_config_info_get(key); |
| 174 | if (!info) |
| 175 | return SR_OK; |
| 176 | expected = sr_variant_type_get(info->datatype); |
| 177 | type = g_variant_get_type(value); |
| 178 | if (!g_variant_type_equal(type, expected)) { |
| 179 | gchar *expected_string = g_variant_type_dup_string(expected); |
| 180 | gchar *type_string = g_variant_type_dup_string(type); |
| 181 | sr_err("Wrong variant type for key '%s': expected '%s', got '%s'", |
| 182 | info->name, expected_string, type_string); |
| 183 | g_free(expected_string); |
| 184 | g_free(type_string); |
| 185 | return SR_ERR_ARG; |
| 186 | } |
| 187 | return SR_OK; |
| 188 | } |
| 189 | |
Bert Vermeulen | a1645fc | 2012-02-13 03:36:32 +0100 | [diff] [blame] | 190 | /** |
Uwe Hermann | cfe064d | 2012-02-29 19:56:15 +0100 | [diff] [blame] | 191 | * Return the list of supported hardware drivers. |
Bert Vermeulen | a1645fc | 2012-02-13 03:36:32 +0100 | [diff] [blame] | 192 | * |
Uwe Hermann | c09f0b5 | 2012-02-28 23:52:30 +0100 | [diff] [blame] | 193 | * @return Pointer to the NULL-terminated list of hardware driver pointers. |
Uwe Hermann | 4711724 | 2014-05-04 20:51:05 +0200 | [diff] [blame] | 194 | * |
| 195 | * @since 0.1.0 |
Bert Vermeulen | a1645fc | 2012-02-13 03:36:32 +0100 | [diff] [blame] | 196 | */ |
Uwe Hermann | cfe064d | 2012-02-29 19:56:15 +0100 | [diff] [blame] | 197 | SR_API struct sr_dev_driver **sr_driver_list(void) |
Uwe Hermann | a1bb33a | 2010-04-02 20:18:27 +0200 | [diff] [blame] | 198 | { |
Bert Vermeulen | 80bf042 | 2012-07-08 16:25:23 +0200 | [diff] [blame] | 199 | |
Uwe Hermann | c09f0b5 | 2012-02-28 23:52:30 +0100 | [diff] [blame] | 200 | return drivers_list; |
Uwe Hermann | a1bb33a | 2010-04-02 20:18:27 +0200 | [diff] [blame] | 201 | } |
| 202 | |
Bert Vermeulen | a1645fc | 2012-02-13 03:36:32 +0100 | [diff] [blame] | 203 | /** |
Uwe Hermann | c09f0b5 | 2012-02-28 23:52:30 +0100 | [diff] [blame] | 204 | * Initialize a hardware driver. |
Bert Vermeulen | a1645fc | 2012-02-13 03:36:32 +0100 | [diff] [blame] | 205 | * |
Uwe Hermann | c0eea11 | 2013-01-28 19:36:16 +0100 | [diff] [blame] | 206 | * This usually involves memory allocations and variable initializations |
| 207 | * within the driver, but _not_ scanning for attached devices. |
| 208 | * The API call sr_driver_scan() is used for that. |
Bert Vermeulen | a1645fc | 2012-02-13 03:36:32 +0100 | [diff] [blame] | 209 | * |
Uwe Hermann | c0eea11 | 2013-01-28 19:36:16 +0100 | [diff] [blame] | 210 | * @param ctx A libsigrok context object allocated by a previous call to |
| 211 | * sr_init(). Must not be NULL. |
| 212 | * @param driver The driver to initialize. This must be a pointer to one of |
| 213 | * the entries returned by sr_driver_list(). Must not be NULL. |
| 214 | * |
Matthias Heidbrink | 67eb6bc | 2014-02-05 14:46:10 +0100 | [diff] [blame] | 215 | * @retval SR_OK Success |
| 216 | * @retval SR_ERR_ARG Invalid parameter(s). |
| 217 | * @retval SR_ERR_BUG Internal errors. |
| 218 | * @retval other Another negative error code upon other errors. |
Uwe Hermann | 4711724 | 2014-05-04 20:51:05 +0200 | [diff] [blame] | 219 | * |
| 220 | * @since 0.2.0 |
Bert Vermeulen | a1645fc | 2012-02-13 03:36:32 +0100 | [diff] [blame] | 221 | */ |
Peter Stuge | 44fc870 | 2012-12-03 02:42:57 +0100 | [diff] [blame] | 222 | SR_API int sr_driver_init(struct sr_context *ctx, struct sr_dev_driver *driver) |
Bert Vermeulen | 8722c31 | 2011-04-04 05:13:29 +0200 | [diff] [blame] | 223 | { |
Uwe Hermann | c0eea11 | 2013-01-28 19:36:16 +0100 | [diff] [blame] | 224 | int ret; |
Bert Vermeulen | 8722c31 | 2011-04-04 05:13:29 +0200 | [diff] [blame] | 225 | |
Uwe Hermann | c0eea11 | 2013-01-28 19:36:16 +0100 | [diff] [blame] | 226 | if (!ctx) { |
| 227 | sr_err("Invalid libsigrok context, can't initialize."); |
| 228 | return SR_ERR_ARG; |
| 229 | } |
Kristoffer Sjöberg | 464d12c | 2011-12-29 17:04:31 +0100 | [diff] [blame] | 230 | |
Uwe Hermann | c0eea11 | 2013-01-28 19:36:16 +0100 | [diff] [blame] | 231 | if (!driver) { |
| 232 | sr_err("Invalid driver, can't initialize."); |
| 233 | return SR_ERR_ARG; |
| 234 | } |
| 235 | |
| 236 | sr_spew("Initializing driver '%s'.", driver->name); |
| 237 | if ((ret = driver->init(ctx)) < 0) |
| 238 | sr_err("Failed to initialize the driver: %d.", ret); |
| 239 | |
| 240 | return ret; |
Bert Vermeulen | 80bf042 | 2012-07-08 16:25:23 +0200 | [diff] [blame] | 241 | } |
Kristoffer Sjöberg | 464d12c | 2011-12-29 17:04:31 +0100 | [diff] [blame] | 242 | |
Bert Vermeulen | 80bf042 | 2012-07-08 16:25:23 +0200 | [diff] [blame] | 243 | /** |
| 244 | * Tell a hardware driver to scan for devices. |
| 245 | * |
Bert Vermeulen | a5f2e70 | 2012-07-22 20:06:13 +0200 | [diff] [blame] | 246 | * In addition to the detection, the devices that are found are also |
| 247 | * initialized automatically. On some devices, this involves a firmware upload, |
| 248 | * or other such measures. |
| 249 | * |
| 250 | * The order in which the system is scanned for devices is not specified. The |
| 251 | * caller should not assume or rely on any specific order. |
| 252 | * |
Uwe Hermann | 4b97c74 | 2013-01-28 20:00:54 +0100 | [diff] [blame] | 253 | * Before calling sr_driver_scan(), the user must have previously initialized |
| 254 | * the driver by calling sr_driver_init(). |
Bert Vermeulen | 80bf042 | 2012-07-08 16:25:23 +0200 | [diff] [blame] | 255 | * |
Uwe Hermann | 4b97c74 | 2013-01-28 20:00:54 +0100 | [diff] [blame] | 256 | * @param driver The driver that should scan. This must be a pointer to one of |
| 257 | * the entries returned by sr_driver_list(). Must not be NULL. |
| 258 | * @param options A list of 'struct sr_hwopt' options to pass to the driver's |
| 259 | * scanner. Can be NULL/empty. |
| 260 | * |
| 261 | * @return A GSList * of 'struct sr_dev_inst', or NULL if no devices were |
| 262 | * found (or errors were encountered). This list must be freed by the |
| 263 | * caller using g_slist_free(), but without freeing the data pointed |
| 264 | * to in the list. |
Uwe Hermann | 4711724 | 2014-05-04 20:51:05 +0200 | [diff] [blame] | 265 | * |
| 266 | * @since 0.2.0 |
Bert Vermeulen | 80bf042 | 2012-07-08 16:25:23 +0200 | [diff] [blame] | 267 | */ |
| 268 | SR_API GSList *sr_driver_scan(struct sr_dev_driver *driver, GSList *options) |
| 269 | { |
Uwe Hermann | 4b97c74 | 2013-01-28 20:00:54 +0100 | [diff] [blame] | 270 | GSList *l; |
Martin Ling | 13fef1e | 2014-09-14 04:47:12 +0100 | [diff] [blame] | 271 | struct sr_config *src; |
Bert Vermeulen | 8722c31 | 2011-04-04 05:13:29 +0200 | [diff] [blame] | 272 | |
Uwe Hermann | 4b97c74 | 2013-01-28 20:00:54 +0100 | [diff] [blame] | 273 | if (!driver) { |
| 274 | sr_err("Invalid driver, can't scan for devices."); |
| 275 | return NULL; |
| 276 | } |
Bert Vermeulen | 80bf042 | 2012-07-08 16:25:23 +0200 | [diff] [blame] | 277 | |
Uwe Hermann | 4b97c74 | 2013-01-28 20:00:54 +0100 | [diff] [blame] | 278 | if (!driver->priv) { |
| 279 | sr_err("Driver not initialized, can't scan for devices."); |
| 280 | return NULL; |
| 281 | } |
| 282 | |
Martin Ling | 13fef1e | 2014-09-14 04:47:12 +0100 | [diff] [blame] | 283 | for (l = options; l; l = l->next) { |
| 284 | src = l->data; |
| 285 | if (sr_variant_type_check(src->key, src->data) != SR_OK) |
| 286 | return NULL; |
| 287 | } |
| 288 | |
Uwe Hermann | 4b97c74 | 2013-01-28 20:00:54 +0100 | [diff] [blame] | 289 | l = driver->scan(options); |
| 290 | |
| 291 | sr_spew("Scan of '%s' found %d devices.", driver->name, |
| 292 | g_slist_length(l)); |
| 293 | |
| 294 | return l; |
Bert Vermeulen | 8722c31 | 2011-04-04 05:13:29 +0200 | [diff] [blame] | 295 | } |
| 296 | |
Matthias Heidbrink | 67eb6bc | 2014-02-05 14:46:10 +0100 | [diff] [blame] | 297 | /** Call driver cleanup function for all drivers. |
| 298 | * @private */ |
Bert Vermeulen | 93a04e3 | 2012-02-15 03:18:48 +0100 | [diff] [blame] | 299 | SR_PRIV void sr_hw_cleanup_all(void) |
Bert Vermeulen | 8722c31 | 2011-04-04 05:13:29 +0200 | [diff] [blame] | 300 | { |
Uwe Hermann | 050e921 | 2012-02-22 21:48:30 +0100 | [diff] [blame] | 301 | int i; |
Uwe Hermann | c09f0b5 | 2012-02-28 23:52:30 +0100 | [diff] [blame] | 302 | struct sr_dev_driver **drivers; |
Bert Vermeulen | 8722c31 | 2011-04-04 05:13:29 +0200 | [diff] [blame] | 303 | |
Uwe Hermann | cfe064d | 2012-02-29 19:56:15 +0100 | [diff] [blame] | 304 | drivers = sr_driver_list(); |
Uwe Hermann | c09f0b5 | 2012-02-28 23:52:30 +0100 | [diff] [blame] | 305 | for (i = 0; drivers[i]; i++) { |
| 306 | if (drivers[i]->cleanup) |
| 307 | drivers[i]->cleanup(); |
Bert Vermeulen | 8722c31 | 2011-04-04 05:13:29 +0200 | [diff] [blame] | 308 | } |
Bert Vermeulen | 8722c31 | 2011-04-04 05:13:29 +0200 | [diff] [blame] | 309 | } |
| 310 | |
Matthias Heidbrink | 67eb6bc | 2014-02-05 14:46:10 +0100 | [diff] [blame] | 311 | /** Allocate struct sr_config. |
| 312 | * A floating reference can be passed in for data. |
| 313 | * @private |
| 314 | */ |
Bert Vermeulen | 584560f | 2014-09-16 17:49:20 +0200 | [diff] [blame] | 315 | SR_PRIV struct sr_config *sr_config_new(uint32_t key, GVariant *data) |
Bert Vermeulen | 4c0e310 | 2013-01-20 16:34:38 +0100 | [diff] [blame] | 316 | { |
| 317 | struct sr_config *src; |
| 318 | |
| 319 | if (!(src = g_try_malloc(sizeof(struct sr_config)))) |
| 320 | return NULL; |
| 321 | src->key = key; |
Bert Vermeulen | bc1c2f0 | 2013-03-25 15:38:44 +0100 | [diff] [blame] | 322 | src->data = g_variant_ref_sink(data); |
Bert Vermeulen | 4c0e310 | 2013-01-20 16:34:38 +0100 | [diff] [blame] | 323 | |
| 324 | return src; |
| 325 | } |
| 326 | |
Matthias Heidbrink | 67eb6bc | 2014-02-05 14:46:10 +0100 | [diff] [blame] | 327 | /** Free struct sr_config. |
| 328 | * @private |
| 329 | */ |
Bert Vermeulen | 722db13 | 2013-03-25 20:23:13 +0100 | [diff] [blame] | 330 | SR_PRIV void sr_config_free(struct sr_config *src) |
| 331 | { |
| 332 | |
| 333 | if (!src || !src->data) { |
| 334 | sr_err("%s: invalid data!", __func__); |
| 335 | return; |
| 336 | } |
| 337 | |
| 338 | g_variant_unref(src->data); |
| 339 | g_free(src); |
| 340 | |
| 341 | } |
| 342 | |
Bert Vermeulen | df12380 | 2012-07-12 22:41:57 +0200 | [diff] [blame] | 343 | /** |
Matthias Heidbrink | 67eb6bc | 2014-02-05 14:46:10 +0100 | [diff] [blame] | 344 | * Query value of a configuration key at the given driver or device instance. |
Bert Vermeulen | df12380 | 2012-07-12 22:41:57 +0200 | [diff] [blame] | 345 | * |
Matthias Heidbrink | 67eb6bc | 2014-02-05 14:46:10 +0100 | [diff] [blame] | 346 | * @param[in] driver The sr_dev_driver struct to query. |
| 347 | * @param[in] sdi (optional) If the key is specific to a device, this must |
Bert Vermeulen | 57ecdbd | 2013-04-28 22:11:05 +0200 | [diff] [blame] | 348 | * contain a pointer to the struct sr_dev_inst to be checked. |
| 349 | * Otherwise it must be NULL. |
Uwe Hermann | 53b4680 | 2014-03-20 21:58:01 +0100 | [diff] [blame] | 350 | * @param[in] cg The channel group on the device for which to list the |
Bert Vermeulen | 57ecdbd | 2013-04-28 22:11:05 +0200 | [diff] [blame] | 351 | * values, or NULL. |
Matthias Heidbrink | 67eb6bc | 2014-02-05 14:46:10 +0100 | [diff] [blame] | 352 | * @param[in] key The configuration key (SR_CONF_*). |
| 353 | * @param[in,out] data Pointer to a GVariant where the value will be stored. |
| 354 | * Must not be NULL. The caller is given ownership of the GVariant |
Bert Vermeulen | bc1c2f0 | 2013-03-25 15:38:44 +0100 | [diff] [blame] | 355 | * and must thus decrease the refcount after use. However if |
| 356 | * this function returns an error code, the field should be |
| 357 | * considered unused, and should not be unreferenced. |
Bert Vermeulen | df12380 | 2012-07-12 22:41:57 +0200 | [diff] [blame] | 358 | * |
Matthias Heidbrink | 67eb6bc | 2014-02-05 14:46:10 +0100 | [diff] [blame] | 359 | * @retval SR_OK Success. |
| 360 | * @retval SR_ERR Error. |
| 361 | * @retval SR_ERR_ARG The driver doesn't know that key, but this is not to be |
| 362 | * interpreted as an error by the caller; merely as an indication |
| 363 | * that it's not applicable. |
Uwe Hermann | 4711724 | 2014-05-04 20:51:05 +0200 | [diff] [blame] | 364 | * |
| 365 | * @since 0.3.0 |
Bert Vermeulen | df12380 | 2012-07-12 22:41:57 +0200 | [diff] [blame] | 366 | */ |
Martin Ling | 8f996b8 | 2013-04-20 01:00:49 +0100 | [diff] [blame] | 367 | SR_API int sr_config_get(const struct sr_dev_driver *driver, |
| 368 | const struct sr_dev_inst *sdi, |
Uwe Hermann | 53b4680 | 2014-03-20 21:58:01 +0100 | [diff] [blame] | 369 | const struct sr_channel_group *cg, |
Bert Vermeulen | 584560f | 2014-09-16 17:49:20 +0200 | [diff] [blame] | 370 | uint32_t key, GVariant **data) |
Bert Vermeulen | df12380 | 2012-07-12 22:41:57 +0200 | [diff] [blame] | 371 | { |
| 372 | int ret; |
| 373 | |
Bert Vermeulen | cbadb85 | 2013-01-26 01:18:19 +0100 | [diff] [blame] | 374 | if (!driver || !data) |
Bert Vermeulen | df12380 | 2012-07-12 22:41:57 +0200 | [diff] [blame] | 375 | return SR_ERR; |
| 376 | |
Bert Vermeulen | 6cefe51 | 2013-04-07 21:50:42 +0200 | [diff] [blame] | 377 | if (!driver->config_get) |
| 378 | return SR_ERR_ARG; |
| 379 | |
Uwe Hermann | 53b4680 | 2014-03-20 21:58:01 +0100 | [diff] [blame] | 380 | if ((ret = driver->config_get(key, data, sdi, cg)) == SR_OK) { |
Bert Vermeulen | bc1c2f0 | 2013-03-25 15:38:44 +0100 | [diff] [blame] | 381 | /* Got a floating reference from the driver. Sink it here, |
| 382 | * caller will need to unref when done with it. */ |
| 383 | g_variant_ref_sink(*data); |
| 384 | } |
Bert Vermeulen | c5fb502 | 2013-01-25 01:24:42 +0100 | [diff] [blame] | 385 | |
| 386 | return ret; |
| 387 | } |
| 388 | |
Bert Vermeulen | a1645fc | 2012-02-13 03:36:32 +0100 | [diff] [blame] | 389 | /** |
Matthias Heidbrink | 67eb6bc | 2014-02-05 14:46:10 +0100 | [diff] [blame] | 390 | * Set value of a configuration key in a device instance. |
Bert Vermeulen | 8bfdc8c | 2012-07-12 20:54:45 +0200 | [diff] [blame] | 391 | * |
Matthias Heidbrink | 67eb6bc | 2014-02-05 14:46:10 +0100 | [diff] [blame] | 392 | * @param[in] sdi The device instance. |
Uwe Hermann | 53b4680 | 2014-03-20 21:58:01 +0100 | [diff] [blame] | 393 | * @param[in] cg The channel group on the device for which to list the |
Bert Vermeulen | 57ecdbd | 2013-04-28 22:11:05 +0200 | [diff] [blame] | 394 | * values, or NULL. |
Matthias Heidbrink | 67eb6bc | 2014-02-05 14:46:10 +0100 | [diff] [blame] | 395 | * @param[in] key The configuration key (SR_CONF_*). |
Bert Vermeulen | bc1c2f0 | 2013-03-25 15:38:44 +0100 | [diff] [blame] | 396 | * @param data The new value for the key, as a GVariant with GVariantType |
| 397 | * appropriate to that key. A floating reference can be passed |
| 398 | * in; its refcount will be sunk and unreferenced after use. |
Bert Vermeulen | cbadb85 | 2013-01-26 01:18:19 +0100 | [diff] [blame] | 399 | * |
Matthias Heidbrink | 67eb6bc | 2014-02-05 14:46:10 +0100 | [diff] [blame] | 400 | * @retval SR_OK Success. |
| 401 | * @retval SR_ERR Error. |
| 402 | * @retval SR_ERR_ARG The driver doesn't know that key, but this is not to be |
| 403 | * interpreted as an error by the caller; merely as an indication |
| 404 | * that it's not applicable. |
Uwe Hermann | 4711724 | 2014-05-04 20:51:05 +0200 | [diff] [blame] | 405 | * |
| 406 | * @since 0.3.0 |
Bert Vermeulen | cbadb85 | 2013-01-26 01:18:19 +0100 | [diff] [blame] | 407 | */ |
Martin Ling | 8f996b8 | 2013-04-20 01:00:49 +0100 | [diff] [blame] | 408 | SR_API int sr_config_set(const struct sr_dev_inst *sdi, |
Uwe Hermann | 53b4680 | 2014-03-20 21:58:01 +0100 | [diff] [blame] | 409 | const struct sr_channel_group *cg, |
Bert Vermeulen | 584560f | 2014-09-16 17:49:20 +0200 | [diff] [blame] | 410 | uint32_t key, GVariant *data) |
Bert Vermeulen | cbadb85 | 2013-01-26 01:18:19 +0100 | [diff] [blame] | 411 | { |
| 412 | int ret; |
| 413 | |
Bert Vermeulen | bc1c2f0 | 2013-03-25 15:38:44 +0100 | [diff] [blame] | 414 | g_variant_ref_sink(data); |
Bert Vermeulen | cbadb85 | 2013-01-26 01:18:19 +0100 | [diff] [blame] | 415 | |
Bert Vermeulen | bc1c2f0 | 2013-03-25 15:38:44 +0100 | [diff] [blame] | 416 | if (!sdi || !sdi->driver || !data) |
| 417 | ret = SR_ERR; |
| 418 | else if (!sdi->driver->config_set) |
| 419 | ret = SR_ERR_ARG; |
Martin Ling | 13fef1e | 2014-09-14 04:47:12 +0100 | [diff] [blame] | 420 | else if ((ret = sr_variant_type_check(key, data)) == SR_OK) |
Uwe Hermann | 53b4680 | 2014-03-20 21:58:01 +0100 | [diff] [blame] | 421 | ret = sdi->driver->config_set(key, data, sdi, cg); |
Bert Vermeulen | cbadb85 | 2013-01-26 01:18:19 +0100 | [diff] [blame] | 422 | |
Bert Vermeulen | bc1c2f0 | 2013-03-25 15:38:44 +0100 | [diff] [blame] | 423 | g_variant_unref(data); |
Bert Vermeulen | cbadb85 | 2013-01-26 01:18:19 +0100 | [diff] [blame] | 424 | |
| 425 | return ret; |
| 426 | } |
| 427 | |
| 428 | /** |
Daniel Elstner | 2a854d7 | 2014-01-19 20:39:11 +0100 | [diff] [blame] | 429 | * Apply configuration settings to the device hardware. |
| 430 | * |
| 431 | * @param sdi The device instance. |
| 432 | * |
| 433 | * @return SR_OK upon success or SR_ERR in case of error. |
Uwe Hermann | 4711724 | 2014-05-04 20:51:05 +0200 | [diff] [blame] | 434 | * |
| 435 | * @since 0.3.0 |
Daniel Elstner | 2a854d7 | 2014-01-19 20:39:11 +0100 | [diff] [blame] | 436 | */ |
| 437 | SR_API int sr_config_commit(const struct sr_dev_inst *sdi) |
| 438 | { |
| 439 | int ret; |
| 440 | |
| 441 | if (!sdi || !sdi->driver) |
| 442 | ret = SR_ERR; |
| 443 | else if (!sdi->driver->config_commit) |
| 444 | ret = SR_OK; |
| 445 | else |
| 446 | ret = sdi->driver->config_commit(sdi); |
| 447 | |
| 448 | return ret; |
| 449 | } |
| 450 | |
| 451 | /** |
Bert Vermeulen | cbadb85 | 2013-01-26 01:18:19 +0100 | [diff] [blame] | 452 | * List all possible values for a configuration key. |
| 453 | * |
Matthias Heidbrink | 67eb6bc | 2014-02-05 14:46:10 +0100 | [diff] [blame] | 454 | * @param[in] driver The sr_dev_driver struct to query. |
| 455 | * @param[in] sdi (optional) If the key is specific to a device, this must |
Bert Vermeulen | 57ecdbd | 2013-04-28 22:11:05 +0200 | [diff] [blame] | 456 | * contain a pointer to the struct sr_dev_inst to be checked. |
Uwe Hermann | 53b4680 | 2014-03-20 21:58:01 +0100 | [diff] [blame] | 457 | * @param[in] cg The channel group on the device for which to list the |
Bert Vermeulen | 57ecdbd | 2013-04-28 22:11:05 +0200 | [diff] [blame] | 458 | * values, or NULL. |
Matthias Heidbrink | 67eb6bc | 2014-02-05 14:46:10 +0100 | [diff] [blame] | 459 | * @param[in] key The configuration key (SR_CONF_*). |
| 460 | * @param[in,out] data A pointer to a GVariant where the list will be stored. |
| 461 | * The caller is given ownership of the GVariant and must thus |
Bert Vermeulen | bc1c2f0 | 2013-03-25 15:38:44 +0100 | [diff] [blame] | 462 | * unref the GVariant after use. However if this function |
| 463 | * returns an error code, the field should be considered |
| 464 | * unused, and should not be unreferenced. |
Bert Vermeulen | cbadb85 | 2013-01-26 01:18:19 +0100 | [diff] [blame] | 465 | * |
Matthias Heidbrink | 67eb6bc | 2014-02-05 14:46:10 +0100 | [diff] [blame] | 466 | * @retval SR_OK Success. |
| 467 | * @retval SR_ERR Error. |
| 468 | * @retval SR_ERR_ARG The driver doesn't know that key, but this is not to be |
| 469 | * interpreted as an error by the caller; merely as an indication |
| 470 | * that it's not applicable. |
Uwe Hermann | 4711724 | 2014-05-04 20:51:05 +0200 | [diff] [blame] | 471 | * |
| 472 | * @since 0.3.0 |
Bert Vermeulen | cbadb85 | 2013-01-26 01:18:19 +0100 | [diff] [blame] | 473 | */ |
Martin Ling | 8f996b8 | 2013-04-20 01:00:49 +0100 | [diff] [blame] | 474 | SR_API int sr_config_list(const struct sr_dev_driver *driver, |
| 475 | const struct sr_dev_inst *sdi, |
Uwe Hermann | 53b4680 | 2014-03-20 21:58:01 +0100 | [diff] [blame] | 476 | const struct sr_channel_group *cg, |
Bert Vermeulen | 584560f | 2014-09-16 17:49:20 +0200 | [diff] [blame] | 477 | uint32_t key, GVariant **data) |
Bert Vermeulen | cbadb85 | 2013-01-26 01:18:19 +0100 | [diff] [blame] | 478 | { |
| 479 | int ret; |
| 480 | |
Bert Vermeulen | 6cefe51 | 2013-04-07 21:50:42 +0200 | [diff] [blame] | 481 | if (!driver || !data) |
Bert Vermeulen | bc1c2f0 | 2013-03-25 15:38:44 +0100 | [diff] [blame] | 482 | ret = SR_ERR; |
Bert Vermeulen | d828480 | 2013-04-07 22:51:45 +0200 | [diff] [blame] | 483 | else if (!driver->config_list) |
Bert Vermeulen | 6cefe51 | 2013-04-07 21:50:42 +0200 | [diff] [blame] | 484 | ret = SR_ERR_ARG; |
Uwe Hermann | 53b4680 | 2014-03-20 21:58:01 +0100 | [diff] [blame] | 485 | else if ((ret = driver->config_list(key, data, sdi, cg)) == SR_OK) |
Bert Vermeulen | bc1c2f0 | 2013-03-25 15:38:44 +0100 | [diff] [blame] | 486 | g_variant_ref_sink(*data); |
Bert Vermeulen | cbadb85 | 2013-01-26 01:18:19 +0100 | [diff] [blame] | 487 | |
| 488 | return ret; |
| 489 | } |
| 490 | |
| 491 | /** |
Matthias Heidbrink | 67eb6bc | 2014-02-05 14:46:10 +0100 | [diff] [blame] | 492 | * Get information about a configuration key, by key. |
Bert Vermeulen | cbadb85 | 2013-01-26 01:18:19 +0100 | [diff] [blame] | 493 | * |
Matthias Heidbrink | 67eb6bc | 2014-02-05 14:46:10 +0100 | [diff] [blame] | 494 | * @param[in] key The configuration key. |
Bert Vermeulen | 8bfdc8c | 2012-07-12 20:54:45 +0200 | [diff] [blame] | 495 | * |
Bert Vermeulen | c89c1c9 | 2013-01-21 21:58:19 +0100 | [diff] [blame] | 496 | * @return A pointer to a struct sr_config_info, or NULL if the key |
Bert Vermeulen | 15cb43d | 2012-08-05 03:18:07 +0200 | [diff] [blame] | 497 | * was not found. |
Uwe Hermann | 4711724 | 2014-05-04 20:51:05 +0200 | [diff] [blame] | 498 | * |
| 499 | * @since 0.2.0 |
Bert Vermeulen | 8bfdc8c | 2012-07-12 20:54:45 +0200 | [diff] [blame] | 500 | */ |
Bert Vermeulen | 584560f | 2014-09-16 17:49:20 +0200 | [diff] [blame] | 501 | SR_API const struct sr_config_info *sr_config_info_get(uint32_t key) |
Bert Vermeulen | 8bfdc8c | 2012-07-12 20:54:45 +0200 | [diff] [blame] | 502 | { |
| 503 | int i; |
| 504 | |
Bert Vermeulen | c89c1c9 | 2013-01-21 21:58:19 +0100 | [diff] [blame] | 505 | for (i = 0; sr_config_info_data[i].key; i++) { |
| 506 | if (sr_config_info_data[i].key == key) |
| 507 | return &sr_config_info_data[i]; |
Bert Vermeulen | 15cb43d | 2012-08-05 03:18:07 +0200 | [diff] [blame] | 508 | } |
| 509 | |
| 510 | return NULL; |
| 511 | } |
| 512 | |
| 513 | /** |
Matthias Heidbrink | 67eb6bc | 2014-02-05 14:46:10 +0100 | [diff] [blame] | 514 | * Get information about a configuration key, by name. |
Bert Vermeulen | 15cb43d | 2012-08-05 03:18:07 +0200 | [diff] [blame] | 515 | * |
Matthias Heidbrink | 67eb6bc | 2014-02-05 14:46:10 +0100 | [diff] [blame] | 516 | * @param[in] optname The configuration key. |
Bert Vermeulen | 15cb43d | 2012-08-05 03:18:07 +0200 | [diff] [blame] | 517 | * |
Bert Vermeulen | c89c1c9 | 2013-01-21 21:58:19 +0100 | [diff] [blame] | 518 | * @return A pointer to a struct sr_config_info, or NULL if the key |
Bert Vermeulen | 15cb43d | 2012-08-05 03:18:07 +0200 | [diff] [blame] | 519 | * was not found. |
Uwe Hermann | 4711724 | 2014-05-04 20:51:05 +0200 | [diff] [blame] | 520 | * |
| 521 | * @since 0.2.0 |
Bert Vermeulen | 15cb43d | 2012-08-05 03:18:07 +0200 | [diff] [blame] | 522 | */ |
Bert Vermeulen | c89c1c9 | 2013-01-21 21:58:19 +0100 | [diff] [blame] | 523 | SR_API const struct sr_config_info *sr_config_info_name_get(const char *optname) |
Bert Vermeulen | 15cb43d | 2012-08-05 03:18:07 +0200 | [diff] [blame] | 524 | { |
| 525 | int i; |
| 526 | |
Bert Vermeulen | c89c1c9 | 2013-01-21 21:58:19 +0100 | [diff] [blame] | 527 | for (i = 0; sr_config_info_data[i].key; i++) { |
| 528 | if (!strcmp(sr_config_info_data[i].id, optname)) |
| 529 | return &sr_config_info_data[i]; |
Uwe Hermann | a1bb33a | 2010-04-02 20:18:27 +0200 | [diff] [blame] | 530 | } |
| 531 | |
Uwe Hermann | 49d0ce5 | 2010-05-19 00:38:14 +0200 | [diff] [blame] | 532 | return NULL; |
Uwe Hermann | a1bb33a | 2010-04-02 20:18:27 +0200 | [diff] [blame] | 533 | } |
| 534 | |
Uwe Hermann | 7b870c3 | 2012-10-21 16:13:36 +0200 | [diff] [blame] | 535 | /** @} */ |