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_
26 #include <fusb_libusb1_base.h>
29 struct libusb_transfer;
30 struct libusb_context;
32 class fusb_ephandle_libusb1;
35 * \brief libusb1 implementation of fusb_devhandle
37 class fusb_devhandle_libusb1 : public fusb_devhandle
40 std::list<libusb_transfer*> d_pending_rqsts;
41 libusb_context *d_ctx;
43 void pending_add (struct libusb_transfer *lut);
44 struct libusb_transfer * pending_get ();
50 fusb_devhandle_libusb1 (libusb_device_handle *udh, libusb_context *ctx);
51 virtual ~fusb_devhandle_libusb1 ();
54 virtual fusb_ephandle *make_ephandle (int endpoint, bool input_p,
55 int block_size = 0, int nblocks = 0);
57 bool _submit_lut (libusb_transfer *);
58 bool _cancel_lut (libusb_transfer *);
59 void _cancel_pending_rqsts (fusb_ephandle_libusb1 *eph);
60 bool _reap (bool ok_to_block_p);
61 void _wait_for_completion ();
63 // accessors to work from callback context
64 bool pending_remove (struct libusb_transfer *lut);
65 inline bool _teardown() { return d_teardown; }
71 * \brief libusb1 implementation of fusb_ephandle
73 class fusb_ephandle_libusb1 : public fusb_ephandle
76 fusb_devhandle_libusb1 *d_devhandle;
77 std::list<libusb_transfer*> d_free_list;
78 std::list<libusb_transfer*> d_completed_list;
79 libusb_transfer *d_write_work_in_progress;
80 unsigned char *d_write_buffer;
81 libusb_transfer *d_read_work_in_progress;
82 unsigned char *d_read_buffer;
83 unsigned char *d_read_buffer_end;
85 libusb_transfer *get_write_work_in_progress ();
86 void reap_complete_writes ();
87 bool reload_read_buffer ();
88 bool submit_lut (libusb_transfer *lut);
92 fusb_ephandle_libusb1 (fusb_devhandle_libusb1 *dh, int endpoint, bool input_p,
93 int block_size = 0, int nblocks = 0);
94 virtual ~fusb_ephandle_libusb1 ();
98 virtual bool start (); //!< begin streaming i/o
99 virtual bool stop (); //!< stop streaming i/o
102 * \returns \p nbytes if write was successfully enqueued, else -1.
103 * Will block if no free buffers available.
105 virtual int write (const void *buffer, int nbytes);
108 * \returns number of bytes read or -1 if error.
109 * number of bytes read will be <= nbytes.
110 * Will block if no input available.
112 virtual int read (void *buffer, int nbytes);
115 * block until all outstanding writes have completed
117 virtual void wait_for_completion ();
119 void free_list_add (struct libusb_transfer *lut);
120 void completed_list_add (struct libusb_transfer *lut);
121 struct libusb_transfer *free_list_get ();
122 struct libusb_transfer *completed_list_get ();
124 // accessor to work from callback context
125 fusb_devhandle_libusb1* get_fusb_devhandle_libusb1 () const {
130 #endif /* _FUSB_LINUX1_H_ */