summaryrefslogtreecommitdiffstats
path: root/mojo/services/dbus_echo/dbus_echo_service.cc
blob: 70762f6da4fabc4b455311c052acc964db8aa40c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "base/at_exit.h"
#include "base/callback.h"
#include "base/command_line.h"
#include "base/logging.h"
#include "base/memory/scoped_ptr.h"
#include "base/message_loop/message_loop.h"
#include "base/run_loop.h"
#include "mojo/common/channel_init.h"
#include "mojo/dbus/dbus_external_service.h"
#include "mojo/embedder/embedder.h"
#include "mojo/public/cpp/bindings/interface.h"
#include "mojo/public/cpp/environment/environment.h"
#include "mojo/services/dbus_echo/echo.mojom.h"

namespace {
class EchoServiceImpl : public mojo::ServiceConnection<mojo::EchoService,
                                                       EchoServiceImpl> {
 public:
  EchoServiceImpl() {}
  virtual ~EchoServiceImpl() {}

 protected:
  virtual void Echo(
      const mojo::String& in_to_echo,
      const mojo::Callback<void(mojo::String)>& callback) OVERRIDE {
    DVLOG(1) << "Asked to echo " << in_to_echo.To<std::string>();
    callback.Run(in_to_echo);
  }
};

const char kServiceName[] = "org.chromium.EchoService";
}  // anonymous namespace

int main(int argc, char** argv) {
  base::AtExitManager exit_manager;
  CommandLine::Init(argc, argv);

  logging::LoggingSettings settings;
  settings.logging_dest = logging::LOG_TO_SYSTEM_DEBUG_LOG;
  logging::InitLogging(settings);
  logging::SetLogItems(false,    // Process ID
                       false,    // Thread ID
                       false,    // Timestamp
                       false);   // Tick count

  mojo::Environment env;
  mojo::embedder::Init();

  base::MessageLoopForIO message_loop;
  base::RunLoop run_loop;

  mojo::DBusExternalService<EchoServiceImpl> echo_service(kServiceName);
  echo_service.Start();

  run_loop.Run();
  return 0;
}