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

Side by Side 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2016 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 <memory>
6 #include <string>
7 #include <utility>
8
9 #include "examples/hello_mojo/hello_mojo.mojom.h"
10 #include "mojo/public/c/system/main.h"
11 #include "mojo/public/cpp/application/application_connection.h"
12 #include "mojo/public/cpp/application/application_delegate.h"
13 #include "mojo/public/cpp/application/application_runner.h"
14 #include "mojo/public/cpp/application/interface_factory.h"
15 #include "mojo/public/cpp/bindings/interface_request.h"
16 #include "mojo/public/cpp/bindings/strong_binding.h"
17 #include "mojo/public/cpp/system/macros.h"
18
19 using examples::HelloMojo;
20
21 namespace {
22
23 class HelloMojoImpl : public HelloMojo {
24 public:
25 explicit HelloMojoImpl(mojo::InterfaceRequest<HelloMojo> hello_mojo_request)
26 : strong_binding_(this, std::move(hello_mojo_request)) {}
27 ~HelloMojoImpl() override {}
28
29 // |examples::HelloMojo| implementation:
30 void Say(const mojo::String& request,
31 const mojo::Callback<void(mojo::String)>& callback) override {
32 callback.Run((request.get() == "hello") ? "mojo" : "WAT");
33 }
34
35 private:
36 mojo::StrongBinding<HelloMojo> strong_binding_;
37
38 MOJO_DISALLOW_COPY_AND_ASSIGN(HelloMojoImpl);
39 };
40
41 class HelloMojoServerApp : public mojo::ApplicationDelegate,
42 public mojo::InterfaceFactory<HelloMojo> {
43 public:
44 HelloMojoServerApp() {}
45 ~HelloMojoServerApp() override {}
46
47 // |mojo::ApplicationDelegate| implementation:
48 bool ConfigureIncomingConnection(
49 mojo::ApplicationConnection* application_connection) override {
50 application_connection->AddService<HelloMojo>(this);
51 return true;
52 }
53
54 // |mojo::InterfaceFactory<HelloMojo>| implementation:
55 void Create(mojo::ApplicationConnection* application_connection,
56 mojo::InterfaceRequest<HelloMojo> hello_mojo_request) override {
57 new HelloMojoImpl(std::move(hello_mojo_request)); // Owns itself.
58 }
59
60 private:
61 MOJO_DISALLOW_COPY_AND_ASSIGN(HelloMojoServerApp);
62 };
63
64 } // namespace
65
66 MojoResult MojoMain(MojoHandle application_request) {
67 return mojo::ApplicationRunner(std::unique_ptr<mojo::ApplicationDelegate>(
68 new HelloMojoServerApp()))
69 .Run(application_request);
70 }
OLDNEW
« 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