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

Unified Diff: examples/hello_mojo/hello_mojo_client.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
« no previous file with comments | « examples/hello_mojo/hello_mojo.mojom ('k') | examples/hello_mojo/hello_mojo_server.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: examples/hello_mojo/hello_mojo_client.cc
diff --git a/examples/hello_mojo/hello_mojo_client.cc b/examples/hello_mojo/hello_mojo_client.cc
new file mode 100644
index 0000000000000000000000000000000000000000..ba12db1925f3254740b8803d06621500fc7bddb8
--- /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()))
kulakowski 2016/02/16 18:35:54 clang format makes me happy
+ .Run(application_request);
+}
« no previous file with comments | « examples/hello_mojo/hello_mojo.mojom ('k') | examples/hello_mojo/hello_mojo_server.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698