| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // BSD-style license that can be found in the LICENSE file. | |
| 4 | |
| 5 library dart_controller_service_isolate; | |
| 6 | |
| 7 import 'dart:async'; | |
| 8 import 'dart:convert'; | |
| 9 import 'dart:io'; | |
| 10 import 'dart:isolate'; | |
| 11 import 'dart:_vmservice'; | |
| 12 | |
| 13 part 'loader.dart'; | |
| 14 part 'server.dart'; | |
| 15 | |
| 16 // The TCP ip/port that the HTTP server listens on. | |
| 17 int _port; | |
| 18 String _ip; | |
| 19 // Should the HTTP server auto start? | |
| 20 bool _autoStart; | |
| 21 | |
| 22 // HTTP server. | |
| 23 Server server; | |
| 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 } | |
| 35 | |
| 36 _onShutdown() { | |
| 37 if (server != null) { | |
| 38 server.close(true).catchError((e, st) { | |
| 39 print(e); | |
| 40 }).whenComplete(_shutdown); | |
| 41 } else { | |
| 42 _shutdown(); | |
| 43 } | |
| 44 } | |
| 45 | |
| 46 void _bootServer() { | |
| 47 // Lazily create service. | |
| 48 var service = new VMService(); | |
| 49 service.onShutdown = _onShutdown; | |
| 50 // Lazily create server. | |
| 51 server = new Server(service, _ip, _port); | |
| 52 } | |
| 53 | |
| 54 main() { | |
| 55 if (_autoStart) { | |
| 56 _bootServer(); | |
| 57 if (server != null) { | |
| 58 server.startup(); | |
| 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(() {}); | |
| 63 } | |
| 64 scriptLoadPort.handler = _processLoadRequest; | |
| 65 return scriptLoadPort; | |
| 66 } | |
| 67 | |
| 68 _shutdown() native "ServiceIsolate_Shutdown"; | |
| OLD | NEW |