From 54cb593812104e6cfd93dbbd47fd2037fd46f67b Mon Sep 17 00:00:00 2001 From: "qsr@chromium.org" Date: Wed, 28 May 2014 14:02:38 +0000 Subject: Updates mojo java core API - Refactor test case to be re-usable - Refactor writeMessage signature to be able to take List of typed handles. - Refactor flags to enable access to constant flags for usual values. - Refactor ReadMessageResult to return the MojoResult value, as we need to differenciate OK, RESOURCE_EXHAUSTED and SHOULD_WAIT Review URL: https://codereview.chromium.org/297833005 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@273215 0039d316-1c4b-4281-b951-d872f2087c98 --- mojo/android/system/core_impl.cc | 2 +- .../src/org/chromium/mojo/system/CoreImpl.java | 69 ++++++---------------- .../mojo/system/MessagePipeHandleImpl.java | 2 +- 3 files changed, 20 insertions(+), 53 deletions(-) (limited to 'mojo/android/system') diff --git a/mojo/android/system/core_impl.cc b/mojo/android/system/core_impl.cc index 34d009c..473bf32 100644 --- a/mojo/android/system/core_impl.cc +++ b/mojo/android/system/core_impl.cc @@ -183,7 +183,7 @@ static jobject ReadMessage(JNIEnv* env, MojoResult result = MojoReadMessage( mojo_handle, buffer_start, &buffer_size, handles, &num_handles, flags); // Jave code will handle taking ownership of any received handle. - return Java_CoreImpl_newNativeReadMessageResult( + return Java_CoreImpl_newReadMessageResult( env, result, buffer_size, num_handles).Release(); } diff --git a/mojo/android/system/src/org/chromium/mojo/system/CoreImpl.java b/mojo/android/system/src/org/chromium/mojo/system/CoreImpl.java index be3c706..af94b44 100644 --- a/mojo/android/system/src/org/chromium/mojo/system/CoreImpl.java +++ b/mojo/android/system/src/org/chromium/mojo/system/CoreImpl.java @@ -20,7 +20,9 @@ import java.util.List; /** * Implementation of {@link Core}. */ -@JNIAdditionalImport(AsyncWaiter.class) +@JNIAdditionalImport({ + AsyncWaiter.class, + MessagePipeHandle.class }) @JNINamespace("mojo::android") public class CoreImpl implements Core, AsyncWaiter { @@ -189,7 +191,7 @@ public class CoreImpl implements Core, AsyncWaiter { * @see MessagePipeHandle#writeMessage(ByteBuffer, List, MessagePipeHandle.WriteFlags) */ void writeMessage(MessagePipeHandleImpl pipeHandle, ByteBuffer bytes, - List handles, MessagePipeHandle.WriteFlags flags) { + List handles, MessagePipeHandle.WriteFlags flags) { ByteBuffer handlesBuffer = null; if (handles != null && !handles.isEmpty()) { handlesBuffer = allocateDirectBuffer(handles.size() * HANDLE_SIZE); @@ -224,28 +226,29 @@ public class CoreImpl implements Core, AsyncWaiter { if (maxNumberOfHandles > 0) { handlesBuffer = allocateDirectBuffer(maxNumberOfHandles * HANDLE_SIZE); } - NativeReadMessageResult result = nativeReadMessage( + MessagePipeHandle.ReadMessageResult result = nativeReadMessage( handle.getMojoHandle(), bytes, handlesBuffer, flags.getFlags()); if (result.getMojoResult() != MojoResult.OK && - result.getMojoResult() != MojoResult.RESOURCE_EXHAUSTED) { + result.getMojoResult() != MojoResult.RESOURCE_EXHAUSTED && + result.getMojoResult() != MojoResult.SHOULD_WAIT) { throw new MojoException(result.getMojoResult()); } if (result.getMojoResult() == MojoResult.OK) { if (bytes != null) { bytes.position(0); - bytes.limit(result.getReadMessageResult().getMessageSize()); + bytes.limit(result.getMessageSize()); } List handles = new ArrayList( - result.getReadMessageResult().getHandlesCount()); - for (int i = 0; i < result.getReadMessageResult().getHandlesCount(); ++i) { + result.getHandlesCount()); + for (int i = 0; i < result.getHandlesCount(); ++i) { int mojoHandle = handlesBuffer.getInt(HANDLE_SIZE * i); handles.add(new UntypedHandleImpl(this, mojoHandle)); } - result.getReadMessageResult().setHandles(handles); + result.setHandles(handles); } - return result.getReadMessageResult(); + return result; } /** @@ -524,55 +527,18 @@ public class CoreImpl implements Core, AsyncWaiter { return result; } - private static class NativeReadMessageResult { - public int mMojoResult; - public MessagePipeHandle.ReadMessageResult mReadMessageResult; - - /** - * @return the mojoResult - */ - public int getMojoResult() { - return mMojoResult; - } - - /** - * @param mojoResult the mojoResult to set - */ - public void setMojoResult(int mojoResult) { - this.mMojoResult = mojoResult; - } - - /** - * @return the readMessageResult - */ - public MessagePipeHandle.ReadMessageResult getReadMessageResult() { - return mReadMessageResult; - } - - /** - * @param readMessageResult the readMessageResult to set - */ - public void setReadMessageResult(MessagePipeHandle.ReadMessageResult readMessageResult) { - this.mReadMessageResult = readMessageResult; - } - } - @CalledByNative - private static NativeReadMessageResult newNativeReadMessageResult(int mojoResult, + private static MessagePipeHandle.ReadMessageResult newReadMessageResult(int mojoResult, int messageSize, int handlesCount) { - NativeReadMessageResult result = new NativeReadMessageResult(); + MessagePipeHandle.ReadMessageResult result = new MessagePipeHandle.ReadMessageResult(); if (mojoResult >= 0) { result.setMojoResult(MojoResult.OK); } else { result.setMojoResult(mojoResult); } - MessagePipeHandle.ReadMessageResult readMessageResult = - new MessagePipeHandle.ReadMessageResult(); - readMessageResult.setWasMessageRead(result.getMojoResult() == MojoResult.OK); - readMessageResult.setMessageSize(messageSize); - readMessageResult.setHandlesCount(handlesCount); - result.setReadMessageResult(readMessageResult); + result.setMessageSize(messageSize); + result.setHandlesCount(handlesCount); return result; } @@ -654,7 +620,8 @@ public class CoreImpl implements Core, AsyncWaiter { private native int nativeWriteMessage(int mojoHandle, ByteBuffer bytes, int numBytes, ByteBuffer handlesBuffer, int flags); - private native NativeReadMessageResult nativeReadMessage(int mojoHandle, ByteBuffer bytes, + private native MessagePipeHandle.ReadMessageResult nativeReadMessage(int mojoHandle, + ByteBuffer bytes, ByteBuffer handlesBuffer, int flags); diff --git a/mojo/android/system/src/org/chromium/mojo/system/MessagePipeHandleImpl.java b/mojo/android/system/src/org/chromium/mojo/system/MessagePipeHandleImpl.java index cbe42af8..54985b1 100644 --- a/mojo/android/system/src/org/chromium/mojo/system/MessagePipeHandleImpl.java +++ b/mojo/android/system/src/org/chromium/mojo/system/MessagePipeHandleImpl.java @@ -30,7 +30,7 @@ class MessagePipeHandleImpl extends HandleBase implements MessagePipeHandle { * @see MessagePipeHandle#writeMessage(ByteBuffer, List, WriteFlags) */ @Override - public void writeMessage(ByteBuffer bytes, List handles, WriteFlags flags) { + public void writeMessage(ByteBuffer bytes, List handles, WriteFlags flags) { mCore.writeMessage(this, bytes, handles, flags); } -- cgit v1.1