1dceaaa52cec11631c72cfea5fb74ee607602ecdevchtchetkine/*
2dceaaa52cec11631c72cfea5fb74ee607602ecdevchtchetkine * Copyright (C) 2006 The Android Open Source Project
3dceaaa52cec11631c72cfea5fb74ee607602ecdevchtchetkine *
4dceaaa52cec11631c72cfea5fb74ee607602ecdevchtchetkine * Licensed under the Apache License, Version 2.0 (the "License");
5dceaaa52cec11631c72cfea5fb74ee607602ecdevchtchetkine * you may not use this file except in compliance with the License.
6dceaaa52cec11631c72cfea5fb74ee607602ecdevchtchetkine * You may obtain a copy of the License at
7dceaaa52cec11631c72cfea5fb74ee607602ecdevchtchetkine *
8dceaaa52cec11631c72cfea5fb74ee607602ecdevchtchetkine *      http://www.apache.org/licenses/LICENSE-2.0
9dceaaa52cec11631c72cfea5fb74ee607602ecdevchtchetkine *
10dceaaa52cec11631c72cfea5fb74ee607602ecdevchtchetkine * Unless required by applicable law or agreed to in writing, software
11dceaaa52cec11631c72cfea5fb74ee607602ecdevchtchetkine * distributed under the License is distributed on an "AS IS" BASIS,
12dceaaa52cec11631c72cfea5fb74ee607602ecdevchtchetkine * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13dceaaa52cec11631c72cfea5fb74ee607602ecdevchtchetkine * See the License for the specific language governing permissions and
14dceaaa52cec11631c72cfea5fb74ee607602ecdevchtchetkine * limitations under the License.
15dceaaa52cec11631c72cfea5fb74ee607602ecdevchtchetkine */
16dceaaa52cec11631c72cfea5fb74ee607602ecdevchtchetkine
17dceaaa52cec11631c72cfea5fb74ee607602ecdevchtchetkine#ifndef ANDROID_USB_API_ADB_INTERFACE_ENUM_H__
18dceaaa52cec11631c72cfea5fb74ee607602ecdevchtchetkine#define ANDROID_USB_API_ADB_INTERFACE_ENUM_H__
19dceaaa52cec11631c72cfea5fb74ee607602ecdevchtchetkine/** \file
20dceaaa52cec11631c72cfea5fb74ee607602ecdevchtchetkine  This file consists of declaration of AdbInterfaceEnumObject class that
21dceaaa52cec11631c72cfea5fb74ee607602ecdevchtchetkine  encapsulates enumerator of USB interfaces available through this API.
22dceaaa52cec11631c72cfea5fb74ee607602ecdevchtchetkine*/
23dceaaa52cec11631c72cfea5fb74ee607602ecdevchtchetkine
24dceaaa52cec11631c72cfea5fb74ee607602ecdevchtchetkine#include "adb_object_handle.h"
25dceaaa52cec11631c72cfea5fb74ee607602ecdevchtchetkine
26dceaaa52cec11631c72cfea5fb74ee607602ecdevchtchetkine/** \brief Enumerator of USB interfaces available through this API.
27dceaaa52cec11631c72cfea5fb74ee607602ecdevchtchetkine*/
28dceaaa52cec11631c72cfea5fb74ee607602ecdevchtchetkineclass AdbInterfaceEnumObject : public AdbObjectHandle {
29dceaaa52cec11631c72cfea5fb74ee607602ecdevchtchetkine public:
30dceaaa52cec11631c72cfea5fb74ee607602ecdevchtchetkine  /** \brief Constructs the object.
31dceaaa52cec11631c72cfea5fb74ee607602ecdevchtchetkine  */
32dceaaa52cec11631c72cfea5fb74ee607602ecdevchtchetkine  AdbInterfaceEnumObject();
33dceaaa52cec11631c72cfea5fb74ee607602ecdevchtchetkine
34dceaaa52cec11631c72cfea5fb74ee607602ecdevchtchetkine protected:
35dceaaa52cec11631c72cfea5fb74ee607602ecdevchtchetkine  /** \brief Destructs the object.
36dceaaa52cec11631c72cfea5fb74ee607602ecdevchtchetkine
37dceaaa52cec11631c72cfea5fb74ee607602ecdevchtchetkine   We hide destructor in order to prevent ourseves from accidentaly allocating
38dceaaa52cec11631c72cfea5fb74ee607602ecdevchtchetkine   instances on the stack. If such attemp occur, compiler will error.
39dceaaa52cec11631c72cfea5fb74ee607602ecdevchtchetkine  */
40dceaaa52cec11631c72cfea5fb74ee607602ecdevchtchetkine  virtual ~AdbInterfaceEnumObject();
41dceaaa52cec11631c72cfea5fb74ee607602ecdevchtchetkine
42dceaaa52cec11631c72cfea5fb74ee607602ecdevchtchetkine public:
43dceaaa52cec11631c72cfea5fb74ee607602ecdevchtchetkine  /** \brief Enumerates all interfaces for the given device class.
44dceaaa52cec11631c72cfea5fb74ee607602ecdevchtchetkine
45dceaaa52cec11631c72cfea5fb74ee607602ecdevchtchetkine    This routine uses SetupDiGetClassDevs to get our device info and calls
46dceaaa52cec11631c72cfea5fb74ee607602ecdevchtchetkine    EnumerateDeviceInterfaces to perform the enumeration.
47dceaaa52cec11631c72cfea5fb74ee607602ecdevchtchetkine    @param[in] class_id Device class ID that is specified by our USB driver
48dceaaa52cec11631c72cfea5fb74ee607602ecdevchtchetkine    @param[in] exclude_not_present If set include only those devices that are
49dceaaa52cec11631c72cfea5fb74ee607602ecdevchtchetkine           currently present.
50dceaaa52cec11631c72cfea5fb74ee607602ecdevchtchetkine    @param[in] exclude_removed If true interfaces with SPINT_REMOVED flag set
51dceaaa52cec11631c72cfea5fb74ee607602ecdevchtchetkine           will be not included in the enumeration.
52dceaaa52cec11631c72cfea5fb74ee607602ecdevchtchetkine    @param[in] active_only If true only active interfaces (with flag
53dceaaa52cec11631c72cfea5fb74ee607602ecdevchtchetkine           SPINT_ACTIVE set) will be included in the enumeration.
54dceaaa52cec11631c72cfea5fb74ee607602ecdevchtchetkine    @return True on success, false on failure, in which case GetLastError()
55dceaaa52cec11631c72cfea5fb74ee607602ecdevchtchetkine            provides extended information about the error that occurred.
56dceaaa52cec11631c72cfea5fb74ee607602ecdevchtchetkine  */
57dceaaa52cec11631c72cfea5fb74ee607602ecdevchtchetkine  bool InitializeEnum(GUID class_id,
58dceaaa52cec11631c72cfea5fb74ee607602ecdevchtchetkine                      bool exclude_not_present,
59dceaaa52cec11631c72cfea5fb74ee607602ecdevchtchetkine                      bool exclude_removed,
60dceaaa52cec11631c72cfea5fb74ee607602ecdevchtchetkine                      bool active_only);
61dceaaa52cec11631c72cfea5fb74ee607602ecdevchtchetkine
62dceaaa52cec11631c72cfea5fb74ee607602ecdevchtchetkine  /** \brief Gets next enumerated interface information
63dceaaa52cec11631c72cfea5fb74ee607602ecdevchtchetkine    @param[out] info Upon successful completion will receive interface
64dceaaa52cec11631c72cfea5fb74ee607602ecdevchtchetkine           information. Can be NULL. If it is NULL, upon return from this
65dceaaa52cec11631c72cfea5fb74ee607602ecdevchtchetkine           method *size will have memory size required to fit this entry.
66dceaaa52cec11631c72cfea5fb74ee607602ecdevchtchetkine    @param[in,out] size On the way in provides size of the memory buffer
67dceaaa52cec11631c72cfea5fb74ee607602ecdevchtchetkine           addressed by info param. On the way out (only if buffer is not
68dceaaa52cec11631c72cfea5fb74ee607602ecdevchtchetkine           big enough) will provide memory size required to fit this entry.
69dceaaa52cec11631c72cfea5fb74ee607602ecdevchtchetkine    @return true on success, false on error. If false is returned
70dceaaa52cec11631c72cfea5fb74ee607602ecdevchtchetkine            GetLastError() provides extended information about the error that
71dceaaa52cec11631c72cfea5fb74ee607602ecdevchtchetkine            occurred. ERROR_INSUFFICIENT_BUFFER indicates that buffer provided
72dceaaa52cec11631c72cfea5fb74ee607602ecdevchtchetkine            in info param was not big enough and *size specifies memory size
73dceaaa52cec11631c72cfea5fb74ee607602ecdevchtchetkine            required to fit this entry. ERROR_NO_MORE_ITEMS indicates that
74dceaaa52cec11631c72cfea5fb74ee607602ecdevchtchetkine            enumeration is over and there are no more entries to return.
75dceaaa52cec11631c72cfea5fb74ee607602ecdevchtchetkine  */
76dceaaa52cec11631c72cfea5fb74ee607602ecdevchtchetkine  bool Next(AdbInterfaceInfo* info, ULONG* size);
77dceaaa52cec11631c72cfea5fb74ee607602ecdevchtchetkine
78dceaaa52cec11631c72cfea5fb74ee607602ecdevchtchetkine  /** \brief Makes enumerator to start from the beginning.
79dceaaa52cec11631c72cfea5fb74ee607602ecdevchtchetkine    @return true on success, false on error. If false is returned
80dceaaa52cec11631c72cfea5fb74ee607602ecdevchtchetkine            GetLastError() provides extended information about the error that
81dceaaa52cec11631c72cfea5fb74ee607602ecdevchtchetkine            occurred.
82dceaaa52cec11631c72cfea5fb74ee607602ecdevchtchetkine  */
83dceaaa52cec11631c72cfea5fb74ee607602ecdevchtchetkine  bool Reset();
84dceaaa52cec11631c72cfea5fb74ee607602ecdevchtchetkine
85dceaaa52cec11631c72cfea5fb74ee607602ecdevchtchetkine  // This is a helper for extracting object from the AdbObjectHandleMap
86dceaaa52cec11631c72cfea5fb74ee607602ecdevchtchetkine  static AdbObjectType Type() {
87dceaaa52cec11631c72cfea5fb74ee607602ecdevchtchetkine    return AdbObjectTypeInterfaceEnumerator;
88dceaaa52cec11631c72cfea5fb74ee607602ecdevchtchetkine  }
89dceaaa52cec11631c72cfea5fb74ee607602ecdevchtchetkine
90dceaaa52cec11631c72cfea5fb74ee607602ecdevchtchetkine protected:
91dceaaa52cec11631c72cfea5fb74ee607602ecdevchtchetkine  /// Array of interfaces enumerated with this object
92dceaaa52cec11631c72cfea5fb74ee607602ecdevchtchetkine  AdbEnumInterfaceArray           interfaces_;
93dceaaa52cec11631c72cfea5fb74ee607602ecdevchtchetkine
94dceaaa52cec11631c72cfea5fb74ee607602ecdevchtchetkine  /// Current enumerator
95dceaaa52cec11631c72cfea5fb74ee607602ecdevchtchetkine  AdbEnumInterfaceArray::iterator current_interface_;
96dceaaa52cec11631c72cfea5fb74ee607602ecdevchtchetkine};
97dceaaa52cec11631c72cfea5fb74ee607602ecdevchtchetkine
98dceaaa52cec11631c72cfea5fb74ee607602ecdevchtchetkine#endif  // ANDROID_USB_API_ADB_INTERFACE_ENUM_H__
99