adb_endpoint_object.cpp revision 52d4c30ca52320ec92d1d1ddc8db3f07f69c4f98
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 AdbIOObject that
19  encapsulates an interface on our USB device.
20*/
21
22#include "stdafx.h"
23#include "adb_endpoint_object.h"
24
25AdbEndpointObject::AdbEndpointObject(AdbInterfaceObject* parent_interf)
26    : AdbIOObject(parent_interf, AdbObjectTypeEndpoint) {
27}
28
29AdbEndpointObject::~AdbEndpointObject() {
30}
31
32bool AdbEndpointObject::IsObjectOfType(AdbObjectType obj_type) const {
33  return ((obj_type == AdbObjectTypeEndpoint) ||
34          (obj_type == AdbObjectTypeIo));
35}
36
37bool AdbEndpointObject::GetEndpointInformation(AdbEndpointInformation* info) {
38  if (!IsOpened() || !IsUsbOpened()) {
39    SetLastError(ERROR_INVALID_HANDLE);
40    return false;
41  }
42
43  // Send IOCTL
44  DWORD ret_bytes = 0;
45  BOOL ret = DeviceIoControl(usb_handle(),
46                             ADB_IOCTL_GET_ENDPOINT_INFORMATION,
47                             NULL, 0,
48                             info, sizeof(AdbEndpointInformation),
49                             &ret_bytes,
50                             NULL);
51  ATLASSERT(!ret || (sizeof(AdbEndpointInformation) == ret_bytes));
52
53  return ret ? true : false;
54}
55