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

Side by Side Diff: sdk/lib/developer/service.dart

Issue 2438613002: Provide an API to dart:developer to control the web server hosting the Service Protocol (Closed)
Patch Set: updated CHANGELOG.md Created 4 years, 2 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
OLDNEW
(Empty)
1 // Copyright (c) 2016, 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 dart.developer;
6
7 /// Information about the service protocol.
8 class ServiceProtocolInfo {
9 /// The major version of the protocol.
rmacnak 2016/10/20 17:12:31 If the running Dart environment does not support t
Cutch 2016/10/20 23:31:51 Done.
10 final int majorVersion = _getServiceMajorVersion();
11 /// The minor version of the protocol.
12 final int minorVersion = _getServiceMinorVersion();
13 /// The Uri to access the service. If the web server is not running, this
14 /// will be null.
15 final Uri serverUri;
16
17 ServiceProtocolInfo(this.serverUri);
18
19 String toString() {
20 if (serverUri != null) {
21 return 'Dart VM Service Protocol v$majorVersion.$minorVersion '
22 'listening on $serverUri';
23 } else {
24 return 'Dart VM Service Protocol v$majorVersion.$minorVersion';
25 }
26 }
27 }
28
29 /// Access information about the service protocol and control the web server.
30 class Service {
31 /// Get information about the service protocol.
32 static Future<ServiceProtocolInfo> getInfo() async {
33 // Port to receive response from service isolate.
34 final RawReceivePort receivePort = new RawReceivePort();
35 final Completer<Uri> uriCompleter = new Completer<Uri>();
36 receivePort.handler = (Uri uri) => uriCompleter.complete(uri);
37 // Request the information from the service isolate.
38 _getServerInfo(receivePort.sendPort);
39 // Await the response from the service isolate.
40 Uri uri = await uriCompleter.future;
41 // Close the port.
42 receivePort.close();
43 return new ServiceProtocolInfo(uri);
44 }
45
46 /// Control the web server that the service protocol is accessed through.
47 static Future<ServiceProtocolInfo> controlWebServer(
48 {bool enable: false}) async {
49 if (enable is! bool) {
50 throw new ArgumentError.value(enable,
51 'enable',
52 'Must be a bool');
53 }
54 // Port to receive response from service isolate.
55 final RawReceivePort receivePort = new RawReceivePort();
56 final Completer<Uri> uriCompleter = new Completer<Uri>();
57 receivePort.handler = (Uri uri) => uriCompleter.complete(uri);
58 // Request the information from the service isolate.
59 _webServerControl(receivePort.sendPort, enable);
60 // Await the response from the service isolate.
61 Uri uri = await uriCompleter.future;
62 // Close the port.
63 receivePort.close();
64 return new ServiceProtocolInfo(uri);
65 }
66 }
67
68 /// [sp] will receive a Uri or null.
69 external void _getServerInfo(SendPort sp);
70
71 /// [sp] will receive a Uri or null.
72 external void _webServerControl(SendPort sp, bool enable);
73
74 /// Returns the major version of the service protocol.
75 external int _getServiceMajorVersion();
76
77 /// Returns the minor version of the service protocol.
78 external int _getServiceMinorVersion();
79
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698