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

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

Issue 2250183003: Make the fuchsia mojo/public repo the source of truth. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Created 4 years, 4 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 | « mojo/public/cpp/bindings/binding.h ('k') | mojo/public/cpp/bindings/callback.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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_BINDING_SET_H_
6 #define MOJO_PUBLIC_CPP_BINDINGS_BINDING_SET_H_
7
8 #include <assert.h>
9
10 #include <algorithm>
11 #include <memory>
12 #include <vector>
13
14 #include "mojo/public/cpp/bindings/binding.h"
15 #include "mojo/public/cpp/system/macros.h"
16
17 namespace mojo {
18
19 // Use this class to manage a set of bindings each of which is
20 // owned by the pipe it is bound to.
21 template <typename Interface>
22 class BindingSet {
23 public:
24 BindingSet() {}
25 ~BindingSet() { CloseAllBindings(); }
26
27 // Adds a binding to the list and arranges for it to be removed when
28 // a connection error occurs. Does not take ownership of |impl|, which
29 // must outlive the binding set.
30 void AddBinding(Interface* impl, InterfaceRequest<Interface> request) {
31 bindings_.emplace_back(new Binding<Interface>(impl, request.Pass()));
32 auto* binding = bindings_.back().get();
33 // Set the connection error handler for the newly added Binding to be a
34 // function that will erase it from the vector.
35 binding->set_connection_error_handler([this, binding]() {
36 auto it =
37 std::find_if(bindings_.begin(), bindings_.end(),
38 [binding](const std::unique_ptr<Binding<Interface>>& b) {
39 return (b.get() == binding);
40 });
41 assert(it != bindings_.end());
42 bindings_.erase(it);
43 });
44 }
45
46 void CloseAllBindings() { bindings_.clear(); }
47
48 size_t size() const { return bindings_.size(); }
49
50 private:
51 std::vector<std::unique_ptr<Binding<Interface>>> bindings_;
52
53 MOJO_DISALLOW_COPY_AND_ASSIGN(BindingSet);
54 };
55
56 } // namespace mojo
57
58 #endif // MOJO_PUBLIC_CPP_BINDINGS_BINDING_SET_H_
OLDNEW
« no previous file with comments | « mojo/public/cpp/bindings/binding.h ('k') | mojo/public/cpp/bindings/callback.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698