GNU Radio 3.4.0 C++ API
|
00001 /* -*- c++ -*- */ 00002 /* 00003 * Copyright 2003,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_LIBUSB1_H_ 00024 #define _FUSB_LIBUSB1_H_ 00025 00026 #include <fusb.h> 00027 #include <list> 00028 00029 struct libusb_transfer; 00030 struct libusb_context; 00031 00032 class fusb_ephandle_libusb1; 00033 00034 /*! 00035 * \brief libusb1 implementation of fusb_devhandle 00036 */ 00037 class fusb_devhandle_libusb1 : public fusb_devhandle 00038 { 00039 private: 00040 std::list<libusb_transfer*> d_pending_rqsts; 00041 libusb_context *d_ctx; 00042 00043 void pending_add (struct libusb_transfer *lut); 00044 struct libusb_transfer * pending_get (); 00045 00046 bool d_teardown; 00047 00048 public: 00049 // CREATORS 00050 fusb_devhandle_libusb1 (libusb_device_handle *udh, libusb_context *ctx); 00051 virtual ~fusb_devhandle_libusb1 (); 00052 00053 // MANIPULATORS 00054 virtual fusb_ephandle *make_ephandle (int endpoint, bool input_p, 00055 int block_size = 0, int nblocks = 0); 00056 // internal use only 00057 bool _submit_lut (libusb_transfer *); 00058 bool _cancel_lut (libusb_transfer *); 00059 void _cancel_pending_rqsts (fusb_ephandle_libusb1 *eph); 00060 bool _reap (bool ok_to_block_p); 00061 void _wait_for_completion (); 00062 00063 // accessors to work from callback context 00064 bool pending_remove (struct libusb_transfer *lut); 00065 inline bool _teardown() { return d_teardown; } 00066 00067 }; 00068 00069 00070 /*! 00071 * \brief libusb1 implementation of fusb_ephandle 00072 */ 00073 class fusb_ephandle_libusb1 : public fusb_ephandle 00074 { 00075 private: 00076 fusb_devhandle_libusb1 *d_devhandle; 00077 std::list<libusb_transfer*> d_free_list; 00078 std::list<libusb_transfer*> d_completed_list; 00079 libusb_transfer *d_write_work_in_progress; 00080 unsigned char *d_write_buffer; 00081 libusb_transfer *d_read_work_in_progress; 00082 unsigned char *d_read_buffer; 00083 unsigned char *d_read_buffer_end; 00084 00085 libusb_transfer *get_write_work_in_progress (); 00086 void reap_complete_writes (); 00087 bool reload_read_buffer (); 00088 bool submit_lut (libusb_transfer *lut); 00089 00090 public: 00091 // CREATORS 00092 fusb_ephandle_libusb1 (fusb_devhandle_libusb1 *dh, int endpoint, bool input_p, 00093 int block_size = 0, int nblocks = 0); 00094 virtual ~fusb_ephandle_libusb1 (); 00095 00096 // MANIPULATORS 00097 00098 virtual bool start (); //!< begin streaming i/o 00099 virtual bool stop (); //!< stop streaming i/o 00100 00101 /*! 00102 * \returns \p nbytes if write was successfully enqueued, else -1. 00103 * Will block if no free buffers available. 00104 */ 00105 virtual int write (const void *buffer, int nbytes); 00106 00107 /*! 00108 * \returns number of bytes read or -1 if error. 00109 * number of bytes read will be <= nbytes. 00110 * Will block if no input available. 00111 */ 00112 virtual int read (void *buffer, int nbytes); 00113 00114 /* 00115 * block until all outstanding writes have completed 00116 */ 00117 virtual void wait_for_completion (); 00118 00119 void free_list_add (struct libusb_transfer *lut); 00120 void completed_list_add (struct libusb_transfer *lut); 00121 struct libusb_transfer *free_list_get (); 00122 struct libusb_transfer *completed_list_get (); 00123 00124 // accessor to work from callback context 00125 fusb_devhandle_libusb1* get_fusb_devhandle_libusb1 () const { 00126 return d_devhandle; 00127 } 00128 }; 00129 00130 #endif /* _FUSB_LINUX1_H_ */ 00131