OLD | NEW |
| (Empty) |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 // Helpers for using |ServiceProvider|s. | |
6 | |
7 #ifndef MOJO_PUBLIC_CPP_APPLICATION_CONNECT_H_ | |
8 #define MOJO_PUBLIC_CPP_APPLICATION_CONNECT_H_ | |
9 | |
10 #include "mojo/public/cpp/bindings/interface_handle.h" | |
11 #include "mojo/public/cpp/bindings/interface_request.h" | |
12 #include "mojo/public/interfaces/application/application_connector.mojom.h" | |
13 #include "mojo/public/interfaces/application/service_provider.mojom.h" | |
14 #include "mojo/public/interfaces/application/shell.mojom.h" | |
15 | |
16 namespace mojo { | |
17 | |
18 // Helper for using a |ServiceProvider|'s |ConnectToService()| that takes a | |
19 // fully-typed interface request (and can use the default interface name). Note | |
20 // that this can be used in conjunction with |GetProxy()|, etc. E.g.: | |
21 // | |
22 // FooPtr foo; | |
23 // ConnectToService(service_provider, GetProxy(&foo)); | |
24 template <typename Interface> | |
25 inline void ConnectToService( | |
26 ServiceProvider* service_provider, | |
27 InterfaceRequest<Interface> interface_request, | |
28 const std::string& interface_name = Interface::Name_) { | |
29 service_provider->ConnectToService(interface_name, | |
30 interface_request.PassMessagePipe()); | |
31 } | |
32 | |
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 | |
35 // |GetProxy()|.) | |
36 template <typename Interface> | |
37 inline void ConnectToService( | |
38 Shell* shell, | |
39 const std::string& application_url, | |
40 InterfaceRequest<Interface> interface_request, | |
41 const std::string& interface_name = Interface::Name_) { | |
42 ServiceProviderPtr service_provider; | |
43 shell->ConnectToApplication(application_url, GetProxy(&service_provider)); | |
44 ConnectToService(service_provider.get(), interface_request.Pass(), | |
45 interface_name); | |
46 } | |
47 | |
48 // Helper for connecting to an application (specified by URL) using an | |
49 // |ApplicationConnector| and then a service from it. (As above, this is typed | |
50 // and may be used with |GetProxy()|.) | |
51 template <typename Interface> | |
52 inline void ConnectToService(ApplicationConnector* application_connector, | |
53 const std::string& application_url, | |
54 InterfaceRequest<Interface> request) { | |
55 ServiceProviderPtr service_provider; | |
56 application_connector->ConnectToApplication(application_url, | |
57 GetProxy(&service_provider)); | |
58 ConnectToService(service_provider.get(), request.Pass()); | |
59 } | |
60 | |
61 // Helper for getting an |InterfaceHandle<ApplicationConnector>| (which can be | |
62 // passed to any thread) from the shell. | |
63 InterfaceHandle<ApplicationConnector> CreateApplicationConnector(Shell* shell); | |
64 | |
65 // Helper for "duplicating" a |ApplicationConnector| (typically, from an | |
66 // |ApplicationConnectorPtr|, getting another independent | |
67 // |InterfaceHandle<ApplicationConnector>|). | |
68 InterfaceHandle<ApplicationConnector> DuplicateApplicationConnector( | |
69 ApplicationConnector* application_connector); | |
70 | |
71 } // namespace mojo | |
72 | |
73 #endif // MOJO_PUBLIC_CPP_APPLICATION_CONNECT_H_ | |
OLD | NEW |