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

Unified Diff: sdk/lib/vmservice/client.dart

Issue 2980733003: Introduced support for external services registration in the ServiceProtocol (Closed)
Patch Set: Fix checked mode exceptions Created 3 years, 5 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 side-by-side diff with in-line comments
Download patch
Index: sdk/lib/vmservice/client.dart
diff --git a/sdk/lib/vmservice/client.dart b/sdk/lib/vmservice/client.dart
index 4eb7460a60a2645f4ba4c22edb4f59e97d280e77..cfe8a33aba0177fbe2e091a3423fdf8d074d6692 100644
--- a/sdk/lib/vmservice/client.dart
+++ b/sdk/lib/vmservice/client.dart
@@ -4,11 +4,16 @@
part of dart._vmservice;
+typedef void ClientServiceHandle(Message response);
+
// A service client.
abstract class Client {
final VMService service;
final bool sendEvents;
final Set<String> streams = new Set<String>();
+ final Map<String, String> services = new Map<String, String>();
+ final Map<String, ClientServiceHandle> serviceHandles =
+ new Map<String, ClientServiceHandle>();
Client(this.service, {bool sendEvents: true}) : this.sendEvents = sendEvents {
service._addClient(this);
@@ -22,18 +27,23 @@ abstract class Client {
service._removeClient(this);
}
- /// Call to process a message. Response will be posted with 'seq'.
- void onMessage(var seq, Message message) {
- try {
- // Send message to service.
- service.route(message).then((response) {
- // Call post when the response arrives.
- post(response);
- });
- } catch (e, st) {
- message.setErrorResponse(kInternalError, 'Unexpected exception:$e\n$st');
- post(message.response);
- }
+ /// Call to process a request. Response will be posted with 'seq'.
+ void onRequest(Message message) {
+ // In JSON-RPC 2.0 messages with and id are Request and must be answered
+ // http://www.jsonrpc.org/specification#notification
+ service.routeRequest(message).then((response) => post(response));
+ }
+
+ void onResponse(Message message) {
+ service.routeResponse(message);
+ }
+
+ /// Call to process a notification. Response will not be posted.
+ void onNotification(Message message) {
+ // In JSON-RPC 2.0 messages without an id are Notification
+ // and should not be answered
+ // http://www.jsonrpc.org/specification#notification
+ service.routeRequest(message);
}
// Sends a result to the client. Implemented in subclasses.

Powered by Google App Engine
This is Rietveld 408576698