2 * Copyright (C) 2009 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_WINUSB_INTERFACE_H__
\r
18 #define ANDROID_USB_API_ADB_WINUSB_INTERFACE_H__
\r
20 This file consists of declaration of class AdbWinUsbInterfaceObject
\r
21 that encapsulates an interface on our USB device that is accessible
\r
25 #include "..\api\adb_interface.h"
\r
27 /** \brief Encapsulates an interface on our USB device that is accessible
\r
30 class AdbWinUsbInterfaceObject : public AdbInterfaceObject {
\r
32 /** \brief Constructs the object.
\r
34 @param[in] interf_name Name of the interface
\r
36 explicit AdbWinUsbInterfaceObject(const wchar_t* interf_name);
\r
39 /** \brief Destructs the object.
\r
41 We hide destructor in order to prevent ourseves from accidentaly allocating
\r
42 instances on the stack. If such attemp occur, compiler will error.
\r
44 virtual ~AdbWinUsbInterfaceObject();
\r
47 // Virtual overrides
\r
51 /** \brief Releases the object.
\r
53 If refcount drops to zero as the result of this release, the object is
\r
54 destroyed in this method. As a general rule, objects must not be touched
\r
55 after this method returns even if returned value is not zero. We override
\r
56 this method in order to make sure that objects of this class are deleted
\r
57 in contect of the DLL they were created in. The problem is that since
\r
58 objects of this class were created in context of AdbWinUsbApi module, they
\r
59 are allocated from the heap assigned to that module. Now, if these objects
\r
60 are deleted outside of AdbWinUsbApi module, this will lead to the heap
\r
61 corruption in the module that deleted these objects. Since all objects of
\r
62 this class are deleted in the Release method only, by overriding it we make
\r
63 sure that we free memory in the context of the module where it was
\r
65 @return Value of the reference counter after object is released in this
\r
68 virtual LONG Release();
\r
70 /** \brief Creates handle to this object.
\r
72 In this call a handle for this object is generated and object is added
\r
73 to the AdbObjectHandleMap. We override this method in order to initialize
\r
74 WinUsb API for the given interface.
\r
75 @return A handle to this object on success or NULL on an error.
\r
76 If NULL is returned GetLastError() provides extended error
\r
77 information. ERROR_GEN_FAILURE is set if an attempt was
\r
78 made to create already opened object.
\r
80 virtual ADBAPIHANDLE CreateHandle();
\r
82 /** \brief This method is called when handle to this object gets closed.
\r
84 In this call object is deleted from the AdbObjectHandleMap. We override
\r
85 this method in order close WinUsb handle created in CreateHandle method
\r
87 @return true on success or false if object is already closed. If
\r
88 false is returned GetLastError() provides extended error
\r
91 virtual bool CloseHandle();
\r
94 // Abstract overrides
\r
98 /** \brief Gets serial number for interface's device.
\r
100 @param[out] buffer Buffer for the serail number string. Can be NULL in
\r
101 which case buffer_char_size will contain number of characters
\r
102 required for the string.
\r
103 @param[in,out] buffer_char_size On the way in supplies size (in characters)
\r
104 of the buffer. On the way out, if method failed and GetLastError
\r
105 reports ERROR_INSUFFICIENT_BUFFER, will contain number of characters
\r
106 required for the name.
\r
107 @param[in] ansi If true the name will be returned as single character
\r
108 string. Otherwise name will be returned as wide character string.
\r
109 @return true on success, false on failure. If false is returned
\r
110 GetLastError() provides extended error information.
\r
112 virtual bool GetSerialNumber(void* buffer,
\r
113 unsigned long* buffer_char_size,
\r
116 /** \brief Gets information about an endpoint on this interface.
\r
118 @param[in] endpoint_index Zero-based endpoint index. There are two
\r
119 shortcuts for this parameter: ADB_QUERY_BULK_WRITE_ENDPOINT_INDEX
\r
120 and ADB_QUERY_BULK_READ_ENDPOINT_INDEX that provide infor about
\r
121 (default?) bulk write and read endpoints respectively.
\r
122 @param[out] info Upon successful completion will have endpoint information.
\r
123 @return true on success, false on failure. If false is returned
\r
124 GetLastError() provides extended error information.
\r
126 virtual bool GetEndpointInformation(UCHAR endpoint_index,
\r
127 AdbEndpointInformation* info);
\r
129 /** \brief Opens an endpoint on this interface.
\r
131 @param[in] endpoint_index Zero-based endpoint index. There are two
\r
132 shortcuts for this parameter: ADB_QUERY_BULK_WRITE_ENDPOINT_INDEX
\r
133 and ADB_QUERY_BULK_READ_ENDPOINT_INDEX that provide infor about
\r
134 (default?) bulk write and read endpoints respectively.
\r
135 @param[in] access_type Desired access type. In the current implementation
\r
136 this parameter has no effect on the way endpoint is opened. It's
\r
137 always read / write access.
\r
138 @param[in] sharing_mode Desired share mode. In the current implementation
\r
139 this parameter has no effect on the way endpoint is opened. It's
\r
140 always shared for read / write.
\r
141 @return Handle to the opened endpoint object or NULL on failure.
\r
142 If NULL is returned GetLastError() provides extended information
\r
143 about the error that occurred.
\r
145 virtual ADBAPIHANDLE OpenEndpoint(UCHAR endpoint_index,
\r
146 AdbOpenAccessType access_type,
\r
147 AdbOpenSharingMode sharing_mode);
\r
154 /** \brief Opens an endpoint on this interface.
\r
156 @param[in] endpoint_id Endpoint (pipe) address on the device.
\r
157 @param[in] endpoint_index Zero-based endpoint index.
\r
158 @return Handle to the opened endpoint object or NULL on failure.
\r
159 If NULL is returned GetLastError() provides extended information
\r
160 about the error that occurred.
\r
162 ADBAPIHANDLE OpenEndpoint(UCHAR endpoint_id, UCHAR endpoint_index);
\r
165 /// Gets handle to the USB device
\r
166 HANDLE usb_device_handle() const {
\r
167 return usb_device_handle_;
\r
170 /// Gets interface handle used by WinUSB API
\r
171 WINUSB_INTERFACE_HANDLE winusb_handle() const {
\r
172 return winusb_handle_;
\r
175 /// Gets current interface number.
\r
176 UCHAR interface_number() const {
\r
177 return interface_number_;
\r
181 /// Handle to the USB device
\r
182 HANDLE usb_device_handle_;
\r
184 /// Interface handle used by WinUSB API
\r
185 WINUSB_INTERFACE_HANDLE winusb_handle_;
\r
187 /// Current interface number. This value is obtained via call to
\r
188 /// WinUsb_GetCurrentAlternateSetting and is used in WinUsb_Xxx
\r
189 /// calls that require interface number.
\r
190 UCHAR interface_number_;
\r
192 /// Index for the default bulk read endpoint
\r
193 UCHAR def_read_endpoint_;
\r
195 /// ID for the default bulk read endpoint
\r
196 UCHAR read_endpoint_id_;
\r
198 /// Index for the default bulk write endpoint
\r
199 UCHAR def_write_endpoint_;
\r
201 /// ID for the default bulk write endpoint
\r
202 UCHAR write_endpoint_id_;
\r
205 #endif // ANDROID_USB_API_ADB_WINUSB_INTERFACE_H__
\r