| 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 DartSideStub _stub; |
| 17 CppSideProxy cppSide; | 18 CppSideProxy cppSide; |
| 18 | 19 |
| 19 Uint8List _sampleData; | 20 Uint8List _sampleData; |
| 20 Uint8List _sampleMessage; | 21 Uint8List _sampleMessage; |
| 21 Completer _completer; | 22 Completer _completer; |
| 22 | 23 |
| 23 DartSideImpl(core.MojoMessagePipeEndpoint endpoint) : super(endpoint) { | 24 DartSideImpl(core.MojoMessagePipeEndpoint endpoint) { |
| 24 super.delegate = this; | 25 _stub = new DartSideStub.fromEndpoint(endpoint) |
| 26 ..delegate = this |
| 27 ..listen(); |
| 25 _sampleData = new Uint8List(CAPACITY_BYTES); | 28 _sampleData = new Uint8List(CAPACITY_BYTES); |
| 26 for (int i = 0; i < _sampleData.length; ++i) { | 29 for (int i = 0; i < _sampleData.length; ++i) { |
| 27 _sampleData[i] = i; | 30 _sampleData[i] = i; |
| 28 } | 31 } |
| 29 _sampleMessage = new Uint8List(CAPACITY_BYTES); | 32 _sampleMessage = new Uint8List(CAPACITY_BYTES); |
| 30 for (int i = 0; i < _sampleMessage.length; ++i) { | 33 for (int i = 0; i < _sampleMessage.length; ++i) { |
| 31 _sampleMessage[i] = 255 - i; | 34 _sampleMessage[i] = 255 - i; |
| 32 } | 35 } |
| 33 _completer = new Completer(); | 36 _completer = new Completer(); |
| 34 } | 37 } |
| 35 | 38 |
| 36 EchoArgsList createEchoArgsList(List<EchoArgs> list) { | 39 EchoArgsList createEchoArgsList(List<EchoArgs> list) { |
| 37 return list.fold(null, (result, arg) { | 40 return list.fold(null, (result, arg) { |
| 38 var element = new EchoArgsList(); | 41 var element = new EchoArgsList(); |
| 39 element.item = arg; | 42 element.item = arg; |
| 40 element.next = result; | 43 element.next = result; |
| 41 return element; | 44 return element; |
| 42 }); | 45 }); |
| 43 } | 46 } |
| 44 | 47 |
| 45 void setClient(CppSideProxy proxy) { | 48 void setClient(bindings.ProxyBase proxy) { |
| 46 assert(cppSide == null); | 49 assert(cppSide == null); |
| 47 cppSide = proxy; | 50 cppSide = proxy; |
| 48 cppSide.startTest(); | 51 cppSide.interface.startTest(); |
| 49 } | 52 } |
| 50 | 53 |
| 51 void ping() { | 54 void ping() { |
| 52 cppSide.pingResponse(); | 55 cppSide.interface.pingResponse(); |
| 53 _completer.complete(null); | 56 _completer.complete(null); |
| 54 cppSide.close(); | 57 cppSide.impl.close(); |
| 55 } | 58 } |
| 56 | 59 |
| 57 void echo(int numIterations, EchoArgs arg) { | 60 void echo(int numIterations, EchoArgs arg) { |
| 58 if (arg.si64 > 0) { | 61 if (arg.si64 > 0) { |
| 59 arg.si64 = BAD_VALUE; | 62 arg.si64 = BAD_VALUE; |
| 60 } | 63 } |
| 61 if (arg.si32 > 0) { | 64 if (arg.si32 > 0) { |
| 62 arg.si32 = BAD_VALUE; | 65 arg.si32 = BAD_VALUE; |
| 63 } | 66 } |
| 64 if (arg.si16 > 0) { | 67 if (arg.si16 > 0) { |
| (...skipping 19 matching lines...) Expand all Loading... |
| 84 specialArg.si8 = -1; | 87 specialArg.si8 = -1; |
| 85 specialArg.name = 'going'; | 88 specialArg.name = 'going'; |
| 86 specialArg.dataHandle = dataPipe2.consumer; | 89 specialArg.dataHandle = dataPipe2.consumer; |
| 87 specialArg.messageHandle = messagePipe2.endpoints[0]; | 90 specialArg.messageHandle = messagePipe2.endpoints[0]; |
| 88 | 91 |
| 89 dataPipe1.producer.write(_sampleData.buffer.asByteData()); | 92 dataPipe1.producer.write(_sampleData.buffer.asByteData()); |
| 90 dataPipe2.producer.write(_sampleData.buffer.asByteData()); | 93 dataPipe2.producer.write(_sampleData.buffer.asByteData()); |
| 91 messagePipe1.endpoints[1].write(_sampleMessage.buffer.asByteData()); | 94 messagePipe1.endpoints[1].write(_sampleMessage.buffer.asByteData()); |
| 92 messagePipe2.endpoints[1].write(_sampleMessage.buffer.asByteData()); | 95 messagePipe2.endpoints[1].write(_sampleMessage.buffer.asByteData()); |
| 93 | 96 |
| 94 cppSide.echoResponse(createEchoArgsList([arg, specialArg])); | 97 cppSide.interface.echoResponse(createEchoArgsList([arg, specialArg])); |
| 95 | 98 |
| 96 dataPipe1.producer.handle.close(); | 99 dataPipe1.producer.handle.close(); |
| 97 dataPipe2.producer.handle.close(); | 100 dataPipe2.producer.handle.close(); |
| 98 messagePipe1.endpoints[1].handle.close(); | 101 messagePipe1.endpoints[1].handle.close(); |
| 99 messagePipe2.endpoints[1].handle.close(); | 102 messagePipe2.endpoints[1].handle.close(); |
| 100 } | 103 } |
| 101 cppSide.testFinished(); | 104 cppSide.interface.testFinished(); |
| 102 _completer.complete(null); | 105 _completer.complete(null); |
| 103 cppSide.close(); | 106 cppSide.impl.close(); |
| 104 } | 107 } |
| 105 | 108 |
| 106 Future<bool> get future => _completer.future; | 109 Future<bool> get future => _completer.future; |
| 107 } | 110 } |
| 108 | 111 |
| 109 | 112 |
| 110 main(List args) { | 113 main(List args) { |
| 111 assert(args.length == 2); | 114 assert(args.length == 2); |
| 112 int mojoHandle = args[0]; | 115 int mojoHandle = args[0]; |
| 113 var rawHandle = new core.MojoHandle(mojoHandle); | 116 var rawHandle = new core.MojoHandle(mojoHandle); |
| 114 var endpoint = new core.MojoMessagePipeEndpoint(rawHandle); | 117 var endpoint = new core.MojoMessagePipeEndpoint(rawHandle); |
| 115 var dartSide = new DartSideImpl(endpoint); | 118 var dartSide = new DartSideImpl(endpoint); |
| 116 dartSide.listen(); | |
| 117 dartSide.future.then((_) { | 119 dartSide.future.then((_) { |
| 118 print('Success'); | 120 print('Success'); |
| 119 }); | 121 }); |
| 120 } | 122 } |
| OLD | NEW |