// Copyright 2017 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.

callback MojoWatchCallback = void (MojoResult result);

[
    ContextEnabled=MojoJS,
    Exposed=(Window,Worker),
    RuntimeEnabled=MojoJS
] interface MojoHandle {
    void close();
    [CallWith=ScriptState] MojoWatcher watch(MojoHandleSignals signals, MojoWatchCallback callback);

    // TODO(alokp): Create MojoMessagePipeHandle, a subclass of MojoHandle
    // and move the following member functions.
    MojoResult writeMessage(BufferSource buffer, sequence<MojoHandle> handles);
    MojoReadMessageResult readMessage(optional MojoReadMessageFlags flags);

    // TODO(alokp): Create MojoDataPipeProducerHandle and MojoDataPipeConsumerHandle,
    // subclasses of MojoHandle and move the following member functions.
    MojoWriteDataResult writeData(BufferSource buffer, optional MojoWriteDataOptions options);
    MojoReadDataResult queryData();
    MojoReadDataResult discardData(unsigned long numBytes, optional MojoDiscardDataOptions options);
    MojoReadDataResult readData(BufferSource buffer, optional MojoReadDataOptions options);

    // TODO(alokp): Create MojoSharedBufferHandle, a subclass of MojoHandle
    // and move the following member functions.
    MojoMapBufferResult mapBuffer(unsigned long offset, unsigned long numBytes);
    MojoCreateSharedBufferResult duplicateBufferHandle(optional MojoDuplicateBufferHandleOptions options);
};
