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

Side by Side Diff: mojo/dart/packages/mojo_services/lib/input/input.mojom.dart

Issue 2006093002: Dart: Futures -> Callbacks. (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Cleanup Created 4 years, 6 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 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 library input_mojom; 5 library input_mojom;
6 import 'dart:async'; 6 import 'dart:async';
7 import 'package:mojo/bindings.dart' as bindings; 7 import 'package:mojo/bindings.dart' as bindings;
8 import 'package:mojo/core.dart' as core; 8 import 'package:mojo/core.dart' as core;
9 import 'package:mojo/mojo/bindings/types/service_describer.mojom.dart' as servic e_describer; 9 import 'package:mojo/mojo/bindings/types/service_describer.mojom.dart' as servic e_describer;
10 10
11 11
12 12
13 class _InputClientOnBackButtonParams extends bindings.Struct { 13 class _InputClientOnBackButtonParams extends bindings.Struct {
14 static const List<bindings.StructDataHeader> kVersions = const [ 14 static const List<bindings.StructDataHeader> kVersions = const [
15 const bindings.StructDataHeader(8, 0) 15 const bindings.StructDataHeader(8, 0)
16 ]; 16 ];
17 17
18 _InputClientOnBackButtonParams() : super(kVersions.last.size); 18 _InputClientOnBackButtonParams() : super(kVersions.last.size);
19 19
20 _InputClientOnBackButtonParams.init(
21 ) : super(kVersions.last.size);
22
20 static _InputClientOnBackButtonParams deserialize(bindings.Message message) { 23 static _InputClientOnBackButtonParams deserialize(bindings.Message message) {
21 var decoder = new bindings.Decoder(message); 24 var decoder = new bindings.Decoder(message);
22 var result = decode(decoder); 25 var result = decode(decoder);
23 if (decoder.excessHandles != null) { 26 if (decoder.excessHandles != null) {
24 decoder.excessHandles.forEach((h) => h.close()); 27 decoder.excessHandles.forEach((h) => h.close());
25 } 28 }
26 return result; 29 return result;
27 } 30 }
28 31
29 static _InputClientOnBackButtonParams decode(bindings.Decoder decoder0) { 32 static _InputClientOnBackButtonParams decode(bindings.Decoder decoder0) {
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
68 } 71 }
69 72
70 73
71 class InputClientOnBackButtonResponseParams extends bindings.Struct { 74 class InputClientOnBackButtonResponseParams extends bindings.Struct {
72 static const List<bindings.StructDataHeader> kVersions = const [ 75 static const List<bindings.StructDataHeader> kVersions = const [
73 const bindings.StructDataHeader(8, 0) 76 const bindings.StructDataHeader(8, 0)
74 ]; 77 ];
75 78
76 InputClientOnBackButtonResponseParams() : super(kVersions.last.size); 79 InputClientOnBackButtonResponseParams() : super(kVersions.last.size);
77 80
81 InputClientOnBackButtonResponseParams.init(
82 ) : super(kVersions.last.size);
83
78 static InputClientOnBackButtonResponseParams deserialize(bindings.Message mess age) { 84 static InputClientOnBackButtonResponseParams deserialize(bindings.Message mess age) {
79 var decoder = new bindings.Decoder(message); 85 var decoder = new bindings.Decoder(message);
80 var result = decode(decoder); 86 var result = decode(decoder);
81 if (decoder.excessHandles != null) { 87 if (decoder.excessHandles != null) {
82 decoder.excessHandles.forEach((h) => h.close()); 88 decoder.excessHandles.forEach((h) => h.close());
83 } 89 }
84 return result; 90 return result;
85 } 91 }
86 92
87 static InputClientOnBackButtonResponseParams decode(bindings.Decoder decoder0) { 93 static InputClientOnBackButtonResponseParams decode(bindings.Decoder decoder0) {
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
127 133
128 134
129 class _InputServiceSetClientParams extends bindings.Struct { 135 class _InputServiceSetClientParams extends bindings.Struct {
130 static const List<bindings.StructDataHeader> kVersions = const [ 136 static const List<bindings.StructDataHeader> kVersions = const [
131 const bindings.StructDataHeader(16, 0) 137 const bindings.StructDataHeader(16, 0)
132 ]; 138 ];
133 InputClientInterface client = null; 139 InputClientInterface client = null;
134 140
135 _InputServiceSetClientParams() : super(kVersions.last.size); 141 _InputServiceSetClientParams() : super(kVersions.last.size);
136 142
143 _InputServiceSetClientParams.init(
144 InputClientInterface this.client
145 ) : super(kVersions.last.size);
146
137 static _InputServiceSetClientParams deserialize(bindings.Message message) { 147 static _InputServiceSetClientParams deserialize(bindings.Message message) {
138 var decoder = new bindings.Decoder(message); 148 var decoder = new bindings.Decoder(message);
139 var result = decode(decoder); 149 var result = decode(decoder);
140 if (decoder.excessHandles != null) { 150 if (decoder.excessHandles != null) {
141 decoder.excessHandles.forEach((h) => h.close()); 151 decoder.excessHandles.forEach((h) => h.close());
142 } 152 }
143 return result; 153 return result;
144 } 154 }
145 155
146 static _InputServiceSetClientParams decode(bindings.Decoder decoder0) { 156 static _InputServiceSetClientParams decode(bindings.Decoder decoder0) {
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
192 202
193 Map toJson() { 203 Map toJson() {
194 throw new bindings.MojoCodecError( 204 throw new bindings.MojoCodecError(
195 'Object containing handles cannot be encoded to JSON.'); 205 'Object containing handles cannot be encoded to JSON.');
196 } 206 }
197 } 207 }
198 208
199 const int _inputClientMethodOnBackButtonName = 0; 209 const int _inputClientMethodOnBackButtonName = 0;
200 210
201 class _InputClientServiceDescription implements service_describer.ServiceDescrip tion { 211 class _InputClientServiceDescription implements service_describer.ServiceDescrip tion {
202 dynamic getTopLevelInterface([Function responseFactory]) => 212 void getTopLevelInterface(Function responder) {
203 responseFactory(null); 213 responder(null);
214 }
204 215
205 dynamic getTypeDefinition(String typeKey, [Function responseFactory]) => 216 void getTypeDefinition(String typeKey, Function responder) {
206 responseFactory(null); 217 responder(null);
218 }
207 219
208 dynamic getAllTypeDefinitions([Function responseFactory]) => 220 void getAllTypeDefinitions(Function responder) {
209 responseFactory(null); 221 responder(null);
222 }
210 } 223 }
211 224
212 abstract class InputClient { 225 abstract class InputClient {
213 static const String serviceName = null; 226 static const String serviceName = null;
214 227
215 static service_describer.ServiceDescription _cachedServiceDescription; 228 static service_describer.ServiceDescription _cachedServiceDescription;
216 static service_describer.ServiceDescription get serviceDescription { 229 static service_describer.ServiceDescription get serviceDescription {
217 if (_cachedServiceDescription == null) { 230 if (_cachedServiceDescription == null) {
218 _cachedServiceDescription = new _InputClientServiceDescription(); 231 _cachedServiceDescription = new _InputClientServiceDescription();
219 } 232 }
220 return _cachedServiceDescription; 233 return _cachedServiceDescription;
221 } 234 }
222 235
223 static InputClientProxy connectToService( 236 static InputClientProxy connectToService(
224 bindings.ServiceConnector s, String url, [String serviceName]) { 237 bindings.ServiceConnector s, String url, [String serviceName]) {
225 InputClientProxy p = new InputClientProxy.unbound(); 238 InputClientProxy p = new InputClientProxy.unbound();
226 String name = serviceName ?? InputClient.serviceName; 239 String name = serviceName ?? InputClient.serviceName;
227 if ((name == null) || name.isEmpty) { 240 if ((name == null) || name.isEmpty) {
228 throw new core.MojoApiError( 241 throw new core.MojoApiError(
229 "If an interface has no ServiceName, then one must be provided."); 242 "If an interface has no ServiceName, then one must be provided.");
230 } 243 }
231 s.connectToService(url, p, name); 244 s.connectToService(url, p, name);
232 return p; 245 return p;
233 } 246 }
234 dynamic onBackButton([Function responseFactory = null]); 247 void onBackButton(void callback());
235 } 248 }
236 249
237 abstract class InputClientInterface 250 abstract class InputClientInterface
238 implements bindings.MojoInterface<InputClient>, 251 implements bindings.MojoInterface<InputClient>,
239 InputClient { 252 InputClient {
240 factory InputClientInterface([InputClient impl]) => 253 factory InputClientInterface([InputClient impl]) =>
241 new InputClientStub.unbound(impl); 254 new InputClientStub.unbound(impl);
242 255
243 factory InputClientInterface.fromEndpoint( 256 factory InputClientInterface.fromEndpoint(
244 core.MojoMessagePipeEndpoint endpoint, 257 core.MojoMessagePipeEndpoint endpoint,
(...skipping 29 matching lines...) Expand all
274 287
275 void handleResponse(bindings.ServiceMessage message) { 288 void handleResponse(bindings.ServiceMessage message) {
276 switch (message.header.type) { 289 switch (message.header.type) {
277 case _inputClientMethodOnBackButtonName: 290 case _inputClientMethodOnBackButtonName:
278 var r = InputClientOnBackButtonResponseParams.deserialize( 291 var r = InputClientOnBackButtonResponseParams.deserialize(
279 message.payload); 292 message.payload);
280 if (!message.header.hasRequestId) { 293 if (!message.header.hasRequestId) {
281 proxyError("Expected a message with a valid request Id."); 294 proxyError("Expected a message with a valid request Id.");
282 return; 295 return;
283 } 296 }
284 Completer c = completerMap[message.header.requestId]; 297 Function callback = callbackMap[message.header.requestId];
285 if (c == null) { 298 if (callback == null) {
286 proxyError( 299 proxyError(
287 "Message had unknown request Id: ${message.header.requestId}"); 300 "Message had unknown request Id: ${message.header.requestId}");
288 return; 301 return;
289 } 302 }
290 completerMap.remove(message.header.requestId); 303 callbackMap.remove(message.header.requestId);
291 if (c.isCompleted) { 304 callback();
292 proxyError("Response completer already completed");
293 return;
294 }
295 c.complete(r);
296 break; 305 break;
297 default: 306 default:
298 proxyError("Unexpected message type: ${message.header.type}"); 307 proxyError("Unexpected message type: ${message.header.type}");
299 close(immediate: true); 308 close(immediate: true);
300 break; 309 break;
301 } 310 }
302 } 311 }
303 312
304 @override 313 @override
305 String toString() { 314 String toString() {
(...skipping 24 matching lines...) Expand all
330 return newMockedProxy; 339 return newMockedProxy;
331 } 340 }
332 341
333 static InputClientProxy newFromEndpoint( 342 static InputClientProxy newFromEndpoint(
334 core.MojoMessagePipeEndpoint endpoint) { 343 core.MojoMessagePipeEndpoint endpoint) {
335 assert(endpoint.setDescription("For InputClientProxy")); 344 assert(endpoint.setDescription("For InputClientProxy"));
336 return new InputClientProxy.fromEndpoint(endpoint); 345 return new InputClientProxy.fromEndpoint(endpoint);
337 } 346 }
338 347
339 348
340 dynamic onBackButton([Function responseFactory = null]) { 349 void onBackButton(void callback()) {
341 if (impl != null) { 350 if (impl != null) {
342 return new Future(() => impl.onBackButton(_InputClientStubControl._inputCl ientOnBackButtonResponseParamsFactory)); 351 impl.onBackButton(callback);
352 return;
343 } 353 }
344 var params = new _InputClientOnBackButtonParams(); 354 var params = new _InputClientOnBackButtonParams();
345 return ctrl.sendMessageWithRequestId( 355 ctrl.sendMessageWithRequestId(
346 params, 356 params,
347 _inputClientMethodOnBackButtonName, 357 _inputClientMethodOnBackButtonName,
348 -1, 358 -1,
349 bindings.MessageHeader.kMessageExpectsResponse); 359 bindings.MessageHeader.kMessageExpectsResponse,
360 callback);
350 } 361 }
351 } 362 }
352 363
353 class _InputClientStubControl 364 class _InputClientStubControl
354 extends bindings.StubMessageHandler 365 extends bindings.StubMessageHandler
355 implements bindings.StubControl<InputClient> { 366 implements bindings.StubControl<InputClient> {
356 InputClient _impl; 367 InputClient _impl;
357 368
358 _InputClientStubControl.fromEndpoint( 369 _InputClientStubControl.fromEndpoint(
359 core.MojoMessagePipeEndpoint endpoint, [InputClient impl]) 370 core.MojoMessagePipeEndpoint endpoint, [InputClient impl])
360 : super.fromEndpoint(endpoint, autoBegin: impl != null) { 371 : super.fromEndpoint(endpoint, autoBegin: impl != null) {
361 _impl = impl; 372 _impl = impl;
362 } 373 }
363 374
364 _InputClientStubControl.fromHandle( 375 _InputClientStubControl.fromHandle(
365 core.MojoHandle handle, [InputClient impl]) 376 core.MojoHandle handle, [InputClient impl])
366 : super.fromHandle(handle, autoBegin: impl != null) { 377 : super.fromHandle(handle, autoBegin: impl != null) {
367 _impl = impl; 378 _impl = impl;
368 } 379 }
369 380
370 _InputClientStubControl.unbound([this._impl]) : super.unbound(); 381 _InputClientStubControl.unbound([this._impl]) : super.unbound();
371 382
372 String get serviceName => InputClient.serviceName; 383 String get serviceName => InputClient.serviceName;
373 384
374 385
375 static InputClientOnBackButtonResponseParams _inputClientOnBackButtonResponseP aramsFactory() { 386 Function _inputClientOnBackButtonResponseParamsResponder(
376 var result = new InputClientOnBackButtonResponseParams(); 387 int requestId) {
377 return result; 388 return () {
389 var result = new InputClientOnBackButtonResponseParams();
390 sendResponse(buildResponseWithId(
391 result,
392 _inputClientMethodOnBackButtonName,
393 requestId,
394 bindings.MessageHeader.kMessageIsResponse));
395 };
378 } 396 }
379 397
380 dynamic handleMessage(bindings.ServiceMessage message) { 398 void handleMessage(bindings.ServiceMessage message) {
381 if (bindings.ControlMessageHandler.isControlMessage(message)) { 399 if (bindings.ControlMessageHandler.isControlMessage(message)) {
382 return bindings.ControlMessageHandler.handleMessage(this, 400 bindings.ControlMessageHandler.handleMessage(
383 0, 401 this, 0, message);
384 message); 402 return;
385 } 403 }
386 if (_impl == null) { 404 if (_impl == null) {
387 throw new core.MojoApiError("$this has no implementation set"); 405 throw new core.MojoApiError("$this has no implementation set");
388 } 406 }
389 switch (message.header.type) { 407 switch (message.header.type) {
390 case _inputClientMethodOnBackButtonName: 408 case _inputClientMethodOnBackButtonName:
391 var response = _impl.onBackButton(_inputClientOnBackButtonResponseParams Factory); 409 _impl.onBackButton(_inputClientOnBackButtonResponseParamsResponder(messa ge.header.requestId));
392 if (response is Future) {
393 return response.then((response) {
394 if (response != null) {
395 return buildResponseWithId(
396 response,
397 _inputClientMethodOnBackButtonName,
398 message.header.requestId,
399 bindings.MessageHeader.kMessageIsResponse);
400 }
401 });
402 } else if (response != null) {
403 return buildResponseWithId(
404 response,
405 _inputClientMethodOnBackButtonName,
406 message.header.requestId,
407 bindings.MessageHeader.kMessageIsResponse);
408 }
409 break; 410 break;
410 default: 411 default:
411 throw new bindings.MojoCodecError("Unexpected message name"); 412 throw new bindings.MojoCodecError("Unexpected message name");
412 break; 413 break;
413 } 414 }
414 return null;
415 } 415 }
416 416
417 InputClient get impl => _impl; 417 InputClient get impl => _impl;
418 set impl(InputClient d) { 418 set impl(InputClient d) {
419 if (d == null) { 419 if (d == null) {
420 throw new core.MojoApiError("$this: Cannot set a null implementation"); 420 throw new core.MojoApiError("$this: Cannot set a null implementation");
421 } 421 }
422 if (isBound && (_impl == null)) { 422 if (isBound && (_impl == null)) {
423 beginHandlingEvents(); 423 beginHandlingEvents();
424 } 424 }
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
458 core.MojoHandle handle, [InputClient impl]) 458 core.MojoHandle handle, [InputClient impl])
459 : super(new _InputClientStubControl.fromHandle(handle, impl)); 459 : super(new _InputClientStubControl.fromHandle(handle, impl));
460 460
461 static InputClientStub newFromEndpoint( 461 static InputClientStub newFromEndpoint(
462 core.MojoMessagePipeEndpoint endpoint) { 462 core.MojoMessagePipeEndpoint endpoint) {
463 assert(endpoint.setDescription("For InputClientStub")); 463 assert(endpoint.setDescription("For InputClientStub"));
464 return new InputClientStub.fromEndpoint(endpoint); 464 return new InputClientStub.fromEndpoint(endpoint);
465 } 465 }
466 466
467 467
468 dynamic onBackButton([Function responseFactory = null]) { 468 void onBackButton(void callback()) {
469 return impl.onBackButton(responseFactory); 469 return impl.onBackButton(callback);
470 } 470 }
471 } 471 }
472 472
473 const int _inputServiceMethodSetClientName = 0; 473 const int _inputServiceMethodSetClientName = 0;
474 474
475 class _InputServiceServiceDescription implements service_describer.ServiceDescri ption { 475 class _InputServiceServiceDescription implements service_describer.ServiceDescri ption {
476 dynamic getTopLevelInterface([Function responseFactory]) => 476 void getTopLevelInterface(Function responder) {
477 responseFactory(null); 477 responder(null);
478 }
478 479
479 dynamic getTypeDefinition(String typeKey, [Function responseFactory]) => 480 void getTypeDefinition(String typeKey, Function responder) {
480 responseFactory(null); 481 responder(null);
482 }
481 483
482 dynamic getAllTypeDefinitions([Function responseFactory]) => 484 void getAllTypeDefinitions(Function responder) {
483 responseFactory(null); 485 responder(null);
486 }
484 } 487 }
485 488
486 abstract class InputService { 489 abstract class InputService {
487 static const String serviceName = "input::InputService"; 490 static const String serviceName = "input::InputService";
488 491
489 static service_describer.ServiceDescription _cachedServiceDescription; 492 static service_describer.ServiceDescription _cachedServiceDescription;
490 static service_describer.ServiceDescription get serviceDescription { 493 static service_describer.ServiceDescription get serviceDescription {
491 if (_cachedServiceDescription == null) { 494 if (_cachedServiceDescription == null) {
492 _cachedServiceDescription = new _InputServiceServiceDescription(); 495 _cachedServiceDescription = new _InputServiceServiceDescription();
493 } 496 }
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
623 : super.fromHandle(handle, autoBegin: impl != null) { 626 : super.fromHandle(handle, autoBegin: impl != null) {
624 _impl = impl; 627 _impl = impl;
625 } 628 }
626 629
627 _InputServiceStubControl.unbound([this._impl]) : super.unbound(); 630 _InputServiceStubControl.unbound([this._impl]) : super.unbound();
628 631
629 String get serviceName => InputService.serviceName; 632 String get serviceName => InputService.serviceName;
630 633
631 634
632 635
633 dynamic handleMessage(bindings.ServiceMessage message) { 636 void handleMessage(bindings.ServiceMessage message) {
634 if (bindings.ControlMessageHandler.isControlMessage(message)) { 637 if (bindings.ControlMessageHandler.isControlMessage(message)) {
635 return bindings.ControlMessageHandler.handleMessage(this, 638 bindings.ControlMessageHandler.handleMessage(
636 0, 639 this, 0, message);
637 message); 640 return;
638 } 641 }
639 if (_impl == null) { 642 if (_impl == null) {
640 throw new core.MojoApiError("$this has no implementation set"); 643 throw new core.MojoApiError("$this has no implementation set");
641 } 644 }
642 switch (message.header.type) { 645 switch (message.header.type) {
643 case _inputServiceMethodSetClientName: 646 case _inputServiceMethodSetClientName:
644 var params = _InputServiceSetClientParams.deserialize( 647 var params = _InputServiceSetClientParams.deserialize(
645 message.payload); 648 message.payload);
646 _impl.setClient(params.client); 649 _impl.setClient(params.client);
647 break; 650 break;
648 default: 651 default:
649 throw new bindings.MojoCodecError("Unexpected message name"); 652 throw new bindings.MojoCodecError("Unexpected message name");
650 break; 653 break;
651 } 654 }
652 return null;
653 } 655 }
654 656
655 InputService get impl => _impl; 657 InputService get impl => _impl;
656 set impl(InputService d) { 658 set impl(InputService d) {
657 if (d == null) { 659 if (d == null) {
658 throw new core.MojoApiError("$this: Cannot set a null implementation"); 660 throw new core.MojoApiError("$this: Cannot set a null implementation");
659 } 661 }
660 if (isBound && (_impl == null)) { 662 if (isBound && (_impl == null)) {
661 beginHandlingEvents(); 663 beginHandlingEvents();
662 } 664 }
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
703 } 705 }
704 706
705 707
706 void setClient(InputClientInterface client) { 708 void setClient(InputClientInterface client) {
707 return impl.setClient(client); 709 return impl.setClient(client);
708 } 710 }
709 } 711 }
710 712
711 713
712 714
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698