Mir
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
published_socket_connector.h
Go to the documentation of this file.
1 /*
2  * Copyright © 2012 Canonical Ltd.
3  *
4  * This program is free software: you can redistribute it and/or modify it
5  * under the terms of the GNU General Public License version 3,
6  * as published by the Free Software Foundation.
7  *
8  * This program is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * GNU General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License
14  * along with this program. If not, see <http://www.gnu.org/licenses/>.
15  *
16  * Authored by: Thomas Guest <thomas.guest@canonical.com>
17  */
18 
19 #ifndef MIR_FRONTEND_PROTOBUF_ASIO_COMMUNICATOR_H_
20 #define MIR_FRONTEND_PROTOBUF_ASIO_COMMUNICATOR_H_
21 
22 #include "mir/frontend/connector.h"
23 
24 #include <boost/asio.hpp>
25 
26 #include <thread>
27 #include <string>
28 #include <vector>
29 #include <functional>
30 
31 namespace google
32 {
33 namespace protobuf
34 {
35 class Message;
36 }
37 }
38 
39 namespace mir
40 {
41 class EmergencyCleanupRegistry;
42 
43 namespace frontend
44 {
45 class ConnectionCreator;
46 class ConnectorReport;
47 
49 class BasicConnector : public Connector
50 {
51 public:
52  explicit BasicConnector(
53  std::shared_ptr<ConnectionCreator> const& connection_creator,
54  int threads,
55  std::shared_ptr<ConnectorReport> const& report);
56  ~BasicConnector() noexcept;
57  void start() override;
58  void stop() override;
59  int client_socket_fd() const override;
60  int client_socket_fd(std::function<void(std::shared_ptr<Session> const& session)> const& connect_handler) const override;
61 
62 protected:
63  void create_session_for(
64  std::shared_ptr<boost::asio::local::stream_protocol::socket> const& server_socket,
65  std::function<void(std::shared_ptr<Session> const& session)> const& connect_handler) const;
66 
67  boost::asio::io_service mutable io_service;
68  boost::asio::io_service::work work;
69  std::shared_ptr<ConnectorReport> const report;
70 
71 private:
72  std::vector<std::thread> io_service_threads;
73  std::shared_ptr<ConnectionCreator> const connection_creator;
74 };
75 
78 {
79 public:
80  explicit PublishedSocketConnector(
81  const std::string& socket_file,
82  std::shared_ptr<ConnectionCreator> const& connection_creator,
83  int threads,
84  EmergencyCleanupRegistry& emergency_cleanup_registry,
85  std::shared_ptr<ConnectorReport> const& report);
86  ~PublishedSocketConnector() noexcept;
87 
88 private:
89  void start_accept();
90  void on_new_connection(std::shared_ptr<boost::asio::local::stream_protocol::socket> const& socket,
91  boost::system::error_code const& ec);
92 
93  const std::string socket_file;
94  boost::asio::local::stream_protocol::acceptor acceptor;
95 };
96 }
97 }
98 
99 #endif // MIR_FRONTEND_PROTOBUF_ASIO_COMMUNICATOR_H_
Handle client process connections.
Definition: connector.h:32
All things Mir.
Definition: aging_buffer.h:24
void create_session_for(std::shared_ptr< boost::asio::local::stream_protocol::socket > const &server_socket, std::function< void(std::shared_ptr< Session > const &session)> const &connect_handler) const
Definition: published_socket_connector.cpp:202
void stop() override
Definition: published_socket_connector.cpp:182
boost::asio::io_service::work work
Definition: published_socket_connector.h:68
std::shared_ptr< ConnectorReport > const report
Definition: published_socket_connector.h:69
provides a client-side socket fd for each connection
Definition: published_socket_connector.h:49
~BasicConnector() noexcept
Definition: published_socket_connector.cpp:243
int client_socket_fd() const override
Definition: published_socket_connector.cpp:216
PublishedSocketConnector(const std::string &socket_file, std::shared_ptr< ConnectionCreator > const &connection_creator, int threads, EmergencyCleanupRegistry &emergency_cleanup_registry, std::shared_ptr< ConnectorReport > const &report)
Definition: published_socket_connector.cpp:100
void start() override
Definition: published_socket_connector.cpp:156
boost::asio::io_service io_service
Definition: published_socket_connector.h:67
Definition: emergency_cleanup_registry.h:30
Accept connections over a published socket.
Definition: published_socket_connector.h:77
BasicConnector(std::shared_ptr< ConnectionCreator > const &connection_creator, int threads, std::shared_ptr< ConnectorReport > const &report)
Definition: published_socket_connector.cpp:145
Definition: connection_configuration.h:24
~PublishedSocketConnector() noexcept
Definition: published_socket_connector.cpp:115

Copyright © 2012,2013 Canonical Ltd.
Generated on Fri Oct 10 14:07:14 UTC 2014