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=MintMakerFullyIsolatedTest.dart:Mint,Purse,PowerfulPurse | 5 // IsolateStubs=MintMakerFullyIsolatedTest.dart:Mint,Purse,PowerfulPurse |
| 6 | 6 |
| 7 #import("../../isolate/src/TestFramework.dart"); | 7 #import("../../isolate/src/TestFramework.dart"); |
|
zundel
2011/10/31 19:00:28
you need to fully revert this file before committi
| |
| 8 | 8 |
| 9 /* class = Purse (file:/usr/local/google/users/scheglov/Clients/Dart/dart/tests/ stub-generator/src/MintMakerFullyIsolatedTest.dart/MintMakerFullyIsolatedTest.da rt: 9) */ | |
| 10 | |
| 11 interface Purse$Proxy { | |
| 12 Promise<int> queryBalance(); | |
| 13 | |
| 14 Purse$Proxy sproutPurse(); | |
| 15 | |
| 16 Promise<int> deposit(int amount, Purse$Proxy source); | |
| 17 } | |
| 18 | |
| 19 class Purse$ProxyImpl extends ProxyImpl implements Purse$Proxy { | |
| 20 Purse$ProxyImpl(Promise<SendPort> port) : super.forReply(port) { } | |
| 21 Purse$ProxyImpl.forIsolate(Proxy isolate) : super.forReply(isolate.call([null] )) { } | |
| 22 factory Purse$ProxyImpl.createIsolate() { | |
| 23 Proxy isolate = new Proxy.forIsolate(new Purse$Dispatcher$Isolate()); | |
| 24 return new Purse$ProxyImpl.forIsolate(isolate); | |
| 25 } | |
| 26 factory Purse$ProxyImpl.localProxy(Purse obj) { | |
| 27 return new Purse$ProxyImpl(new Promise<SendPort>.fromValue(Dispatcher.serve( new Purse$Dispatcher(obj)))); | |
| 28 } | |
| 29 | |
| 30 Promise<int> queryBalance() { | |
| 31 return this.call(["queryBalance"]); | |
| 32 } | |
| 33 | |
| 34 Purse$Proxy sproutPurse() { | |
| 35 return new Purse$ProxyImpl(new PromiseProxy<SendPort>(this.call(["sproutPurs e"]))); | |
| 36 } | |
| 37 | |
| 38 Promise<int> deposit(int amount, Purse$Proxy source) { | |
| 39 return new PromiseProxy<int>(this.call(["deposit", amount, source])); | |
| 40 } | |
| 41 } | |
| 42 | |
| 43 class Purse$Dispatcher extends Dispatcher<Purse> { | |
| 44 Purse$Dispatcher(Purse thing) : super(thing) { } | |
| 45 | |
| 46 void process(var message, void reply(var response)) { | |
| 47 String command = message[0]; | |
| 48 if (command == "Purse") { | |
| 49 } else if (command == "queryBalance") { | |
| 50 int queryBalance = target.queryBalance(); | |
| 51 reply(queryBalance); | |
| 52 } else if (command == "sproutPurse") { | |
| 53 Purse$Proxy sproutPurse = target.sproutPurse(); | |
| 54 reply(sproutPurse); | |
| 55 } else if (command == "deposit") { | |
| 56 int amount = message[1]; | |
| 57 List<Promise<SendPort>> promises = new List<Promise<SendPort>>(); | |
| 58 promises.add(new PromiseProxy<SendPort>(new Promise<SendPort>.fromValue(me ssage[2]))); | |
| 59 Promise done = new Promise(); | |
| 60 done.waitFor(promises, 1); | |
| 61 done.addCompleteHandler((_) { | |
| 62 Purse$Proxy source = new Purse$ProxyImpl(promises[0]); | |
| 63 Promise<int> deposit = target.deposit(amount, source); | |
| 64 reply(deposit); | |
| 65 }); | |
| 66 } else { | |
| 67 // TODO(kasperl,benl): Somehow throw an exception instead. | |
| 68 reply("Exception: command '" + command + "' not understood by Purse."); | |
| 69 } | |
| 70 } | |
| 71 } | |
| 72 | |
| 73 class Purse$Dispatcher$Isolate extends Isolate { | |
| 74 Purse$Dispatcher$Isolate() : super() { } | |
| 75 | |
| 76 void main() { | |
| 77 this.port.receive(void _(var message, SendPort replyTo) { | |
| 78 Purse thing = new Purse(); | |
| 79 SendPort port = Dispatcher.serve(new Purse$Dispatcher(thing)); | |
| 80 Proxy proxy = new Proxy.forPort(replyTo); | |
| 81 proxy.send([port]); | |
| 82 }); | |
| 83 } | |
| 84 } | |
| 85 | |
| 86 /* class = PowerfulPurse (file:/usr/local/google/users/scheglov/Clients/Dart/dar t/tests/stub-generator/src/MintMakerFullyIsolatedTest.dart/MintMakerFullyIsolate dTest.dart: 18) */ | |
| 87 | |
| 88 interface PowerfulPurse$Proxy { | |
| 89 void init(Mint$Proxy mint, int balance); | |
| 90 | |
| 91 Promise<int> grab(int amount); | |
| 92 | |
| 93 Purse$Proxy weak(); | |
| 94 } | |
| 95 | |
| 96 class PowerfulPurse$ProxyImpl extends ProxyImpl implements PowerfulPurse$Proxy { | |
| 97 PowerfulPurse$ProxyImpl(Promise<SendPort> port) : super.forReply(port) { } | |
| 98 PowerfulPurse$ProxyImpl.forIsolate(Proxy isolate) : super.forReply(isolate.cal l([null])) { } | |
| 99 factory PowerfulPurse$ProxyImpl.createIsolate() { | |
| 100 Proxy isolate = new Proxy.forIsolate(new PowerfulPurse$Dispatcher$Isolate()) ; | |
| 101 return new PowerfulPurse$ProxyImpl.forIsolate(isolate); | |
| 102 } | |
| 103 factory PowerfulPurse$ProxyImpl.localProxy(PowerfulPurse obj) { | |
| 104 return new PowerfulPurse$ProxyImpl(new Promise<SendPort>.fromValue(Dispatche r.serve(new PowerfulPurse$Dispatcher(obj)))); | |
| 105 } | |
| 106 | |
| 107 void init(Mint$Proxy mint, int balance) { | |
| 108 this.send(["init", mint, balance]); | |
| 109 } | |
| 110 | |
| 111 Promise<int> grab(int amount) { | |
| 112 return this.call(["grab", amount]); | |
| 113 } | |
| 114 | |
| 115 Purse$Proxy weak() { | |
| 116 return new Purse$ProxyImpl(this.call(["weak"])); | |
| 117 } | |
| 118 } | |
| 119 | |
| 120 class PowerfulPurse$Dispatcher extends Dispatcher<PowerfulPurse> { | |
| 121 PowerfulPurse$Dispatcher(PowerfulPurse thing) : super(thing) { } | |
| 122 | |
| 123 void process(var message, void reply(var response)) { | |
| 124 String command = message[0]; | |
| 125 if (command == "PowerfulPurse") { | |
| 126 } else if (command == "init") { | |
| 127 List<Promise<SendPort>> promises = new List<Promise<SendPort>>(); | |
| 128 promises.add(new PromiseProxy<SendPort>(new Promise<SendPort>.fromValue(me ssage[1]))); | |
| 129 int balance = message[2]; | |
| 130 Promise done = new Promise(); | |
| 131 done.waitFor(promises, 1); | |
| 132 done.addCompleteHandler((_) { | |
| 133 Mint$Proxy mint = new Mint$ProxyImpl(promises[0]); | |
| 134 target.init(mint, balance); | |
| 135 }); | |
| 136 } else if (command == "grab") { | |
| 137 int amount = message[1]; | |
| 138 int grab = target.grab(amount); | |
| 139 reply(grab); | |
| 140 } else if (command == "weak") { | |
| 141 Purse weak = target.weak(); | |
| 142 SendPort port = Dispatcher.serve(new Purse$Dispatcher(weak)); | |
| 143 reply(port); | |
| 144 } else { | |
| 145 // TODO(kasperl,benl): Somehow throw an exception instead. | |
| 146 reply("Exception: command '" + command + "' not understood by PowerfulPurs e."); | |
| 147 } | |
| 148 } | |
| 149 } | |
| 150 | |
| 151 class PowerfulPurse$Dispatcher$Isolate extends Isolate { | |
| 152 PowerfulPurse$Dispatcher$Isolate() : super() { } | |
| 153 | |
| 154 void main() { | |
| 155 this.port.receive(void _(var message, SendPort replyTo) { | |
| 156 PowerfulPurse thing = new PowerfulPurse(); | |
| 157 SendPort port = Dispatcher.serve(new PowerfulPurse$Dispatcher(thing)); | |
| 158 Proxy proxy = new Proxy.forPort(replyTo); | |
| 159 proxy.send([port]); | |
| 160 }); | |
| 161 } | |
| 162 } | |
| 163 | |
| 164 /* class = Mint (file:/usr/local/google/users/scheglov/Clients/Dart/dart/tests/s tub-generator/src/MintMakerFullyIsolatedTest.dart/MintMakerFullyIsolatedTest.dar t: 28) */ | |
| 165 | |
| 166 interface Mint$Proxy { | |
| 167 Purse$Proxy createPurse(int balance); | |
| 168 | |
| 169 PowerfulPurse$Proxy promote(Purse$Proxy purse); | |
| 170 } | |
| 171 | |
| 172 class Mint$ProxyImpl extends ProxyImpl implements Mint$Proxy { | |
| 173 Mint$ProxyImpl(Promise<SendPort> port) : super.forReply(port) { } | |
| 174 Mint$ProxyImpl.forIsolate(Proxy isolate) : super.forReply(isolate.call([null]) ) { } | |
| 175 factory Mint$ProxyImpl.createIsolate() { | |
| 176 Proxy isolate = new Proxy.forIsolate(new Mint$Dispatcher$Isolate()); | |
| 177 return new Mint$ProxyImpl.forIsolate(isolate); | |
| 178 } | |
| 179 factory Mint$ProxyImpl.localProxy(Mint obj) { | |
| 180 return new Mint$ProxyImpl(new Promise<SendPort>.fromValue(Dispatcher.serve(n ew Mint$Dispatcher(obj)))); | |
| 181 } | |
| 182 | |
| 183 Purse$Proxy createPurse(int balance) { | |
| 184 return new Purse$ProxyImpl(new PromiseProxy<SendPort>(this.call(["createPurs e", balance]))); | |
| 185 } | |
| 186 | |
| 187 PowerfulPurse$Proxy promote(Purse$Proxy purse) { | |
| 188 return new PowerfulPurse$ProxyImpl(new PromiseProxy<SendPort>(this.call(["pr omote", purse]))); | |
| 189 } | |
| 190 } | |
| 191 | |
| 192 class Mint$Dispatcher extends Dispatcher<Mint> { | |
| 193 Mint$Dispatcher(Mint thing) : super(thing) { } | |
| 194 | |
| 195 void process(var message, void reply(var response)) { | |
| 196 String command = message[0]; | |
| 197 if (command == "Mint") { | |
| 198 } else if (command == "createPurse") { | |
| 199 int balance = message[1]; | |
| 200 Purse$Proxy createPurse = target.createPurse(balance); | |
| 201 reply(createPurse); | |
| 202 } else if (command == "promote") { | |
| 203 List<Promise<SendPort>> promises = new List<Promise<SendPort>>(); | |
| 204 promises.add(new PromiseProxy<SendPort>(new Promise<SendPort>.fromValue(me ssage[1]))); | |
| 205 Promise done = new Promise(); | |
| 206 done.waitFor(promises, 1); | |
| 207 done.addCompleteHandler((_) { | |
| 208 Purse$Proxy purse = new Purse$ProxyImpl(promises[0]); | |
| 209 PowerfulPurse$Proxy promote = target.promote(purse); | |
| 210 reply(promote); | |
| 211 }); | |
| 212 } else { | |
| 213 // TODO(kasperl,benl): Somehow throw an exception instead. | |
| 214 reply("Exception: command '" + command + "' not understood by Mint."); | |
| 215 } | |
| 216 } | |
| 217 } | |
| 218 | |
| 219 class Mint$Dispatcher$Isolate extends Isolate { | |
| 220 Mint$Dispatcher$Isolate() : super() { } | |
| 221 | |
| 222 void main() { | |
| 223 this.port.receive(void _(var message, SendPort replyTo) { | |
| 224 Mint thing = new Mint(); | |
| 225 SendPort port = Dispatcher.serve(new Mint$Dispatcher(thing)); | |
| 226 Proxy proxy = new Proxy.forPort(replyTo); | |
| 227 proxy.send([port]); | |
| 228 }); | |
| 229 } | |
| 230 } | |
| 231 interface Purse { | 9 interface Purse { |
| 232 Purse(); | 10 Purse(); |
| 233 int queryBalance(); | 11 int queryBalance(); |
| 234 Purse$Proxy sproutPurse(); | 12 Purse$Proxy sproutPurse(); |
| 235 // The deposit has not completed until the promise completes. If we | 13 // The deposit has not completed until the promise completes. If we |
| 236 // supported Promise<void> then this could use that. | 14 // supported Promise<void> then this could use that. |
| 237 Promise<int> deposit(int amount, Purse$Proxy source); | 15 Promise<int> deposit(int amount, Purse$Proxy source); |
| 238 } | 16 } |
| 239 | 17 |
| 240 interface PowerfulPurse extends Purse factory PurseImpl { | 18 interface PowerfulPurse extends Purse factory PurseImpl { |
| (...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 423 Promise<int> allDone = new Promise<int>(); | 201 Promise<int> allDone = new Promise<int>(); |
| 424 allDone.waitFor([d3, inner, inner2], 3); | 202 allDone.waitFor([d3, inner, inner2], 3); |
| 425 allDone.then((_) => expect.succeeded()); | 203 allDone.then((_) => expect.succeeded()); |
| 426 } | 204 } |
| 427 | 205 |
| 428 } | 206 } |
| 429 | 207 |
| 430 main() { | 208 main() { |
| 431 runTests([MintMakerFullyIsolatedTest.testMain]); | 209 runTests([MintMakerFullyIsolatedTest.testMain]); |
| 432 } | 210 } |
| OLD | NEW |