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

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;
11
12 final List<String> path = new List<String>();
13 final Map<String, String> parameters = new Map<String, String>();
14
15 Message.fromUri(Uri uri) {
16 var split = uri.path.split('/');
17 if (split.length == 0) {
18 setErrorResponse('Invalid uri: $uri.');
19 return;
20 }
21 for (int i = 0; i < split.length; i++) {
22 var pathSegment = split[i];
23 if (pathSegment == '') {
24 continue;
25 }
26 path.add(pathSegment);
27 }
28 parameters.addAll(uri.queryParameters);
29 }
30
31 Message.fromMap(Map map) {
32 if (map['path'] != null) {
33 path.addAll(map['path']);
34 }
35 if (map['parameters'] != null) {
36 parameters.addAll(map['parameters']);
37 }
38 }
39
40 Map toJson() {
41 return {
42 'path': path,
43 'parameters': parameters
44 };
45 }
46
47 Future send(SendPort sendPort) {
48 final receivePort = new RawReceivePort();
49 receivePort.handler = (value) {
50 receivePort.close();
51 if (value is Exception) {
52 _completer.completeError(value);
53 } else {
54 _completer.complete(value);
55 }
56 };
57 var keys = parameters.keys.toList();
58 var values = parameters.values.toList();
59 var request = [path, keys, values];
60 sendServiceMessage(sendPort, receivePort, request);
61 return _completer.future;
62 }
63
64 void setResponse(String response) {
65 _completer.complete(response);
66 }
67
68 void setErrorResponse(String error) {
69 _completer.complete(JSON.encode({
70 'type': 'Error',
71 'msg': error,
72 'path': path,
73 'parameters': parameters
74 }));
75 }
76 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698