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

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

Issue 2980733003: Introduced support for external services registration in the ServiceProtocol (Closed)
Patch Set: Address comments 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
« no previous file with comments | « runtime/vm/service_event.cc ('k') | sdk/lib/vmservice/message.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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.
« no previous file with comments | « runtime/vm/service_event.cc ('k') | sdk/lib/vmservice/message.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698