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

Side by Side Diff: runtime/bin/vmservice/message.dart

Issue 112223002: WebSocket client for VM service (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years 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
OLDNEW
(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 part of vmservice;
6
7 class Message {
8 final Completer _completer = new Completer.sync();
9 bool get completed => _completer.isCompleted;
10 Future get future => _completer.future;
turnidge 2013/12/11 17:56:07 I found myself looking for a less generic name her
Cutch 2013/12/12 22:37:42 I think we can do this: Future<String> response;
11 /// Path.
12 final List<String> path = new List<String>();
13 /// Options.
14 final Map<String, String> options = new Map<String, String>();
15
16 Message.fromUri(Uri uri) {
17 var split = uri.path.split('/');
18 if (split.length == 0) {
19 setErrorResponse('Invalid uri: $uri.');
20 return;
21 }
22 for (int i = 0; i < split.length; i++) {
23 var pathSegment = split[i];
24 if (pathSegment == '') {
turnidge 2013/12/11 17:56:07 Does uri parsing often yield these empty path segm
Cutch 2013/12/12 22:37:42 Splitting the path on '/' yields many empty string
25 continue;
26 }
27 path.add(pathSegment);
28 }
29 options.addAll(uri.queryParameters);
30 }
31
32 Message.fromMap(Map map) {
33 if (map['path'] != null) {
34 path.addAll(map['path']);
35 }
36 if (map['options'] != null) {
37 options.addAll(map['options']);
38 }
39 }
40
41 Map toJson() {
42 return {
43 'path': path,
44 'options': options
45 };
46 }
47
48 Future send(SendPort sendPort) {
turnidge 2013/12/11 17:56:07 What do you think of making this return Future<Str
Cutch 2013/12/12 22:37:42 Done.
49 final receivePort = new RawReceivePort();
50 receivePort.handler = (value) {
51 receivePort.close();
52 if (value is Exception) {
53 _completer.completeError(value);
54 } else {
55 _completer.complete(value);
56 }
57 };
58 var keys = options.keys.toList();
59 var values = options.values.toList();
60 var request = [path, keys, values];
61 sendServiceMessage(sendPort, receivePort, request);
62 return _completer.future;
63 }
64
65 void setResponse(String response) {
66 _completer.complete(response);
67 }
68
69 void setErrorResponse(String error) {
70 _completer.complete(JSON.encode({
71 'type': 'Error',
72 'msg': error,
73 'path': path,
74 'options': options
75 }));
76 }
77 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698