Add and init libusb_context * in struct sr_context when using libusb-1.0
This allows hardware drivers to use a common libusb_context.
This commit is contained in:
parent
b8072700c1
commit
785b9ff290
12
backend.c
12
backend.c
|
@ -40,6 +40,14 @@ SR_API int sr_init(struct sr_context **ctx)
|
|||
goto done;
|
||||
}
|
||||
|
||||
#ifdef HAVE_LIBUSB_1_0
|
||||
ret = libusb_init(&context->libusb_ctx);
|
||||
if (LIBUSB_SUCCESS != ret) {
|
||||
sr_err("libusb_init() returned %s\n", libusb_error_name(ret));
|
||||
goto done;
|
||||
}
|
||||
#endif
|
||||
|
||||
*ctx = context;
|
||||
ret = SR_OK;
|
||||
|
||||
|
@ -56,6 +64,10 @@ SR_API int sr_exit(struct sr_context *ctx)
|
|||
{
|
||||
sr_hw_cleanup_all();
|
||||
|
||||
#ifdef HAVE_LIBUSB_1_0
|
||||
libusb_exit(ctx->libusb_ctx);
|
||||
#endif
|
||||
|
||||
g_free(ctx);
|
||||
|
||||
return SR_OK;
|
||||
|
|
|
@ -46,6 +46,9 @@
|
|||
#define DATASTORE_CHUNKSIZE (512 * 1024)
|
||||
|
||||
struct sr_context {
|
||||
#ifdef HAVE_LIBUSB_1_0
|
||||
libusb_context *libusb_ctx;
|
||||
#endif
|
||||
};
|
||||
|
||||
#ifdef HAVE_LIBUSB_1_0
|
||||
|
|
Loading…
Reference in New Issue