blob: 5d32fb2bff9cfe9c2e5c760c64a058b2c69bdd52 [file] [log] [blame]
// Copyright 2014 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 'mojo:application';
import 'mojo:bindings';
import 'mojo:core';
import 'package:services/dart/test/echo_service.mojom.dart';
class EchoServiceImpl implements EchoService {
EchoServiceStub _stub;
Application _application;
EchoServiceImpl(Application application, MojoMessagePipeEndpoint endpoint)
: _application = application {
_stub = new EchoServiceStub.fromEndpoint(endpoint, impl: this);
}
echoString(String value, Function responseFactory) {
if (value == "quit") {
_stub.close();
}
return new Future.value(responseFactory(value));
}
}
class EchoApplication extends Application {
EchoApplication.fromHandle(MojoHandle handle) : super.fromHandle(handle);
@override
void acceptConnection(String requestorUrl, String resolvedUrl,
ApplicationConnection connection) {
connection.provideService(
EchoServiceName,
(endpoint) => new EchoServiceImpl(this, endpoint));
connection.listen();
}
}
main(List args) {
MojoHandle appHandle = new MojoHandle(args[0]);
String url = args[1];
new EchoApplication.fromHandle(appHandle);
}