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 import 'dart:typed_data'; | 6 import 'dart:typed_data'; |
7 import 'mojo:bindings' as bindings; | 7 import 'mojo:bindings' as bindings; |
8 import 'mojo:core' as core; | 8 import 'mojo:core' as core; |
9 | 9 |
10 import 'package:mojo/dart/embedder/test/dart_to_cpp.mojom.dart'; | 10 import 'package:mojo/dart/embedder/test/dart_to_cpp.mojom.dart'; |
11 | 11 |
12 class DartSideImpl extends DartSide { | 12 class DartSideImpl implements DartSide { |
13 static const int BAD_VALUE = 13; | 13 static const int BAD_VALUE = 13; |
14 static const int ELEMENT_BYTES = 1; | 14 static const int ELEMENT_BYTES = 1; |
15 static const int CAPACITY_BYTES = 64; | 15 static const int CAPACITY_BYTES = 64; |
16 | 16 |
17 CppSideProxy cppSide; | 17 DartSideStub _stub; |
| 18 CppSideProxy cppSideProxy; |
| 19 CppSide cppSide; |
18 | 20 |
19 Uint8List _sampleData; | 21 Uint8List _sampleData; |
20 Uint8List _sampleMessage; | 22 Uint8List _sampleMessage; |
21 Completer _completer; | 23 Completer _completer; |
22 | 24 |
23 DartSideImpl(core.MojoMessagePipeEndpoint endpoint) : super(endpoint) { | 25 DartSideImpl(core.MojoMessagePipeEndpoint endpoint) { |
24 super.delegate = this; | 26 _stub = new DartSideStub.fromEndpoint(endpoint) |
| 27 ..delegate = this |
| 28 ..listen(); |
25 _sampleData = new Uint8List(CAPACITY_BYTES); | 29 _sampleData = new Uint8List(CAPACITY_BYTES); |
26 for (int i = 0; i < _sampleData.length; ++i) { | 30 for (int i = 0; i < _sampleData.length; ++i) { |
27 _sampleData[i] = i; | 31 _sampleData[i] = i; |
28 } | 32 } |
29 _sampleMessage = new Uint8List(CAPACITY_BYTES); | 33 _sampleMessage = new Uint8List(CAPACITY_BYTES); |
30 for (int i = 0; i < _sampleMessage.length; ++i) { | 34 for (int i = 0; i < _sampleMessage.length; ++i) { |
31 _sampleMessage[i] = 255 - i; | 35 _sampleMessage[i] = 255 - i; |
32 } | 36 } |
33 _completer = new Completer(); | 37 _completer = new Completer(); |
34 } | 38 } |
35 | 39 |
36 EchoArgsList createEchoArgsList(List<EchoArgs> list) { | 40 EchoArgsList createEchoArgsList(List<EchoArgs> list) { |
37 return list.fold(null, (result, arg) { | 41 return list.fold(null, (result, arg) { |
38 var element = new EchoArgsList(); | 42 var element = new EchoArgsList(); |
39 element.item = arg; | 43 element.item = arg; |
40 element.next = result; | 44 element.next = result; |
41 return element; | 45 return element; |
42 }); | 46 }); |
43 } | 47 } |
44 | 48 |
45 void setClient(CppSideProxy proxy) { | 49 void setClient(bindings.ProxyBase proxy) { |
46 assert(cppSide == null); | 50 assert(cppSide == null); |
47 cppSide = proxy; | 51 cppSideProxy = proxy; |
| 52 cppSide = cppSideProxy.interface; |
48 cppSide.startTest(); | 53 cppSide.startTest(); |
49 } | 54 } |
50 | 55 |
51 void ping() { | 56 void ping() { |
52 cppSide.pingResponse(); | 57 cppSide.pingResponse(); |
53 _completer.complete(null); | 58 _completer.complete(null); |
54 cppSide.close(); | 59 cppSideProxy.impl.close(); |
55 } | 60 } |
56 | 61 |
57 void echo(int numIterations, EchoArgs arg) { | 62 void echo(int numIterations, EchoArgs arg) { |
58 if (arg.si64 > 0) { | 63 if (arg.si64 > 0) { |
59 arg.si64 = BAD_VALUE; | 64 arg.si64 = BAD_VALUE; |
60 } | 65 } |
61 if (arg.si32 > 0) { | 66 if (arg.si32 > 0) { |
62 arg.si32 = BAD_VALUE; | 67 arg.si32 = BAD_VALUE; |
63 } | 68 } |
64 if (arg.si16 > 0) { | 69 if (arg.si16 > 0) { |
(...skipping 28 matching lines...) Expand all Loading... |
93 | 98 |
94 cppSide.echoResponse(createEchoArgsList([arg, specialArg])); | 99 cppSide.echoResponse(createEchoArgsList([arg, specialArg])); |
95 | 100 |
96 dataPipe1.producer.handle.close(); | 101 dataPipe1.producer.handle.close(); |
97 dataPipe2.producer.handle.close(); | 102 dataPipe2.producer.handle.close(); |
98 messagePipe1.endpoints[1].handle.close(); | 103 messagePipe1.endpoints[1].handle.close(); |
99 messagePipe2.endpoints[1].handle.close(); | 104 messagePipe2.endpoints[1].handle.close(); |
100 } | 105 } |
101 cppSide.testFinished(); | 106 cppSide.testFinished(); |
102 _completer.complete(null); | 107 _completer.complete(null); |
103 cppSide.close(); | 108 cppSideProxy.impl.close(); |
104 } | 109 } |
105 | 110 |
106 Future<bool> get future => _completer.future; | 111 Future<bool> get future => _completer.future; |
107 } | 112 } |
108 | 113 |
109 | 114 |
110 main(List args) { | 115 main(List args) { |
111 assert(args.length == 2); | 116 assert(args.length == 2); |
112 int mojoHandle = args[0]; | 117 int mojoHandle = args[0]; |
113 var rawHandle = new core.MojoHandle(mojoHandle); | 118 var rawHandle = new core.MojoHandle(mojoHandle); |
114 var endpoint = new core.MojoMessagePipeEndpoint(rawHandle); | 119 var endpoint = new core.MojoMessagePipeEndpoint(rawHandle); |
115 var dartSide = new DartSideImpl(endpoint); | 120 var dartSide = new DartSideImpl(endpoint); |
116 dartSide.listen(); | |
117 dartSide.future.then((_) { | 121 dartSide.future.then((_) { |
118 print('Success'); | 122 print('Success'); |
119 }); | 123 }); |
120 } | 124 } |
OLD | NEW |