]> sigrok.org Git - libsigrok.git/blobdiff - backend.c
Add and init libusb_context * in struct sr_context when using libusb-1.0
[libsigrok.git] / backend.c
index c94483f96be3d3e0ddfda4f17a28d3ae7d0a6e9b..dd38f66e287a4fb5c53332ac84aacb7a0f672922 100644 (file)
--- 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;