Changeset 9214

Show
Ignore:
Timestamp:
08/08/08 11:15:12
Author:
jcorgan
Message:

Better fix for detecting file error.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • usrp2/trunk/host-ng/apps/rx_streaming_samples.cc

    r9210 r9214  
    6767 
    6868protected: 
    69   bool         *d_err; 
     69  bool          d_err; 
    7070   
    7171public: 
    7272   
    73   rx_nop_handler(size_t max_samples, bool *err=0
    74     : d_max_samples(max_samples), d_nsamples(0), d_nframes(0), d_err(err) {} 
     73  rx_nop_handler(size_t max_samples
     74    : d_max_samples(max_samples), d_nsamples(0), d_nframes(0), d_err(false) {} 
    7575       
    7676  ~rx_nop_handler(); 
     
    7979  size_t nsamples() const { return d_nsamples; } 
    8080  size_t max_samples() const { return d_max_samples; } 
    81  
     81  bool   has_errored_p() const { return d_err; } 
     82  bool   has_finished_p() const  
     83    { return d_max_samples == 0 ? false : d_nsamples >= d_max_samples; } 
     84     
    8285  bool  
    8386  operator()(const uint32_t *items, size_t nitems, const usrp2::rx_metadata *metadata) 
     
    8992    d_nframes++; 
    9093 
    91     if (d_max_samples != 0) 
    92         return d_nsamples < d_max_samples; 
    93  
    94     return true;         
     94    return !has_finished_p(); 
    9595  } 
    9696}; 
     
    112112public: 
    113113 
    114   complex_16_file_writer(const std::string &filename, size_t max_samples, bool *err=0
    115     : rx_nop_handler(max_samples, err), d_filename(filename) 
     114  complex_16_file_writer(const std::string &filename, size_t max_samples
     115    : rx_nop_handler(max_samples), d_filename(filename) 
    116116  { 
    117117    d_fp = fopen(filename.c_str(), "wb"); 
     
    139139      n += r; 
    140140      if (r == 0){      // out of space? 
    141         if (d_err) 
    142             *d_err = true; 
     141        d_err = true; 
    143142        perror(d_filename.c_str()); 
    144143        ok = false; 
     
    165164public: 
    166165 
    167   complex_float_file_writer(const std::string &filename, size_t max_samples, bool *err=0
    168     : rx_nop_handler(max_samples, err), d_filename(filename) 
     166  complex_float_file_writer(const std::string &filename, size_t max_samples
     167    : rx_nop_handler(max_samples), d_filename(filename) 
    169168  { 
    170169    d_fp = fopen(filename.c_str(), "wb"); 
     
    192191      n += r; 
    193192      if (r == 0){      // out of space? 
    194         if (d_err) 
    195           *d_err = true; 
     193        d_err = true; 
    196194        perror(d_filename.c_str()); 
    197195        ok = false; 
     
    254252  int ch; 
    255253 
    256   while ((ch = getopt(argc, argv, "he:m:f:d:g:No:sv")) != EOF){ 
     254  while ((ch = getopt(argc, argv, "he:m:f:d:g:N:o:sv")) != EOF){ 
    257255    double tmp; 
    258256    switch (ch){ 
     
    292290 
    293291    case 'N': 
     292      printf("In 'N' clause: optarg=%p &tmp=%p\n", optarg, &tmp); 
    294293      if (!strtod_si(optarg, &tmp)) { 
    295294        std::cerr << "invalid number: " << optarg << std::endl; 
     
    337336  handler_sptr handler; 
    338337 
    339   bool file_err = false; 
    340338  if (output_filename){ 
    341339    if (output_shorts) 
    342       handler = handler_sptr(new complex_16_file_writer(output_filename, nsamples, &file_err)); 
     340      handler = handler_sptr(new complex_16_file_writer(output_filename, nsamples)); 
    343341    else 
    344       handler = handler_sptr(new complex_float_file_writer(output_filename, nsamples, &file_err)); 
     342      handler = handler_sptr(new complex_float_file_writer(output_filename, nsamples)); 
    345343  } 
    346344  else 
     
    400398  gettimeofday(&start, 0); 
    401399 
    402   while(!signaled && !file_err &&  
    403         (handler->max_samples() == 0 || handler->nsamples() < handler->max_samples())){ 
     400  while (!signaled &&  
     401         !handler->has_errored_p() &&  
     402         !handler->has_finished_p()) { 
    404403    bool ok = u2->rx_samples(0, handler.get()); 
    405404    if (!ok){