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_APPLICATION_APPLICATION_CONNECTION_H_ | 5 #ifndef MOJO_PUBLIC_APPLICATION_APPLICATION_CONNECTION_H_ |
6 #define MOJO_PUBLIC_APPLICATION_APPLICATION_CONNECTION_H_ | 6 #define MOJO_PUBLIC_APPLICATION_APPLICATION_CONNECTION_H_ |
7 | 7 |
8 #include <memory> | |
9 #include <string> | |
10 | |
11 #include "mojo/public/cpp/application/lib/interface_factory_connector.h" | |
12 #include "mojo/public/cpp/application/service_provider_impl.h" | 8 #include "mojo/public/cpp/application/service_provider_impl.h" |
13 #include "mojo/public/interfaces/application/service_provider.mojom.h" | |
14 | 9 |
15 namespace mojo { | 10 namespace mojo { |
16 | 11 |
17 struct ConnectionContext; | |
18 class ServiceConnector; | |
19 | |
20 // Represents a connection to another application. An instance of this class is | 12 // Represents a connection to another application. An instance of this class is |
21 // passed to ApplicationDelegate's ConfigureIncomingConnection() method each | 13 // passed to ApplicationDelegate's ConfigureIncomingConnection() method each |
22 // time a connection is made to this app, and is returned by the | 14 // time a connection is made to this app, and is returned by the |
23 // ApplicationDelegate's ConnectToApplication() method when this app | 15 // ApplicationDelegate's ConnectToApplication() method when this app |
24 // connects to another. | 16 // connects to another. |
25 // | |
26 // To use, define a class that implements your specific service API (e.g., | |
27 // FooImpl to implement a service named Foo). Then implement an | |
28 // InterfaceFactory<Foo> that binds instances of FooImpl to | |
29 // InterfaceRequest<Foo>s and register that on the connection like this: | |
30 // | |
31 // connection->AddService(&factory); | |
32 // | |
33 // Or, if you have multiple factories implemented by the same type, explicitly | |
34 // specify the interface to register the factory for: | |
35 // | |
36 // connection->AddService<Foo>(&my_foo_and_bar_factory_); | |
37 // connection->AddService<Bar>(&my_foo_and_bar_factory_); | |
38 // | |
39 // The InterfaceFactory must outlive the ApplicationConnection. | |
40 // | |
41 // TODO(vtl): Don't get too attached to this class. I'm going to remove it. | 17 // TODO(vtl): Don't get too attached to this class. I'm going to remove it. |
42 class ApplicationConnection { | 18 class ApplicationConnection { |
43 public: | 19 public: |
44 virtual ~ApplicationConnection(); | 20 virtual ~ApplicationConnection(); |
45 | 21 |
46 // Makes Interface available as a service to the remote application. | |
47 // |factory| will create implementations of Interface on demand. | |
48 template <typename Interface> | |
49 void AddService(InterfaceFactory<Interface>* factory) { | |
50 GetServiceProviderImpl().AddServiceForName( | |
51 std::unique_ptr<ServiceConnector>( | |
52 new internal::InterfaceFactoryConnector<Interface>(factory)), | |
53 Interface::Name_); | |
54 } | |
55 | |
56 virtual ServiceProviderImpl& GetServiceProviderImpl() = 0; | 22 virtual ServiceProviderImpl& GetServiceProviderImpl() = 0; |
57 }; | 23 }; |
58 | 24 |
59 } // namespace mojo | 25 } // namespace mojo |
60 | 26 |
61 #endif // MOJO_PUBLIC_APPLICATION_APPLICATION_CONNECTION_H_ | 27 #endif // MOJO_PUBLIC_APPLICATION_APPLICATION_CONNECTION_H_ |
OLD | NEW |