]> sigrok.org Git - libsigrok.git/blame - src/drivers.c
group all drivers into a single object
[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
21#include <glib.h>
22#include <libsigrok/libsigrok.h>
23#include "libsigrok-internal.h"
24
25/*
26 * sr_driver_list is a special section contains pointers to all the hardware
27 * drivers built into the library. The __start and __stop symbols are
28 * auto-generated by the linker (OSX needs a little help) and point to the start
29 * and end of the section. They are used to iterate over the list of all
30 * drivers.
31 */
32#ifdef __APPLE__
33extern struct sr_dev_driver *__start_sr_driver_list __asm("section$start$__DATA$__sr_driver_list");
34extern struct sr_dev_driver *__stop_sr_driver_list __asm("section$end$__DATA$__sr_driver_list");
35#else
36extern struct sr_dev_driver *__start_sr_driver_list;
37extern struct sr_dev_driver *__stop_sr_driver_list;
38#endif
39
40/** @private
41 * Initialize the driver list in a fresh libsigrok context.
42 *
43 * @param ctx Pointer to a libsigrok context struct. Must not be NULL.
44 */
45SR_PRIV void sr_drivers_init(struct sr_context *ctx)
46{
47 struct sr_dev_driver **drivers;
48 GArray *array;
49
50 array = g_array_new(TRUE, FALSE, sizeof(struct sr_dev_driver *));
51 for (drivers = &__start_sr_driver_list; drivers < &__stop_sr_driver_list;
52 drivers++)
53 g_array_append_val(array, *drivers);
54 ctx->driver_list = (struct sr_dev_driver **)array->data;
55 g_array_free(array, FALSE);
56}