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 /** 8 * Core mojo interface giving access to the base operations. See |src/mojo/public/c/system/core.h| 9 * for the underlying api. 10 */ 11 public interface Core { 12 13 /** 14 * Used to indicate an infinite deadline (timeout). 15 */ 16 public static final long DEADLINE_INFINITE = -1; 17 18 /** 19 * Signals for the wait operations on handles. 20 */ 21 public static class HandleSignals extends Flags<HandleSignals> { 22 /** 23 * Constructor. 24 * 25 * @param signals the serialized signals. 26 */ HandleSignals(int signals)27 public HandleSignals(int signals) { 28 super(signals); 29 } 30 31 private static final int FLAG_NONE = 0; 32 private static final int FLAG_READABLE = 1 << 0; 33 private static final int FLAG_WRITABLE = 1 << 1; 34 private static final int FLAG_PEER_CLOSED = 1 << 2; 35 36 /** 37 * Immutable signals. 38 */ 39 public static final HandleSignals NONE = HandleSignals.none().immutable(); 40 public static final HandleSignals READABLE = 41 HandleSignals.none().setReadable(true).immutable(); 42 public static final HandleSignals WRITABLE = 43 HandleSignals.none().setWritable(true).immutable(); 44 45 /** 46 * Change the readable bit of this signal. 47 * 48 * @param readable the new value of the readable bit. 49 * @return this. 50 */ setReadable(boolean readable)51 public HandleSignals setReadable(boolean readable) { 52 return setFlag(FLAG_READABLE, readable); 53 } 54 55 /** 56 * Change the writable bit of this signal. 57 * 58 * @param writable the new value of the writable bit. 59 * @return this. 60 */ setWritable(boolean writable)61 public HandleSignals setWritable(boolean writable) { 62 return setFlag(FLAG_WRITABLE, writable); 63 } 64 65 /** 66 * Change the peer closed bit of this signal. 67 * 68 * @param peerClosed the new value of the peer closed bit. 69 * @return this. 70 */ setPeerClosed(boolean peerClosed)71 public HandleSignals setPeerClosed(boolean peerClosed) { 72 return setFlag(FLAG_PEER_CLOSED, peerClosed); 73 } 74 75 /** 76 * Returns a signal with no bit set. 77 */ none()78 public static HandleSignals none() { 79 return new HandleSignals(FLAG_NONE); 80 } 81 82 } 83 84 /** 85 * Returns a platform-dependent monotonically increasing tick count representing "right now." 86 */ getTimeTicksNow()87 public long getTimeTicksNow(); 88 89 /** 90 * Returned by wait functions to indicate the signaling state of handles. 91 */ 92 public static class HandleSignalsState { 93 /** 94 * Signals that were satisfied at some time // before the call returned. 95 */ 96 private final HandleSignals mSatisfiedSignals; 97 98 /** 99 * Signals that are possible to satisfy. For example, if the return value was 100 * |MOJO_RESULT_FAILED_PRECONDITION|, you can use this field to determine which, if any, of 101 * the signals can still be satisfied. 102 */ 103 private final HandleSignals mSatisfiableSignals; 104 105 /** 106 * Constructor. 107 */ HandleSignalsState( HandleSignals satisfiedSignals, HandleSignals satisfiableSignals)108 public HandleSignalsState( 109 HandleSignals satisfiedSignals, HandleSignals satisfiableSignals) { 110 mSatisfiedSignals = satisfiedSignals; 111 mSatisfiableSignals = satisfiableSignals; 112 } 113 114 /** 115 * Returns the satisfiedSignals. 116 */ getSatisfiedSignals()117 public HandleSignals getSatisfiedSignals() { 118 return mSatisfiedSignals; 119 } 120 121 /** 122 * Returns the satisfiableSignals. 123 */ getSatisfiableSignals()124 public HandleSignals getSatisfiableSignals() { 125 return mSatisfiableSignals; 126 } 127 } 128 129 /** 130 * Creates a message pipe, which is a bidirectional communication channel for framed data (i.e., 131 * messages), with the given options. Messages can contain plain data and/or Mojo handles. 132 * 133 * @return the set of handles for the two endpoints (ports) of the message pipe. 134 */ createMessagePipe( MessagePipeHandle.CreateOptions options)135 public Pair<MessagePipeHandle, MessagePipeHandle> createMessagePipe( 136 MessagePipeHandle.CreateOptions options); 137 138 /** 139 * Creates a data pipe, which is a unidirectional communication channel for unframed data, with 140 * the given options. Data is unframed, but must come as (multiples of) discrete elements, of 141 * the size given in |options|. See |DataPipe.CreateOptions| for a description of the different 142 * options available for data pipes. |options| may be set to null for a data pipe with the 143 * default options (which will have an element size of one byte and have some system-dependent 144 * capacity). 145 * 146 * @return the set of handles for the two endpoints of the data pipe. 147 */ createDataPipe( DataPipe.CreateOptions options)148 public Pair<DataPipe.ProducerHandle, DataPipe.ConsumerHandle> createDataPipe( 149 DataPipe.CreateOptions options); 150 151 /** 152 * Creates a buffer that can be shared between applications (by duplicating the handle -- see 153 * |SharedBufferHandle.duplicate()| -- and passing it over a message pipe). To access the 154 * buffer, one must call |SharedBufferHandle.map|. 155 * 156 * @return the new |SharedBufferHandle|. 157 */ createSharedBuffer(SharedBufferHandle.CreateOptions options, long numBytes)158 public SharedBufferHandle createSharedBuffer(SharedBufferHandle.CreateOptions options, 159 long numBytes); 160 161 /** 162 * Acquires a handle from the native side. The handle will be owned by the returned object and 163 * must not be closed outside of it. 164 * 165 * @return a new {@link UntypedHandle} representing the native handle. 166 */ acquireNativeHandle(int handle)167 public UntypedHandle acquireNativeHandle(int handle); 168 169 /** 170 * Returns an implementation of {@link Watcher}. 171 */ getWatcher()172 public Watcher getWatcher(); 173 174 /** 175 * Returns a new run loop. 176 */ createDefaultRunLoop()177 public RunLoop createDefaultRunLoop(); 178 179 /** 180 * Returns the current run loop if it exists. 181 */ getCurrentRunLoop()182 public RunLoop getCurrentRunLoop(); 183 } 184