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/lib/interface_impl_internal.h" | 8 #include "mojo/public/cpp/bindings/lib/interface_impl_internal.h" |
9 #include "mojo/public/cpp/system/macros.h" | 9 #include "mojo/public/cpp/system/macros.h" |
10 | 10 |
11 namespace mojo { | 11 namespace mojo { |
12 | 12 |
13 // InterfaceImpl<..> is designed to be the base class of an interface | 13 // 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 | 14 // implementation. It may be bound to a pipe or a proxy, see BindToPipe and |
15 // BindToProxy. | 15 // BindToProxy. |
16 // | 16 // |
17 // NOTE: A base class of WithErrorHandler<Interface> is used to avoid multiple | 17 // NOTE: A base class of WithInterfaceImplBase<Interface> is used to avoid |
18 // inheritance. This base class inserts the signature of ErrorHandler into the | 18 // multiple inheritance. This base class inserts the signature of |
19 // inheritance chain. | 19 // InterfaceImplBase into the inheritance chain. |
20 template <typename Interface> | 20 template <typename Interface> |
21 class InterfaceImpl : public WithErrorHandler<Interface> { | 21 class InterfaceImpl : public internal::WithInterfaceImplBase<Interface> { |
22 public: | 22 public: |
23 typedef typename Interface::Client Client; | 23 typedef typename Interface::Client Client; |
24 | 24 |
25 InterfaceImpl() : internal_state_(this) {} | 25 InterfaceImpl() : internal_state_(this) {} |
26 virtual ~InterfaceImpl() {} | 26 virtual ~InterfaceImpl() {} |
27 | 27 |
| 28 // Subclasses can override this to handle post connection initialization. |
| 29 virtual void OnConnectionEstablished() {} |
| 30 |
28 // Subclasses must handle connection errors. | 31 // Subclasses must handle connection errors. |
29 virtual void OnConnectionError() = 0; | 32 virtual void OnConnectionError() = 0; |
30 | 33 |
31 // We override SetClient here so subclasses don't each have to. | 34 // We override SetClient here so subclasses don't each have to. |
32 virtual void SetClient(Client* client) MOJO_OVERRIDE { | 35 virtual void SetClient(Client* client) MOJO_OVERRIDE { |
33 internal_state_.set_client(client); | 36 internal_state_.set_client(client); |
34 } | 37 } |
35 Client* client() { return internal_state_.client(); } | 38 Client* client() { return internal_state_.client(); } |
36 | 39 |
37 // DO NOT USE. Exposed only for internal use and for testing. | 40 // DO NOT USE. Exposed only for internal use and for testing. |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
78 Impl* BindToProxy(Impl* instance, | 81 Impl* BindToProxy(Impl* instance, |
79 InterfacePtr<Interface>* ptr, | 82 InterfacePtr<Interface>* ptr, |
80 MojoAsyncWaiter* waiter = GetDefaultAsyncWaiter()) { | 83 MojoAsyncWaiter* waiter = 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 } // namespace mojo | 88 } // namespace mojo |
86 | 89 |
87 #endif // MOJO_PUBLIC_CPP_BINDINGS_INTERFACE_IMPL_H_ | 90 #endif // MOJO_PUBLIC_CPP_BINDINGS_INTERFACE_IMPL_H_ |
OLD | NEW |