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

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: Move code from mojo_patch to proxy.dart 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
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 factory InputClientInterface.fromEndpoint( 255 factory InputClientInterface.fromEndpoint(
243 core.MojoMessagePipeEndpoint endpoint, 256 core.MojoMessagePipeEndpoint endpoint,
244 [InputClient impl]) => 257 [InputClient impl]) =>
(...skipping 22 matching lines...) Expand all
267 280
268 void handleResponse(bindings.ServiceMessage message) { 281 void handleResponse(bindings.ServiceMessage message) {
269 switch (message.header.type) { 282 switch (message.header.type) {
270 case _inputClientMethodOnBackButtonName: 283 case _inputClientMethodOnBackButtonName:
271 var r = InputClientOnBackButtonResponseParams.deserialize( 284 var r = InputClientOnBackButtonResponseParams.deserialize(
272 message.payload); 285 message.payload);
273 if (!message.header.hasRequestId) { 286 if (!message.header.hasRequestId) {
274 proxyError("Expected a message with a valid request Id."); 287 proxyError("Expected a message with a valid request Id.");
275 return; 288 return;
276 } 289 }
277 Completer c = completerMap[message.header.requestId]; 290 Function callback = callbackMap[message.header.requestId];
278 if (c == null) { 291 if (callback == null) {
279 proxyError( 292 proxyError(
280 "Message had unknown request Id: ${message.header.requestId}"); 293 "Message had unknown request Id: ${message.header.requestId}");
281 return; 294 return;
282 } 295 }
283 completerMap.remove(message.header.requestId); 296 callbackMap.remove(message.header.requestId);
284 if (c.isCompleted) { 297 callback();
285 proxyError("Response completer already completed");
286 return;
287 }
288 c.complete(r);
289 break; 298 break;
290 default: 299 default:
291 proxyError("Unexpected message type: ${message.header.type}"); 300 proxyError("Unexpected message type: ${message.header.type}");
292 close(immediate: true); 301 close(immediate: true);
293 break; 302 break;
294 } 303 }
295 } 304 }
296 305
297 InputClient get impl => null; 306 InputClient get impl => null;
298 set impl(InputClient _) { 307 set impl(InputClient _) {
(...skipping 22 matching lines...) Expand all
321 InputClientProxy.unbound() 330 InputClientProxy.unbound()
322 : super(new _InputClientProxyControl.unbound()); 331 : super(new _InputClientProxyControl.unbound());
323 332
324 static InputClientProxy newFromEndpoint( 333 static InputClientProxy newFromEndpoint(
325 core.MojoMessagePipeEndpoint endpoint) { 334 core.MojoMessagePipeEndpoint endpoint) {
326 assert(endpoint.setDescription("For InputClientProxy")); 335 assert(endpoint.setDescription("For InputClientProxy"));
327 return new InputClientProxy.fromEndpoint(endpoint); 336 return new InputClientProxy.fromEndpoint(endpoint);
328 } 337 }
329 338
330 339
331 dynamic onBackButton([Function responseFactory = null]) { 340 void onBackButton(void callback()) {
332 var params = new _InputClientOnBackButtonParams(); 341 var params = new _InputClientOnBackButtonParams();
333 return ctrl.sendMessageWithRequestId( 342 ctrl.sendMessageWithRequestId(
334 params, 343 params,
335 _inputClientMethodOnBackButtonName, 344 _inputClientMethodOnBackButtonName,
336 -1, 345 -1,
337 bindings.MessageHeader.kMessageExpectsResponse); 346 bindings.MessageHeader.kMessageExpectsResponse,
347 callback);
338 } 348 }
339 } 349 }
340 350
341 class _InputClientStubControl 351 class _InputClientStubControl
342 extends bindings.StubMessageHandler 352 extends bindings.StubMessageHandler
343 implements bindings.StubControl<InputClient> { 353 implements bindings.StubControl<InputClient> {
344 InputClient _impl; 354 InputClient _impl;
345 355
346 _InputClientStubControl.fromEndpoint( 356 _InputClientStubControl.fromEndpoint(
347 core.MojoMessagePipeEndpoint endpoint, [InputClient impl]) 357 core.MojoMessagePipeEndpoint endpoint, [InputClient impl])
348 : super.fromEndpoint(endpoint, autoBegin: impl != null) { 358 : super.fromEndpoint(endpoint, autoBegin: impl != null) {
349 _impl = impl; 359 _impl = impl;
350 } 360 }
351 361
352 _InputClientStubControl.fromHandle( 362 _InputClientStubControl.fromHandle(
353 core.MojoHandle handle, [InputClient impl]) 363 core.MojoHandle handle, [InputClient impl])
354 : super.fromHandle(handle, autoBegin: impl != null) { 364 : super.fromHandle(handle, autoBegin: impl != null) {
355 _impl = impl; 365 _impl = impl;
356 } 366 }
357 367
358 _InputClientStubControl.unbound([this._impl]) : super.unbound(); 368 _InputClientStubControl.unbound([this._impl]) : super.unbound();
359 369
360 String get serviceName => InputClient.serviceName; 370 String get serviceName => InputClient.serviceName;
361 371
362 372
363 InputClientOnBackButtonResponseParams _inputClientOnBackButtonResponseParamsFa ctory() { 373 Function _inputClientOnBackButtonResponseParamsResponder(
364 var result = new InputClientOnBackButtonResponseParams(); 374 int requestId) {
365 return result; 375 return () {
376 var result = new InputClientOnBackButtonResponseParams();
377 sendResponse(buildResponseWithId(
378 result,
379 _inputClientMethodOnBackButtonName,
380 requestId,
381 bindings.MessageHeader.kMessageIsResponse));
382 };
366 } 383 }
367 384
368 dynamic handleMessage(bindings.ServiceMessage message) { 385 void handleMessage(bindings.ServiceMessage message) {
369 if (bindings.ControlMessageHandler.isControlMessage(message)) { 386 if (bindings.ControlMessageHandler.isControlMessage(message)) {
370 return bindings.ControlMessageHandler.handleMessage(this, 387 bindings.ControlMessageHandler.handleMessage(
371 0, 388 this, 0, message);
372 message); 389 return;
373 } 390 }
374 if (_impl == null) { 391 if (_impl == null) {
375 throw new core.MojoApiError("$this has no implementation set"); 392 throw new core.MojoApiError("$this has no implementation set");
376 } 393 }
377 switch (message.header.type) { 394 switch (message.header.type) {
378 case _inputClientMethodOnBackButtonName: 395 case _inputClientMethodOnBackButtonName:
379 var response = _impl.onBackButton(_inputClientOnBackButtonResponseParams Factory); 396 _impl.onBackButton(_inputClientOnBackButtonResponseParamsResponder(messa ge.header.requestId));
380 if (response is Future) {
381 return response.then((response) {
382 if (response != null) {
383 return buildResponseWithId(
384 response,
385 _inputClientMethodOnBackButtonName,
386 message.header.requestId,
387 bindings.MessageHeader.kMessageIsResponse);
388 }
389 });
390 } else if (response != null) {
391 return buildResponseWithId(
392 response,
393 _inputClientMethodOnBackButtonName,
394 message.header.requestId,
395 bindings.MessageHeader.kMessageIsResponse);
396 }
397 break; 397 break;
398 default: 398 default:
399 throw new bindings.MojoCodecError("Unexpected message name"); 399 throw new bindings.MojoCodecError("Unexpected message name");
400 break; 400 break;
401 } 401 }
402 return null;
403 } 402 }
404 403
405 InputClient get impl => _impl; 404 InputClient get impl => _impl;
406 set impl(InputClient d) { 405 set impl(InputClient d) {
407 if (d == null) { 406 if (d == null) {
408 throw new core.MojoApiError("$this: Cannot set a null implementation"); 407 throw new core.MojoApiError("$this: Cannot set a null implementation");
409 } 408 }
410 if (isBound && (_impl == null)) { 409 if (isBound && (_impl == null)) {
411 beginHandlingEvents(); 410 beginHandlingEvents();
412 } 411 }
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
446 core.MojoHandle handle, [InputClient impl]) 445 core.MojoHandle handle, [InputClient impl])
447 : super(new _InputClientStubControl.fromHandle(handle, impl)); 446 : super(new _InputClientStubControl.fromHandle(handle, impl));
448 447
449 static InputClientStub newFromEndpoint( 448 static InputClientStub newFromEndpoint(
450 core.MojoMessagePipeEndpoint endpoint) { 449 core.MojoMessagePipeEndpoint endpoint) {
451 assert(endpoint.setDescription("For InputClientStub")); 450 assert(endpoint.setDescription("For InputClientStub"));
452 return new InputClientStub.fromEndpoint(endpoint); 451 return new InputClientStub.fromEndpoint(endpoint);
453 } 452 }
454 453
455 454
456 dynamic onBackButton([Function responseFactory = null]) { 455 void onBackButton(void callback()) {
457 return impl.onBackButton(responseFactory); 456 return impl.onBackButton(callback);
458 } 457 }
459 } 458 }
460 459
461 const int _inputServiceMethodSetClientName = 0; 460 const int _inputServiceMethodSetClientName = 0;
462 461
463 class _InputServiceServiceDescription implements service_describer.ServiceDescri ption { 462 class _InputServiceServiceDescription implements service_describer.ServiceDescri ption {
464 dynamic getTopLevelInterface([Function responseFactory]) => 463 void getTopLevelInterface(Function responder) {
465 responseFactory(null); 464 responder(null);
465 }
466 466
467 dynamic getTypeDefinition(String typeKey, [Function responseFactory]) => 467 void getTypeDefinition(String typeKey, Function responder) {
468 responseFactory(null); 468 responder(null);
469 }
469 470
470 dynamic getAllTypeDefinitions([Function responseFactory]) => 471 void getAllTypeDefinitions(Function responder) {
471 responseFactory(null); 472 responder(null);
473 }
472 } 474 }
473 475
474 abstract class InputService { 476 abstract class InputService {
475 static const String serviceName = "input::InputService"; 477 static const String serviceName = "input::InputService";
476 478
477 static service_describer.ServiceDescription _cachedServiceDescription; 479 static service_describer.ServiceDescription _cachedServiceDescription;
478 static service_describer.ServiceDescription get serviceDescription { 480 static service_describer.ServiceDescription get serviceDescription {
479 if (_cachedServiceDescription == null) { 481 if (_cachedServiceDescription == null) {
480 _cachedServiceDescription = new _InputServiceServiceDescription(); 482 _cachedServiceDescription = new _InputServiceServiceDescription();
481 } 483 }
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
598 : super.fromHandle(handle, autoBegin: impl != null) { 600 : super.fromHandle(handle, autoBegin: impl != null) {
599 _impl = impl; 601 _impl = impl;
600 } 602 }
601 603
602 _InputServiceStubControl.unbound([this._impl]) : super.unbound(); 604 _InputServiceStubControl.unbound([this._impl]) : super.unbound();
603 605
604 String get serviceName => InputService.serviceName; 606 String get serviceName => InputService.serviceName;
605 607
606 608
607 609
608 dynamic handleMessage(bindings.ServiceMessage message) { 610 void handleMessage(bindings.ServiceMessage message) {
609 if (bindings.ControlMessageHandler.isControlMessage(message)) { 611 if (bindings.ControlMessageHandler.isControlMessage(message)) {
610 return bindings.ControlMessageHandler.handleMessage(this, 612 bindings.ControlMessageHandler.handleMessage(
611 0, 613 this, 0, message);
612 message); 614 return;
613 } 615 }
614 if (_impl == null) { 616 if (_impl == null) {
615 throw new core.MojoApiError("$this has no implementation set"); 617 throw new core.MojoApiError("$this has no implementation set");
616 } 618 }
617 switch (message.header.type) { 619 switch (message.header.type) {
618 case _inputServiceMethodSetClientName: 620 case _inputServiceMethodSetClientName:
619 var params = _InputServiceSetClientParams.deserialize( 621 var params = _InputServiceSetClientParams.deserialize(
620 message.payload); 622 message.payload);
621 _impl.setClient(params.client); 623 _impl.setClient(params.client);
622 break; 624 break;
623 default: 625 default:
624 throw new bindings.MojoCodecError("Unexpected message name"); 626 throw new bindings.MojoCodecError("Unexpected message name");
625 break; 627 break;
626 } 628 }
627 return null;
628 } 629 }
629 630
630 InputService get impl => _impl; 631 InputService get impl => _impl;
631 set impl(InputService d) { 632 set impl(InputService d) {
632 if (d == null) { 633 if (d == null) {
633 throw new core.MojoApiError("$this: Cannot set a null implementation"); 634 throw new core.MojoApiError("$this: Cannot set a null implementation");
634 } 635 }
635 if (isBound && (_impl == null)) { 636 if (isBound && (_impl == null)) {
636 beginHandlingEvents(); 637 beginHandlingEvents();
637 } 638 }
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
678 } 679 }
679 680
680 681
681 void setClient(InputClientInterface client) { 682 void setClient(InputClientInterface client) {
682 return impl.setClient(client); 683 return impl.setClient(client);
683 } 684 }
684 } 685 }
685 686
686 687
687 688
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698