diff options
author | qsr@chromium.org <qsr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-07-16 21:29:27 +0000 |
---|---|---|
committer | qsr@chromium.org <qsr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-07-16 21:29:27 +0000 |
commit | 1cf53fa74a2aa53382505fb45acee76331f31b34 (patch) | |
tree | 0bf917be1819d4c1a6407d96fb8cd3f06a78b5ea | |
parent | 8221d58715f2a05503d85037de8bf65d7c8c086f (diff) | |
download | chromium_src-1cf53fa74a2aa53382505fb45acee76331f31b34.zip chromium_src-1cf53fa74a2aa53382505fb45acee76331f31b34.tar.gz chromium_src-1cf53fa74a2aa53382505fb45acee76331f31b34.tar.bz2 |
Add support for MojoCreateMessagePipeOptions struct to Java bindings
R=viettrungluu@chromium.org
BUG=386892
Review URL: https://codereview.chromium.org/397493007
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@283515 0039d316-1c4b-4281-b951-d872f2087c98
9 files changed, 114 insertions, 31 deletions
diff --git a/mojo/android/javatests/src/org/chromium/mojo/bindings/ConnectorTest.java b/mojo/android/javatests/src/org/chromium/mojo/bindings/ConnectorTest.java index 57f2550..21ac624 100644 --- a/mojo/android/javatests/src/org/chromium/mojo/bindings/ConnectorTest.java +++ b/mojo/android/javatests/src/org/chromium/mojo/bindings/ConnectorTest.java @@ -42,7 +42,8 @@ public class ConnectorTest extends MojoTestCase { protected void setUp() throws Exception { super.setUp(); Core core = CoreImpl.getInstance(); - Pair<MessagePipeHandle, MessagePipeHandle> handles = core.createMessagePipe(); + Pair<MessagePipeHandle, MessagePipeHandle> handles = core.createMessagePipe( + new MessagePipeHandle.CreateOptions()); mHandle = handles.first; mConnector = new Connector(handles.second); mReceiver = new RecordingMessageReceiver(); diff --git a/mojo/android/javatests/src/org/chromium/mojo/bindings/MessageTest.java b/mojo/android/javatests/src/org/chromium/mojo/bindings/MessageTest.java index 9f518f5..ab2e871 100644 --- a/mojo/android/javatests/src/org/chromium/mojo/bindings/MessageTest.java +++ b/mojo/android/javatests/src/org/chromium/mojo/bindings/MessageTest.java @@ -45,7 +45,7 @@ public class MessageTest extends MojoTestCase { Core core = CoreImpl.getInstance(); mData = TestUtils.newRandomBuffer(DATA_SIZE); mMessageReceiver = new RecordingMessageReceiver(); - mHandles = core.createMessagePipe(); + mHandles = core.createMessagePipe(new MessagePipeHandle.CreateOptions()); Pair<DataPipe.ProducerHandle, DataPipe.ConsumerHandle> datapipe = core.createDataPipe(null); mHandlesToSend.addAll(Arrays.asList(datapipe.first, datapipe.second)); mHandlesToClose.addAll(Arrays.asList(mHandles.first, mHandles.second)); diff --git a/mojo/android/javatests/src/org/chromium/mojo/system/impl/CoreImplTest.java b/mojo/android/javatests/src/org/chromium/mojo/system/impl/CoreImplTest.java index e3afb81..abe7fa3 100644 --- a/mojo/android/javatests/src/org/chromium/mojo/system/impl/CoreImplTest.java +++ b/mojo/android/javatests/src/org/chromium/mojo/system/impl/CoreImplTest.java @@ -174,7 +174,7 @@ public class CoreImplTest extends MojoTestCase { @SmallTest public void testWaitMany() { Core core = CoreImpl.getInstance(); - Pair<MessagePipeHandle, MessagePipeHandle> handles = core.createMessagePipe(); + Pair<MessagePipeHandle, MessagePipeHandle> handles = core.createMessagePipe(null); addHandlePairToClose(handles); List<Pair<Handle, Core.HandleSignals>> handlesToWaitOn = new ArrayList< @@ -204,7 +204,7 @@ public class CoreImplTest extends MojoTestCase { public void testGetCore() { Core core = CoreImpl.getInstance(); - Pair<? extends Handle, ? extends Handle> handles = core.createMessagePipe(); + Pair<? extends Handle, ? extends Handle> handles = core.createMessagePipe(null); addHandlePairToClose(handles); assertEquals(core, handles.first.getCore()); assertEquals(core, handles.second.getCore()); @@ -222,13 +222,31 @@ public class CoreImplTest extends MojoTestCase { assertEquals(core, handle2.getCore()); } + private static void createAndCloseMessagePipe(MessagePipeHandle.CreateOptions options) { + Core core = CoreImpl.getInstance(); + Pair<MessagePipeHandle, MessagePipeHandle> handles = core.createMessagePipe(options); + handles.first.close(); + handles.second.close(); + } + + /** + * Testing {@link MessagePipeHandle} creation. + */ + @SmallTest + public void testMessagePipeCreation() { + // Test creation with null options. + createAndCloseMessagePipe(null); + // Test creation with default options. + createAndCloseMessagePipe(new MessagePipeHandle.CreateOptions()); + } + /** * Testing {@link MessagePipeHandle}. */ @SmallTest public void testMessagePipeEmpty() { Core core = CoreImpl.getInstance(); - Pair<MessagePipeHandle, MessagePipeHandle> handles = core.createMessagePipe(); + Pair<MessagePipeHandle, MessagePipeHandle> handles = core.createMessagePipe(null); addHandlePairToClose(handles); // Testing wait. assertEquals(MojoResult.OK, @@ -248,7 +266,7 @@ public class CoreImplTest extends MojoTestCase { assertEquals(MojoResult.CANCELLED, handles.first.wait(Core.HandleSignals.READABLE, 1000000L)); - handles = core.createMessagePipe(); + handles = core.createMessagePipe(null); addHandlePairToClose(handles); // Closing the other pipe while waiting. @@ -269,7 +287,7 @@ public class CoreImplTest extends MojoTestCase { @SmallTest public void testMessagePipeSend() { Core core = CoreImpl.getInstance(); - Pair<MessagePipeHandle, MessagePipeHandle> handles = core.createMessagePipe(); + Pair<MessagePipeHandle, MessagePipeHandle> handles = core.createMessagePipe(null); addHandlePairToClose(handles); checkSendingMessage(handles.first, handles.second); @@ -283,7 +301,7 @@ public class CoreImplTest extends MojoTestCase { public void testMessagePipeReceiveOnSmallBuffer() { Random random = new Random(); Core core = CoreImpl.getInstance(); - Pair<MessagePipeHandle, MessagePipeHandle> handles = core.createMessagePipe(); + Pair<MessagePipeHandle, MessagePipeHandle> handles = core.createMessagePipe(null); addHandlePairToClose(handles); // Writing a random 8 bytes message. @@ -307,8 +325,8 @@ public class CoreImplTest extends MojoTestCase { @SmallTest public void testMessagePipeSendHandles() { Core core = CoreImpl.getInstance(); - Pair<MessagePipeHandle, MessagePipeHandle> handles = core.createMessagePipe(); - Pair<MessagePipeHandle, MessagePipeHandle> handlesToShare = core.createMessagePipe(); + Pair<MessagePipeHandle, MessagePipeHandle> handles = core.createMessagePipe(null); + Pair<MessagePipeHandle, MessagePipeHandle> handlesToShare = core.createMessagePipe(null); addHandlePairToClose(handles); addHandlePairToClose(handlesToShare); @@ -509,7 +527,7 @@ public class CoreImplTest extends MojoTestCase { // Until the behavior is changed on the C++ side, handle gracefully 2 different use case: // - Receive a INVALID_ARGUMENT exception // - Receive an invalid handle on the other side. - Pair<MessagePipeHandle, MessagePipeHandle> handles = core.createMessagePipe(); + Pair<MessagePipeHandle, MessagePipeHandle> handles = core.createMessagePipe(null); addHandlePairToClose(handles); try { handles.first.writeMessage(null, Collections.<Handle> singletonList(handle), @@ -567,7 +585,7 @@ public class CoreImplTest extends MojoTestCase { Core core = CoreImpl.getInstance(); // Checking a correct result. - Pair<MessagePipeHandle, MessagePipeHandle> handles = core.createMessagePipe(); + Pair<MessagePipeHandle, MessagePipeHandle> handles = core.createMessagePipe(null); addHandlePairToClose(handles); final AsyncWaiterResult asyncWaiterResult = new AsyncWaiterResult(); assertEquals(Integer.MIN_VALUE, asyncWaiterResult.getResult()); @@ -593,7 +611,7 @@ public class CoreImplTest extends MojoTestCase { Core core = CoreImpl.getInstance(); // Closing the peer handle. - Pair<MessagePipeHandle, MessagePipeHandle> handles = core.createMessagePipe(); + Pair<MessagePipeHandle, MessagePipeHandle> handles = core.createMessagePipe(null); addHandlePairToClose(handles); final AsyncWaiterResult asyncWaiterResult = new AsyncWaiterResult(); @@ -623,7 +641,7 @@ public class CoreImplTest extends MojoTestCase { Core core = CoreImpl.getInstance(); // Closing the peer handle. - Pair<MessagePipeHandle, MessagePipeHandle> handles = core.createMessagePipe(); + Pair<MessagePipeHandle, MessagePipeHandle> handles = core.createMessagePipe(null); addHandlePairToClose(handles); final AsyncWaiterResult asyncWaiterResult = new AsyncWaiterResult(); @@ -654,7 +672,7 @@ public class CoreImplTest extends MojoTestCase { Core core = CoreImpl.getInstance(); // Closing the peer handle. - Pair<MessagePipeHandle, MessagePipeHandle> handles = core.createMessagePipe(); + Pair<MessagePipeHandle, MessagePipeHandle> handles = core.createMessagePipe(null); addHandlePairToClose(handles); final AsyncWaiterResult asyncWaiterResult = new AsyncWaiterResult(); @@ -704,7 +722,7 @@ public class CoreImplTest extends MojoTestCase { Core core = CoreImpl.getInstance(); // Closing the peer handle. - Pair<MessagePipeHandle, MessagePipeHandle> handles = core.createMessagePipe(); + Pair<MessagePipeHandle, MessagePipeHandle> handles = core.createMessagePipe(null); addHandlePairToClose(handles); final AsyncWaiterResult asyncWaiterResult = new AsyncWaiterResult(); @@ -729,7 +747,7 @@ public class CoreImplTest extends MojoTestCase { Core core = CoreImpl.getInstance(); // Closing the peer handle. - Pair<MessagePipeHandle, MessagePipeHandle> handles = core.createMessagePipe(); + Pair<MessagePipeHandle, MessagePipeHandle> handles = core.createMessagePipe(null); addHandlePairToClose(handles); final AsyncWaiterResult asyncWaiterResult = new AsyncWaiterResult(); @@ -765,7 +783,7 @@ public class CoreImplTest extends MojoTestCase { Core core = CoreImpl.getInstance(); // Closing the peer handle. - Pair<MessagePipeHandle, MessagePipeHandle> handles = core.createMessagePipe(); + Pair<MessagePipeHandle, MessagePipeHandle> handles = core.createMessagePipe(null); addHandlePairToClose(handles); final AsyncWaiterResult asyncWaiterResult = new AsyncWaiterResult(); @@ -790,7 +808,7 @@ public class CoreImplTest extends MojoTestCase { @SmallTest public void testMessagePipeHandlePass() { Core core = CoreImpl.getInstance(); - Pair<MessagePipeHandle, MessagePipeHandle> handles = core.createMessagePipe(); + Pair<MessagePipeHandle, MessagePipeHandle> handles = core.createMessagePipe(null); addHandlePairToClose(handles); assertTrue(handles.first.isValid()); diff --git a/mojo/android/system/core_impl.cc b/mojo/android/system/core_impl.cc index 2d74a0f..36b28dc 100644 --- a/mojo/android/system/core_impl.cc +++ b/mojo/android/system/core_impl.cc @@ -75,11 +75,21 @@ static jint WaitMany(JNIEnv* env, return MojoWaitMany(handle_start, signals_start, nb_handles, deadline); } -static jobject CreateMessagePipe(JNIEnv* env, jobject jcaller) { +static jobject CreateMessagePipe(JNIEnv* env, + jobject jcaller, + jobject options_buffer) { + const MojoCreateMessagePipeOptions* options = NULL; + if (options_buffer) { + const void* buffer_start = env->GetDirectBufferAddress(options_buffer); + DCHECK(buffer_start); + const size_t buffer_size = env->GetDirectBufferCapacity(options_buffer); + DCHECK_EQ(buffer_size, sizeof(MojoCreateMessagePipeOptions)); + options = static_cast<const MojoCreateMessagePipeOptions*>(buffer_start); + DCHECK_EQ(options->struct_size, buffer_size); + } MojoHandle handle1; MojoHandle handle2; - // TODO(vtl): Add support for the options struct. - MojoResult result = MojoCreateMessagePipe(NULL, &handle1, &handle2); + MojoResult result = MojoCreateMessagePipe(options, &handle1, &handle2); return Java_CoreImpl_newNativeCreationResult(env, result, handle1, handle2) .Release(); } 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 6c0475e..570d3bd 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 @@ -109,11 +109,18 @@ public class CoreImpl implements Core, AsyncWaiter { } /** - * @see Core#createMessagePipe() + * @see Core#createMessagePipe(MessagePipeHandle.CreateOptions) */ @Override - public Pair<MessagePipeHandle, MessagePipeHandle> createMessagePipe() { - NativeCreationResult result = nativeCreateMessagePipe(); + public Pair<MessagePipeHandle, MessagePipeHandle> createMessagePipe( + MessagePipeHandle.CreateOptions options) { + ByteBuffer optionsBuffer = null; + if (options != null) { + optionsBuffer = allocateDirectBuffer(8); + optionsBuffer.putInt(0, 8); + optionsBuffer.putInt(4, options.getFlags().getFlags()); + } + NativeCreationResult result = nativeCreateMessagePipe(optionsBuffer); if (result.getMojoResult() != MojoResult.OK) { throw new MojoException(result.getMojoResult()); } @@ -611,7 +618,7 @@ public class CoreImpl implements Core, AsyncWaiter { private native int nativeWaitMany(ByteBuffer buffer, long deadline); - private native NativeCreationResult nativeCreateMessagePipe(); + private native NativeCreationResult nativeCreateMessagePipe(ByteBuffer optionsBuffer); private native NativeCreationResult nativeCreateDataPipe(ByteBuffer optionsBuffer); diff --git a/mojo/bindings/java/src/org/chromium/mojo/bindings/ExecutorFactory.java b/mojo/bindings/java/src/org/chromium/mojo/bindings/ExecutorFactory.java index 6f5e02b..d0d5c3b 100644 --- a/mojo/bindings/java/src/org/chromium/mojo/bindings/ExecutorFactory.java +++ b/mojo/bindings/java/src/org/chromium/mojo/bindings/ExecutorFactory.java @@ -68,7 +68,8 @@ class ExecutorFactory { mWaiter = core.getDefaultAsyncWaiter(); assert mWaiter != null; mLock = new Object(); - Pair<MessagePipeHandle, MessagePipeHandle> handles = core.createMessagePipe(); + Pair<MessagePipeHandle, MessagePipeHandle> handles = core.createMessagePipe( + new MessagePipeHandle.CreateOptions()); mReadHandle = handles.first; mWriteHandle = handles.second; mPendingActions = new ArrayList<Runnable>(); diff --git a/mojo/public/java/src/org/chromium/mojo/system/Core.java b/mojo/public/java/src/org/chromium/mojo/system/Core.java index 017e1e0..f0ff6a0 100644 --- a/mojo/public/java/src/org/chromium/mojo/system/Core.java +++ b/mojo/public/java/src/org/chromium/mojo/system/Core.java @@ -149,11 +149,12 @@ public interface Core { /** * Creates a message pipe, which is a bidirectional communication channel for framed data (i.e., - * messages). Messages can contain plain data and/or Mojo handles. + * messages), with the given options. Messages can contain plain data and/or Mojo handles. * * @return the set of handles for the two endpoints (ports) of the message pipe. */ - public Pair<MessagePipeHandle, MessagePipeHandle> createMessagePipe(); + public Pair<MessagePipeHandle, MessagePipeHandle> createMessagePipe( + MessagePipeHandle.CreateOptions options); /** * Creates a data pipe, which is a unidirectional communication channel for unframed data, with diff --git a/mojo/public/java/src/org/chromium/mojo/system/MessagePipeHandle.java b/mojo/public/java/src/org/chromium/mojo/system/MessagePipeHandle.java index cfb0327..60ac682 100644 --- a/mojo/public/java/src/org/chromium/mojo/system/MessagePipeHandle.java +++ b/mojo/public/java/src/org/chromium/mojo/system/MessagePipeHandle.java @@ -12,6 +12,51 @@ import java.util.List; * can contain plain data and/or Mojo handles. */ public interface MessagePipeHandle extends Handle { + + /** + * Flags for the message pipe creation operation. + */ + public static class CreateFlags extends Flags<CreateFlags> { + private static final int FLAG_NONE = 0; + + /** + * Immutable flag with not bit set. + */ + public static final CreateFlags NONE = CreateFlags.none().immutable(); + + /** + * Dedicated constructor. + * + * @param flags initial value of the flags. + */ + protected CreateFlags(int flags) { + super(flags); + } + + /** + * @return flags with no bit set. + */ + public static CreateFlags none() { + return new CreateFlags(FLAG_NONE); + } + + } + + /** + * Used to specify creation parameters for a message pipe to |Core#createMessagePipe()|. + */ + public static class CreateOptions { + private CreateFlags mFlags = CreateFlags.NONE; + + /** + * @return the flags + */ + public CreateFlags getFlags() { + return mFlags; + } + + } + /** * Flags for the write operations on MessagePipeHandle . */ diff --git a/mojo/public/java/src/org/chromium/mojo/system/SharedBufferHandle.java b/mojo/public/java/src/org/chromium/mojo/system/SharedBufferHandle.java index b2eef0b..df317d1 100644 --- a/mojo/public/java/src/org/chromium/mojo/system/SharedBufferHandle.java +++ b/mojo/public/java/src/org/chromium/mojo/system/SharedBufferHandle.java @@ -44,7 +44,7 @@ public interface SharedBufferHandle extends Handle { * Used to specify creation parameters for a shared buffer to |Core#createSharedBuffer()|. */ public static class CreateOptions { - private CreateFlags mFlags = CreateFlags.none(); + private CreateFlags mFlags = CreateFlags.NONE; /** * @return the flags @@ -89,7 +89,7 @@ public interface SharedBufferHandle extends Handle { * |SharedBufferHandle#duplicate| */ public static class DuplicateOptions { - private DuplicateFlags mFlags = DuplicateFlags.none(); + private DuplicateFlags mFlags = DuplicateFlags.NONE; /** * @return the flags |