| 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 // This example demonstrates the simple use of SynchronousInterfacePtr<>, which | 5 // This example demonstrates the simple use of SynchronousInterfacePtr<>, which |
| 6 // is the blocking, synchronous version of mojom interface calls (typically used | 6 // is the blocking, synchronous version of mojom interface calls (typically used |
| 7 // via InterfacePtr<>). | 7 // via InterfacePtr<>). |
| 8 | 8 |
| 9 #include <memory> | 9 #include <memory> |
| 10 #include <utility> | 10 #include <utility> |
| 11 | 11 |
| 12 #include "examples/echo/echo.mojom-sync.h" | 12 #include "examples/echo/echo.mojom-sync.h" |
| 13 #include "examples/echo/echo.mojom.h" | 13 #include "examples/echo/echo.mojom.h" |
| 14 #include "mojo/public/c/system/main.h" | 14 #include "mojo/public/c/system/main.h" |
| 15 #include "mojo/public/cpp/application/application_delegate.h" | 15 #include "mojo/public/cpp/application/application_delegate.h" |
| 16 #include "mojo/public/cpp/application/application_impl.h" | 16 #include "mojo/public/cpp/application/application_impl.h" |
| 17 #include "mojo/public/cpp/application/application_runner.h" | 17 #include "mojo/public/cpp/application/application_runner.h" |
| 18 #include "mojo/public/cpp/bindings/synchronous_interface_ptr.h" | 18 #include "mojo/public/cpp/bindings/synchronous_interface_ptr.h" |
| 19 #include "mojo/public/cpp/environment/logging.h" | 19 #include "mojo/public/cpp/environment/logging.h" |
| 20 #include "mojo/public/cpp/utility/run_loop.h" | 20 #include "mojo/public/cpp/utility/run_loop.h" |
| 21 | 21 |
| 22 namespace mojo { | 22 namespace mojo { |
| 23 namespace examples { | 23 namespace examples { |
| 24 | 24 |
| 25 class EchoClientDelegate : public ApplicationDelegate { | 25 class EchoClientDelegate : public ApplicationDelegate { |
| 26 public: | 26 public: |
| 27 void Initialize(ApplicationImpl* app) override { | 27 void Initialize(ApplicationImpl* app) override { |
| 28 EchoPtr echo; | 28 EchoPtr echo; |
| 29 app->ConnectToService("mojo:echo_server", &echo); | 29 app->ConnectToServiceDeprecated("mojo:echo_server", &echo); |
| 30 | 30 |
| 31 mojo::String out = "yo!"; | 31 mojo::String out = "yo!"; |
| 32 auto echo_proxy = | 32 auto echo_proxy = |
| 33 SynchronousInterfacePtr<Echo>::Create(echo.PassInterfaceHandle()); | 33 SynchronousInterfacePtr<Echo>::Create(echo.PassInterfaceHandle()); |
| 34 MOJO_CHECK(echo_proxy->EchoString("hello", &out)); | 34 MOJO_CHECK(echo_proxy->EchoString("hello", &out)); |
| 35 MOJO_LOG(INFO) << "Got response: " << out; | 35 MOJO_LOG(INFO) << "Got response: " << out; |
| 36 RunLoop::current()->Quit(); | 36 RunLoop::current()->Quit(); |
| 37 } | 37 } |
| 38 }; | 38 }; |
| 39 | 39 |
| 40 } // namespace examples | 40 } // namespace examples |
| 41 } // namespace mojo | 41 } // namespace mojo |
| 42 | 42 |
| 43 MojoResult MojoMain(MojoHandle application_request) { | 43 MojoResult MojoMain(MojoHandle application_request) { |
| 44 mojo::ApplicationRunner runner( | 44 mojo::ApplicationRunner runner( |
| 45 std::unique_ptr<mojo::examples::EchoClientDelegate>( | 45 std::unique_ptr<mojo::examples::EchoClientDelegate>( |
| 46 new mojo::examples::EchoClientDelegate())); | 46 new mojo::examples::EchoClientDelegate())); |
| 47 return runner.Run(application_request); | 47 return runner.Run(application_request); |
| 48 } | 48 } |
| OLD | NEW |