| 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/lib/interface_impl_internal.h" | 9 #include "mojo/public/cpp/bindings/lib/interface_impl_internal.h" |
| 9 #include "mojo/public/cpp/system/macros.h" | 10 #include "mojo/public/cpp/system/macros.h" |
| 10 | 11 |
| 11 namespace mojo { | 12 namespace mojo { |
| 12 | 13 |
| 13 // InterfaceImpl<..> is designed to be the base class of an interface | 14 // InterfaceImpl<..> is designed to be the base class of an interface |
| 14 // implementation. It may be bound to a pipe or a proxy, see BindToPipe and | 15 // implementation. It may be bound to a pipe or a proxy, see BindToPipe and |
| 15 // BindToProxy. | 16 // BindToProxy. |
| 16 template <typename Interface> | 17 template <typename Interface> |
| 17 class InterfaceImpl : public internal::InterfaceImplBase<Interface> { | 18 class InterfaceImpl : public internal::InterfaceImplBase<Interface> { |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 74 // | 75 // |
| 75 // Before returning, the instance's OnConnectionEstablished method is called. | 76 // Before returning, the instance's OnConnectionEstablished method is called. |
| 76 template <typename Impl, typename Interface> | 77 template <typename Impl, typename Interface> |
| 77 Impl* BindToProxy(Impl* instance, | 78 Impl* BindToProxy(Impl* instance, |
| 78 InterfacePtr<Interface>* ptr, | 79 InterfacePtr<Interface>* ptr, |
| 79 MojoAsyncWaiter* waiter = GetDefaultAsyncWaiter()) { | 80 MojoAsyncWaiter* waiter = GetDefaultAsyncWaiter()) { |
| 80 instance->internal_state()->BindProxy(ptr, waiter); | 81 instance->internal_state()->BindProxy(ptr, waiter); |
| 81 return instance; | 82 return instance; |
| 82 } | 83 } |
| 83 | 84 |
| 85 // Takes an instance of an InterfaceImpl<..> subclass and binds it to the given |
| 86 // InterfaceRequest<..>. The instance is returned for convenience in member |
| 87 // initializer lists, etc. If the pipe is closed, the instance's |
| 88 // OnConnectionError method will be called. |
| 89 // |
| 90 // 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 |
| 92 // also be deleted, and along with it, its end point of the pipe will be closed. |
| 93 // |
| 94 // 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. |
| 96 template <typename Impl, typename Interface> |
| 97 Impl* BindToRequest(Impl* instance, |
| 98 InterfaceRequest<Interface>* request, |
| 99 MojoAsyncWaiter* waiter = GetDefaultAsyncWaiter()) { |
| 100 return BindToPipe(instance, request->PassMessagePipe(), waiter); |
| 101 } |
| 102 |
| 84 } // namespace mojo | 103 } // namespace mojo |
| 85 | 104 |
| 86 #endif // MOJO_PUBLIC_CPP_BINDINGS_INTERFACE_IMPL_H_ | 105 #endif // MOJO_PUBLIC_CPP_BINDINGS_INTERFACE_IMPL_H_ |
| OLD | NEW |