Mir
mir_basic_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_BASIC_RPC_CHANNEL_H_
20 #define MIR_CLIENT_RPC_MIR_BASIC_RPC_CHANNEL_H_
21 
22 #include <memory>
23 #include <map>
24 #include <mutex>
25 #include <atomic>
26 #include <vector>
27 
28 namespace google
29 {
30 namespace protobuf
31 {
32 class Closure;
33 class MessageLite;
34 }
35 }
36 
37 namespace mir
38 {
39 namespace protobuf
40 {
41 namespace wire
42 {
43 class Invocation;
44 class Result;
45 }
46 }
47 
48 namespace client
49 {
50 namespace rpc
51 {
52 
53 class RpcReport;
54 
55 namespace detail
56 {
57 typedef std::vector<uint8_t> SendBuffer;
58 
60 {
61 public:
62  PendingCallCache(std::shared_ptr<RpcReport> const& rpc_report);
63 
64  void save_completion_details(
65  mir::protobuf::wire::Invocation const& invoke,
66  google::protobuf::MessageLite* response,
67  google::protobuf::Closure* complete);
68 
69 
70  void populate_message_for_result(
71  mir::protobuf::wire::Result& result,
72  std::function<void(google::protobuf::MessageLite*)> const& populator);
73 
74  void complete_response(mir::protobuf::wire::Result& result);
75 
76  void force_completion();
77 
78  bool empty() const;
79 
80 private:
81 
82  struct PendingCall
83  {
84  PendingCall(
85  google::protobuf::MessageLite* response,
86  google::protobuf::Closure* target)
87  : response(response), complete(target) {}
88 
89  PendingCall()
90  : response(0), complete() {}
91 
92  google::protobuf::MessageLite* response;
93  google::protobuf::Closure* complete;
94  };
95 
96  std::mutex mutable mutex;
97  std::map<int, PendingCall> pending_calls;
98  std::shared_ptr<RpcReport> const rpc_report;
99 };
100 }
101 
103 {
104 public:
105  virtual ~MirBasicRpcChannel();
106 
107  virtual void call_method(
108  std::string const& method_name,
109  google::protobuf::MessageLite const* parameters,
110  google::protobuf::MessageLite* response,
111  google::protobuf::Closure* complete) = 0;
112 
113 protected:
115  mir::protobuf::wire::Invocation invocation_for(
116  std::string const& method_name,
117  google::protobuf::MessageLite const* request,
118  size_t num_side_channel_fds);
119  int next_id();
120 
121 private:
122  std::atomic<int> next_message_id;
123  int const protocol_version;
124 };
125 
126 }
127 }
128 }
129 
130 #endif /* MIR_CLIENT_RPC_MIR_BASIC_RPC_CHANNEL_H_ */
All things Mir.
Definition: atomic_callback.h:25
void invoke(Self *self, Server *server, void(ServerX::*function)(ParameterMessage const *request, ResultMessage *response,::google::protobuf::Closure *done), Invocation const &invocation)
Definition: template_protobuf_message_processor.h:48
Definition: mir_basic_rpc_channel.h:59
Definition: mir_basic_rpc_channel.h:102
complete_response
Definition: rpc_report_tp.h:71
std::vector< uint8_t > SendBuffer
Definition: mir_basic_rpc_channel.h:57
Definition: buffer_stream.h:37

Copyright © 2012-2015 Canonical Ltd.
Generated on Wed Mar 30 00:29:56 UTC 2016