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

Side by Side Diff: mojo/public/cpp/bindings/associated_interface_request.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 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 "mojo/public/cpp/system/macros.h" 8 #include "base/macros.h"
9 #include "mojo/public/cpp/bindings/lib/scoped_interface_endpoint_handle.h"
9 10
10 namespace mojo { 11 namespace mojo {
11 12
12 // Represents an associated interface request. 13 namespace internal {
13 // TODO(yzshen): implement it. 14 class AssociatedInterfaceRequestHelper;
15 }
16
17 // AssociatedInterfaceRequest represents an associated interface request. It is
18 // similar to InterfaceRequest except that it doesn't own a message pipe handle.
14 template <typename Interface> 19 template <typename Interface>
15 class AssociatedInterfaceRequest { 20 class AssociatedInterfaceRequest {
16 MOJO_MOVE_ONLY_TYPE(AssociatedInterfaceRequest) 21 MOVE_ONLY_TYPE_WITH_MOVE_CONSTRUCTOR_FOR_CPP_03(AssociatedInterfaceRequest);
17 22
18 public: 23 public:
24 // Constructs an empty AssociatedInterfaceRequest, representing that the
25 // client is not requesting an implementation of Interface.
19 AssociatedInterfaceRequest() {} 26 AssociatedInterfaceRequest() {}
20 AssociatedInterfaceRequest(AssociatedInterfaceRequest&& other) {} 27 AssociatedInterfaceRequest(decltype(nullptr)) {}
21 28
29 // Takes the interface endpoint handle from another
30 // AssociatedInterfaceRequest.
31 AssociatedInterfaceRequest(AssociatedInterfaceRequest&& other) {
32 handle_ = other.handle_.Pass();
33 }
22 AssociatedInterfaceRequest& operator=(AssociatedInterfaceRequest&& other) { 34 AssociatedInterfaceRequest& operator=(AssociatedInterfaceRequest&& other) {
35 if (this != &other)
36 handle_ = other.handle_.Pass();
23 return *this; 37 return *this;
24 } 38 }
25 39
26 bool is_pending() const { return false; } 40 // Assigning to nullptr resets the AssociatedInterfaceRequest to an empty
41 // state, closing the interface endpoint handle currently bound to it (if
42 // any).
43 AssociatedInterfaceRequest& operator=(decltype(nullptr)) {
44 handle_.reset();
45 return *this;
46 }
47
48 // Indicates whether the request currently contains a valid interface endpoint
49 // handle.
50 bool is_pending() const { return handle_.is_valid(); }
51
52 private:
53 friend class internal::AssociatedInterfaceRequestHelper;
54
55 internal::ScopedInterfaceEndpointHandle handle_;
27 }; 56 };
28 57
58 namespace internal {
59
60 // With this helper, AssociatedInterfaceRequest doesn't have to expose any
61 // operations related to ScopedInterfaceEndpointHandle, which is an internal
62 // class.
63 class AssociatedInterfaceRequestHelper {
64 public:
65 template <typename Interface>
66 static ScopedInterfaceEndpointHandle PassHandle(
67 AssociatedInterfaceRequest<Interface>* request) {
68 return request->handle_.Pass();
69 }
70
71 template <typename Interface>
72 static const ScopedInterfaceEndpointHandle& GetHandle(
73 AssociatedInterfaceRequest<Interface>* request) {
74 return request->handle_;
75 }
76
77 template <typename Interface>
78 static void SetHandle(AssociatedInterfaceRequest<Interface>* request,
79 ScopedInterfaceEndpointHandle handle) {
80 request->handle_ = handle.Pass();
81 }
82 };
83
84 } // namespace internal
29 } // namespace mojo 85 } // namespace mojo
30 86
31 #endif // MOJO_PUBLIC_CPP_BINDINGS_ASSOCIATED_INTERFACE_REQUEST_H_ 87 #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