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 part of app; | 5 part of app; |
6 | 6 |
7 /// The observatory application. Instances of this are created and owned | 7 /// The observatory application. Instances of this are created and owned |
8 /// by the observatory_application custom element. | 8 /// by the observatory_application custom element. |
9 class ObservatoryApplication extends Observable { | 9 class ObservatoryApplication extends Observable { |
10 static ObservatoryApplication app; | 10 static ObservatoryApplication app; |
11 final _pageRegistry = new List<Page>(); | 11 final _pageRegistry = new List<Page>(); |
12 LocationManager _locationManager; | 12 LocationManager _locationManager; |
13 LocationManager get locationManager => _locationManager; | 13 LocationManager get locationManager => _locationManager; |
14 @observable Page currentPage; | 14 @observable Page currentPage; |
15 VM _vm; | 15 VM _vm; |
16 VM get vm => _vm; | 16 VM get vm => _vm; |
17 set vm(VM vm) { | 17 set vm(VM vm) { |
18 if (_vm == vm) { | 18 if (_vm == vm) { |
19 // Do nothing. | 19 // Do nothing. |
20 return; | 20 return; |
21 } | 21 } |
22 if (_vm != null) { | 22 if (_vm != null) { |
23 // Disconnect from current VM. | 23 // Disconnect from current VM. |
24 notifications.clear(); | 24 notifications.clear(); |
25 _vm.disconnect(); | 25 _vm.disconnect(); |
26 } | 26 } |
27 if (vm != null) { | 27 if (vm != null) { |
28 Logger.root.info('Registering new VM callbacks'); | 28 Logger.root.info('Registering new VM callbacks'); |
29 vm.onConnect.then(_vmConnected); | 29 |
30 vm.onDisconnect.then(_vmDisconnected); | 30 vm.onConnect.then((_) { |
| 31 if (vm is WebSocketVM) { |
| 32 targets.add(vm.target); |
| 33 } |
| 34 _removeDisconnectEvents(); |
| 35 }); |
| 36 |
| 37 vm.onDisconnect.then((String reason) { |
| 38 if (this.vm != vm) { |
| 39 // This disconnect event occured *after* a new VM was installed. |
| 40 return; |
| 41 } |
| 42 notifications.add(new ServiceEvent.connectionClosed(reason)); |
| 43 }); |
| 44 |
31 vm.errors.stream.listen(_onError); | 45 vm.errors.stream.listen(_onError); |
32 vm.events.stream.listen(_onEvent); | 46 vm.events.stream.listen(_onEvent); |
33 vm.exceptions.stream.listen(_onException); | 47 vm.exceptions.stream.listen(_onException); |
34 } | 48 } |
35 _vm = vm; | 49 _vm = vm; |
36 } | 50 } |
37 final TargetManager targets; | 51 final TargetManager targets; |
38 @reflectable final ObservatoryApplicationElement rootElement; | 52 @reflectable final ObservatoryApplicationElement rootElement; |
39 | 53 |
40 TraceViewElement _traceView = null; | 54 TraceViewElement _traceView = null; |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
123 _visit(Uri.parse('error/'), null); | 137 _visit(Uri.parse('error/'), null); |
124 } | 138 } |
125 | 139 |
126 void _onException(ServiceException exception) { | 140 void _onException(ServiceException exception) { |
127 lastErrorOrException = exception; | 141 lastErrorOrException = exception; |
128 if (exception.kind == 'NetworkException') { | 142 if (exception.kind == 'NetworkException') { |
129 // Got a network exception, visit the vm-connect page. | 143 // Got a network exception, visit the vm-connect page. |
130 this.vm = null; | 144 this.vm = null; |
131 locationManager.go(locationManager.makeLink('/vm-connect/')); | 145 locationManager.go(locationManager.makeLink('/vm-connect/')); |
132 } else { | 146 } else { |
133 _visit(Uri.parse('error/'), null); | 147 _visit(Uri.parse('error/'), {}); |
134 } | 148 } |
135 } | 149 } |
136 | 150 |
137 void _visit(Uri uri, Map internalArguments) { | 151 void _visit(Uri uri, Map internalArguments) { |
138 if (internalArguments['trace'] != null) { | 152 if (internalArguments['trace'] != null) { |
139 var traceArg = internalArguments['trace']; | 153 var traceArg = internalArguments['trace']; |
140 if (traceArg == 'on') { | 154 if (traceArg == 'on') { |
141 Tracer.start(); | 155 Tracer.start(); |
142 } else if (traceArg == 'off') { | 156 } else if (traceArg == 'off') { |
143 Tracer.stop(); | 157 Tracer.stop(); |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
193 | 207 |
194 ObservatoryApplication(this.rootElement) : | 208 ObservatoryApplication(this.rootElement) : |
195 targets = new TargetManager() { | 209 targets = new TargetManager() { |
196 _locationManager = new LocationManager(this); | 210 _locationManager = new LocationManager(this); |
197 vm = new WebSocketVM(targets.defaultTarget); | 211 vm = new WebSocketVM(targets.defaultTarget); |
198 _initOnce(); | 212 _initOnce(); |
199 } | 213 } |
200 | 214 |
201 void _removeDisconnectEvents() { | 215 void _removeDisconnectEvents() { |
202 notifications.removeWhere((oldEvent) { | 216 notifications.removeWhere((oldEvent) { |
203 return (oldEvent.eventType == ServiceEvent.kVMDisconnected); | 217 return (oldEvent.eventType == ServiceEvent.kConnectionClosed); |
204 }); | 218 }); |
205 } | 219 } |
206 | |
207 _vmConnected(VM vm) { | |
208 if (vm is WebSocketVM) { | |
209 targets.add(vm.target); | |
210 } | |
211 _removeDisconnectEvents(); | |
212 } | |
213 | |
214 _vmDisconnected(VM vm) { | |
215 if (this.vm != vm) { | |
216 // This disconnect event occured *after* a new VM was installed. | |
217 return; | |
218 } | |
219 this.vm = null; | |
220 notifications.add(new ServiceEvent.vmDisconencted()); | |
221 } | |
222 } | 220 } |
OLD | NEW |