Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(598)

Unified Diff: mojo/examples/dbus_echo/dbus_echo_app.cc

Issue 242763003: Implement a trivial Mojo EchoService that can be connected to over DBus (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase to switch MojoChannelInit to ChannelInit Created 6 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | mojo/mojo.gyp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: mojo/examples/dbus_echo/dbus_echo_app.cc
diff --git a/mojo/examples/dbus_echo/dbus_echo_app.cc b/mojo/examples/dbus_echo/dbus_echo_app.cc
new file mode 100644
index 0000000000000000000000000000000000000000..459ad216283b1acf2a7c0e9403819f3b9d5b936d
--- /dev/null
+++ b/mojo/examples/dbus_echo/dbus_echo_app.cc
@@ -0,0 +1,67 @@
+// 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 <stdio.h>
+#include <string>
+
+#include "base/bind.h"
+#include "base/logging.h"
+#include "mojo/public/cpp/bindings/allocation_scope.h"
+#include "mojo/public/cpp/bindings/remote_ptr.h"
+#include "mojo/public/cpp/environment/environment.h"
+#include "mojo/public/cpp/shell/application.h"
+#include "mojo/public/cpp/system/core.h"
+#include "mojo/public/cpp/system/macros.h"
+#include "mojo/public/cpp/utility/run_loop.h"
+#include "mojo/public/interfaces/shell/shell.mojom.h"
+#include "mojo/services/dbus_echo/echo.mojom.h"
+
+#if defined(WIN32)
+#if !defined(CDECL)
+#define CDECL __cdecl
+#endif
+#define DBUS_ECHO_APP_EXPORT __declspec(dllexport)
+#else
+#define CDECL
+#define DBUS_ECHO_APP_EXPORT __attribute__((visibility("default")))
+#endif
+
+namespace mojo {
+namespace examples {
+
+class DBusEchoApp : public Application, public mojo::EchoClient {
+ public:
+ explicit DBusEchoApp(MojoHandle shell_handle) : Application(shell_handle) {
+ InterfacePipe<EchoService, AnyInterface> echo_pipe;
+ mojo::AllocationScope scope;
+ shell()->Connect("dbus:org.chromium.EchoService/org/chromium/MojoImpl",
+ echo_pipe.handle_to_peer.Pass());
+ echo_service_.reset(echo_pipe.handle_to_self.Pass(), this);
+ echo_service_->Echo("who", base::Bind(&DBusEchoApp::OnEcho,
+ base::Unretained(this)));
+ }
+
+ virtual ~DBusEchoApp() {
+ }
+
+ private:
+ void OnEcho(const mojo::String& echoed) {
+ LOG(INFO) << "echo'd " << echoed.To<std::string>();
+ }
+
+ RemotePtr<EchoService> echo_service_;
+};
+
+} // namespace examples
+} // namespace mojo
+
+extern "C" DBUS_ECHO_APP_EXPORT MojoResult CDECL MojoMain(
+ MojoHandle shell_handle) {
+ mojo::Environment env;
+ mojo::RunLoop loop;
+
+ mojo::examples::DBusEchoApp app(shell_handle);
+ loop.Run();
+ return MOJO_RESULT_OK;
+}
« no previous file with comments | « no previous file | mojo/mojo.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698