Commit 0471e477 authored by Giovanni Ortuño Urquidi's avatar Giovanni Ortuño Urquidi Committed by Commit Bot

mojo: Use new names in interface_support.js

As a first step towards using new primitive types, replace internal use
of Proxy and Target with Remote and Receiver.

Bug: 968369
Change-Id: Ib37130094c9ec85ac8d0f8346910c00764519cbf
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1636255
Auto-Submit: Giovanni Ortuño Urquidi <ortuno@chromium.org>
Reviewed-by: default avatarcalamity <calamity@chromium.org>
Reviewed-by: default avatarKen Rockot <rockot@google.com>
Commit-Queue: Giovanni Ortuño Urquidi <ortuno@chromium.org>
Cr-Commit-Position: refs/heads/master@{#666551}
parent 2f419137
......@@ -11,7 +11,7 @@ goog.provide('mojo.internal.interfaceSupport');
/**
* Handles incoming interface control messages on a proxy or router endpoint.
* Handles incoming interface control messages on a remote or router endpoint.
*/
mojo.internal.interfaceSupport.ControlMessageHandler = class {
/** @param {!MojoHandle} handle */
......@@ -72,8 +72,8 @@ mojo.internal.interfaceSupport.ControlMessageHandler = class {
};
/**
* Captures metadata about a request which was sent by a local proxy, for which
* a response is expected.
* Captures metadata about a request which was sent by a remote, for which a
* response is expected.
*/
mojo.internal.interfaceSupport.PendingResponse = class {
/**
......@@ -150,16 +150,16 @@ mojo.internal.interfaceSupport.ConnectionErrorEventRouter = class {
};
/**
* Generic helper used to implement all generated proxy classes. Knows how to
* Generic helper used to implement all generated remote classes. Knows how to
* serialize requests and deserialize their replies, both according to
* declarative message structure specs.
* @template T
* @export
*/
mojo.internal.interfaceSupport.InterfaceProxyBase = class {
mojo.internal.interfaceSupport.InterfaceRemoteBase = class {
/**
* @param {!function(new:T, !MojoHandle)} requestType
* @param {MojoHandle=} opt_handle The message pipe handle to use as a proxy
* @param {MojoHandle=} opt_handle The message pipe handle to use as a remote
* endpoint. If null, this object must be bound with bindHandle before
* it can be used to send any messages.
* @public
......@@ -196,7 +196,7 @@ mojo.internal.interfaceSupport.InterfaceProxyBase = class {
/**
* @return {!T}
*/
createRequest() {
bindNewPipeAndPassReceiver() {
let {handle0, handle1} = Mojo.createMessagePipe();
this.bindHandle(handle0);
return new this.requestType_(handle1);
......@@ -208,7 +208,7 @@ mojo.internal.interfaceSupport.InterfaceProxyBase = class {
*/
bindHandle(handle) {
if (this.handle)
throw new Error('Proxy already bound.');
throw new Error('Remote already bound.');
this.handle = handle;
const reader = new mojo.internal.interfaceSupport.HandleReader(handle);
......@@ -253,7 +253,8 @@ mojo.internal.interfaceSupport.InterfaceProxyBase = class {
sendMessage(ordinal, paramStruct, responseStruct, args) {
if (!this.handle) {
throw new Error(
'Attempting to use an unbound proxy. Try $.createRequest() first.')
'Attempting to use an unbound remote. Try ' +
'$.bindNewPipeAndPassReceiver() first.')
}
// The pipe has already been closed, so just drop the message.
......@@ -344,33 +345,42 @@ mojo.internal.interfaceSupport.InterfaceProxyBase = class {
};
/**
* Wrapper around mojo.internal.interfaceSupport.InterfaceProxyBase that
* exposes the subset of InterfaceProxyBase's method that users are allowed
* Wrapper around mojo.internal.interfaceSupport.InterfaceRemoteBase that
* exposes the subset of InterfaceRemoteBase's method that users are allowed
* to use.
* @template T
* @export
*/
mojo.internal.interfaceSupport.InterfaceProxyBaseWrapper = class {
mojo.internal.interfaceSupport.InterfaceRemoteBaseWrapper = class {
/**
* @param {!mojo.internal.interfaceSupport.InterfaceProxyBase<T>} proxy
* @param {!mojo.internal.interfaceSupport.InterfaceRemoteBase<T>} remote
* @public
*/
constructor(proxy) {
/** @private {!mojo.internal.interfaceSupport.InterfaceProxyBase<T>} */
this.proxy_ = proxy;
constructor(remote) {
/** @private {!mojo.internal.interfaceSupport.InterfaceRemoteBase<T>} */
this.remote_ = remote;
}
// TODO(ortuno): Remove once new names are used in the exposed interfaces.
/**
* @return {!T}
* @export
*/
createRequest() {
return this.proxy_.createRequest();
return this.remote_.bindNewPipeAndPassReceiver();
}
/**
* @return {!T}
* @export
*/
bindNewPipeAndPassReceiver() {
return this.remote_.bindNewPipeAndPassReceiver();
}
/** @export */
close() {
this.proxy_.close();
this.remote_.close();
}
/**
......@@ -378,7 +388,7 @@ mojo.internal.interfaceSupport.InterfaceProxyBaseWrapper = class {
* @export
*/
flushForTesting() {
return this.proxy_.flushForTesting();
return this.remote_.flushForTesting();
}
}
......@@ -417,7 +427,7 @@ mojo.internal.interfaceSupport.CallbackRouter = class {
* messages to listeners.
* @export
*/
mojo.internal.interfaceSupport.InterfaceCallbackTarget = class {
mojo.internal.interfaceSupport.InterfaceCallbackReceiver = class {
/**
* @public
* @param {!mojo.internal.interfaceSupport.CallbackRouter} callbackRouter
......@@ -449,7 +459,7 @@ mojo.internal.interfaceSupport.InterfaceCallbackTarget = class {
* @return {!Function}
* @export
*/
createTargetHandler(expectsResponse) {
createReceiverHandler(expectsResponse) {
if (expectsResponse)
return this.dispatchWithResponse_.bind(this);
return this.dispatch_.bind(this);
......@@ -488,7 +498,7 @@ mojo.internal.interfaceSupport.InterfaceCallbackTarget = class {
};
/**
* Wraps message handlers attached to an InterfaceTarget.
* Wraps message handlers attached to an InterfaceReceiver.
*/
mojo.internal.interfaceSupport.MessageHandler = class {
/**
......@@ -515,7 +525,7 @@ mojo.internal.interfaceSupport.MessageHandler = class {
* message number.
* @export
*/
mojo.internal.interfaceSupport.InterfaceTarget = class {
mojo.internal.interfaceSupport.InterfaceReceiver = class {
/** @public */
constructor() {
/**
......@@ -592,7 +602,7 @@ mojo.internal.interfaceSupport.InterfaceTarget = class {
if (this.controlMessageHandler_.maybeHandleControlMessage(header, buffer))
return;
if (header.flags & mojo.internal.kMessageFlagIsResponse)
throw new Error('Received unexpected response on interface target');
throw new Error('Received unexpected response on interface receiver');
const handler = this.messageHandlers_.get(header.ordinal);
if (!handler)
throw new Error('Received unknown message');
......@@ -654,8 +664,8 @@ mojo.internal.interfaceSupport.InterfaceTarget = class {
/**
* Watches a MojoHandle for readability or peer closure, forwarding either event
* to one of two callbacks on the reader. Used by both InterfaceProxyBase and
* InterfaceTarget to watch for incoming messages.
* to one of two callbacks on the reader. Used by both InterfaceRemoteBase and
* InterfaceReceiver to watch for incoming messages.
*/
mojo.internal.interfaceSupport.HandleReader = class {
/**
......
......@@ -56,17 +56,17 @@ goog.provide('{{module.namespace}}.{{interface.name}}Request');
/** @param {MojoHandle=} opt_handle */
constructor(opt_handle) {
/**
* @private {!mojo.internal.interfaceSupport.InterfaceProxyBase<!{{module.namespace}}.{{interface.name}}Request>}
* @private {!mojo.internal.interfaceSupport.InterfaceRemoteBase<!{{module.namespace}}.{{interface.name}}Request>}
*/
this.proxy =
new mojo.internal.interfaceSupport.InterfaceProxyBase(
new mojo.internal.interfaceSupport.InterfaceRemoteBase(
{{module.namespace}}.{{interface.name}}Request,
opt_handle);
/**
* @public {!mojo.internal.interfaceSupport.InterfaceProxyBaseWrapper<!{{module.namespace}}.{{interface.name}}Request>}
* @public {!mojo.internal.interfaceSupport.InterfaceRemoteBaseWrapper<!{{module.namespace}}.{{interface.name}}Request>}
*/
this.$ = new mojo.internal.interfaceSupport.InterfaceProxyBaseWrapper(this.proxy);
this.$ = new mojo.internal.interfaceSupport.InterfaceRemoteBaseWrapper(this.proxy);
/** @public {!mojo.internal.interfaceSupport.ConnectionErrorEventRouter} */
this.onConnectionError = this.proxy.getConnectionErrorEventRouter();
......@@ -114,11 +114,11 @@ goog.provide('{{module.namespace}}.{{interface.name}}Request');
* @param {!{{module.namespace}}.{{interface.name}}Interface } impl
*/
constructor(impl) {
this.target_ = new mojo.internal.interfaceSupport.InterfaceTarget;
this.receiver_ = new mojo.internal.interfaceSupport.InterfaceReceiver;
{% for method in interface.methods %}
{%- set interface_message_id =
interface.mojom_name ~ "_" ~ method.mojom_name %}
this.target_.registerHandler(
this.receiver_.registerHandler(
{{method.ordinal}},
{{module.namespace}}.{{interface_message_id}}_ParamsSpec.$,
{%- if method.response_parameters != None %}
......@@ -129,7 +129,7 @@ goog.provide('{{module.namespace}}.{{interface.name}}Request');
impl.{{method.name}}.bind(impl));
{%- endfor %}
/** @public {!mojo.internal.interfaceSupport.ConnectionErrorEventRouter} */
this.onConnectionError = this.target_.getConnectionErrorEventRouter();
this.onConnectionError = this.receiver_.getConnectionErrorEventRouter();
}
/**
......@@ -140,7 +140,7 @@ goog.provide('{{module.namespace}}.{{interface.name}}Request');
* @export
*/
bindHandle(handle) {
this.target_.bindHandle(handle);
this.receiver_.bindHandle(handle);
}
/**
......@@ -149,7 +149,7 @@ goog.provide('{{module.namespace}}.{{interface.name}}Request');
* @export
*/
closeBindings() {
this.target_.closeBindings();
this.receiver_.closeBindings();
}
/**
......@@ -163,7 +163,7 @@ goog.provide('{{module.namespace}}.{{interface.name}}Request');
static getProxy() {
let proxy = new {{module.namespace}}.{{interface.name}}Proxy;
Mojo.bindInterface('{{mojom_namespace}}.{{interface.name}}',
proxy.$.createRequest().handle);
proxy.$.bindNewPipeAndPassReceiver().handle);
return proxy;
}
......@@ -176,7 +176,7 @@ goog.provide('{{module.namespace}}.{{interface.name}}Request');
*/
createProxy() {
let proxy = new {{module.namespace}}.{{interface.name}}Proxy;
this.target_.bindHandle(proxy.$.createRequest().handle);
this.receiver_.bindHandle(proxy.$.bindNewPipeAndPassReceiver().handle);
return proxy;
}
};
......@@ -198,39 +198,39 @@ goog.provide('{{module.namespace}}.{{interface.name}}Request');
/**
* An object which receives request messages for the {{interface.name}}
* mojom interface and dispatches them as callbacks. One callback target exists
* mojom interface and dispatches them as callbacks. One callback receiver exists
* on this object for each message defined in the mojom interface, and each
* target can have any number of listeners added to it.
* receiver can have any number of listeners added to it.
*
* @export
*/
{{module.namespace}}.{{interface.name}}CallbackRouter = class {
constructor() {
this.target_ = new mojo.internal.interfaceSupport.InterfaceTarget;
this.receiver_ = new mojo.internal.interfaceSupport.InterfaceReceiver;
this.router_ = new mojo.internal.interfaceSupport.CallbackRouter;
{% for method in interface.methods %}
{%- set interface_message_id =
interface.mojom_name ~ "_" ~ method.mojom_name %}
/**
* @public {!mojo.internal.interfaceSupport.InterfaceCallbackTarget}
* @public {!mojo.internal.interfaceSupport.InterfaceCallbackReceiver}
*/
this.{{method.name}} =
new mojo.internal.interfaceSupport.InterfaceCallbackTarget(
new mojo.internal.interfaceSupport.InterfaceCallbackReceiver(
this.router_);
this.target_.registerHandler(
this.receiver_.registerHandler(
{{method.ordinal}},
{{module.namespace}}.{{interface_message_id}}_ParamsSpec.$,
{%- if method.response_parameters != None %}
{{module.namespace}}.{{interface_message_id}}_ResponseParamsSpec.$,
this.{{method.name}}.createTargetHandler(true /* expectsResponse */));
this.{{method.name}}.createReceiverHandler(true /* expectsResponse */));
{%- else %}
null,
this.{{method.name}}.createTargetHandler(false /* expectsResponse */));
this.{{method.name}}.createReceiverHandler(false /* expectsResponse */));
{%- endif %}
{%- endfor %}
/** @public {!mojo.internal.interfaceSupport.ConnectionErrorEventRouter} */
this.onConnectionError = this.target_.getConnectionErrorEventRouter();
this.onConnectionError = this.receiver_.getConnectionErrorEventRouter();
}
/**
......@@ -241,15 +241,15 @@ goog.provide('{{module.namespace}}.{{interface.name}}Request');
* @export
*/
bindHandle(handle) {
this.target_.bindHandle(handle);
this.receiver_.bindHandle(handle);
}
/**
* Closes all bindings bound to this target. The target will not receive any
* Closes all bindings bound to this receiver. The receiver will not receive any
* further message message events unless rebound to one or more handles.
*/
closeBindings() {
this.target_.closeBindings();
this.receiver_.closeBindings();
}
/**
......@@ -261,7 +261,7 @@ goog.provide('{{module.namespace}}.{{interface.name}}Request');
*/
createProxy() {
let proxy = new {{module.namespace}}.{{interface.name}}Proxy;
this.target_.bindHandle(proxy.$.createRequest().handle);
this.receiver_.bindHandle(proxy.$.bindNewPipeAndPassReceiver().handle);
return proxy;
}
......
......@@ -109,7 +109,7 @@ mojo.makeRequest = function(interfacePtr) {};
/** @const */
mojo.internal = {};
mojo.internal.InterfaceProxyBase = class {
mojo.internal.InterfaceRemoteBase = class {
/**
* @param {MojoHandle=} opt_handle
*/
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment