OLD | NEW |
---|---|
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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 library vmservice; | 5 library vmservice; |
6 | 6 |
7 import 'dart:async'; | 7 import 'dart:async'; |
8 import 'dart:json' as JSON; | 8 import 'dart:json' as JSON; |
9 // TODO(johnmccutchan): Factor 'dart:io' dependency into separate library. | |
siva
2013/07/19 17:41:16
Can we open an issue and add that issue number her
Cutch
2013/07/19 18:15:02
Done.
| |
9 import 'dart:io'; | 10 import 'dart:io'; |
10 import 'dart:isolate'; | 11 import 'dart:isolate'; |
11 import 'dart:typed_data'; | 12 import 'dart:typed_data'; |
12 import 'dart:utf' as UTF; | 13 import 'dart:utf' as UTF; |
13 | 14 |
14 | 15 |
15 void messageHandler(message, SendPort replyTo) { | 16 class VmService { |
17 static VmService _instance; | |
18 RunningIsolates runningIsolates = new RunningIsolates(); | |
19 | |
20 void controlMessageHandler(int code, SendPort sp) { | |
21 switch (code) { | |
22 case Constants.isolateStartupMessageId: | |
23 runningIsolates.isolateStartup(sp); | |
24 break; | |
25 case Constants.isolateShutdownMessageId: | |
26 runningIsolates.isolateShutdown(sp); | |
27 break; | |
28 } | |
29 } | |
30 | |
31 | |
32 void messageHandler(message, SendPort replyTo) { | |
33 if (message is List && message.length == 2) { | |
34 controlMessageHandler(message[0], message[1]); | |
35 } | |
36 } | |
37 | |
38 | |
39 VmService._internal() { | |
40 port.receive(messageHandler); | |
41 } | |
42 | |
43 | |
44 factory VmService() { | |
45 if (VmService._instance == null) { | |
46 VmService._instance = new VmService._internal(); | |
47 } | |
48 return _instance; | |
49 } | |
16 } | 50 } |
17 | 51 |
52 void sendServiceMessage(SendPort sp, ReceivePort rp, Object m) | |
53 native "SendServiceMessage"; | |
18 | 54 |
19 main() { | |
20 port.receive(messageHandler); | |
21 } | |
OLD | NEW |