dbus_echo_app.cc revision 5f1c94371a64b3196d4be9466099bb892df9b88e
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_delegate.h"
11#include "mojo/public/cpp/application/application_impl.h"
12#include "mojo/public/cpp/environment/environment.h"
13#include "mojo/public/cpp/system/core.h"
14#include "mojo/public/cpp/system/macros.h"
15#include "mojo/services/dbus_echo/echo.mojom.h"
16
17namespace mojo {
18namespace examples {
19
20class DBusEchoApp : public ApplicationDelegate {
21 public:
22  DBusEchoApp() {}
23  virtual ~DBusEchoApp() {}
24
25  virtual void Initialize(ApplicationImpl* app) MOJO_OVERRIDE {
26    app->ConnectToService(
27        "dbus:org.chromium.EchoService/org/chromium/MojoImpl", &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
47ApplicationDelegate* ApplicationDelegate::Create() {
48  return new examples::DBusEchoApp();
49}
50
51}  // namespace mojo
52