Home | History | Annotate | Download | only in dbus_echo
      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
      3 // found in the LICENSE file.
      4 
      5 #include "base/at_exit.h"
      6 #include "base/callback.h"
      7 #include "base/command_line.h"
      8 #include "base/logging.h"
      9 #include "base/memory/scoped_ptr.h"
     10 #include "base/message_loop/message_loop.h"
     11 #include "base/run_loop.h"
     12 #include "mojo/dbus/dbus_external_service.h"
     13 #include "mojo/embedder/channel_init.h"
     14 #include "mojo/embedder/embedder.h"
     15 #include "mojo/embedder/simple_platform_support.h"
     16 #include "mojo/examples/echo/echo_service.mojom.h"
     17 #include "mojo/public/cpp/environment/environment.h"
     18 
     19 namespace {
     20 class EchoServiceImpl
     21     : public mojo::InterfaceImpl<mojo::examples::EchoService> {
     22  public:
     23   EchoServiceImpl() {}
     24   virtual ~EchoServiceImpl() {}
     25 
     26  protected:
     27   virtual void EchoString(
     28       const mojo::String& in_to_echo,
     29       const mojo::Callback<void(mojo::String)>& callback) OVERRIDE {
     30     DVLOG(1) << "Asked to echo " << in_to_echo;
     31     callback.Run(in_to_echo);
     32   }
     33 };
     34 
     35 const char kServiceName[] = "org.chromium.EchoService";
     36 }  // anonymous namespace
     37 
     38 int main(int argc, char** argv) {
     39   base::AtExitManager exit_manager;
     40   base::CommandLine::Init(argc, argv);
     41 
     42   logging::LoggingSettings settings;
     43   settings.logging_dest = logging::LOG_TO_SYSTEM_DEBUG_LOG;
     44   logging::InitLogging(settings);
     45   logging::SetLogItems(false,   // Process ID
     46                        false,   // Thread ID
     47                        false,   // Timestamp
     48                        false);  // Tick count
     49 
     50   mojo::embedder::Init(scoped_ptr<mojo::embedder::PlatformSupport>(
     51       new mojo::embedder::SimplePlatformSupport()));
     52 
     53   base::MessageLoopForIO message_loop;
     54   base::RunLoop run_loop;
     55 
     56   mojo::DBusExternalService<EchoServiceImpl> echo_service(kServiceName);
     57   echo_service.Start();
     58 
     59   run_loop.Run();
     60   return 0;
     61 }
     62