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") {
deps = [
"//base:base_java",
"//base:jni_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.
......
......@@ -6,6 +6,7 @@ package org.chromium.mojo.system.impl;
import org.chromium.base.annotations.CalledByNative;
import org.chromium.base.annotations.JNINamespace;
import org.chromium.base.annotations.NativeMethods;
import org.chromium.mojo.system.RunLoop;
/**
......@@ -21,31 +22,31 @@ class BaseRunLoop implements RunLoop {
BaseRunLoop(CoreImpl core) {
this.mCore = core;
this.mRunLoopID = nativeCreateBaseRunLoop();
this.mRunLoopID = BaseRunLoopJni.get().createBaseRunLoop(BaseRunLoop.this);
}
@Override
public void run() {
assert mRunLoopID != 0 : "The run loop cannot run once closed";
nativeRun();
BaseRunLoopJni.get().run(BaseRunLoop.this);
}
@Override
public void runUntilIdle() {
assert mRunLoopID != 0 : "The run loop cannot run once closed";
nativeRunUntilIdle();
BaseRunLoopJni.get().runUntilIdle(BaseRunLoop.this);
}
@Override
public void quit() {
assert mRunLoopID != 0 : "The run loop cannot be quitted run once closed";
nativeQuit();
BaseRunLoopJni.get().quit(BaseRunLoop.this);
}
@Override
public void postDelayedTask(Runnable runnable, long delay) {
assert mRunLoopID != 0 : "The run loop cannot run tasks once closed";
nativePostDelayedTask(mRunLoopID, runnable, delay);
BaseRunLoopJni.get().postDelayedTask(BaseRunLoop.this, mRunLoopID, runnable, delay);
}
@Override
......@@ -56,7 +57,7 @@ class BaseRunLoop implements RunLoop {
// We don't want to de-register a different run loop!
assert mCore.getCurrentRunLoop() == this : "Only the current run loop can be closed";
mCore.clearCurrentRunLoop();
nativeDeleteMessageLoop(mRunLoopID);
BaseRunLoopJni.get().deleteMessageLoop(BaseRunLoop.this, mRunLoopID);
mRunLoopID = 0;
}
......@@ -65,10 +66,13 @@ class BaseRunLoop implements RunLoop {
runnable.run();
}
private native long nativeCreateBaseRunLoop();
private native void nativeRun();
private native void nativeRunUntilIdle();
private native void nativeQuit();
private native void nativePostDelayedTask(long runLoopID, Runnable runnable, long delay);
private native void nativeDeleteMessageLoop(long runLoopID);
@NativeMethods
interface Natives {
long createBaseRunLoop(BaseRunLoop caller);
void run(BaseRunLoop caller);
void runUntilIdle(BaseRunLoop caller);
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;
import org.chromium.base.annotations.CalledByNative;
import org.chromium.base.annotations.JNINamespace;
import org.chromium.base.annotations.MainDex;
import org.chromium.base.annotations.NativeMethods;
import org.chromium.mojo.system.Core;
import org.chromium.mojo.system.Core.HandleSignalsState;
import org.chromium.mojo.system.DataPipe;
......@@ -79,7 +80,8 @@ public class CoreImpl implements Core {
// Fix for the ART runtime, before:
// https://android.googlesource.com/platform/libcore/+/fb6c80875a8a8d0a9628562f89c250b6a962e824%5E!/
// 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 {
*/
@Override
public long getTimeTicksNow() {
return nativeGetTimeTicksNow();
return CoreImplJni.get().getTimeTicksNow(CoreImpl.this);
}
/**
......@@ -102,7 +104,8 @@ public class CoreImpl implements Core {
optionsBuffer.putInt(0, 8);
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) {
throw new MojoException(result.getMojoResult());
}
......@@ -124,7 +127,8 @@ public class CoreImpl implements Core {
optionsBuffer.putInt(8, options.getElementNumBytes());
optionsBuffer.putInt(12, options.getCapacityNumBytes());
}
ResultAnd<IntegerPair> result = nativeCreateDataPipe(optionsBuffer);
ResultAnd<IntegerPair> result =
CoreImplJni.get().createDataPipe(CoreImpl.this, optionsBuffer);
if (result.getMojoResult() != MojoResult.OK) {
throw new MojoException(result.getMojoResult());
}
......@@ -145,7 +149,8 @@ public class CoreImpl implements Core {
optionsBuffer.putInt(0, 8);
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) {
throw new MojoException(result.getMojoResult());
}
......@@ -197,11 +202,11 @@ public class CoreImpl implements Core {
}
int closeWithResult(int mojoHandle) {
return nativeClose(mojoHandle);
return CoreImplJni.get().close(CoreImpl.this, mojoHandle);
}
void close(int mojoHandle) {
int mojoResult = nativeClose(mojoHandle);
int mojoResult = CoreImplJni.get().close(CoreImpl.this, mojoHandle);
if (mojoResult != MojoResult.OK) {
throw new MojoException(mojoResult);
}
......@@ -209,7 +214,7 @@ public class CoreImpl implements Core {
HandleSignalsState queryHandleSignalsState(int mojoHandle) {
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);
return new HandleSignalsState(
new HandleSignals(buffer.getInt(0)), new HandleSignals(buffer.getInt(4)));
......@@ -228,8 +233,8 @@ public class CoreImpl implements Core {
}
handlesBuffer.position(0);
}
int mojoResult = nativeWriteMessage(pipeHandle.getMojoHandle(), bytes,
bytes == null ? 0 : bytes.limit(), handlesBuffer, flags.getFlags());
int mojoResult = CoreImplJni.get().writeMessage(CoreImpl.this, pipeHandle.getMojoHandle(),
bytes, bytes == null ? 0 : bytes.limit(), handlesBuffer, flags.getFlags());
if (mojoResult != MojoResult.OK) {
throw new MojoException(mojoResult);
}
......@@ -248,8 +253,8 @@ public class CoreImpl implements Core {
*/
ResultAnd<MessagePipeHandle.ReadMessageResult> readMessage(
MessagePipeHandleImpl handle, MessagePipeHandle.ReadFlags flags) {
ResultAnd<MessagePipeHandle.ReadMessageResult> result =
nativeReadMessage(handle.getMojoHandle(), flags.getFlags());
ResultAnd<MessagePipeHandle.ReadMessageResult> result = CoreImplJni.get().readMessage(
CoreImpl.this, handle.getMojoHandle(), flags.getFlags());
if (result.getMojoResult() != MojoResult.OK
&& result.getMojoResult() != MojoResult.SHOULD_WAIT) {
throw new MojoException(result.getMojoResult());
......@@ -273,8 +278,9 @@ public class CoreImpl implements Core {
* @see ConsumerHandle#discardData(int, DataPipe.ReadFlags)
*/
int discardData(DataPipeConsumerHandleImpl handle, int numBytes, DataPipe.ReadFlags flags) {
ResultAnd<Integer> result = nativeReadData(handle.getMojoHandle(), null, numBytes,
flags.getFlags() | MOJO_READ_DATA_FLAG_DISCARD);
ResultAnd<Integer> result =
CoreImplJni.get().readData(CoreImpl.this, handle.getMojoHandle(), null, numBytes,
flags.getFlags() | MOJO_READ_DATA_FLAG_DISCARD);
if (result.getMojoResult() != MojoResult.OK) {
throw new MojoException(result.getMojoResult());
}
......@@ -286,8 +292,9 @@ public class CoreImpl implements Core {
*/
ResultAnd<Integer> readData(
DataPipeConsumerHandleImpl handle, ByteBuffer elements, DataPipe.ReadFlags flags) {
ResultAnd<Integer> result = nativeReadData(handle.getMojoHandle(), elements,
elements == null ? 0 : elements.capacity(), flags.getFlags());
ResultAnd<Integer> result =
CoreImplJni.get().readData(CoreImpl.this, handle.getMojoHandle(), elements,
elements == null ? 0 : elements.capacity(), flags.getFlags());
if (result.getMojoResult() != MojoResult.OK
&& result.getMojoResult() != MojoResult.SHOULD_WAIT) {
throw new MojoException(result.getMojoResult());
......@@ -305,8 +312,8 @@ public class CoreImpl implements Core {
*/
ByteBuffer beginReadData(
DataPipeConsumerHandleImpl handle, int numBytes, DataPipe.ReadFlags flags) {
ResultAnd<ByteBuffer> result =
nativeBeginReadData(handle.getMojoHandle(), numBytes, flags.getFlags());
ResultAnd<ByteBuffer> result = CoreImplJni.get().beginReadData(
CoreImpl.this, handle.getMojoHandle(), numBytes, flags.getFlags());
if (result.getMojoResult() != MojoResult.OK) {
throw new MojoException(result.getMojoResult());
}
......@@ -317,7 +324,8 @@ public class CoreImpl implements Core {
* @see ConsumerHandle#endReadData(int)
*/
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) {
throw new MojoException(result);
}
......@@ -328,8 +336,8 @@ public class CoreImpl implements Core {
*/
ResultAnd<Integer> writeData(
DataPipeProducerHandleImpl handle, ByteBuffer elements, DataPipe.WriteFlags flags) {
return nativeWriteData(
handle.getMojoHandle(), elements, elements.limit(), flags.getFlags());
return CoreImplJni.get().writeData(CoreImpl.this, handle.getMojoHandle(), elements,
elements.limit(), flags.getFlags());
}
/**
......@@ -337,8 +345,8 @@ public class CoreImpl implements Core {
*/
ByteBuffer beginWriteData(
DataPipeProducerHandleImpl handle, int numBytes, DataPipe.WriteFlags flags) {
ResultAnd<ByteBuffer> result =
nativeBeginWriteData(handle.getMojoHandle(), numBytes, flags.getFlags());
ResultAnd<ByteBuffer> result = CoreImplJni.get().beginWriteData(
CoreImpl.this, handle.getMojoHandle(), numBytes, flags.getFlags());
if (result.getMojoResult() != MojoResult.OK) {
throw new MojoException(result.getMojoResult());
}
......@@ -349,7 +357,8 @@ public class CoreImpl implements Core {
* @see ProducerHandle#endWriteData(int)
*/
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) {
throw new MojoException(result);
}
......@@ -365,7 +374,8 @@ public class CoreImpl implements Core {
optionsBuffer.putInt(0, 8);
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) {
throw new MojoException(result.getMojoResult());
}
......@@ -376,8 +386,8 @@ public class CoreImpl implements Core {
* @see SharedBufferHandle#map(long, long, MapFlags)
*/
ByteBuffer map(SharedBufferHandleImpl handle, long offset, long numBytes, MapFlags flags) {
ResultAnd<ByteBuffer> result =
nativeMap(handle.getMojoHandle(), offset, numBytes, flags.getFlags());
ResultAnd<ByteBuffer> result = CoreImplJni.get().map(
CoreImpl.this, handle.getMojoHandle(), offset, numBytes, flags.getFlags());
if (result.getMojoResult() != MojoResult.OK) {
throw new MojoException(result.getMojoResult());
}
......@@ -388,7 +398,7 @@ public class CoreImpl implements Core {
* @see SharedBufferHandle#unmap(ByteBuffer)
*/
void unmap(ByteBuffer buffer) {
int result = nativeUnmap(buffer);
int result = CoreImplJni.get().unmap(CoreImpl.this, buffer);
if (result != MojoResult.OK) {
throw new MojoException(result);
}
......@@ -441,7 +451,7 @@ public class CoreImpl implements Core {
* Trivial alias for Pair<Integer, Integer>. This is needed because our jni generator is unable
* 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) {
super(first, second);
}
......@@ -469,47 +479,33 @@ public class CoreImpl implements Core {
return new ResultAnd<>(mojoResult, new IntegerPair(mojoHandle1, mojoHandle2));
}
private native long nativeGetTimeTicksNow();
private native ResultAnd<IntegerPair> nativeCreateMessagePipe(ByteBuffer optionsBuffer);
private native ResultAnd<IntegerPair> nativeCreateDataPipe(ByteBuffer optionsBuffer);
private native ResultAnd<Integer> nativeCreateSharedBuffer(
ByteBuffer optionsBuffer, long numBytes);
private native int nativeClose(int mojoHandle);
private native int nativeQueryHandleSignalsState(int mojoHandle, ByteBuffer signalsStateBuffer);
private native int nativeWriteMessage(
int mojoHandle, ByteBuffer bytes, int numBytes, ByteBuffer handlesBuffer, int flags);
private native ResultAnd<MessagePipeHandle.ReadMessageResult> nativeReadMessage(
int mojoHandle, int flags);
private native ResultAnd<Integer> nativeReadData(
int mojoHandle, ByteBuffer elements, int elementsSize, int flags);
private native ResultAnd<ByteBuffer> nativeBeginReadData(
int mojoHandle, int numBytes, int flags);
private native int nativeEndReadData(int mojoHandle, int numBytesRead);
private native ResultAnd<Integer> nativeWriteData(
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);
@NativeMethods
interface Natives {
long getTimeTicksNow(CoreImpl caller);
ResultAnd<IntegerPair> createMessagePipe(CoreImpl caller, ByteBuffer optionsBuffer);
ResultAnd<IntegerPair> createDataPipe(CoreImpl caller, ByteBuffer optionsBuffer);
ResultAnd<Integer> createSharedBuffer(
CoreImpl caller, ByteBuffer optionsBuffer, long numBytes);
int close(CoreImpl caller, int mojoHandle);
int queryHandleSignalsState(CoreImpl caller, int mojoHandle, ByteBuffer signalsStateBuffer);
int writeMessage(CoreImpl caller, int mojoHandle, ByteBuffer bytes, int numBytes,
ByteBuffer handlesBuffer, int flags);
ResultAnd<MessagePipeHandle.ReadMessageResult> readMessage(
CoreImpl caller, int mojoHandle, int flags);
ResultAnd<Integer> readData(
CoreImpl caller, int mojoHandle, ByteBuffer elements, int elementsSize, int flags);
ResultAnd<ByteBuffer> beginReadData(
CoreImpl caller, int mojoHandle, int numBytes, int flags);
int endReadData(CoreImpl caller, int mojoHandle, int numBytesRead);
ResultAnd<Integer> writeData(
CoreImpl caller, int mojoHandle, ByteBuffer elements, int limit, int flags);
ResultAnd<ByteBuffer> beginWriteData(
CoreImpl caller, int mojoHandle, int numBytes, int flags);
int endWriteData(CoreImpl caller, int mojoHandle, int numBytesWritten);
ResultAnd<Integer> duplicate(CoreImpl caller, int mojoHandle, ByteBuffer optionsBuffer);
ResultAnd<ByteBuffer> map(
CoreImpl caller, int mojoHandle, long offset, long numBytes, int flags);
int unmap(CoreImpl caller, ByteBuffer buffer);
int getNativeBufferOffset(CoreImpl caller, ByteBuffer buffer, int alignment);
}
}
......@@ -6,6 +6,7 @@ package org.chromium.mojo.system.impl;
import org.chromium.base.annotations.CalledByNative;
import org.chromium.base.annotations.JNINamespace;
import org.chromium.base.annotations.NativeMethods;
import org.chromium.mojo.system.Core;
import org.chromium.mojo.system.Handle;
import org.chromium.mojo.system.MojoResult;
......@@ -13,7 +14,7 @@ import org.chromium.mojo.system.Watcher;
@JNINamespace("mojo::android")
class WatcherImpl implements Watcher {
private long mImplPtr = nativeCreateWatcher();
private long mImplPtr = WatcherImplJni.get().createWatcher(WatcherImpl.this);
private Callback mCallback;
@Override
......@@ -24,8 +25,8 @@ class WatcherImpl implements Watcher {
if (!(handle instanceof HandleBase)) {
return MojoResult.INVALID_ARGUMENT;
}
int result =
nativeStart(mImplPtr, ((HandleBase) handle).getMojoHandle(), signals.getFlags());
int result = WatcherImplJni.get().start(WatcherImpl.this, mImplPtr,
((HandleBase) handle).getMojoHandle(), signals.getFlags());
if (result == MojoResult.OK) mCallback = callback;
return result;
}
......@@ -36,7 +37,7 @@ class WatcherImpl implements Watcher {
return;
}
mCallback = null;
nativeCancel(mImplPtr);
WatcherImplJni.get().cancel(WatcherImpl.this, mImplPtr);
}
@Override
......@@ -44,7 +45,7 @@ class WatcherImpl implements Watcher {
if (mImplPtr == 0) {
return;
}
nativeDelete(mImplPtr);
WatcherImplJni.get().delete(WatcherImpl.this, mImplPtr);
mImplPtr = 0;
}
......@@ -53,11 +54,11 @@ class WatcherImpl implements Watcher {
mCallback.onResult(result);
}
private native long nativeCreateWatcher();
private native int nativeStart(long implPtr, int mojoHandle, int flags);
private native void nativeCancel(long implPtr);
private native void nativeDelete(long implPtr);
@NativeMethods
interface Natives {
long createWatcher(WatcherImpl caller);
int start(WatcherImpl caller, long implPtr, int mojoHandle, int flags);
void cancel(WatcherImpl caller, long implPtr);
void delete(WatcherImpl caller, 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