00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
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
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
00050 fusb_devhandle_libusb1 (libusb_device_handle *udh, libusb_context *ctx);
00051 virtual ~fusb_devhandle_libusb1 ();
00052
00053
00054 virtual fusb_ephandle *make_ephandle (int endpoint, bool input_p,
00055 int block_size = 0, int nblocks = 0);
00056
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
00064 bool pending_remove (struct libusb_transfer *lut);
00065 inline bool _teardown() { return d_teardown; }
00066
00067 };
00068
00069
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
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
00097
00098 virtual bool start ();
00099 virtual bool stop ();
00100
00105 virtual int write (const void *buffer, int nbytes);
00106
00112 virtual int read (void *buffer, int nbytes);
00113
00114
00115
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
00125 fusb_devhandle_libusb1* get_fusb_devhandle_libusb1 () const {
00126 return d_devhandle;
00127 }
00128 };
00129
00130 #endif
00131