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_H_ | 5 #ifndef MOJO_PUBLIC_APPLICATION_APPLICATION_H_ |
6 #define MOJO_PUBLIC_APPLICATION_APPLICATION_H_ | 6 #define MOJO_PUBLIC_APPLICATION_APPLICATION_H_ |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "mojo/public/cpp/application/connect.h" | 9 #include "mojo/public/cpp/application/connect.h" |
10 #include "mojo/public/cpp/application/lib/service_connector.h" | 10 #include "mojo/public/cpp/application/lib/service_connector.h" |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
57 // | 57 // |
58 // Create an Application instance that collects any service implementations. | 58 // Create an Application instance that collects any service implementations. |
59 // | 59 // |
60 // Application app(service_provider_handle); | 60 // Application app(service_provider_handle); |
61 // app.AddService<FooImpl>(); | 61 // app.AddService<FooImpl>(); |
62 // | 62 // |
63 // BarContext context; | 63 // BarContext context; |
64 // app.AddService<BarImpl>(&context); | 64 // app.AddService<BarImpl>(&context); |
65 // | 65 // |
66 // | 66 // |
67 class Application : public internal::ServiceConnectorBase::Owner { | 67 class Application { |
68 public: | 68 public: |
69 Application(); | 69 Application(); |
70 explicit Application(ScopedMessagePipeHandle service_provider_handle); | 70 explicit Application(ScopedMessagePipeHandle service_provider_handle); |
71 explicit Application(MojoHandle service_provider_handle); | 71 explicit Application(MojoHandle service_provider_handle); |
72 virtual ~Application(); | 72 virtual ~Application(); |
73 | 73 |
74 virtual bool IsConnectionValid(const mojo::String& service_name, | |
darin (slow to review)
2014/06/12 16:11:51
nit: some documentation for this method would be h
DaveMoore
2014/06/12 16:28:14
Done.
| |
75 const mojo::String& requestor_url); | |
76 | |
77 template <typename Impl, typename Context> | |
78 void AddService(Context* context) { | |
79 service_registry_.AddServiceConnector( | |
80 new internal::ServiceConnector<Impl, Context>(Impl::Name_, context)); | |
81 } | |
82 | |
83 template <typename Impl> | |
84 void AddService() { | |
85 service_registry_.AddServiceConnector( | |
86 new internal::ServiceConnector<Impl, void>(Impl::Name_, NULL)); | |
87 } | |
88 | |
89 template <typename Interface> | |
90 void ConnectTo(const std::string& url, InterfacePtr<Interface>* ptr) { | |
91 mojo::ConnectToService(service_provider(), url, ptr); | |
92 } | |
93 | |
94 ServiceProvider* service_provider() { | |
95 return service_registry_.service_provider(); | |
darin (slow to review)
2014/06/12 16:11:51
nit: indentation
DaveMoore
2014/06/12 16:28:13
Done.
| |
96 } | |
97 | |
98 void BindServiceProvider(ScopedMessagePipeHandle service_provider_handle); | |
99 | |
100 protected: | |
74 // Override this to do any necessary initialization. There's no need to call | 101 // Override this to do any necessary initialization. There's no need to call |
75 // Application's implementation. | 102 // Application's implementation. |
76 // The service_provider will be bound to its pipe before this is called. | 103 // The service_provider will be bound to its pipe before this is called. |
77 virtual void Initialize(); | 104 virtual void Initialize(); |
78 | 105 |
79 template <typename Impl, typename Context> | |
80 void AddService(Context* context) { | |
81 AddServiceConnector( | |
82 new internal::ServiceConnector<Impl, Context>(Impl::Name_, context)); | |
83 } | |
84 | |
85 template <typename Impl> | |
86 void AddService() { | |
87 AddServiceConnector( | |
88 new internal::ServiceConnector<Impl, void>(Impl::Name_, NULL)); | |
89 } | |
90 | |
91 template <typename Interface> | |
92 void ConnectTo(const std::string& url, | |
93 InterfacePtr<Interface>* ptr) { | |
94 mojo::ConnectToService(service_provider(), url, ptr); | |
95 } | |
96 | |
97 ServiceProvider* service_provider() { return service_provider_.get(); } | |
98 void BindServiceProvider(ScopedMessagePipeHandle service_provider_handle); | |
99 | |
100 protected: | |
101 // ServiceProvider methods. | |
102 // Override this to dispatch to correct service when there's more than one. | |
103 virtual void ConnectToService(const mojo::String& service_url, | |
104 const mojo::String& service_name, | |
105 ScopedMessagePipeHandle client_handle, | |
106 const mojo::String& requestor_url) | |
107 MOJO_OVERRIDE; | |
108 | |
109 private: | 106 private: |
110 friend MojoResult (::MojoMain)(MojoHandle); | 107 friend MojoResult (::MojoMain)(MojoHandle); |
111 | 108 |
112 // Implement this method to create the specific subclass of Application. | 109 // Implement this method to create the specific subclass of Application. |
113 static Application* Create(); | 110 static Application* Create(); |
114 | 111 |
115 // internal::ServiceConnectorBase::Owner methods. | 112 internal::ServiceRegistry service_registry_; |
116 // Takes ownership of |service_connector|. | |
117 virtual void AddServiceConnector( | |
118 internal::ServiceConnectorBase* service_connector) MOJO_OVERRIDE; | |
119 virtual void RemoveServiceConnector( | |
120 internal::ServiceConnectorBase* service_connector) MOJO_OVERRIDE; | |
121 | 113 |
122 typedef std::map<std::string, internal::ServiceConnectorBase*> | 114 MOJO_DISALLOW_COPY_AND_ASSIGN(Application); |
123 NameToServiceConnectorMap; | |
124 NameToServiceConnectorMap name_to_service_connector_; | |
125 }; | 115 }; |
126 | 116 |
127 } // namespace mojo | 117 } // namespace mojo |
128 | 118 |
129 #endif // MOJO_PUBLIC_APPLICATION_APPLICATION_H_ | 119 #endif // MOJO_PUBLIC_APPLICATION_APPLICATION_H_ |
OLD | NEW |