OLD | NEW |
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_PTR_INFO_H_ | 5 #ifndef MOJO_PUBLIC_CPP_BINDINGS_ASSOCIATED_INTERFACE_PTR_INFO_H_ |
6 #define MOJO_PUBLIC_CPP_BINDINGS_ASSOCIATED_INTERFACE_PTR_INFO_H_ | 6 #define MOJO_PUBLIC_CPP_BINDINGS_ASSOCIATED_INTERFACE_PTR_INFO_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 |
| 13 namespace internal { |
| 14 class AssociatedInterfacePtrInfoHelper; |
| 15 } |
| 16 |
12 // AssociatedInterfacePtrInfo stores necessary information to construct an | 17 // AssociatedInterfacePtrInfo stores necessary information to construct an |
13 // associated interface pointer. | 18 // associated interface pointer. It is similar to InterfacePtrInfo except that |
14 // TODO(yzshen): implement it. | 19 // it doesn't own a message pipe handle. |
15 template <typename Interface> | 20 template <typename Interface> |
16 class AssociatedInterfacePtrInfo { | 21 class AssociatedInterfacePtrInfo { |
17 MOJO_MOVE_ONLY_TYPE(AssociatedInterfacePtrInfo); | 22 MOVE_ONLY_TYPE_WITH_MOVE_CONSTRUCTOR_FOR_CPP_03(AssociatedInterfacePtrInfo); |
18 | 23 |
19 public: | 24 public: |
20 AssociatedInterfacePtrInfo() {} | 25 AssociatedInterfacePtrInfo() : version_(0u) {} |
21 AssociatedInterfacePtrInfo(AssociatedInterfacePtrInfo&& other) {} | 26 |
| 27 AssociatedInterfacePtrInfo(AssociatedInterfacePtrInfo&& other) |
| 28 : handle_(other.handle_.Pass()), version_(other.version_) { |
| 29 other.version_ = 0u; |
| 30 } |
| 31 |
| 32 ~AssociatedInterfacePtrInfo() {} |
22 | 33 |
23 AssociatedInterfacePtrInfo& operator=(AssociatedInterfacePtrInfo&& other) { | 34 AssociatedInterfacePtrInfo& operator=(AssociatedInterfacePtrInfo&& other) { |
| 35 if (this != &other) { |
| 36 handle_ = other.handle_.Pass(); |
| 37 version_ = other.version_; |
| 38 other.version_ = 0u; |
| 39 } |
| 40 |
24 return *this; | 41 return *this; |
25 } | 42 } |
26 | 43 |
27 bool is_valid() const { return false; } | 44 bool is_valid() const { return handle_.is_valid(); } |
| 45 |
| 46 uint32_t version() const { return version_; } |
| 47 void set_version(uint32_t version) { version_ = version; } |
| 48 |
| 49 private: |
| 50 friend class internal::AssociatedInterfacePtrInfoHelper; |
| 51 |
| 52 internal::ScopedInterfaceEndpointHandle handle_; |
| 53 uint32_t version_; |
28 }; | 54 }; |
29 | 55 |
| 56 namespace internal { |
| 57 |
| 58 // With this helper, AssociatedInterfacePtrInfo doesn't have to expose any |
| 59 // operations related to ScopedInterfaceEndpointHandle, which is an internal |
| 60 // class. |
| 61 class AssociatedInterfacePtrInfoHelper { |
| 62 public: |
| 63 template <typename Interface> |
| 64 static ScopedInterfaceEndpointHandle PassHandle( |
| 65 AssociatedInterfacePtrInfo<Interface>* info) { |
| 66 return info->handle_.Pass(); |
| 67 } |
| 68 |
| 69 template <typename Interface> |
| 70 static const ScopedInterfaceEndpointHandle& GetHandle( |
| 71 AssociatedInterfacePtrInfo<Interface>* info) { |
| 72 return info->handle_; |
| 73 } |
| 74 |
| 75 template <typename Interface> |
| 76 static void SetHandle(AssociatedInterfacePtrInfo<Interface>* info, |
| 77 ScopedInterfaceEndpointHandle handle) { |
| 78 info->handle_ = handle.Pass(); |
| 79 } |
| 80 }; |
| 81 |
| 82 } // namespace internal |
30 } // namespace mojo | 83 } // namespace mojo |
31 | 84 |
32 #endif // MOJO_PUBLIC_CPP_BINDINGS_ASSOCIATED_INTERFACE_PTR_INFO_H_ | 85 #endif // MOJO_PUBLIC_CPP_BINDINGS_ASSOCIATED_INTERFACE_PTR_INFO_H_ |
OLD | NEW |