]> sigrok.org Git - libsigrok.git/blob - src/drivers.c
d2763414acb8ae79f389ca519989f3d1332a62da
[libsigrok.git] / src / drivers.c
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 <config.h>
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
30  * and end of the section.  They are used to iterate over the list of all
31  * drivers.
32  */
33 #ifdef __APPLE__
34 extern struct sr_dev_driver *__start_sr_driver_list __asm("section$start$__DATA$__sr_driver_list");
35 extern struct sr_dev_driver *__stop_sr_driver_list __asm("section$end$__DATA$__sr_driver_list");
36 #else
37 extern struct sr_dev_driver *__start_sr_driver_list;
38 extern 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  */
46 SR_API void sr_drivers_init(struct sr_context *ctx)
47 {
48         GArray *array;
49
50         array = g_array_new(TRUE, FALSE, sizeof(struct sr_dev_driver *));
51 #ifdef HAVE_DRIVERS
52         for (struct sr_dev_driver **drivers = &__start_sr_driver_list;
53              drivers < &__stop_sr_driver_list; drivers++)
54                 g_array_append_val(array, *drivers);
55 #endif
56         ctx->driver_list = (struct sr_dev_driver **)array->data;
57         g_array_free(array, FALSE);
58 }