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(11927): Factor 'dart:io' dependency into separate library. |
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.ISOLATE_STARTUP_MESSAGE_ID: |
| 23 runningIsolates.isolateStartup(sp); |
| 24 break; |
| 25 case Constants.ISOLATE_SHUTDOWN_MESSAGE_ID: |
| 26 runningIsolates.isolateShutdown(sp); |
| 27 break; |
| 28 } |
| 29 } |
| 30 |
| 31 void messageHandler(message, SendPort replyTo) { |
| 32 if (message is List && message.length == 2) { |
| 33 controlMessageHandler(message[0], message[1]); |
| 34 } |
| 35 } |
| 36 |
| 37 VmService._internal() { |
| 38 port.receive(messageHandler); |
| 39 } |
| 40 |
| 41 factory VmService() { |
| 42 if (VmService._instance == null) { |
| 43 VmService._instance = new VmService._internal(); |
| 44 } |
| 45 return _instance; |
| 46 } |
16 } | 47 } |
17 | 48 |
18 | 49 void sendServiceMessage(SendPort sp, ReceivePort rp, Object m) |
19 main() { | 50 native "SendServiceMessage"; |
20 port.receive(messageHandler); | |
21 } | |
OLD | NEW |