fusb.h

Go to the documentation of this file.
00001 /* -*- c++ -*- */
00002 /*
00003  * Copyright 2003 Free Software Foundation, Inc.
00004  * 
00005  * This file is part of GNU Radio
00006  * 
00007  * GNU Radio is free software; you can redistribute it and/or modify
00008  * it under the terms of the GNU General Public License as published by
00009  * the Free Software Foundation; either version 3, or (at your option)
00010  * any later version.
00011  * 
00012  * GNU Radio is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  * GNU General Public License for more details.
00016  * 
00017  * You should have received a copy of the GNU General Public License
00018  * along with GNU Radio; see the file COPYING.  If not, write to
00019  * the Free Software Foundation, Inc., 51 Franklin Street,
00020  * Boston, MA 02110-1301, USA.
00021  */
00022 
00023 // Fast USB interface
00024 
00025 #ifndef _FUSB_H_
00026 #define _FUSB_H_
00027 
00028 
00029 struct  usb_dev_handle;
00030 class   fusb_ephandle;
00031 
00032 /*!
00033  * \brief abstract usb device handle
00034  */
00035 class fusb_devhandle {
00036 private:
00037   // NOT IMPLEMENTED
00038   fusb_devhandle (const fusb_devhandle &rhs);             // no copy constructor
00039   fusb_devhandle &operator= (const fusb_devhandle &rhs);  // no assignment operator
00040 
00041 protected:
00042   usb_dev_handle                *d_udh;
00043 
00044 public:
00045   // CREATORS
00046   fusb_devhandle (usb_dev_handle *udh);
00047   virtual ~fusb_devhandle ();
00048 
00049   // MANIPULATORS
00050   
00051   /*!
00052    * \brief return an ephandle of the correct subtype
00053    */
00054   virtual fusb_ephandle *make_ephandle (int endpoint, bool input_p,
00055                                         int block_size = 0, int nblocks = 0) = 0;
00056   
00057   // ACCESSORS
00058   usb_dev_handle *get_usb_dev_handle () const { return d_udh; }
00059 };
00060 
00061 
00062 /*!
00063  * \brief abstract usb end point handle
00064  */
00065 class fusb_ephandle {
00066 private:
00067   // NOT IMPLEMENTED
00068   fusb_ephandle (const fusb_ephandle &rhs);             // no copy constructor
00069   fusb_ephandle &operator= (const fusb_ephandle &rhs);  // no assignment operator
00070 
00071 protected:
00072   int                           d_endpoint;
00073   bool                          d_input_p;
00074   int                           d_block_size;
00075   int                           d_nblocks;
00076   bool                          d_started;
00077 
00078 public:
00079   fusb_ephandle (int endpoint, bool input_p,
00080                  int block_size = 0, int nblocks = 0);
00081   virtual ~fusb_ephandle ();
00082 
00083   virtual bool start () = 0;    //!< begin streaming i/o
00084   virtual bool stop () = 0;     //!< stop streaming i/o
00085 
00086   /*!
00087    * \returns \p nbytes if write was successfully enqueued, else -1.
00088    * Will block if no free buffers available.
00089    */
00090   virtual int write (const void *buffer, int nbytes) = 0;
00091 
00092   /*!
00093    * \returns number of bytes read or -1 if error.
00094    * number of bytes read will be <= nbytes.
00095    * Will block if no input available.
00096    */
00097   virtual int read (void *buffer, int nbytes) = 0;
00098 
00099   /*
00100    * block until all outstanding writes have completed
00101    */
00102   virtual void wait_for_completion () = 0;
00103 
00104   /*!
00105    * \brief returns current block size.
00106    */
00107   int block_size () { return d_block_size; };
00108 };
00109 
00110 
00111 /*!
00112  * \brief factory for creating concrete instances of the appropriate subtype.
00113  */
00114 class fusb_sysconfig {
00115 public:
00116   /*!
00117    * \brief returns fusb_devhandle or throws if trouble
00118    */
00119   static fusb_devhandle *make_devhandle (usb_dev_handle *udh);
00120 
00121   /*!
00122    * \brief Returns max block size in bytes (hard limit).
00123    */
00124   static int max_block_size ();
00125 
00126   /*!
00127    * \brief Returns default block size in bytes.
00128    */
00129   static int default_block_size ();
00130 
00131   /*!
00132    * \brief Returns the default buffer size in bytes.
00133    */
00134   static int default_buffer_size ();
00135 
00136 };
00137 
00138 #endif /* _FUSB_H_ */

Generated on Wed Jul 29 07:24:32 2009 for GNU Radio 3.2.2 C++ API by  doxygen 1.5.8