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