]> sigrok.org Git - libsigrok.git/blame - src/drivers.c
z60_libsigrok.rules: Add Brymen BU-86X adapter IDs.
[libsigrok.git] / src / drivers.c
CommitLineData
5d8b3913
AJ
1/*
2 * This file is part of the libsigrok project.
3 *
4 * Copyright (C) 2016 Lars-Peter Clausen <lars@metafoo.de>
5 * Copyright (C) 2016 Aurelien Jacobs <aurel@gnuage.org>
6 *
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19 */
20
bf85ea21 21#include <config.h>
5d8b3913
AJ
22#include <glib.h>
23#include <libsigrok/libsigrok.h>
24#include "libsigrok-internal.h"
25
26/*
27 * sr_driver_list is a special section contains pointers to all the hardware
28 * drivers built into the library. The __start and __stop symbols are
29 * auto-generated by the linker (OSX needs a little help) and point to the start
d9251a2c 30 * and end of the section. They are used to iterate over the list of all
5d8b3913
AJ
31 * drivers.
32 */
33#ifdef __APPLE__
34extern struct sr_dev_driver *__start_sr_driver_list __asm("section$start$__DATA$__sr_driver_list");
35extern struct sr_dev_driver *__stop_sr_driver_list __asm("section$end$__DATA$__sr_driver_list");
36#else
37extern struct sr_dev_driver *__start_sr_driver_list;
38extern struct sr_dev_driver *__stop_sr_driver_list;
39#endif
40
41/** @private
42 * Initialize the driver list in a fresh libsigrok context.
43 *
44 * @param ctx Pointer to a libsigrok context struct. Must not be NULL.
45 */
ced48274 46SR_API void sr_drivers_init(struct sr_context *ctx)
5d8b3913 47{
5d8b3913
AJ
48 GArray *array;
49
50 array = g_array_new(TRUE, FALSE, sizeof(struct sr_dev_driver *));
bf85ea21
AJ
51#ifdef HAVE_DRIVERS
52 for (struct sr_dev_driver **drivers = &__start_sr_driver_list;
53 drivers < &__stop_sr_driver_list; drivers++)
5d8b3913 54 g_array_append_val(array, *drivers);
bf85ea21 55#endif
5d8b3913
AJ
56 ctx->driver_list = (struct sr_dev_driver **)array->data;
57 g_array_free(array, FALSE);
58}