1// Copyright 2014 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5package org.chromium.mojo.system;
6
7import java.io.Closeable;
8
9/**
10 * A generic mojo handle.
11 */
12public interface Handle extends Closeable {
13
14    /**
15     * Closes the given |handle|.
16     * <p>
17     * Concurrent operations on |handle| may succeed (or fail as usual) if they happen before the
18     * close, be cancelled with result |MojoResult.CANCELLED| if they properly overlap (this is
19     * likely the case with |wait()|, etc.), or fail with |MojoResult.INVALID_ARGUMENT| if they
20     * happen after.
21     */
22    @Override
23    public void close();
24
25    /**
26     * @see Core#wait(Handle, Core.HandleSignals, long)
27     */
28    public int wait(Core.HandleSignals signals, long deadline);
29
30    /**
31     * @return whether the handle is valid. A handle is valid until it has been explicitly closed or
32     *         send through a message pipe via |MessagePipeHandle.writeMessage|.
33     */
34    public boolean isValid();
35
36    /**
37     * Converts this handle into an {@link UntypedHandle}, invalidating this handle.
38     */
39    public UntypedHandle toUntypedHandle();
40
41    /**
42     * Returns the {@link Core} implementation for this handle. Can be null if this handle is
43     * invalid.
44     */
45    public Core getCore();
46
47    /**
48     * Passes ownership of the handle from this handle to the newly created Handle object,
49     * invalidating this handle object in the process.
50     */
51    public Handle pass();
52
53    /**
54     * Releases the native handle backed by this {@link Handle}. The caller owns the handle and must
55     * close it.
56     */
57    public int releaseNativeHandle();
58
59}
60