1 /*
2  * Copyright (C) 2006 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 /** \file
18   This file consists of implementation of class AdbEndpointObject that
19   encapsulates a handle opened to an endpoint on our device.
20 */
21 
22 #include "stdafx.h"
23 #include "adb_endpoint_object.h"
24 
AdbEndpointObject(AdbInterfaceObject * parent_interf,UCHAR endpoint_id,UCHAR endpoint_index)25 AdbEndpointObject::AdbEndpointObject(AdbInterfaceObject* parent_interf,
26                                      UCHAR endpoint_id,
27                                      UCHAR endpoint_index)
28     : AdbObjectHandle(AdbObjectTypeEndpoint),
29       parent_interface_(parent_interf),
30       endpoint_id_(endpoint_id),
31       endpoint_index_(endpoint_index) {
32   if (NULL != parent_interface_)
33     parent_interface_->AddRef();
34 }
35 
~AdbEndpointObject()36 AdbEndpointObject::~AdbEndpointObject() {
37   if (NULL != parent_interface_)
38     parent_interface_->Release();
39 }
40 
GetEndpointInformation(AdbEndpointInformation * info)41 bool AdbEndpointObject::GetEndpointInformation(AdbEndpointInformation* info) {
42   if (!IsOpened()) {
43     SetLastError(ERROR_INVALID_HANDLE);
44     return false;
45   }
46 
47   return parent_interface()->GetEndpointInformation(endpoint_index(), info);
48 }
49 
AsyncRead(void * buffer,ULONG bytes_to_read,ULONG * bytes_read,HANDLE event_handle,ULONG time_out)50 ADBAPIHANDLE AdbEndpointObject::AsyncRead(void* buffer,
51                                     ULONG bytes_to_read,
52                                     ULONG* bytes_read,
53                                     HANDLE event_handle,
54                                     ULONG time_out) {
55   return CommonAsyncReadWrite(true,
56                               buffer,
57                               bytes_to_read,
58                               bytes_read,
59                               event_handle,
60                               time_out);
61 }
62 
AsyncWrite(void * buffer,ULONG bytes_to_write,ULONG * bytes_written,HANDLE event_handle,ULONG time_out)63 ADBAPIHANDLE AdbEndpointObject::AsyncWrite(void* buffer,
64                                      ULONG bytes_to_write,
65                                      ULONG* bytes_written,
66                                      HANDLE event_handle,
67                                      ULONG time_out) {
68   return CommonAsyncReadWrite(false,
69                               buffer,
70                               bytes_to_write,
71                               bytes_written,
72                               event_handle,
73                               time_out);
74 }
75 
SyncRead(void * buffer,ULONG bytes_to_read,ULONG * bytes_read,ULONG time_out)76 bool AdbEndpointObject::SyncRead(void* buffer,
77                            ULONG bytes_to_read,
78                            ULONG* bytes_read,
79                            ULONG time_out) {
80   return CommonSyncReadWrite(true,
81                              buffer,
82                              bytes_to_read,
83                              bytes_read,
84                              time_out);
85 }
86 
SyncWrite(void * buffer,ULONG bytes_to_write,ULONG * bytes_written,ULONG time_out)87 bool AdbEndpointObject::SyncWrite(void* buffer,
88                             ULONG bytes_to_write,
89                             ULONG* bytes_written,
90                             ULONG time_out) {
91   return CommonSyncReadWrite(false,
92                              buffer,
93                              bytes_to_write,
94                              bytes_written,
95                              time_out);
96 }
97