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

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

Issue 959993002: Dart: Removes name conflicts from generated bindings. (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Remove interface tear-offs from Proxies Created 5 years, 9 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 unified diff | Download patch
OLDNEW
1 {%- for method in interface.methods %} 1 {%- for method in interface.methods %}
2 const int k{{interface|name}}_{{method|name}}_name = {{method.ordinal}}; 2 const int k{{interface|name}}_{{method|name}}_name = {{method.ordinal}};
3 {%- endfor %} 3 {%- endfor %}
4 4
5 abstract class {{interface|name}} implements core.Listener { 5 const String {{interface|name}}Name =
6 static const String name = '{{namespace|replace(".","::")}}::{{interface|name} }'; 6 '{{namespace|replace(".","::")}}::{{interface|name}}';
7 {{interface|name}}Stub stub;
8 7
9 {{interface|name}}(core.MojoMessagePipeEndpoint endpoint) : 8 abstract class {{interface|name}} {
10 stub = new {{interface|name}}Stub(endpoint);
11
12 {{interface|name}}.fromHandle(core.MojoHandle handle) :
13 stub = new {{interface|name}}Stub.fromHandle(handle);
14
15 {{interface|name}}.fromStub(this.stub);
16
17 {{interface|name}}.unbound() :
18 stub = new {{interface|name}}Stub.unbound();
19
20 void close({bool nodefer : false}) => stub.close(nodefer: nodefer);
21
22 StreamSubscription<int> listen() => stub.listen();
23
24 {{interface|name}} get delegate => stub.delegate;
25 set delegate({{interface|name}} d) {
26 stub.delegate = d;
27 }
28
29 {%- for method in interface.methods %} 9 {%- for method in interface.methods %}
30 {%- if method.response_parameters == None %} 10 {%- if method.response_parameters == None %}
31 void {{method|name}}( 11 void {{method|name}}(
32 {%- for parameter in method.parameters -%} 12 {%- for parameter in method.parameters -%}
33 {{parameter.kind|dart_type}} {{parameter|name}}{% if not loop.last %}, {% endif %} 13 {{parameter.kind|dart_type}} {{parameter|name}}{% if not loop.last %}, {% endif %}
34 {%- endfor -%} 14 {%- endfor -%}
35 ); 15 );
36 {%- else %} 16 {%- else %}
37 {%- set response_struct = method|response_struct_from_method %} 17 {%- set response_struct = method|response_struct_from_method %}
38 Future<{{response_struct|name}}> {{method|name}}( 18 Future<{{response_struct|name}}> {{method|name}}(
39 {%- for parameter in method.parameters -%} 19 {%- for parameter in method.parameters -%}
40 {{parameter.kind|dart_type}} {{parameter|name}}, 20 {{parameter.kind|dart_type}} {{parameter|name}},
41 {%- endfor -%} 21 {%- endfor -%}
42 [Function responseFactory = null]); 22 [Function responseFactory = null]);
43 {%- endif %} 23 {%- endif %}
44 {%- endfor %} 24 {%- endfor %}
45 25
46
47 {#--- Interface Constants #} 26 {#--- Interface Constants #}
48 {% for constant in interface.constants %} 27 {% for constant in interface.constants %}
49 static final {{constant|name}} = {{constant.value|expression_to_text}}; 28 static final {{constant|name}} = {{constant.value|expression_to_text}};
50 {%- endfor %} 29 {%- endfor %}
51 30
52
53 {#--- Interface Enums #} 31 {#--- Interface Enums #}
54 {%- from "enum_definition.tmpl" import enum_def -%} 32 {%- from "enum_definition.tmpl" import enum_def -%}
55 {%- for enum in interface.enums %} 33 {%- for enum in interface.enums %}
56 {{ enum_def(" static ", enum) }} 34 {{ enum_def(" static ", enum) }}
57 {%- endfor %} 35 {%- endfor %}
58 } 36 }
59 37
60 class {{interface|name}}Proxy extends bindings.Proxy implements {{interface|name }} {
61 {{interface|name}}Proxy(core.MojoMessagePipeEndpoint endpoint) : super(endpoin t);
62 38
63 {{interface|name}}Proxy.fromHandle(core.MojoHandle handle) : 39 class {{interface|name}}ProxyImpl extends bindings.Proxy {
40 {{interface|name}}ProxyImpl.fromEndpoint(
41 core.MojoMessagePipeEndpoint endpoint) : super(endpoint);
42
43 {{interface|name}}ProxyImpl.fromHandle(core.MojoHandle handle) :
64 super.fromHandle(handle); 44 super.fromHandle(handle);
65 45
66 {{interface|name}}Proxy.unbound() : super.unbound(); 46 {{interface|name}}ProxyImpl.unbound() : super.unbound();
67 47
68 String get name => {{interface|name}}.name; 48 static {{interface|name}}ProxyImpl newFromEndpoint(
49 core.MojoMessagePipeEndpoint endpoint) =>
50 new {{interface|name}}ProxyImpl.fromEndpoint(endpoint);
69 51
70 static {{interface|name}}Proxy newFromEndpoint( 52 String get name => {{interface|name}}Name;
71 core.MojoMessagePipeEndpoint endpoint) =>
72 new {{interface|name}}Proxy(endpoint);
73 53
74 void handleResponse(bindings.ServiceMessage message) { 54 void handleResponse(bindings.ServiceMessage message) {
75 switch (message.header.type) { 55 switch (message.header.type) {
76 {%- for method in interface.methods %} 56 {%- for method in interface.methods %}
77 {%- if method.response_parameters != None %} 57 {%- if method.response_parameters != None %}
78 {%- set response_struct = method|response_struct_from_method %} 58 {%- set response_struct = method|response_struct_from_method %}
79 case k{{interface|name}}_{{method|name}}_name: 59 case k{{interface|name}}_{{method|name}}_name:
80 var r = {{response_struct|name}}.deserialize( 60 var r = {{response_struct|name}}.deserialize(
81 message.payload); 61 message.payload);
82 if (!message.header.hasRequestId) { 62 if (!message.header.hasRequestId) {
83 throw 'Expected a message with a valid request Id.'; 63 throw 'Expected a message with a valid request Id.';
84 } 64 }
85 Completer c = completerMap[message.header.requestId]; 65 Completer c = completerMap[message.header.requestId];
86 completerMap[message.header.requestId] = null; 66 completerMap[message.header.requestId] = null;
87 c.complete(r); 67 c.complete(r);
88 break; 68 break;
89 {%- endif %} 69 {%- endif %}
90 {%- endfor %} 70 {%- endfor %}
91 default: 71 default:
92 throw new bindings.MojoCodecError("Unexpected message name"); 72 throw new bindings.MojoCodecError("Unexpected message name");
93 break; 73 break;
94 } 74 }
95 } 75 }
76 }
96 77
97 {%- for method in interface.methods %} 78
98 {%- if method.response_parameters == None %} 79 class _{{interface|name}}ProxyCalls implements {{interface|name}} {
99 void {{method|name}}( 80 {{interface|name}}ProxyImpl _proxyImpl;
100 {%- for parameter in method.parameters -%} 81
101 {{parameter.kind|dart_type}} {{parameter|name}}{% if not loop.last %}, {% en dif %} 82 _{{interface|name}}ProxyCalls(this._proxyImpl);
102 {%- endfor -%} 83
103 {%- set request_struct = method|struct_from_method -%} 84 _{{interface|name}}ProxyCalls.fromEndpoint(
104 ) { 85 core.MojoMessagePipeEndpoint endpoint) :
105 var params = new {{request_struct|name}}(); 86 _proxyImpl = new {{interface|name}}ProxyImpl.fromEndpoint(endpoint);
106 {%- for parameter in method.parameters %} 87
107 params.{{parameter|name}} = {{parameter|name}}; 88 _{{interface|name}}ProxyCalls.fromHandle(core.MojoHandle handle) :
108 {%- endfor %} 89 _proxyImpl = new {{interface|name}}ProxyImpl.fromHandle(handle);
109 sendMessage(params, k{{interface|name}}_{{method|name}}_name); 90
91 _{{interface|name}}ProxyCalls.unbound() :
92 _proxyImpl = new {{interface|name}}ProxyImpl.unbound();
93
94 {%- for method in interface.methods %}
95 {%- if method.response_parameters == None %}
96 void {{method|name}}(
97 {%- for parameter in method.parameters -%}
98 {{parameter.kind|dart_type}} {{parameter|name}}{% if not loop.last %}, {% endif %}
99 {%- endfor -%}
100 {%- set request_struct = method|struct_from_method -%}
101 ) {
102 var params = new {{request_struct|name}}();
103 {%- for parameter in method.parameters %}
104 params.{{parameter|name}} = {{parameter|name}};
105 {%- endfor %}
106 _proxyImpl.sendMessage(params, k{{interface|name}}_{{method|name}}_name);
107 }
108 {% else %}
109 {%- set response_struct = method|response_struct_from_method %}
110 {%- set request_struct = method|struct_from_method %}
111 Future<{{response_struct|name}}> {{method|name}}(
112 {%- for parameter in method.parameters -%}
113 {{parameter.kind|dart_type}} {{parameter|name}},
114 {%- endfor -%}
115 [Function responseFactory = null]) {
116 var params = new {{request_struct|name}}();
117 {%- for parameter in method.parameters %}
118 params.{{parameter|name}} = {{parameter|name}};
119 {%- endfor %}
120 return _proxyImpl.sendMessageWithRequestId(
121 params,
122 k{{interface|name}}_{{method|name}}_name,
123 -1,
124 bindings.MessageHeader.kMessageExpectsResponse);
125 }
126 {%- endif %}
127 {%- endfor %}
128 }
129
130
131 class {{interface|name}}Proxy implements bindings.ProxyBase {
132 final bindings.Proxy impl;
133 {{interface|name}} interface;
134 final String name = {{interface|name}}Name;
135
136 {{interface|name}}Proxy({{interface|name}}ProxyImpl proxyImpl) :
137 impl = proxyImpl,
138 interface = new _{{interface|name}}ProxyCalls(proxyImpl);
139
140 {{interface|name}}Proxy.fromEndpoint(
141 core.MojoMessagePipeEndpoint endpoint) :
142 impl = new {{interface|name}}ProxyImpl.fromEndpoint(endpoint) {
143 interface = new _{{interface|name}}ProxyCalls(impl);
110 } 144 }
111 {% else %} 145
112 {%- set response_struct = method|response_struct_from_method %} 146 {{interface|name}}Proxy.fromHandle(core.MojoHandle handle) :
113 {%- set request_struct = method|struct_from_method %} 147 impl = new {{interface|name}}ProxyImpl.fromHandle(handle) {
114 Future<{{response_struct|name}}> {{method|name}}( 148 interface = new _{{interface|name}}ProxyCalls(impl);
115 {%- for parameter in method.parameters -%}
116 {{parameter.kind|dart_type}} {{parameter|name}},
117 {%- endfor -%}
118 [Function responseFactory = null]) {
119 var params = new {{request_struct|name}}();
120 {%- for parameter in method.parameters %}
121 params.{{parameter|name}} = {{parameter|name}};
122 {%- endfor %}
123 return sendMessageWithRequestId(
124 params,
125 k{{interface|name}}_{{method|name}}_name,
126 -1,
127 bindings.MessageHeader.kMessageExpectsResponse);
128 } 149 }
129 {%- endif %} 150
130 {%- endfor %} 151 {{interface|name}}Proxy.unbound() :
152 impl = new {{interface|name}}ProxyImpl.unbound() {
153 interface = new _{{interface|name}}ProxyCalls(impl);
154 }
155
156 static {{interface|name}}Proxy newFromEndpoint(
157 core.MojoMessagePipeEndpoint endpoint) =>
158 new {{interface|name}}Proxy.fromEndpoint(endpoint);
131 } 159 }
132 160
161
133 class {{interface|name}}Stub extends bindings.Stub { 162 class {{interface|name}}Stub extends bindings.Stub {
134 {{interface|name}} _delegate = null; 163 {{interface|name}} _delegate = null;
135 164
136 {{interface|name}}Stub(core.MojoMessagePipeEndpoint endpoint) : super(endpoint ); 165 {{interface|name}}Stub.fromEndpoint(core.MojoMessagePipeEndpoint endpoint) :
166 super(endpoint);
137 167
138 {{interface|name}}Stub.fromHandle(core.MojoHandle handle) : 168 {{interface|name}}Stub.fromHandle(core.MojoHandle handle) :
139 super.fromHandle(handle); 169 super.fromHandle(handle);
140 170
141 {{interface|name}}Stub.unbound() : super.unbound(); 171 {{interface|name}}Stub.unbound() : super.unbound();
142 172
143 static {{interface|name}}Stub newFromEndpoint( 173 static {{interface|name}}Stub newFromEndpoint(
144 core.MojoMessagePipeEndpoint endpoint) => 174 core.MojoMessagePipeEndpoint endpoint) =>
145 new {{interface|name}}Stub(endpoint); 175 new {{interface|name}}Stub.fromEndpoint(endpoint);
146 176
147 static const String name = {{interface|name}}.name; 177 static const String name = {{interface|name}}Name;
148 178
149 {% for method in interface.methods %} 179 {% for method in interface.methods %}
150 {%- if method.response_parameters != None %} 180 {%- if method.response_parameters != None %}
151 {%- set response_struct = method|response_struct_from_method %} 181 {%- set response_struct = method|response_struct_from_method %}
152 {{response_struct|name}} _{{response_struct|name}}Factory( 182 {{response_struct|name}} _{{response_struct|name}}Factory(
153 {%- for param in method.response_parameters -%} 183 {%- for param in method.response_parameters -%}
154 {{param.kind|dart_type}} {{param|name}}{% if not loop.last %}, {% endif %} 184 {{param.kind|dart_type}} {{param|name}}{% if not loop.last %}, {% endif %}
155 {%- endfor -%} 185 {%- endfor -%}
156 ) { 186 ) {
157 var result = new {{response_struct|name}}(); 187 var result = new {{response_struct|name}}();
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
201 } 231 }
202 return null; 232 return null;
203 } 233 }
204 234
205 {{interface|name}} get delegate => _delegate; 235 {{interface|name}} get delegate => _delegate;
206 set delegate({{interface|name}} d) { 236 set delegate({{interface|name}} d) {
207 assert(_delegate == null); 237 assert(_delegate == null);
208 _delegate = d; 238 _delegate = d;
209 } 239 }
210 } 240 }
211
212
213 {#--- TODO(zra): Validation #}
214
215
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698