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_APPLICATION_CONNECT_H_ | 5 #ifndef MOJO_PUBLIC_CPP_APPLICATION_CONNECT_H_ |
6 #define MOJO_PUBLIC_CPP_APPLICATION_CONNECT_H_ | 6 #define MOJO_PUBLIC_CPP_APPLICATION_CONNECT_H_ |
7 | 7 |
| 8 #include "mojo/public/interfaces/application/application_connector.mojom.h" |
8 #include "mojo/public/interfaces/application/service_provider.mojom.h" | 9 #include "mojo/public/interfaces/application/service_provider.mojom.h" |
9 #include "mojo/public/interfaces/application/shell.mojom.h" | 10 #include "mojo/public/interfaces/application/shell.mojom.h" |
10 | 11 |
11 namespace mojo { | 12 namespace mojo { |
12 | 13 |
13 // Binds |ptr| to a remote implementation of Interface from |service_provider|. | 14 // Binds |ptr| to a remote implementation of Interface from |service_provider|. |
14 template <typename Interface> | 15 template <typename Interface> |
15 inline void ConnectToService(ServiceProvider* service_provider, | 16 inline void ConnectToService(ServiceProvider* service_provider, |
16 InterfacePtr<Interface>* ptr) { | 17 InterfacePtr<Interface>* ptr) { |
17 MessagePipe pipe; | 18 MessagePipe pipe; |
18 ptr->Bind(InterfacePtrInfo<Interface>(pipe.handle0.Pass(), 0u)); | 19 ptr->Bind(InterfacePtrInfo<Interface>(pipe.handle0.Pass(), 0u)); |
19 service_provider->ConnectToService(Interface::Name_, pipe.handle1.Pass()); | 20 service_provider->ConnectToService(Interface::Name_, pipe.handle1.Pass()); |
20 } | 21 } |
21 | 22 |
22 // Binds |ptr| to a remote implementation of Interface from |application_url|. | 23 // Binds |ptr| to a remote implementation of Interface from |application_url|. |
23 template <typename Interface> | 24 template <typename Interface> |
24 inline void ConnectToService(Shell* shell, | 25 inline void ConnectToService(Shell* shell, |
25 const std::string& application_url, | 26 const std::string& application_url, |
26 InterfacePtr<Interface>* ptr) { | 27 InterfacePtr<Interface>* ptr) { |
27 ServiceProviderPtr service_provider; | 28 ServiceProviderPtr service_provider; |
28 shell->ConnectToApplication(application_url, | 29 shell->ConnectToApplication(application_url, |
29 GetProxy(&service_provider), nullptr); | 30 GetProxy(&service_provider), nullptr); |
30 ConnectToService(service_provider.get(), ptr); | 31 ConnectToService(service_provider.get(), ptr); |
31 } | 32 } |
32 | 33 |
| 34 // Binds |ptr| to a remote implementation of Interface from |application_url|. |
| 35 template <typename Interface> |
| 36 inline void ConnectToService(ApplicationConnector* application_connector, |
| 37 const std::string& application_url, |
| 38 InterfacePtr<Interface>* ptr) { |
| 39 ServiceProviderPtr service_provider; |
| 40 application_connector->ConnectToApplication( |
| 41 application_url, GetProxy(&service_provider), nullptr); |
| 42 ConnectToService(service_provider.get(), ptr); |
| 43 } |
| 44 |
33 } // namespace mojo | 45 } // namespace mojo |
34 | 46 |
35 #endif // MOJO_PUBLIC_CPP_APPLICATION_CONNECT_H_ | 47 #endif // MOJO_PUBLIC_CPP_APPLICATION_CONNECT_H_ |
OLD | NEW |