| OLD | NEW |
| 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 import 'dart:async'; | 5 import 'dart:async'; |
| 6 | 6 |
| 7 import 'package:mojo/application.dart'; | 7 import 'package:mojo/application.dart'; |
| 8 import 'package:mojo/bindings.dart'; | 8 import 'package:mojo/bindings.dart'; |
| 9 import 'package:mojo/core.dart'; | 9 import 'package:mojo/core.dart'; |
| 10 import 'package:_mojo_for_test_only/test/echo_service.mojom.dart'; | 10 import 'package:_mojo_for_test_only/test/echo_service.mojom.dart'; |
| 11 | 11 |
| 12 class EchoServiceImpl implements EchoService { | 12 class EchoServiceImpl implements EchoService { |
| 13 EchoServiceInterface _service; | 13 EchoServiceInterface _service; |
| 14 Application _application; | 14 Application _application; |
| 15 | 15 |
| 16 EchoServiceImpl(this._application, MojoMessagePipeEndpoint endpoint) { | 16 EchoServiceImpl(this._application, MojoMessagePipeEndpoint endpoint) { |
| 17 _service = new EchoServiceInterface.fromEndpoint(endpoint, this); | 17 _service = new EchoServiceInterface.fromEndpoint(endpoint, this); |
| 18 } | 18 } |
| 19 | 19 |
| 20 dynamic echoString(String value, [Function responseFactory]) { | 20 void echoString(String value, void callback(String value)) { |
| 21 if (value == "quit") { | 21 if (value == "quit") { |
| 22 _service.close(); | 22 _service.close(); |
| 23 } | 23 } |
| 24 return responseFactory(value); | 24 callback(value); |
| 25 } | 25 } |
| 26 | 26 |
| 27 dynamic delayedEchoString(String value, int millis, | 27 void delayedEchoString( |
| 28 [Function responseFactory]) { | 28 String value, int millis, void callback(String value)) { |
| 29 if (value == "quit") { | 29 if (value == "quit") { |
| 30 _service.close(); | 30 _service.close(); |
| 31 } | 31 } |
| 32 return new Future.delayed( | 32 new Future.delayed( |
| 33 new Duration(milliseconds: millis), () => responseFactory(value)); | 33 new Duration(milliseconds: millis), () => callback(value)); |
| 34 } | 34 } |
| 35 | 35 |
| 36 void swap() { | 36 void swap() { |
| 37 _swapImpls(this); | 37 _swapImpls(this); |
| 38 } | 38 } |
| 39 | 39 |
| 40 void quit() {} | 40 void quit() {} |
| 41 | 41 |
| 42 static void _swapImpls(EchoServiceImpl impl) { | 42 static void _swapImpls(EchoServiceImpl impl) { |
| 43 final stub = impl._service; | 43 final stub = impl._service; |
| (...skipping 18 matching lines...) Expand all Loading... |
| 62 } | 62 } |
| 63 } | 63 } |
| 64 | 64 |
| 65 main(List args, Object handleToken) { | 65 main(List args, Object handleToken) { |
| 66 MojoHandle appHandle = new MojoHandle(handleToken); | 66 MojoHandle appHandle = new MojoHandle(handleToken); |
| 67 new EchoApplication.fromHandle(appHandle) | 67 new EchoApplication.fromHandle(appHandle) |
| 68 ..onError = ((_) { | 68 ..onError = ((_) { |
| 69 MojoHandle.reportLeakedHandles(); | 69 MojoHandle.reportLeakedHandles(); |
| 70 }); | 70 }); |
| 71 } | 71 } |
| OLD | NEW |