dbus_echo_app.cc revision cedac228d2dd51db4b79ea1e72c7f249408ee061
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 <stdio.h>
6#include <string>
7
8#include "base/bind.h"
9#include "base/logging.h"
10#include "mojo/public/cpp/application/application.h"
11#include "mojo/public/cpp/environment/environment.h"
12#include "mojo/public/cpp/system/core.h"
13#include "mojo/public/cpp/system/macros.h"
14#include "mojo/public/interfaces/service_provider/service_provider.mojom.h"
15#include "mojo/services/dbus_echo/echo.mojom.h"
16
17namespace mojo {
18namespace examples {
19
20class DBusEchoApp : public Application {
21 public:
22  DBusEchoApp() {}
23  virtual ~DBusEchoApp() {}
24
25  virtual void Initialize() MOJO_OVERRIDE {
26    ConnectTo("dbus:org.chromium.EchoService/org/chromium/MojoImpl",
27              &echo_service_);
28
29    echo_service_->Echo(
30        String::From("who"),
31        base::Bind(&DBusEchoApp::OnEcho, base::Unretained(this)));
32  }
33
34 private:
35  void OnEcho(String echoed) {
36    LOG(INFO) << "echo'd " << echoed;
37  }
38
39  EchoServicePtr echo_service_;
40
41  DISALLOW_COPY_AND_ASSIGN(DBusEchoApp);
42};
43
44}  // namespace examples
45
46// static
47Application* Application::Create() {
48  return new examples::DBusEchoApp();
49}
50
51}  // namespace mojo
52