| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 import 'dart:async'; | |
| 6 import 'dart:typed_data'; | |
| 7 | |
| 8 import 'package:_mojo_for_test_only/dart_to_cpp/dart_to_cpp.mojom.dart'; | |
| 9 import 'package:mojo/bindings.dart' as bindings; | |
| 10 import 'package:mojo/core.dart' as core; | |
| 11 | |
| 12 class DartSideImpl implements DartSide { | |
| 13 static const int BAD_VALUE = 13; | |
| 14 static const int ELEMENT_BYTES = 1; | |
| 15 static const int CAPACITY_BYTES = 64; | |
| 16 | |
| 17 DartSideStub _stub; | |
| 18 CppSideProxy cppSide; | |
| 19 | |
| 20 Uint8List _sampleData; | |
| 21 Uint8List _sampleMessage; | |
| 22 Completer _completer; | |
| 23 | |
| 24 DartSideImpl(core.MojoMessagePipeEndpoint endpoint) { | |
| 25 _stub = new DartSideStub.fromEndpoint(endpoint, this); | |
| 26 _sampleData = new Uint8List(CAPACITY_BYTES); | |
| 27 for (int i = 0; i < _sampleData.length; ++i) { | |
| 28 _sampleData[i] = i; | |
| 29 } | |
| 30 _sampleMessage = new Uint8List(CAPACITY_BYTES); | |
| 31 for (int i = 0; i < _sampleMessage.length; ++i) { | |
| 32 _sampleMessage[i] = 255 - i; | |
| 33 } | |
| 34 _completer = new Completer(); | |
| 35 } | |
| 36 | |
| 37 EchoArgsList createEchoArgsList(List<EchoArgs> list) { | |
| 38 return list.fold(null, (result, arg) { | |
| 39 var element = new EchoArgsList(); | |
| 40 element.item = arg; | |
| 41 element.next = result; | |
| 42 return element; | |
| 43 }); | |
| 44 } | |
| 45 | |
| 46 void setClient(bindings.ProxyBase proxy) { | |
| 47 assert(cppSide == null); | |
| 48 cppSide = proxy; | |
| 49 cppSide.ptr.startTest(); | |
| 50 } | |
| 51 | |
| 52 void ping() { | |
| 53 cppSide.ptr.pingResponse(); | |
| 54 _completer.complete(null); | |
| 55 cppSide.close(); | |
| 56 } | |
| 57 | |
| 58 void echo(int numIterations, EchoArgs arg) { | |
| 59 if (arg.si64 > 0) { | |
| 60 arg.si64 = BAD_VALUE; | |
| 61 } | |
| 62 if (arg.si32 > 0) { | |
| 63 arg.si32 = BAD_VALUE; | |
| 64 } | |
| 65 if (arg.si16 > 0) { | |
| 66 arg.si16 = BAD_VALUE; | |
| 67 } | |
| 68 if (arg.si8 > 0) { | |
| 69 arg.si8 = BAD_VALUE; | |
| 70 } | |
| 71 | |
| 72 for (int i = 0; i < numIterations; ++i) { | |
| 73 var dataPipe1 = new core.MojoDataPipe(ELEMENT_BYTES, CAPACITY_BYTES); | |
| 74 var dataPipe2 = new core.MojoDataPipe(ELEMENT_BYTES, CAPACITY_BYTES); | |
| 75 var messagePipe1 = new core.MojoMessagePipe(); | |
| 76 var messagePipe2 = new core.MojoMessagePipe(); | |
| 77 | |
| 78 arg.dataHandle = dataPipe1.consumer; | |
| 79 arg.messageHandle = messagePipe1.endpoints[0]; | |
| 80 | |
| 81 var specialArg = new EchoArgs(); | |
| 82 specialArg.si64 = -1; | |
| 83 specialArg.si32 = -1; | |
| 84 specialArg.si16 = -1; | |
| 85 specialArg.si8 = -1; | |
| 86 specialArg.name = 'going'; | |
| 87 specialArg.dataHandle = dataPipe2.consumer; | |
| 88 specialArg.messageHandle = messagePipe2.endpoints[0]; | |
| 89 | |
| 90 dataPipe1.producer.write(_sampleData.buffer.asByteData()); | |
| 91 dataPipe2.producer.write(_sampleData.buffer.asByteData()); | |
| 92 messagePipe1.endpoints[1].write(_sampleMessage.buffer.asByteData()); | |
| 93 messagePipe2.endpoints[1].write(_sampleMessage.buffer.asByteData()); | |
| 94 | |
| 95 cppSide.ptr.echoResponse(createEchoArgsList([arg, specialArg])); | |
| 96 | |
| 97 dataPipe1.producer.handle.close(); | |
| 98 dataPipe2.producer.handle.close(); | |
| 99 messagePipe1.endpoints[1].handle.close(); | |
| 100 messagePipe2.endpoints[1].handle.close(); | |
| 101 } | |
| 102 cppSide.ptr.testFinished(); | |
| 103 _completer.complete(null); | |
| 104 cppSide.close(); | |
| 105 } | |
| 106 | |
| 107 Future<bool> get future => _completer.future; | |
| 108 } | |
| 109 | |
| 110 main(List args) { | |
| 111 assert(args.length == 3); | |
| 112 int mojoHandle = args[0]; | |
| 113 var rawHandle = new core.MojoHandle(mojoHandle); | |
| 114 var endpoint = new core.MojoMessagePipeEndpoint(rawHandle); | |
| 115 var dartSide = new DartSideImpl(endpoint); | |
| 116 dartSide.future.then((_) { | |
| 117 print('Success'); | |
| 118 }); | |
| 119 } | |
| OLD | NEW |