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 |
9 /* class = Mint (tests/stub-generator/src/MintMakerPromiseWithStubsTest.dart/Min
tMakerPromiseWithStubsTest.dart: 9) */ | 9 /* class = Mint (tests/stub-generator/src/MintMakerPromiseWithStubsTest.dart/Min
tMakerPromiseWithStubsTest.dart: 9) */ |
10 | 10 |
11 interface Mint$Proxy extends Proxy { | 11 interface Mint$Proxy { |
12 Purse$Proxy createPurse(int balance); | 12 Purse$Proxy createPurse(int balance); |
13 } | 13 } |
14 | 14 |
15 class Mint$ProxyImpl extends ProxyImpl implements Mint$Proxy { | 15 class Mint$ProxyImpl extends Proxy implements Mint$Proxy { |
16 Mint$ProxyImpl(Promise<SendPort> port) : super.forReply(port) { } | 16 Mint$ProxyImpl(Promise<SendPort> port) : super.forReply(port) { } |
17 Mint$ProxyImpl.forIsolate(Proxy isolate) : super.forReply(isolate.call([null])
) { } | 17 Mint$ProxyImpl.forIsolate(Proxy isolate) : super.forReply(isolate.call([null])
) { } |
18 factory Mint$ProxyImpl.createIsolate() { | 18 factory Mint$ProxyImpl.createIsolate() { |
19 Proxy isolate = new Proxy.forIsolate(new Mint$Dispatcher$Isolate()); | 19 Proxy isolate = new Proxy.forIsolate(new Mint$Dispatcher$Isolate()); |
20 return new Mint$ProxyImpl.forIsolate(isolate); | 20 return new Mint$ProxyImpl.forIsolate(isolate); |
21 } | 21 } |
22 factory Mint$ProxyImpl.localProxy(Mint obj) { | 22 factory Mint$ProxyImpl.localProxy(Mint obj) { |
23 return new Mint$ProxyImpl(new Promise<SendPort>.fromValue(Dispatcher.serve(n
ew Mint$Dispatcher(obj)))); | 23 return new Mint$ProxyImpl(new Promise<SendPort>.fromValue(Dispatcher.serve(n
ew Mint$Dispatcher(obj)))); |
24 } | 24 } |
25 | 25 |
(...skipping 28 matching lines...) Expand all Loading... |
54 Mint thing = new Mint(); | 54 Mint thing = new Mint(); |
55 SendPort port = Dispatcher.serve(new Mint$Dispatcher(thing)); | 55 SendPort port = Dispatcher.serve(new Mint$Dispatcher(thing)); |
56 Proxy proxy = new Proxy.forPort(replyTo); | 56 Proxy proxy = new Proxy.forPort(replyTo); |
57 proxy.send([port]); | 57 proxy.send([port]); |
58 }); | 58 }); |
59 } | 59 } |
60 } | 60 } |
61 | 61 |
62 /* class = Purse (tests/stub-generator/src/MintMakerPromiseWithStubsTest.dart/Mi
ntMakerPromiseWithStubsTest.dart: 17) */ | 62 /* class = Purse (tests/stub-generator/src/MintMakerPromiseWithStubsTest.dart/Mi
ntMakerPromiseWithStubsTest.dart: 17) */ |
63 | 63 |
64 interface Purse$Proxy extends Proxy { | 64 interface Purse$Proxy { |
65 Promise<int> queryBalance(); | 65 Promise<int> queryBalance(); |
66 | 66 |
67 Purse$Proxy sproutPurse(); | 67 Purse$Proxy sproutPurse(); |
68 | 68 |
69 Promise<int> deposit(int amount, Purse$Proxy source); | 69 Promise<int> deposit(int amount, Purse$Proxy source); |
70 } | 70 } |
71 | 71 |
72 class Purse$ProxyImpl extends ProxyImpl implements Purse$Proxy { | 72 class Purse$ProxyImpl extends Proxy implements Purse$Proxy { |
73 Purse$ProxyImpl(Promise<SendPort> port) : super.forReply(port) { } | 73 Purse$ProxyImpl(Promise<SendPort> port) : super.forReply(port) { } |
74 Purse$ProxyImpl.forIsolate(Proxy isolate) : super.forReply(isolate.call([null]
)) { } | 74 Purse$ProxyImpl.forIsolate(Proxy isolate) : super.forReply(isolate.call([null]
)) { } |
75 factory Purse$ProxyImpl.createIsolate() { | 75 factory Purse$ProxyImpl.createIsolate() { |
76 Proxy isolate = new Proxy.forIsolate(new Purse$Dispatcher$Isolate()); | 76 Proxy isolate = new Proxy.forIsolate(new Purse$Dispatcher$Isolate()); |
77 return new Purse$ProxyImpl.forIsolate(isolate); | 77 return new Purse$ProxyImpl.forIsolate(isolate); |
78 } | 78 } |
79 factory Purse$ProxyImpl.localProxy(Purse obj) { | 79 factory Purse$ProxyImpl.localProxy(Purse obj) { |
80 return new Purse$ProxyImpl(new Promise<SendPort>.fromValue(Dispatcher.serve(
new Purse$Dispatcher(obj)))); | 80 return new Purse$ProxyImpl(new Promise<SendPort>.fromValue(Dispatcher.serve(
new Purse$Dispatcher(obj)))); |
81 } | 81 } |
82 | 82 |
83 Promise<int> queryBalance() { | 83 Promise<int> queryBalance() { |
84 return this.call(["queryBalance"]); | 84 return this.call(["queryBalance"]); |
85 } | 85 } |
86 | 86 |
87 Purse$Proxy sproutPurse() { | 87 Purse$Proxy sproutPurse() { |
88 return new Purse$ProxyImpl(this.call(["sproutPurse"])); | 88 return new Purse$ProxyImpl(this.call(["sproutPurse"])); |
89 } | 89 } |
90 | 90 |
91 Promise<int> deposit(int amount, Purse$Proxy source) { | 91 Promise<int> deposit(int amount, Purse$Proxy source) { |
92 return new PromiseProxy<int>(this.call(["deposit", amount, source])); | 92 return this.call(["deposit", amount, source]); |
93 } | 93 } |
94 } | 94 } |
95 | 95 |
96 class Purse$Dispatcher extends Dispatcher<Purse> { | 96 class Purse$Dispatcher extends Dispatcher<Purse> { |
97 Purse$Dispatcher(Purse thing) : super(thing) { } | 97 Purse$Dispatcher(Purse thing) : super(thing) { } |
98 | 98 |
99 void process(var message, void reply(var response)) { | 99 void process(var message, void reply(var response)) { |
100 String command = message[0]; | 100 String command = message[0]; |
101 if (command == "Purse") { | 101 if (command == "Purse") { |
102 } else if (command == "queryBalance") { | 102 } else if (command == "queryBalance") { |
103 int queryBalance = target.queryBalance(); | 103 int queryBalance = target.queryBalance(); |
104 reply(queryBalance); | 104 reply(queryBalance); |
105 } else if (command == "sproutPurse") { | 105 } else if (command == "sproutPurse") { |
106 Purse sproutPurse = target.sproutPurse(); | 106 Purse sproutPurse = target.sproutPurse(); |
107 SendPort port = Dispatcher.serve(new Purse$Dispatcher(sproutPurse)); | 107 SendPort port = Dispatcher.serve(new Purse$Dispatcher(sproutPurse)); |
108 reply(port); | 108 reply(port); |
109 } else if (command == "deposit") { | 109 } else if (command == "deposit") { |
110 int amount = message[1]; | 110 int amount = message[1]; |
111 List<Promise<SendPort>> promises = new List<Promise<SendPort>>(); | 111 Purse$Proxy source = new Purse$ProxyImpl(new Promise<SendPort>.fromValue(m
essage[2])); |
112 promises.add(new PromiseProxy<SendPort>(new Promise<SendPort>.fromValue(me
ssage[2]))); | |
113 Purse$Proxy source = new Purse$ProxyImpl(promises[0]); | |
114 Promise<int> deposit = target.deposit(amount, source); | 112 Promise<int> deposit = target.deposit(amount, source); |
115 reply(deposit); | 113 reply(deposit); |
116 } else { | 114 } else { |
117 // TODO(kasperl,benl): Somehow throw an exception instead. | 115 // TODO(kasperl,benl): Somehow throw an exception instead. |
118 reply("Exception: command '" + command + "' not understood by Purse."); | 116 reply("Exception: command '" + command + "' not understood by Purse."); |
119 } | 117 } |
120 } | 118 } |
121 } | 119 } |
122 | 120 |
123 class Purse$Dispatcher$Isolate extends Isolate { | 121 class Purse$Dispatcher$Isolate extends Isolate { |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
245 expect.succeeded(); | 243 expect.succeeded(); |
246 print("##DONE##"); | 244 print("##DONE##"); |
247 }); | 245 }); |
248 } | 246 } |
249 | 247 |
250 } | 248 } |
251 | 249 |
252 main() { | 250 main() { |
253 runTests([MintMakerPromiseWithStubsTest.testMain]); | 251 runTests([MintMakerPromiseWithStubsTest.testMain]); |
254 } | 252 } |
OLD | NEW |