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