blob: b87218abfaf0f725320667545a2371af716524b4 [file] [log] [blame]
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'dart:async';
import 'package:mojo/application.dart';
import 'package:mojo/bindings.dart';
import 'package:mojo/core.dart';
import 'package:_mojo_for_test_only/test/pingpong_service.mojom.dart';
class PingPongServiceImpl implements PingPongService {
PingPongServiceStub _stub;
Application _application;
PingPongClientProxy _pingPongClient;
PingPongServiceImpl(this._application, MojoMessagePipeEndpoint endpoint) {
_stub = new PingPongServiceStub.fromEndpoint(endpoint, this);
}
PingPongServiceImpl.fromStub(this._stub) {
_stub.impl = this;
}
void setClient(ProxyBase proxyBase) {
assert(_pingPongClient == null);
_pingPongClient = proxyBase;
}
void ping(int pingValue) => _pingPongClient.ptr.pong(pingValue + 1);
// These methods are unimplemented; they merely throw on invocation.
dynamic pingTargetUrl(String url, int count, [Function responseFactory]) =>
throw "Unimplemented";
dynamic pingTargetService(
Object service, int count, [Function responseFactory]) =>
throw "Unimplemented";
void getPingPongService(Object service) {
new PingPongServiceImpl.fromStub(service);
}
void quit() {}
}
class PingPongApplication extends Application {
PingPongApplication.fromHandle(MojoHandle handle) : super.fromHandle(handle);
@override
void acceptConnection(String requestorUrl, String resolvedUrl,
ApplicationConnection connection) {
// Provide the service implemented by PingPongServiceImpl.
connection.provideService(PingPongService.serviceName,
(endpoint) => new PingPongServiceImpl(this, endpoint));
// No services are required from the remote end.
connection.remoteServiceProvider.close();
}
Future closeApplication() async {
await close();
MojoHandle.reportLeakedHandles();
}
}
main(List args, Object handleToken) {
MojoHandle appHandle = new MojoHandle(handleToken);
new PingPongApplication.fromHandle(appHandle);
}