adb_interface_enum.h revision 5c11852110eeb03dc5a69111354b383f98d15336
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#ifndef ANDROID_USB_API_ADB_INTERFACE_ENUM_H__
18#define ANDROID_USB_API_ADB_INTERFACE_ENUM_H__
19/** \file
20  This file consists of declaration of AdbInterfaceEnumObject class that
21  encapsulates enumerator of USB interfaces available through this API.
22*/
23
24#include "adb_object_handle.h"
25
26/** Class AdbInterfaceEnumObject encapsulates enumerator of USB
27  interfaces available through this API.
28*/
29class AdbInterfaceEnumObject : public AdbObjectHandle {
30 public:
31  /** \brief Constructs the object.
32  */
33  AdbInterfaceEnumObject();
34
35 protected:
36  /** \brief Destructs the object.
37
38   We hide destructor in order to prevent ourseves from accidentaly allocating
39   instances on the stack. If such attemp occur, compiler will error.
40  */
41  virtual ~AdbInterfaceEnumObject();
42
43 public:
44  /** \brief Enumerates all interfaces for our device class
45
46    This routine uses SetupDiGetClassDevs to get our device info and calls
47    EnumerateDeviceInterfaces to perform the enumeration.
48    @param class_id[in] Device class ID that is specified by our USB driver
49    @param exclude_not_present[in] If set include only those devices that are
50           currently present.
51    @param exclude_removed[in] If true interfaces with SPINT_REMOVED flag set
52           will be not included in the enumeration.
53    @param active_only[in] If 'true' only active interfaces (with flag
54           SPINT_ACTIVE set) will be included in the enumeration.
55    @return True on success, false on failure, in which case GetLastError()
56            provides extended information about the error that occurred.
57  */
58  bool InitializeEnum(GUID class_id,
59                      bool exclude_not_present,
60                      bool exclude_removed,
61                      bool active_only);
62
63  /** \brief Gets next enumerated interface information
64
65    @param info[out] Upon successful completion will receive interface
66           information. Can be NULL. If it is NULL, upon return from this
67           method *size will have memory size required to fit this entry.
68    @param size[in,out]. On the way in provides size of the memory buffer
69           addressed by info param. On the way out (only if buffer is not
70           big enough) will provide memory size required to fit this entry.
71    @return true on success, false on error. If false is returned
72            GetLastError() provides extended information about the error that
73            occurred. ERROR_INSUFFICIENT_BUFFER indicates that buffer provided
74            in info param was not big enough and *size specifies memory size
75            required to fit this entry. ERROR_NO_MORE_ITEMS indicates that
76            enumeration is over and there are no more entries to return.
77  */
78  bool Next(AdbInterfaceInfo* info, ULONG* size);
79
80  /** \brief Makes enumerator to start from the beginning.
81
82    @return true on success, false on error. If false is returned
83            GetLastError() provides extended information about the error that
84            occurred.
85  */
86  bool Reset();
87
88  // This is a helper for extracting object from the AdbObjectHandleMap
89  static AdbObjectType Type() {
90    return AdbObjectTypeInterfaceEnumerator;
91  }
92
93 protected:
94  /// Array of interfaces enumerated with this object
95  AdbEnumInterfaceArray           interfaces_;
96
97  /// Current enumerator
98  AdbEnumInterfaceArray::iterator current_interface_;
99};
100
101#endif  // ANDROID_USB_API_ADB_INTERFACE_ENUM_H__
102