// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

// http://wicg.github.io/webusb/#idl-def-usbtransferstatus

enum USBTransferStatus {
    "ok",
    "stall",
    "babble"
};

// http://wicg.github.io/webusb/#device-usage

[
    OriginTrialEnabled=WebUSB,
] interface USBDevice {
    readonly attribute octet usbVersionMajor;
    readonly attribute octet usbVersionMinor;
    readonly attribute octet usbVersionSubminor;
    readonly attribute octet deviceClass;
    readonly attribute octet deviceSubclass;
    readonly attribute octet deviceProtocol;
    readonly attribute unsigned short vendorId;
    readonly attribute unsigned short productId;
    readonly attribute octet deviceVersionMajor;
    readonly attribute octet deviceVersionMinor;
    readonly attribute octet deviceVersionSubminor;
    readonly attribute DOMString? manufacturerName;
    readonly attribute DOMString? productName;
    readonly attribute DOMString? serialNumber;
    readonly attribute USBConfiguration? configuration;
    readonly attribute sequence<USBConfiguration> configurations;
    readonly attribute boolean opened;

    [CallWith=ScriptState] Promise<void> open();
    [CallWith=ScriptState] Promise<void> close();
    [CallWith=ScriptState] Promise<void> selectConfiguration(octet configurationValue);
    [CallWith=ScriptState] Promise<void> claimInterface(octet interfaceNumber);
    [CallWith=ScriptState] Promise<void> releaseInterface(octet interfaceNumber);
    [CallWith=ScriptState] Promise<void> selectAlternateInterface(octet interfaceNumber, octet alternateSetting);
    [CallWith=ScriptState] Promise<USBInTransferResult> controlTransferIn(USBControlTransferParameters setup, unsigned short length);
    [CallWith=ScriptState] Promise<USBOutTransferResult> controlTransferOut(USBControlTransferParameters setup, optional BufferSource data);
    [CallWith=ScriptState] Promise<void> clearHalt(USBDirection direction, octet endpointNumber);
    [CallWith=ScriptState] Promise<USBInTransferResult> transferIn(octet endpointNumber, unsigned long length);
    [CallWith=ScriptState] Promise<USBOutTransferResult> transferOut(octet endpointNumber, BufferSource data);
    [CallWith=ScriptState] Promise<USBIsochronousInTransferResult>  isochronousTransferIn(octet endpointNumber, sequence<unsigned long> packetLengths);
    [CallWith=ScriptState] Promise<UsbIsochronousOutTransferResult> isochronousTransferOut(octet endpointNumber, BufferSource data, sequence<unsigned long> packetLengths);
    [CallWith=ScriptState] Promise<void> reset();
};
