| 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 dart._vmservice; | 5 part of dart._vmservice; |
| 6 | 6 |
| 7 // A service client. | 7 // A service client. |
| 8 abstract class Client { | 8 abstract class Client { |
| 9 final VMService service; | 9 final VMService service; |
| 10 final bool sendEvents; | 10 final bool sendEvents; |
| 11 final Set<String> streams = new Set<String>(); | 11 final Set<String> streams = new Set<String>(); |
| 12 | 12 |
| 13 Client(this.service, { bool sendEvents: true }) | 13 Client(this.service, {bool sendEvents: true}) : this.sendEvents = sendEvents { |
| 14 : this.sendEvents = sendEvents { | |
| 15 service._addClient(this); | 14 service._addClient(this); |
| 16 } | 15 } |
| 17 | 16 |
| 18 // Disconnects the client. | 17 // Disconnects the client. |
| 19 disconnect(); | 18 disconnect(); |
| 20 | 19 |
| 21 /// When implementing, call [close] when the network connection closes. | 20 /// When implementing, call [close] when the network connection closes. |
| 22 void close() { | 21 void close() { |
| 23 service._removeClient(this); | 22 service._removeClient(this); |
| 24 } | 23 } |
| 25 | 24 |
| 26 /// Call to process a message. Response will be posted with 'seq'. | 25 /// Call to process a message. Response will be posted with 'seq'. |
| 27 void onMessage(var seq, Message message) { | 26 void onMessage(var seq, Message message) { |
| 28 try { | 27 try { |
| 29 // Send message to service. | 28 // Send message to service. |
| 30 service.route(message).then((response) { | 29 service.route(message).then((response) { |
| 31 // Call post when the response arrives. | 30 // Call post when the response arrives. |
| 32 post(response); | 31 post(response); |
| 33 }); | 32 }); |
| 34 } catch (e, st) { | 33 } catch (e, st) { |
| 35 message.setErrorResponse( | 34 message.setErrorResponse(kInternalError, 'Unexpected exception:$e\n$st'); |
| 36 kInternalError, 'Unexpected exception:$e\n$st'); | |
| 37 post(message.response); | 35 post(message.response); |
| 38 } | 36 } |
| 39 } | 37 } |
| 40 | 38 |
| 41 // Sends a result to the client. Implemented in subclasses. | 39 // Sends a result to the client. Implemented in subclasses. |
| 42 void post(dynamic result); | 40 void post(dynamic result); |
| 43 | 41 |
| 44 dynamic toJson() { | 42 dynamic toJson() { |
| 45 return { | 43 return {}; |
| 46 }; | |
| 47 } | 44 } |
| 48 } | 45 } |
| OLD | NEW |