| 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 <stdio.h> | 5 #include <stdio.h> |
| 6 #include <string> | 6 #include <string> |
| 7 | 7 |
| 8 #include "base/bind.h" | 8 #include "base/bind.h" |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "mojo/public/cpp/bindings/allocation_scope.h" | 10 #include "mojo/public/cpp/bindings/allocation_scope.h" |
| 11 #include "mojo/public/cpp/bindings/remote_ptr.h" | |
| 12 #include "mojo/public/cpp/environment/environment.h" | 11 #include "mojo/public/cpp/environment/environment.h" |
| 13 #include "mojo/public/cpp/shell/application.h" | 12 #include "mojo/public/cpp/shell/application.h" |
| 14 #include "mojo/public/cpp/system/core.h" | 13 #include "mojo/public/cpp/system/core.h" |
| 15 #include "mojo/public/cpp/system/macros.h" | 14 #include "mojo/public/cpp/system/macros.h" |
| 16 #include "mojo/public/cpp/utility/run_loop.h" | 15 #include "mojo/public/cpp/utility/run_loop.h" |
| 17 #include "mojo/public/interfaces/shell/shell.mojom.h" | 16 #include "mojo/public/interfaces/shell/shell.mojom.h" |
| 18 #include "mojo/services/dbus_echo/echo.mojom.h" | 17 #include "mojo/services/dbus_echo/echo.mojom.h" |
| 19 | 18 |
| 20 #if defined(WIN32) | 19 #if defined(WIN32) |
| 21 #if !defined(CDECL) | 20 #if !defined(CDECL) |
| 22 #define CDECL __cdecl | 21 #define CDECL __cdecl |
| 23 #endif | 22 #endif |
| 24 #define DBUS_ECHO_APP_EXPORT __declspec(dllexport) | 23 #define DBUS_ECHO_APP_EXPORT __declspec(dllexport) |
| 25 #else | 24 #else |
| 26 #define CDECL | 25 #define CDECL |
| 27 #define DBUS_ECHO_APP_EXPORT __attribute__((visibility("default"))) | 26 #define DBUS_ECHO_APP_EXPORT __attribute__((visibility("default"))) |
| 28 #endif | 27 #endif |
| 29 | 28 |
| 30 namespace mojo { | 29 namespace mojo { |
| 31 namespace examples { | 30 namespace examples { |
| 32 | 31 |
| 33 class DBusEchoApp : public Application, public mojo::EchoClient { | 32 class DBusEchoApp : public Application { |
| 34 public: | 33 public: |
| 35 explicit DBusEchoApp(MojoHandle shell_handle) : Application(shell_handle) { | 34 explicit DBusEchoApp(MojoHandle shell_handle) : Application(shell_handle) { |
| 36 InterfacePipe<EchoService, AnyInterface> echo_pipe; | 35 ConnectTo("dbus:org.chromium.EchoService/org/chromium/MojoImpl", |
| 37 mojo::AllocationScope scope; | 36 &echo_service_); |
| 38 shell()->Connect("dbus:org.chromium.EchoService/org/chromium/MojoImpl", | 37 |
| 39 echo_pipe.handle_to_peer.Pass()); | 38 AllocationScope scope; |
| 40 echo_service_.reset(echo_pipe.handle_to_self.Pass(), this); | |
| 41 echo_service_->Echo("who", base::Bind(&DBusEchoApp::OnEcho, | 39 echo_service_->Echo("who", base::Bind(&DBusEchoApp::OnEcho, |
| 42 base::Unretained(this))); | 40 base::Unretained(this))); |
| 43 } | 41 } |
| 44 | 42 |
| 45 virtual ~DBusEchoApp() { | 43 virtual ~DBusEchoApp() { |
| 46 } | 44 } |
| 47 | 45 |
| 48 private: | 46 private: |
| 49 void OnEcho(const mojo::String& echoed) { | 47 void OnEcho(const String& echoed) { |
| 50 LOG(INFO) << "echo'd " << echoed.To<std::string>(); | 48 LOG(INFO) << "echo'd " << echoed.To<std::string>(); |
| 51 } | 49 } |
| 52 | 50 |
| 53 RemotePtr<EchoService> echo_service_; | 51 EchoServicePtr echo_service_; |
| 54 }; | 52 }; |
| 55 | 53 |
| 56 } // namespace examples | 54 } // namespace examples |
| 57 } // namespace mojo | 55 } // namespace mojo |
| 58 | 56 |
| 59 extern "C" DBUS_ECHO_APP_EXPORT MojoResult CDECL MojoMain( | 57 extern "C" DBUS_ECHO_APP_EXPORT MojoResult CDECL MojoMain( |
| 60 MojoHandle shell_handle) { | 58 MojoHandle shell_handle) { |
| 61 mojo::Environment env; | 59 mojo::Environment env; |
| 62 mojo::RunLoop loop; | 60 mojo::RunLoop loop; |
| 63 | 61 |
| 64 mojo::examples::DBusEchoApp app(shell_handle); | 62 mojo::examples::DBusEchoApp app(shell_handle); |
| 65 loop.Run(); | 63 loop.Run(); |
| 66 return MOJO_RESULT_OK; | 64 return MOJO_RESULT_OK; |
| 67 } | 65 } |
| OLD | NEW |