| Index: sdk/lib/vmservice/client.dart
|
| diff --git a/sdk/lib/vmservice/client.dart b/sdk/lib/vmservice/client.dart
|
| index 4eb7460a60a2645f4ba4c22edb4f59e97d280e77..3f99607a64c22c7fd9f30b8f80bc6a79d42faad5 100644
|
| --- a/sdk/lib/vmservice/client.dart
|
| +++ b/sdk/lib/vmservice/client.dart
|
| @@ -4,12 +4,27 @@
|
|
|
| part of dart._vmservice;
|
|
|
| +typedef void ClientServiceHandle(Message response);
|
| +
|
| // A service client.
|
| abstract class Client {
|
| final VMService service;
|
| final bool sendEvents;
|
| +
|
| + /// A set streamIds which describes the streams the client is connected to
|
| final Set<String> streams = new Set<String>();
|
|
|
| + /// Services registered and their aliases
|
| + /// key: service
|
| + /// value: alias
|
| + final Map<String, String> services = new Map<String, String>();
|
| +
|
| + /// Callbacks registered for service invocations set to the client
|
| + /// key: RPC id used for the request
|
| + /// value: callback that should be invoked
|
| + final Map<String, ClientServiceHandle> serviceHandles =
|
| + new Map<String, ClientServiceHandle>();
|
| +
|
| Client(this.service, {bool sendEvents: true}) : this.sendEvents = sendEvents {
|
| service._addClient(this);
|
| }
|
| @@ -22,18 +37,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.
|
|
|