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

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

Issue 1558333002: Rectify our use of std::nullptr_t, inclusions of <stddef.h>/<cstddef>. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Created 4 years, 11 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/array.h ('k') | mojo/public/cpp/bindings/interface_request.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 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 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_INTERFACE_PTR_H_ 5 #ifndef MOJO_PUBLIC_CPP_BINDINGS_INTERFACE_PTR_H_
6 #define MOJO_PUBLIC_CPP_BINDINGS_INTERFACE_PTR_H_ 6 #define MOJO_PUBLIC_CPP_BINDINGS_INTERFACE_PTR_H_
7 7
8 #include <algorithm> 8 #include <algorithm>
9 #include <cstddef>
9 10
10 #include "mojo/public/cpp/bindings/callback.h" 11 #include "mojo/public/cpp/bindings/callback.h"
11 #include "mojo/public/cpp/bindings/interface_ptr_info.h" 12 #include "mojo/public/cpp/bindings/interface_ptr_info.h"
12 #include "mojo/public/cpp/bindings/lib/interface_ptr_internal.h" 13 #include "mojo/public/cpp/bindings/lib/interface_ptr_internal.h"
13 #include "mojo/public/cpp/environment/environment.h" 14 #include "mojo/public/cpp/environment/environment.h"
14 #include "mojo/public/cpp/system/macros.h" 15 #include "mojo/public/cpp/system/macros.h"
15 16
16 namespace mojo { 17 namespace mojo {
17 18
18 // A pointer to a local proxy of a remote Interface implementation. Uses a 19 // A pointer to a local proxy of a remote Interface implementation. Uses a
19 // message pipe to communicate with the remote implementation, and automatically 20 // message pipe to communicate with the remote implementation, and automatically
20 // closes the pipe and deletes the proxy on destruction. The pointer must be 21 // closes the pipe and deletes the proxy on destruction. The pointer must be
21 // bound to a message pipe before the interface methods can be called. 22 // bound to a message pipe before the interface methods can be called.
22 // 23 //
23 // This class is thread hostile, as is the local proxy it manages. All calls to 24 // This class is thread hostile, as is the local proxy it manages. All calls to
24 // this class or the proxy should be from the same thread that created it. If 25 // this class or the proxy should be from the same thread that created it. If
25 // you need to move the proxy to a different thread, extract the 26 // you need to move the proxy to a different thread, extract the
26 // InterfacePtrInfo (containing just the message pipe and any version 27 // InterfacePtrInfo (containing just the message pipe and any version
27 // information) using PassInterface(), pass it to a different thread, and 28 // information) using PassInterface(), pass it to a different thread, and
28 // create and bind a new InterfacePtr from that thread. 29 // create and bind a new InterfacePtr from that thread.
29 template <typename Interface> 30 template <typename Interface>
30 class InterfacePtr { 31 class InterfacePtr {
31 public: 32 public:
32 // Constructs an unbound InterfacePtr. 33 // Constructs an unbound InterfacePtr.
33 InterfacePtr() {} 34 InterfacePtr() {}
34 InterfacePtr(decltype(nullptr)) {} 35 InterfacePtr(std::nullptr_t) {}
35 36
36 // Takes over the binding of another InterfacePtr. 37 // Takes over the binding of another InterfacePtr.
37 InterfacePtr(InterfacePtr&& other) { 38 InterfacePtr(InterfacePtr&& other) {
38 internal_state_.Swap(&other.internal_state_); 39 internal_state_.Swap(&other.internal_state_);
39 } 40 }
40 41
41 // Takes over the binding of another InterfacePtr, and closes any message pipe 42 // Takes over the binding of another InterfacePtr, and closes any message pipe
42 // already bound to this pointer. 43 // already bound to this pointer.
43 InterfacePtr& operator=(InterfacePtr&& other) { 44 InterfacePtr& operator=(InterfacePtr&& other) {
44 reset(); 45 reset();
45 internal_state_.Swap(&other.internal_state_); 46 internal_state_.Swap(&other.internal_state_);
46 return *this; 47 return *this;
47 } 48 }
48 49
49 // Assigning nullptr to this class causes it to close the currently bound 50 // Assigning nullptr to this class causes it to close the currently bound
50 // message pipe (if any) and returns the pointer to the unbound state. 51 // message pipe (if any) and returns the pointer to the unbound state.
51 InterfacePtr& operator=(decltype(nullptr)) { 52 InterfacePtr& operator=(std::nullptr_t) {
52 reset(); 53 reset();
53 return *this; 54 return *this;
54 } 55 }
55 56
56 // Closes the bound message pipe (if any) on destruction. 57 // Closes the bound message pipe (if any) on destruction.
57 ~InterfacePtr() {} 58 ~InterfacePtr() {}
58 59
59 // Binds the InterfacePtr to a remote implementation of Interface. The 60 // Binds the InterfacePtr to a remote implementation of Interface. The
60 // |waiter| is used for receiving notifications when there is data to read 61 // |waiter| is used for receiving notifications when there is data to read
61 // from the message pipe. For most callers, the default |waiter| will be 62 // from the message pipe. For most callers, the default |waiter| will be
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
180 const MojoAsyncWaiter* waiter = Environment::GetDefaultAsyncWaiter()) { 181 const MojoAsyncWaiter* waiter = Environment::GetDefaultAsyncWaiter()) {
181 InterfacePtr<Interface> ptr; 182 InterfacePtr<Interface> ptr;
182 if (info.is_valid()) 183 if (info.is_valid())
183 ptr.Bind(info.Pass(), waiter); 184 ptr.Bind(info.Pass(), waiter);
184 return ptr; 185 return ptr;
185 } 186 }
186 187
187 } // namespace mojo 188 } // namespace mojo
188 189
189 #endif // MOJO_PUBLIC_CPP_BINDINGS_INTERFACE_PTR_H_ 190 #endif // MOJO_PUBLIC_CPP_BINDINGS_INTERFACE_PTR_H_
OLDNEW
« no previous file with comments | « mojo/public/cpp/bindings/array.h ('k') | mojo/public/cpp/bindings/interface_request.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698