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

Unified Diff: examples/hello_mojo/hello_mojo_server.cc

Issue 1702103002: Add an even simpler standalone example. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Created 4 years, 10 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
Index: examples/hello_mojo/hello_mojo_server.cc
diff --git a/examples/hello_mojo/hello_mojo_server.cc b/examples/hello_mojo/hello_mojo_server.cc
new file mode 100644
index 0000000000000000000000000000000000000000..08efddde334bf3c5817e7f42d63e94d0713538e7
--- /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);
+}
« examples/hello_mojo/hello_mojo_client.cc ('K') | « examples/hello_mojo/hello_mojo_client.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698