Statistics
| Branch: | Tag: | Revision:

root / host / lib / transport / libusb1_base.hpp @ dc8bcfde

History | View | Annotate | Download (4.4 KB)

1
//
2
// Copyright 2010 Ettus Research LLC
3
//
4
// This program is free software: you can redistribute it and/or modify
5
// it under the terms of the GNU General Public License as published by
6
// the Free Software Foundation, either version 3 of the License, or
7
// (at your option) any later version.
8
//
9
// This program is distributed in the hope that it will be useful,
10
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
// GNU General Public License for more details.
13
//
14
// You should have received a copy of the GNU General Public License
15
// along with this program.  If not, see <http://www.gnu.org/licenses/>.
16
//
17

    
18
#ifndef INCLUDED_LIBUHD_TRANSPORT_LIBUSB_HPP
19
#define INCLUDED_LIBUHD_TRANSPORT_LIBUSB_HPP
20

    
21
#include <uhd/config.hpp>
22
#include <boost/utility.hpp>
23
#include <boost/shared_ptr.hpp>
24
#include <uhd/transport/usb_device_handle.hpp>
25
#include <libusb-1.0/libusb.h>
26

    
27
namespace uhd { namespace transport {
28

    
29
namespace libusb {
30

    
31
    /*!
32
     * This session class holds a global libusb context for this process.
33
     * The get global session call will create a new context if none exists.
34
     * When all references to session are destroyed, the context will be freed.
35
     */
36
    class session : boost::noncopyable {
37
    public:
38
        typedef boost::shared_ptr<session> sptr;
39

    
40
        /*!
41
         *   Level 0: no messages ever printed by the library (default)
42
         *   Level 1: error messages are printed to stderr
43
         *   Level 2: warning and error messages are printed to stderr
44
         *   Level 3: informational messages are printed to stdout, warning
45
         *            and error messages are printed to stderr
46
         */
47
        static const int debug_level = 0;
48

    
49
        //! get a shared pointer to the global session
50
        static sptr get_global_session(void);
51

    
52
        //! get the underlying libusb context pointer
53
        virtual libusb_context *get_context(void) const = 0;
54
    };
55

    
56
    /*!
57
     * Holds a device pointer with a reference to the session.
58
     */
59
    class device : boost::noncopyable {
60
    public:
61
        typedef boost::shared_ptr<device> sptr;
62

    
63
        //! get the underlying device pointer
64
        virtual libusb_device *get(void) const = 0;
65
    };
66

    
67
    /*!
68
     * This device list class holds a device list that will be
69
     * automatically freed when the last reference is destroyed.
70
     */
71
    class device_list : boost::noncopyable {
72
    public:
73
        typedef boost::shared_ptr<device_list> sptr;
74

    
75
        //! make a new device list
76
        static sptr make(void);
77

    
78
        //! the number of devices in this list
79
        virtual size_t size() const = 0;
80

    
81
        //! get the device pointer at a particular index
82
        virtual device::sptr at(size_t index) const = 0;
83
    };
84

    
85
    /*!
86
     * Holds a device descriptor and a reference to the device.
87
     */
88
    class device_descriptor : boost::noncopyable {
89
    public:
90
        typedef boost::shared_ptr<device_descriptor> sptr;
91

    
92
        //! make a new descriptor from a device reference
93
        static sptr make(device::sptr);
94

    
95
        //! get the underlying device descriptor
96
        virtual const libusb_device_descriptor &get(void) const = 0;
97

    
98
        virtual std::string get_ascii_serial(void) const = 0;
99
    };
100

    
101
    /*!
102
     * Holds a device handle and a reference to the device.
103
     */
104
    class device_handle : boost::noncopyable {
105
    public:
106
        typedef boost::shared_ptr<device_handle> sptr;
107

    
108
        //! get a cached handle or make a new one given the device
109
        static sptr get_cached_handle(device::sptr);
110

    
111
        //! get the underlying device handle
112
        virtual libusb_device_handle *get(void) const = 0;
113

    
114
        /*!
115
         * Open USB interfaces for control using magic value
116
         * IN interface:      2
117
         * OUT interface:     1
118
         * Control interface: 0
119
         */
120
        virtual void claim_interface(int) = 0;
121
    };
122

    
123
    /*!
124
     * The special handle is our internal implementation of the
125
     * usb device handle which is used publicly to identify a device.
126
     */
127
    class special_handle : public usb_device_handle {
128
    public:
129
        typedef boost::shared_ptr<special_handle> sptr;
130

    
131
        //! make a new special handle from device
132
        static sptr make(device::sptr);
133

    
134
        //! get the underlying device reference
135
        virtual device::sptr get_device(void) const = 0;
136
    };
137

    
138
}
139

    
140
}} //namespace
141

    
142
#endif /* INCLUDED_LIBUHD_TRANSPORT_LIBUSB_HPP */