diff options
Diffstat (limited to 'mojo/public')
-rw-r--r-- | mojo/public/cpp/application/DEPS (renamed from mojo/public/cpp/shell/DEPS) | 2 | ||||
-rw-r--r-- | mojo/public/cpp/application/application.h (renamed from mojo/public/cpp/shell/application.h) | 29 | ||||
-rw-r--r-- | mojo/public/cpp/application/connect.h | 26 | ||||
-rw-r--r-- | mojo/public/cpp/application/lib/application.cc (renamed from mojo/public/cpp/shell/lib/application.cc) | 17 | ||||
-rw-r--r-- | mojo/public/cpp/application/lib/service_connector.cc (renamed from mojo/public/cpp/shell/lib/service_connector.cc) | 9 | ||||
-rw-r--r-- | mojo/public/cpp/application/lib/service_connector.h (renamed from mojo/public/cpp/shell/lib/service_connector.h) | 22 | ||||
-rw-r--r-- | mojo/public/cpp/shell/connect.h | 25 | ||||
-rw-r--r-- | mojo/public/interfaces/service_provider/service_provider.mojom (renamed from mojo/public/interfaces/shell/shell.mojom) | 12 |
8 files changed, 72 insertions, 70 deletions
diff --git a/mojo/public/cpp/shell/DEPS b/mojo/public/cpp/application/DEPS index 7432ab1..a0e2b06 100644 --- a/mojo/public/cpp/shell/DEPS +++ b/mojo/public/cpp/application/DEPS @@ -1,4 +1,4 @@ include_rules = [ "+mojo/public/cpp/bindings", - "+mojo/public/interfaces/shell", + "+mojo/public/interfaces/service_provider", ] diff --git a/mojo/public/cpp/shell/application.h b/mojo/public/cpp/application/application.h index 3e016d1..58e9d05 100644 --- a/mojo/public/cpp/shell/application.h +++ b/mojo/public/cpp/application/application.h @@ -2,19 +2,19 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#ifndef MOJO_PUBLIC_SHELL_APPLICATION_H_ -#define MOJO_PUBLIC_SHELL_APPLICATION_H_ +#ifndef MOJO_PUBLIC_APPLICATION_APPLICATION_H_ +#define MOJO_PUBLIC_APPLICATION_APPLICATION_H_ #include <vector> -#include "mojo/public/cpp/shell/connect.h" -#include "mojo/public/cpp/shell/lib/service_connector.h" +#include "mojo/public/cpp/application/connect.h" +#include "mojo/public/cpp/application/lib/service_connector.h" #include "mojo/public/cpp/system/core.h" -#include "mojo/public/interfaces/shell/shell.mojom.h" +#include "mojo/public/interfaces/service_provider/service_provider.mojom.h" namespace mojo { -// Utility class for creating ShellClients that vend service instances. +// Utility class for creating ServiceProviders that vend service instances. // To use define a class that implements your specific server api, e.g. FooImpl // to implement a service named Foo. // That class must subclass an InterfaceImpl specialization. @@ -40,7 +40,7 @@ namespace mojo { // // Create an Application instance that collects any service implementations. // -// Application app(shell_handle); +// Application app(service_provider_handle); // app.AddService<FooImpl>(); // // BarContext context; @@ -49,8 +49,8 @@ namespace mojo { // class Application : public internal::ServiceConnectorBase::Owner { public: - explicit Application(ScopedMessagePipeHandle shell_handle); - explicit Application(MojoHandle shell_handle); + explicit Application(ScopedMessagePipeHandle service_provider_handle); + explicit Application(MojoHandle service_provider_handle); virtual ~Application(); template <typename Impl, typename Context> @@ -64,15 +64,16 @@ class Application : public internal::ServiceConnectorBase::Owner { } template <typename Interface> - void ConnectTo(const std::string& url, InterfacePtr<Interface>* ptr) { - mojo::ConnectTo(shell(), url, ptr); + void ConnectTo(const std::string& url, + InterfacePtr<Interface>* ptr) { + mojo::ConnectToService(service_provider(), url, ptr); } protected: - // ShellClient methods. + // ServiceProvider methods. // Override this to dispatch to correct service when there's more than one. // TODO(davemoore): Augment this with name registration. - virtual void AcceptConnection(const mojo::String& url, + virtual void ConnectToService(const mojo::String& url, ScopedMessagePipeHandle client_handle) MOJO_OVERRIDE; @@ -90,4 +91,4 @@ class Application : public internal::ServiceConnectorBase::Owner { } // namespace mojo -#endif // MOJO_PUBLIC_SHELL_APPLICATION_H_ +#endif // MOJO_PUBLIC_APPLICATION_APPLICATION_H_ diff --git a/mojo/public/cpp/application/connect.h b/mojo/public/cpp/application/connect.h new file mode 100644 index 0000000..1f81dea --- /dev/null +++ b/mojo/public/cpp/application/connect.h @@ -0,0 +1,26 @@ +// Copyright 2014 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef MOJO_PUBLIC_CPP_APPLICATION_CONNECT_H_ +#define MOJO_PUBLIC_CPP_APPLICATION_CONNECT_H_ + +#include "mojo/public/cpp/bindings/allocation_scope.h" +#include "mojo/public/interfaces/service_provider/service_provider.mojom.h" + +namespace mojo { + +template <typename Interface> +inline void ConnectToService(ServiceProvider* service_provider, + const std::string& url, + InterfacePtr<Interface>* ptr) { + MessagePipe pipe; + ptr->Bind(pipe.handle0.Pass()); + + AllocationScope scope; + service_provider->ConnectToService(url, pipe.handle1.Pass()); +} + +} // namespace mojo + +#endif // MOJO_PUBLIC_CPP_APPLICATION_CONNECT_H_ diff --git a/mojo/public/cpp/shell/lib/application.cc b/mojo/public/cpp/application/lib/application.cc index 161e4e0..72ce5802 100644 --- a/mojo/public/cpp/shell/lib/application.cc +++ b/mojo/public/cpp/application/lib/application.cc @@ -2,17 +2,18 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "mojo/public/cpp/shell/application.h" +#include "mojo/public/cpp/application/application.h" namespace mojo { -Application::Application(ScopedMessagePipeHandle shell_handle) - : internal::ServiceConnectorBase::Owner(shell_handle.Pass()) { +Application::Application(ScopedMessagePipeHandle service_provider_handle) + : internal::ServiceConnectorBase::Owner(service_provider_handle.Pass()) { } -Application::Application(MojoHandle shell_handle) +Application::Application(MojoHandle service_provider_handle) : internal::ServiceConnectorBase::Owner( - mojo::MakeScopedHandle(MessagePipeHandle(shell_handle)).Pass()) {} + mojo::MakeScopedHandle( + MessagePipeHandle(service_provider_handle)).Pass()) {} Application::~Application() { for (ServiceConnectorList::iterator it = service_connectors_.begin(); @@ -38,16 +39,16 @@ void Application::RemoveServiceConnector( } } if (service_connectors_.empty()) - shell_.reset(); + service_provider_.reset(); } -void Application::AcceptConnection(const mojo::String& url, +void Application::ConnectToService(const mojo::String& url, ScopedMessagePipeHandle client_handle) { // TODO(davemoore): This method must be overridden by an Application subclass // to dispatch to the right ServiceConnector. We need to figure out an // approach to registration to make this better. assert(1 == service_connectors_.size()); - return service_connectors_.front()->AcceptConnection(url.To<std::string>(), + return service_connectors_.front()->ConnectToService(url.To<std::string>(), client_handle.Pass()); } diff --git a/mojo/public/cpp/shell/lib/service_connector.cc b/mojo/public/cpp/application/lib/service_connector.cc index bdd1f3f..10bda99 100644 --- a/mojo/public/cpp/shell/lib/service_connector.cc +++ b/mojo/public/cpp/application/lib/service_connector.cc @@ -2,14 +2,15 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "mojo/public/cpp/shell/lib/service_connector.h" +#include "mojo/public/cpp/application/lib/service_connector.h" namespace mojo { namespace internal { -ServiceConnectorBase::Owner::Owner(ScopedMessagePipeHandle shell_handle) { - shell_.Bind(shell_handle.Pass()); - shell_.set_client(this); +ServiceConnectorBase::Owner::Owner( + ScopedMessagePipeHandle service_provider_handle) { + service_provider_.Bind(service_provider_handle.Pass()); + service_provider_.set_client(this); } ServiceConnectorBase::Owner::~Owner() {} diff --git a/mojo/public/cpp/shell/lib/service_connector.h b/mojo/public/cpp/application/lib/service_connector.h index 421cb72..8dda334 100644 --- a/mojo/public/cpp/shell/lib/service_connector.h +++ b/mojo/public/cpp/application/lib/service_connector.h @@ -2,15 +2,15 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#ifndef MOJO_PUBLIC_CPP_SHELL_LIB_SERVICE_CONNECTOR_H_ -#define MOJO_PUBLIC_CPP_SHELL_LIB_SERVICE_CONNECTOR_H_ +#ifndef MOJO_PUBLIC_CPP_APPLICATION_LIB_SERVICE_CONNECTOR_H_ +#define MOJO_PUBLIC_CPP_APPLICATION_LIB_SERVICE_CONNECTOR_H_ #include <assert.h> #include <vector> #include "mojo/public/cpp/bindings/allocation_scope.h" -#include "mojo/public/interfaces/shell/shell.mojom.h" +#include "mojo/public/interfaces/service_provider/service_provider.mojom.h" namespace mojo { namespace internal { @@ -61,11 +61,11 @@ struct ServiceConstructor<ServiceImpl, void> { class ServiceConnectorBase { public: - class Owner : public ShellClient { + class Owner : public ServiceProvider { public: - Owner(ScopedMessagePipeHandle shell_handle); + Owner(ScopedMessagePipeHandle service_provider_handle); virtual ~Owner(); - Shell* shell() { return shell_.get(); } + ServiceProvider* service_provider() { return service_provider_.get(); } virtual void AddServiceConnector( internal::ServiceConnectorBase* service_connector) = 0; virtual void RemoveServiceConnector( @@ -76,12 +76,12 @@ class ServiceConnectorBase { Owner* owner) { service_connector->owner_ = owner; } - ShellPtr shell_; + ServiceProviderPtr service_provider_; }; ServiceConnectorBase() : owner_(NULL) {} virtual ~ServiceConnectorBase(); - Shell* shell() { return owner_->shell(); } - virtual void AcceptConnection(const std::string& url, + ServiceProvider* service_provider() { return owner_->service_provider(); } + virtual void ConnectToService(const std::string& url, ScopedMessagePipeHandle client_handle) = 0; protected: @@ -103,7 +103,7 @@ class ServiceConnector : public internal::ServiceConnectorBase { assert(connections_.empty()); // No one should have added more! } - virtual void AcceptConnection(const std::string& url, + virtual void ConnectToService(const std::string& url, ScopedMessagePipeHandle handle) MOJO_OVERRIDE { ServiceConnection<ServiceImpl, Context>* impl = ServiceConstructor<ServiceImpl, Context>::New(context_); @@ -138,4 +138,4 @@ class ServiceConnector : public internal::ServiceConnectorBase { } // namespace internal } // namespace mojo -#endif // MOJO_PUBLIC_CPP_SHELL_LIB_SERVICE_CONNECTOR_H_ +#endif // MOJO_PUBLIC_CPP_APPLICATION_LIB_SERVICE_CONNECTOR_H_ diff --git a/mojo/public/cpp/shell/connect.h b/mojo/public/cpp/shell/connect.h deleted file mode 100644 index caee589..0000000 --- a/mojo/public/cpp/shell/connect.h +++ /dev/null @@ -1,25 +0,0 @@ -// Copyright 2014 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef MOJO_PUBLIC_CPP_SHELL_CONNECT_H_ -#define MOJO_PUBLIC_CPP_SHELL_CONNECT_H_ - -#include "mojo/public/cpp/bindings/allocation_scope.h" -#include "mojo/public/interfaces/shell/shell.mojom.h" - -namespace mojo { - -template <typename Interface> -inline void ConnectTo(Shell* shell, const std::string& url, - InterfacePtr<Interface>* ptr) { - MessagePipe pipe; - ptr->Bind(pipe.handle0.Pass()); - - AllocationScope scope; - shell->Connect(url, pipe.handle1.Pass()); -} - -} // namespace mojo - -#endif // MOJO_PUBLIC_CPP_SHELL_CONNECT_H_ diff --git a/mojo/public/interfaces/shell/shell.mojom b/mojo/public/interfaces/service_provider/service_provider.mojom index e5f6c39..85484eb 100644 --- a/mojo/public/interfaces/shell/shell.mojom +++ b/mojo/public/interfaces/service_provider/service_provider.mojom @@ -4,15 +4,13 @@ module mojo { -[Client=ShellClient] -interface Shell { +// ServiceProviders can forward requests to their clients. The relationship +// is symetrical. +[Client=ServiceProvider] +interface ServiceProvider { // Loads url. mojo:{service} will result in the user of the value of the // --origin flag to the shell being used. - Connect(string url, handle<message_pipe> client_handle); -}; - -interface ShellClient { - AcceptConnection(string url, handle<message_pipe> client_handle); + ConnectToService(string url, handle<message_pipe> client_handle); }; } |