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

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

Issue 1948003003: Dart: Wait to handle events on a Stub until it makes sense to do it. (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Add test 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 unified diff | Download patch
« no previous file with comments | « mojo/dart/packages/mojo_services/lib/vsync/vsync.mojom.dart ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 {%- for method in interface.methods %} 1 {%- for method in interface.methods %}
2 const int _{{interface|name|lower_camel}}Method{{method|name|upper_camel}}Name = {{method.ordinal}}; 2 const int _{{interface|name|lower_camel}}Method{{method|name|upper_camel}}Name = {{method.ordinal}};
3 {%- endfor %} 3 {%- endfor %}
4 4
5 {#--- Interface Enums #} 5 {#--- Interface Enums #}
6 {%- from "enum_definition.tmpl" import enum_def -%} 6 {%- from "enum_definition.tmpl" import enum_def -%}
7 {%- for enum in interface.enums %} 7 {%- for enum in interface.enums %}
8 {{ enum_def(enum, typepkg, package) }} 8 {{ enum_def(enum, typepkg, package) }}
9 {%- endfor %} 9 {%- endfor %}
10 10
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after
224 impl.requireVersion(requiredVersion); 224 impl.requireVersion(requiredVersion);
225 } 225 }
226 226
227 String toString() { 227 String toString() {
228 return "{{interface|name}}Proxy($impl)"; 228 return "{{interface|name}}Proxy($impl)";
229 } 229 }
230 } 230 }
231 231
232 232
233 class {{interface|name}}Stub extends bindings.Stub { 233 class {{interface|name}}Stub extends bindings.Stub {
234 {{interface|name}} _impl = null; 234 {{interface|name}} _impl;
235 235
236 {{interface|name}}Stub.fromEndpoint( 236 {{interface|name}}Stub.fromEndpoint(
237 core.MojoMessagePipeEndpoint endpoint, [this._impl]) 237 core.MojoMessagePipeEndpoint endpoint, [{{interface|name}} impl])
238 : super.fromEndpoint(endpoint); 238 : super.fromEndpoint(endpoint, autoBegin: impl != null) {
239 _impl = impl;
240 }
239 241
240 {{interface|name}}Stub.fromHandle(core.MojoHandle handle, [this._impl]) 242 {{interface|name}}Stub.fromHandle(
241 : super.fromHandle(handle); 243 core.MojoHandle handle, [{{interface|name}} impl])
244 : super.fromHandle(handle, autoBegin: impl != null) {
245 _impl = impl;
246 }
242 247
243 {{interface|name}}Stub.unbound() : super.unbound(); 248 {{interface|name}}Stub.unbound() : super.unbound();
244 249
245 static {{interface|name}}Stub newFromEndpoint( 250 static {{interface|name}}Stub newFromEndpoint(
246 core.MojoMessagePipeEndpoint endpoint) { 251 core.MojoMessagePipeEndpoint endpoint) {
247 assert(endpoint.setDescription("For {{interface|name}}Stub")); 252 assert(endpoint.setDescription("For {{interface|name}}Stub"));
248 return new {{interface|name}}Stub.fromEndpoint(endpoint); 253 return new {{interface|name}}Stub.fromEndpoint(endpoint);
249 } 254 }
250 255
251 {% for method in interface.methods %} 256 {% for method in interface.methods %}
(...skipping 12 matching lines...) Expand all
264 } 269 }
265 {%- endif %} 270 {%- endif %}
266 {%- endfor %} 271 {%- endfor %}
267 272
268 dynamic handleMessage(bindings.ServiceMessage message) { 273 dynamic handleMessage(bindings.ServiceMessage message) {
269 if (bindings.ControlMessageHandler.isControlMessage(message)) { 274 if (bindings.ControlMessageHandler.isControlMessage(message)) {
270 return bindings.ControlMessageHandler.handleMessage(this, 275 return bindings.ControlMessageHandler.handleMessage(this,
271 {{interface.version}}, 276 {{interface.version}},
272 message); 277 message);
273 } 278 }
274 assert(_impl != null); 279 if (_impl == null) {
280 throw new core.MojoApiError("$this has no implementation set");
281 }
275 switch (message.header.type) { 282 switch (message.header.type) {
276 {%- for method in interface.methods %} 283 {%- for method in interface.methods %}
277 {%- set request_struct = method.param_struct %} 284 {%- set request_struct = method.param_struct %}
278 case _{{interface|name|lower_camel}}Method{{method|name|upper_camel}}Name: 285 case _{{interface|name|lower_camel}}Method{{method|name|upper_camel}}Name:
279 {%- if method.parameters %} 286 {%- if method.parameters %}
280 var params = {{request_struct|name}}.deserialize( 287 var params = {{request_struct|name}}.deserialize(
281 message.payload); 288 message.payload);
282 {%- endif %} 289 {%- endif %}
283 {%- if method.response_parameters == None %} 290 {%- if method.response_parameters == None %}
284 _impl.{{method|name}}( 291 _impl.{{method|name}}(
(...skipping 30 matching lines...) Expand all
315 {%- endfor %} 322 {%- endfor %}
316 default: 323 default:
317 throw new bindings.MojoCodecError("Unexpected message name"); 324 throw new bindings.MojoCodecError("Unexpected message name");
318 break; 325 break;
319 } 326 }
320 return null; 327 return null;
321 } 328 }
322 329
323 {{interface|name}} get impl => _impl; 330 {{interface|name}} get impl => _impl;
324 set impl({{interface|name}} d) { 331 set impl({{interface|name}} d) {
325 assert(_impl == null); 332 if (d == null) {
333 throw new core.MojoApiError("$this: Cannot set a null implementation");
334 }
335 if (isBound && (_impl == null)) {
336 beginHandlingEvents();
337 }
326 _impl = d; 338 _impl = d;
327 } 339 }
328 340
341 @override
342 void bind(core.MojoMessagePipeEndpoint endpoint) {
343 super.bind(endpoint);
344 if (!isOpen && (_impl != null)) {
345 beginHandlingEvents();
346 }
347 }
348
329 String toString() { 349 String toString() {
330 var superString = super.toString(); 350 var superString = super.toString();
331 return "{{interface|name}}Stub($superString)"; 351 return "{{interface|name}}Stub($superString)";
332 } 352 }
333 353
334 int get version => {{interface.version}}; 354 int get version => {{interface.version}};
335 355
336 static {{descpkg}}ServiceDescription _cachedServiceDescription; 356 static {{descpkg}}ServiceDescription _cachedServiceDescription;
337 static {{descpkg}}ServiceDescription get serviceDescription { 357 static {{descpkg}}ServiceDescription get serviceDescription {
338 if (_cachedServiceDescription == null) { 358 if (_cachedServiceDescription == null) {
339 _cachedServiceDescription = new _{{interface|name}}ServiceDescription(); 359 _cachedServiceDescription = new _{{interface|name}}ServiceDescription();
340 } 360 }
341 return _cachedServiceDescription; 361 return _cachedServiceDescription;
342 } 362 }
343 } 363 }
OLDNEW
« no previous file with comments | « mojo/dart/packages/mojo_services/lib/vsync/vsync.mojom.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698