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:
Peter Stuge 2012-10-21 20:23:36 +02:00
parent b8072700c1
commit 785b9ff290
2 changed files with 15 additions and 0 deletions

View File

@ -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;

View File

@ -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