OLD | NEW |
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 <assert.h> | 8 #include <assert.h> |
9 | 9 |
10 #include <algorithm> | 10 #include <algorithm> |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
53 // To move a bound InterfacePtr<..> to another thread, call | 53 // To move a bound InterfacePtr<..> to another thread, call |
54 // ResetAndReturnMessagePipe. Then create a new InterfacePtr<..> on another | 54 // ResetAndReturnMessagePipe. Then create a new InterfacePtr<..> on another |
55 // thread, and bind the new InterfacePtr<..> to the message pipe on that | 55 // thread, and bind the new InterfacePtr<..> to the message pipe on that |
56 // thread. | 56 // thread. |
57 void Bind(ScopedMessagePipeHandle handle, | 57 void Bind(ScopedMessagePipeHandle handle, |
58 MojoAsyncWaiter* waiter = GetDefaultAsyncWaiter()) { | 58 MojoAsyncWaiter* waiter = GetDefaultAsyncWaiter()) { |
59 reset(); | 59 reset(); |
60 internal_state_.ConfigureProxy(handle.Pass(), waiter); | 60 internal_state_.ConfigureProxy(handle.Pass(), waiter); |
61 } | 61 } |
62 | 62 |
| 63 // The client interface may only be set after this InterfacePtr<..> is bound. |
| 64 void set_client(typename Interface::Client* client) { |
| 65 internal_state_.set_client(client); |
| 66 } |
| 67 |
63 // This method may be called to query if the underlying pipe has encountered | 68 // This method may be called to query if the underlying pipe has encountered |
64 // an error. If true, this means method calls made on this interface will be | 69 // an error. If true, this means method calls made on this interface will be |
65 // dropped (and may have already been dropped) on the floor. | 70 // dropped (and may have already been dropped) on the floor. |
66 bool encountered_error() const { | 71 bool encountered_error() const { |
67 assert(internal_state_.router()); | 72 assert(internal_state_.router()); |
68 return internal_state_.router()->encountered_error(); | 73 return internal_state_.router()->encountered_error(); |
69 } | 74 } |
70 | 75 |
71 // This method may be called to register an ErrorHandler to observe a | 76 // This method may be called to register an ErrorHandler to observe a |
72 // connection error on the underlying pipe. The callback runs asynchronously | 77 // connection error on the underlying pipe. The callback runs asynchronously |
(...skipping 19 matching lines...) Expand all Loading... |
92 } | 97 } |
93 | 98 |
94 private: | 99 private: |
95 typedef internal::InterfacePtrState<Interface> State; | 100 typedef internal::InterfacePtrState<Interface> State; |
96 State internal_state_; | 101 State internal_state_; |
97 }; | 102 }; |
98 | 103 |
99 // Takes a handle to the proxy end-point of a pipe. On the other end is | 104 // Takes a handle to the proxy end-point of a pipe. On the other end is |
100 // presumed to be an interface implementation of type |Interface|. Returns a | 105 // presumed to be an interface implementation of type |Interface|. Returns a |
101 // generated proxy to that interface, which may be used on the current thread. | 106 // generated proxy to that interface, which may be used on the current thread. |
102 // It is valid to call SetClient on the returned Interface to set an instance | 107 // It is valid to call set_client on the returned InterfacePtr<..> to set an |
103 // of Interface::Client. | 108 // instance of Interface::Client. |
104 template <typename Interface> | 109 template <typename Interface> |
105 InterfacePtr<Interface> MakeProxy( | 110 InterfacePtr<Interface> MakeProxy( |
106 ScopedMessagePipeHandle handle, | 111 ScopedMessagePipeHandle handle, |
107 MojoAsyncWaiter* waiter = GetDefaultAsyncWaiter()) { | 112 MojoAsyncWaiter* waiter = GetDefaultAsyncWaiter()) { |
108 InterfacePtr<Interface> ptr; | 113 InterfacePtr<Interface> ptr; |
109 if (handle.is_valid()) | 114 if (handle.is_valid()) |
110 ptr.Bind(handle.Pass(), waiter); | 115 ptr.Bind(handle.Pass(), waiter); |
111 return ptr.Pass(); | 116 return ptr.Pass(); |
112 } | 117 } |
113 | 118 |
114 } // namespace mojo | 119 } // namespace mojo |
115 | 120 |
116 #endif // MOJO_PUBLIC_CPP_BINDINGS_INTERFACE_PTR_H_ | 121 #endif // MOJO_PUBLIC_CPP_BINDINGS_INTERFACE_PTR_H_ |
OLD | NEW |