mirror of https://gerrit.osmocom.org/libusrp
moved all 'fprintf (stderr, ...)' calls to std::cerr, for 'universal' OSX printing of long and pointer types
This commit is contained in:
parent
0001665212
commit
d04f732630
|
@ -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
|
||||
|
@ -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 () {
|
||||
|
@ -150,13 +151,14 @@ public:
|
|||
*/
|
||||
|
||||
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););
|
||||
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,21 +177,21 @@ 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;
|
||||
}
|
||||
}
|
||||
|
@ -233,9 +235,10 @@ public:
|
|||
*/
|
||||
|
||||
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););
|
||||
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");
|
||||
|
@ -246,9 +249,9 @@ public:
|
|||
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,29 +262,29 @@ 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)
|
||||
|
|
|
@ -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;
|
||||
};
|
||||
|
|
|
@ -116,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(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(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) \
|
||||
fprintf(stderr, "USB error: %s\n", usb_error_str); \
|
||||
return x; \
|
||||
} 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) \
|
||||
fprintf(stderr, "USB error: %s\n", usb_error_str); \
|
||||
} 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 */
|
||||
/*
|
||||
* 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;
|
||||
|
@ -158,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;
|
||||
|
||||
USB_ERROR_STR_ORIG (-darwin_to_errno(ret),
|
||||
"ep_to_pipeRef(GetPipeProperties): %s",
|
||||
darwin_error_str(ret));
|
||||
}
|
||||
|
||||
if (usb_debug > 3)
|
||||
fprintf (stderr, "ep_to_pipeRef: Pipe %i: DIR: %i number: %i\n", i, direction, number);
|
||||
if (usb_debug > 3) {
|
||||
std::cerr << "ep_to_pipeRef: Pipe " << i << ": DIR: "
|
||||
<< direction << " number: " << number << std::endl;
|
||||
}
|
||||
|
||||
/* 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);
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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.
|
||||
*
|
||||
|
@ -414,9 +414,11 @@ fusb_ephandle_darwin::read_completed (void* refCon,
|
|||
<< " (" << l_size << " bytes)" << std::endl;
|
||||
}
|
||||
|
||||
// add this read to the transfer buffer
|
||||
// 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);
|
||||
}
|
||||
|
||||
|
|
|
@ -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.
|
||||
*
|
||||
|
@ -98,11 +98,11 @@ public:
|
|||
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);
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
int
|
||||
|
@ -82,6 +83,8 @@ _usb_control_transfer (struct usb_dev_handle *udh, int request_type,
|
|||
(char*) data, length, (int) timeout);
|
||||
if (ret < 0)
|
||||
fprintf (stderr, "usrp: usb_claim_interface failed: %s\n", usb_strerror());
|
||||
|
||||
return (ret);
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue