| 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_STRONG_BINDING_H_ | 5 #ifndef MOJO_PUBLIC_CPP_BINDINGS_STRONG_BINDING_H_ |
| 6 #define MOJO_PUBLIC_CPP_BINDINGS_STRONG_BINDING_H_ | 6 #define MOJO_PUBLIC_CPP_BINDINGS_STRONG_BINDING_H_ |
| 7 | 7 |
| 8 #include <assert.h> | 8 #include <assert.h> |
| 9 #include <utility> |
| 9 | 10 |
| 10 #include "mojo/public/c/environment/async_waiter.h" | 11 #include "mojo/public/c/environment/async_waiter.h" |
| 11 #include "mojo/public/cpp/bindings/binding.h" | 12 #include "mojo/public/cpp/bindings/binding.h" |
| 12 #include "mojo/public/cpp/bindings/callback.h" | 13 #include "mojo/public/cpp/bindings/callback.h" |
| 13 #include "mojo/public/cpp/bindings/interface_ptr.h" | 14 #include "mojo/public/cpp/bindings/interface_ptr.h" |
| 14 #include "mojo/public/cpp/bindings/interface_request.h" | 15 #include "mojo/public/cpp/bindings/interface_request.h" |
| 15 #include "mojo/public/cpp/bindings/lib/filter_chain.h" | 16 #include "mojo/public/cpp/bindings/lib/filter_chain.h" |
| 16 #include "mojo/public/cpp/bindings/lib/message_header_validator.h" | 17 #include "mojo/public/cpp/bindings/lib/message_header_validator.h" |
| 17 #include "mojo/public/cpp/bindings/lib/router.h" | 18 #include "mojo/public/cpp/bindings/lib/router.h" |
| 18 #include "mojo/public/cpp/system/core.h" | 19 #include "mojo/public/cpp/system/core.h" |
| (...skipping 29 matching lines...) Expand all Loading... |
| 48 MOJO_MOVE_ONLY_TYPE(StrongBinding) | 49 MOJO_MOVE_ONLY_TYPE(StrongBinding) |
| 49 | 50 |
| 50 public: | 51 public: |
| 51 explicit StrongBinding(Interface* impl) : binding_(impl) {} | 52 explicit StrongBinding(Interface* impl) : binding_(impl) {} |
| 52 | 53 |
| 53 StrongBinding( | 54 StrongBinding( |
| 54 Interface* impl, | 55 Interface* impl, |
| 55 ScopedMessagePipeHandle handle, | 56 ScopedMessagePipeHandle handle, |
| 56 const MojoAsyncWaiter* waiter = Environment::GetDefaultAsyncWaiter()) | 57 const MojoAsyncWaiter* waiter = Environment::GetDefaultAsyncWaiter()) |
| 57 : StrongBinding(impl) { | 58 : StrongBinding(impl) { |
| 58 Bind(handle.Pass(), waiter); | 59 Bind(std::move(handle), waiter); |
| 59 } | 60 } |
| 60 | 61 |
| 61 StrongBinding( | 62 StrongBinding( |
| 62 Interface* impl, | 63 Interface* impl, |
| 63 InterfacePtr<Interface>* ptr, | 64 InterfacePtr<Interface>* ptr, |
| 64 const MojoAsyncWaiter* waiter = Environment::GetDefaultAsyncWaiter()) | 65 const MojoAsyncWaiter* waiter = Environment::GetDefaultAsyncWaiter()) |
| 65 : StrongBinding(impl) { | 66 : StrongBinding(impl) { |
| 66 Bind(ptr, waiter); | 67 Bind(ptr, waiter); |
| 67 } | 68 } |
| 68 | 69 |
| 69 StrongBinding( | 70 StrongBinding( |
| 70 Interface* impl, | 71 Interface* impl, |
| 71 InterfaceRequest<Interface> request, | 72 InterfaceRequest<Interface> request, |
| 72 const MojoAsyncWaiter* waiter = Environment::GetDefaultAsyncWaiter()) | 73 const MojoAsyncWaiter* waiter = Environment::GetDefaultAsyncWaiter()) |
| 73 : StrongBinding(impl) { | 74 : StrongBinding(impl) { |
| 74 Bind(request.Pass(), waiter); | 75 Bind(std::move(request), waiter); |
| 75 } | 76 } |
| 76 | 77 |
| 77 ~StrongBinding() {} | 78 ~StrongBinding() {} |
| 78 | 79 |
| 79 void Bind( | 80 void Bind( |
| 80 ScopedMessagePipeHandle handle, | 81 ScopedMessagePipeHandle handle, |
| 81 const MojoAsyncWaiter* waiter = Environment::GetDefaultAsyncWaiter()) { | 82 const MojoAsyncWaiter* waiter = Environment::GetDefaultAsyncWaiter()) { |
| 82 assert(!binding_.is_bound()); | 83 assert(!binding_.is_bound()); |
| 83 binding_.Bind(handle.Pass(), waiter); | 84 binding_.Bind(std::move(handle), waiter); |
| 84 binding_.set_connection_error_handler([this]() { OnConnectionError(); }); | 85 binding_.set_connection_error_handler([this]() { OnConnectionError(); }); |
| 85 } | 86 } |
| 86 | 87 |
| 87 void Bind( | 88 void Bind( |
| 88 InterfacePtr<Interface>* ptr, | 89 InterfacePtr<Interface>* ptr, |
| 89 const MojoAsyncWaiter* waiter = Environment::GetDefaultAsyncWaiter()) { | 90 const MojoAsyncWaiter* waiter = Environment::GetDefaultAsyncWaiter()) { |
| 90 assert(!binding_.is_bound()); | 91 assert(!binding_.is_bound()); |
| 91 binding_.Bind(ptr, waiter); | 92 binding_.Bind(ptr, waiter); |
| 92 binding_.set_connection_error_handler([this]() { OnConnectionError(); }); | 93 binding_.set_connection_error_handler([this]() { OnConnectionError(); }); |
| 93 } | 94 } |
| 94 | 95 |
| 95 void Bind( | 96 void Bind( |
| 96 InterfaceRequest<Interface> request, | 97 InterfaceRequest<Interface> request, |
| 97 const MojoAsyncWaiter* waiter = Environment::GetDefaultAsyncWaiter()) { | 98 const MojoAsyncWaiter* waiter = Environment::GetDefaultAsyncWaiter()) { |
| 98 assert(!binding_.is_bound()); | 99 assert(!binding_.is_bound()); |
| 99 binding_.Bind(request.Pass(), waiter); | 100 binding_.Bind(std::move(request), waiter); |
| 100 binding_.set_connection_error_handler([this]() { OnConnectionError(); }); | 101 binding_.set_connection_error_handler([this]() { OnConnectionError(); }); |
| 101 } | 102 } |
| 102 | 103 |
| 103 bool WaitForIncomingMethodCall() { | 104 bool WaitForIncomingMethodCall() { |
| 104 return binding_.WaitForIncomingMethodCall(); | 105 return binding_.WaitForIncomingMethodCall(); |
| 105 } | 106 } |
| 106 | 107 |
| 107 // Note: The error handler must not delete the interface implementation. | 108 // Note: The error handler must not delete the interface implementation. |
| 108 // | 109 // |
| 109 // This method may only be called after this StrongBinding has been bound to a | 110 // This method may only be called after this StrongBinding has been bound to a |
| (...skipping 13 matching lines...) Expand all Loading... |
| 123 } | 124 } |
| 124 | 125 |
| 125 private: | 126 private: |
| 126 Closure connection_error_handler_; | 127 Closure connection_error_handler_; |
| 127 Binding<Interface> binding_; | 128 Binding<Interface> binding_; |
| 128 }; | 129 }; |
| 129 | 130 |
| 130 } // namespace mojo | 131 } // namespace mojo |
| 131 | 132 |
| 132 #endif // MOJO_PUBLIC_CPP_BINDINGS_STRONG_BINDING_H_ | 133 #endif // MOJO_PUBLIC_CPP_BINDINGS_STRONG_BINDING_H_ |
| OLD | NEW |