• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2009 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #ifndef ANDROID_USB_API_ADB_LEGACY_ENDPOINT_OBJECT_H__
18 #define ANDROID_USB_API_ADB_LEGACY_ENDPOINT_OBJECT_H__
19 /** \file
20   This file consists of declaration of class AdbLegacyEndpointObject that
21   encapsulates a handle opened to an endpoint on our device controlled by
22   a custom (legacy) USB driver.
23 */
24 
25 #include "adb_endpoint_object.h"
26 #include "adb_legacy_interface.h"
27 
28 /** Encapsulates a handle opened to an endpoint on our device controlled by
29   a custom (legacy) USB driver.
30 */
31 class AdbLegacyEndpointObject : public AdbEndpointObject {
32  public:
33   /** \brief Constructs the object
34 
35     @param[in] interface Parent legacy USB interface for this object.
36     @param[in] endpoint_id Endpoint ID (endpoint address) on the device.
37     @param[in] endpoint_index Zero-based endpoint index in the interface's
38           array of endpoints.
39   */
40   AdbLegacyEndpointObject(AdbLegacyInterfaceObject* parent_interf,
41                           UCHAR endpoint_id,
42                           UCHAR endpoint_index);
43 
44  protected:
45   /** \brief Destructs the object.
46 
47     We hide destructor in order to prevent ourseves from accidentaly allocating
48     instances on the stack. If such attemp occur, compiler will error.
49   */
50   virtual ~AdbLegacyEndpointObject();
51 
52   //
53   // Abstract overrides
54   //
55 
56  protected:
57   /** \brief Common code for async read / write
58 
59     @param[in] is_read Read or write selector.
60     @param[in,out] buffer Pointer to the buffer for read / write.
61     @param[in] bytes_to_transfer Number of bytes to be read / written.
62     @param[out] bytes_transferred Number of bytes read / written. Can be NULL.
63     @param[in] event_handle Event handle that should be signaled when async I/O
64            completes. Can be NULL. If it's not NULL this handle will be used to
65            initialize OVERLAPPED structure for this I/O.
66     @param[in] time_out A timeout (in milliseconds) required for this I/O to
67            complete. Zero value in this parameter means that there is no
68            timeout set for this I/O.
69     @return A handle to IO completion object or NULL on failure. If NULL is
70             returned GetLastError() provides extended error information.
71   */
72   virtual ADBAPIHANDLE CommonAsyncReadWrite(bool is_read,
73                                             void* buffer,
74                                             ULONG bytes_to_transfer,
75                                             ULONG* bytes_transferred,
76                                             HANDLE event_handle,
77                                             ULONG time_out);
78 
79   /** \brief Common code for sync read / write
80 
81     @param[in] is_read Read or write selector.
82     @param[in,out] buffer Pointer to the buffer for read / write.
83     @param[in] bytes_to_transfer Number of bytes to be read / written.
84     @param[out] bytes_transferred Number of bytes read / written. Can be NULL.
85     @param[in] time_out A timeout (in milliseconds) required for this I/O to
86            complete. Zero value in this parameter means that there is no
87            timeout set for this I/O.
88     @return true on success, false on failure. If false is returned
89             GetLastError() provides extended error information.
90   */
91   virtual bool CommonSyncReadWrite(bool is_read,
92                                    void* buffer,
93                                    ULONG bytes_to_transfer,
94                                    ULONG* bytes_transferred,
95                                    ULONG time_out);
96 
97   //
98   // Operations
99   //
100 
101  public:
102   /** \brief Opens endpoint and creates a handle to this object
103 
104     @param item_path[in] Path to the endpoint on our USB device.
105     @param access_type[in] Desired access type. In the current implementation
106           this parameter has no effect on the way item is opened. It's
107           always read / write access.
108     @param sharing_mode[in] Desired share mode. In the current implementation
109           this parameter has no effect on the way item is opened. It's
110           always shared for read / write.
111     @return A handle to this object on success or NULL on an error.
112             If NULL is returned GetLastError() provides extended error
113             information. ERROR_GEN_FAILURE is set if an attempt was
114             made to create already opened object.
115   */
116   virtual ADBAPIHANDLE CreateHandle(const wchar_t* item_path,
117                                     AdbOpenAccessType access_type,
118                                     AdbOpenSharingMode share_mode);
119 
120 
121   /** \brief This method is called when handle to this object gets closed.
122 
123     We override this method in order to close handle to the endpoint opened
124     in CreateHandle method of this class.
125     @return true on success or false if object is already closed. If
126             false is returned GetLastError() provides extended error
127             information.
128   */
129   virtual bool CloseHandle();
130 
131  public:
132   /// Gets handle to the endpoint opened on our USB device.
usb_handle()133   HANDLE usb_handle() const {
134     return usb_handle_;
135   }
136 
137  protected:
138   /// Handle to the endpoint opened on our USB device.
139   HANDLE              usb_handle_;
140 };
141 
142 #endif  // ANDROID_USB_API_ADB_LEGACY_ENDPOINT_OBJECT_H__
143