1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "mojo/application/public/cpp/application_delegate.h"
6 #include "mojo/application/public/cpp/application_impl.h"
7 #include "mojo/application/public/cpp/application_runner.h"
8 #include "mojo/application/public/cpp/interface_factory.h"
9 #include "mojo/public/c/system/main.h"
10 #include "mojo/public/cpp/bindings/callback.h"
11 #include "mojo/public/cpp/bindings/interface_request.h"
12 #include "mojo/public/cpp/bindings/strong_binding.h"
13 #include "mojo/runner/test/pingable.mojom.h"
17 class PingableImpl
: public Pingable
{
19 PingableImpl(InterfaceRequest
<Pingable
> request
,
20 const std::string
& app_url
,
21 const std::string
& connection_url
)
22 : binding_(this, request
.Pass()),
24 connection_url_(connection_url
) {}
26 ~PingableImpl() override
{}
29 void Ping(const String
& message
,
30 const Callback
<void(String
, String
, String
)>& callback
) override
{
31 callback
.Run(app_url_
, connection_url_
, message
);
34 StrongBinding
<Pingable
> binding_
;
36 std::string connection_url_
;
39 class PingableApp
: public mojo::ApplicationDelegate
,
40 public mojo::InterfaceFactory
<Pingable
> {
43 ~PingableApp() override
{}
46 // ApplicationDelegate:
47 void Initialize(ApplicationImpl
* impl
) override
{ app_url_
= impl
->url(); }
49 bool ConfigureIncomingConnection(
50 mojo::ApplicationConnection
* connection
) override
{
51 connection
->AddService(this);
55 // InterfaceFactory<Pingable>:
56 void Create(mojo::ApplicationConnection
* connection
,
57 mojo::InterfaceRequest
<Pingable
> request
) override
{
58 new PingableImpl(request
.Pass(), app_url_
, connection
->GetConnectionURL());
66 MojoResult
MojoMain(MojoHandle shell_handle
) {
67 mojo::ApplicationRunner
runner(new mojo::PingableApp
);
68 return runner
.Run(shell_handle
);