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_IMPL_H_ | 5 #ifndef MOJO_PUBLIC_CPP_BINDINGS_INTERFACE_IMPL_H_ |
6 #define MOJO_PUBLIC_CPP_BINDINGS_INTERFACE_IMPL_H_ | 6 #define MOJO_PUBLIC_CPP_BINDINGS_INTERFACE_IMPL_H_ |
7 | 7 |
8 #include "mojo/public/cpp/bindings/interface_request.h" | 8 #include "mojo/public/cpp/bindings/interface_request.h" |
9 #include "mojo/public/cpp/bindings/lib/interface_impl_internal.h" | 9 #include "mojo/public/cpp/bindings/lib/interface_impl_internal.h" |
| 10 #include "mojo/public/cpp/environment/environment.h" |
10 #include "mojo/public/cpp/system/macros.h" | 11 #include "mojo/public/cpp/system/macros.h" |
11 | 12 |
12 namespace mojo { | 13 namespace mojo { |
13 | 14 |
14 // InterfaceImpl<..> is designed to be the base class of an interface | 15 // InterfaceImpl<..> is designed to be the base class of an interface |
15 // implementation. It may be bound to a pipe or a proxy, see BindToPipe and | 16 // implementation. It may be bound to a pipe or a proxy, see BindToPipe and |
16 // BindToProxy. | 17 // BindToProxy. |
17 template <typename Interface> | 18 template <typename Interface> |
18 class InterfaceImpl : public internal::InterfaceImplBase<Interface> { | 19 class InterfaceImpl : public internal::InterfaceImplBase<Interface> { |
19 public: | 20 public: |
(...skipping 30 matching lines...) Expand all Loading... |
50 // MessagePipe. The instance is returned for convenience in member initializer | 51 // MessagePipe. The instance is returned for convenience in member initializer |
51 // lists, etc. If the pipe is closed, the instance's OnConnectionError method | 52 // lists, etc. If the pipe is closed, the instance's OnConnectionError method |
52 // will be called. | 53 // will be called. |
53 // | 54 // |
54 // The instance is also bound to the current thread. Its methods will only be | 55 // The instance is also bound to the current thread. Its methods will only be |
55 // called on the current thread, and if the current thread exits, then it will | 56 // called on the current thread, and if the current thread exits, then it will |
56 // also be deleted, and along with it, its end point of the pipe will be closed. | 57 // also be deleted, and along with it, its end point of the pipe will be closed. |
57 // | 58 // |
58 // Before returning, the instance's OnConnectionEstablished method is called. | 59 // Before returning, the instance's OnConnectionEstablished method is called. |
59 template <typename Impl> | 60 template <typename Impl> |
60 Impl* BindToPipe(Impl* instance, | 61 Impl* BindToPipe( |
61 ScopedMessagePipeHandle handle, | 62 Impl* instance, |
62 const MojoAsyncWaiter* waiter = GetDefaultAsyncWaiter()) { | 63 ScopedMessagePipeHandle handle, |
| 64 const MojoAsyncWaiter* waiter = Environment::GetDefaultAsyncWaiter()) { |
63 instance->internal_state()->Bind(handle.Pass(), waiter); | 65 instance->internal_state()->Bind(handle.Pass(), waiter); |
64 return instance; | 66 return instance; |
65 } | 67 } |
66 | 68 |
67 // Takes an instance of an InterfaceImpl<..> subclass and binds it to the given | 69 // Takes an instance of an InterfaceImpl<..> subclass and binds it to the given |
68 // InterfacePtr<..>. The instance is returned for convenience in member | 70 // InterfacePtr<..>. The instance is returned for convenience in member |
69 // initializer lists, etc. If the pipe is closed, the instance's | 71 // initializer lists, etc. If the pipe is closed, the instance's |
70 // OnConnectionError method will be called. | 72 // OnConnectionError method will be called. |
71 // | 73 // |
72 // The instance is also bound to the current thread. Its methods will only be | 74 // The instance is also bound to the current thread. Its methods will only be |
73 // called on the current thread, and if the current thread exits, then it will | 75 // called on the current thread, and if the current thread exits, then it will |
74 // also be deleted, and along with it, its end point of the pipe will be closed. | 76 // also be deleted, and along with it, its end point of the pipe will be closed. |
75 // | 77 // |
76 // Before returning, the instance's OnConnectionEstablished method is called. | 78 // Before returning, the instance's OnConnectionEstablished method is called. |
77 template <typename Impl, typename Interface> | 79 template <typename Impl, typename Interface> |
78 Impl* BindToProxy(Impl* instance, | 80 Impl* BindToProxy( |
79 InterfacePtr<Interface>* ptr, | 81 Impl* instance, |
80 const MojoAsyncWaiter* waiter = GetDefaultAsyncWaiter()) { | 82 InterfacePtr<Interface>* ptr, |
| 83 const MojoAsyncWaiter* waiter = Environment::GetDefaultAsyncWaiter()) { |
81 instance->internal_state()->BindProxy(ptr, waiter); | 84 instance->internal_state()->BindProxy(ptr, waiter); |
82 return instance; | 85 return instance; |
83 } | 86 } |
84 | 87 |
85 // Takes an instance of an InterfaceImpl<..> subclass and binds it to the given | 88 // Takes an instance of an InterfaceImpl<..> subclass and binds it to the given |
86 // InterfaceRequest<..>. The instance is returned for convenience in member | 89 // InterfaceRequest<..>. The instance is returned for convenience in member |
87 // initializer lists, etc. If the pipe is closed, the instance's | 90 // initializer lists, etc. If the pipe is closed, the instance's |
88 // OnConnectionError method will be called. | 91 // OnConnectionError method will be called. |
89 // | 92 // |
90 // The instance is also bound to the current thread. Its methods will only be | 93 // The instance is also bound to the current thread. Its methods will only be |
91 // called on the current thread, and if the current thread exits, then it will | 94 // called on the current thread, and if the current thread exits, then it will |
92 // also be deleted, and along with it, its end point of the pipe will be closed. | 95 // also be deleted, and along with it, its end point of the pipe will be closed. |
93 // | 96 // |
94 // Before returning, the instance will receive a SetClient call, providing it | 97 // Before returning, the instance will receive a SetClient call, providing it |
95 // with a proxy to the client on the other end of the pipe. | 98 // with a proxy to the client on the other end of the pipe. |
96 template <typename Impl, typename Interface> | 99 template <typename Impl, typename Interface> |
97 Impl* BindToRequest(Impl* instance, | 100 Impl* BindToRequest( |
98 InterfaceRequest<Interface>* request, | 101 Impl* instance, |
99 const MojoAsyncWaiter* waiter = GetDefaultAsyncWaiter()) { | 102 InterfaceRequest<Interface>* request, |
| 103 const MojoAsyncWaiter* waiter = Environment::GetDefaultAsyncWaiter()) { |
100 return BindToPipe(instance, request->PassMessagePipe(), waiter); | 104 return BindToPipe(instance, request->PassMessagePipe(), waiter); |
101 } | 105 } |
102 | 106 |
103 } // namespace mojo | 107 } // namespace mojo |
104 | 108 |
105 #endif // MOJO_PUBLIC_CPP_BINDINGS_INTERFACE_IMPL_H_ | 109 #endif // MOJO_PUBLIC_CPP_BINDINGS_INTERFACE_IMPL_H_ |
OLD | NEW |