Mir
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
mir_socket_rpc_channel.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 Lesser 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 Lesser General Public License for more details.
12  *
13  * You should have received a copy of the GNU Lesser General Public License
14  * along with this program. If not, see <http://www.gnu.org/licenses/>.
15  *
16  * Authored by: Alan Griffiths <alan@octopull.co.uk>
17  */
18 
19 #ifndef MIR_CLIENT_RPC_MIR_SOCKET_RPC_CHANNEL_H_
20 #define MIR_CLIENT_RPC_MIR_SOCKET_RPC_CHANNEL_H_
21 
22 #include "mir_basic_rpc_channel.h"
23 
24 #include <boost/asio.hpp>
25 
26 #include <google/protobuf/service.h>
27 #include <google/protobuf/descriptor.h>
28 
29 #include <thread>
30 
31 namespace mir
32 {
33 namespace protobuf
34 {
35 namespace wire
36 {
37 class Invocation;
38 class Result;
39 }
40 }
41 
42 namespace client
43 {
44 class DisplayConfiguration;
45 class SurfaceMap;
46 class LifecycleControl;
47 namespace rpc
48 {
49 
50 class RpcReport;
51 
53 {
54 public:
55  MirSocketRpcChannel(std::string const& endpoint,
56  std::shared_ptr<SurfaceMap> const& surface_map,
57  std::shared_ptr<DisplayConfiguration> const& disp_config,
58  std::shared_ptr<RpcReport> const& rpc_report,
59  std::shared_ptr<LifecycleControl> const& lifecycle_control);
60 
61  MirSocketRpcChannel(int native_socket,
62  std::shared_ptr<SurfaceMap> const& surface_map,
63  std::shared_ptr<DisplayConfiguration> const& disp_config,
64  std::shared_ptr<RpcReport> const& rpc_report,
65  std::shared_ptr<LifecycleControl> const& lifecycle_control);
67 
68 private:
69  void init();
70 
71  virtual void CallMethod(const google::protobuf::MethodDescriptor* method, google::protobuf::RpcController*,
72  const google::protobuf::Message* parameters, google::protobuf::Message* response,
73  google::protobuf::Closure* complete);
74  std::shared_ptr<RpcReport> const rpc_report;
75  detail::PendingCallCache pending_calls;
76  std::thread io_service_thread;
77  boost::asio::io_service io_service;
78  boost::asio::io_service::work work;
79  boost::asio::local::stream_protocol::socket socket;
80 
81  static size_t const size_of_header = 2;
82  unsigned char header_bytes[size_of_header];
83 
84  void receive_file_descriptors(google::protobuf::Message* response, google::protobuf::Closure* complete);
85  void receive_file_descriptors(std::vector<int> &fds);
86  void send_message(mir::protobuf::wire::Invocation const& body, detail::SendBuffer& buffer,
87  mir::protobuf::wire::Invocation const& invocation);
88  void on_header_read(const boost::system::error_code& error);
89 
90  void read_message();
91  void process_event_sequence(std::string const& event);
92 
93  size_t read_message_header();
94 
95  mir::protobuf::wire::Result read_message_body(const size_t body_size);
96  void notify_disconnected();
97 
98  std::shared_ptr<SurfaceMap> surface_map;
99  std::shared_ptr<DisplayConfiguration> display_configuration;
100  std::shared_ptr<LifecycleControl> lifecycle_control;
101  std::atomic<bool> disconnected;
102 };
103 
104 }
105 }
106 }
107 
108 #endif /* MIR_CLIENT_RPC_MIR_SOCKET_RPC_CHANNEL_H_ */

Copyright © 2012,2013 Canonical Ltd.
Generated on Wed Oct 30 18:52:19 UTC 2013