Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(42)

Side by Side Diff: runtime/vm/service/client.dart

Issue 1077823003: Some cleanups in the code that posts results to service clients. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 5 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « runtime/vm/service.cc ('k') | runtime/vm/service/constants.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 vmservice; 5 part of vmservice;
6 6
7 // A service client. 7 // A service client.
8 abstract class Client { 8 abstract class Client {
9 /// A port for receipt of asynchronous service events.
10 final RawReceivePort eventPort = new RawReceivePort();
11 final VMService service; 9 final VMService service;
10 final bool sendEvents;
12 11
13 Client(this.service) { 12 Client(this.service, { bool sendEvents: true })
14 eventPort.handler = (response) { 13 : this.sendEvents = sendEvents {
15 post(null, response);
16 };
17 service._addClient(this); 14 service._addClient(this);
18 } 15 }
19 16
20 /// When implementing, call [close] when the network connection closes. 17 /// When implementing, call [close] when the network connection closes.
21 void close() { 18 void close() {
22 eventPort.close();
23 service._removeClient(this); 19 service._removeClient(this);
24 } 20 }
25 21
26 /// Call to process a message. Response will be posted with 'seq'. 22 /// Call to process a message. Response will be posted with 'seq'.
27 void onMessage(var seq, Message message) { 23 void onMessage(var seq, Message message) {
28 try { 24 try {
29 // Send message to service. 25 // Send message to service.
30 service.route(message).then((response) { 26 service.route(message).then((response) {
31 // Call post when the response arrives. 27 // Call post when the response arrives.
32 post(seq, response); 28 post(seq, response);
33 }); 29 });
34 } catch (e, st) { 30 } catch (e, st) {
35 message.setErrorResponse('Internal error: $e'); 31 message.setErrorResponse('Internal error: $e');
36 post(seq, message.response); 32 post(seq, message.response);
37 } 33 }
38 } 34 }
39 35
40 /// When implementing, responsible for sending [response] to the client. 36 // Sends a result to the client. Implemented in subclasses.
41 void post(var seq, dynamic response); 37 void post(var seq, dynamic result);
42 38
43 dynamic toJson() { 39 dynamic toJson() {
44 return { 40 return {
45 }; 41 };
46 } 42 }
47 } 43 }
OLDNEW
« no previous file with comments | « runtime/vm/service.cc ('k') | runtime/vm/service/constants.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698