Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 // IsolateStubs=MintMakerPromiseWithStubsTest.dart:Mint,Purse | 5 // IsolateStubs=MintMakerPromiseWithStubsTest.dart:Mint,Purse |
| 6 | 6 |
| 7 #import("../../isolate/src/TestFramework.dart"); | 7 #import("../../isolate/src/TestFramework.dart"); |
| 8 | 8 |
|
zundel
2011/10/31 19:00:28
you need to fully revert this file before committi
| |
| 9 /* class = Mint (file:/usr/local/google/users/scheglov/Clients/Dart/dart/tests/s tub-generator/src/MintMakerPromiseWithStubsTest.dart/MintMakerPromiseWithStubsTe st.dart: 9) */ | |
| 10 | |
| 11 interface Mint$Proxy { | |
| 12 Purse$Proxy createPurse(int balance); | |
| 13 } | |
| 14 | |
| 15 class Mint$ProxyImpl extends ProxyImpl implements Mint$Proxy { | |
| 16 Mint$ProxyImpl(Promise<SendPort> port) : super.forReply(port) { } | |
| 17 Mint$ProxyImpl.forIsolate(Proxy isolate) : super.forReply(isolate.call([null]) ) { } | |
| 18 factory Mint$ProxyImpl.createIsolate() { | |
| 19 Proxy isolate = new Proxy.forIsolate(new Mint$Dispatcher$Isolate()); | |
| 20 return new Mint$ProxyImpl.forIsolate(isolate); | |
| 21 } | |
| 22 factory Mint$ProxyImpl.localProxy(Mint obj) { | |
| 23 return new Mint$ProxyImpl(new Promise<SendPort>.fromValue(Dispatcher.serve(n ew Mint$Dispatcher(obj)))); | |
| 24 } | |
| 25 | |
| 26 Purse$Proxy createPurse(int balance) { | |
| 27 return new Purse$ProxyImpl(this.call(["createPurse", balance])); | |
| 28 } | |
| 29 } | |
| 30 | |
| 31 class Mint$Dispatcher extends Dispatcher<Mint> { | |
| 32 Mint$Dispatcher(Mint thing) : super(thing) { } | |
| 33 | |
| 34 void process(var message, void reply(var response)) { | |
| 35 String command = message[0]; | |
| 36 if (command == "Mint") { | |
| 37 } else if (command == "createPurse") { | |
| 38 int balance = message[1]; | |
| 39 Purse createPurse = target.createPurse(balance); | |
| 40 SendPort port = Dispatcher.serve(new Purse$Dispatcher(createPurse)); | |
| 41 reply(port); | |
| 42 } else { | |
| 43 // TODO(kasperl,benl): Somehow throw an exception instead. | |
| 44 reply("Exception: command '" + command + "' not understood by Mint."); | |
| 45 } | |
| 46 } | |
| 47 } | |
| 48 | |
| 49 class Mint$Dispatcher$Isolate extends Isolate { | |
| 50 Mint$Dispatcher$Isolate() : super() { } | |
| 51 | |
| 52 void main() { | |
| 53 this.port.receive(void _(var message, SendPort replyTo) { | |
| 54 Mint thing = new Mint(); | |
| 55 SendPort port = Dispatcher.serve(new Mint$Dispatcher(thing)); | |
| 56 Proxy proxy = new Proxy.forPort(replyTo); | |
| 57 proxy.send([port]); | |
| 58 }); | |
| 59 } | |
| 60 } | |
| 61 | |
| 62 /* class = Purse (file:/usr/local/google/users/scheglov/Clients/Dart/dart/tests/ stub-generator/src/MintMakerPromiseWithStubsTest.dart/MintMakerPromiseWithStubsT est.dart: 17) */ | |
| 63 | |
| 64 interface Purse$Proxy { | |
| 65 Promise<int> queryBalance(); | |
| 66 | |
| 67 Purse$Proxy sproutPurse(); | |
| 68 | |
| 69 Promise<int> deposit(int amount, Purse$Proxy source); | |
| 70 } | |
| 71 | |
| 72 class Purse$ProxyImpl extends ProxyImpl implements Purse$Proxy { | |
| 73 Purse$ProxyImpl(Promise<SendPort> port) : super.forReply(port) { } | |
| 74 Purse$ProxyImpl.forIsolate(Proxy isolate) : super.forReply(isolate.call([null] )) { } | |
| 75 factory Purse$ProxyImpl.createIsolate() { | |
| 76 Proxy isolate = new Proxy.forIsolate(new Purse$Dispatcher$Isolate()); | |
| 77 return new Purse$ProxyImpl.forIsolate(isolate); | |
| 78 } | |
| 79 factory Purse$ProxyImpl.localProxy(Purse obj) { | |
| 80 return new Purse$ProxyImpl(new Promise<SendPort>.fromValue(Dispatcher.serve( new Purse$Dispatcher(obj)))); | |
| 81 } | |
| 82 | |
| 83 Promise<int> queryBalance() { | |
| 84 return this.call(["queryBalance"]); | |
| 85 } | |
| 86 | |
| 87 Purse$Proxy sproutPurse() { | |
| 88 return new Purse$ProxyImpl(this.call(["sproutPurse"])); | |
| 89 } | |
| 90 | |
| 91 Promise<int> deposit(int amount, Purse$Proxy source) { | |
| 92 return this.call(["deposit", amount, source]); | |
| 93 } | |
| 94 } | |
| 95 | |
| 96 class Purse$Dispatcher extends Dispatcher<Purse> { | |
| 97 Purse$Dispatcher(Purse thing) : super(thing) { } | |
| 98 | |
| 99 void process(var message, void reply(var response)) { | |
| 100 String command = message[0]; | |
| 101 if (command == "Purse") { | |
| 102 } else if (command == "queryBalance") { | |
| 103 int queryBalance = target.queryBalance(); | |
| 104 reply(queryBalance); | |
| 105 } else if (command == "sproutPurse") { | |
| 106 Purse sproutPurse = target.sproutPurse(); | |
| 107 SendPort port = Dispatcher.serve(new Purse$Dispatcher(sproutPurse)); | |
| 108 reply(port); | |
| 109 } else if (command == "deposit") { | |
| 110 int amount = message[1]; | |
| 111 List<Promise<SendPort>> promises = new List<Promise<SendPort>>(); | |
| 112 promises.add(new PromiseProxy<SendPort>(new Promise<SendPort>.fromValue(me ssage[2]))); | |
| 113 Promise done = new Promise(); | |
| 114 done.waitFor(promises, 1); | |
| 115 done.addCompleteHandler((_) { | |
| 116 Purse$Proxy source = new Purse$ProxyImpl(promises[0]); | |
| 117 int deposit = target.deposit(amount, source); | |
| 118 reply(deposit); | |
| 119 }); | |
| 120 } else { | |
| 121 // TODO(kasperl,benl): Somehow throw an exception instead. | |
| 122 reply("Exception: command '" + command + "' not understood by Purse."); | |
| 123 } | |
| 124 } | |
| 125 } | |
| 126 | |
| 127 class Purse$Dispatcher$Isolate extends Isolate { | |
| 128 Purse$Dispatcher$Isolate() : super() { } | |
| 129 | |
| 130 void main() { | |
| 131 this.port.receive(void _(var message, SendPort replyTo) { | |
| 132 Purse thing = new Purse(); | |
| 133 SendPort port = Dispatcher.serve(new Purse$Dispatcher(thing)); | |
| 134 Proxy proxy = new Proxy.forPort(replyTo); | |
| 135 proxy.send([port]); | |
| 136 }); | |
| 137 } | |
| 138 } | |
| 139 interface Mint factory MintImpl { | 9 interface Mint factory MintImpl { |
| 140 | 10 |
| 141 Mint(); | 11 Mint(); |
| 142 | 12 |
| 143 Purse createPurse(int balance); | 13 Purse createPurse(int balance); |
| 144 | 14 |
| 145 } | 15 } |
| 146 | 16 |
| 147 interface Purse factory PurseImpl { | 17 interface Purse factory PurseImpl { |
| 148 | 18 |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 231 }); | 101 }); |
| 232 }); | 102 }); |
| 233 expect.succeeded(); | 103 expect.succeeded(); |
| 234 } | 104 } |
| 235 | 105 |
| 236 } | 106 } |
| 237 | 107 |
| 238 main() { | 108 main() { |
| 239 runTests([MintMakerPromiseWithStubsTest.testMain]); | 109 runTests([MintMakerPromiseWithStubsTest.testMain]); |
| 240 } | 110 } |
| OLD | NEW |