From: Peter Stuge Date: Sun, 21 Oct 2012 18:23:36 +0000 (+0200) Subject: Add and init libusb_context * in struct sr_context when using libusb-1.0 X-Git-Tag: dsupstream~652 X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=785b9ff290cbdb86e7d0b0280c33b43faf9c0518;p=libsigrok.git Add and init libusb_context * in struct sr_context when using libusb-1.0 This allows hardware drivers to use a common libusb_context. --- diff --git a/backend.c b/backend.c index c94483f9..dd38f66e 100644 --- a/backend.c +++ b/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; diff --git a/libsigrok-internal.h b/libsigrok-internal.h index 640ab0be..56360572 100644 --- a/libsigrok-internal.h +++ b/libsigrok-internal.h @@ -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