3 * Copyright 2003 Free Software Foundation, Inc.
5 * This file is part of GNU Radio
7 * GNU Radio is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 3, or (at your option)
12 * GNU Radio is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with GNU Radio; see the file COPYING. If not, write to
19 * the Free Software Foundation, Inc., 51 Franklin Street,
20 * Boston, MA 02110-1301, USA.
23 #ifndef _FUSB_LIBUSB1_H_
24 #define _FUSB_LIBUSB1_H_
29 struct libusb_transfer;
30 class fusb_ephandle_libusb1;
33 * \brief libusb1 implementation of fusb_devhandle
35 class fusb_devhandle_libusb1 : public fusb_devhandle
38 std::list<libusb_transfer*> d_pending_rqsts;
40 void pending_add (struct libusb_transfer *lut);
41 struct libusb_transfer * pending_get ();
47 fusb_devhandle_libusb1 (libusb_device_handle *udh);
48 virtual ~fusb_devhandle_libusb1 ();
51 virtual fusb_ephandle *make_ephandle (int endpoint, bool input_p,
52 int block_size = 0, int nblocks = 0);
54 bool _submit_lut (libusb_transfer *);
55 bool _cancel_lut (libusb_transfer *);
56 void _cancel_pending_rqsts (fusb_ephandle_libusb1 *eph);
57 void _wait_for_completion ();
59 // accessors to work from callback context
60 bool pending_remove (struct libusb_transfer *lut);
61 inline bool _teardown() { return d_teardown; }
67 * \brief libusb1 implementation of fusb_ephandle
69 class fusb_ephandle_libusb1 : public fusb_ephandle
72 fusb_devhandle_libusb1 *d_devhandle;
73 std::list<libusb_transfer*> d_free_list;
74 std::list<libusb_transfer*> d_completed_list;
75 libusb_transfer *d_write_work_in_progress;
76 unsigned char *d_write_buffer;
77 libusb_transfer *d_read_work_in_progress;
78 unsigned char *d_read_buffer;
79 unsigned char *d_read_buffer_end;
81 libusb_transfer *get_write_work_in_progress ();
82 void reap_complete_writes ();
83 bool reload_read_buffer ();
84 bool submit_lut (libusb_transfer *lut);
88 fusb_ephandle_libusb1 (fusb_devhandle_libusb1 *dh, int endpoint, bool input_p,
89 int block_size = 0, int nblocks = 0);
90 virtual ~fusb_ephandle_libusb1 ();
94 virtual bool start (); //!< begin streaming i/o
95 virtual bool stop (); //!< stop streaming i/o
98 * \returns \p nbytes if write was successfully enqueued, else -1.
99 * Will block if no free buffers available.
101 virtual int write (const void *buffer, int nbytes);
104 * \returns number of bytes read or -1 if error.
105 * number of bytes read will be <= nbytes.
106 * Will block if no input available.
108 virtual int read (void *buffer, int nbytes);
111 * block until all outstanding writes have completed
113 virtual void wait_for_completion ();
115 void free_list_add (struct libusb_transfer *lut);
116 void completed_list_add (struct libusb_transfer *lut);
117 struct libusb_transfer *free_list_get ();
118 struct libusb_transfer *completed_list_get ();
120 // accessor to work from callback context
121 fusb_devhandle_libusb1* get_fusb_devhandle_libusb1 () const {
126 #endif /* _FUSB_LINUX1_H_ */