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 // Helpers for using |ServiceProvider|s. | 5 // Helpers for using |ServiceProvider|s. |
6 | 6 |
7 #ifndef MOJO_PUBLIC_CPP_APPLICATION_CONNECT_H_ | 7 #ifndef MOJO_PUBLIC_CPP_APPLICATION_CONNECT_H_ |
8 #define MOJO_PUBLIC_CPP_APPLICATION_CONNECT_H_ | 8 #define MOJO_PUBLIC_CPP_APPLICATION_CONNECT_H_ |
9 | 9 |
10 #include "mojo/public/cpp/bindings/interface_handle.h" | 10 #include "mojo/public/cpp/bindings/interface_handle.h" |
(...skipping 22 matching lines...) Expand all Loading... |
33 // Helper for connecting to an application (specified by URL) using the |Shell| | 33 // Helper for connecting to an application (specified by URL) using the |Shell| |
34 // and then a service from it. (As above, this is typed and may be used with | 34 // and then a service from it. (As above, this is typed and may be used with |
35 // |GetProxy()|.) | 35 // |GetProxy()|.) |
36 template <typename Interface> | 36 template <typename Interface> |
37 inline void ConnectToService( | 37 inline void ConnectToService( |
38 Shell* shell, | 38 Shell* shell, |
39 const std::string& application_url, | 39 const std::string& application_url, |
40 InterfaceRequest<Interface> interface_request, | 40 InterfaceRequest<Interface> interface_request, |
41 const std::string& interface_name = Interface::Name_) { | 41 const std::string& interface_name = Interface::Name_) { |
42 ServiceProviderPtr service_provider; | 42 ServiceProviderPtr service_provider; |
43 shell->ConnectToApplication(application_url, GetProxy(&service_provider), | 43 shell->ConnectToApplication(application_url, GetProxy(&service_provider)); |
44 nullptr); | |
45 ConnectToService(service_provider.get(), interface_request.Pass(), | 44 ConnectToService(service_provider.get(), interface_request.Pass(), |
46 interface_name); | 45 interface_name); |
47 } | 46 } |
48 | 47 |
49 // Helper for connecting to an application (specified by URL) using an | 48 // Helper for connecting to an application (specified by URL) using an |
50 // |ApplicationConnector| and then a service from it. (As above, this is typed | 49 // |ApplicationConnector| and then a service from it. (As above, this is typed |
51 // and may be used with |GetProxy()|.) | 50 // and may be used with |GetProxy()|.) |
52 template <typename Interface> | 51 template <typename Interface> |
53 inline void ConnectToService(ApplicationConnector* application_connector, | 52 inline void ConnectToService(ApplicationConnector* application_connector, |
54 const std::string& application_url, | 53 const std::string& application_url, |
55 InterfaceRequest<Interface> request) { | 54 InterfaceRequest<Interface> request) { |
56 ServiceProviderPtr service_provider; | 55 ServiceProviderPtr service_provider; |
57 application_connector->ConnectToApplication( | 56 application_connector->ConnectToApplication(application_url, |
58 application_url, GetProxy(&service_provider), nullptr); | 57 GetProxy(&service_provider)); |
59 ConnectToService(service_provider.get(), request.Pass()); | 58 ConnectToService(service_provider.get(), request.Pass()); |
60 } | 59 } |
61 | 60 |
62 // Helper for getting an |InterfaceHandle<ApplicationConnector>| (which can be | 61 // Helper for getting an |InterfaceHandle<ApplicationConnector>| (which can be |
63 // passed to any thread) from the shell. | 62 // passed to any thread) from the shell. |
64 InterfaceHandle<ApplicationConnector> CreateApplicationConnector(Shell* shell); | 63 InterfaceHandle<ApplicationConnector> CreateApplicationConnector(Shell* shell); |
65 | 64 |
66 // Helper for "duplicating" a |ApplicationConnector| (typically, from an | 65 // Helper for "duplicating" a |ApplicationConnector| (typically, from an |
67 // |ApplicationConnectorPtr|, getting another independent | 66 // |ApplicationConnectorPtr|, getting another independent |
68 // |InterfaceHandle<ApplicationConnector>|). | 67 // |InterfaceHandle<ApplicationConnector>|). |
69 InterfaceHandle<ApplicationConnector> DuplicateApplicationConnector( | 68 InterfaceHandle<ApplicationConnector> DuplicateApplicationConnector( |
70 ApplicationConnector* application_connector); | 69 ApplicationConnector* application_connector); |
71 | 70 |
72 } // namespace mojo | 71 } // namespace mojo |
73 | 72 |
74 #endif // MOJO_PUBLIC_CPP_APPLICATION_CONNECT_H_ | 73 #endif // MOJO_PUBLIC_CPP_APPLICATION_CONNECT_H_ |
OLD | NEW |