Index: mojo/bindings/java/src/org/chromium/mojo/bindings/InterfaceWithClient.java |
diff --git a/mojo/bindings/java/src/org/chromium/mojo/bindings/InterfaceWithClient.java b/mojo/bindings/java/src/org/chromium/mojo/bindings/InterfaceWithClient.java |
index 69fe6edcb3b5c217c1da54db65d2916e0b15dc2b..60ca8935e63734a65c834e0b642942adf8f84739 100644 |
--- a/mojo/bindings/java/src/org/chromium/mojo/bindings/InterfaceWithClient.java |
+++ b/mojo/bindings/java/src/org/chromium/mojo/bindings/InterfaceWithClient.java |
@@ -4,6 +4,9 @@ |
package org.chromium.mojo.bindings; |
+import org.chromium.mojo.system.Core; |
+import org.chromium.mojo.system.MessagePipeHandle; |
+ |
/** |
* Base class for mojo generated interfaces that have a client. |
* |
@@ -12,8 +15,96 @@ package org.chromium.mojo.bindings; |
public interface InterfaceWithClient<C extends Interface> extends Interface { |
/** |
- * Set the client associated with this interface. |
+ * TODO(qsr): Insert description here. |
+ * |
+ * @param <C> |
*/ |
- public void setClient(C client); |
+ abstract class Proxy<C extends Interface> extends |
+ Interface.Proxy implements InterfaceWithClient<C> { |
+ /** |
+ * TODO(qsr): |
+ * |
+ * @param messageReceiver |
+ */ |
+ public Proxy(Core core, MessageReceiverWithResponder messageReceiver) { |
+ super(core, messageReceiver); |
+ } |
+ |
+ /** |
+ * @see InterfaceWithClient#setClient(Interface) |
+ */ |
+ @Override |
+ public void setClient(C client) { |
+ throw new UnsupportedOperationException( |
+ "Setting the client on a proxy is not supported"); |
+ } |
+ } |
+ |
+ /** |
+ * TODO(qsr): Insert description here. |
+ * |
+ * @param <I> |
+ */ |
+ abstract class Builder<C extends Interface, I extends InterfaceWithClient<C>, |
+ P extends Proxy<C>> extends Interface.Builder<I, P> { |
+ |
+ private final Interface.Builder<C, ?> mClientBuilder; |
+ /** |
+ * TODO(qsr): |
+ * |
+ * @param clientBuilder |
+ */ |
+ protected Builder(Interface.Builder<C, ?> clientBuilder) { |
+ if (clientBuilder == null) { |
+ // Passing null to this method is a conventional value used to handle an interface |
+ // that is its own client. |
+ @SuppressWarnings("unchecked") |
+ Interface.Builder<C, P> thisAsClientBuilder = (Interface.Builder<C, P>) this; |
+ this.mClientBuilder = thisAsClientBuilder; |
+ } else { |
+ this.mClientBuilder = clientBuilder; |
+ } |
+ } |
+ |
+ /** |
+ * @see Interface.Builder#bind(org.chromium.mojo.system.MessagePipeHandle, Interface) |
+ */ |
+ @Override |
+ public void bind(MessagePipeHandle handle, I impl) { |
+ Router router = new RouterImpl(handle); |
+ super.bind(handle.getCore(), router, impl); |
+ @SuppressWarnings("unchecked") |
+ C client = (C) mClientBuilder.connect(handle.getCore(), router); |
+ impl.setClient(client); |
+ router.setErrorHandler(impl); |
+ router.start(); |
+ } |
+ |
+ /** |
+ * TODO(qsr): |
+ * |
+ * @param handle |
+ * @param client |
+ * @return |
+ */ |
+ public P connect(MessagePipeHandle handle, C client) { |
+ Router router = new RouterImpl(handle); |
+ mClientBuilder.bind(handle.getCore(), router, client); |
+ P proxy = super.connect(handle.getCore(), router); |
+ DelegatingConnectionErrorHandler handlers = new DelegatingConnectionErrorHandler(); |
+ handlers.addConnectionErrorHandler(client); |
+ handlers.addConnectionErrorHandler(proxy); |
+ router.setErrorHandler(handlers); |
+ router.start(); |
+ return proxy; |
+ } |
+ } |
+ |
+ /** |
+ * TODO(qsr): |
+ * |
+ * @param client |
+ */ |
+ public void setClient(C client); |
} |