Added copyright header
[debian/gnuradio] / usrp / host / lib / fusb.h
1 /* -*- c++ -*- */
2 /*
3  * Copyright 2003 Free Software Foundation, Inc.
4  * 
5  * This file is part of GNU Radio
6  * 
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)
10  * any later version.
11  * 
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.
16  * 
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.
21  */
22
23 // Fast USB interface
24
25 #ifndef _FUSB_H_
26 #define _FUSB_H_
27
28 struct  usb_dev_handle;
29 typedef usb_dev_handle libusb_device_handle;
30
31 struct  libusb_context;
32 class   fusb_ephandle;
33
34 /*!
35  * \brief abstract usb device handle
36  */
37 class fusb_devhandle {
38 private:
39   // NOT IMPLEMENTED
40   fusb_devhandle (const fusb_devhandle &rhs);             // no copy constructor
41   fusb_devhandle &operator= (const fusb_devhandle &rhs);  // no assignment operator
42
43 protected:
44   libusb_device_handle          *d_udh;
45
46 public:
47   // CREATORS
48   fusb_devhandle (libusb_device_handle *udh);
49   virtual ~fusb_devhandle ();
50
51   // MANIPULATORS
52   
53   /*!
54    * \brief return an ephandle of the correct subtype
55    */
56   virtual fusb_ephandle *make_ephandle (int endpoint, bool input_p,
57                                         int block_size = 0, int nblocks = 0) = 0;
58   
59   // ACCESSORS
60   libusb_device_handle *get_usb_dev_handle () const { return d_udh; }
61 };
62
63
64 /*!
65  * \brief abstract usb end point handle
66  */
67 class fusb_ephandle {
68 private:
69   // NOT IMPLEMENTED
70   fusb_ephandle (const fusb_ephandle &rhs);             // no copy constructor
71   fusb_ephandle &operator= (const fusb_ephandle &rhs);  // no assignment operator
72
73 protected:
74   int                           d_endpoint;
75   bool                          d_input_p;
76   int                           d_block_size;
77   int                           d_nblocks;
78   bool                          d_started;
79
80 public:
81   fusb_ephandle (int endpoint, bool input_p,
82                  int block_size = 0, int nblocks = 0);
83   virtual ~fusb_ephandle ();
84
85   virtual bool start () = 0;    //!< begin streaming i/o
86   virtual bool stop () = 0;     //!< stop streaming i/o
87
88   /*!
89    * \returns \p nbytes if write was successfully enqueued, else -1.
90    * Will block if no free buffers available.
91    */
92   virtual int write (const void *buffer, int nbytes) = 0;
93
94   /*!
95    * \returns number of bytes read or -1 if error.
96    * number of bytes read will be <= nbytes.
97    * Will block if no input available.
98    */
99   virtual int read (void *buffer, int nbytes) = 0;
100
101   /*
102    * block until all outstanding writes have completed
103    */
104   virtual void wait_for_completion () = 0;
105
106   /*!
107    * \brief returns current block size.
108    */
109   int block_size () { return d_block_size; };
110 };
111
112
113 /*!
114  * \brief factory for creating concrete instances of the appropriate subtype.
115  */
116 class fusb_sysconfig {
117 public:
118   /*!
119    * \brief returns fusb_devhandle or throws if trouble
120    */
121   static fusb_devhandle *make_devhandle (libusb_device_handle *udh,
122                                          libusb_context *ctx = 0);
123
124   /*!
125    * \brief Returns max block size in bytes (hard limit).
126    */
127   static int max_block_size ();
128
129   /*!
130    * \brief Returns default block size in bytes.
131    */
132   static int default_block_size ();
133
134   /*!
135    * \brief Returns the default buffer size in bytes.
136    */
137   static int default_buffer_size ();
138
139 };
140
141 #endif /* _FUSB_H_ */