Debian Codegraph @

libusb/os/haiku_usb.h

raw
1 /*
2 * Haiku Backend for libusb
3 * Copyright © 2014 Akshay Jaggi <[email protected]>
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18 */
19
20 #include <List.h>
21 #include <Locker.h>
22 #include <Autolock.h>
23 #include <USBKit.h>
24 #include <map>
25 #include "libusbi.h"
26 #include "haiku_usb_raw.h"
27
28 using namespace std;
29
30 class USBDevice;
31 class USBDeviceHandle;
32 class USBTransfer;
33
34 class USBDevice {
35 public:
36 USBDevice(const char *);
37 virtual ~USBDevice();
38 const char* Location() const;
39 uint8 CountConfigurations() const;
40 const usb_device_descriptor* Descriptor() const;
41 const usb_configuration_descriptor* ConfigurationDescriptor(uint8) const;
42 const usb_configuration_descriptor* ActiveConfiguration() const;
43 uint8 EndpointToIndex(uint8) const;
44 uint8 EndpointToInterface(uint8) const;
45 int ClaimInterface(uint8);
46 int ReleaseInterface(uint8);
47 int CheckInterfacesFree(uint8);
48 void SetActiveConfiguration(uint8);
49 uint8 ActiveConfigurationIndex() const;
50 bool InitCheck();
51 private:
52 int Initialise();
53 unsigned int fClaimedInterfaces; // Max Interfaces can be 32. Using a bitmask
54 usb_device_descriptor fDeviceDescriptor;
55 unsigned char** fConfigurationDescriptors;
56 uint8 fActiveConfiguration;
57 char* fPath;
58 map<uint8,uint8> fConfigToIndex;
59 map<uint8,uint8>* fEndpointToIndex;
60 map<uint8,uint8>* fEndpointToInterface;
61 bool fInitCheck;
62 };
63
64 class USBDeviceHandle {
65 public:
66 USBDeviceHandle(USBDevice *dev);
67 virtual ~USBDeviceHandle();
68 int ClaimInterface(uint8);
69 int ReleaseInterface(uint8);
70 int SetConfiguration(uint8);
71 int SetAltSetting(uint8, uint8);
72 int ClearHalt(uint8);
73 status_t SubmitTransfer(struct usbi_transfer *);
74 status_t CancelTransfer(USBTransfer *);
75 bool InitCheck();
76 private:
77 int fRawFD;
78 static status_t TransfersThread(void *);
79 void TransfersWorker();
80 USBDevice* fUSBDevice;
81 unsigned int fClaimedInterfaces;
82 BList fTransfers;
83 BLocker fTransfersLock;
84 sem_id fTransfersSem;
85 thread_id fTransfersThread;
86 bool fInitCheck;
87 };
88
89 class USBTransfer {
90 public:
91 USBTransfer(struct usbi_transfer *, USBDevice *);
92 virtual ~USBTransfer();
93 void Do(int);
94 struct usbi_transfer* UsbiTransfer();
95 void SetCancelled();
96 bool IsCancelled();
97 private:
98 struct usbi_transfer* fUsbiTransfer;
99 struct libusb_transfer* fLibusbTransfer;
100 USBDevice* fUSBDevice;
101 BLocker fStatusLock;
102 bool fCancelled;
103 };
104
105 class USBRoster {
106 public:
107 USBRoster();
108 virtual ~USBRoster();
109 int Start();
110 void Stop();
111 private:
112 void* fLooper;
113 };