| 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 dart_controller_service_isolate; | 5 library dart_controller_service_isolate; |
| 6 | 6 |
| 7 import 'dart:async'; | 7 import 'dart:async'; |
| 8 import 'dart:convert'; | 8 import 'dart:convert'; |
| 9 import 'dart:io'; | 9 import 'dart:io'; |
| 10 import 'dart:isolate'; | 10 import 'dart:isolate'; |
| 11 import 'dart:_vmservice'; | 11 import 'dart:_vmservice'; |
| 12 | 12 |
| 13 part 'loader.dart'; | 13 part 'loader.dart'; |
| 14 part 'server.dart'; | 14 part 'server.dart'; |
| 15 | 15 |
| 16 // The TCP ip/port that the HTTP server listens on. | 16 // The TCP ip/port that the HTTP server listens on. |
| 17 int _port; | 17 int _port; |
| 18 String _ip; | 18 String _ip; |
| 19 // Should the HTTP server auto start? | 19 // Should the HTTP server auto start? |
| 20 bool _autoStart; | 20 bool _autoStart; |
| 21 | 21 |
| 22 // HTTP server. | 22 // HTTP server. |
| 23 Server server; | 23 Server server; |
| 24 Map<String, Asset> assets; | 24 Map<String, Asset> _assets; |
| 25 Map<String, Asset> get assets { |
| 26 if (_assets == null) { |
| 27 try { |
| 28 _assets = Asset.request(); |
| 29 } catch (e) { |
| 30 print('Could not load Observatory assets: $e'); |
| 31 } |
| 32 } |
| 33 return _assets; |
| 34 } |
| 25 | 35 |
| 26 _onShutdown() { | 36 _onShutdown() { |
| 27 if (server != null) { | 37 if (server != null) { |
| 28 server.close(true).catchError((e, st) { | 38 server.close(true).catchError((e, st) { |
| 29 print(e); | 39 print(e); |
| 30 }).whenComplete(_shutdown); | 40 }).whenComplete(_shutdown); |
| 31 } else { | 41 } else { |
| 32 _shutdown(); | 42 _shutdown(); |
| 33 } | 43 } |
| 34 } | 44 } |
| 35 | 45 |
| 36 void _bootServer() { | 46 void _bootServer() { |
| 37 try { | |
| 38 assets = Asset.request(); | |
| 39 } catch (e) { | |
| 40 print('Could not load Observatory assets: $e'); | |
| 41 } | |
| 42 // Lazily create service. | 47 // Lazily create service. |
| 43 var service = new VMService(); | 48 var service = new VMService(); |
| 44 service.onShutdown = _onShutdown; | 49 service.onShutdown = _onShutdown; |
| 45 // Lazily create server. | 50 // Lazily create server. |
| 46 server = new Server(service, _ip, _port); | 51 server = new Server(service, _ip, _port); |
| 47 } | 52 } |
| 48 | 53 |
| 49 main() { | 54 main() { |
| 50 if (_autoStart) { | 55 if (_autoStart) { |
| 51 _bootServer(); | 56 _bootServer(); |
| 52 if (server != null) { | 57 if (server != null) { |
| 53 server.startup(); | 58 server.startup(); |
| 54 } | 59 } |
| 60 // It's just here to push an event on the event loop so that we invoke the |
| 61 // scheduled microtasks. |
| 62 Timer.run(() {}); |
| 55 } | 63 } |
| 56 scriptLoadPort.handler = _processLoadRequest; | 64 scriptLoadPort.handler = _processLoadRequest; |
| 57 // It's just here to push an event on the event loop so that we invoke the | |
| 58 // scheduled microtasks. | |
| 59 Timer.run(() {}); | |
| 60 return scriptLoadPort; | 65 return scriptLoadPort; |
| 61 } | 66 } |
| 62 | 67 |
| 63 _shutdown() native "ServiceIsolate_Shutdown"; | 68 _shutdown() native "ServiceIsolate_Shutdown"; |
| OLD | NEW |