usrp: Cleanup of usrp_basic
[debian/gnuradio] / usrp / host / lib / usrp_prims_libusb1.cc
index 4e30047973facbeece17ce80e1fab643a5b56c32..5dfe416e148231a3770781180b9f635fa823fd9c 100644 (file)
@@ -42,6 +42,8 @@ extern "C" {
 
 using namespace ad9862;
 
+static const int LIBUSB1_DEBUG = 0;
+
 /*
  * libusb 0.12 / 1.0 compatibility
  */
@@ -57,7 +59,7 @@ _get_usb_error_str (int usb_err)
   case LIBUSB_ERROR_INVALID_PARAM:
     return "Invalid parameter";
   case LIBUSB_ERROR_ACCESS:
-    return "Access denied (insufficient permissions";
+    return "Access denied (insufficient permissions)";
   case LIBUSB_ERROR_NO_DEVICE:
     return "No such device (it may have been disconnected)";
   case LIBUSB_ERROR_NOT_FOUND:
@@ -133,6 +135,7 @@ _usb_control_transfer (struct libusb_device_handle *udh, int request_type,
   return ret;
 }
 
+
 // ----------------------------------------------------------------
 
 
@@ -144,9 +147,21 @@ usrp_one_time_init (libusb_context **ctx)
   if ((ret = libusb_init (ctx)) < 0)
     fprintf (stderr, "usrp: libusb_init failed: %s\n", _get_usb_error_str(ret));
 
-  // Set debug verbosity to max. This will only work if the debug option is
-  // compiled into libusb. Otherwise this call does nothing.
-  libusb_set_debug(*ctx, 3);
+  // Enable debug verbosity if requested. This will only work if the debug
+  // option is compiled into libusb and may produce a generous amount of output
+  // on stdout. If debug output is not compiled into libusb, this call does
+  // nothing. 
+  if (LIBUSB1_DEBUG)
+    libusb_set_debug(*ctx, 3);
+}
+
+void
+usrp_deinit (struct libusb_context *ctx)
+{
+  // Each object _should_ be running in its own context. If running in default
+  // context then leave the instance open as it may be shared.
+  if (ctx != NULL)
+    libusb_exit (ctx);
 }
 
 void
@@ -155,7 +170,6 @@ usrp_rescan ()
   // nop
 }
 
-
 struct libusb_device *
 usrp_find_device (int nth, bool fx2_ok_p, libusb_context *ctx)
 {