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

Side by Side Diff: mojo/public/cpp/bindings/strong_connector.h

Issue 718473003: Add mojo::Binding<Interface> for more flexible pipe<->impl binding (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 6 years, 1 month 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 2014 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 #ifndef MOJO_PUBLIC_CPP_BINDINGS_STRONG_CONNECTOR_H_
6 #define MOJO_PUBLIC_CPP_BINDINGS_STRONG_CONNECTOR_H_
7
8 #include "mojo/public/c/environment/async_waiter.h"
9 #include "mojo/public/cpp/bindings/connector.h"
10 #include "mojo/public/cpp/bindings/error_handler.h"
11 #include "mojo/public/cpp/bindings/lib/filter_chain.h"
12 #include "mojo/public/cpp/bindings/lib/message_header_validator.h"
13 #include "mojo/public/cpp/bindings/lib/router.h"
14 #include "mojo/public/cpp/system/core.h"
15
16 namespace mojo {
17
18 // This connects an interface implementation strongly to a pipe. When a
19 // connection error is detected the implementation is deleted. Deleting the
20 // connector also closes the pipe.
21 //
22 // Example of an implementation that is always bound strongly to a pipe
23 //
24 // class StronglyBound : public Foo {
25 // public:
26 // explicit StronglyBound(ScopedMessagePipeHandle handle)
27 // : connector_(this, handle.Pass()) {}
28 //
29 // // Foo implementation here
30 //
31 // private:
32 // StrongConnector<Foo> connector_;
33 // };
34 //
35 template <typename Interface>
36 class StrongConnector : public Connector<Interface> {
37 public:
38 explicit StrongConnector(Interface* impl) : Connector<Interface>(impl) {}
39
40 StrongConnector(
41 Interface* impl,
42 ScopedMessagePipeHandle handle,
43 const MojoAsyncWaiter* waiter = Environment::GetDefaultAsyncWaiter())
44 : Connector<Interface>(impl, handle.Pass(), waiter) {}
45
46 virtual ~StrongConnector() {}
47
48 // ErrorHandler implementation
49 void OnConnectionError() override {
50 Connector<Interface>::OnConnectionError();
51 delete this->impl();
52 }
53 };
54
55 } // namespace mojo
56
57 #endif // MOJO_PUBLIC_CPP_BINDINGS_STRONG_CONNECTOR_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698