2 * Copyright (C) 2006 The Android Open Source Project
\r
4 * Licensed under the Apache License, Version 2.0 (the "License");
\r
5 * you may not use this file except in compliance with the License.
\r
6 * You may obtain a copy of the License at
\r
8 * http://www.apache.org/licenses/LICENSE-2.0
\r
10 * Unless required by applicable law or agreed to in writing, software
\r
11 * distributed under the License is distributed on an "AS IS" BASIS,
\r
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
13 * See the License for the specific language governing permissions and
\r
14 * limitations under the License.
\r
17 #ifndef ANDROID_USB_API_ADB_INTERFACE_H__
\r
18 #define ANDROID_USB_API_ADB_INTERFACE_H__
\r
20 This file consists of declaration of class AdbInterfaceObject that
\r
21 encapsulates a generic interface on our USB device.
\r
24 #include "adb_object_handle.h"
\r
26 /** \brief Encapsulates an interface on our USB device.
\r
28 This is an abstract class that implements functionality common for both,
\r
29 legacy, and WinUsb based interfaces.
\r
31 class AdbInterfaceObject : public AdbObjectHandle {
\r
33 /** \brief Constructs the object.
\r
35 @param[in] interf_name Name of the interface
\r
37 explicit AdbInterfaceObject(const wchar_t* interf_name);
\r
40 /** \brief Destructs the object.
\r
42 We hide destructor in order to prevent ourseves from accidentaly allocating
\r
43 instances on the stack. If such attemp occur, compiler will error.
\r
45 virtual ~AdbInterfaceObject();
\r
52 /** \brief Gets serial number for interface's device.
\r
54 @param[out] buffer Buffer for the serail number string. Can be NULL in
\r
55 which case buffer_char_size will contain number of characters
\r
56 required for the string.
\r
57 @param[in,out] buffer_char_size On the way in supplies size (in characters)
\r
58 of the buffer. On the way out, if method failed and GetLastError
\r
59 reports ERROR_INSUFFICIENT_BUFFER, will contain number of characters
\r
60 required for the name.
\r
61 @param[in] ansi If true the name will be returned as single character
\r
62 string. Otherwise name will be returned as wide character string.
\r
63 @return true on success, false on failure. If false is returned
\r
64 GetLastError() provides extended error information.
\r
66 virtual bool GetSerialNumber(void* buffer,
\r
67 unsigned long* buffer_char_size,
\r
71 /** \brief Gets information about an endpoint on this interface.
\r
73 @param[in] endpoint_index Zero-based endpoint index. There are two
\r
74 shortcuts for this parameter: ADB_QUERY_BULK_WRITE_ENDPOINT_INDEX
\r
75 and ADB_QUERY_BULK_READ_ENDPOINT_INDEX that provide infor about
\r
76 (default?) bulk write and read endpoints respectively.
\r
77 @param[out] info Upon successful completion will have endpoint information.
\r
78 @return true on success, false on failure. If false is returned
\r
79 GetLastError() provides extended error information.
\r
81 virtual bool GetEndpointInformation(UCHAR endpoint_index,
\r
82 AdbEndpointInformation* info) = 0;
\r
84 /** \brief Opens an endpoint on this interface.
\r
86 @param[in] endpoint_index Zero-based endpoint index. There are two
\r
87 shortcuts for this parameter: ADB_QUERY_BULK_WRITE_ENDPOINT_INDEX
\r
88 and ADB_QUERY_BULK_READ_ENDPOINT_INDEX that provide infor about
\r
89 (default?) bulk write and read endpoints respectively.
\r
90 @param[in] access_type Desired access type. In the current implementation
\r
91 this parameter has no effect on the way endpoint is opened. It's
\r
92 always read / write access.
\r
93 @param[in] sharing_mode Desired share mode. In the current implementation
\r
94 this parameter has no effect on the way endpoint is opened. It's
\r
95 always shared for read / write.
\r
96 @return Handle to the opened endpoint object or NULL on failure.
\r
97 If NULL is returned GetLastError() provides extended information
\r
98 about the error that occurred.
\r
100 virtual ADBAPIHANDLE OpenEndpoint(UCHAR endpoint_index,
\r
101 AdbOpenAccessType access_type,
\r
102 AdbOpenSharingMode sharing_mode) = 0;
\r
109 /** \brief Gets interface device name.
\r
111 @param[out] buffer Buffer for the name. Can be NULL in which case
\r
112 buffer_char_size will contain number of characters required to fit
\r
114 @param[in,out] buffer_char_size On the way in supplies size (in characters)
\r
115 of the buffer. On the way out if method failed and GetLastError
\r
116 reports ERROR_INSUFFICIENT_BUFFER will contain number of characters
\r
117 required to fit the name.
\r
118 @param[in] ansi If true the name will be returned as single character
\r
119 string. Otherwise name will be returned as wide character string.
\r
120 @return true on success, false on failure. If false is returned
\r
121 GetLastError() provides extended error information.
\r
123 virtual bool GetInterfaceName(void* buffer,
\r
124 unsigned long* buffer_char_size,
\r
127 /** \brief Gets device descriptor for the USB device associated with
\r
130 @param[out] desc Upon successful completion will have usb device
\r
132 @return true on success, false on failure. If false is returned
\r
133 GetLastError() provides extended error information.
\r
135 virtual bool GetUsbDeviceDescriptor(USB_DEVICE_DESCRIPTOR* desc);
\r
137 /** \brief Gets descriptor for the selected USB device configuration.
\r
139 @param[out] desc Upon successful completion will have usb device
\r
140 configuration descriptor.
\r
141 @return true on success, false on failure. If false is returned
\r
142 GetLastError() provides extended error information.
\r
144 virtual bool GetUsbConfigurationDescriptor(
\r
145 USB_CONFIGURATION_DESCRIPTOR* desc);
\r
147 /** \brief Gets descriptor for this interface.
\r
149 @param[out] desc Upon successful completion will have interface
\r
151 @return true on success, false on failure. If false is returned
\r
152 GetLastError() provides extended error information.
\r
154 virtual bool GetUsbInterfaceDescriptor(USB_INTERFACE_DESCRIPTOR* desc);
\r
157 /// Gets name of the USB interface (device name) for this object
\r
158 const std::wstring& interface_name() const {
\r
159 return interface_name_;
\r
162 /// This is a helper for extracting object from the AdbObjectHandleMap
\r
163 static AdbObjectType Type() {
\r
164 return AdbObjectTypeInterface;
\r
167 /// Gets cached usb device descriptor
\r
168 const USB_DEVICE_DESCRIPTOR* usb_device_descriptor() const {
\r
169 return &usb_device_descriptor_;
\r
172 /// Gets cached usb configuration descriptor
\r
173 const USB_CONFIGURATION_DESCRIPTOR* usb_config_descriptor() const {
\r
174 return &usb_config_descriptor_;
\r
177 /// Gets cached usb interface descriptor
\r
178 const USB_INTERFACE_DESCRIPTOR* usb_interface_descriptor() const {
\r
179 return &usb_interface_descriptor_;
\r
183 /// Name of the USB interface (device name) for this object
\r
184 std::wstring interface_name_;
\r
186 /// Cached usb device descriptor
\r
187 USB_DEVICE_DESCRIPTOR usb_device_descriptor_;
\r
189 /// Cached usb configuration descriptor
\r
190 USB_CONFIGURATION_DESCRIPTOR usb_config_descriptor_;
\r
192 /// Cached usb interface descriptor
\r
193 USB_INTERFACE_DESCRIPTOR usb_interface_descriptor_;
\r
196 #endif // ANDROID_USB_API_ADB_INTERFACE_H__
\r