| 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 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 52 // }; | 52 // }; |
| 53 // | 53 // |
| 54 // or | 54 // or |
| 55 // | 55 // |
| 56 // class BarImpl : public InterfaceImpl<Bar> { | 56 // class BarImpl : public InterfaceImpl<Bar> { |
| 57 // public: | 57 // public: |
| 58 // // contexts will remain valid for the lifetime of BarImpl. | 58 // // contexts will remain valid for the lifetime of BarImpl. |
| 59 // BarImpl(ApplicationContext* app_context, BarContext* service_context) | 59 // BarImpl(ApplicationContext* app_context, BarContext* service_context) |
| 60 // : app_context_(app_context), servicecontext_(context) {} | 60 // : app_context_(app_context), servicecontext_(context) {} |
| 61 // | 61 // |
| 62 // Create an ApplicationImpl instance that collects any service implementations. | 62 // Create an ApplicationDele instance that collects any service implementations. |
| 63 // | 63 // |
| 64 // ApplicationImpl app(service_provider_handle); | 64 // ApplicationImpl app(service_provider_handle); |
| 65 // app.AddService<FooImpl>(); | 65 // app.AddService<FooImpl>(); |
| 66 // | 66 // |
| 67 // BarContext context; | 67 // BarContext context; |
| 68 // app.AddService<BarImpl>(&context); | 68 // app.AddService<BarImpl>(&context); |
| 69 // | 69 // |
| 70 // | 70 // |
| 71 class ApplicationImpl : public InterfaceImpl<Application> { | 71 class ApplicationImpl : public InterfaceImpl<Application> { |
| 72 public: | 72 public: |
| 73 explicit ApplicationImpl(ApplicationDelegate* delegate); | 73 explicit ApplicationImpl(ApplicationDelegate* delegate); |
| 74 ApplicationImpl(ApplicationDelegate* delegate, | 74 ApplicationImpl(ApplicationDelegate* delegate, |
| 75 ScopedMessagePipeHandle shell_handle); | 75 ScopedMessagePipeHandle shell_handle); |
| 76 ApplicationImpl(ApplicationDelegate* delegate, | 76 ApplicationImpl(ApplicationDelegate* delegate, |
| 77 MojoHandle shell_handle); | 77 MojoHandle shell_handle); |
| 78 virtual ~ApplicationImpl(); | 78 virtual ~ApplicationImpl(); |
| 79 | 79 |
| 80 // Establishes a new connection to an application. Caller does not own. | 80 // Establishes a new connection to an application. Caller does not own. |
| 81 ApplicationConnection* ConnectToApplication(const String& application_url); | 81 ApplicationConnection* ConnectToApplication(const String& application_url); |
| 82 | 82 |
| 83 // Connect to application identified by |application_url| and connect to the | 83 // Connect to application identified by |application_url| and connect to the |
| 84 // service implementation of the interface identified by |Interface|. | 84 // service implementation of the interface identified by |Interface|. |
| 85 template <typename Interface> | 85 template <typename Interface> |
| 86 void ConnectToService(const std::string& application_url, | 86 void ConnectToService(const std::string& application_url, |
| 87 InterfacePtr<Interface>* ptr) { | 87 InterfacePtr<Interface>* ptr) { |
| 88 ConnectToApplication(application_url)->ConnectToService(ptr); | 88 ConnectToApplication(application_url)->ConnectToService(ptr); |
| 89 } | 89 } |
| 90 | 90 |
| 91 private: | 91 private: |
| 92 class ShellPtrWatcher : public ErrorHandler { | |
| 93 public: | |
| 94 explicit ShellPtrWatcher(ApplicationImpl* impl); | |
| 95 virtual ~ShellPtrWatcher(); | |
| 96 virtual void OnConnectionError() MOJO_OVERRIDE; | |
| 97 private: | |
| 98 ApplicationImpl* impl_; | |
| 99 MOJO_DISALLOW_COPY_AND_ASSIGN(ShellPtrWatcher); | |
| 100 }; | |
| 101 | |
| 102 friend MojoResult (::MojoMain)(MojoHandle); | 92 friend MojoResult (::MojoMain)(MojoHandle); |
| 103 | 93 |
| 104 void BindShell(ScopedMessagePipeHandle shell_handle); | 94 void BindShell(ScopedMessagePipeHandle shell_handle); |
| 105 void BindShell(MojoHandle shell_handle); | 95 void BindShell(MojoHandle shell_handle); |
| 106 void ClearConnections(); | |
| 107 void OnShellError() { ClearConnections(); Terminate(); }; | |
| 108 | |
| 109 // Quits the main run loop for this application. | |
| 110 void Terminate(); | |
| 111 | 96 |
| 112 // Application implementation. | 97 // Application implementation. |
| 113 virtual void AcceptConnection(const String& requestor_url, | 98 virtual void AcceptConnection(const String& requestor_url, |
| 114 ServiceProviderPtr provider) MOJO_OVERRIDE; | 99 ServiceProviderPtr provider) MOJO_OVERRIDE; |
| 115 | 100 |
| 116 typedef std::vector<internal::ServiceRegistry*> ServiceRegistryList; | 101 typedef std::vector<internal::ServiceRegistry*> ServiceRegistryList; |
| 117 ServiceRegistryList incoming_service_registries_; | 102 ServiceRegistryList incoming_service_registries_; |
| 118 ServiceRegistryList outgoing_service_registries_; | 103 ServiceRegistryList outgoing_service_registries_; |
| 119 ApplicationDelegate* delegate_; | 104 ApplicationDelegate* delegate_; |
| 120 ShellPtr shell_; | 105 ShellPtr shell_; |
| 121 ShellPtrWatcher shell_watch_; | |
| 122 | 106 |
| 123 MOJO_DISALLOW_COPY_AND_ASSIGN(ApplicationImpl); | 107 MOJO_DISALLOW_COPY_AND_ASSIGN(ApplicationImpl); |
| 124 }; | 108 }; |
| 125 | 109 |
| 126 } // namespace mojo | 110 } // namespace mojo |
| 127 | 111 |
| 128 #endif // MOJO_PUBLIC_APPLICATION_APPLICATION_IMPL_H_ | 112 #endif // MOJO_PUBLIC_APPLICATION_APPLICATION_IMPL_H_ |
| OLD | NEW |