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