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

Unified 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: CHANGELOG.md merge and fatal error Created 4 years, 1 month 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
« no previous file with comments | « sdk/lib/developer/developer_sources.gypi ('k') | sdk/lib/vmservice/constants.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sdk/lib/developer/service.dart
diff --git a/sdk/lib/developer/service.dart b/sdk/lib/developer/service.dart
new file mode 100644
index 0000000000000000000000000000000000000000..2934afe41f09ee5c592eafbc60cee3e87181e8eb
--- /dev/null
+++ b/sdk/lib/developer/service.dart
@@ -0,0 +1,81 @@
+// Copyright (c) 2016, 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 dart.developer;
+
+/// Information about the service protocol.
+class ServiceProtocolInfo {
+ /// The major version of the protocol. If the running Dart environment does
+ /// not support the service protocol, this is 0.
+ final int majorVersion = _getServiceMajorVersion();
+ /// The minor version of the protocol. If the running Dart environment does
+ /// not support the service protocol, this is 0.
+ final int minorVersion = _getServiceMinorVersion();
+ /// The Uri to access the service. If the web server is not running, this
+ /// will be null.
+ final Uri serverUri;
+
+ ServiceProtocolInfo(this.serverUri);
+
+ String toString() {
+ if (serverUri != null) {
+ return 'Dart VM Service Protocol v$majorVersion.$minorVersion '
+ 'listening on $serverUri';
+ } else {
+ return 'Dart VM Service Protocol v$majorVersion.$minorVersion';
+ }
+ }
+}
+
+/// Access information about the service protocol and control the web server.
+class Service {
+ /// Get information about the service protocol.
+ static Future<ServiceProtocolInfo> getInfo() async {
+ // Port to receive response from service isolate.
+ final RawReceivePort receivePort = new RawReceivePort();
+ final Completer<Uri> uriCompleter = new Completer<Uri>();
+ receivePort.handler = (Uri uri) => uriCompleter.complete(uri);
+ // Request the information from the service isolate.
+ _getServerInfo(receivePort.sendPort);
+ // Await the response from the service isolate.
+ Uri uri = await uriCompleter.future;
+ // Close the port.
+ receivePort.close();
+ return new ServiceProtocolInfo(uri);
+ }
+
+ /// Control the web server that the service protocol is accessed through.
+ static Future<ServiceProtocolInfo> controlWebServer(
+ {bool enable: false}) async {
+ if (enable is! bool) {
+ throw new ArgumentError.value(enable,
+ 'enable',
+ 'Must be a bool');
+ }
+ // Port to receive response from service isolate.
+ final RawReceivePort receivePort = new RawReceivePort();
+ final Completer<Uri> uriCompleter = new Completer<Uri>();
+ receivePort.handler = (Uri uri) => uriCompleter.complete(uri);
+ // Request the information from the service isolate.
+ _webServerControl(receivePort.sendPort, enable);
+ // Await the response from the service isolate.
+ Uri uri = await uriCompleter.future;
+ // Close the port.
+ receivePort.close();
+ return new ServiceProtocolInfo(uri);
+ }
+}
+
+/// [sp] will receive a Uri or null.
+external void _getServerInfo(SendPort sp);
+
+/// [sp] will receive a Uri or null.
+external void _webServerControl(SendPort sp, bool enable);
+
+/// Returns the major version of the service protocol.
+external int _getServiceMajorVersion();
+
+/// Returns the minor version of the service protocol.
+external int _getServiceMinorVersion();
+
« no previous file with comments | « sdk/lib/developer/developer_sources.gypi ('k') | sdk/lib/vmservice/constants.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698