blob: 70c13809525bea6e368029a199a36c4b1e1fd553 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
|
// 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_LIB_SERVICE_CONNECTOR_H_
#define MOJO_PUBLIC_CPP_APPLICATION_LIB_SERVICE_CONNECTOR_H_
#include "mojo/public/cpp/application/interface_factory.h"
#include "mojo/public/cpp/bindings/interface_request.h"
namespace mojo {
class ApplicationConnection;
namespace internal {
class ServiceConnectorBase {
public:
ServiceConnectorBase(const std::string& name);
virtual ~ServiceConnectorBase();
virtual void ConnectToService(const std::string& name,
ScopedMessagePipeHandle client_handle) = 0;
std::string name() const { return name_; }
void set_application_connection(ApplicationConnection* connection) {
application_connection_ = connection;
}
protected:
std::string name_;
ApplicationConnection* application_connection_;
MOJO_DISALLOW_COPY_AND_ASSIGN(ServiceConnectorBase);
};
template <typename Interface>
class InterfaceFactoryConnector : public ServiceConnectorBase {
public:
explicit InterfaceFactoryConnector(InterfaceFactory<Interface>* factory)
: ServiceConnectorBase(Interface::Name_), factory_(factory) {}
virtual ~InterfaceFactoryConnector() {}
virtual void ConnectToService(const std::string& name,
ScopedMessagePipeHandle client_handle) {
factory_->Create(application_connection_,
MakeRequest<Interface>(client_handle.Pass()));
}
private:
InterfaceFactory<Interface>* factory_;
MOJO_DISALLOW_COPY_AND_ASSIGN(InterfaceFactoryConnector);
};
} // namespace internal
} // namespace mojo
#endif // MOJO_PUBLIC_CPP_APPLICATION_LIB_SERVICE_CONNECTOR_H_
|