10529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch// Copyright 2014 The Chromium Authors. All rights reserved.
20529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch// Use of this source code is governed by a BSD-style license that can be
30529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch// found in the LICENSE file.
40529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch
50529e5d033099cbfc42635f6f6183833b09dff6eBen Murdochpackage org.chromium.mojo.system;
60529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch
70529e5d033099cbfc42635f6f6183833b09dff6eBen Murdochimport java.io.Closeable;
80529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch
90529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch/**
100529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch * A generic mojo handle.
110529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch */
120529e5d033099cbfc42635f6f6183833b09dff6eBen Murdochpublic interface Handle extends Closeable {
130529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch
140529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch    /**
150529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch     * Closes the given |handle|.
160529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch     * <p>
170529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch     * Concurrent operations on |handle| may succeed (or fail as usual) if they happen before the
180529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch     * close, be cancelled with result |MojoResult.CANCELLED| if they properly overlap (this is
190529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch     * likely the case with |wait()|, etc.), or fail with |MojoResult.INVALID_ARGUMENT| if they
200529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch     * happen after.
210529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch     */
220529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch    @Override
230529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch    public void close();
240529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch
250529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch    /**
26116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch     * @see Core#wait(Handle, Core.HandleSignals, long)
270529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch     */
28116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch    public int wait(Core.HandleSignals signals, long deadline);
290529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch
300529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch    /**
310529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch     * @return whether the handle is valid. A handle is valid until it has been explicitly closed or
320529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch     *         send through a message pipe via |MessagePipeHandle.writeMessage|.
330529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch     */
340529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch    public boolean isValid();
350529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch
36cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)    /**
37cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)     * Converts this handle into an {@link UntypedHandle}, invalidating this handle.
38cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)     */
39cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)    public UntypedHandle toUntypedHandle();
40cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)
4146d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)    /**
4246d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)     * Returns the {@link Core} implementation for this handle. Can be null if this handle is
4346d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)     * invalid.
4446d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)     */
4546d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)    public Core getCore();
4646d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)
47116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch    /**
48116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch     * Passes ownership of the handle from this handle to the newly created Handle object,
49116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch     * invalidating this handle object in the process.
50116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch     */
51116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch    public Handle pass();
52116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch
531320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci    /**
541320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci     * Releases the native handle backed by this {@link Handle}. The caller owns the handle and must
551320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci     * close it.
561320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci     */
571320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci    public int releaseNativeHandle();
581320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci
590529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch}
60