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

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

Issue 1991463002: Mojo: Expose untyped associated endpoints through public API (Closed) Base URL: https://chromium.googlesource.com/chromium/src.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
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 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 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 #ifndef MOJO_PUBLIC_CPP_BINDINGS_ASSOCIATED_INTERFACE_REQUEST_H_ 5 #ifndef MOJO_PUBLIC_CPP_BINDINGS_ASSOCIATED_INTERFACE_REQUEST_H_
6 #define MOJO_PUBLIC_CPP_BINDINGS_ASSOCIATED_INTERFACE_REQUEST_H_ 6 #define MOJO_PUBLIC_CPP_BINDINGS_ASSOCIATED_INTERFACE_REQUEST_H_
7 7
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/macros.h" 10 #include "base/macros.h"
11 #include "mojo/public/cpp/bindings/lib/scoped_interface_endpoint_handle.h" 11 #include "mojo/public/cpp/bindings/scoped_interface_endpoint_handle.h"
12 12
13 namespace mojo { 13 namespace mojo {
14 14
15 namespace internal {
16 class AssociatedInterfaceRequestHelper;
17 }
18
19 // AssociatedInterfaceRequest represents an associated interface request. It is 15 // AssociatedInterfaceRequest represents an associated interface request. It is
20 // similar to InterfaceRequest except that it doesn't own a message pipe handle. 16 // similar to InterfaceRequest except that it doesn't own a message pipe handle.
21 template <typename Interface> 17 template <typename Interface>
22 class AssociatedInterfaceRequest { 18 class AssociatedInterfaceRequest {
23 DISALLOW_COPY_AND_ASSIGN_WITH_MOVE_FOR_BIND(AssociatedInterfaceRequest); 19 DISALLOW_COPY_AND_ASSIGN_WITH_MOVE_FOR_BIND(AssociatedInterfaceRequest);
24 20
25 public: 21 public:
26 // Constructs an empty AssociatedInterfaceRequest, representing that the 22 // Constructs an empty AssociatedInterfaceRequest, representing that the
27 // client is not requesting an implementation of Interface. 23 // client is not requesting an implementation of Interface.
28 AssociatedInterfaceRequest() {} 24 AssociatedInterfaceRequest() {}
(...skipping 15 matching lines...) Expand all
44 // any). 40 // any).
45 AssociatedInterfaceRequest& operator=(decltype(nullptr)) { 41 AssociatedInterfaceRequest& operator=(decltype(nullptr)) {
46 handle_.reset(); 42 handle_.reset();
47 return *this; 43 return *this;
48 } 44 }
49 45
50 // Indicates whether the request currently contains a valid interface endpoint 46 // Indicates whether the request currently contains a valid interface endpoint
51 // handle. 47 // handle.
52 bool is_pending() const { return handle_.is_valid(); } 48 bool is_pending() const { return handle_.is_valid(); }
53 49
50 void Bind(ScopedInterfaceEndpointHandle handle) {
51 handle_ = std::move(handle);
52 }
53
54 ScopedInterfaceEndpointHandle PassHandle() {
55 return std::move(handle_);
56 }
57
58 const ScopedInterfaceEndpointHandle& handle() const { return handle_; }
59
54 private: 60 private:
55 friend class internal::AssociatedInterfaceRequestHelper; 61 ScopedInterfaceEndpointHandle handle_;
56
57 internal::ScopedInterfaceEndpointHandle handle_;
58 }; 62 };
59 63
60 namespace internal { 64 // Makes an AssociatedInterfaceRequest bound to the specified associated
65 // endpoint.
66 template <typename Interface>
67 AssociatedInterfaceRequest<Interface> MakeAssociatedRequest(
68 ScopedInterfaceEndpointHandle handle) {
69 AssociatedInterfaceRequest<Interface> request;
70 request.Bind(std::move(handle));
71 return request;
72 }
61 73
62 // With this helper, AssociatedInterfaceRequest doesn't have to expose any
63 // operations related to ScopedInterfaceEndpointHandle, which is an internal
64 // class.
65 class AssociatedInterfaceRequestHelper {
66 public:
67 template <typename Interface>
68 static ScopedInterfaceEndpointHandle PassHandle(
69 AssociatedInterfaceRequest<Interface>* request) {
70 return std::move(request->handle_);
71 }
72
73 template <typename Interface>
74 static const ScopedInterfaceEndpointHandle& GetHandle(
75 AssociatedInterfaceRequest<Interface>* request) {
76 return request->handle_;
77 }
78
79 template <typename Interface>
80 static void SetHandle(AssociatedInterfaceRequest<Interface>* request,
81 ScopedInterfaceEndpointHandle handle) {
82 request->handle_ = std::move(handle);
83 }
84 };
85
86 } // namespace internal
87 } // namespace mojo 74 } // namespace mojo
88 75
89 #endif // MOJO_PUBLIC_CPP_BINDINGS_ASSOCIATED_INTERFACE_REQUEST_H_ 76 #endif // MOJO_PUBLIC_CPP_BINDINGS_ASSOCIATED_INTERFACE_REQUEST_H_
OLDNEW
« no previous file with comments | « mojo/public/cpp/bindings/associated_interface_ptr_info.h ('k') | mojo/public/cpp/bindings/lib/associated_group.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698