Mir
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator 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::function<void()> const& force_requests_to_complete,
54  std::shared_ptr<ConnectorReport> const& report);
55  ~BasicConnector() noexcept;
56  void start() override;
57  void stop() override;
58  int client_socket_fd() const override;
59  void remove_endpoint() const override;
60 
61 
62 protected:
63  void create_session_for(std::shared_ptr<boost::asio::local::stream_protocol::socket> const& server_socket) const;
64  boost::asio::io_service mutable io_service;
65  std::shared_ptr<ConnectorReport> const report;
66 
67 private:
68  std::vector<std::thread> io_service_threads;
69  std::function<void()> const force_requests_to_complete;
70  std::shared_ptr<SessionCreator> const session_creator;
71 };
72 
75 {
76 public:
77  explicit PublishedSocketConnector(
78  const std::string& socket_file,
79  std::shared_ptr<SessionCreator> const& session_creator,
80  int threads,
81  std::function<void()> const& force_requests_to_complete,
82  std::shared_ptr<ConnectorReport> const& report);
83  ~PublishedSocketConnector() noexcept;
84 
85  void remove_endpoint() const override;
86 
87 private:
88  void start_accept();
89  void on_new_connection(std::shared_ptr<boost::asio::local::stream_protocol::socket> const& socket,
90  boost::system::error_code const& ec);
91 
92  const std::string socket_file;
93  boost::asio::local::stream_protocol::acceptor acceptor;
94 };
95 }
96 }
97 
98 #endif // MIR_FRONTEND_PROTOBUF_ASIO_COMMUNICATOR_H_

Copyright © 2012,2013 Canonical Ltd.
Generated on Tue Oct 15 00:23:28 UTC 2013