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

Side by Side Diff: examples/hello_mojo/hello_mojo_client.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. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
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 <stdio.h> 5 #include <stdio.h>
6 6
7 #include <memory>
8 #include <string> 7 #include <string>
9 8
10 #include "examples/hello_mojo/hello_mojo.mojom.h" 9 #include "examples/hello_mojo/hello_mojo.mojom.h"
11 #include "mojo/public/c/system/main.h" 10 #include "mojo/public/c/system/main.h"
12 #include "mojo/public/cpp/application/application_delegate.h" 11 #include "mojo/public/cpp/application/application_impl_base.h"
13 #include "mojo/public/cpp/application/application_impl.h"
14 #include "mojo/public/cpp/application/application_runner.h"
15 #include "mojo/public/cpp/application/connect.h" 12 #include "mojo/public/cpp/application/connect.h"
13 #include "mojo/public/cpp/application/run_application.h"
16 #include "mojo/public/cpp/system/macros.h" 14 #include "mojo/public/cpp/system/macros.h"
17 #include "mojo/public/cpp/utility/run_loop.h" 15 #include "mojo/public/cpp/utility/run_loop.h"
18 16
19 using examples::HelloMojoPtr; 17 using examples::HelloMojoPtr;
20 18
21 namespace { 19 namespace {
22 20
23 class HelloMojoClientApp : public mojo::ApplicationDelegate { 21 class HelloMojoClientApp : public mojo::ApplicationImplBase {
24 public: 22 public:
25 HelloMojoClientApp() {} 23 HelloMojoClientApp() {}
26 ~HelloMojoClientApp() override {} 24 ~HelloMojoClientApp() override {}
27 25
28 void Initialize(mojo::ApplicationImpl* application) override { 26 void OnInitialize() override {
29 mojo::ConnectToService(application->shell(), "mojo:hello_mojo_server", 27 mojo::ConnectToService(shell(), "mojo:hello_mojo_server",
30 GetProxy(&hello_mojo_)); 28 GetProxy(&hello_mojo_));
31 29
32 DoIt("hello"); 30 DoIt("hello");
33 DoIt("goodbye"); 31 DoIt("goodbye");
34 } 32 }
35 33
36 private: 34 private:
37 void DoIt(const std::string& request) { 35 void DoIt(const std::string& request) {
38 hello_mojo_->Say(request, [request](const mojo::String& response) { 36 hello_mojo_->Say(request, [request](const mojo::String& response) {
39 printf("%s --> %s\n", request.c_str(), response.get().c_str()); 37 printf("%s --> %s\n", request.c_str(), response.get().c_str());
40 }); 38 });
41 } 39 }
42 40
43 HelloMojoPtr hello_mojo_; 41 HelloMojoPtr hello_mojo_;
44 42
45 MOJO_DISALLOW_COPY_AND_ASSIGN(HelloMojoClientApp); 43 MOJO_DISALLOW_COPY_AND_ASSIGN(HelloMojoClientApp);
46 }; 44 };
47 45
48 } // namespace 46 } // namespace
49 47
50 MojoResult MojoMain(MojoHandle application_request) { 48 MojoResult MojoMain(MojoHandle application_request) {
51 return mojo::ApplicationRunner(std::unique_ptr<mojo::ApplicationDelegate>( 49 HelloMojoClientApp hello_mojo_client_app;
52 new HelloMojoClientApp())) 50 return mojo::RunMainApplication(application_request, &hello_mojo_client_app);
53 .Run(application_request);
54 } 51 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698