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

Side by Side Diff: examples/echo/echo_server.cc

Issue 1975993002: Change InterfaceFactory<I>::Create() to take a ConnectionContext instead of an ApplicationConnectio… (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: 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
« no previous file with comments | « examples/content_handler_demo/content_handler_demo.cc ('k') | examples/echo_terminal/main.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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> 5 #include <memory>
6 6
7 #include "examples/echo/echo.mojom.h" 7 #include "examples/echo/echo.mojom.h"
8 #include "mojo/common/binding_set.h" 8 #include "mojo/common/binding_set.h"
9 #include "mojo/public/c/system/main.h" 9 #include "mojo/public/c/system/main.h"
10 #include "mojo/public/cpp/application/application_connection.h" 10 #include "mojo/public/cpp/application/application_connection.h"
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
57 MultiServer() {} 57 MultiServer() {}
58 58
59 // From ApplicationDelegate 59 // From ApplicationDelegate
60 bool ConfigureIncomingConnection( 60 bool ConfigureIncomingConnection(
61 mojo::ApplicationConnection* connection) override { 61 mojo::ApplicationConnection* connection) override {
62 connection->AddService<Echo>(this); 62 connection->AddService<Echo>(this);
63 return true; 63 return true;
64 } 64 }
65 65
66 // From InterfaceFactory<Echo> 66 // From InterfaceFactory<Echo>
67 void Create(mojo::ApplicationConnection* connection, 67 void Create(const mojo::ConnectionContext& connection_context,
68 mojo::InterfaceRequest<Echo> request) override { 68 mojo::InterfaceRequest<Echo> request) override {
69 // This object will be deleted automatically because of the use of 69 // This object will be deleted automatically because of the use of
70 // StrongBinding<> for the declaration of |strong_binding_|. 70 // StrongBinding<> for the declaration of |strong_binding_|.
71 new StrongBindingEchoImpl(request.Pass()); 71 new StrongBindingEchoImpl(request.Pass());
72 } 72 }
73 }; 73 };
74 74
75 // SingletonServer uses the same object to handle all message pipes. Useful 75 // SingletonServer uses the same object to handle all message pipes. Useful
76 // for stateless operation. 76 // for stateless operation.
77 class SingletonServer : public mojo::ApplicationDelegate, 77 class SingletonServer : public mojo::ApplicationDelegate,
78 public mojo::InterfaceFactory<Echo> { 78 public mojo::InterfaceFactory<Echo> {
79 public: 79 public:
80 SingletonServer() {} 80 SingletonServer() {}
81 81
82 // From ApplicationDelegate 82 // From ApplicationDelegate
83 bool ConfigureIncomingConnection( 83 bool ConfigureIncomingConnection(
84 mojo::ApplicationConnection* connection) override { 84 mojo::ApplicationConnection* connection) override {
85 connection->AddService<Echo>(this); 85 connection->AddService<Echo>(this);
86 return true; 86 return true;
87 } 87 }
88 88
89 // From InterfaceFactory<Echo> 89 // From InterfaceFactory<Echo>
90 void Create(mojo::ApplicationConnection* connection, 90 void Create(const mojo::ConnectionContext& connection_context,
91 mojo::InterfaceRequest<Echo> request) override { 91 mojo::InterfaceRequest<Echo> request) override {
92 // All channels will connect to this singleton object, so just 92 // All channels will connect to this singleton object, so just
93 // add the binding to our collection. 93 // add the binding to our collection.
94 bindings_.AddBinding(&echo_impl_, request.Pass()); 94 bindings_.AddBinding(&echo_impl_, request.Pass());
95 } 95 }
96 96
97 private: 97 private:
98 EchoImpl echo_impl_; 98 EchoImpl echo_impl_;
99 99
100 mojo::BindingSet<Echo> bindings_; 100 mojo::BindingSet<Echo> bindings_;
(...skipping 11 matching lines...) Expand all
112 OneAtATimeServer() : binding_(&echo_impl_) {} 112 OneAtATimeServer() : binding_(&echo_impl_) {}
113 113
114 // From ApplicationDelegate 114 // From ApplicationDelegate
115 bool ConfigureIncomingConnection( 115 bool ConfigureIncomingConnection(
116 mojo::ApplicationConnection* connection) override { 116 mojo::ApplicationConnection* connection) override {
117 connection->AddService<Echo>(this); 117 connection->AddService<Echo>(this);
118 return true; 118 return true;
119 } 119 }
120 120
121 // From InterfaceFactory<Echo> 121 // From InterfaceFactory<Echo>
122 void Create(mojo::ApplicationConnection* connection, 122 void Create(const mojo::ConnectionContext& connection_context,
123 mojo::InterfaceRequest<Echo> request) override { 123 mojo::InterfaceRequest<Echo> request) override {
124 binding_.Bind(request.Pass()); 124 binding_.Bind(request.Pass());
125 } 125 }
126 126
127 private: 127 private:
128 EchoImpl echo_impl_; 128 EchoImpl echo_impl_;
129 129
130 mojo::Binding<Echo> binding_; 130 mojo::Binding<Echo> binding_;
131 }; 131 };
132 132
133 } // namespace examples 133 } // namespace examples
134 } // namespace mojo 134 } // namespace mojo
135 135
136 MojoResult MojoMain(MojoHandle application_request) { 136 MojoResult MojoMain(MojoHandle application_request) {
137 // Uncomment one of the three servers at a time to see it work: 137 // Uncomment one of the three servers at a time to see it work:
138 mojo::ApplicationRunner runner(std::unique_ptr<mojo::examples::MultiServer>( 138 mojo::ApplicationRunner runner(std::unique_ptr<mojo::examples::MultiServer>(
139 new mojo::examples::MultiServer())); 139 new mojo::examples::MultiServer()));
140 // mojo::ApplicationRunner runner(new mojo::examples::SingletonServer()); 140 // mojo::ApplicationRunner runner(new mojo::examples::SingletonServer());
141 // mojo::ApplicationRunner runner(new mojo::examples::OneAtATimeServer()); 141 // mojo::ApplicationRunner runner(new mojo::examples::OneAtATimeServer());
142 142
143 return runner.Run(application_request); 143 return runner.Run(application_request);
144 } 144 }
OLDNEW
« no previous file with comments | « examples/content_handler_demo/content_handler_demo.cc ('k') | examples/echo_terminal/main.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698