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_LIB_INTERFACE_IMPL_INTERNAL_H_ | 5 #ifndef MOJO_PUBLIC_CPP_BINDINGS_LIB_INTERFACE_IMPL_INTERNAL_H_ |
6 #define MOJO_PUBLIC_CPP_BINDINGS_LIB_INTERFACE_IMPL_INTERNAL_H_ | 6 #define MOJO_PUBLIC_CPP_BINDINGS_LIB_INTERFACE_IMPL_INTERNAL_H_ |
7 | 7 |
8 #include "mojo/public/cpp/bindings/error_handler.h" | 8 #include "mojo/public/cpp/bindings/error_handler.h" |
9 #include "mojo/public/cpp/bindings/interface_ptr.h" | 9 #include "mojo/public/cpp/bindings/interface_ptr.h" |
10 #include "mojo/public/cpp/system/macros.h" | 10 #include "mojo/public/cpp/system/macros.h" |
11 | 11 |
12 namespace mojo { | 12 namespace mojo { |
13 namespace internal { | 13 namespace internal { |
14 | 14 |
15 template <typename Interface> | 15 template <typename Interface> |
| 16 class InterfaceImplBase : public Interface { |
| 17 public: |
| 18 virtual ~InterfaceImplBase() {} |
| 19 virtual void OnConnectionEstablished() = 0; |
| 20 virtual void OnConnectionError() = 0; |
| 21 }; |
| 22 |
| 23 template <typename Interface> |
16 class InterfaceImplState : public ErrorHandler { | 24 class InterfaceImplState : public ErrorHandler { |
17 public: | 25 public: |
18 typedef typename Interface::Client Client; | 26 typedef typename Interface::Client Client; |
19 | 27 |
20 explicit InterfaceImplState(WithErrorHandler<Interface>* instance) | 28 explicit InterfaceImplState(InterfaceImplBase<Interface>* instance) |
21 : router_(NULL), | 29 : router_(NULL), |
22 client_(NULL), | 30 client_(NULL), |
23 proxy_(NULL) { | 31 proxy_(NULL) { |
24 assert(instance); | 32 assert(instance); |
25 stub_.set_sink(instance); | 33 stub_.set_sink(instance); |
26 } | 34 } |
27 | 35 |
28 virtual ~InterfaceImplState() { | 36 virtual ~InterfaceImplState() { |
29 delete proxy_; | 37 delete proxy_; |
30 if (router_) { | 38 if (router_) { |
(...skipping 13 matching lines...) Expand all Loading... |
44 void Bind(ScopedMessagePipeHandle handle, | 52 void Bind(ScopedMessagePipeHandle handle, |
45 MojoAsyncWaiter* waiter) { | 53 MojoAsyncWaiter* waiter) { |
46 assert(!router_); | 54 assert(!router_); |
47 | 55 |
48 router_ = new Router(handle.Pass(), waiter); | 56 router_ = new Router(handle.Pass(), waiter); |
49 router_->set_incoming_receiver(&stub_); | 57 router_->set_incoming_receiver(&stub_); |
50 router_->set_error_handler(this); | 58 router_->set_error_handler(this); |
51 | 59 |
52 proxy_ = new typename Client::Proxy_(router_); | 60 proxy_ = new typename Client::Proxy_(router_); |
53 | 61 |
54 stub_.sink()->SetClient(proxy_); | 62 instance()->SetClient(proxy_); |
| 63 instance()->OnConnectionEstablished(); |
55 } | 64 } |
56 | 65 |
57 Router* router() { return router_; } | 66 Router* router() { return router_; } |
58 | 67 |
59 void set_client(Client* client) { client_ = client; } | 68 void set_client(Client* client) { client_ = client; } |
60 Client* client() { return client_; } | 69 Client* client() { return client_; } |
61 | 70 |
62 private: | 71 private: |
| 72 InterfaceImplBase<Interface>* instance() { |
| 73 return static_cast<InterfaceImplBase<Interface>*>(stub_.sink()); |
| 74 } |
| 75 |
63 virtual void OnConnectionError() MOJO_OVERRIDE { | 76 virtual void OnConnectionError() MOJO_OVERRIDE { |
64 static_cast<WithErrorHandler<Interface>*>(stub_.sink())-> | 77 instance()->OnConnectionError(); |
65 OnConnectionError(); | |
66 } | 78 } |
67 | 79 |
68 internal::Router* router_; | 80 internal::Router* router_; |
69 Client* client_; | 81 Client* client_; |
70 typename Client::Proxy_* proxy_; | 82 typename Client::Proxy_* proxy_; |
71 typename Interface::Stub_ stub_; | 83 typename Interface::Stub_ stub_; |
72 | 84 |
73 MOJO_DISALLOW_COPY_AND_ASSIGN(InterfaceImplState); | 85 MOJO_DISALLOW_COPY_AND_ASSIGN(InterfaceImplState); |
74 }; | 86 }; |
75 | 87 |
76 } // namespace internal | 88 } // namespace internal |
77 } // namespace mojo | 89 } // namespace mojo |
78 | 90 |
79 #endif // MOJO_PUBLIC_CPP_BINDINGS_LIB_INTERFACE_IMPL_INTERNAL_H_ | 91 #endif // MOJO_PUBLIC_CPP_BINDINGS_LIB_INTERFACE_IMPL_INTERNAL_H_ |
OLD | NEW |