Debian Codegraph @

mtp/backend/haiku/usb/DeviceDescriptor.cpp

raw
1 /*
2 * DeviceDescriptor.cpp
3 * Copyright (C) 2022 pulkomandy <pulkomandy@shredder>
4 *
5 * Distributed under terms of the MIT license.
6 */
7
8 #include "DeviceDescriptor.h"
9
10
11
12 namespace mtp { namespace usb
13 {
14 DeviceDescriptor::DeviceDescriptor(BUSBDevice* dev)
15 :_dev(dev)
16 {
17 }
18
19 DeviceDescriptor::~DeviceDescriptor()
20 {
21 }
22
23 ConfigurationPtr DeviceDescriptor::GetConfiguration(int conf)
24 {
25 return std::make_shared<Configuration>(_dev->ConfigurationAt(conf));
26 }
27
28 ByteArray DeviceDescriptor::GetDescriptor() const
29 {
30 const usb_device_descriptor* descriptor = _dev->Descriptor();
31 ByteArray out;
32 out.reserve(sizeof(usb_device_descriptor));
33 memcpy(out.data(), descriptor, sizeof(usb_device_descriptor));
34 return out;
35 }
36
37 DevicePtr DeviceDescriptor::TryOpen(ContextPtr context)
38 {
39 if (_dev->InitCheck() != B_OK)
40 return nullptr;
41 return std::make_shared<Device>(context, _dev);
42 }
43 }}