OLD | NEW |
| (Empty) |
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. | |
4 | |
5 #include "mojo/public/c/system/main.h" | |
6 #include "mojo/public/cpp/application/application_delegate.h" | |
7 #include "mojo/public/cpp/application/application_impl.h" | |
8 #include "mojo/public/cpp/application/application_runner.h" | |
9 #include "mojo/public/cpp/application/interface_factory.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/shell/test/pingable.mojom.h" | |
14 | |
15 namespace mojo { | |
16 | |
17 class PingableImpl : public Pingable { | |
18 public: | |
19 PingableImpl(InterfaceRequest<Pingable> request, | |
20 const std::string& app_url, | |
21 const std::string& connection_url) | |
22 : binding_(this, request.Pass()), | |
23 app_url_(app_url), | |
24 connection_url_(connection_url) {} | |
25 | |
26 ~PingableImpl() override {} | |
27 | |
28 private: | |
29 void Ping(const String& message, | |
30 const Callback<void(String, String, String)>& callback) override { | |
31 callback.Run(app_url_, connection_url_, message); | |
32 } | |
33 | |
34 StrongBinding<Pingable> binding_; | |
35 std::string app_url_; | |
36 std::string connection_url_; | |
37 }; | |
38 | |
39 class PingableApp : public mojo::ApplicationDelegate, | |
40 public mojo::InterfaceFactory<Pingable> { | |
41 public: | |
42 PingableApp() {} | |
43 ~PingableApp() override {} | |
44 | |
45 private: | |
46 // ApplicationDelegate: | |
47 void Initialize(ApplicationImpl* impl) override { app_url_ = impl->url(); } | |
48 | |
49 bool ConfigureIncomingConnection( | |
50 mojo::ApplicationConnection* connection) override { | |
51 connection->AddService(this); | |
52 return true; | |
53 } | |
54 | |
55 // InterfaceFactory<Pingable>: | |
56 void Create(mojo::ApplicationConnection* connection, | |
57 mojo::InterfaceRequest<Pingable> request) override { | |
58 new PingableImpl(request.Pass(), app_url_, connection->GetConnectionURL()); | |
59 } | |
60 | |
61 std::string app_url_; | |
62 }; | |
63 | |
64 } // namespace mojo | |
65 | |
66 MojoResult MojoMain(MojoHandle shell_handle) { | |
67 mojo::ApplicationRunner runner(new mojo::PingableApp); | |
68 return runner.Run(shell_handle); | |
69 } | |
OLD | NEW |