Chromium Code Reviews

Side by Side Diff: examples/hello_mojo/hello_mojo_server.cc

Issue 2015643002: Add (optional) options to Run[Main]Application(). (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: doh Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff |
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include <memory>
6 #include <string> 5 #include <string>
7 #include <utility> 6 #include <utility>
8 7
9 #include "examples/hello_mojo/hello_mojo.mojom.h" 8 #include "examples/hello_mojo/hello_mojo.mojom.h"
10 #include "mojo/public/c/system/main.h" 9 #include "mojo/public/c/system/main.h"
11 #include "mojo/public/cpp/application/application_delegate.h" 10 #include "mojo/public/cpp/application/application_impl_base.h"
12 #include "mojo/public/cpp/application/application_runner.h" 11 #include "mojo/public/cpp/application/run_application.h"
13 #include "mojo/public/cpp/application/service_provider_impl.h" 12 #include "mojo/public/cpp/application/service_provider_impl.h"
14 #include "mojo/public/cpp/bindings/interface_request.h" 13 #include "mojo/public/cpp/bindings/interface_request.h"
15 #include "mojo/public/cpp/bindings/strong_binding.h" 14 #include "mojo/public/cpp/bindings/strong_binding.h"
16 #include "mojo/public/cpp/system/macros.h" 15 #include "mojo/public/cpp/system/macros.h"
17 16
18 using examples::HelloMojo; 17 using examples::HelloMojo;
19 18
20 namespace { 19 namespace {
21 20
22 class HelloMojoImpl : public HelloMojo { 21 class HelloMojoImpl : public HelloMojo {
23 public: 22 public:
24 explicit HelloMojoImpl(mojo::InterfaceRequest<HelloMojo> hello_mojo_request) 23 explicit HelloMojoImpl(mojo::InterfaceRequest<HelloMojo> hello_mojo_request)
25 : strong_binding_(this, std::move(hello_mojo_request)) {} 24 : strong_binding_(this, std::move(hello_mojo_request)) {}
26 ~HelloMojoImpl() override {} 25 ~HelloMojoImpl() override {}
27 26
28 // |examples::HelloMojo| implementation: 27 // |examples::HelloMojo| implementation:
29 void Say(const mojo::String& request, 28 void Say(const mojo::String& request,
30 const mojo::Callback<void(mojo::String)>& callback) override { 29 const mojo::Callback<void(mojo::String)>& callback) override {
31 callback.Run((request.get() == "hello") ? "mojo" : "WAT"); 30 callback.Run((request.get() == "hello") ? "mojo" : "WAT");
32 } 31 }
33 32
34 private: 33 private:
35 mojo::StrongBinding<HelloMojo> strong_binding_; 34 mojo::StrongBinding<HelloMojo> strong_binding_;
36 35
37 MOJO_DISALLOW_COPY_AND_ASSIGN(HelloMojoImpl); 36 MOJO_DISALLOW_COPY_AND_ASSIGN(HelloMojoImpl);
38 }; 37 };
39 38
40 class HelloMojoServerApp : public mojo::ApplicationDelegate { 39 class HelloMojoServerApp : public mojo::ApplicationImplBase {
41 public: 40 public:
42 HelloMojoServerApp() {} 41 HelloMojoServerApp() {}
43 ~HelloMojoServerApp() override {} 42 ~HelloMojoServerApp() override {}
44 43
45 // |mojo::ApplicationDelegate| implementation: 44 // |mojo::ApplicationImplBase| override:
46 bool ConfigureIncomingConnection( 45 bool OnAcceptConnection(
47 mojo::ServiceProviderImpl* service_provider_impl) override { 46 mojo::ServiceProviderImpl* service_provider_impl) override {
48 service_provider_impl->AddService<HelloMojo>( 47 service_provider_impl->AddService<HelloMojo>(
49 [](const mojo::ConnectionContext& connection_context, 48 [](const mojo::ConnectionContext& connection_context,
50 mojo::InterfaceRequest<HelloMojo> hello_mojo_request) { 49 mojo::InterfaceRequest<HelloMojo> hello_mojo_request) {
51 new HelloMojoImpl(std::move(hello_mojo_request)); // Owns itself. 50 new HelloMojoImpl(std::move(hello_mojo_request)); // Owns itself.
52 }); 51 });
53 return true; 52 return true;
54 } 53 }
55 54
56 private: 55 private:
57 MOJO_DISALLOW_COPY_AND_ASSIGN(HelloMojoServerApp); 56 MOJO_DISALLOW_COPY_AND_ASSIGN(HelloMojoServerApp);
58 }; 57 };
59 58
60 } // namespace 59 } // namespace
61 60
62 MojoResult MojoMain(MojoHandle application_request) { 61 MojoResult MojoMain(MojoHandle application_request) {
63 return mojo::ApplicationRunner(std::unique_ptr<mojo::ApplicationDelegate>( 62 HelloMojoServerApp hello_mojo_server_app;
64 new HelloMojoServerApp())) 63 return mojo::RunMainApplication(application_request, &hello_mojo_server_app);
65 .Run(application_request);
66 } 64 }
OLDNEW

Powered by Google App Engine