blob: a97a3a8b21641b56b821b45c5c1990b9a8f7bd6b [file] [log] [blame]
vchtchetkine82675112009-07-24 11:30:41 -07001/*
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_WINUSB_IO_COMPLETION_H__
18#define ANDROID_USB_API_ADB_WINUSB_IO_COMPLETION_H__
19/** \file
20 This file consists of declaration of class AdbWinUsbIOCompletion that
21 encapsulates a wrapper around OVERLAPPED Win32 structure returned from
22 asynchronous I/O requests issued via WinUsb API.
23*/
24
Raphael3e44f3b2009-08-06 20:51:11 -070025#include "adb_io_completion.h"
vchtchetkine82675112009-07-24 11:30:41 -070026#include "adb_winusb_endpoint_object.h"
27
28/** \brief Encapsulates encapsulates a wrapper around OVERLAPPED Win32
29 structure returned from asynchronous I/O requests issued via WinUsb API.
30
31 A handle to this object is returned to the caller of each successful
32 asynchronous I/O request. Just like all other handles this handle
33 must be closed after it's no longer needed.
34*/
35class AdbWinUsbIOCompletion : public AdbIOCompletion {
36 public:
37 /** \brief Constructs the object
38
39 @param[in] parent_io_obj Parent WinUsb I/O object that created this
40 instance.
41 @param[in] expected_trans_size Number of bytes expected to be transferred
42 with the I/O.
43 @param[in] event_hndl Event handle that should be signaled when I/O
44 completes. Can be NULL. If it's not NULL this handle will be
45 used to initialize OVERLAPPED structure for this object.
46 */
47 AdbWinUsbIOCompletion(AdbWinUsbEndpointObject* parent_io_obj,
48 ULONG expected_trans_size,
49 HANDLE event_hndl);
50
51 protected:
52 /** \brief Destructs the object.
53
54 We hide destructor in order to prevent ourseves from accidentaly allocating
55 instances on the stack. If such attemp occur, compiler will error.
56 */
57 virtual ~AdbWinUsbIOCompletion();
58
59 //
vchtchetkine82675112009-07-24 11:30:41 -070060 // Abstract overrides
61 //
62
63 public:
64 /** \brief Gets overlapped I/O result
65
66 This method uses WinUsb_GetOverlappedResult to get results of the
67 overlapped I/O operation.
68 @param[out] ovl_data Buffer for the copy of this object's OVERLAPPED
69 structure. Can be NULL.
70 @param[out] bytes_transferred Pointer to a variable that receives the
71 number of bytes that were actually transferred by a read or write
72 operation. See SDK doc on GetOvelappedResult for more information.
73 Unlike regular GetOvelappedResult call this parameter can be NULL.
74 @param[in] wait If this parameter is true, the method does not return
75 until the operation has been completed. If this parameter is false
76 and the operation is still pending, the method returns false and
77 the GetLastError function returns ERROR_IO_INCOMPLETE.
78 @return true if I/O has been completed or false on failure or if request
79 is not yet completed. If false is returned GetLastError() provides
80 extended error information. If GetLastError returns
81 ERROR_IO_INCOMPLETE it means that I/O is not yet completed.
82 */
83 virtual bool GetOvelappedIoResult(LPOVERLAPPED ovl_data,
84 ULONG* bytes_transferred,
85 bool wait);
86
87 public:
88 /// Gets WinUsb parent object
89 AdbWinUsbEndpointObject* parent_winusb_io_object() const {
90 return reinterpret_cast<AdbWinUsbEndpointObject*>(parent_io_object());
91 }
92};
93
94#endif // ANDROID_USB_API_ADB_WINUSB_IO_COMPLETION_H__