Mir
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
mir_protobuf_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_PROTOBUF_RPC_CHANNEL_H_
20 #define MIR_CLIENT_RPC_MIR_PROTOBUF_RPC_CHANNEL_H_
21 
22 #include "mir_basic_rpc_channel.h"
23 #include "stream_transport.h"
24 
25 #include <google/protobuf/service.h>
26 #include <google/protobuf/descriptor.h>
27 
28 #include <thread>
29 #include <atomic>
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 class EventSink;
48 namespace rpc
49 {
50 
51 class RpcReport;
52 
54  public MirBasicRpcChannel,
56 {
57 public:
58  MirProtobufRpcChannel(std::unique_ptr<StreamTransport> transport,
59  std::shared_ptr<SurfaceMap> const& surface_map,
60  std::shared_ptr<DisplayConfiguration> const& disp_config,
61  std::shared_ptr<RpcReport> const& rpc_report,
62  std::shared_ptr<LifecycleControl> const& lifecycle_control,
63  std::shared_ptr<EventSink> const& event_sink);
64 
65  ~MirProtobufRpcChannel() = default;
66 
67  void on_data_available() override;
68  void on_disconnected() override;
69 private:
70  virtual void CallMethod(const google::protobuf::MethodDescriptor* method, google::protobuf::RpcController*,
71  const google::protobuf::Message* parameters, google::protobuf::Message* response,
72  google::protobuf::Closure* complete);
73 
74  std::shared_ptr<RpcReport> const rpc_report;
75  detail::PendingCallCache pending_calls;
76 
77  static constexpr size_t size_of_header = 2;
78  detail::SendBuffer header_bytes;
79  detail::SendBuffer body_bytes;
80 
81  void receive_file_descriptors(google::protobuf::Message* response, google::protobuf::Closure* complete);
82  template<class MessageType>
83  void receive_any_file_descriptors_for(MessageType* response);
84  void send_message(mir::protobuf::wire::Invocation const& body,
85  mir::protobuf::wire::Invocation const& invocation);
86 
87  void read_message();
88  void process_event_sequence(std::string const& event);
89 
90  void notify_disconnected();
91 
92  std::shared_ptr<SurfaceMap> surface_map;
93  std::shared_ptr<DisplayConfiguration> display_configuration;
94  std::shared_ptr<LifecycleControl> lifecycle_control;
95  std::shared_ptr<EventSink> event_sink;
96  std::atomic<bool> disconnected;
97  std::mutex read_mutex;
98  std::mutex write_mutex;
99 
100  /* We use the guarantee that the transport's destructor blocks until
101  * pending processing has finished to ensure that on_data_available()
102  * isn't called after the members it relies on are destroyed.
103  *
104  * This means the transport field must appear after any field used
105  * by on_data_available. For simplicity, put it last.
106  */
107  std::unique_ptr<StreamTransport> transport;
108 };
109 
110 }
111 }
112 }
113 
114 #endif /* MIR_CLIENT_RPC_MIR_PROTOBUF_RPC_CHANNEL_H_ */
All things Mir.
Definition: aging_buffer.h:24
Definition: mir_protobuf_wire.pb.h:43
void on_disconnected() override
Called by the Transport when the connection to the server has been broken.
Definition: mir_protobuf_rpc_channel.cpp:324
Definition: mir_basic_rpc_channel.h:52
Definition: mir_basic_rpc_channel.h:91
MirProtobufRpcChannel(std::unique_ptr< StreamTransport > transport, std::shared_ptr< SurfaceMap > const &surface_map, std::shared_ptr< DisplayConfiguration > const &disp_config, std::shared_ptr< RpcReport > const &rpc_report, std::shared_ptr< LifecycleControl > const &lifecycle_control, std::shared_ptr< EventSink > const &event_sink)
Definition: mir_protobuf_rpc_channel.cpp:47
std::vector< uint8_t > SendBuffer
Definition: mir_basic_rpc_channel.h:50
Definition: mir_protobuf_rpc_channel.h:53
void on_data_available() override
Called by the Transport when data is available for reading.
Definition: mir_protobuf_rpc_channel.cpp:271
Observer of IO status.
Definition: stream_transport.h:86

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