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

Unified Diff: examples/echo/echo_server.cc

Issue 1975253002: ApplicationConnection devolution, part 2.1. (Closed) Base URL: https://github.com/domokit/mojo.git@work792-x-work791_service_registry_spimpl
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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « examples/echo/README.md ('k') | examples/echo_terminal/main.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: examples/echo/echo_server.cc
diff --git a/examples/echo/echo_server.cc b/examples/echo/echo_server.cc
index 7cd54d5df5c10d227a639e4ff48cd9ca2703ecb9..2da7ede4e9c8868db37af770d8c12d8639481005 100644
--- a/examples/echo/echo_server.cc
+++ b/examples/echo/echo_server.cc
@@ -10,7 +10,6 @@
#include "mojo/public/cpp/application/application_connection.h"
#include "mojo/public/cpp/application/application_delegate.h"
#include "mojo/public/cpp/application/application_runner.h"
-#include "mojo/public/cpp/application/interface_factory.h"
#include "mojo/public/cpp/bindings/strong_binding.h"
namespace mojo {
@@ -25,8 +24,8 @@ namespace examples {
// StrongBinding.
// 2. SingletonServer -- all requests are handled by one object. Connections are
// tracked using BindingSet.
-// 3. OneAtATimeServer -- each Create call from InterfaceFactory<> closes the
-// old interface pipe and binds the new interface pipe.
+// 3. OneAtATimeServer -- each request "replaces" any previous request. Any old
+// interface pipe is closed and the new interface pipe is bound.
// EchoImpl defines our implementation of the Echo interface.
// It is used by all three server variants.
@@ -51,49 +50,43 @@ class StrongBindingEchoImpl : public EchoImpl {
};
// MultiServer creates a new object to handle each message pipe.
-class MultiServer : public mojo::ApplicationDelegate,
- public mojo::InterfaceFactory<Echo> {
+class MultiServer : public mojo::ApplicationDelegate {
public:
MultiServer() {}
// From ApplicationDelegate
bool ConfigureIncomingConnection(
mojo::ApplicationConnection* connection) override {
- connection->AddService<Echo>(this);
+ connection->GetServiceProviderImpl().AddService<Echo>(
+ [](const mojo::ConnectionContext& connection_context,
+ mojo::InterfaceRequest<Echo> echo_request) {
+ // This object will be deleted automatically because of the use of
+ // StrongBinding<> for the declaration of |strong_binding_|.
+ new StrongBindingEchoImpl(echo_request.Pass());
+ });
return true;
}
-
- // From InterfaceFactory<Echo>
- void Create(const mojo::ConnectionContext& connection_context,
- mojo::InterfaceRequest<Echo> request) override {
- // This object will be deleted automatically because of the use of
- // StrongBinding<> for the declaration of |strong_binding_|.
- new StrongBindingEchoImpl(request.Pass());
- }
};
// SingletonServer uses the same object to handle all message pipes. Useful
// for stateless operation.
-class SingletonServer : public mojo::ApplicationDelegate,
- public mojo::InterfaceFactory<Echo> {
+class SingletonServer : public mojo::ApplicationDelegate {
public:
SingletonServer() {}
// From ApplicationDelegate
bool ConfigureIncomingConnection(
mojo::ApplicationConnection* connection) override {
- connection->AddService<Echo>(this);
+ connection->GetServiceProviderImpl().AddService<Echo>(
+ [this](const mojo::ConnectionContext& connection_context,
+ mojo::InterfaceRequest<Echo> echo_request) {
+ // All channels will connect to this singleton object, so just
+ // add the binding to our collection.
+ bindings_.AddBinding(&echo_impl_, echo_request.Pass());
+ });
return true;
}
- // From InterfaceFactory<Echo>
- void Create(const mojo::ConnectionContext& connection_context,
- mojo::InterfaceRequest<Echo> request) override {
- // All channels will connect to this singleton object, so just
- // add the binding to our collection.
- bindings_.AddBinding(&echo_impl_, request.Pass());
- }
-
private:
EchoImpl echo_impl_;
@@ -106,24 +99,21 @@ class SingletonServer : public mojo::ApplicationDelegate,
// not reliable. There's a race condition because a second client could bind
// to the server before the first client called EchoString(). Therefore, this
// is an example of how not to write your code.
-class OneAtATimeServer : public mojo::ApplicationDelegate,
- public mojo::InterfaceFactory<Echo> {
+class OneAtATimeServer : public mojo::ApplicationDelegate {
public:
OneAtATimeServer() : binding_(&echo_impl_) {}
// From ApplicationDelegate
bool ConfigureIncomingConnection(
mojo::ApplicationConnection* connection) override {
- connection->AddService<Echo>(this);
+ connection->GetServiceProviderImpl().AddService<Echo>(
+ [this](const mojo::ConnectionContext& connection_context,
+ mojo::InterfaceRequest<Echo> echo_request) {
+ binding_.Bind(echo_request.Pass());
+ });
return true;
}
- // From InterfaceFactory<Echo>
- void Create(const mojo::ConnectionContext& connection_context,
- mojo::InterfaceRequest<Echo> request) override {
- binding_.Bind(request.Pass());
- }
-
private:
EchoImpl echo_impl_;
« no previous file with comments | « examples/echo/README.md ('k') | examples/echo_terminal/main.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698