Chromium Code Reviews| Index: mojo/public/java/bindings/src/org/chromium/mojo/bindings/Encoder.java |
| diff --git a/mojo/public/java/bindings/src/org/chromium/mojo/bindings/Encoder.java b/mojo/public/java/bindings/src/org/chromium/mojo/bindings/Encoder.java |
| index 9ec2cb248e0bb8cc5e697a29cdec93f84398bbf8..5ac079094f73efb0c7d7d09d46b6564b8cf6eb81 100644 |
| --- a/mojo/public/java/bindings/src/org/chromium/mojo/bindings/Encoder.java |
| +++ b/mojo/public/java/bindings/src/org/chromium/mojo/bindings/Encoder.java |
| @@ -7,6 +7,8 @@ package org.chromium.mojo.bindings; |
| import org.chromium.mojo.bindings.Struct.DataHeader; |
| import org.chromium.mojo.system.Core; |
| import org.chromium.mojo.system.Handle; |
| +import org.chromium.mojo.system.MessagePipeHandle; |
| +import org.chromium.mojo.system.Pair; |
| import java.nio.ByteBuffer; |
| import java.nio.ByteOrder; |
| @@ -139,7 +141,6 @@ public class Encoder { |
| Encoder result = new Encoder(mEncoderState); |
| result.encode(dataHeader); |
| return result; |
| - |
| } |
| /** |
| @@ -243,25 +244,43 @@ public class Encoder { |
| /** |
| * Encode an {@link Interface}. |
| */ |
| - public <T extends Interface> void encode(T v, int offset, Object builder) { |
| + public <T extends Interface> void encode(T v, int offset, Interface.Manager<T, ?> manager) { |
| + if (v == null) { |
| + encode(-1, offset); |
| + return; |
| + } |
| if (mEncoderState.core == null) { |
| throw new UnsupportedOperationException( |
| "The encoder has been created without a Core. It can't encode an interface."); |
| } |
| - // TODO(qsr): To be implemented when interfaces proxy and stubs are implemented. |
| - throw new UnsupportedOperationException("Unimplemented operation"); |
| + // If the instance is a proxy, pass the proxy's handle instead of creating a new stub. |
| + if (v instanceof Interface.AbstractProxy) { |
| + Interface.AbstractProxy proxy = (Interface.AbstractProxy) v; |
| + if (proxy.getMessageReceiver() instanceof HandleOwner) { |
| + encode(((HandleOwner<?>) proxy.getMessageReceiver()).passHandle(), offset); |
| + return; |
| + } |
| + // If the proxy is not over a message pipe, the default case applies. |
| + } |
| + Pair<MessagePipeHandle, MessagePipeHandle> handles = |
| + mEncoderState.core.createMessagePipe(null); |
| + manager.bind(v, handles.first); |
| + encode(handles.second, offset); |
| } |
| /** |
| * Encode an {@link InterfaceRequest}. |
| */ |
| - public <T extends Interface> void encode(InterfaceRequest<T> v, int offset) { |
| + public <I extends Interface> void encode(InterfaceRequest<I> v, int offset) { |
| + if (v == null) { |
| + encode(-1, offset); |
| + return; |
| + } |
| if (mEncoderState.core == null) { |
| throw new UnsupportedOperationException( |
| "The encoder has been created without a Core. It can't encode an interface."); |
| } |
| - // TODO(qsr): To be implemented when interfaces proxy and stubs are implemented. |
| - throw new UnsupportedOperationException("Unimplemented operation"); |
| + encode(v.passHandle(), offset); |
| } |
| /** |
| @@ -347,7 +366,7 @@ public class Encoder { |
| } |
| /** |
| - * Encodes an array of doubles. |
| + * Encodes an array of doubles |
|
rmcilroy
2014/08/26 10:18:23
nit - add back the "."
qsr
2014/08/26 12:53:34
Done.
|
| */ |
| public void encode(double[] v, int offset) { |
| if (v == null) { |
| @@ -374,7 +393,8 @@ public class Encoder { |
| /** |
| * Encodes an array of {@link Interface}. |
| */ |
| - public <T extends Interface> void encode(T[] v, int offset, Object builder) { |
| + public <T extends Interface> void encode(T[] v, int offset, |
| + Interface.Manager<T, ?> manager) { |
| if (v == null) { |
| encodeNullPointer(offset); |
| return; |
| @@ -382,14 +402,14 @@ public class Encoder { |
| Encoder e = encoderForArray(BindingsHelper.SERIALIZED_HANDLE_SIZE, v.length, offset); |
| for (int i = 0; i < v.length; ++i) { |
| e.encode(v[i], DataHeader.HEADER_SIZE + BindingsHelper.SERIALIZED_HANDLE_SIZE * i, |
| - builder); |
| + manager); |
| } |
| } |
| /** |
| - * Encodes an array of {@link Interface}. |
| + * Encodes an array of {@link InterfaceRequest}. |
| */ |
| - public <T extends Interface> void encode(InterfaceRequest<T>[] v, int offset) { |
| + public <I extends Interface> void encode(InterfaceRequest<I>[] v, int offset) { |
| if (v == null) { |
| encodeNullPointer(offset); |
| return; |