GNU Radio 3.3.0 C++ API
|
00001 /* -*- c++ -*- */ 00002 /* 00003 * Copyright 2005,2009 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 #ifndef _FUSB_H_ 00024 #define _FUSB_H_ 00025 00026 #include <usrp/libusb_types.h> 00027 00028 struct libusb_context; 00029 class fusb_ephandle; 00030 00031 /*! 00032 * \brief abstract usb device handle 00033 */ 00034 class fusb_devhandle { 00035 private: 00036 // NOT IMPLEMENTED 00037 fusb_devhandle (const fusb_devhandle &rhs); // no copy constructor 00038 fusb_devhandle &operator= (const fusb_devhandle &rhs); // no assignment operator 00039 00040 protected: 00041 libusb_device_handle *d_udh; 00042 00043 public: 00044 // CREATORS 00045 fusb_devhandle (libusb_device_handle *udh); 00046 virtual ~fusb_devhandle (); 00047 00048 // MANIPULATORS 00049 00050 /*! 00051 * \brief return an ephandle of the correct subtype 00052 */ 00053 virtual fusb_ephandle *make_ephandle (int endpoint, bool input_p, 00054 int block_size = 0, int nblocks = 0) = 0; 00055 00056 // ACCESSORS 00057 libusb_device_handle *get_usb_dev_handle () const { return d_udh; } 00058 }; 00059 00060 00061 /*! 00062 * \brief abstract usb end point handle 00063 */ 00064 class fusb_ephandle { 00065 private: 00066 // NOT IMPLEMENTED 00067 fusb_ephandle (const fusb_ephandle &rhs); // no copy constructor 00068 fusb_ephandle &operator= (const fusb_ephandle &rhs); // no assignment operator 00069 00070 protected: 00071 int d_endpoint; 00072 bool d_input_p; 00073 int d_block_size; 00074 int d_nblocks; 00075 bool d_started; 00076 00077 public: 00078 fusb_ephandle (int endpoint, bool input_p, 00079 int block_size = 0, int nblocks = 0); 00080 virtual ~fusb_ephandle (); 00081 00082 virtual bool start () = 0; //!< begin streaming i/o 00083 virtual bool stop () = 0; //!< stop streaming i/o 00084 00085 /*! 00086 * \returns \p nbytes if write was successfully enqueued, else -1. 00087 * Will block if no free buffers available. 00088 */ 00089 virtual int write (const void *buffer, int nbytes) = 0; 00090 00091 /*! 00092 * \returns number of bytes read or -1 if error. 00093 * number of bytes read will be <= nbytes. 00094 * Will block if no input available. 00095 */ 00096 virtual int read (void *buffer, int nbytes) = 0; 00097 00098 /* 00099 * block until all outstanding writes have completed 00100 */ 00101 virtual void wait_for_completion () = 0; 00102 00103 /*! 00104 * \brief returns current block size. 00105 */ 00106 int block_size () { return d_block_size; }; 00107 }; 00108 00109 00110 /*! 00111 * \brief factory for creating concrete instances of the appropriate subtype. 00112 */ 00113 class fusb_sysconfig { 00114 public: 00115 /*! 00116 * \brief returns fusb_devhandle or throws if trouble 00117 */ 00118 static fusb_devhandle *make_devhandle (libusb_device_handle *udh, 00119 libusb_context *ctx = 0); 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_ */