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