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.
5 package org.chromium.mojo.system;
10 * Core mojo interface giving access to the base operations. See |src/mojo/public/c/system/core.h|
11 * for the underlying api.
13 public interface Core {
16 * Used to indicate an infinite deadline (timeout).
18 public static final long DEADLINE_INFINITE = -1;
21 * Signals for the wait operations on handles.
23 public static class HandleSignals extends Flags<HandleSignals> {
27 * @param signals the serialized signals.
29 private HandleSignals(int signals) {
33 private static final int FLAG_NONE = 0;
34 private static final int FLAG_READABLE = 1 << 0;
35 private static final int FLAG_WRITABLE = 1 << 1;
40 public static final HandleSignals NONE = HandleSignals.none().immutable();
41 public static final HandleSignals READABLE =
42 HandleSignals.none().setReadable(true).immutable();
43 public static final HandleSignals WRITABLE =
44 HandleSignals.none().setWritable(true).immutable();
47 * Change the readable bit of this signal.
49 * @param readable the new value of the readable bit.
52 public HandleSignals setReadable(boolean readable) {
53 return setFlag(FLAG_READABLE, readable);
57 * Change the writable bit of this signal.
59 * @param writable the new value of the writable bit.
62 public HandleSignals setWritable(boolean writable) {
63 return setFlag(FLAG_WRITABLE, writable);
67 * @return a signal with no bit set.
69 public static HandleSignals none() {
70 return new HandleSignals(FLAG_NONE);
76 * @return a platform-dependent monotonically increasing tick count representing "right now."
78 public long getTimeTicksNow();
81 * Waits on the given |handle| until the state indicated by |signals| is satisfied or until
82 * |deadline| has passed.
84 * @return |MojoResult.OK| if some signal in |signals| was satisfied (or is already satisfied).
86 * |MojoResult.DEADLINE_EXCEEDED| if the deadline has passed without any of the signals
89 * |MojoResult.CANCELLED| if |handle| is closed concurrently by another thread.
91 * |MojoResult.FAILED_PRECONDITION| if it is or becomes impossible that any flag in
92 * |signals| will ever be satisfied (for example, if the other endpoint is close).
94 public int wait(Handle handle, HandleSignals signals, long deadline);
97 * Result for the |waitMany| method.
99 public static class WaitManyResult {
102 * See |wait| for the different possible values.
104 private int mMojoResult;
106 * If |mojoResult| is |MojoResult.OK|, |handleIndex| is the index of the handle for which
107 * some flag was satisfied (or is already satisfied). If |mojoResult| is
108 * |MojoResult.CANCELLED| or |MojoResult.FAILED_PRECONDITION|, |handleIndex| is the index of
109 * the handle for which the issue occurred.
111 private int mHandleIndex;
114 * @return the mojoResult
116 public int getMojoResult() {
121 * @param mojoResult the mojoResult to set
123 public void setMojoResult(int mojoResult) {
124 mMojoResult = mojoResult;
128 * @return the handleIndex
130 public int getHandleIndex() {
135 * @param handleIndex the handleIndex to set
137 public void setHandleIndex(int handleIndex) {
138 mHandleIndex = handleIndex;
143 * Waits on handle in |handles| for at least one of them to satisfy the associated
144 * |HandleSignals|, or until |deadline| has passed.
146 * @returns a |WaitManyResult|.
148 public WaitManyResult waitMany(List<Pair<Handle, HandleSignals>> handles, long deadline);
151 * Creates a message pipe, which is a bidirectional communication channel for framed data (i.e.,
152 * messages), with the given options. Messages can contain plain data and/or Mojo handles.
154 * @return the set of handles for the two endpoints (ports) of the message pipe.
156 public Pair<MessagePipeHandle, MessagePipeHandle> createMessagePipe(
157 MessagePipeHandle.CreateOptions options);
160 * Creates a data pipe, which is a unidirectional communication channel for unframed data, with
161 * the given options. Data is unframed, but must come as (multiples of) discrete elements, of
162 * the size given in |options|. See |DataPipe.CreateOptions| for a description of the different
163 * options available for data pipes. |options| may be set to null for a data pipe with the
164 * default options (which will have an element size of one byte and have some system-dependent
167 * @return the set of handles for the two endpoints of the data pipe.
169 public Pair<DataPipe.ProducerHandle, DataPipe.ConsumerHandle> createDataPipe(
170 DataPipe.CreateOptions options);
173 * Creates a buffer that can be shared between applications (by duplicating the handle -- see
174 * |SharedBufferHandle.duplicate()| -- and passing it over a message pipe). To access the
175 * buffer, one must call |SharedBufferHandle.map|.
177 * @return the new |SharedBufferHandle|.
179 public SharedBufferHandle createSharedBuffer(SharedBufferHandle.CreateOptions options,
183 * Acquires a handle from the native side. The handle will be owned by the returned object and
184 * must not be closed outside of it.
186 * @return a new {@link UntypedHandle} representing the native handle.
188 public UntypedHandle acquireNativeHandle(int handle);
191 * Returns a default implementation of {@link AsyncWaiter}.
193 public AsyncWaiter getDefaultAsyncWaiter();