Commit 1662bf88 authored by Eric Stevenson's avatar Eric Stevenson Committed by Commit Bot

JNI refactor: @NativeMethods conversion (//mojo).

This CL was generated by
//base/android/jni_generator/jni_refactorer.py.

Bug: 929661
Change-Id: Ia3a1f45ce0255362c44b51dded3abd640ad1d966
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1809335Reviewed-by: default avatarKen Rockot <rockot@google.com>
Commit-Queue: Eric Stevenson <estevenson@chromium.org>
Cr-Commit-Position: refs/heads/master@{#697825}
parent 901bcc21
...@@ -61,8 +61,10 @@ android_library("system_impl_java") { ...@@ -61,8 +61,10 @@ android_library("system_impl_java") {
deps = [ deps = [
"//base:base_java", "//base:base_java",
"//base:jni_java",
"//mojo/public/java:system_java", "//mojo/public/java:system_java",
] ]
annotation_processor_deps = [ "//base/android/jni_generator:jni_processor" ]
} }
# Targets should also depend on :test_support for the native side. # Targets should also depend on :test_support for the native side.
......
...@@ -6,6 +6,7 @@ package org.chromium.mojo.system.impl; ...@@ -6,6 +6,7 @@ package org.chromium.mojo.system.impl;
import org.chromium.base.annotations.CalledByNative; import org.chromium.base.annotations.CalledByNative;
import org.chromium.base.annotations.JNINamespace; import org.chromium.base.annotations.JNINamespace;
import org.chromium.base.annotations.NativeMethods;
import org.chromium.mojo.system.RunLoop; import org.chromium.mojo.system.RunLoop;
/** /**
...@@ -21,31 +22,31 @@ class BaseRunLoop implements RunLoop { ...@@ -21,31 +22,31 @@ class BaseRunLoop implements RunLoop {
BaseRunLoop(CoreImpl core) { BaseRunLoop(CoreImpl core) {
this.mCore = core; this.mCore = core;
this.mRunLoopID = nativeCreateBaseRunLoop(); this.mRunLoopID = BaseRunLoopJni.get().createBaseRunLoop(BaseRunLoop.this);
} }
@Override @Override
public void run() { public void run() {
assert mRunLoopID != 0 : "The run loop cannot run once closed"; assert mRunLoopID != 0 : "The run loop cannot run once closed";
nativeRun(); BaseRunLoopJni.get().run(BaseRunLoop.this);
} }
@Override @Override
public void runUntilIdle() { public void runUntilIdle() {
assert mRunLoopID != 0 : "The run loop cannot run once closed"; assert mRunLoopID != 0 : "The run loop cannot run once closed";
nativeRunUntilIdle(); BaseRunLoopJni.get().runUntilIdle(BaseRunLoop.this);
} }
@Override @Override
public void quit() { public void quit() {
assert mRunLoopID != 0 : "The run loop cannot be quitted run once closed"; assert mRunLoopID != 0 : "The run loop cannot be quitted run once closed";
nativeQuit(); BaseRunLoopJni.get().quit(BaseRunLoop.this);
} }
@Override @Override
public void postDelayedTask(Runnable runnable, long delay) { public void postDelayedTask(Runnable runnable, long delay) {
assert mRunLoopID != 0 : "The run loop cannot run tasks once closed"; assert mRunLoopID != 0 : "The run loop cannot run tasks once closed";
nativePostDelayedTask(mRunLoopID, runnable, delay); BaseRunLoopJni.get().postDelayedTask(BaseRunLoop.this, mRunLoopID, runnable, delay);
} }
@Override @Override
...@@ -56,7 +57,7 @@ class BaseRunLoop implements RunLoop { ...@@ -56,7 +57,7 @@ class BaseRunLoop implements RunLoop {
// We don't want to de-register a different run loop! // We don't want to de-register a different run loop!
assert mCore.getCurrentRunLoop() == this : "Only the current run loop can be closed"; assert mCore.getCurrentRunLoop() == this : "Only the current run loop can be closed";
mCore.clearCurrentRunLoop(); mCore.clearCurrentRunLoop();
nativeDeleteMessageLoop(mRunLoopID); BaseRunLoopJni.get().deleteMessageLoop(BaseRunLoop.this, mRunLoopID);
mRunLoopID = 0; mRunLoopID = 0;
} }
...@@ -65,10 +66,13 @@ class BaseRunLoop implements RunLoop { ...@@ -65,10 +66,13 @@ class BaseRunLoop implements RunLoop {
runnable.run(); runnable.run();
} }
private native long nativeCreateBaseRunLoop(); @NativeMethods
private native void nativeRun(); interface Natives {
private native void nativeRunUntilIdle(); long createBaseRunLoop(BaseRunLoop caller);
private native void nativeQuit(); void run(BaseRunLoop caller);
private native void nativePostDelayedTask(long runLoopID, Runnable runnable, long delay); void runUntilIdle(BaseRunLoop caller);
private native void nativeDeleteMessageLoop(long runLoopID); void quit(BaseRunLoop caller);
void postDelayedTask(BaseRunLoop caller, long runLoopID, Runnable runnable, long delay);
void deleteMessageLoop(BaseRunLoop caller, long runLoopID);
}
} }
...@@ -7,6 +7,7 @@ package org.chromium.mojo.system.impl; ...@@ -7,6 +7,7 @@ package org.chromium.mojo.system.impl;
import org.chromium.base.annotations.CalledByNative; import org.chromium.base.annotations.CalledByNative;
import org.chromium.base.annotations.JNINamespace; import org.chromium.base.annotations.JNINamespace;
import org.chromium.base.annotations.MainDex; import org.chromium.base.annotations.MainDex;
import org.chromium.base.annotations.NativeMethods;
import org.chromium.mojo.system.Core; import org.chromium.mojo.system.Core;
import org.chromium.mojo.system.Core.HandleSignalsState; import org.chromium.mojo.system.Core.HandleSignalsState;
import org.chromium.mojo.system.DataPipe; import org.chromium.mojo.system.DataPipe;
...@@ -79,7 +80,8 @@ public class CoreImpl implements Core { ...@@ -79,7 +80,8 @@ public class CoreImpl implements Core {
// Fix for the ART runtime, before: // Fix for the ART runtime, before:
// https://android.googlesource.com/platform/libcore/+/fb6c80875a8a8d0a9628562f89c250b6a962e824%5E!/ // https://android.googlesource.com/platform/libcore/+/fb6c80875a8a8d0a9628562f89c250b6a962e824%5E!/
// This assumes consistent allocation. // This assumes consistent allocation.
mByteBufferOffset = nativeGetNativeBufferOffset(ByteBuffer.allocateDirect(8), 8); mByteBufferOffset = CoreImplJni.get().getNativeBufferOffset(
CoreImpl.this, ByteBuffer.allocateDirect(8), 8);
} }
/** /**
...@@ -87,7 +89,7 @@ public class CoreImpl implements Core { ...@@ -87,7 +89,7 @@ public class CoreImpl implements Core {
*/ */
@Override @Override
public long getTimeTicksNow() { public long getTimeTicksNow() {
return nativeGetTimeTicksNow(); return CoreImplJni.get().getTimeTicksNow(CoreImpl.this);
} }
/** /**
...@@ -102,7 +104,8 @@ public class CoreImpl implements Core { ...@@ -102,7 +104,8 @@ public class CoreImpl implements Core {
optionsBuffer.putInt(0, 8); optionsBuffer.putInt(0, 8);
optionsBuffer.putInt(4, options.getFlags().getFlags()); optionsBuffer.putInt(4, options.getFlags().getFlags());
} }
ResultAnd<IntegerPair> result = nativeCreateMessagePipe(optionsBuffer); ResultAnd<IntegerPair> result =
CoreImplJni.get().createMessagePipe(CoreImpl.this, optionsBuffer);
if (result.getMojoResult() != MojoResult.OK) { if (result.getMojoResult() != MojoResult.OK) {
throw new MojoException(result.getMojoResult()); throw new MojoException(result.getMojoResult());
} }
...@@ -124,7 +127,8 @@ public class CoreImpl implements Core { ...@@ -124,7 +127,8 @@ public class CoreImpl implements Core {
optionsBuffer.putInt(8, options.getElementNumBytes()); optionsBuffer.putInt(8, options.getElementNumBytes());
optionsBuffer.putInt(12, options.getCapacityNumBytes()); optionsBuffer.putInt(12, options.getCapacityNumBytes());
} }
ResultAnd<IntegerPair> result = nativeCreateDataPipe(optionsBuffer); ResultAnd<IntegerPair> result =
CoreImplJni.get().createDataPipe(CoreImpl.this, optionsBuffer);
if (result.getMojoResult() != MojoResult.OK) { if (result.getMojoResult() != MojoResult.OK) {
throw new MojoException(result.getMojoResult()); throw new MojoException(result.getMojoResult());
} }
...@@ -145,7 +149,8 @@ public class CoreImpl implements Core { ...@@ -145,7 +149,8 @@ public class CoreImpl implements Core {
optionsBuffer.putInt(0, 8); optionsBuffer.putInt(0, 8);
optionsBuffer.putInt(4, options.getFlags().getFlags()); optionsBuffer.putInt(4, options.getFlags().getFlags());
} }
ResultAnd<Integer> result = nativeCreateSharedBuffer(optionsBuffer, numBytes); ResultAnd<Integer> result =
CoreImplJni.get().createSharedBuffer(CoreImpl.this, optionsBuffer, numBytes);
if (result.getMojoResult() != MojoResult.OK) { if (result.getMojoResult() != MojoResult.OK) {
throw new MojoException(result.getMojoResult()); throw new MojoException(result.getMojoResult());
} }
...@@ -197,11 +202,11 @@ public class CoreImpl implements Core { ...@@ -197,11 +202,11 @@ public class CoreImpl implements Core {
} }
int closeWithResult(int mojoHandle) { int closeWithResult(int mojoHandle) {
return nativeClose(mojoHandle); return CoreImplJni.get().close(CoreImpl.this, mojoHandle);
} }
void close(int mojoHandle) { void close(int mojoHandle) {
int mojoResult = nativeClose(mojoHandle); int mojoResult = CoreImplJni.get().close(CoreImpl.this, mojoHandle);
if (mojoResult != MojoResult.OK) { if (mojoResult != MojoResult.OK) {
throw new MojoException(mojoResult); throw new MojoException(mojoResult);
} }
...@@ -209,7 +214,7 @@ public class CoreImpl implements Core { ...@@ -209,7 +214,7 @@ public class CoreImpl implements Core {
HandleSignalsState queryHandleSignalsState(int mojoHandle) { HandleSignalsState queryHandleSignalsState(int mojoHandle) {
ByteBuffer buffer = allocateDirectBuffer(8); ByteBuffer buffer = allocateDirectBuffer(8);
int result = nativeQueryHandleSignalsState(mojoHandle, buffer); int result = CoreImplJni.get().queryHandleSignalsState(CoreImpl.this, mojoHandle, buffer);
if (result != MojoResult.OK) throw new MojoException(result); if (result != MojoResult.OK) throw new MojoException(result);
return new HandleSignalsState( return new HandleSignalsState(
new HandleSignals(buffer.getInt(0)), new HandleSignals(buffer.getInt(4))); new HandleSignals(buffer.getInt(0)), new HandleSignals(buffer.getInt(4)));
...@@ -228,8 +233,8 @@ public class CoreImpl implements Core { ...@@ -228,8 +233,8 @@ public class CoreImpl implements Core {
} }
handlesBuffer.position(0); handlesBuffer.position(0);
} }
int mojoResult = nativeWriteMessage(pipeHandle.getMojoHandle(), bytes, int mojoResult = CoreImplJni.get().writeMessage(CoreImpl.this, pipeHandle.getMojoHandle(),
bytes == null ? 0 : bytes.limit(), handlesBuffer, flags.getFlags()); bytes, bytes == null ? 0 : bytes.limit(), handlesBuffer, flags.getFlags());
if (mojoResult != MojoResult.OK) { if (mojoResult != MojoResult.OK) {
throw new MojoException(mojoResult); throw new MojoException(mojoResult);
} }
...@@ -248,8 +253,8 @@ public class CoreImpl implements Core { ...@@ -248,8 +253,8 @@ public class CoreImpl implements Core {
*/ */
ResultAnd<MessagePipeHandle.ReadMessageResult> readMessage( ResultAnd<MessagePipeHandle.ReadMessageResult> readMessage(
MessagePipeHandleImpl handle, MessagePipeHandle.ReadFlags flags) { MessagePipeHandleImpl handle, MessagePipeHandle.ReadFlags flags) {
ResultAnd<MessagePipeHandle.ReadMessageResult> result = ResultAnd<MessagePipeHandle.ReadMessageResult> result = CoreImplJni.get().readMessage(
nativeReadMessage(handle.getMojoHandle(), flags.getFlags()); CoreImpl.this, handle.getMojoHandle(), flags.getFlags());
if (result.getMojoResult() != MojoResult.OK if (result.getMojoResult() != MojoResult.OK
&& result.getMojoResult() != MojoResult.SHOULD_WAIT) { && result.getMojoResult() != MojoResult.SHOULD_WAIT) {
throw new MojoException(result.getMojoResult()); throw new MojoException(result.getMojoResult());
...@@ -273,8 +278,9 @@ public class CoreImpl implements Core { ...@@ -273,8 +278,9 @@ public class CoreImpl implements Core {
* @see ConsumerHandle#discardData(int, DataPipe.ReadFlags) * @see ConsumerHandle#discardData(int, DataPipe.ReadFlags)
*/ */
int discardData(DataPipeConsumerHandleImpl handle, int numBytes, DataPipe.ReadFlags flags) { int discardData(DataPipeConsumerHandleImpl handle, int numBytes, DataPipe.ReadFlags flags) {
ResultAnd<Integer> result = nativeReadData(handle.getMojoHandle(), null, numBytes, ResultAnd<Integer> result =
flags.getFlags() | MOJO_READ_DATA_FLAG_DISCARD); CoreImplJni.get().readData(CoreImpl.this, handle.getMojoHandle(), null, numBytes,
flags.getFlags() | MOJO_READ_DATA_FLAG_DISCARD);
if (result.getMojoResult() != MojoResult.OK) { if (result.getMojoResult() != MojoResult.OK) {
throw new MojoException(result.getMojoResult()); throw new MojoException(result.getMojoResult());
} }
...@@ -286,8 +292,9 @@ public class CoreImpl implements Core { ...@@ -286,8 +292,9 @@ public class CoreImpl implements Core {
*/ */
ResultAnd<Integer> readData( ResultAnd<Integer> readData(
DataPipeConsumerHandleImpl handle, ByteBuffer elements, DataPipe.ReadFlags flags) { DataPipeConsumerHandleImpl handle, ByteBuffer elements, DataPipe.ReadFlags flags) {
ResultAnd<Integer> result = nativeReadData(handle.getMojoHandle(), elements, ResultAnd<Integer> result =
elements == null ? 0 : elements.capacity(), flags.getFlags()); CoreImplJni.get().readData(CoreImpl.this, handle.getMojoHandle(), elements,
elements == null ? 0 : elements.capacity(), flags.getFlags());
if (result.getMojoResult() != MojoResult.OK if (result.getMojoResult() != MojoResult.OK
&& result.getMojoResult() != MojoResult.SHOULD_WAIT) { && result.getMojoResult() != MojoResult.SHOULD_WAIT) {
throw new MojoException(result.getMojoResult()); throw new MojoException(result.getMojoResult());
...@@ -305,8 +312,8 @@ public class CoreImpl implements Core { ...@@ -305,8 +312,8 @@ public class CoreImpl implements Core {
*/ */
ByteBuffer beginReadData( ByteBuffer beginReadData(
DataPipeConsumerHandleImpl handle, int numBytes, DataPipe.ReadFlags flags) { DataPipeConsumerHandleImpl handle, int numBytes, DataPipe.ReadFlags flags) {
ResultAnd<ByteBuffer> result = ResultAnd<ByteBuffer> result = CoreImplJni.get().beginReadData(
nativeBeginReadData(handle.getMojoHandle(), numBytes, flags.getFlags()); CoreImpl.this, handle.getMojoHandle(), numBytes, flags.getFlags());
if (result.getMojoResult() != MojoResult.OK) { if (result.getMojoResult() != MojoResult.OK) {
throw new MojoException(result.getMojoResult()); throw new MojoException(result.getMojoResult());
} }
...@@ -317,7 +324,8 @@ public class CoreImpl implements Core { ...@@ -317,7 +324,8 @@ public class CoreImpl implements Core {
* @see ConsumerHandle#endReadData(int) * @see ConsumerHandle#endReadData(int)
*/ */
void endReadData(DataPipeConsumerHandleImpl handle, int numBytesRead) { void endReadData(DataPipeConsumerHandleImpl handle, int numBytesRead) {
int result = nativeEndReadData(handle.getMojoHandle(), numBytesRead); int result =
CoreImplJni.get().endReadData(CoreImpl.this, handle.getMojoHandle(), numBytesRead);
if (result != MojoResult.OK) { if (result != MojoResult.OK) {
throw new MojoException(result); throw new MojoException(result);
} }
...@@ -328,8 +336,8 @@ public class CoreImpl implements Core { ...@@ -328,8 +336,8 @@ public class CoreImpl implements Core {
*/ */
ResultAnd<Integer> writeData( ResultAnd<Integer> writeData(
DataPipeProducerHandleImpl handle, ByteBuffer elements, DataPipe.WriteFlags flags) { DataPipeProducerHandleImpl handle, ByteBuffer elements, DataPipe.WriteFlags flags) {
return nativeWriteData( return CoreImplJni.get().writeData(CoreImpl.this, handle.getMojoHandle(), elements,
handle.getMojoHandle(), elements, elements.limit(), flags.getFlags()); elements.limit(), flags.getFlags());
} }
/** /**
...@@ -337,8 +345,8 @@ public class CoreImpl implements Core { ...@@ -337,8 +345,8 @@ public class CoreImpl implements Core {
*/ */
ByteBuffer beginWriteData( ByteBuffer beginWriteData(
DataPipeProducerHandleImpl handle, int numBytes, DataPipe.WriteFlags flags) { DataPipeProducerHandleImpl handle, int numBytes, DataPipe.WriteFlags flags) {
ResultAnd<ByteBuffer> result = ResultAnd<ByteBuffer> result = CoreImplJni.get().beginWriteData(
nativeBeginWriteData(handle.getMojoHandle(), numBytes, flags.getFlags()); CoreImpl.this, handle.getMojoHandle(), numBytes, flags.getFlags());
if (result.getMojoResult() != MojoResult.OK) { if (result.getMojoResult() != MojoResult.OK) {
throw new MojoException(result.getMojoResult()); throw new MojoException(result.getMojoResult());
} }
...@@ -349,7 +357,8 @@ public class CoreImpl implements Core { ...@@ -349,7 +357,8 @@ public class CoreImpl implements Core {
* @see ProducerHandle#endWriteData(int) * @see ProducerHandle#endWriteData(int)
*/ */
void endWriteData(DataPipeProducerHandleImpl handle, int numBytesWritten) { void endWriteData(DataPipeProducerHandleImpl handle, int numBytesWritten) {
int result = nativeEndWriteData(handle.getMojoHandle(), numBytesWritten); int result = CoreImplJni.get().endWriteData(
CoreImpl.this, handle.getMojoHandle(), numBytesWritten);
if (result != MojoResult.OK) { if (result != MojoResult.OK) {
throw new MojoException(result); throw new MojoException(result);
} }
...@@ -365,7 +374,8 @@ public class CoreImpl implements Core { ...@@ -365,7 +374,8 @@ public class CoreImpl implements Core {
optionsBuffer.putInt(0, 8); optionsBuffer.putInt(0, 8);
optionsBuffer.putInt(4, options.getFlags().getFlags()); optionsBuffer.putInt(4, options.getFlags().getFlags());
} }
ResultAnd<Integer> result = nativeDuplicate(handle.getMojoHandle(), optionsBuffer); ResultAnd<Integer> result =
CoreImplJni.get().duplicate(CoreImpl.this, handle.getMojoHandle(), optionsBuffer);
if (result.getMojoResult() != MojoResult.OK) { if (result.getMojoResult() != MojoResult.OK) {
throw new MojoException(result.getMojoResult()); throw new MojoException(result.getMojoResult());
} }
...@@ -376,8 +386,8 @@ public class CoreImpl implements Core { ...@@ -376,8 +386,8 @@ public class CoreImpl implements Core {
* @see SharedBufferHandle#map(long, long, MapFlags) * @see SharedBufferHandle#map(long, long, MapFlags)
*/ */
ByteBuffer map(SharedBufferHandleImpl handle, long offset, long numBytes, MapFlags flags) { ByteBuffer map(SharedBufferHandleImpl handle, long offset, long numBytes, MapFlags flags) {
ResultAnd<ByteBuffer> result = ResultAnd<ByteBuffer> result = CoreImplJni.get().map(
nativeMap(handle.getMojoHandle(), offset, numBytes, flags.getFlags()); CoreImpl.this, handle.getMojoHandle(), offset, numBytes, flags.getFlags());
if (result.getMojoResult() != MojoResult.OK) { if (result.getMojoResult() != MojoResult.OK) {
throw new MojoException(result.getMojoResult()); throw new MojoException(result.getMojoResult());
} }
...@@ -388,7 +398,7 @@ public class CoreImpl implements Core { ...@@ -388,7 +398,7 @@ public class CoreImpl implements Core {
* @see SharedBufferHandle#unmap(ByteBuffer) * @see SharedBufferHandle#unmap(ByteBuffer)
*/ */
void unmap(ByteBuffer buffer) { void unmap(ByteBuffer buffer) {
int result = nativeUnmap(buffer); int result = CoreImplJni.get().unmap(CoreImpl.this, buffer);
if (result != MojoResult.OK) { if (result != MojoResult.OK) {
throw new MojoException(result); throw new MojoException(result);
} }
...@@ -441,7 +451,7 @@ public class CoreImpl implements Core { ...@@ -441,7 +451,7 @@ public class CoreImpl implements Core {
* Trivial alias for Pair<Integer, Integer>. This is needed because our jni generator is unable * Trivial alias for Pair<Integer, Integer>. This is needed because our jni generator is unable
* to handle class that contains space. * to handle class that contains space.
*/ */
private static final class IntegerPair extends Pair<Integer, Integer> { static final class IntegerPair extends Pair<Integer, Integer> {
public IntegerPair(Integer first, Integer second) { public IntegerPair(Integer first, Integer second) {
super(first, second); super(first, second);
} }
...@@ -469,47 +479,33 @@ public class CoreImpl implements Core { ...@@ -469,47 +479,33 @@ public class CoreImpl implements Core {
return new ResultAnd<>(mojoResult, new IntegerPair(mojoHandle1, mojoHandle2)); return new ResultAnd<>(mojoResult, new IntegerPair(mojoHandle1, mojoHandle2));
} }
private native long nativeGetTimeTicksNow(); @NativeMethods
interface Natives {
private native ResultAnd<IntegerPair> nativeCreateMessagePipe(ByteBuffer optionsBuffer); long getTimeTicksNow(CoreImpl caller);
ResultAnd<IntegerPair> createMessagePipe(CoreImpl caller, ByteBuffer optionsBuffer);
private native ResultAnd<IntegerPair> nativeCreateDataPipe(ByteBuffer optionsBuffer); ResultAnd<IntegerPair> createDataPipe(CoreImpl caller, ByteBuffer optionsBuffer);
ResultAnd<Integer> createSharedBuffer(
private native ResultAnd<Integer> nativeCreateSharedBuffer( CoreImpl caller, ByteBuffer optionsBuffer, long numBytes);
ByteBuffer optionsBuffer, long numBytes); int close(CoreImpl caller, int mojoHandle);
int queryHandleSignalsState(CoreImpl caller, int mojoHandle, ByteBuffer signalsStateBuffer);
private native int nativeClose(int mojoHandle); int writeMessage(CoreImpl caller, int mojoHandle, ByteBuffer bytes, int numBytes,
ByteBuffer handlesBuffer, int flags);
private native int nativeQueryHandleSignalsState(int mojoHandle, ByteBuffer signalsStateBuffer); ResultAnd<MessagePipeHandle.ReadMessageResult> readMessage(
CoreImpl caller, int mojoHandle, int flags);
private native int nativeWriteMessage( ResultAnd<Integer> readData(
int mojoHandle, ByteBuffer bytes, int numBytes, ByteBuffer handlesBuffer, int flags); CoreImpl caller, int mojoHandle, ByteBuffer elements, int elementsSize, int flags);
ResultAnd<ByteBuffer> beginReadData(
private native ResultAnd<MessagePipeHandle.ReadMessageResult> nativeReadMessage( CoreImpl caller, int mojoHandle, int numBytes, int flags);
int mojoHandle, int flags); int endReadData(CoreImpl caller, int mojoHandle, int numBytesRead);
ResultAnd<Integer> writeData(
private native ResultAnd<Integer> nativeReadData( CoreImpl caller, int mojoHandle, ByteBuffer elements, int limit, int flags);
int mojoHandle, ByteBuffer elements, int elementsSize, int flags); ResultAnd<ByteBuffer> beginWriteData(
CoreImpl caller, int mojoHandle, int numBytes, int flags);
private native ResultAnd<ByteBuffer> nativeBeginReadData( int endWriteData(CoreImpl caller, int mojoHandle, int numBytesWritten);
int mojoHandle, int numBytes, int flags); ResultAnd<Integer> duplicate(CoreImpl caller, int mojoHandle, ByteBuffer optionsBuffer);
ResultAnd<ByteBuffer> map(
private native int nativeEndReadData(int mojoHandle, int numBytesRead); CoreImpl caller, int mojoHandle, long offset, long numBytes, int flags);
int unmap(CoreImpl caller, ByteBuffer buffer);
private native ResultAnd<Integer> nativeWriteData( int getNativeBufferOffset(CoreImpl caller, ByteBuffer buffer, int alignment);
int mojoHandle, ByteBuffer elements, int limit, int flags); }
private native ResultAnd<ByteBuffer> nativeBeginWriteData(
int mojoHandle, int numBytes, int flags);
private native int nativeEndWriteData(int mojoHandle, int numBytesWritten);
private native ResultAnd<Integer> nativeDuplicate(int mojoHandle, ByteBuffer optionsBuffer);
private native ResultAnd<ByteBuffer> nativeMap(
int mojoHandle, long offset, long numBytes, int flags);
private native int nativeUnmap(ByteBuffer buffer);
private native int nativeGetNativeBufferOffset(ByteBuffer buffer, int alignment);
} }
...@@ -6,6 +6,7 @@ package org.chromium.mojo.system.impl; ...@@ -6,6 +6,7 @@ package org.chromium.mojo.system.impl;
import org.chromium.base.annotations.CalledByNative; import org.chromium.base.annotations.CalledByNative;
import org.chromium.base.annotations.JNINamespace; import org.chromium.base.annotations.JNINamespace;
import org.chromium.base.annotations.NativeMethods;
import org.chromium.mojo.system.Core; import org.chromium.mojo.system.Core;
import org.chromium.mojo.system.Handle; import org.chromium.mojo.system.Handle;
import org.chromium.mojo.system.MojoResult; import org.chromium.mojo.system.MojoResult;
...@@ -13,7 +14,7 @@ import org.chromium.mojo.system.Watcher; ...@@ -13,7 +14,7 @@ import org.chromium.mojo.system.Watcher;
@JNINamespace("mojo::android") @JNINamespace("mojo::android")
class WatcherImpl implements Watcher { class WatcherImpl implements Watcher {
private long mImplPtr = nativeCreateWatcher(); private long mImplPtr = WatcherImplJni.get().createWatcher(WatcherImpl.this);
private Callback mCallback; private Callback mCallback;
@Override @Override
...@@ -24,8 +25,8 @@ class WatcherImpl implements Watcher { ...@@ -24,8 +25,8 @@ class WatcherImpl implements Watcher {
if (!(handle instanceof HandleBase)) { if (!(handle instanceof HandleBase)) {
return MojoResult.INVALID_ARGUMENT; return MojoResult.INVALID_ARGUMENT;
} }
int result = int result = WatcherImplJni.get().start(WatcherImpl.this, mImplPtr,
nativeStart(mImplPtr, ((HandleBase) handle).getMojoHandle(), signals.getFlags()); ((HandleBase) handle).getMojoHandle(), signals.getFlags());
if (result == MojoResult.OK) mCallback = callback; if (result == MojoResult.OK) mCallback = callback;
return result; return result;
} }
...@@ -36,7 +37,7 @@ class WatcherImpl implements Watcher { ...@@ -36,7 +37,7 @@ class WatcherImpl implements Watcher {
return; return;
} }
mCallback = null; mCallback = null;
nativeCancel(mImplPtr); WatcherImplJni.get().cancel(WatcherImpl.this, mImplPtr);
} }
@Override @Override
...@@ -44,7 +45,7 @@ class WatcherImpl implements Watcher { ...@@ -44,7 +45,7 @@ class WatcherImpl implements Watcher {
if (mImplPtr == 0) { if (mImplPtr == 0) {
return; return;
} }
nativeDelete(mImplPtr); WatcherImplJni.get().delete(WatcherImpl.this, mImplPtr);
mImplPtr = 0; mImplPtr = 0;
} }
...@@ -53,11 +54,11 @@ class WatcherImpl implements Watcher { ...@@ -53,11 +54,11 @@ class WatcherImpl implements Watcher {
mCallback.onResult(result); mCallback.onResult(result);
} }
private native long nativeCreateWatcher(); @NativeMethods
interface Natives {
private native int nativeStart(long implPtr, int mojoHandle, int flags); long createWatcher(WatcherImpl caller);
int start(WatcherImpl caller, long implPtr, int mojoHandle, int flags);
private native void nativeCancel(long implPtr); void cancel(WatcherImpl caller, long implPtr);
void delete(WatcherImpl caller, long implPtr);
private native void nativeDelete(long implPtr); }
} }
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment