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_IMPL_H_ | 5 #ifndef MOJO_PUBLIC_APPLICATION_APPLICATION_IMPL_H_ |
6 #define MOJO_PUBLIC_APPLICATION_APPLICATION_IMPL_H_ | 6 #define MOJO_PUBLIC_APPLICATION_APPLICATION_IMPL_H_ |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "mojo/public/cpp/application/application_connection.h" | 9 #include "mojo/public/cpp/application/application_connection.h" |
10 #include "mojo/public/cpp/application/lib/service_connector.h" | 10 #include "mojo/public/cpp/application/lib/service_connector.h" |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
43 // | 43 // |
44 // Create an ApplicationImpl instance that collects any service implementations. | 44 // Create an ApplicationImpl instance that collects any service implementations. |
45 // | 45 // |
46 // ApplicationImpl app(service_provider_handle); | 46 // ApplicationImpl app(service_provider_handle); |
47 // app.AddService<FooImpl>(); | 47 // app.AddService<FooImpl>(); |
48 // | 48 // |
49 // BarContext context; | 49 // BarContext context; |
50 // app.AddService<BarImpl>(&context); | 50 // app.AddService<BarImpl>(&context); |
51 // | 51 // |
52 // | 52 // |
53 class ApplicationImpl : public InterfaceImpl<Application> { | 53 class ApplicationImpl : public Application { |
54 public: | 54 public: |
55 ApplicationImpl(ApplicationDelegate* delegate, ShellPtr shell); | 55 ApplicationImpl(ApplicationDelegate* delegate, |
56 InterfaceRequest<Application> request); | |
56 ~ApplicationImpl() override; | 57 ~ApplicationImpl() override; |
57 | 58 |
58 Shell* shell() const { return shell_.get(); } | 59 Shell* shell() const { return shell_.get(); } |
59 | 60 |
60 // Returns any initial configuration arguments, passed by the Shell. | 61 // Returns any initial configuration arguments, passed by the Shell. |
61 const std::vector<std::string>& args() const { return args_; } | 62 const std::vector<std::string>& args() const { return args_; } |
62 bool HasArg(const std::string& arg) const; | 63 bool HasArg(const std::string& arg) const; |
63 | 64 |
64 // Establishes a new connection to an application. Caller does not own. | 65 // Establishes a new connection to an application. Caller does not own. |
65 ApplicationConnection* ConnectToApplication(const String& application_url); | 66 ApplicationConnection* ConnectToApplication(const String& application_url); |
66 | 67 |
67 // Connect to application identified by |application_url| and connect to the | 68 // Connect to application identified by |application_url| and connect to the |
68 // service implementation of the interface identified by |Interface|. | 69 // service implementation of the interface identified by |Interface|. |
69 template <typename Interface> | 70 template <typename Interface> |
70 void ConnectToService(const std::string& application_url, | 71 void ConnectToService(const std::string& application_url, |
71 InterfacePtr<Interface>* ptr) { | 72 InterfacePtr<Interface>* ptr) { |
72 ConnectToApplication(application_url)->ConnectToService(ptr); | 73 ConnectToApplication(application_url)->ConnectToService(ptr); |
73 } | 74 } |
74 | 75 |
75 // Unbind the shell from this application and return its handle. | 76 // Application implementation. |
76 ShellPtr UnbindShell(); | 77 void Initialize(ShellPtr shell, Array<String> args) override; |
77 | 78 |
78 // Application implementation. | 79 // Block until the Application is initialized, if it is not already. |
79 void Initialize(Array<String> args) override; | 80 void WaitForInitialize(); |
81 | |
82 // Unbinds the Shell and Application connections. Must be called after | |
83 // Initialize. | |
DaveMoore
2015/01/27 00:41:29
Nit: This seems very specific to our test infrastr
jamesr
2015/01/27 00:59:04
You could do this if you wanted to bind to another
| |
84 void UnbindConnections(InterfaceRequest<Application>* application_request, | |
85 ShellPtr* shell); | |
80 | 86 |
81 // Quits the main run loop for this application. | 87 // Quits the main run loop for this application. |
82 static void Terminate(); | 88 static void Terminate(); |
83 | 89 |
84 private: | 90 private: |
85 class ShellPtrWatcher; | 91 class ShellPtrWatcher; |
86 | 92 |
87 void ClearConnections(); | 93 void ClearConnections(); |
88 | 94 |
89 void OnShellError() { | 95 void OnShellError() { |
90 ClearConnections(); | 96 ClearConnections(); |
91 Terminate(); | 97 Terminate(); |
92 } | 98 } |
93 | 99 |
94 // Application implementation. | 100 // Application implementation. |
95 void AcceptConnection(const String& requestor_url, | 101 void AcceptConnection(const String& requestor_url, |
96 InterfaceRequest<ServiceProvider> services, | 102 InterfaceRequest<ServiceProvider> services, |
97 ServiceProviderPtr exposed_services) override; | 103 ServiceProviderPtr exposed_services) override; |
98 void RequestQuit() override; | 104 void RequestQuit() override; |
99 | 105 |
100 typedef std::vector<internal::ServiceRegistry*> ServiceRegistryList; | 106 typedef std::vector<internal::ServiceRegistry*> ServiceRegistryList; |
101 | 107 |
102 bool initialized_; | 108 bool initialized_; |
DaveMoore
2015/01/27 00:41:29
Nit: Can't initialized_ go away now?
jamesr
2015/01/27 00:59:04
Ah right, yes. It's redundant with shell_ now.
| |
103 ServiceRegistryList incoming_service_registries_; | 109 ServiceRegistryList incoming_service_registries_; |
104 ServiceRegistryList outgoing_service_registries_; | 110 ServiceRegistryList outgoing_service_registries_; |
105 ApplicationDelegate* delegate_; | 111 ApplicationDelegate* delegate_; |
112 Binding<Application> binding_; | |
106 ShellPtr shell_; | 113 ShellPtr shell_; |
107 ShellPtrWatcher* shell_watch_; | 114 ShellPtrWatcher* shell_watch_; |
108 std::vector<std::string> args_; | 115 std::vector<std::string> args_; |
109 | 116 |
110 MOJO_DISALLOW_COPY_AND_ASSIGN(ApplicationImpl); | 117 MOJO_DISALLOW_COPY_AND_ASSIGN(ApplicationImpl); |
111 }; | 118 }; |
112 | 119 |
113 } // namespace mojo | 120 } // namespace mojo |
114 | 121 |
115 #endif // MOJO_PUBLIC_APPLICATION_APPLICATION_IMPL_H_ | 122 #endif // MOJO_PUBLIC_APPLICATION_APPLICATION_IMPL_H_ |
OLD | NEW |