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 // TODO(vardhan): Replaces uses of ConnectToService(.., InterfacePtr<>) with the |
| 15 // ConnectToService(.., InterfaceHandle<>) alternative instead, and get |
| 16 // rid of following 3 functions. |
| 17 |
14 // Binds |ptr| to a remote implementation of Interface from |service_provider|. | 18 // Binds |ptr| to a remote implementation of Interface from |service_provider|. |
15 template <typename Interface> | 19 template <typename Interface> |
16 inline void ConnectToService(ServiceProvider* service_provider, | 20 inline void ConnectToService(ServiceProvider* service_provider, |
17 InterfacePtr<Interface>* ptr) { | 21 InterfacePtr<Interface>* ptr) { |
18 MessagePipe pipe; | 22 MessagePipe pipe; |
19 ptr->Bind(InterfaceHandle<Interface>(pipe.handle0.Pass(), 0u)); | 23 ptr->Bind(InterfaceHandle<Interface>(pipe.handle0.Pass(), 0u)); |
20 service_provider->ConnectToService(Interface::Name_, pipe.handle1.Pass()); | 24 service_provider->ConnectToService(Interface::Name_, pipe.handle1.Pass()); |
21 } | 25 } |
22 | 26 |
23 // Binds |ptr| to a remote implementation of Interface from |application_url|. | 27 // Binds |ptr| to a remote implementation of Interface from |application_url|. |
24 template <typename Interface> | 28 template <typename Interface> |
25 inline void ConnectToService(Shell* shell, | 29 inline void ConnectToService(Shell* shell, |
26 const std::string& application_url, | 30 const std::string& application_url, |
27 InterfacePtr<Interface>* ptr) { | 31 InterfacePtr<Interface>* ptr) { |
28 ServiceProviderPtr service_provider; | 32 ServiceProviderPtr service_provider; |
29 shell->ConnectToApplication(application_url, | 33 shell->ConnectToApplication(application_url, GetProxy(&service_provider), |
30 GetProxy(&service_provider), nullptr); | 34 nullptr); |
31 ConnectToService(service_provider.get(), ptr); | 35 ConnectToService(service_provider.get(), ptr); |
32 } | 36 } |
33 | 37 |
34 // Binds |ptr| to a remote implementation of Interface from |application_url|. | 38 // Binds |ptr| to a remote implementation of Interface from |application_url|. |
35 template <typename Interface> | 39 template <typename Interface> |
36 inline void ConnectToService(ApplicationConnector* application_connector, | 40 inline void ConnectToService(ApplicationConnector* application_connector, |
37 const std::string& application_url, | 41 const std::string& application_url, |
38 InterfacePtr<Interface>* ptr) { | 42 InterfacePtr<Interface>* ptr) { |
39 ServiceProviderPtr service_provider; | 43 ServiceProviderPtr service_provider; |
40 application_connector->ConnectToApplication( | 44 application_connector->ConnectToApplication( |
41 application_url, GetProxy(&service_provider), nullptr); | 45 application_url, GetProxy(&service_provider), nullptr); |
42 ConnectToService(service_provider.get(), ptr); | 46 ConnectToService(service_provider.get(), ptr); |
43 } | 47 } |
44 | 48 |
| 49 // Binds |ptr| to a remote implementation of Interface from |service_provider|. |
| 50 template <typename Interface> |
| 51 inline void ConnectToService(ServiceProvider* service_provider, |
| 52 InterfaceHandle<Interface>* ptr) { |
| 53 MessagePipe pipe; |
| 54 *ptr = InterfaceHandle<Interface>(pipe.handle0.Pass(), 0u); |
| 55 service_provider->ConnectToService(Interface::Name_, pipe.handle1.Pass()); |
| 56 } |
| 57 |
| 58 // Binds |ptr| to a remote implementation of Interface from |application_url|. |
| 59 template <typename Interface> |
| 60 inline void ConnectToService(Shell* shell, |
| 61 const std::string& application_url, |
| 62 InterfaceHandle<Interface>* ptr) { |
| 63 ServiceProviderPtr service_provider; |
| 64 shell->ConnectToApplication(application_url, GetProxy(&service_provider), |
| 65 nullptr); |
| 66 ConnectToService(service_provider.get(), ptr); |
| 67 } |
| 68 |
| 69 // Binds |ptr| to a remote implementation of Interface from |application_url|. |
| 70 template <typename Interface> |
| 71 inline void ConnectToService(ApplicationConnector* application_connector, |
| 72 const std::string& application_url, |
| 73 InterfaceHandle<Interface>* ptr) { |
| 74 ServiceProviderPtr service_provider; |
| 75 application_connector->ConnectToApplication( |
| 76 application_url, GetProxy(&service_provider), nullptr); |
| 77 ConnectToService(service_provider.get(), ptr); |
| 78 } |
| 79 |
45 } // namespace mojo | 80 } // namespace mojo |
46 | 81 |
47 #endif // MOJO_PUBLIC_CPP_APPLICATION_CONNECT_H_ | 82 #endif // MOJO_PUBLIC_CPP_APPLICATION_CONNECT_H_ |
OLD | NEW |