blob: 7e0fdd8a78e36b03d71f8238725dabf111956dbd [file] [log] [blame]
// Copyright (c) 2013, 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._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 {
// Disconnects the client.
/// When implementing, call [close] when the network connection closes.
void close() {
/// 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
void onResponse(Message 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
// Sends a result to the client. Implemented in subclasses.
void post(Response result);
dynamic toJson() {
return {};