| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include <memory> | |
| 6 | |
| 7 #include "base/logging.h" | 5 #include "base/logging.h" |
| 8 #include "examples/echo/echo.mojom.h" | 6 #include "examples/echo/echo.mojom.h" |
| 9 #include "mojo/public/c/system/main.h" | 7 #include "mojo/public/c/system/main.h" |
| 10 #include "mojo/public/cpp/application/application_delegate.h" | 8 #include "mojo/public/cpp/application/application_impl_base.h" |
| 11 #include "mojo/public/cpp/application/application_impl.h" | |
| 12 #include "mojo/public/cpp/application/application_runner.h" | |
| 13 #include "mojo/public/cpp/application/connect.h" | 9 #include "mojo/public/cpp/application/connect.h" |
| 10 #include "mojo/public/cpp/application/run_application.h" |
| 14 #include "mojo/public/cpp/utility/run_loop.h" | 11 #include "mojo/public/cpp/utility/run_loop.h" |
| 15 | 12 |
| 16 namespace mojo { | 13 namespace mojo { |
| 17 namespace examples { | 14 namespace examples { |
| 18 | 15 |
| 19 class ResponsePrinter { | 16 class ResponsePrinter { |
| 20 public: | 17 public: |
| 21 void Run(const String& value) const { | 18 void Run(const String& value) const { |
| 22 LOG(INFO) << "***** Response: " << value.get().c_str(); | 19 LOG(INFO) << "***** Response: " << value.get().c_str(); |
| 23 RunLoop::current()->Quit(); // All done! | 20 RunLoop::current()->Quit(); // All done! |
| 24 } | 21 } |
| 25 }; | 22 }; |
| 26 | 23 |
| 27 class EchoClientDelegate : public ApplicationDelegate { | 24 class EchoClientApp : public ApplicationImplBase { |
| 28 public: | 25 public: |
| 29 void Initialize(ApplicationImpl* app) override { | 26 void OnInitialize() override { |
| 30 ConnectToService(app->shell(), "mojo:echo_server", GetProxy(&echo_)); | 27 ConnectToService(shell(), "mojo:echo_server", GetProxy(&echo_)); |
| 31 | 28 |
| 32 echo_->EchoString("hello world", ResponsePrinter()); | 29 echo_->EchoString("hello world", ResponsePrinter()); |
| 33 } | 30 } |
| 34 | 31 |
| 35 private: | 32 private: |
| 36 EchoPtr echo_; | 33 EchoPtr echo_; |
| 37 }; | 34 }; |
| 38 | 35 |
| 39 } // namespace examples | 36 } // namespace examples |
| 40 } // namespace mojo | 37 } // namespace mojo |
| 41 | 38 |
| 42 MojoResult MojoMain(MojoHandle application_request) { | 39 MojoResult MojoMain(MojoHandle application_request) { |
| 43 mojo::ApplicationRunner runner( | 40 mojo::examples::EchoClientApp echo_client_app; |
| 44 std::unique_ptr<mojo::examples::EchoClientDelegate>( | 41 return mojo::RunMainApplication(application_request, &echo_client_app); |
| 45 new mojo::examples::EchoClientDelegate())); | |
| 46 return runner.Run(application_request); | |
| 47 } | 42 } |
| OLD | NEW |