OSX 10.6 x86_64 fixes for configure and libusb; Audio is next
authorMichael <mlk@alum.mit.edu>
Thu, 15 Oct 2009 13:43:20 +0000 (09:43 -0400)
committerMichael <mlk@alum.mit.edu>
Thu, 15 Oct 2009 13:43:20 +0000 (09:43 -0400)
config/gr_set_md_cpu.m4
gr-audio-osx/src/circular_buffer.h
usrp/host/lib/circular_buffer.h
usrp/host/lib/darwin_libusb.h
usrp/host/lib/fusb_darwin.cc
usrp/host/lib/fusb_darwin.h

index d8714c4a71861a87466ccee3c01e478295aaaf34..bb2862deeaad15b02b1fd0fb5bfc3e813e4a43c2 100644 (file)
@@ -50,8 +50,19 @@ AC_DEFUN([GR_SET_MD_CPU],[
   AC_ARG_WITH(md-cpu,
        AC_HELP_STRING([--with-md-cpu=ARCH],[set machine dependent speedups (auto)]),
                [cf_with_md_cpu="$withval"],
-               [cf_with_md_cpu="$host_cpu"])
-
+               [
+    dnl temporary fix for Darwin 10.6; $host_cpu is always "i386" no matter
+    dnl if the kernel is in 32-bit or 64-bit mode.
+    case "$host_os" in
+      darwin*)
+        cf_with_md_cpu=`uname -m`
+        ;;
+      *)
+        cf_with_md_cpu="$host_cpu"
+        ;;
+    esac
+  ])
+  AC_MSG_RESULT($cf_with_md_cpu)
   case "$cf_with_md_cpu" in
    x86 | i[[3-7]]86)   MD_CPU=x86      MD_SUBCPU=x86 ;;
    x86_64)             MD_CPU=x86      MD_SUBCPU=x86_64 ;;
index fa451d607b728e2c64a92ef067720b1551351d39..996b1b74bc10dd2a82af4f7738e02462b00b68b9 100644 (file)
@@ -26,7 +26,9 @@
 #include "mld_threads.h"
 #include <stdexcept>
 
+#ifndef DO_DEBUG
 #define DO_DEBUG 0
+#endif
 
 #if DO_DEBUG
 #define DEBUG(X) do{X} while(0);
@@ -41,8 +43,8 @@ private:
   T* d_buffer;
 
 // the following are in Items (type T)
-  UInt32 d_bufLen_I, d_readNdx_I, d_writeNdx_I;
-  UInt32 d_n_avail_write_I, d_n_avail_read_I;
+  size_t d_bufLen_I, d_readNdx_I, d_writeNdx_I;
+  size_t d_n_avail_write_I, d_n_avail_read_I;
 
 // stuff to control access to class internals
   mld_mutex_ptr d_internal;
@@ -67,7 +69,7 @@ private:
   };
 
 public:
-  circular_buffer (UInt32 bufLen_I,
+  circular_buffer (size_t bufLen_I,
                   bool doWriteBlock = true, bool doFullRead = false) {
     if (bufLen_I == 0)
       throw std::runtime_error ("circular_buffer(): "
@@ -82,7 +84,7 @@ public:
     DEBUG (fprintf (stderr, "c_b(): buf len (items) = %ld, "
                    "doWriteBlock = %s, doFullRead = %s\n", d_bufLen_I,
                    (d_doWriteBlock ? "true" : "false"),
-                   (d_doFullRead ? "true" : "false")));
+                   (d_doFullRead ? "true" : "false")););
   };
 
   ~circular_buffer () {
@@ -90,21 +92,21 @@ public:
     delete [] d_buffer;
   };
 
