Chromium Code Reviews| 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_H_ | 5 #ifndef MOJO_PUBLIC_CPP_BINDINGS_INTERFACE_H_ |
| 6 #define MOJO_PUBLIC_CPP_BINDINGS_INTERFACE_H_ | 6 #define MOJO_PUBLIC_CPP_BINDINGS_INTERFACE_H_ |
| 7 | 7 |
| 8 #include <assert.h> | 8 #include <assert.h> |
| 9 | 9 |
| 10 #include "mojo/public/cpp/bindings/message.h" | 10 #include "mojo/public/cpp/bindings/message.h" |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 56 typedef InterfaceHandle<S> Handle; | 56 typedef InterfaceHandle<S> Handle; |
| 57 typedef ScopedHandleBase<InterfaceHandle<S> > ScopedHandle; | 57 typedef ScopedHandleBase<InterfaceHandle<S> > ScopedHandle; |
| 58 }; | 58 }; |
| 59 | 59 |
| 60 template <> | 60 template <> |
| 61 struct Interface<mojo::NoInterface> { | 61 struct Interface<mojo::NoInterface> { |
| 62 typedef MessagePipeHandle Handle; | 62 typedef MessagePipeHandle Handle; |
| 63 typedef ScopedMessagePipeHandle ScopedHandle; | 63 typedef ScopedMessagePipeHandle ScopedHandle; |
| 64 }; | 64 }; |
| 65 | 65 |
| 66 // Use to convert from a ScopedMessagePipeHandle to an scoped interface | |
| 67 // handle. For example, | |
| 68 // ConvertToInterface<OmniboxPage>(message_pip_handle.Pass()), | |
|
vtl
2014/04/03 14:58:30
drive-by nit: message_pip -> message_pipe
| |
| 69 // where OmniboxPage names an interface in a mojom file. | |
| 70 template <typename S> | |
| 71 typename Interface<S>::ScopedHandle ConvertToInterface( | |
| 72 ScopedMessagePipeHandle message_pipe_handle) { | |
| 73 return Interface<S>::ScopedHandle( | |
| 74 Interface<S>::Handle(message_pipe_handle.release().value())); | |
| 75 } | |
| 66 | 76 |
| 67 // InterfacePipe<S,P> is used to construct a MessagePipe with typed interfaces | 77 // InterfacePipe<S,P> is used to construct a MessagePipe with typed interfaces |
| 68 // on either end. | 78 // on either end. |
| 69 | 79 |
| 70 template <typename S, typename P = typename S::_Peer> | 80 template <typename S, typename P = typename S::_Peer> |
| 71 class InterfacePipe { | 81 class InterfacePipe { |
| 72 public: | 82 public: |
| 73 InterfacePipe() { | 83 InterfacePipe() { |
| 74 typename Interface<S>::Handle h0; | 84 typename Interface<S>::Handle h0; |
| 75 typename Interface<P>::Handle h1; | 85 typename Interface<P>::Handle h1; |
| 76 MojoResult result MOJO_ALLOW_UNUSED = | 86 MojoResult result MOJO_ALLOW_UNUSED = |
| 77 MojoCreateMessagePipe(h0.mutable_value(), h1.mutable_value()); | 87 MojoCreateMessagePipe(h0.mutable_value(), h1.mutable_value()); |
| 78 assert(result == MOJO_RESULT_OK); | 88 assert(result == MOJO_RESULT_OK); |
| 79 handle_to_self.reset(h0); | 89 handle_to_self.reset(h0); |
| 80 handle_to_peer.reset(h1); | 90 handle_to_peer.reset(h1); |
| 81 } | 91 } |
| 82 | 92 |
| 83 typename Interface<S>::ScopedHandle handle_to_self; | 93 typename Interface<S>::ScopedHandle handle_to_self; |
| 84 typename Interface<P>::ScopedHandle handle_to_peer; | 94 typename Interface<P>::ScopedHandle handle_to_peer; |
| 85 }; | 95 }; |
| 86 | 96 |
| 87 // TODO(darin): Once we have the ability to use C++11 features, consider | 97 // TODO(darin): Once we have the ability to use C++11 features, consider |
| 88 // defining a template alias for ScopedInterfaceHandle<S>. | 98 // defining a template alias for ScopedInterfaceHandle<S>. |
| 89 | 99 |
| 90 } // namespace mojo | 100 } // namespace mojo |
| 91 | 101 |
| 92 #endif // MOJO_PUBLIC_CPP_BINDINGS_INTERFACE_H_ | 102 #endif // MOJO_PUBLIC_CPP_BINDINGS_INTERFACE_H_ |
| OLD | NEW |