Merge branch 'osx_10.6_64_fixes' of http://gnuradio.org/git/michaelld
authorJohnathan Corgan <jcorgan@corganenterprises.com>
Mon, 19 Oct 2009 15:25:35 +0000 (08:25 -0700)
committerJohnathan Corgan <jcorgan@corganenterprises.com>
Mon, 19 Oct 2009 15:25:35 +0000 (08:25 -0700)
This merge adds support for OSX 10.6 in gr-audio-osx and usrp.

Conflicts:
usrp/host/lib/usrp_prims_libusb0.cc

config/gr_set_md_cpu.m4
gr-audio-osx/src/audio_osx.h
gr-audio-osx/src/audio_osx_sink.cc
gr-audio-osx/src/audio_osx_source.cc
gr-audio-osx/src/circular_buffer.h
usrp/host/lib/circular_buffer.h
usrp/host/lib/circular_linked_list.h
usrp/host/lib/darwin_libusb.h
usrp/host/lib/fusb_darwin.cc
usrp/host/lib/fusb_darwin.h
usrp/host/lib/usrp_prims_libusb0.cc

index d8714c4a71861a87466ccee3c01e478295aaaf34..7ebf88a66428d73309c626e6467686d43bed9457 100644 (file)
@@ -50,8 +50,32 @@ 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 see if the user has specified --host or --build, via 'cross_compiling'
+  if test "$cross_compiling" != no; then
+    dnl when cross-compiling, because the user specified it either via
+    dnl --target or --build, just keep the user's specs & hope for the best.
+    cf_with_md_cpu="$host_cpu"
+  else
+    dnl when the user didn't specify --target or --build, on Darwin 10
+    dnl (OSX 10.6.0 and .1) and GNU libtoool 2.2.6, 'configure' doesn't
+    dnl figure out the CPU type correctly, so do it by hand here using
+    dnl the sizeof (void*): if 4 then use i386, and otherwise use x86_64.
+    case "$host_os" in
+     *darwin*10*)
+      AC_CHECK_SIZEOF(void*)
+      if test "$ac_cv_sizeof_voidp" = 4; then
+       cf_with_md_cpu="i386"
+      else
+       cf_with_md_cpu="x86_64"
+      fi
+      ;;
+     *)
+      cf_with_md_cpu="$host_cpu"
+      ;;
+    esac
+  fi
+  ])
   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 c92fbcb0d9cf641e11582634680a8791171894f6..79e79e36cb0edeed5f7d43183cf76a520b32db53 100644 (file)
 #ifndef INCLUDED_AUDIO_OSX_H
 #define INCLUDED_AUDIO_OSX_H
 
-#define CheckErrorAndThrow(err,what,throw_str) \
-if (err) { \
-  OSStatus error = static_cast<OSStatus>(err); \
-  fprintf (stderr, "%s\n  Error# %ld ('%4s')\n  %s:%d\n", \
-          what, error, (char*)(&err), __FILE__, __LINE__); \
-  fflush (stdout); \
-  throw std::runtime_error (throw_str); \
-}
+#include <iostream>
+#include <string.h>
 
-#define CheckError(err,what) \
-if (err) { \
-  OSStatus error = static_cast<OSStatus>(err); \
-  fprintf (stderr, "%s\n  Error# %ld ('%4s')\n  %s:%d\n", \
-          what, error, (char*)(&err), __FILE__, __LINE__); \
-  fflush (stdout); \
-}
+#define CheckErrorAndThrow(err,what,throw_str)                         \
+  if (err) {                                                           \
+    OSStatus error = static_cast<OSStatus>(err);                       \
+    char err_str[4];                                                   \
+    strncpy (err_str, (char*)(&err), 4);                               \
+    std::cerr << what << std::endl;                                    \
+    std::cerr << "  Error# " << error << " ('" << err_str              \
+             << "')" << std::endl;                                     \
+    std::cerr << "  " << __FILE__ << ":" << __LINE__ << std::endl;     \
+    fflush (stderr);                                                   \
+    throw std::runtime_error (throw_str);                              \
+  }
+
+#define CheckError(err,what)                                           \
+  if (err) {                                                           \
+    OSStatus error = static_cast<OSStatus>(err);                       \
+    char err_str[4];                                                   \
+    strncpy (err_str, (char*)(&err), 4);                               \
+    std::cerr << what << std::endl;                                    \
+    std::cerr << "  Error# " << error << " ('" << err_str              \
+             << "')" << std::endl;                                     \
+    std::cerr << "  " << __FILE__ << ":" << __LINE__ << std::endl;     \
+    fflush (stderr);                                                   \
+  }
 
 #ifdef WORDS_BIGENDIAN
 #define GR_PCM_ENDIANNESS kLinearPCMFormatFlagIsBigEndian
