Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(926)

Unified Diff: mojo/public/java/bindings/src/org/chromium/mojo/bindings/Encoder.java

Issue 411913002: mojo: generate Proxies and Stubs for java bindings. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Follow first pass review. Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..22af8518735c4df2d635a3bd3c2669f3af86f007 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,42 @@ 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.Builder<T, ?> builder) {
+ 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) {
rmcilroy 2014/08/21 14:43:52 Would it work to have a getHandleOwnerMessageRecie
qsr 2014/08/22 08:11:18 The other issue is that Interface will be implemen
rmcilroy 2014/08/26 10:18:23 Yeah, makes sense (re: not wanting the service to
+ Interface.AbstractProxy proxy = (Interface.AbstractProxy) v;
+ if (proxy.getMessageReceiver() instanceof HandleOwner) {
+ encode(((HandleOwner<?>) proxy.getMessageReceiver()).passHandle(), offset);
+ return;
+ }
+ }
+ Pair<MessagePipeHandle, MessagePipeHandle> handles =
+ mEncoderState.core.createMessagePipe(null);
+ builder.bind(handles.first, v);
+ encode(handles.second, offset);
}
/**
* Encode an {@link InterfaceRequest}.
*/
- public <T extends Interface> void encode(InterfaceRequest<T> v, int offset) {
+ public <P extends Interface.Proxy> void encode(InterfaceRequest<P> 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 +365,7 @@ public class Encoder {
}
/**
- * Encodes an array of doubles.
+ * Encodes an array of doubles
*/
public void encode(double[] v, int offset) {
if (v == null) {
@@ -374,7 +392,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.Builder<T, ?> builder) {
if (v == null) {
encodeNullPointer(offset);
return;
@@ -387,9 +406,9 @@ public class Encoder {
}
/**
- * Encodes an array of {@link Interface}.
+ * Encodes an array of {@link InterfaceRequest}.
*/
- public <T extends Interface> void encode(InterfaceRequest<T>[] v, int offset) {
+ public <P extends Interface.Proxy> void encode(InterfaceRequest<P>[] v, int offset) {
if (v == null) {
encodeNullPointer(offset);
return;

Powered by Google App Engine
This is Rietveld 408576698