blob: 28aba75348f891f678ae5fa8b5ea1b581d9daee8 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
|
#include "internals.h"
#ifndef LIBTIO_DISABLED_LIBUSB
TIO_HOOK(void) tio_libusb_close(tio_libusb_cookie_t *cookie)
{
libusb_exit(cookie->context);
}
TIO_LOCAL_DATA(tio_system_functions_t const) libusb_functions = {
(tio_close_t *)&tio_libusb_close,
(tio_open_usb_stream_t *)&tio_libusb_open,
(tio_list_usb_devices_t *)&tio_libusb_list_devices
};
TIO_EXTERN(int) tio_open_libusb_system(tio_system_t **systemp)
{
libusb_context *ctx;
tio_libusb_cookie_t *cookie;
int lerr, err;
/* Open a libusb context and create the cookie. */
if ((lerr = libusb_init(&ctx))) {
msg((ll_fatal, "libusb_init failed with error %s: %s.",
libusb_error_name(lerr), libusb_strerror(lerr)));
return (tio_error_unknown);
}
if (!(cookie = tio_alloc(1, sizeof(tio_libusb_cookie_t)))) {
libusb_exit(ctx);
return (tio_error_alloc);
}
cookie->context = ctx;
/* Open the system. */
return (tio_open_system(systemp, cookie, TIO_OPENFLAG_SYSTEM_ALL,
&libusb_functions));
}
#endif
|