Mir
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups 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 namespace frontend
42 {
43 class SessionCreator;
44 class ConnectorReport;
45 
47 class BasicConnector : public Connector
48 {
49 public:
50  explicit BasicConnector(
51  std::shared_ptr<SessionCreator> const& session_creator,
52  int threads,
53  std::shared_ptr<ConnectorReport> const& report);
54  ~BasicConnector() noexcept;
55  void start() override;
56  void stop() override;
57  int client_socket_fd() const override;
58  void remove_endpoint() const override;
59 
60 
61 protected:
62  void create_session_for(std::shared_ptr<boost::asio::local::stream_protocol::socket> const& server_socket) const;
63  boost::asio::io_service mutable io_service;
64  boost::asio::io_service::work work;
65  std::shared_ptr<ConnectorReport> const report;
66 
67 private:
68  std::vector<std::thread> io_service_threads;
69  std::shared_ptr<SessionCreator> const session_creator;
70 };
71 
74 {
75 public:
76  explicit PublishedSocketConnector(
77  const std::string& socket_file,
78  std::shared_ptr<SessionCreator> const& session_creator,
79  int threads,
80  std::shared_ptr<ConnectorReport> const& report);
81  ~PublishedSocketConnector() noexcept;
82 
83  void remove_endpoint() const override;
84 
85 private:
86  void start_accept();
87  void on_new_connection(std::shared_ptr<boost::asio::local::stream_protocol::socket> const& socket,
88  boost::system::error_code const& ec);
89 
90  const std::string socket_file;
91  boost::asio::local::stream_protocol::acceptor acceptor;
92 };
93 }
94 }
95 
96 #endif // MIR_FRONTEND_PROTOBUF_ASIO_COMMUNICATOR_H_
Handle client process connections.
Definition: connector.h:27
void remove_endpoint() const override
Definition: published_socket_connector.cpp:66
BasicConnector(std::shared_ptr< SessionCreator > const &session_creator, int threads, std::shared_ptr< ConnectorReport > const &report)
Definition: published_socket_connector.cpp:82
void stop() override
Definition: published_socket_connector.cpp:118
boost::asio::io_service::work work
Definition: published_socket_connector.h:64
std::shared_ptr< ConnectorReport > const report
Definition: published_socket_connector.h:65
provides a client-side socket fd for each connection
Definition: published_socket_connector.h:47
~BasicConnector() noexcept
Definition: published_socket_connector.cpp:170
int client_socket_fd() const override
Definition: published_socket_connector.cpp:144
void start() override
Definition: published_socket_connector.cpp:93
boost::asio::io_service io_service
Definition: published_socket_connector.h:63
PublishedSocketConnector(const std::string &socket_file, std::shared_ptr< SessionCreator > const &session_creator, int threads, std::shared_ptr< ConnectorReport > const &report)
Definition: published_socket_connector.cpp:34
Accept connections over a published socket.
Definition: published_socket_connector.h:73
void remove_endpoint() const override
Definition: published_socket_connector.cpp:166
~PublishedSocketConnector() noexcept
Definition: published_socket_connector.cpp:46
void create_session_for(std::shared_ptr< boost::asio::local::stream_protocol::socket > const &server_socket) const
Definition: published_socket_connector.cpp:138

Copyright © 2012,2013 Canonical Ltd.
Generated on Fri Apr 11 21:14:53 UTC 2014