Debian Codegraph @

mtp/backend/haiku/usb/DeviceDescriptor.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_DEVICEDESCRIPTOR_H
21 #define AFTL_MTP_BACKEND_LIBUSB_USB_DEVICEDESCRIPTOR_H
22
23 #include <mtp/types.h>
24 #include <usb/Device.h>
25 #include <usb/Interface.h>
26
27 namespace mtp { namespace usb
28 {
29 class Configuration : Noncopyable
30 {
31 const BUSBConfiguration *_config;
32
33 public:
34 Configuration(const BUSBConfiguration *config) : _config(config) { }
35 ~Configuration() { /* configuration is owned by its parent device */ }
36
37 int GetIndex() const
38 { return _config->Index(); }
39
40 int GetInterfaceCount() const
41 { return _config->CountInterfaces(); }
42
43 int GetInterfaceAltSettingsCount(int idx) const
44 { return _config->InterfaceAt(idx)->CountAlternates(); }
45
46 // TODO figure out what to do with "int settings"
47 InterfacePtr GetInterface(DevicePtr device, ConfigurationPtr config, int idx, int settings) const
48 { return std::make_shared<Interface>(device, config, *_config->InterfaceAt(idx)->AlternateAt(settings)); }
49 };
50
51 class DeviceDescriptor
52 {
53 private:
54 BUSBDevice * _dev;
55
56 public:
57 DeviceDescriptor(BUSBDevice *dev);
58 ~DeviceDescriptor();
59
60 u16 GetVendorId() const
61 { return _dev->VendorID(); }
62
63 u16 GetProductId() const
64 { return _dev->ProductID(); }
65
66 DevicePtr Open(ContextPtr context);
67 DevicePtr TryOpen(ContextPtr context);
68
69 int GetConfigurationsCount() const
70 { return _dev->CountConfigurations(); }
71
72 ConfigurationPtr GetConfiguration(int conf);
73
74 ByteArray GetDescriptor() const;
75 };
76 DECLARE_PTR(DeviceDescriptor);
77
78 }}
79
80 #endif
81