Mir
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 <functional>
29 
30 namespace google
31 {
32 namespace protobuf
33 {
34 class Message;
35 }
36 }
37 
38 namespace mir
39 {
40 class EmergencyCleanupRegistry;
41 
42 namespace frontend
43 {
44 class ConnectionCreator;
45 class ConnectorReport;
46 
48 class BasicConnector : public Connector
49 {
50 public:
51  explicit BasicConnector(
52  std::shared_ptr<ConnectionCreator> const& connection_creator,
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  int client_socket_fd(std::function<void(std::shared_ptr<Session> const& session)> const& connect_handler) const override;
59 
60 protected:
61  void create_session_for(
62  std::shared_ptr<boost::asio::local::stream_protocol::socket> const& server_socket,
63  std::function<void(std::shared_ptr<Session> const& session)> const& connect_handler) const;
64 
65  boost::asio::io_service mutable io_service;
66  boost::asio::io_service::work work;
67  std::shared_ptr<ConnectorReport> const report;
68 
69 private:
70  std::thread io_service_thread;
71  std::shared_ptr<ConnectionCreator> const connection_creator;
72 };
73 
76 {
77 public:
78  explicit PublishedSocketConnector(
79  const std::string& socket_file,
80  std::shared_ptr<ConnectionCreator> const& connection_creator,
81  EmergencyCleanupRegistry& emergency_cleanup_registry,
82  std::shared_ptr<ConnectorReport> const& report);
83  ~PublishedSocketConnector() noexcept;
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:32
All things Mir.
Definition: atomic_callback.h:25
boost::asio::io_service::work work
Definition: published_socket_connector.h:66
std::shared_ptr< ConnectorReport > const report
Definition: published_socket_connector.h:67
provides a client-side socket fd for each connection
Definition: published_socket_connector.h:48
boost::asio::io_service io_service
Definition: published_socket_connector.h:65
std::promise< bool > stop
Definition: in.cpp:28
Definition: emergency_cleanup_registry.h:32
Accept connections over a published socket.
Definition: published_socket_connector.h:75
Definition: buffer_stream.h:37

Copyright © 2012-2015 Canonical Ltd.
Generated on Thu Sep 8 14:50:19 UTC 2016