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