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

Unified Diff: mojo/public/tools/bindings/generators/dart_templates/interface_definition.tmpl

Issue 1998433002: Dart: Adds Interface and InterfaceRequest interfaces. (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Merge Created 4 years, 7 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/tools/bindings/generators/dart_templates/interface_definition.tmpl
diff --git a/mojo/public/tools/bindings/generators/dart_templates/interface_definition.tmpl b/mojo/public/tools/bindings/generators/dart_templates/interface_definition.tmpl
index a44dc8b7cc4a4622de2f79c317ba949e594df64f..8d8b48f1fa8657762cc8b60708649a31500f1235 100644
--- a/mojo/public/tools/bindings/generators/dart_templates/interface_definition.tmpl
+++ b/mojo/public/tools/bindings/generators/dart_templates/interface_definition.tmpl
@@ -40,6 +40,26 @@ abstract class {{interface|name}} {
static const String serviceName = null;
{%- endif %}
+ static {{descpkg}}ServiceDescription _cachedServiceDescription;
+ static {{descpkg}}ServiceDescription get serviceDescription {
+ if (_cachedServiceDescription == null) {
+ _cachedServiceDescription = new _{{interface|name}}ServiceDescription();
+ }
+ return _cachedServiceDescription;
+ }
+
+ static {{interface|name}}Proxy connectToService(
+ bindings.ServiceConnector s, String url, [String serviceName]) {
+ {{interface|name}}Proxy p = new {{interface|name}}Proxy.unbound();
+ String name = serviceName ?? {{interface|name}}.serviceName;
+ if ((name == null) || name.isEmpty) {
+ throw new core.MojoApiError(
+ "If an interface has no ServiceName, then one must be provided.");
+ }
+ s.connectToService(url, p, name);
+ return p;
+ }
+
{%- for method in interface.methods %}
{%- if method.response_parameters == None %}
void {{method|name}}(
@@ -62,9 +82,27 @@ abstract class {{interface|name}} {
{%- endfor %}
}
+abstract class {{interface|name}}Interface
+ implements bindings.MojoInterface<{{interface|name}}>,
+ {{interface|name}} {
+ factory {{interface|name}}Interface([{{interface|name}} impl]) =>
+ new {{interface|name}}Stub.unbound(impl);
+ factory {{interface|name}}Interface.fromEndpoint(
+ core.MojoMessagePipeEndpoint endpoint,
+ [{{interface|name}} impl]) =>
+ new {{interface|name}}Stub.fromEndpoint(endpoint, impl);
+}
+
+abstract class {{interface|name}}InterfaceRequest
+ implements bindings.MojoInterface<{{interface|name}}>,
+ {{interface|name}} {
+ factory {{interface|name}}InterfaceRequest() =>
+ new {{interface|name}}Proxy.unbound();
+}
+
class _{{interface|name}}ProxyControl
extends bindings.ProxyMessageHandler
- implements bindings.ProxyControl {
+ implements bindings.ProxyControl<{{interface|name}}> {
_{{interface|name}}ProxyControl.fromEndpoint(
core.MojoMessagePipeEndpoint endpoint) : super.fromEndpoint(endpoint);
@@ -73,9 +111,6 @@ class _{{interface|name}}ProxyControl
_{{interface|name}}ProxyControl.unbound() : super.unbound();
- {{descpkg}}ServiceDescription get serviceDescription =>
- new _{{interface|name}}ServiceDescription();
-
String get serviceName => {{interface|name}}.serviceName;
void handleResponse(bindings.ServiceMessage message) {
@@ -112,6 +147,11 @@ class _{{interface|name}}ProxyControl
}
}
+ {{interface|name}} get impl => null;
+ set impl({{interface|name}} _) {
+ throw new core.MojoApiError("The impl of a Proxy cannot be set.");
+ }
+
@override
String toString() {
var superString = super.toString();
@@ -120,8 +160,10 @@ class _{{interface|name}}ProxyControl
}
class {{interface|name}}Proxy
- extends bindings.Proxy
- implements {{interface|name}} {
+ extends bindings.Proxy<{{interface|name}}>
+ implements {{interface|name}},
+ {{interface|name}}Interface,
+ {{interface|name}}InterfaceRequest {
{{interface|name}}Proxy.fromEndpoint(
core.MojoMessagePipeEndpoint endpoint)
: super(new _{{interface|name}}ProxyControl.fromEndpoint(endpoint));
@@ -138,13 +180,6 @@ class {{interface|name}}Proxy
return new {{interface|name}}Proxy.fromEndpoint(endpoint);
}
- factory {{interface|name}}Proxy.connectToService(
- bindings.ServiceConnector s, String url, [String serviceName]) {
- {{interface|name}}Proxy p = new {{interface|name}}Proxy.unbound();
- s.connectToService(url, p, serviceName);
- return p;
- }
-
{% for method in interface.methods %}
{%- if method.response_parameters == None %}
void {{method|name}}(
@@ -204,6 +239,8 @@ class _{{interface|name}}StubControl
_{{interface|name}}StubControl.unbound([this._impl]) : super.unbound();
+ String get serviceName => {{interface|name}}.serviceName;
+
{% for method in interface.methods %}
{%- if method.response_parameters != None %}
{%- set response_struct = method.response_param_struct %}
@@ -304,19 +341,16 @@ class _{{interface|name}}StubControl
}
int get version => {{interface.version}};
-
- static {{descpkg}}ServiceDescription _cachedServiceDescription;
- static {{descpkg}}ServiceDescription get serviceDescription {
- if (_cachedServiceDescription == null) {
- _cachedServiceDescription = new _{{interface|name}}ServiceDescription();
- }
- return _cachedServiceDescription;
- }
}
class {{interface|name}}Stub
extends bindings.Stub<{{interface|name}}>
- implements {{interface|name}} {
+ implements {{interface|name}},
+ {{interface|name}}Interface,
+ {{interface|name}}InterfaceRequest {
+ {{interface|name}}Stub.unbound([{{interface|name}} impl])
+ : super(new _{{interface|name}}StubControl.unbound(impl));
+
{{interface|name}}Stub.fromEndpoint(
core.MojoMessagePipeEndpoint endpoint, [{{interface|name}} impl])
: super(new _{{interface|name}}StubControl.fromEndpoint(endpoint, impl));
@@ -325,18 +359,12 @@ class {{interface|name}}Stub
core.MojoHandle handle, [{{interface|name}} impl])
: super(new _{{interface|name}}StubControl.fromHandle(handle, impl));
- {{interface|name}}Stub.unbound([{{interface|name}} impl])
- : super(new _{{interface|name}}StubControl.unbound(impl));
-
static {{interface|name}}Stub newFromEndpoint(
core.MojoMessagePipeEndpoint endpoint) {
assert(endpoint.setDescription("For {{interface|name}}Stub"));
return new {{interface|name}}Stub.fromEndpoint(endpoint);
}
- static {{descpkg}}ServiceDescription get serviceDescription =>
- _{{interface|name}}StubControl.serviceDescription;
-
{% for method in interface.methods %}
{%- if method.response_parameters == None %}
void {{method|name}}(

Powered by Google App Engine
This is Rietveld 408576698