Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(846)

Unified Diff: mojo/android/system/src/org/chromium/mojo/system/impl/CoreImpl.java

Issue 2750273002: Revert of Mojo EDK: Introduce MojoQueryHandleSignalsState API (Closed)
Patch Set: Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: mojo/android/system/src/org/chromium/mojo/system/impl/CoreImpl.java
diff --git a/mojo/android/system/src/org/chromium/mojo/system/impl/CoreImpl.java b/mojo/android/system/src/org/chromium/mojo/system/impl/CoreImpl.java
index 173f80180f6639f25ef85991a409cb4ada75a49c..8330586714ab02779d4020b7a8ffbba3227be343 100644
--- a/mojo/android/system/src/org/chromium/mojo/system/impl/CoreImpl.java
+++ b/mojo/android/system/src/org/chromium/mojo/system/impl/CoreImpl.java
@@ -8,7 +8,6 @@
import org.chromium.base.annotations.JNINamespace;
import org.chromium.base.annotations.MainDex;
import org.chromium.mojo.system.Core;
-import org.chromium.mojo.system.Core.HandleSignalsState;
import org.chromium.mojo.system.DataPipe;
import org.chromium.mojo.system.DataPipe.ConsumerHandle;
import org.chromium.mojo.system.DataPipe.ProducerHandle;
@@ -28,6 +27,7 @@
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.List;
/**
@@ -88,6 +88,61 @@
@Override
public long getTimeTicksNow() {
return nativeGetTimeTicksNow();
+ }
+
+ /**
+ * @see Core#waitMany(List, long)
+ */
+ @Override
+ public WaitManyResult waitMany(List<Pair<Handle, HandleSignals>> handles, long deadline) {
+ // Allocate a direct buffer to allow native code not to reach back to java. The buffer
+ // layout will be:
+ // input: The array of handles (int, 4 bytes each)
+ // input: The array of signals (int, 4 bytes each)
+ // space for output: The array of handle states (2 ints, 8 bytes each)
+ // Space for output: The result index (int, 4 bytes)
+ // The handles and signals will be filled before calling the native method. When the native
+ // method returns, the handle states and the index will have been set.
+ ByteBuffer buffer = allocateDirectBuffer(handles.size() * 16 + 4);
+ int index = 0;
+ for (Pair<Handle, HandleSignals> handle : handles) {
+ buffer.putInt(HANDLE_SIZE * index, getMojoHandle(handle.first));
+ buffer.putInt(
+ HANDLE_SIZE * handles.size() + FLAG_SIZE * index, handle.second.getFlags());
+ index++;
+ }
+ int code = nativeWaitMany(buffer, deadline);
+ WaitManyResult result = new WaitManyResult();
+ result.setMojoResult(filterMojoResultForWait(code));
+ result.setHandleIndex(buffer.getInt(handles.size() * 16));
+ if (result.getMojoResult() != MojoResult.INVALID_ARGUMENT
+ && result.getMojoResult() != MojoResult.RESOURCE_EXHAUSTED) {
+ HandleSignalsState[] states = new HandleSignalsState[handles.size()];
+ for (int i = 0; i < handles.size(); ++i) {
+ states[i] = new HandleSignalsState(
+ new HandleSignals(buffer.getInt(8 * (handles.size() + i))),
+ new HandleSignals(buffer.getInt(8 * (handles.size() + i) + 4)));
+ }
+ result.setSignalStates(Arrays.asList(states));
+ }
+ return result;
+ }
+
+ /**
+ * @see Core#wait(Handle, HandleSignals, long)
+ */
+ @Override
+ public WaitResult wait(Handle handle, HandleSignals signals, long deadline) {
+ // Allocate a direct buffer to allow native code not to reach back to java. Buffer will
+ // contain spaces to write the handle state.
+ ByteBuffer buffer = allocateDirectBuffer(8);
+ WaitResult result = new WaitResult();
+ result.setMojoResult(filterMojoResultForWait(
+ nativeWait(buffer, getMojoHandle(handle), signals.getFlags(), deadline)));
+ HandleSignalsState signalsState = new HandleSignalsState(
+ new HandleSignals(buffer.getInt(0)), new HandleSignals(buffer.getInt(4)));
+ result.setHandleSignalsState(signalsState);
+ return result;
}
/**
@@ -205,14 +260,6 @@
if (mojoResult != MojoResult.OK) {
throw new MojoException(mojoResult);
}
- }
-
- HandleSignalsState queryHandleSignalsState(int mojoHandle) {
- ByteBuffer buffer = allocateDirectBuffer(8);
- int result = nativeQueryHandleSignalsState(mojoHandle, buffer);
- if (result != MojoResult.OK) throw new MojoException(result);
- return new HandleSignalsState(
- new HandleSignals(buffer.getInt(0)), new HandleSignals(buffer.getInt(4)));
}
/**
@@ -478,6 +525,8 @@
private native long nativeGetTimeTicksNow();
+ private native int nativeWaitMany(ByteBuffer buffer, long deadline);
+
private native ResultAnd<IntegerPair> nativeCreateMessagePipe(ByteBuffer optionsBuffer);
private native ResultAnd<IntegerPair> nativeCreateDataPipe(ByteBuffer optionsBuffer);
@@ -487,7 +536,7 @@
private native int nativeClose(int mojoHandle);
- private native int nativeQueryHandleSignalsState(int mojoHandle, ByteBuffer signalsStateBuffer);
+ private native int nativeWait(ByteBuffer buffer, int mojoHandle, int signals, long deadline);
private native int nativeWriteMessage(
int mojoHandle, ByteBuffer bytes, int numBytes, ByteBuffer handlesBuffer, int flags);
« no previous file with comments | « mojo/android/system/core_impl.cc ('k') | mojo/android/system/src/org/chromium/mojo/system/impl/HandleBase.java » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698