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/bindings/lib/filter_chain.h" | 10 #include "mojo/public/cpp/bindings/lib/filter_chain.h" |
(...skipping 11 matching lines...) Expand all Loading... |
22 virtual void OnConnectionError() = 0; | 22 virtual void OnConnectionError() = 0; |
23 }; | 23 }; |
24 | 24 |
25 template <typename Interface> | 25 template <typename Interface> |
26 class InterfaceImplState : public ErrorHandler { | 26 class InterfaceImplState : public ErrorHandler { |
27 public: | 27 public: |
28 typedef typename Interface::Client Client; | 28 typedef typename Interface::Client Client; |
29 | 29 |
30 explicit InterfaceImplState(InterfaceImplBase<Interface>* instance) | 30 explicit InterfaceImplState(InterfaceImplBase<Interface>* instance) |
31 : router_(NULL), | 31 : router_(NULL), |
32 client_(NULL), | |
33 proxy_(NULL) { | 32 proxy_(NULL) { |
34 assert(instance); | 33 assert(instance); |
35 stub_.set_sink(instance); | 34 stub_.set_sink(instance); |
36 } | 35 } |
37 | 36 |
38 virtual ~InterfaceImplState() { | 37 virtual ~InterfaceImplState() { |
39 delete proxy_; | 38 delete proxy_; |
40 if (router_) { | 39 if (router_) { |
41 router_->set_error_handler(NULL); | 40 router_->set_error_handler(NULL); |
42 delete router_; | 41 delete router_; |
(...skipping 16 matching lines...) Expand all Loading... |
59 filters.Append<MessageHeaderValidator>(); | 58 filters.Append<MessageHeaderValidator>(); |
60 filters.Append<typename Interface::RequestValidator_>(); | 59 filters.Append<typename Interface::RequestValidator_>(); |
61 filters.Append<typename Interface::Client::ResponseValidator_>(); | 60 filters.Append<typename Interface::Client::ResponseValidator_>(); |
62 | 61 |
63 router_ = new Router(handle.Pass(), filters.Pass(), waiter); | 62 router_ = new Router(handle.Pass(), filters.Pass(), waiter); |
64 router_->set_incoming_receiver(&stub_); | 63 router_->set_incoming_receiver(&stub_); |
65 router_->set_error_handler(this); | 64 router_->set_error_handler(this); |
66 | 65 |
67 proxy_ = new typename Client::Proxy_(router_); | 66 proxy_ = new typename Client::Proxy_(router_); |
68 | 67 |
69 instance()->SetClient(proxy_); | |
70 instance()->OnConnectionEstablished(); | 68 instance()->OnConnectionEstablished(); |
71 } | 69 } |
72 | 70 |
73 Router* router() { return router_; } | 71 Router* router() { return router_; } |
74 | 72 Client* client() { return proxy_; } |
75 void set_client(Client* client) { client_ = client; } | |
76 Client* client() { return client_; } | |
77 | 73 |
78 private: | 74 private: |
79 InterfaceImplBase<Interface>* instance() { | 75 InterfaceImplBase<Interface>* instance() { |
80 return static_cast<InterfaceImplBase<Interface>*>(stub_.sink()); | 76 return static_cast<InterfaceImplBase<Interface>*>(stub_.sink()); |
81 } | 77 } |
82 | 78 |
83 virtual void OnConnectionError() MOJO_OVERRIDE { | 79 virtual void OnConnectionError() MOJO_OVERRIDE { |
84 instance()->OnConnectionError(); | 80 instance()->OnConnectionError(); |
85 } | 81 } |
86 | 82 |
87 Router* router_; | 83 Router* router_; |
88 Client* client_; | |
89 typename Client::Proxy_* proxy_; | 84 typename Client::Proxy_* proxy_; |
90 typename Interface::Stub_ stub_; | 85 typename Interface::Stub_ stub_; |
91 | 86 |
92 MOJO_DISALLOW_COPY_AND_ASSIGN(InterfaceImplState); | 87 MOJO_DISALLOW_COPY_AND_ASSIGN(InterfaceImplState); |
93 }; | 88 }; |
94 | 89 |
95 } // namespace internal | 90 } // namespace internal |
96 } // namespace mojo | 91 } // namespace mojo |
97 | 92 |
98 #endif // MOJO_PUBLIC_CPP_BINDINGS_LIB_INTERFACE_IMPL_INTERNAL_H_ | 93 #endif // MOJO_PUBLIC_CPP_BINDINGS_LIB_INTERFACE_IMPL_INTERNAL_H_ |
OLD | NEW |