Add an even simpler standalone example.
This example is like the echo examples, but has no dependencies outside
of //mojo/public (in particular, no //base dependency).
R=vardhan@google.com
Review URL: https://codereview.chromium.org/1702103002 .
diff --git a/examples/BUILD.gn b/examples/BUILD.gn
index 2eb75dc..1f8da31 100644
--- a/examples/BUILD.gn
+++ b/examples/BUILD.gn
@@ -18,6 +18,7 @@
"//examples/echo",
"//examples/echo_terminal",
"//examples/forwarding_content_handler",
+ "//examples/hello_mojo",
"//examples/http_handler",
"//examples/indirect_service",
"//examples/native_run_app",
diff --git a/examples/hello_mojo/BUILD.gn b/examples/hello_mojo/BUILD.gn
new file mode 100644
index 0000000..1c909a2
--- /dev/null
+++ b/examples/hello_mojo/BUILD.gn
@@ -0,0 +1,49 @@
+# Copyright 2016 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.
+
+import("//mojo/public/mojo_application.gni")
+import("//mojo/public/tools/bindings/mojom.gni")
+
+group("hello_mojo") {
+ deps = [
+ ":hello_mojo_client",
+ ":hello_mojo_server",
+ ]
+}
+
+mojo_native_application("hello_mojo_client") {
+ deps = [
+ ":hello_mojo_interface",
+ "//mojo/public/c/system",
+ "//mojo/public/cpp/application:standalone",
+ "//mojo/public/cpp/bindings",
+ "//mojo/public/cpp/system",
+ "//mojo/public/cpp/utility",
+ ]
+
+ sources = [
+ "hello_mojo_client.cc",
+ ]
+}
+
+mojo_native_application("hello_mojo_server") {
+ deps = [
+ ":hello_mojo_interface",
+ "//mojo/public/c/system",
+ "//mojo/public/cpp/application:standalone",
+ "//mojo/public/cpp/bindings",
+ "//mojo/public/cpp/system",
+ "//mojo/public/cpp/utility",
+ ]
+
+ sources = [
+ "hello_mojo_server.cc",
+ ]
+}
+
+mojom("hello_mojo_interface") {
+ sources = [
+ "hello_mojo.mojom",
+ ]
+}
diff --git a/examples/hello_mojo/README.md b/examples/hello_mojo/README.md
new file mode 100644
index 0000000..80fb48a
--- /dev/null
+++ b/examples/hello_mojo/README.md
@@ -0,0 +1,17 @@
+# Hello Mojo example applications
+
+`hello_mojo_server` and `hello_mojo_client` are like the [echo
+examples](../echo), but a bit more minimal and with no dependencies outside of
+the [Mojo public C/C++ SDK](../../mojo/public).
+
+## Running
+
+For example, for a Linux debug build, from the command line:
+
+ $ out/Debug/mojo_shell mojo:hello_mojo_client
+
+## See also
+
+* [echo examples](../echo)
+* [Mojo public C SDK](../../mojo/public/c)
+* [Mojo public C++ SDK](../../mojo/public/cpp)
diff --git a/examples/hello_mojo/hello_mojo.mojom b/examples/hello_mojo/hello_mojo.mojom
new file mode 100644
index 0000000..7c02852
--- /dev/null
+++ b/examples/hello_mojo/hello_mojo.mojom
@@ -0,0 +1,10 @@
+// Copyright 2016 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.
+
+module examples;
+
+[ServiceName="examples.HelloMojo"]
+interface HelloMojo {
+ Say(string request) => (string response);
+};
diff --git a/examples/hello_mojo/hello_mojo_client.cc b/examples/hello_mojo/hello_mojo_client.cc
new file mode 100644
index 0000000..ba12db1
--- /dev/null
+++ b/examples/hello_mojo/hello_mojo_client.cc
@@ -0,0 +1,52 @@
+// Copyright 2016 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 <memory>
+#include <string>
+
+#include "examples/hello_mojo/hello_mojo.mojom.h"
+#include "mojo/public/c/system/main.h"
+#include "mojo/public/cpp/application/application_delegate.h"
+#include "mojo/public/cpp/application/application_impl.h"
+#include "mojo/public/cpp/application/application_runner.h"
+#include "mojo/public/cpp/system/macros.h"
+#include "mojo/public/cpp/utility/run_loop.h"
+
+using examples::HelloMojoPtr;
+
+namespace {
+
+class HelloMojoClientApp : public mojo::ApplicationDelegate {
+ public:
+ HelloMojoClientApp() {}
+ ~HelloMojoClientApp() override {}
+
+ void Initialize(mojo::ApplicationImpl* application) override {
+ application->ConnectToService("mojo:hello_mojo_server", &hello_mojo_);
+
+ DoIt("hello");
+ DoIt("goodbye");
+ }
+
+ private:
+ void DoIt(const std::string& request) {
+ hello_mojo_->Say(request, [request](const mojo::String& response) {
+ printf("%s --> %s\n", request.c_str(), response.get().c_str());
+ });
+ }
+
+ HelloMojoPtr hello_mojo_;
+
+ MOJO_DISALLOW_COPY_AND_ASSIGN(HelloMojoClientApp);
+};
+
+} // namespace
+
+MojoResult MojoMain(MojoHandle application_request) {
+ return mojo::ApplicationRunner(std::unique_ptr<mojo::ApplicationDelegate>(
+ new HelloMojoClientApp()))
+ .Run(application_request);
+}
diff --git a/examples/hello_mojo/hello_mojo_server.cc b/examples/hello_mojo/hello_mojo_server.cc
new file mode 100644
index 0000000..08efddd
--- /dev/null
+++ b/examples/hello_mojo/hello_mojo_server.cc
@@ -0,0 +1,70 @@
+// Copyright 2016 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 <memory>
+#include <string>
+#include <utility>
+
+#include "examples/hello_mojo/hello_mojo.mojom.h"
+#include "mojo/public/c/system/main.h"
+#include "mojo/public/cpp/application/application_connection.h"
+#include "mojo/public/cpp/application/application_delegate.h"
+#include "mojo/public/cpp/application/application_runner.h"
+#include "mojo/public/cpp/application/interface_factory.h"
+#include "mojo/public/cpp/bindings/interface_request.h"
+#include "mojo/public/cpp/bindings/strong_binding.h"
+#include "mojo/public/cpp/system/macros.h"
+
+using examples::HelloMojo;
+
+namespace {
+
+class HelloMojoImpl : public HelloMojo {
+ public:
+ explicit HelloMojoImpl(mojo::InterfaceRequest<HelloMojo> hello_mojo_request)
+ : strong_binding_(this, std::move(hello_mojo_request)) {}
+ ~HelloMojoImpl() override {}
+
+ // |examples::HelloMojo| implementation:
+ void Say(const mojo::String& request,
+ const mojo::Callback<void(mojo::String)>& callback) override {
+ callback.Run((request.get() == "hello") ? "mojo" : "WAT");
+ }
+
+ private:
+ mojo::StrongBinding<HelloMojo> strong_binding_;
+
+ MOJO_DISALLOW_COPY_AND_ASSIGN(HelloMojoImpl);
+};
+
+class HelloMojoServerApp : public mojo::ApplicationDelegate,
+ public mojo::InterfaceFactory<HelloMojo> {
+ public:
+ HelloMojoServerApp() {}
+ ~HelloMojoServerApp() override {}
+
+ // |mojo::ApplicationDelegate| implementation:
+ bool ConfigureIncomingConnection(
+ mojo::ApplicationConnection* application_connection) override {
+ application_connection->AddService<HelloMojo>(this);
+ return true;
+ }
+
+ // |mojo::InterfaceFactory<HelloMojo>| implementation:
+ void Create(mojo::ApplicationConnection* application_connection,
+ mojo::InterfaceRequest<HelloMojo> hello_mojo_request) override {
+ new HelloMojoImpl(std::move(hello_mojo_request)); // Owns itself.
+ }
+
+ private:
+ MOJO_DISALLOW_COPY_AND_ASSIGN(HelloMojoServerApp);
+};
+
+} // namespace
+
+MojoResult MojoMain(MojoHandle application_request) {
+ return mojo::ApplicationRunner(std::unique_ptr<mojo::ApplicationDelegate>(
+ new HelloMojoServerApp()))
+ .Run(application_request);
+}