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

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

Issue 1465293002: Mojo C++ bindings: introduce public associated-interface-related types. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 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 2015 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_ASSOCIATED_GROUP_H_
6 #define MOJO_PUBLIC_CPP_BINDINGS_ASSOCIATED_GROUP_H_
7
8 #include "base/memory/ref_counted.h"
9 #include "mojo/public/cpp/bindings/associated_interface_ptr_info.h"
10 #include "mojo/public/cpp/bindings/associated_interface_request.h"
11 #include "mojo/public/cpp/bindings/lib/scoped_interface_endpoint_handle.h"
12
13 namespace mojo {
14
15 namespace internal {
16 class MultiplexRouter;
17 }
18
19 // AssociatedGroup refers to all the interface endpoints running at one end of a
20 // message pipe. It is used to create associated interfaces for that message
21 // pipe.
22 // It is thread safe and cheap to make copies.
23 class AssociatedGroup {
24 public:
25 // Configuration used by CreateAssociatedInterface(). Please see the comments
26 // of that method for more details.
27 enum AssociatedInterfaceConfig { WILL_PASS_PTR, WILL_PASS_REQUEST };
28
29 AssociatedGroup();
30 AssociatedGroup(const AssociatedGroup& other);
31
32 ~AssociatedGroup();
33
34 AssociatedGroup& operator=(const AssociatedGroup& other);
35
36 // |config| indicates whether |ptr_info| or |request| will be sent to the
37 // remote side of the message pipe.
38 //
39 // NOTE: If |config| is |WILL_PASS_REQUEST|, you will want to bind |ptr_info|
40 // to a local AssociatedInterfacePtr to make calls. However, there is one
41 // restriction: the pointer should NOT be used to make calls before |request|
42 // is sent. Violating that will cause the message pipe to be closed. On the
43 // other hand, as soon as |request| is sent, the pointer is usable. There is
44 // no need to wait until |request| is bound to an implementation at the remote
45 // side.
46 template <typename T>
47 void CreateAssociatedInterface(AssociatedInterfaceConfig config,
48 AssociatedInterfacePtrInfo<T>* ptr_info,
49 AssociatedInterfaceRequest<T>* request) {
50 internal::ScopedInterfaceEndpointHandle local;
51 internal::ScopedInterfaceEndpointHandle remote;
52 CreateEndpointHandlePair(&local, &remote);
53
54 if (!local.is_valid() || !remote.is_valid()) {
55 *ptr_info = AssociatedInterfacePtrInfo<T>();
56 *request = AssociatedInterfaceRequest<T>();
57 return;
58 }
59
60 if (config == WILL_PASS_PTR) {
61 internal::AssociatedInterfacePtrInfoHelper::SetHandle(ptr_info,
62 remote.Pass());
63 // The implementation is local, therefore set the version according to
64 // the interface definition that this code is built against.
65 ptr_info->set_version(T::Version_);
66 internal::AssociatedInterfaceRequestHelper::SetHandle(request,
67 local.Pass());
68 } else {
69 internal::AssociatedInterfacePtrInfoHelper::SetHandle(ptr_info,
70 local.Pass());
71 // The implementation is remote, we don't know about its actual version
72 // yet.
73 ptr_info->set_version(0u);
74 internal::AssociatedInterfaceRequestHelper::SetHandle(request,
75 remote.Pass());
76 }
77 }
78
79 private:
80 friend class internal::MultiplexRouter;
81
82 void CreateEndpointHandlePair(
83 internal::ScopedInterfaceEndpointHandle* local_endpoint,
84 internal::ScopedInterfaceEndpointHandle* remote_endpoint);
85
86 scoped_refptr<internal::MultiplexRouter> router_;
87 };
88
89 } // namespace mojo
90
91 #endif // MOJO_PUBLIC_CPP_BINDINGS_ASSOCIATED_GROUP_H_
OLDNEW
« no previous file with comments | « mojo/public/cpp/bindings/associated_binding.h ('k') | mojo/public/cpp/bindings/associated_interface_ptr.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698