Home | History | Annotate | Download | only in api
      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_ADB_API_PRIVATE_DEFINES_H__
     18 #define ANDROID_USB_ADB_API_PRIVATE_DEFINES_H__
     19 /** \file
     20   This file consists of private definitions used inside the API
     21 */
     22 
     23 #include "adb_api.h"
     24 
     25 /** \brief Encapsulates an entry in the array of enumerated interfaces.
     26 */
     27 class AdbInstanceEnumEntry {
     28  public:
     29   /** \brief Constructs an empty object.
     30   */
     31   AdbInstanceEnumEntry()
     32       : flags_(0) {
     33     ZeroMemory(&class_id_, sizeof(class_id_));
     34   }
     35 
     36   /** \brief Copy constructor
     37   */
     38   AdbInstanceEnumEntry(const AdbInstanceEnumEntry& proto) {
     39     Set(proto.device_name().c_str(), proto.class_id(), proto.flags());
     40   }
     41 
     42   /** \brief Constructs the object with parameters.
     43   */
     44   AdbInstanceEnumEntry(const wchar_t* dev_name, GUID cls_id, DWORD flgs) {
     45     Set(dev_name, cls_id, flgs);
     46   }
     47 
     48   /** \brief Destructs the object.
     49   */
     50   ~AdbInstanceEnumEntry() {
     51   }
     52 
     53   /// Operator =
     54   AdbInstanceEnumEntry& operator=(const AdbInstanceEnumEntry& proto) {
     55     Set(proto.device_name().c_str(), proto.class_id(), proto.flags());
     56     return *this;
     57   }
     58 
     59   /// Initializes instance with parameters
     60   void Set(const wchar_t* dev_name, GUID cls_id, DWORD flgs) {
     61     device_name_ = dev_name;
     62     class_id_ = cls_id;
     63     flags_ = flgs;
     64   }
     65 
     66   /// Calculates memory size needed to save this entry into AdbInterfaceInfo
     67   /// structure
     68   ULONG GetFlatSize() const {
     69     return static_cast<ULONG>(FIELD_OFFSET(AdbInterfaceInfo, device_name) +
     70                               (device_name_.length() + 1) * sizeof(wchar_t));
     71   }
     72 
     73   /** \brief Saves this entry into AdbInterfaceInfo structure.
     74 
     75     @param[in] info Buffer to save this entry to. Must be big enough to fit it.
     76            Use GetFlatSize() method to get buffer size needed for that.
     77 
     78   */
     79   void Save(AdbInterfaceInfo* info) const {
     80     info->class_id = class_id();
     81     info->flags = flags();
     82     wcscpy(info->device_name, device_name().c_str());
     83   }
     84 
     85   /// Gets interface's device name
     86   const std::wstring& device_name() const {
     87     return device_name_;
     88   }
     89 
     90   /// Gets inteface's class id
     91   GUID class_id() const {
     92     return class_id_;
     93   }
     94 
     95   /// Gets interface flags
     96   DWORD flags() const {
     97     return flags_;
     98   }
     99 
    100  private:
    101   /// Inteface's class id (see SP_DEVICE_INTERFACE_DATA)
    102   GUID          class_id_;
    103 
    104   /// Interface's device name
    105   std::wstring  device_name_;
    106 
    107   /// Interface flags (see SP_DEVICE_INTERFACE_DATA)
    108   DWORD         flags_;
    109 };
    110 
    111 /// Defines array of enumerated interface entries
    112 typedef std::vector< AdbInstanceEnumEntry > AdbEnumInterfaceArray;
    113 
    114 #endif  // ANDROID_USB_ADB_API_PRIVATE_DEFINES_H__
    115