Debian Codegraph @

mtp/backend/haiku/usb/Device.h

raw
1 /*
2 This file is part of Android File Transfer For Linux.
3 Copyright (C) 2015-2020 Vladimir Menshakov
4
5 This library is free software; you can redistribute it and/or modify it
6 under the terms of the GNU Lesser General Public License as published by
7 the Free Software Foundation; either version 2.1 of the License,
8 or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful, but
11 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 License
16 along with this library; if not, write to the Free Software Foundation,
17 Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 */
19
20 #ifndef AFTL_MTP_BACKEND_LIBUSB_USB_DEVICE_H
21 #define AFTL_MTP_BACKEND_LIBUSB_USB_DEVICE_H
22
23 #include <mtp/ptp/IObjectStream.h>
24 #include <mtp/ByteArray.h>
25 #include <mtp/Token.h>
26 #include <mtp/types.h>
27 #include <mtp/usb/types.h>
28 #include <device/USBKit.h>
29
30 namespace mtp { namespace usb
31 {
32 class Context;
33 DECLARE_PTR(Context);
34
35 class Endpoint
36 {
37 const BUSBEndpoint & _endpoint;
38
39 public:
40 Endpoint(const BUSBEndpoint & endpoint) : _endpoint(endpoint) { }
41
42 u8 GetAddress() const
43 { return _endpoint.Index(); }
44
45 int GetMaxPacketSize() const
46 { return _endpoint.MaxPacketSize(); }
47
48 EndpointDirection GetDirection() const
49 {
50 if (_endpoint.IsInput())
51 return EndpointDirection::In;
52 else
53 return EndpointDirection::Out;
54 }
55
56 EndpointType GetType() const
57 {
58 if (_endpoint.IsBulk())
59 return EndpointType::Bulk;
60 if (_endpoint.IsInterrupt())
61 return EndpointType::Interrupt;
62 if (_endpoint.IsIsochronous())
63 return EndpointType::Isochronous;
64 return EndpointType::Control;
65 }
66
67 friend class Device;
68 };
69 DECLARE_PTR(Endpoint);
70
71 class Interface;
72 DECLARE_PTR(Interface);
73 class InterfaceToken;
74 DECLARE_PTR(InterfaceToken);
75
76 class Device : Noncopyable
77 {
78 private:
79 ContextPtr _context;
80 BUSBDevice * _handle;
81
82 public:
83 Device(ContextPtr ctx, BUSBDevice * handle);
84 ~Device();
85
86 BUSBDevice * GetHandle()
87 { return _handle; }
88
89 InterfaceTokenPtr ClaimInterface(const InterfacePtr & interface);
90
91 void Reset();
92 int GetConfiguration() const;
93 void SetConfiguration(int idx);
94
95 void WriteBulk(const EndpointPtr & ep, const IObjectInputStreamPtr &inputStream, int timeout);
96 void ReadBulk(const EndpointPtr & ep, const IObjectOutputStreamPtr &outputStream, int timeout);
97
98 void ReadControl(u8 type, u8 req, u16 value, u16 index, ByteArray &data, int timeout);
99 void WriteControl(u8 type, u8 req, u16 value, u16 index, const ByteArray &data, int timeout);
100
101 void ClearHalt(const EndpointPtr & ep);
102
103 std::string GetString(int idx) const;
104 };
105 DECLARE_PTR(Device);
106 }}
107
108 #endif /* DEVICE_H */
109