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. |