-  inline UInt32 n_avail_write_items () {
+  inline size_t n_avail_write_items () {
     d_internal->lock ();
-    UInt32 retVal = d_n_avail_write_I;
+    size_t retVal = d_n_avail_write_I;
     d_internal->unlock ();
     return (retVal);
   };
 
-  inline UInt32 n_avail_read_items () {
+  inline size_t n_avail_read_items () {
     d_internal->lock ();
-    UInt32 retVal = d_n_avail_read_I;
+    size_t retVal = d_n_avail_read_I;
     d_internal->unlock ();
     return (retVal);
   };
 
-  inline UInt32 buffer_length_items () {return (d_bufLen_I);};
+  inline size_t buffer_length_items () {return (d_bufLen_I);};
   inline bool do_write_block () {return (d_doWriteBlock);};
   inline bool do_full_read () {return (d_doFullRead);};
 
@@ -147,10 +149,10 @@ public:
  *     buffer length is larger than the instantiated buffer length
  */
 
-  int enqueue (T* buf, UInt32 bufLen_I) {
+  int enqueue (T* buf, size_t bufLen_I) {
     DEBUG (fprintf (stderr, "enqueue: buf = %X, bufLen = %ld, #av_wr = %ld, "
                    "#av_rd = %ld.\n", (unsigned int)buf, bufLen_I,
-                   d_n_avail_write_I, d_n_avail_read_I));
+                   d_n_avail_write_I, d_n_avail_read_I););
     if (bufLen_I > d_bufLen_I) {
       fprintf (stderr, "cannot add buffer longer (%ld"
               ") than instantiated length (%ld"
@@ -173,25 +175,25 @@ public:
     if (bufLen_I > d_n_avail_write_I) {
       if (d_doWriteBlock) {
        while (bufLen_I > d_n_avail_write_I) {
-         DEBUG (fprintf (stderr, "enqueue: #len > #a, waiting.\n"));
+         DEBUG (fprintf (stderr, "enqueue: #len > #a, waiting.\n"););
          // wait will automatically unlock() the internal mutex
          d_writeBlock->wait ();
          // and lock() it here.
          if (d_doAbort) {
            d_internal->unlock ();
-           DEBUG (fprintf (stderr, "enqueue: #len > #a, aborting.\n"));
+           DEBUG (fprintf (stderr, "enqueue: #len > #a, aborting.\n"););
            return (2);
          }
-         DEBUG (fprintf (stderr, "enqueue: #len > #a, done waiting.\n"));
+         DEBUG (fprintf (stderr, "enqueue: #len > #a, done waiting.\n"););
        }
       } else {
        d_n_avail_read_I = d_bufLen_I - bufLen_I;
        d_n_avail_write_I = bufLen_I;
-       DEBUG (fprintf (stderr, "circular_buffer::enqueue: overflow\n"));
+       DEBUG (fprintf (stderr, "circular_buffer::enqueue: overflow\n"););
        retval = -1;
       }
     }
-    UInt32 n_now_I = d_bufLen_I - d_writeNdx_I, n_start_I = 0;
+    size_t n_now_I = d_bufLen_I - d_writeNdx_I, n_start_I = 0;
     if (n_now_I > bufLen_I)
       n_now_I = bufLen_I;
     else if (n_now_I < bufLen_I)
@@ -230,17 +232,17 @@ public:
  *     buffer length is larger than the instantiated buffer length
  */
 
-  int dequeue (T* buf, UInt32* bufLen_I) {
+  int dequeue (T* buf, size_t* bufLen_I) {
     DEBUG (fprintf (stderr, "dequeue: buf = %X, *bufLen = %ld, #av_wr = %ld, "
                    "#av_rd = %ld.\n", (unsigned int)buf, *bufLen_I,
-                   d_n_avail_write_I, d_n_avail_read_I));
+                   d_n_avail_write_I, d_n_avail_read_I););
     if (!bufLen_I)
       throw std::runtime_error ("circular_buffer::dequeue(): "
                                "input bufLen pointer is NULL.\n");
     if (!buf)
       throw std::runtime_error ("circular_buffer::dequeue(): "
                                "input buffer pointer is NULL.\n");
-    UInt32 l_bufLen_I = *bufLen_I;
+    size_t l_bufLen_I = *bufLen_I;
     if (l_bufLen_I == 0)
       return (0);
     if (l_bufLen_I > d_bufLen_I) {
@@ -257,34 +259,34 @@ public:
     }
     if (d_doFullRead) {
       while (d_n_avail_read_I < l_bufLen_I) {
-       DEBUG (fprintf (stderr, "dequeue: #a < #len, waiting.\n"));
+       DEBUG (fprintf (stderr, "dequeue: #a < #len, waiting.\n"););
        // wait will automatically unlock() the internal mutex
        d_readBlock->wait ();
        // and lock() it here.
        if (d_doAbort) {
          d_internal->unlock ();
-         DEBUG (fprintf (stderr, "dequeue: #a < #len, aborting.\n"));
+         DEBUG (fprintf (stderr, "dequeue: #a < #len, aborting.\n"););
          return (2);
        }
-       DEBUG (fprintf (stderr, "dequeue: #a < #len, done waiting.\n"));
+       DEBUG (fprintf (stderr, "dequeue: #a < #len, done waiting.\n"););
      }
     } else {
       while (d_n_avail_read_I == 0) {
-       DEBUG (fprintf (stderr, "dequeue: #a == 0, waiting.\n"));
+       DEBUG (fprintf (stderr, "dequeue: #a == 0, waiting.\n"););
        // wait will automatically unlock() the internal mutex
        d_readBlock->wait ();
        // and lock() it here.
        if (d_doAbort) {
          d_internal->unlock ();
-         DEBUG (fprintf (stderr, "dequeue: #a == 0, aborting.\n"));
+         DEBUG (fprintf (stderr, "dequeue: #a == 0, aborting.\n"););
          return (2);
        }
-       DEBUG (fprintf (stderr, "dequeue: #a == 0, done waiting.\n"));
+       DEBUG (fprintf (stderr, "dequeue: #a == 0, done waiting.\n"););
       }
     }
     if (l_bufLen_I > d_n_avail_read_I)
       l_bufLen_I = d_n_avail_read_I;
-    UInt32 n_now_I = d_bufLen_I - d_readNdx_I, n_start_I = 0;
+    size_t n_now_I = d_bufLen_I - d_readNdx_I, n_start_I = 0;
     if (n_now_I > l_bufLen_I)
       n_now_I = l_bufLen_I;
     else if (n_now_I < l_bufLen_I)
index 8898e4194830c6b4243f4b7e9880fd1f89be723a..996b1b74bc10dd2a82af4f7738e02462b00b68b9 100644 (file)
@@ -43,8 +43,8 @@ private:
   T* d_buffer;
 
 // the following are in Items (type T)
-  UInt32 d_bufLen_I, d_readNdx_I, d_writeNdx_I;
-  UInt32 d_n_avail_write_I, d_n_avail_read_I;
+  size_t d_bufLen_I, d_readNdx_I, d_writeNdx_I;
+  size_t d_n_avail_write_I, d_n_avail_read_I;
 
 // stuff to control access to class internals
   mld_mutex_ptr d_internal;
@@ -69,7 +69,7 @@ private:
   };
 
 public:
-  circular_buffer (UInt32 bufLen_I,
+  circular_buffer (size_t bufLen_I,
                   bool doWriteBlock = true, bool doFullRead = false) {
     if (bufLen_I == 0)
       throw std::runtime_error ("circular_buffer(): "
@@ -92,21 +92,21 @@ public:
     delete [] d_buffer;
   };
 
-  inline UInt32 n_avail_write_items () {
+  inline size_t n_avail_write_items () {
     d_internal->lock ();
-    UInt32 retVal = d_n_avail_write_I;
+    size_t retVal = d_n_avail_write_I;
     d_internal->unlock ();
     return (retVal);
   };
 
-  inline UInt32 n_avail_read_items () {
+  inline size_t n_avail_read_items () {
     d_internal->lock ();
-    UInt32 retVal = d_n_avail_read_I;
+    size_t retVal = d_n_avail_read_I;
     d_internal->unlock ();
     return (retVal);
   };
 
-  inline UInt32 buffer_length_items () {return (d_bufLen_I);};
+  inline size_t buffer_length_items () {return (d_bufLen_I);};
   inline bool do_write_block () {return (d_doWriteBlock);};
   inline bool do_full_read () {return (d_doFullRead);};
 
@@ -149,7 +149,7 @@ public:
  *     buffer length is larger than the instantiated buffer length
  */
 
-  int enqueue (T* buf, UInt32 bufLen_I) {
+  int enqueue (T* buf, size_t bufLen_I) {
     DEBUG (fprintf (stderr, "enqueue: buf = %X, bufLen = %ld, #av_wr = %ld, "
                    "#av_rd = %ld.\n", (unsigned int)buf, bufLen_I,
                    d_n_avail_write_I, d_n_avail_read_I););
@@ -193,7 +193,7 @@ public:
        retval = -1;
       }
     }
-    UInt32 n_now_I = d_bufLen_I - d_writeNdx_I, n_start_I = 0;
+    size_t n_now_I = d_bufLen_I - d_writeNdx_I, n_start_I = 0;
     if (n_now_I > bufLen_I)
       n_now_I = bufLen_I;
     else if (n_now_I < bufLen_I)
@@ -232,7 +232,7 @@ public:
  *     buffer length is larger than the instantiated buffer length
  */
 
-  int dequeue (T* buf, UInt32* bufLen_I) {
+  int dequeue (T* buf, size_t* bufLen_I) {
     DEBUG (fprintf (stderr, "dequeue: buf = %X, *bufLen = %ld, #av_wr = %ld, "
                    "#av_rd = %ld.\n", (unsigned int)buf, *bufLen_I,
                    d_n_avail_write_I, d_n_avail_read_I););
@@ -242,7 +242,7 @@ public:
     if (!buf)
       throw std::runtime_error ("circular_buffer::dequeue(): "
                                "input buffer pointer is NULL.\n");
-    UInt32 l_bufLen_I = *bufLen_I;
+    size_t l_bufLen_I = *bufLen_I;
     if (l_bufLen_I == 0)
       return (0);
     if (l_bufLen_I > d_bufLen_I) {
@@ -286,7 +286,7 @@ public:
     }
     if (l_bufLen_I > d_n_avail_read_I)
       l_bufLen_I = d_n_avail_read_I;
-    UInt32 n_now_I = d_bufLen_I - d_readNdx_I, n_start_I = 0;
+    size_t n_now_I = d_bufLen_I - d_readNdx_I, n_start_I = 0;
     if (n_now_I > l_bufLen_I)
       n_now_I = l_bufLen_I;
     else if (n_now_I < l_bufLen_I)
index 063a2e9c645e55c36fd12f67eb1e8094a75e1b45..a9cd2055a4420a305eed8b1799a968e354e540f4 100644 (file)
@@ -1,6 +1,6 @@
 /* -*- c++ -*- */
 /*
- * Copyright 2006 Free Software Foundation, Inc.
+ * Copyright 2006,2009 Free Software Foundation, Inc.
  * 
  * This file is part of GNU Radio.
  *
 #include <IOKit/IOKitLib.h>
 
 extern "C" {
-static char *
+
+static const char* darwin_error_strings[] = {
+  "no error",
+  "device not opened for exclusive access",
+  "no connection to an IOService",
+  "no asyc port has been opened for interface",
+  "another process has device opened for exclusive access",
+  "pipe is stalled",
+  "could not establish a connection to Darin kernel",
+  "invalid argument",
+  "unknown error"
+};
+
+static const char *
 darwin_error_str (int result)
 {
   switch (result) {
   case kIOReturnSuccess:
-    return "no error";
+    return (darwin_error_strings[0]);
   case kIOReturnNotOpen:
-    return "device not opened for exclusive access";
+    return (darwin_error_strings[1]);
   case kIOReturnNoDevice:
-    return "no connection to an IOService";
+    return (darwin_error_strings[2]);
   case kIOUSBNoAsyncPortErr:
-    return "no asyc port has been opened for interface";
+    return (darwin_error_strings[3]);
   case kIOReturnExclusiveAccess:
-    return "another process has device opened for exclusive access";
+    return (darwin_error_strings[4]);
   case kIOUSBPipeStalled:
-    return "pipe is stalled";
+    return (darwin_error_strings[5]);
   case kIOReturnError:
-    return "could not establish a connection to Darin kernel";
+    return (darwin_error_strings[6]);
   case kIOReturnBadArgument:
-    return "invalid argument";
+    return (darwin_error_strings[7]);
   default:
-    return "unknown error";
+    return (darwin_error_strings[8]);
   }
 }
 
index 737387b877bc9cac8798ff8a659b856bba3e6123..91185de28fb35a50128011151ea78b5f7efdbba8 100644 (file)
@@ -33,6 +33,7 @@
 #include "fusb.h"
 #include "fusb_darwin.h"
 #include "darwin_libusb.h"
+#include <iostream>
 
 static const int USB_TIMEOUT = 100;    // in milliseconds
 static const UInt8 NUM_QUEUE_ITEMS = 20;
@@ -153,9 +154,10 @@ fusb_ephandle_darwin::start ()
     USB_ERROR_STR (false, -ENOENT, "fusb_ephandle_darwin::start: "
                   "device not initialized");
 
-  if (usb_debug)
-    fprintf (stderr, "fusb_ephandle_darwin::start: "
-            "dev = %p, device = %p\n", dev, device);
+  if (usb_debug) {
+    std::cerr << "fusb_ephandle_darwin::start: dev = " <<
+      (void*) dev << ", device = " << (void*) device << std::endl;
+  }
 
   d_interfaceRef = device->interface;
   if (! d_interfaceRef)
@@ -165,10 +167,10 @@ fusb_ephandle_darwin::start ()
 
 // get read or write pipe info (depends on "d_input_p")
 
-  if (usb_debug > 3)
-    fprintf (stderr, "fusb_ephandle_darwin::start "
-            "d_endpoint = %d, d_input_p = %s\n",
-            d_endpoint, d_input_p ? "TRUE" : "FALSE");
+  if (usb_debug > 3) {
+    std::cerr << "fusb_ephandle_darwin::start d_endpoint = " << d_endpoint
+             << ", d_input_p = " << (d_input_p ? "TRUE" : "FALSE") << std::endl;
+  }
 
   int l_endpoint = (d_input_p ? USB_ENDPOINT_IN : USB_ENDPOINT_OUT);
   int pipeRef = ep_to_pipeRef (device, d_endpoint | l_endpoint);
@@ -184,12 +186,14 @@ fusb_ephandle_darwin::start ()
                                  &d_transferType,
                                  &maxPacketSize,
                                  &interval);
-  if (usb_debug == 3)
-    fprintf (stderr, "fusb_ephandle_darwin::start: %s: ep = 0x%02x, "
-            "pipeRef = %d, d_i = %p, d_iR = %p, if_dir = %d, if_# = %d, "
-            "if_int = %d, if_maxPS = %d\n", d_input_p ? "read" : "write",
-            d_endpoint, d_pipeRef, d_interface, d_interfaceRef, direction,
-            number, interval, maxPacketSize);
+  if (usb_debug == 3) {
+    std::cerr << "fusb_ephandle_darwin::start: " << (d_input_p ? "read" : "write")
+             << ": ep = " << d_endpoint << ", pipeRef = " << d_pipeRef << "interface = "
+             << d_interface << ", interfaceRef = " << d_interfaceRef
+             << ", if_direction = " << direction << ", if_# = " << number
+             << ", if_interval = " << interval << ", if_maxPacketSize = "
+             << maxPacketSize << std::endl;
+  }
 
   // set global start boolean
   d_started = true;
@@ -205,9 +209,10 @@ fusb_ephandle_darwin::start ()
   // going; this will unlock the mutex before waiting for a signal ()
   d_runBlock->wait ();
 
-  if (usb_debug)
-    fprintf (stderr, "fusb_ephandle_darwin::start: %s started.\n",
-            d_input_p ? "read" : "write");
+  if (usb_debug) {
+    std::cerr << "fusb_ephandle_darwin::start: " << (d_input_p ? "read" : "write")
+             << " started." << std::endl;
+  }
 
   return (true);
 }
@@ -229,10 +234,10 @@ fusb_ephandle_darwin::run_thread (void* arg)
 
   bool l_input_p = This->d_input_p;
 
-  if (usb_debug)
-    fprintf (stderr, "fusb_ephandle_darwin::run_thread: "
-            "starting for %s.\n",
-            l_input_p ? "read" : "write");
+  if (usb_debug) {
+    std::cerr << "fusb_ephandle_darwin::run_thread: starting for "
+             << (l_input_p ? "read" : "write") << "." << std::endl;
+  }
 
   usb_interface_t** l_interfaceRef = This->d_interfaceRef;
   usb_interface_t* l_interface = This->d_interface;
@@ -286,9 +291,10 @@ fusb_ephandle_darwin::run_thread (void* arg)
   CFRunLoopRemoveSource (CFRunLoopGetCurrent (),
                         l_cfSource, kCFRunLoopDefaultMode);
 
-  if (usb_debug)
-    fprintf (stderr, "fusb_ephandle_darwin::run_thread: finished for %s.\n",
-            l_input_p ? "read" : "write");
+  if (usb_debug) {
+    std::cerr << "fusb_ephandle_darwin::run_thread: finished for "
+             << (l_input_p ? "read" : "write") << "." << std::endl;
+  }
 
   // release the run thread running mutex
   l_runThreadRunning->unlock ();
@@ -297,8 +303,9 @@ fusb_ephandle_darwin::run_thread (void* arg)
 void
 fusb_ephandle_darwin::read_thread (void* arg)
 {
-  if (usb_debug)
-    fprintf (stderr, "fusb_ephandle_darwin::read_thread: starting.\n");
+  if (usb_debug) {
+    std::cerr << "fusb_ephandle_darwin::read_thread: starting." << std::endl;
+  }
 
   fusb_ephandle_darwin* This = static_cast<fusb_ephandle_darwin*>(arg);
 
@@ -331,8 +338,9 @@ fusb_ephandle_darwin::read_thread (void* arg)
     l_node = l_queue->iterate_next ();
   }
 
-  if (usb_debug)
-    fprintf (stderr, "fusb_ephandle_darwin::read_thread: finished.\n");
+  if (usb_debug) {
+    std::cerr << "fusb_ephandle_darwin::read_thread: finished." << std::endl;
+  }
 
   // release the read running mutex, to let the parent thread knows
   // that this thread is finished
@@ -343,10 +351,11 @@ void
 fusb_ephandle_darwin::read_issue (s_both_ptr l_both)
 {
   if ((! l_both) || (! d_started)) {
-    if (usb_debug > 4)
-      fprintf (stderr, "fusb_ephandle_darwin::read_issue: Doing nothing; "
-              "l_both is %X; started is %s\n", (unsigned int) l_both,
-              d_started ? "TRUE" : "FALSE");
+    if (usb_debug > 4) {
+      std::cerr << "fusb_ephandle_darwin::read_issue: Doing nothing; "
+               << "l_both is " << (void*) l_both << "; started is "
+               << (d_started ? "TRUE" : "FALSE") << std::endl;
+    }
     return;
   }
 
@@ -356,7 +365,7 @@ fusb_ephandle_darwin::read_issue (s_both_ptr l_both)
   void* v_buffer = (void*) l_buf->buffer ();
 
 // read up to d_bufLenBytes
-  UInt32 bufLen = d_bufLenBytes;
+  size_t bufLen = d_bufLenBytes;
   l_buf->n_used (bufLen);
 
 // setup system call result
@@ -378,9 +387,10 @@ fusb_ephandle_darwin::read_issue (s_both_ptr l_both)
                          "(ReadPipeAsync%s): %s",
                          d_transferType == kUSBInterrupt ? "" : "TO",
                          darwin_error_str (result));
-  else if (usb_debug > 4)
-    fprintf (stderr, "fusb_ephandle_darwin::read_issue: "
-            "Queued %X (%ld Bytes)\n", (unsigned int) l_both, bufLen);
+  else if (usb_debug > 4) {
+    std::cerr << "fusb_ephandle_darwin::read_issue: Queued " << (void*) l_both
+             << " (" << bufLen << " Bytes)" << std::endl;
+  }
 }
 
 void
@@ -388,22 +398,21 @@ fusb_ephandle_darwin::read_completed (void* refCon,
                                      io_return_t result,
                                      void* io_size)
 {
-  UInt32 l_size = (UInt32) io_size;
+  size_t l_size = (size_t) io_size;
   s_both_ptr l_both = static_cast<s_both_ptr>(refCon);
   fusb_ephandle_darwin* This = static_cast<fusb_ephandle_darwin*>(l_both->This ());
   s_node_ptr l_node = l_both->node ();
   circular_buffer<char>* l_buffer = This->d_buffer;
   s_buffer_ptr l_buf = l_node->object ();
-  UInt32 l_i_size = l_buf->n_used ();
-
-  if (This->d_started && (l_i_size != l_size))
-    fprintf (stderr, "fusb_ephandle_darwin::read_completed: "
-            "Expected %ld bytes; read %ld.\n",
-            l_i_size, l_size);
-  else if (usb_debug > 4)
-    fprintf (stderr, "fusb_ephandle_darwin::read_completed: "
-            "Read %X (%ld bytes)\n",
-            (unsigned int) l_both, l_size);
+  size_t l_i_size = l_buf->n_used ();
+
+  if (This->d_started && (l_i_size != l_size)) {
+    std::cerr << "fusb_ephandle_darwin::read_completed: Expected " << l_i_size
+             << " bytes; read " << l_size << "." << std::endl;
+  } else if (usb_debug > 4) {
+    std::cerr << "fusb_ephandle_darwin::read_completed: Read " << (void*) l_both
+             << " (" << l_size << " bytes)" << std::endl;
+  }
 
 // add this read to the transfer buffer
   if (l_buffer->enqueue (l_buf->buffer (), l_size) == -1) {
@@ -421,11 +430,13 @@ fusb_ephandle_darwin::read_completed (void* refCon,
 int
 fusb_ephandle_darwin::read (void* buffer, int nbytes)
 {
-  UInt32 l_nbytes = (UInt32) nbytes;
+  size_t l_nbytes = (size_t) nbytes;
   d_buffer->dequeue ((char*) buffer, &l_nbytes);
 
-  if (usb_debug > 4)
-    fprintf (stderr, "fusb_ephandle_darwin::read: request for %d bytes, %ld bytes retrieved.\n", nbytes, l_nbytes);
+  if (usb_debug > 4) {
+    std::cerr << "fusb_ephandle_darwin::read: request for " << nbytes
+             << " bytes, " << l_nbytes << " bytes retrieved." << std::endl;
+  }
 
   return ((int) l_nbytes);
 }
@@ -433,18 +444,18 @@ fusb_ephandle_darwin::read (void* buffer, int nbytes)
 int
 fusb_ephandle_darwin::write (const void* buffer, int nbytes)
 {
-  UInt32 l_nbytes = (UInt32) nbytes;
+  size_t l_nbytes = (size_t) nbytes;
 
   if (! d_started) {
-    if (usb_debug)
-      fprintf (stderr, "fusb_ephandle_darwin::write: Not yet started.\n");
-
+    if (usb_debug) {
+      std::cerr << "fusb_ephandle_darwin::write: Not yet started." << std::endl;
+    }
     return (0);
   }
 
   while (l_nbytes != 0) {
 // find out how much data to copy; limited to "d_bufLenBytes" per node
-    UInt32 t_nbytes = (l_nbytes > d_bufLenBytes) ? d_bufLenBytes : l_nbytes;
+    size_t t_nbytes = (l_nbytes > d_bufLenBytes) ? d_bufLenBytes : l_nbytes;
 
 // get next available node to write into;
 // blocks internally if none available
@@ -476,8 +487,8 @@ fusb_ephandle_darwin::write (const void* buffer, int nbytes)
                     d_transferType == kUSBInterrupt ? "" : "TO",
                     darwin_error_str (result));
     else if (usb_debug > 4) {
-      fprintf (stderr, "fusb_ephandle_darwin::write_thread: "
-              "Queued %X (%ld Bytes)\n", (unsigned int) l_both, t_nbytes);
+      std::cerr << "fusb_ephandle_darwin::write_thread: Queued " << (void*) l_both
+               << " (" << t_nbytes << " Bytes)" << std::endl;
     }
     l_nbytes -= t_nbytes;
   }
@@ -492,19 +503,19 @@ fusb_ephandle_darwin::write_completed (void* refCon,
 {
   s_both_ptr l_both = static_cast<s_both_ptr>(refCon);
   fusb_ephandle_darwin* This = static_cast<fusb_ephandle_darwin*>(l_both->This ());
-  UInt32 l_size = (UInt32) io_size;
+  size_t l_size = (size_t) io_size;
   s_node_ptr l_node = l_both->node ();
   s_queue_ptr l_queue = This->d_queue;
   s_buffer_ptr l_buf = l_node->object ();
-  UInt32 l_i_size = l_buf->n_used ();
-
-  if (This->d_started && (l_i_size != l_size))
-    fprintf (stderr, "fusb_ephandle_darwin::write_completed: "
-            "Expected %ld bytes written; wrote %ld.\n",
-            l_i_size, l_size);
-  else if (usb_debug > 4)
-    fprintf (stderr, "fusb_ephandle_darwin::write_completed: "
-            "Wrote %X (%ld Bytes)\n", (unsigned int) l_both, l_size);
+  size_t l_i_size = l_buf->n_used ();
+
+  if (This->d_started && (l_i_size != l_size)) {
+    std::cerr << "fusb_ephandle_darwin::write_completed: Expected " << l_i_size
+             << " bytes written; wrote " << l_size << "." << std::endl;
+  } else if (usb_debug > 4) {
+    std::cerr << "fusb_ephandle_darwin::write_completed: Wrote " << (void*) l_both
+             << " (" << l_size << " Bytes)" << std::endl;
+  }
 
 // set buffer's # data to 0
   l_buf->n_used (0);
@@ -515,8 +526,9 @@ fusb_ephandle_darwin::write_completed (void* refCon,
 void
 fusb_ephandle_darwin::abort ()
 {
-  if (usb_debug)
-    fprintf (stderr, "fusb_ephandle_darwin::abort: starting.\n");
+  if (usb_debug) {
+    std::cerr << "fusb_ephandle_darwin::abort: starting." << std::endl;
+  }
 
   io_return_t result = d_interface->AbortPipe (d_interfaceRef, d_pipeRef);
 
@@ -524,8 +536,9 @@ fusb_ephandle_darwin::abort ()
     USB_ERROR_STR_NO_RET (- darwin_to_errno (result),
                          "fusb_ephandle_darwin::abort "
                          "(AbortPipe): %s", darwin_error_str (result));
-  if (usb_debug)
-    fprintf (stderr, "fusb_ephandle_darwin::abort: finished.\n");
+  if (usb_debug) {
+    std::cerr << "fusb_ephandle_darwin::abort: finished." << std::endl;
+  }
 }
 
 bool
@@ -534,9 +547,10 @@ fusb_ephandle_darwin::stop ()
   if (! d_started)
     return (true);
 
-  if (usb_debug)
-    fprintf (stderr, "fusb_ephandle_darwin::stop: stopping %s.\n",
-            d_input_p ? "read" : "write");
+  if (usb_debug) {
+    std::cerr << "fusb_ephandle_darwin::stop: stopping "
+             << (d_input_p ? "read" : "write") << "." << std::endl;
+  }
 
   d_started = false;
 
@@ -556,9 +570,10 @@ fusb_ephandle_darwin::stop ()
   d_runThreadRunning->lock ();
   d_runThreadRunning->unlock ();
 
-  if (usb_debug)
-    fprintf (stderr, "fusb_ephandle_darwin::stop: %s stopped.\n",
-            d_input_p ? "read" : "write");
+  if (usb_debug) {
+    std::cerr << "fusb_ephandle_darwin::stop: " << (d_input_p ? "read" : "write")
+             << " stopped." << std::endl;
+  }
 
   return (true);
 }
index bb717b58c5e785648298bebb3de16f0dfd879ebe..63016648bc3373916f334de425556f85d0002cd5 100644 (file)
@@ -75,10 +75,10 @@ class s_buffer
 {
 private:
   char* d_buffer;
-  UInt32 d_n_used, d_n_alloc;
+  size_t d_n_used, d_n_alloc;
 
 public:
-  inline s_buffer (UInt32 n_alloc = 0) {
+  inline s_buffer (size_t n_alloc = 0) {
     d_n_used = 0;
     d_n_alloc = n_alloc;
     if (n_alloc) {
@@ -92,11 +92,11 @@ public:
       delete [] d_buffer;
     }
   };
-  inline UInt32 n_used () { return (d_n_used); };
-  inline void n_used (UInt32 bufLen) {
+  inline size_t n_used () { return (d_n_used); };
+  inline void n_used (size_t bufLen) {
     d_n_used = (bufLen > d_n_alloc) ? d_n_alloc : bufLen; };
-  inline UInt32 n_alloc () { return (d_n_alloc); };
-  void buffer (char* l_buffer, UInt32 bufLen) {
+  inline size_t n_alloc () { return (d_n_alloc); };
+  void buffer (char* l_buffer, size_t bufLen) {
     if (bufLen > d_n_alloc) {
       fprintf (stderr, "s_buffer::set: Copying only allocated bytes.\n");
       bufLen = d_n_alloc;
@@ -173,7 +173,7 @@ public:
   usb_interface_t* d_interface;
   s_queue_ptr d_queue;
   circular_buffer<char>* d_buffer;
-  UInt32 d_bufLenBytes;
+  size_t d_bufLenBytes;
   mld_mutex_ptr d_readRunning;
   mld_condition_ptr d_runBlock, d_readBlock;