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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: runtime/bin/vmservice/message.dart
diff --git a/runtime/bin/vmservice/message.dart b/runtime/bin/vmservice/message.dart
new file mode 100644
index 0000000000000000000000000000000000000000..b6c551f99b19e405b2b037aecc2b0b8fb8bc5248
--- /dev/null
+++ b/runtime/bin/vmservice/message.dart
@@ -0,0 +1,77 @@
+// Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+
+part of vmservice;
+
+class Message {
+ final Completer _completer = new Completer.sync();
+ bool get completed => _completer.isCompleted;
+ 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;
+ /// Path.
+ final List<String> path = new List<String>();
+ /// Options.
+ final Map<String, String> options = new Map<String, String>();
+
+ Message.fromUri(Uri uri) {
+ var split = uri.path.split('/');
+ if (split.length == 0) {
+ setErrorResponse('Invalid uri: $uri.');
+ return;
+ }
+ for (int i = 0; i < split.length; i++) {
+ var pathSegment = split[i];
+ 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
+ continue;
+ }
+ path.add(pathSegment);
+ }
+ options.addAll(uri.queryParameters);
+ }
+
+ Message.fromMap(Map map) {
+ if (map['path'] != null) {
+ path.addAll(map['path']);
+ }
+ if (map['options'] != null) {
+ options.addAll(map['options']);
+ }
+ }
+
+ Map toJson() {
+ return {
+ 'path': path,
+ 'options': options
+ };
+ }
+
+ 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.
+ final receivePort = new RawReceivePort();
+ receivePort.handler = (value) {
+ receivePort.close();
+ if (value is Exception) {
+ _completer.completeError(value);
+ } else {
+ _completer.complete(value);
+ }
+ };
+ var keys = options.keys.toList();
+ var values = options.values.toList();
+ var request = [path, keys, values];
+ sendServiceMessage(sendPort, receivePort, request);
+ return _completer.future;
+ }
+
+ void setResponse(String response) {
+ _completer.complete(response);
+ }
+
+ void setErrorResponse(String error) {
+ _completer.complete(JSON.encode({
+ 'type': 'Error',
+ 'msg': error,
+ 'path': path,
+ 'options': options
+ }));
+ }
+}

Powered by Google App Engine
This is Rietveld 408576698