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

Side by Side Diff: services/dart/test/pingpong/lib/main.dart

Issue 1545483003: Dart: Reorganize files (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Fix build file Created 4 years, 12 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 | « services/dart/test/pingpong/BUILD.gn ('k') | services/dart/test/pingpong/pubspec.lock » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 import 'dart:async';
6
7 import 'package:mojo/application.dart';
8 import 'package:mojo/bindings.dart';
9 import 'package:mojo/core.dart';
10
11 import 'package:_mojo_for_test_only/test/pingpong_service.mojom.dart';
12
13 class PingPongClientImpl implements PingPongClient {
14 final PingPongClientStub stub;
15 Completer _completer;
16 int _count;
17
18 PingPongClientImpl.unbound(this._count, this._completer)
19 : stub = new PingPongClientStub.unbound() {
20 stub.impl = this;
21 }
22
23 void pong(int pongValue) {
24 if (pongValue == _count) {
25 _completer.complete(null);
26 stub.close();
27 }
28 }
29 }
30
31 class PingPongServiceImpl implements PingPongService {
32 PingPongServiceStub _stub;
33 Application _application;
34 PingPongClientProxy _pingPongClient;
35
36 PingPongServiceImpl(this._application, MojoMessagePipeEndpoint endpoint) {
37 _stub = new PingPongServiceStub.fromEndpoint(endpoint, this);
38 }
39
40 PingPongServiceImpl.fromStub(this._stub) {
41 _stub.impl = this;
42 }
43
44 void setClient(ProxyBase proxyBase) {
45 assert(_pingPongClient == null);
46 _pingPongClient = proxyBase;
47 }
48
49 void ping(int pingValue) {
50 if (_pingPongClient != null) {
51 _pingPongClient.ptr.pong(pingValue + 1);
52 }
53 }
54
55 Future pingTargetUrl(String url, int count,
56 [Function responseFactory]) async {
57 if (_application == null) {
58 return responseFactory(false);
59 }
60 var completer = new Completer();
61 var pingPongService = new PingPongServiceProxy.unbound();
62 _application.connectToService(url, pingPongService);
63
64 var pingPongClient = new PingPongClientImpl.unbound(count, completer);
65 pingPongService.ptr.setClient(pingPongClient.stub);
66
67 for (var i = 0; i < count; i++) {
68 pingPongService.ptr.ping(i);
69 }
70 await completer.future;
71 pingPongService.ptr.quit();
72 pingPongService.close();
73
74 return responseFactory(true);
75 }
76
77 Future pingTargetService(ProxyBase proxyBase, int count,
78 [Function responseFactory]) async {
79 var pingPongService = proxyBase;
80 var completer = new Completer();
81 var client = new PingPongClientImpl.unbound(count, completer);
82 pingPongService.ptr.setClient(client.stub);
83
84 for (var i = 0; i < count; i++) {
85 pingPongService.ptr.ping(i);
86 }
87 await completer.future;
88 pingPongService.ptr.quit();
89 pingPongService.close();
90
91 return responseFactory(true);
92 }
93
94 getPingPongService(PingPongServiceStub serviceStub) {
95 new PingPongServiceImpl.fromStub(serviceStub);
96 }
97
98 void quit() {
99 if (_pingPongClient != null) {
100 _pingPongClient.close();
101 _pingPongClient = null;
102 }
103 _stub.close();
104 _stub = null;
105 }
106 }
107
108 class PingPongApplication extends Application {
109 PingPongApplication.fromHandle(MojoHandle handle) : super.fromHandle(handle);
110
111 @override
112 void acceptConnection(String requestorUrl, String resolvedUrl,
113 ApplicationConnection connection) {
114 connection.provideService(PingPongService.serviceName,
115 (endpoint) => new PingPongServiceImpl(this, endpoint));
116 }
117 }
118
119 main(List args) {
120 MojoHandle appHandle = new MojoHandle(args[0]);
121 String url = args[1];
122 new PingPongApplication.fromHandle(appHandle)
123 ..onError = ((_) {
124 MojoHandle.reportLeakedHandles();
125 });
126 }
OLDNEW
« no previous file with comments | « services/dart/test/pingpong/BUILD.gn ('k') | services/dart/test/pingpong/pubspec.lock » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698