@@ -46,4 +57,15 @@ if (err) { \
 #define GR_PCM_ENDIANNESS 0
 #endif
 
+// Check the version of MacOSX being used
+#ifdef __APPLE_CC__
+#include <AvailabilityMacros.h>
+#ifndef MAC_OS_X_VERSION_10_6
+#define MAC_OS_X_VERSION_10_6 1060
+#endif
+#if MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_6
+#define GR_USE_OLD_AUDIO_UNIT
+#endif
+#endif
+
 #endif /* INCLUDED_AUDIO_OSX_H */
index fef21babd939be34b6196c58ede4716ad5f40866..e91716c0acacc44dfb32a39614d61d5735afed65 100644 (file)
@@ -47,19 +47,19 @@ audio_osx_sink::audio_osx_sink (int sample_rate,
     d_OutputAU (0)
 {
   if (sample_rate <= 0) {
-    fprintf (stderr, "Invalid Sample Rate: %d\n", sample_rate);
+    std::cerr << "Invalid Sample Rate: " << sample_rate << std::endl;
     throw std::invalid_argument ("audio_osx_sink::audio_osx_sink");
   } else
     d_sample_rate = (Float64) sample_rate;
 
   if (channel_config <= 0 & channel_config != -1) {
-    fprintf (stderr, "Invalid Channel Config: %d\n", channel_config);
+    std::cerr << "Invalid Channel Config: " << channel_config << std::endl;
     throw std::invalid_argument ("audio_osx_sink::audio_osx_sink");
   } else if (channel_config == -1) {
 // no user input; try "device name" instead
     int l_n_channels = (int) strtol (device_name.data(), (char **)NULL, 10);
     if (l_n_channels == 0 & errno) {
-      fprintf (stderr, "Error Converting Device Name: %d\n", errno);
+      std::cerr << "Error Converting Device Name: " << errno << std::endl;
       throw std::invalid_argument ("audio_osx_sink::audio_osx_sink");
     }
     if (l_n_channels <= 0)
@@ -79,7 +79,7 @@ audio_osx_sink::audio_osx_sink (int sample_rate,
   if (max_sample_count == -1)
     max_sample_count = sample_rate;
   else if (max_sample_count <= 0) {
-    fprintf (stderr, "Invalid Max Sample Count: %d\n", max_sample_count);
+    std::cerr << "Invalid Max Sample Count: " << max_sample_count << std::endl;
     throw std::invalid_argument ("audio_osx_sink::audio_osx_sink");
   }
 
@@ -98,21 +98,39 @@ audio_osx_sink::audio_osx_sink (int sample_rate,
   OSStatus err = noErr;
 
 // Open the default output unit
+#ifndef GR_USE_OLD_AUDIO_UNIT
+  AudioComponentDescription desc;
+#else
   ComponentDescription desc;
+#endif
+
   desc.componentType = kAudioUnitType_Output;
   desc.componentSubType = kAudioUnitSubType_DefaultOutput;
   desc.componentManufacturer = kAudioUnitManufacturer_Apple;
   desc.componentFlags = 0;
   desc.componentFlagsMask = 0;
 
+#ifndef GR_USE_OLD_AUDIO_UNIT
+  AudioComponent comp = AudioComponentFindNext(NULL, &desc);
+  if (comp == NULL) {
+    std::cerr << "AudioComponentFindNext Error" << std::endl;
+    throw std::runtime_error ("audio_osx_sink::audio_osx_sink");
+  }
+#else
   Component comp = FindNextComponent (NULL, &desc);
   if (comp == NULL) {
-    fprintf (stderr, "FindNextComponent Error\n");
+    std::cerr << "FindNextComponent Error" << std::endl;
     throw std::runtime_error ("audio_osx_sink::audio_osx_sink");
   }
+#endif
 
+#ifndef GR_USE_OLD_AUDIO_UNIT
+  err = AudioComponentInstanceNew (comp, &d_OutputAU);
+  CheckErrorAndThrow (err, "AudioComponentInstanceNew", "audio_osx_sink::audio_osx_sink");
+#else
   err = OpenAComponent (comp, &d_OutputAU);
   CheckErrorAndThrow (err, "OpenAComponent", "audio_osx_sink::audio_osx_sink");
+#endif
 
 // Set up a callback function to generate output to the output unit
 
@@ -167,11 +185,10 @@ audio_osx_sink::audio_osx_sink (int sample_rate,
                      "audio_osx_sink::audio_osx_sink");
 
 #if _OSX_AU_DEBUG_
-  fprintf (stderr, "audio_osx_sink Parameters:\n");
-  fprintf (stderr, "  Sample Rate is %g\n", d_sample_rate);
-  fprintf (stderr, "  Number of Channels is %ld\n", d_n_channels);
-  fprintf (stderr, "  Max # samples to store per channel is %ld",
-          d_max_sample_count);
+  std::cerr << "audio_osx_sink Parameters:" << std::endl;
+  std::cerr << "  Sample Rate is " << d_sample_rate << std::endl;
+  std::cerr << "  Number of Channels is " << d_n_channels << std::endl;
+  std::cerr << "  Max # samples to store per channel is " << d_max_sample_count << std::endl;
 #endif
 }
 
@@ -220,7 +237,11 @@ audio_osx_sink::~audio_osx_sink ()
 // stop and close the AudioUnit
   stop ();
   AudioUnitUninitialize (d_OutputAU);
+#ifndef GR_USE_OLD_AUDIO_UNIT
+  AudioComponentInstanceDispose (d_OutputAU);
+#else
   CloseComponent (d_OutputAU);
+#endif
 
 // empty and delete the queues
   for (UInt32 n = 0; n < d_n_channels; n++) {
@@ -275,8 +296,8 @@ audio_osx_sink::work (int noutput_items,
 #endif
 
 #if _OSX_AU_DEBUG_
-  fprintf (stderr, "work1: qSC = %ld, lMC = %ld, dmSC = %ld, nOI = %d\n",
-          d_queueSampleCount, l_max_count, d_max_sample_count, noutput_items);
+  std::cerr << "work1: qSC = " << d_queueSampleCount << ", lMC = "<< l_max_count
+           << ", dmSC = " << d_max_sample_count << ", nOI = " << noutput_items << std::endl;
 #endif
 
   if (d_queueSampleCount > l_max_count) {
@@ -318,7 +339,7 @@ audio_osx_sink::work (int noutput_items,
   if (res == -1) {
 // data coming in too fast
 // drop oldest buffer
-    fputs ("oX", stderr);
+    fputs ("aO", stderr);
     fflush (stderr);
 // set the local number of samples available to the max
     d_queueSampleCount = d_buffers[0]->buffer_length_items ();
@@ -328,8 +349,8 @@ audio_osx_sink::work (int noutput_items,
   }
 
 #if _OSX_AU_DEBUG_
-  fprintf (stderr, "work2: #OI = %4d, #Cnt = %4ld, mSC = %ld\n",
-          noutput_items, d_queueSampleCount, d_max_sample_count);
+  std::cerr << "work2: #OI = " << noutput_items << ", #Cnt = "
+           << d_queueSampleCount << ", mSC = " << d_max_sample_count << std::endl;
 #endif
 
 // release control to allow for other processing parts to run
@@ -352,8 +373,8 @@ OSStatus audio_osx_sink::AUOutputCallback
   This->d_internal->lock ();
 
 #if _OSX_AU_DEBUG_
-  fprintf (stderr, "cb_in: SC = %4ld, in#F = %4ld\n",
-          This->d_queueSampleCount, inNumberFrames);
+  std::cerr << "cb_in: SC = " << This->d_queueSampleCount
+           << ", in#F = " << inNumberFrames << std::endl;
 #endif
 
   if (This->d_queueSampleCount < inNumberFrames) {
@@ -364,7 +385,7 @@ OSStatus audio_osx_sink::AUOutputCallback
     int l_counter = This->d_n_channels;
 
     while (--l_counter >= 0) {
-      UInt32 t_n_output_items = inNumberFrames;
+      size_t t_n_output_items = inNumberFrames;
       float* outBuffer = (float*) ioData->mBuffers[l_counter].mData;
       This->d_buffers[l_counter]->dequeue (outBuffer, &t_n_output_items);
       if (t_n_output_items != inNumberFrames) {
@@ -378,7 +399,7 @@ OSStatus audio_osx_sink::AUOutputCallback
   }
 
 #if _OSX_AU_DEBUG_
-  fprintf (stderr, "cb_out: SC = %4ld\n", This->d_queueSampleCount);
+  std::cerr << "cb_out: SC = " << This->d_queueSampleCount << std::endl;
 #endif
 
 // signal that data is available
index e82e8ad21515e128a8ea778ff7b0860912ca0036..61838745b53081e68d9e8d857a8fe60ee9423bdb 100644 (file)
 void PrintStreamDesc (AudioStreamBasicDescription *inDesc)
 {
   if (inDesc == NULL) {
-    fprintf (stderr, "PrintStreamDesc: Can't print a NULL desc!\n");
+    std::cerr << "PrintStreamDesc: Can't print a NULL desc!" << std::endl;
     return;
   }
 
-  fprintf (stderr, "  Sample Rate        : %g\n", inDesc->mSampleRate);
-  fprintf (stderr, "  Format ID          : %4s\n", (char*)&inDesc->mFormatID);
-  fprintf (stderr, "  Format Flags       : %lX\n", inDesc->mFormatFlags);
-  fprintf (stderr, "  Bytes per Packet   : %ld\n", inDesc->mBytesPerPacket);
-  fprintf (stderr, "  Frames per Packet  : %ld\n", inDesc->mFramesPerPacket);
-  fprintf (stderr, "  Bytes per Frame    : %ld\n", inDesc->mBytesPerFrame);
-  fprintf (stderr, "  Channels per Frame : %ld\n", inDesc->mChannelsPerFrame);
-  fprintf (stderr, "  Bits per Channel   : %ld\n", inDesc->mBitsPerChannel);
+  std::cerr << "  Sample Rate        : " << inDesc->mSampleRate << std::endl;
+  char format_id[4];
+  strncpy (format_id, (char*)(&inDesc->mFormatID), 4);
+  std::cerr << "  Format ID          : " << format_id << std::endl;
+  std::cerr << "  Format Flags       : " << inDesc->mFormatFlags << std::endl;
+  std::cerr << "  Bytes per Packet   : " << inDesc->mBytesPerPacket << std::endl;
+  std::cerr << "  Frames per Packet  : " << inDesc->mFramesPerPacket << std::endl;
+  std::cerr << "  Bytes per Frame    : " << inDesc->mBytesPerFrame << std::endl;
+  std::cerr << "  Channels per Frame : " << inDesc->mChannelsPerFrame << std::endl;
+  std::cerr << "  Bits per Channel   : " << inDesc->mBitsPerChannel << std::endl;
 }
 
 // FIXME these should query some kind of user preference
@@ -79,19 +81,19 @@ audio_osx_source::audio_osx_source (int sample_rate,
     d_AudioConverter (0)
 {
   if (sample_rate <= 0) {
-    fprintf (stderr, "Invalid Sample Rate: %d\n", sample_rate);
+    std::cerr << "Invalid Sample Rate: " << sample_rate << std::endl;
     throw std::invalid_argument ("audio_osx_source::audio_osx_source");
   } else
     d_outputSampleRate = (Float64) sample_rate;
 
   if (channel_config <= 0 & channel_config != -1) {
-    fprintf (stderr, "Invalid Channel Config: %d\n", channel_config);
+    std::cerr << "Invalid Channel Config: " << channel_config << std::endl;
     throw std::invalid_argument ("audio_osx_source::audio_osx_source");
   } else if (channel_config == -1) {
 // no user input; try "device name" instead
     int l_n_channels = (int) strtol (device_name.data(), (char **)NULL, 10);
     if (l_n_channels == 0 & errno) {
-      fprintf (stderr, "Error Converting Device Name: %d\n", errno);
+      std::cerr << "Error Converting Device Name: " << errno << std::endl;
       throw std::invalid_argument ("audio_osx_source::audio_osx_source");
     }
     if (l_n_channels <= 0)
@@ -107,14 +109,14 @@ audio_osx_source::audio_osx_source (int sample_rate,
   if (max_sample_count == -1)
     max_sample_count = sample_rate;
   else if (max_sample_count <= 0) {
-    fprintf (stderr, "Invalid Max Sample Count: %d\n", max_sample_count);
+    std::cerr << "Invalid Max Sample Count: " << max_sample_count << std::endl;
     throw std::invalid_argument ("audio_osx_source::audio_osx_source");
   }
 
   d_max_sample_count = max_sample_count;
 
 #if _OSX_AU_DEBUG_
-  fprintf (stderr, "source(): max # samples = %ld\n", d_max_sample_count);
+  std::cerr << "source(): max # samples = " << d_max_sample_count << std::endl;
 #endif
 
   OSStatus err = noErr;
@@ -122,7 +124,12 @@ audio_osx_source::audio_osx_source (int sample_rate,
 // create the default AudioUnit for input
 
 // Open the default input unit
+#ifndef GR_USE_OLD_AUDIO_UNIT
+  AudioComponentDescription InputDesc;
+#else
   ComponentDescription InputDesc;
+#endif
+  
 
   InputDesc.componentType = kAudioUnitType_Output;
   InputDesc.componentSubType = kAudioUnitSubType_HALOutput;
@@ -130,15 +137,31 @@ audio_osx_source::audio_osx_source (int sample_rate,
   InputDesc.componentFlags = 0;
   InputDesc.componentFlagsMask = 0;
 
+#ifndef GR_USE_OLD_AUDIO_UNIT
+  AudioComponent comp = AudioComponentFindNext (NULL, &InputDesc);
+#else
   Component comp = FindNextComponent (NULL, &InputDesc);
+#endif
+  
   if (comp == NULL) {
-    fprintf (stderr, "FindNextComponent Error\n");
+#ifndef GR_USE_OLD_AUDIO_UNIT
+    std::cerr << "AudioComponentFindNext Error" << std::endl;
+#else
+    std::cerr << "FindNextComponent Error" << std::endl;
+#endif
     throw std::runtime_error ("audio_osx_source::audio_osx_source");
   }
 
+#ifndef GR_USE_OLD_AUDIO_UNIT
+  err = AudioComponentInstanceNew (comp, &d_InputAU);
+  CheckErrorAndThrow (err, "AudioComponentInstanceNew",
+                     "audio_osx_source::audio_osx_source");
+#else
   err = OpenAComponent (comp, &d_InputAU);
   CheckErrorAndThrow (err, "OpenAComponent",
                      "audio_osx_source::audio_osx_source");
+#endif
+  
 
   UInt32 enableIO;
 
@@ -208,7 +231,7 @@ audio_osx_source::audio_osx_source (int sample_rate,
   CheckErrorAndThrow (err, "AudioUnitGetProperty HasIO",
                      "audio_osx_source::audio_osx_source");
   if (hasInput == 0) {
-    fprintf (stderr, "Selected Audio Device does not support Input.\n");
+    std::cerr << "Selected Audio Device does not support Input." << std::endl;
     throw std::runtime_error ("audio_osx_source::audio_osx_source");
   }
 
@@ -248,7 +271,7 @@ audio_osx_source::audio_osx_source (int sample_rate,
                      "audio_osx_source::audio_osx_source");
 
 #if _OSX_AU_DEBUG_
-  fprintf (stderr, "\n---- Device Stream Format ----\n" );
+  std::cerr << std::endl << "---- Device Stream Format ----" << std::endl;
   PrintStreamDesc (&asbd_device);
 #endif
 
@@ -264,7 +287,7 @@ audio_osx_source::audio_osx_source (int sample_rate,
                      "audio_osx_source::audio_osx_source");
 
 #if _OSX_AU_DEBUG_
-  fprintf (stderr, "\n---- Client Stream Format ----\n");
+  std::cerr << std::endl << "---- Client Stream Format ----" << std::endl;
   PrintStreamDesc (&asbd_client);
 #endif
 
@@ -436,22 +459,17 @@ audio_osx_source::audio_osx_source (int sample_rate,
                      "audio_osx_source::audio_osx_source");
 
 #if _OSX_AU_DEBUG_
-  fprintf (stderr, "audio_osx_source Parameters:\n");
-  fprintf (stderr, "  Device Sample Rate is %g\n", d_deviceSampleRate);
-  fprintf (stderr, "  User Sample Rate is %g\n", d_outputSampleRate);
-  fprintf (stderr, "  Max Sample Count is %ld\n", d_max_sample_count);
-  fprintf (stderr, "  # Device Channels is %ld\n", d_n_deviceChannels);
-  fprintf (stderr, "  # Max Channels is %ld\n", d_n_max_channels);
-  fprintf (stderr, "  Device Buffer Size is Frames = %ld\n",
-          d_deviceBufferSizeFrames);
-  fprintf (stderr, "  Lead Size is Frames = %ld\n",
-          d_leadSizeFrames);
-  fprintf (stderr, "  Trail Size is Frames = %ld\n",
-          d_trailSizeFrames);
-  fprintf (stderr, "  Input Buffer Size is Frames = %ld\n",
-          d_inputBufferSizeFrames);
-  fprintf (stderr, "  Output Buffer Size is Frames = %ld\n",
-          d_outputBufferSizeFrames);
+  std::cerr << "audio_osx_source Parameters:" << std::endl;
+  std::cerr << "  Device Sample Rate is " << d_deviceSampleRate << std::endl;
+  std::cerr << "  User Sample Rate is " << d_outputSampleRate << std::endl;
+  std::cerr << "  Max Sample Count is " << d_max_sample_count << std::endl;
+  std::cerr << "  # Device Channels is " << d_n_deviceChannels << std::endl;
+  std::cerr << "  # Max Channels is " << d_n_max_channels << std::endl;
+  std::cerr << "  Device Buffer Size is Frames = " << d_deviceBufferSizeFrames << std::endl;
+  std::cerr << "  Lead Size is Frames = " << d_leadSizeFrames << std::endl;
+  std::cerr << "  Trail Size is Frames = " << d_trailSizeFrames << std::endl;
+  std::cerr << "  Input Buffer Size is Frames = " << d_inputBufferSizeFrames << std::endl;
+  std::cerr << "  Output Buffer Size is Frames = " << d_outputBufferSizeFrames << std::endl;
 #endif
 }
 
@@ -564,8 +582,13 @@ audio_osx_source::~audio_osx_source ()
   err = AudioUnitUninitialize (d_InputAU);
   CheckError (err, "~audio_osx_source: AudioUnitUninitialize");
 
+#ifndef GR_USE_OLD_AUDIO_UNIT
+  err = AudioComponentInstanceDispose (d_InputAU);
+  CheckError (err, "~audio_osx_source: AudioComponentInstanceDispose");
+#else
   err = CloseComponent (d_InputAU);
   CheckError (err, "~audio_osx_source: CloseComponent");
+#endif
 
 // empty and delete the queues
   for (UInt32 n = 0; n < d_n_max_channels; n++) {
@@ -598,18 +621,18 @@ audio_osx_source::check_topology (int ninputs, int noutputs)
 {
 // check # inputs to make sure it's valid
   if (ninputs != 0) {
-    fprintf (stderr, "audio_osx_source::check_topology(): "
-            "number of input streams provided (%d) should be 0.\n",
-            ninputs);
+    std::cerr << "audio_osx_source::check_topology(): number of input "
+             << "streams provided (" << ninputs
+             << ") should be 0." << std::endl;
     throw std::runtime_error ("audio_osx_source::check_topology()");
   }
 
 // check # outputs to make sure it's valid
   if ((noutputs < 1) | (noutputs > (int) d_n_max_channels)) {
-    fprintf (stderr, "audio_osx_source::check_topology(): "
-            "number of output streams provided (%d) should be in "
-            "[1,%ld] for the selected audio device.\n",
-            noutputs, d_n_max_channels);
+    std::cerr << "audio_osx_source::check_topology(): number of output "
+             << "streams provided (" << noutputs << ") should be in [1,"
+             << d_n_max_channels << "] for the selected audio device."
+             << std::endl;
     throw std::runtime_error ("audio_osx_source::check_topology()");
   }
 
@@ -617,8 +640,8 @@ audio_osx_source::check_topology (int ninputs, int noutputs)
   d_n_user_channels = noutputs;
 
 #if _OSX_AU_DEBUG_
-  fprintf (stderr, "chk_topo: Actual # user output channels = %d\n",
-          noutputs);
+  std::cerr << "chk_topo: Actual # user output channels = "
+           << noutputs << std::endl;
 #endif
 
   return (true);
@@ -634,8 +657,9 @@ audio_osx_source::work
   d_internal->lock ();
 
 #if _OSX_AU_DEBUG_
-  fprintf (stderr, "work1: SC = %4ld, #OI = %4d, #Chan = %ld\n",
-          d_queueSampleCount, noutput_items, output_items.size());
+  std::cerr << "work1: SC = " << d_queueSampleCount
+           << ", #OI = " << noutput_items
+           << ", #Chan = " << output_items.size() << std::endl;
 #endif
 
   // set the actual # of output items to the 'desired' amount then
@@ -675,14 +699,14 @@ audio_osx_source::work
   // verify that the number copied out is as expected.
 
   while (--l_counter >= 0) {
-    UInt32 t_n_output_items = actual_noutput_items;
+    size_t t_n_output_items = actual_noutput_items;
     d_buffers[l_counter]->dequeue ((float*) output_items[l_counter],
                                   &t_n_output_items);
     if (t_n_output_items != actual_noutput_items) {
-      fprintf (stderr, "audio_osx_source::work(): "
-              "number of available items changing "
-              "unexpectedly; expecting %ld, got %ld.\n",
-              actual_noutput_items, t_n_output_items);
+      std::cerr << "audio_osx_source::work(): ERROR: number of "
+               << "available items changing unexpectedly; expecting "
+               << actual_noutput_items << ", got "
+               << t_n_output_items << "." << std::endl;
       throw std::runtime_error ("audio_osx_source::work()");
     }
   }
@@ -693,8 +717,8 @@ audio_osx_source::work
   d_queueSampleCount -= actual_noutput_items;
 
 #if _OSX_AU_DEBUG_
-  fprintf (stderr, "work2: SC = %4ld, act#OI = %4ld\n",
-          d_queueSampleCount, actual_noutput_items);
+  std::cerr << "work2: SC = " << d_queueSampleCount
+           << ", act#OI = " << actual_noutput_items << std::endl;
 #endif
 
   // release control to allow for other processing parts to run
@@ -702,7 +726,7 @@ audio_osx_source::work
   d_internal->unlock ();
 
 #if _OSX_AU_DEBUG_
-  fprintf (stderr, "work3: Returning.\n");
+  std::cerr << "work3: Returning." << std::endl;
 #endif
 
   return (actual_noutput_items);
@@ -728,8 +752,9 @@ audio_osx_source::ConverterCallback
   This->d_n_ActualInputFrames = (*ioNumberDataPackets);
 
 #if _OSX_AU_DEBUG_
-  fprintf (stderr, "cc1: io#DP = %ld, TIBSB = %ld, #C = %d\n",
-          *ioNumberDataPackets, totalInputBufferSizeBytes, counter);
+  std::cerr << "cc1: io#DP = " << (*ioNumberDataPackets)
+           << ", TIBSB = " << totalInputBufferSizeBytes
+           << ", #C = " << counter << std::endl;
 #endif
 
   while (--counter >= 0)  {
@@ -740,7 +765,7 @@ audio_osx_source::ConverterCallback
   }
 
 #if _OSX_AU_DEBUG_
-  fprintf (stderr, "cc2: Returning.\n");
+  std::cerr << "cc2: Returning." << std::endl;
 #endif
 
   return (noErr);
@@ -760,8 +785,9 @@ audio_osx_source::AUInputCallback (void* inRefCon,
   This->d_internal->lock ();
 
 #if _OSX_AU_DEBUG_
-  fprintf (stderr, "cb0: in#F = %4ld, inBN = %ld, SC = %4ld\n",
-          inNumberFrames, inBusNumber, This->d_queueSampleCount);
+  std::cerr << "cb0: in#F = " << inNumberFrames
+           << ", inBN = " << inBusNumber
+           << ", SC = " << This->d_queueSampleCount << std::endl;
 #endif
 
 // Get the new audio data from the input device
@@ -821,8 +847,8 @@ audio_osx_source::AUInputCallback (void* inRefCon,
 #endif
 
 #if _OSX_AU_DEBUG_
-    fprintf (stderr, "cb1:  avail: #IF = %ld, #OF = %ld\n",
-            AvailableInputFrames, AvailableOutputFrames);
+    std::cerr << "cb1:  avail: #IF = " << AvailableInputFrames
+             << ", #OF = " << AvailableOutputFrames << std::endl;
 #endif
     ActualOutputFrames = AvailableOutputFrames;
 
@@ -841,11 +867,11 @@ audio_osx_source::AUInputCallback (void* inRefCon,
 // on output, ActualOutputFrames is the actual number of output frames
 
 #if _OSX_AU_DEBUG_
-    fprintf (stderr, "cb2: actual: #IF = %ld, #OF = %ld\n",
-            This->d_n_ActualInputFrames, AvailableOutputFrames);
+    std::cerr << "cb2: actual: #IF = " << This->d_n_ActualInputFrames
+             << ", #OF = " << AvailableOutputFrames << std::endl;
     if (This->d_n_ActualInputFrames != AvailableInputFrames)
-      fprintf (stderr, "cb2.1: avail#IF = %ld, actual#IF = %ld\n",
-              AvailableInputFrames, This->d_n_ActualInputFrames);
+      std::cerr << "cb2.1: avail#IF = " << AvailableInputFrames
+               << ", actual#IF = " << This->d_n_ActualInputFrames << std::endl;
 #endif
   }
 
@@ -858,7 +884,7 @@ audio_osx_source::AUInputCallback (void* inRefCon,
     float* inBuffer = (float*) This->d_OutputBuffer->mBuffers[l_counter].mData;
 
 #if _OSX_AU_DEBUG_
-  fprintf (stderr, "cb3: enqueuing audio data.\n");
+    std::cerr << "cb3: enqueuing audio data." << std::endl;
 #endif
 
     int l_res = This->d_buffers[l_counter]->enqueue (inBuffer, ActualOutputFrames);
@@ -879,23 +905,23 @@ audio_osx_source::AUInputCallback (void* inRefCon,
   }
 
 #if _OSX_AU_DEBUG_
-  fprintf (stderr, "cb4: #OI = %4ld, #Cnt = %4ld, mSC = %ld, \n",
-          ActualOutputFrames, This->d_queueSampleCount,
-          This->d_max_sample_count);
+  std::cerr << "cb4: #OI = " << ActualOutputFrames
+           << ", #Cnt = " << This->d_queueSampleCount
+           << ", mSC = " << This->d_max_sample_count << std::endl;
 #endif
 
 // signal that data is available, if appropraite
   This->d_cond_data->signal ();
 
 #if _OSX_AU_DEBUG_
-  fprintf (stderr, "cb5: releasing internal mutex.\n");
+  std::cerr << "cb5: releasing internal mutex." << std::endl;
 #endif
 
 // release control to allow for other processing parts to run
   This->d_internal->unlock ();
 
 #if _OSX_AU_DEBUG_
-  fprintf (stderr, "cb6: returning.\n");
+  std::cerr << "cb6: returning." << std::endl;
 #endif
 
   return (err);
@@ -930,7 +956,7 @@ audio_osx_source::HardwareListener
   OSStatus err = noErr;
   audio_osx_source* This = static_cast<audio_osx_source*>(inClientData);
 
-  fprintf (stderr, "a_o_s::HardwareListener\n");
+  std::cerr << "a_o_s::HardwareListener" << std::endl;
 
 // set the new default hardware input device for use by our AU
 
@@ -957,7 +983,7 @@ audio_osx_source::UnitListener
   audio_osx_source* This = static_cast<audio_osx_source*>(inRefCon);
   AudioStreamBasicDescription asbd;                    
 
-  fprintf (stderr, "a_o_s::UnitListener\n");
+  std::cerr << "a_o_s::UnitListener" << std::endl;
 
 // get the converter's input ASBD (for printing)
 
@@ -970,8 +996,8 @@ audio_osx_source::UnitListener
                      "CurrentInputStreamDescription",
                      "audio_osx_source::UnitListener");
 
-  fprintf (stderr, "UnitListener: Input Source changed.\n"
-          "Old Source Output Info:\n");
+  std::cerr << "UnitListener: Input Source changed." << std::endl
+           << "Old Source Output Info:" << std::endl;
   PrintStreamDesc (&asbd);
 
 // get the new input unit's output ASBD
@@ -984,7 +1010,7 @@ audio_osx_source::UnitListener
   CheckErrorAndThrow (err, "AudioUnitGetProperty StreamFormat",
                      "audio_osx_source::UnitListener");
 
-  fprintf (stderr, "New Source Output Info:\n");
+  std::cerr << "New Source Output Info:" << std::endl;
   PrintStreamDesc (&asbd);
 
 // set the converter's input ASBD to this
index fa451d607b728e2c64a92ef067720b1551351d39..6d491fb6f09499fd912a077275e5e2ee9c039f0b 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.
  *
 #define _CIRCULAR_BUFFER_H_
 
 #include "mld_threads.h"
+#include <iostream>
 #include <stdexcept>
 
+#ifndef DO_DEBUG
 #define DO_DEBUG 0
+#endif
 
 #if DO_DEBUG
 #define DEBUG(X) do{X} while(0);
@@ -41,8 +44,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 +70,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(): "
@@ -79,10 +82,10 @@ public:
     d_internal = NULL;
     d_readBlock = d_writeBlock = NULL;
     reset ();
-    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")));
+    DEBUG (std::cerr << "c_b(): buf len (items) = " << d_bufLen_
+          << ", doWriteBlock = " << (d_doWriteBlock ? "true" : "false")
+          << ", doFullRead = " << (d_doFullRead ? "true" : "false")
+          << std::endl);
   };
 
   ~circular_buffer () {
@@ -90,21 +93,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,14 +150,15 @@ public:
  *     buffer length is larger than the instantiated buffer length
  */
 
-  int enqueue (T* buf, UInt32 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));
+  int enqueue (T* buf, size_t bufLen_I) {
+    DEBUG (std::cerr << "enqueue: buf = " << (void*) buf
+          << ", bufLen = " << bufLen_I
+          << ", #av_wr = " << d_n_avail_write_I
+          << ", #av_rd = " << d_n_avail_read_I << std::endl);
     if (bufLen_I > d_bufLen_I) {
-      fprintf (stderr, "cannot add buffer longer (%ld"
-              ") than instantiated length (%ld"
-              ").\n", bufLen_I, d_bufLen_I);
+      std::cerr << "ERROR: cannot add buffer longer ("
+               << bufLen_I << ") than instantiated length ("
+               << d_bufLen_I << ")." << std::endl;
       throw std::runtime_error ("circular_buffer::enqueue()");
     }
 
@@ -173,25 +177,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 (std::cerr << "enqueue: #len > #a, waiting." << std::endl);
          // 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 (std::cerr << "enqueue: #len > #a, aborting." << std::endl);
            return (2);
          }
-         DEBUG (fprintf (stderr, "enqueue: #len > #a, done waiting.\n"));
+         DEBUG (std::cerr << "enqueue: #len > #a, done waiting." << std::endl);
        }
       } 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 (std::cerr << "circular_buffer::enqueue: overflow" << std::endl);
        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,23 +234,24 @@ public:
  *     buffer length is larger than the instantiated buffer length
  */
 
-  int dequeue (T* buf, UInt32* 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));
+  int dequeue (T* buf, size_t* bufLen_I) {
+    DEBUG (std::cerr << "dequeue: buf = " << ((void*) buf)
+          << ", *bufLen = " << (*bufLen_I)
+          << ", #av_wr = " <<  d_n_avail_write_I
+          << ", #av_rd = " << d_n_avail_read_I << std::endl);
     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) {
-      fprintf (stderr, "cannot remove buffer longer (%ld"
-              ") than instantiated length (%ld"
-              ").\n", l_bufLen_I, d_bufLen_I);
+      std::cerr << "ERROR: cannot remove buffer longer ("
+               << l_bufLen_I << ") than instantiated length ("
+               << d_bufLen_I << ")." << std::endl;
       throw std::runtime_error ("circular_buffer::dequeue()");
     }
 
@@ -257,34 +262,34 @@ public:
     }
     if (d_doFullRead) {
       while (d_n_avail_read_I < l_bufLen_I) {
-       DEBUG (fprintf (stderr, "dequeue: #a < #len, waiting.\n"));
+       DEBUG (std::cerr << "dequeue: #a < #len, waiting." << std::endl);
        // 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 (std::cerr << "dequeue: #a < #len, aborting." << std::endl);
          return (2);
        }
-       DEBUG (fprintf (stderr, "dequeue: #a < #len, done waiting.\n"));
+       DEBUG (std::cerr << "dequeue: #a < #len, done waiting." << std::endl);
      }
     } else {
       while (d_n_avail_read_I == 0) {
-       DEBUG (fprintf (stderr, "dequeue: #a == 0, waiting.\n"));
+       DEBUG (std::cerr << "dequeue: #a == 0, waiting." << std::endl);
        // 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 (std::cerr << "dequeue: #a == 0, aborting." << std::endl);
          return (2);
        }
-       DEBUG (fprintf (stderr, "dequeue: #a == 0, done waiting.\n"));
+       DEBUG (std::cerr << "dequeue: #a == 0, done waiting." << std::endl);
       }
     }
     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..6d491fb6f09499fd912a077275e5e2ee9c039f0b 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.
  *
@@ -24,6 +24,7 @@
 #define _CIRCULAR_BUFFER_H_
 
 #include "mld_threads.h"
+#include <iostream>
 #include <stdexcept>
 
 #ifndef DO_DEBUG
@@ -43,8 +44,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 +70,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(): "
@@ -81,10 +82,10 @@ public:
     d_internal = NULL;
     d_readBlock = d_writeBlock = NULL;
     reset ();
-    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")););
+    DEBUG (std::cerr << "c_b(): buf len (items) = " << d_bufLen_
+          << ", doWriteBlock = " << (d_doWriteBlock ? "true" : "false")
+          << ", doFullRead = " << (d_doFullRead ? "true" : "false")
+          << std::endl);
   };
 
   ~circular_buffer () {
@@ -92,21 +93,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,14 +150,15 @@ public:
  *     buffer length is larger than the instantiated buffer length
  */
 
-  int enqueue (T* buf, UInt32 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););
+  int enqueue (T* buf, size_t bufLen_I) {
+    DEBUG (std::cerr << "enqueue: buf = " << (void*) buf
+          << ", bufLen = " << bufLen_I
+          << ", #av_wr = " << d_n_avail_write_I
+          << ", #av_rd = " << d_n_avail_read_I << std::endl);
     if (bufLen_I > d_bufLen_I) {
-      fprintf (stderr, "cannot add buffer longer (%ld"
-              ") than instantiated length (%ld"
-              ").\n", bufLen_I, d_bufLen_I);
+      std::cerr << "ERROR: cannot add buffer longer ("
+               << bufLen_I << ") than instantiated length ("
+               << d_bufLen_I << ")." << std::endl;
       throw std::runtime_error ("circular_buffer::enqueue()");
     }
 
@@ -175,25 +177,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 (std::cerr << "enqueue: #len > #a, waiting." << std::endl);
          // 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 (std::cerr << "enqueue: #len > #a, aborting." << std::endl);
            return (2);
          }
-         DEBUG (fprintf (stderr, "enqueue: #len > #a, done waiting.\n"););
+         DEBUG (std::cerr << "enqueue: #len > #a, done waiting." << std::endl);
        }
       } 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 (std::cerr << "circular_buffer::enqueue: overflow" << std::endl);
        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,23 +234,24 @@ public:
  *     buffer length is larger than the instantiated buffer length
  */
 
-  int dequeue (T* buf, UInt32* 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););
+  int dequeue (T* buf, size_t* bufLen_I) {
+    DEBUG (std::cerr << "dequeue: buf = " << ((void*) buf)
+          << ", *bufLen = " << (*bufLen_I)
+          << ", #av_wr = " <<  d_n_avail_write_I
+          << ", #av_rd = " << d_n_avail_read_I << std::endl);
     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) {
-      fprintf (stderr, "cannot remove buffer longer (%ld"
-              ") than instantiated length (%ld"
-              ").\n", l_bufLen_I, d_bufLen_I);
+      std::cerr << "ERROR: cannot remove buffer longer ("
+               << l_bufLen_I << ") than instantiated length ("
+               << d_bufLen_I << ")." << std::endl;
       throw std::runtime_error ("circular_buffer::dequeue()");
     }
 
@@ -259,34 +262,34 @@ public:
     }
     if (d_doFullRead) {
       while (d_n_avail_read_I < l_bufLen_I) {
-       DEBUG (fprintf (stderr, "dequeue: #a < #len, waiting.\n"););
+       DEBUG (std::cerr << "dequeue: #a < #len, waiting." << std::endl);
        // 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 (std::cerr << "dequeue: #a < #len, aborting." << std::endl);
          return (2);
        }
-       DEBUG (fprintf (stderr, "dequeue: #a < #len, done waiting.\n"););
+       DEBUG (std::cerr << "dequeue: #a < #len, done waiting." << std::endl);
      }
     } else {
       while (d_n_avail_read_I == 0) {
-       DEBUG (fprintf (stderr, "dequeue: #a == 0, waiting.\n"););
+       DEBUG (std::cerr << "dequeue: #a == 0, waiting." << std::endl);
        // 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 (std::cerr << "dequeue: #a == 0, aborting." << std::endl);
          return (2);
        }
-       DEBUG (fprintf (stderr, "dequeue: #a == 0, done waiting.\n"););
+       DEBUG (std::cerr << "dequeue: #a == 0, done waiting." << std::endl);
       }
     }
     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 e495d609b2f6c265b19d48a4b24515cd8f036588..97fe2c1a897f1a2bf893a8771404c96766d42f5c 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.
  *
@@ -109,12 +109,12 @@ template <class T> class circular_linked_list {
 
 private:
   s_node_ptr d_current, d_iterate, d_available, d_inUse;
-  UInt32 d_n_nodes, d_n_used;
+  size_t d_n_nodes, d_n_used;
   mld_mutex_ptr d_internal;
   mld_condition_ptr d_ioBlock;
 
 public:
-  circular_linked_list (UInt32 n_nodes) {
+  circular_linked_list (size_t n_nodes) {
     if (n_nodes == 0)
       throw std::runtime_error ("circular_linked_list(): n_nodes == 0");
 
@@ -136,7 +136,7 @@ public:
       l_prev->next (l_next);
       l_prev->prev (l_next);
       if (n_nodes > 2) {
-       UInt32 n = n_nodes - 2;
+       size_t n = n_nodes - 2;
        while (n-- > 0) {
          d_current = new s_node<T> (l_prev, l_next);
          d_current->set_available ();
@@ -171,17 +171,17 @@ public:
     d_internal->lock ();
 // find an available node
     s_node_ptr l_node = d_available; 
-    DEBUG (fprintf (stderr, "w "););
+    DEBUG (std::cerr << "w ");
     while (! l_node) {
-      DEBUG (fprintf (stderr, "x\n"););
+      DEBUG (std::cerr << "x" << std::endl);
       // the ioBlock condition will automatically unlock() d_internal
       d_ioBlock->wait ();
       // and lock() is here
-      DEBUG (fprintf (stderr, "y\n"););
+      DEBUG (std::cerr << "y" << std::endl);
       l_node = d_available;
     }
-    DEBUG (fprintf (stderr, "::f_n_a_n: #u = %ld, node = %p\n",
-                   num_used(), l_node););
+    DEBUG (std::cerr << "::f_n_a_n: #u = " << num_used()
+          << ", node = " << l_node << std::endl);
 // remove this one from the current available list
     if (num_available () == 1) {
 // last one, just set available to NULL
@@ -203,8 +203,8 @@ public:
   void make_node_available (s_node_ptr l_node) {
     if (!l_node) return;
     d_internal->lock ();
-    DEBUG (fprintf (stderr, "::m_n_a: #u = %ld, node = %p\n",
-                   num_used(), l_node););
+    DEBUG (std::cerr << "::m_n_a: #u = " << num_used()
+          << ", node = " << l_node << std::endl);
 // remove this node from the inUse list
     if (num_used () == 1) {
 // last one, just set inUse to NULL
@@ -219,10 +219,10 @@ public:
       l_node->insert_before (d_available);
     d_n_used--;
 
-    DEBUG (fprintf (stderr, "s%ld ", d_n_used););
+    DEBUG (std::cerr << "s" << d_n_used);
 // signal the condition when new data arrives
     d_ioBlock->signal ();
-    DEBUG (fprintf (stderr, "t "););
+    DEBUG (std::cerr << "t ");
 
 // unlock the mutex for thread safety
     d_internal->unlock ();
@@ -251,10 +251,10 @@ public:
 
   __INLINE__ T object () { return (d_current->d_object); };
   __INLINE__ void object (T l_object) { d_current->d_object = l_object; };
-  __INLINE__ UInt32 num_nodes () { return (d_n_nodes); };
-  __INLINE__ UInt32 num_used () { return (d_n_used); };
-  __INLINE__ void num_used (UInt32 l_n_used) { d_n_used = l_n_used; };
-  __INLINE__ UInt32 num_available () { return (d_n_nodes - d_n_used); };
+  __INLINE__ size_t num_nodes () { return (d_n_nodes); };
+  __INLINE__ size_t num_used () { return (d_n_used); };
+  __INLINE__ void num_used (size_t l_n_used) { d_n_used = l_n_used; };
+  __INLINE__ size_t num_available () { return (d_n_nodes - d_n_used); };
   __INLINE__ void num_used_inc (void) {
     if (d_n_used < d_n_nodes) ++d_n_used;
   };
index 063a2e9c645e55c36fd12f67eb1e8094a75e1b45..8446f044ec633ec6233b48c993b0f1d8da235dd2 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]);
   }
 }
 
@@ -103,40 +116,49 @@ extern char usb_error_str[1024];
 extern int usb_error_errno;
 extern usb_error_type_t usb_error_type;
 
-#define USB_ERROR(r, x)                                \
-       do { \
-          usb_error_type = USB_ERROR_TYPE_ERRNO; \
-          usb_error_errno = x; \
-         return r; \
-       } while (0)
-
-#define USB_ERROR_STR(r, x, format, args...)   \
-       do { \
-         usb_error_type = USB_ERROR_TYPE_STRING; \
-         snprintf(usb_error_str, sizeof(usb_error_str) - 1, format, ## args); \
-          if (usb_debug) \
-            fprintf(stderr, "USB error: %s\n", usb_error_str); \
-         return r; \
-       } while (0)
-
-#define USB_ERROR_STR_ORIG(x, format, args...) \
-       do { \
-         usb_error_type = USB_ERROR_TYPE_STRING; \
-         snprintf(usb_error_str, sizeof(usb_error_str) - 1, format, ## args); \
-          if (usb_debug) \
-            fprintf(stderr, "USB error: %s\n", usb_error_str); \
-         return x; \
-       } while (0)
-
-#define USB_ERROR_STR_NO_RET(x, format, args...)       \
-       do { \
-         usb_error_type = USB_ERROR_TYPE_STRING; \
-         snprintf(usb_error_str, sizeof(usb_error_str) - 1, format, ## args); \
-          if (usb_debug) \
-            fprintf(stderr, "USB error: %s\n", usb_error_str); \
-       } while (0)
-
-/* simple function that figures out what pipeRef is associated with an endpoint */
+#define USB_ERROR(r, x)                                 \
+  do {                                          \
+    usb_error_type = USB_ERROR_TYPE_ERRNO;      \
+    usb_error_errno = x;                        \
+    return (r);                                         \
+  } while (0)
+
+#define USB_ERROR_STR(r, x, format, args...)                           \
+  do {                                                                 \
+    usb_error_type = USB_ERROR_TYPE_STRING;                            \
+    snprintf (usb_error_str, sizeof (usb_error_str) - 1,               \
+             format, ## args);                                         \
+    if (usb_debug) {                                                   \
+      std::cerr << "USB error: " << usb_error_str << std::cerr;                \
+    }                                                                  \
+    return (r);                                                                \
+  } while (0)
+
+#define USB_ERROR_STR_ORIG(x, format, args...)                         \
+  do {                                                                 \
+    usb_error_type = USB_ERROR_TYPE_STRING;                            \
+    snprintf (usb_error_str, sizeof (usb_error_str) - 1,               \
+             format, ## args);                                         \
+    if (usb_debug) {                                                   \
+      std::cerr << "USB error: " << usb_error_str << std::endl;                \
+    }                                                                  \
+    return (x);                                                                \
+  } while (0)
+
+#define USB_ERROR_STR_NO_RET(x, format, args...)                       \
+  do {                                                                 \
+    usb_error_type = USB_ERROR_TYPE_STRING;                            \
+    snprintf (usb_error_str, sizeof (usb_error_str) - 1,               \
+             format, ## args);                                         \
+    if (usb_debug) {                                                   \
+      std::cerr << "USB error: " << usb_error_str << std::endl;                \
+    }                                                                  \
+  } while (0)
+
+/*
+ * simple function that figures out what pipeRef
+ * is associated with an endpoint
+ */
 static int ep_to_pipeRef (darwin_dev_handle *device, int ep)
 {
   io_return_t ret;
@@ -145,45 +167,60 @@ static int ep_to_pipeRef (darwin_dev_handle *device, int ep)
   UInt16 dont_care2;
   int i;
 
-  if (usb_debug > 3)
-    fprintf(stderr, "Converting ep address to pipeRef.\n");
+  if (usb_debug > 3) {
+    std::cerr << "Converting ep address to pipeRef." << std::endl;
+  }
 
   /* retrieve the total number of endpoints on this interface */
   ret = (*(device->interface))->GetNumEndpoints(device->interface, &numep);
   if ( ret ) {
-    if ( usb_debug > 3 )
-      fprintf ( stderr, "ep_to_pipeRef: interface is %p\n", device->interface );
-    USB_ERROR_STR_ORIG ( -ret, "ep_to_pipeRef: can't get number of endpoints for interface" );
+    if ( usb_debug > 3 ) {
+      std::cerr << "ep_to_pipeRef: interface is "
+               << device->interface << std::endl;
+    }
+    USB_ERROR_STR_ORIG ( -ret, "ep_to_pipeRef: can't get number of "
+                        "endpoints for interface" );
   }
 
   /* iterate through the pipeRefs until we find the correct one */
   for (i = 1 ; i <= numep ; i++) {
-    ret = (*(device->interface))->GetPipeProperties(device->interface, i, &direction, &number,
-                                                   &dont_care1, &dont_care2, &dont_care3);
+    ret = (*(device->interface))->GetPipeProperties
+      (device->interface, i, &direction, &number,
+       &dont_care1, &dont_care2, &dont_care3);
 
     if (ret != kIOReturnSuccess) {
-      fprintf (stderr, "ep_to_pipeRef: an error occurred getting pipe information on pipe %d\n",
-              i );
-      USB_ERROR_STR_ORIG (-darwin_to_errno(ret), "ep_to_pipeRef(GetPipeProperties): %s", darwin_error_str(ret));
-    }
+      std::cerr << "ep_to_pipeRef: an error occurred getting "
+               << "pipe information on pipe " << i << std::endl;
 
-    if (usb_debug > 3)
-      fprintf (stderr, "ep_to_pipeRef: Pipe %i: DIR: %i number: %i\n", i, direction, number);
+      USB_ERROR_STR_ORIG (-darwin_to_errno(ret),
+                         "ep_to_pipeRef(GetPipeProperties): %s",
+                         darwin_error_str(ret));
+    }
 
-    /* calculate the endpoint of the pipe and check it versus the requested endpoint */
-    if ( ((direction << 7 & USB_ENDPOINT_DIR_MASK) | (number & USB_ENDPOINT_ADDRESS_MASK)) == ep ) {
-      if (usb_debug > 3)
-       fprintf(stderr, "ep_to_pipeRef: pipeRef for ep address 0x%02x found: 0x%02x\n", ep, i);
+    if (usb_debug > 3) {
+      std::cerr << "ep_to_pipeRef: Pipe " << i << ": DIR: "
+               << direction << " number: " << number << std::endl;
+    }
 
-      return i;
+    /* calculate the endpoint of the pipe and check it versus
+       the requested endpoint */
+    if ( ((direction << 7 & USB_ENDPOINT_DIR_MASK) |
+         (number & USB_ENDPOINT_ADDRESS_MASK)) == ep ) {
+      if (usb_debug > 3) {
+       std::cerr << "ep_to_pipeRef: pipeRef for ep address "
+                 << ep << " found: " << i << std::endl;
+      }
+      return (i);
     }
   }
 
-  if (usb_debug > 3)
-    fprintf(stderr, "ep_to_pipeRef: No pipeRef found with endpoint address 0x%02x.\n", ep);
-  
+  if (usb_debug > 3) {
+    std::cerr << "ep_to_pipeRef: No pipeRef found with endpoint address "
+             << ep << std::endl;
+  }
+
   /* none of the found pipes match the requested endpoint */
-  return -1;
+  return (-1);
 }
 
 }
index 737387b877bc9cac8798ff8a659b856bba3e6123..95c4878aa621b70ca9f1f88b76521023da63b20c 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.
  *
@@ -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,26 +398,27 @@ 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);
-
-// add this read to the transfer buffer
+  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, and check for overflow
+// -> data is being enqueued faster than it can be dequeued
   if (l_buffer->enqueue (l_buf->buffer (), l_size) == -1) {
-    fputs ("iU", stderr);
+// print out that there's an overflow
+    fputs ("uO", stderr);
     fflush (stderr);
   }
 
@@ -421,11 +432,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 +446,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 +489,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 +505,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 +528,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 +538,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 +549,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 +572,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..735e5f16d0548540252f9c7248eea1b1ca0cc8b7 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.
  *
@@ -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,17 +92,17 @@ 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");
+      std::cerr << "s_buffer::set: Copying only allocated bytes." << std::endl;
       bufLen = d_n_alloc;
     }
     if (!l_buffer) {
-      fprintf (stderr, "s_buffer::set: NULL buffer.\n");
+      std::cerr << "s_buffer::set: NULL buffer." << std::endl;
       return;
     }
     bcopy (l_buffer, d_buffer, bufLen);
@@ -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;
 
index 0d685d84f4939a71c83691376ce822be0d924cca..7053786d807926a02dd2df84a54b6d96cbf11a49 100644 (file)
@@ -69,6 +69,7 @@ _get_usb_string_descriptor (struct usb_dev_handle *udh, int index,
     fprintf (stderr, "usrp: usb_get_string_descriptor failed: %s\n",
              usb_strerror());
   }
+
   return ret;
 }