diff options
author | davemoore@chromium.org <davemoore@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-06-25 21:57:02 +0000 |
---|---|---|
committer | davemoore@chromium.org <davemoore@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-06-25 21:57:02 +0000 |
commit | 8fc44a9f0c97c5f2e61fc8125a4822a057c67446 (patch) | |
tree | 0e3745a55a87d85cc5463b4a157aadccd0713c45 /mojo/public/cpp/application/application_connection.h | |
parent | cf0c55a04cc3cb7e996d823eaf574e70d305a303 (diff) | |
download | chromium_src-8fc44a9f0c97c5f2e61fc8125a4822a057c67446.zip chromium_src-8fc44a9f0c97c5f2e61fc8125a4822a057c67446.tar.gz chromium_src-8fc44a9f0c97c5f2e61fc8125a4822a057c67446.tar.bz2 |
Split ServiceProvider into 3
BUG=
R=darin@chromium.org, qsr@chromium.org
Review URL: https://codereview.chromium.org/347333002
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@279830 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'mojo/public/cpp/application/application_connection.h')
-rw-r--r-- | mojo/public/cpp/application/application_connection.h | 106 |
1 files changed, 106 insertions, 0 deletions
diff --git a/mojo/public/cpp/application/application_connection.h b/mojo/public/cpp/application/application_connection.h new file mode 100644 index 0000000..2044af1 --- /dev/null +++ b/mojo/public/cpp/application/application_connection.h @@ -0,0 +1,106 @@ +// 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_APPLICATION_APPLICATION_CONNECTION_H_ +#define MOJO_PUBLIC_APPLICATION_APPLICATION_CONNECTION_H_ + +#include <string> + +#include "mojo/public/cpp/application/lib/service_connector.h" + +namespace mojo { + +// An instance of this class is passed to +// ApplicationDelegate's ConfigureIncomingConnection() method each time a +// connection is made to this app, and to ApplicationDelegate's +// ConfigureOutgoingConnection() method when the app connects to +// another. +// +// To use define a class that implements your specific service api, e.g. FooImpl +// to implement a service named Foo. +// That class must subclass an InterfaceImpl specialization. +// +// If there is context that is to be shared amongst all instances, define a +// constructor with that class as its only argument, otherwise define an empty +// constructor. +// +// class FooImpl : public InterfaceImpl<Foo> { +// public: +// explicit FooImpl(ApplicationConnnection* connection) {} +// }; +// +// or +// +// class BarImpl : public InterfaceImpl<Bar> { +// public: +// // contexts will remain valid for the lifetime of BarImpl. +// BarImpl(ApplicationConnnection* connection, BarContext* service_context) +// : connection_(connection), servicecontext_(context) {} +// +// Create an ApplicationDelegate instance and pass it to the constructor +// of an ApplicationImpl. The delegate will be called when new connections are +// made to other applications. +// +// connection->AddService<FooImpl>(); +// +// BarContext context; +// connection->AddService<BarImpl>(&context); +class ApplicationConnection { + public: + virtual ~ApplicationConnection(); + + // Impl’s constructor will receive two arguments: + // Impl::Impl(Application::Context* app_context, + // ServiceContext* svc_context) + template <typename Impl, typename ServiceContext> + void AddService(ServiceContext* context) { + AddServiceConnector( + new internal::ServiceConnector<Impl, ServiceContext>(Impl::Name_, + context)); + } + + // Impl’s constructor will receive one argument: + // Impl::Impl(Application::Context* app_context) + template <typename Impl> + void AddService() { + AddServiceConnector( + new internal::ServiceConnector<Impl, void>(Impl::Name_, NULL)); + } + + // Connect to the service implementing |Interface|. + template <typename Interface> + void ConnectToService(InterfacePtr<Interface>* ptr) { + MessagePipe pipe; + ptr->Bind(pipe.handle0.Pass()); + GetServiceProvider()->ConnectToService(Interface::Name_, + pipe.handle1.Pass()); + } + + // The url identifying the application on the other end of this connection. + virtual const std::string& GetRemoteApplicationURL() = 0; + + // Establishes a new connection to an application. + // TODO(davemoore): Would it be better to expose the ApplicationImpl? + virtual ApplicationConnection* ConnectToApplication( + const std::string& url) = 0; + + // Connect to application identified by |application_url| and connect to + // the service implementation of the interface identified by |Interface|. + template <typename Interface> + void ConnectToService(const std::string& application_url, + InterfacePtr<Interface>* ptr) { + ConnectToApplication(application_url)->ConnectToService(ptr); + } + + // Raw ServiceProvider interface to remote application. + virtual ServiceProvider* GetServiceProvider() = 0; + +private: + virtual void AddServiceConnector( + internal::ServiceConnectorBase* service_connector) = 0; +}; + +} // namespace mojo + +#endif // MOJO_PUBLIC_APPLICATION_APPLICATION_CONNECTION_H_ |