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 <google/protobuf/service.h>
23 #include <google/protobuf/descriptor.h>
24 
25 #include <memory>
26 #include <map>
27 #include <mutex>
28 #include <atomic>
29 
30 namespace mir
31 {
32 namespace protobuf
33 {
34 namespace wire
35 {
36 class Invocation;
37 class Result;
38 }
39 }
40 
41 namespace client
42 {
43 namespace rpc
44 {
45 
46 class RpcReport;
47 
48 namespace detail
49 {
50 typedef std::vector<uint8_t> SendBuffer;
51 
53 {
54 public:
55  PendingCallCache(std::shared_ptr<RpcReport> const& rpc_report);
56 
58  mir::protobuf::wire::Invocation const& invoke,
59  google::protobuf::Message* response,
60  std::shared_ptr<google::protobuf::Closure> const& complete);
61 
62 
63  void complete_response(mir::protobuf::wire::Result& result);
64 
65  void force_completion();
66 
67  bool empty() const;
68 
69 private:
70 
71  struct PendingCall
72  {
73  PendingCall(
74  google::protobuf::Message* response,
75  std::shared_ptr<google::protobuf::Closure> const& target)
76  : response(response), complete(target) {}
77 
78  PendingCall()
79  : response(0), complete() {}
80 
81  google::protobuf::Message* response;
82  std::shared_ptr<google::protobuf::Closure> complete;
83  };
84 
85  std::mutex mutable mutex;
86  std::map<int, PendingCall> pending_calls;
87  std::shared_ptr<RpcReport> const rpc_report;
88 };
89 }
90 
91 class MirBasicRpcChannel : public google::protobuf::RpcChannel
92 {
93 public:
96 
97 protected:
98  mir::protobuf::wire::Invocation invocation_for(
99  google::protobuf::MethodDescriptor const* method,
100  google::protobuf::Message const* request,
101  size_t num_side_channel_fds);
102  int next_id();
103 
104 private:
105  std::atomic<int> next_message_id;
106 };
107 
108 }
109 }
110 }
111 
112 #endif /* MIR_CLIENT_RPC_MIR_BASIC_RPC_CHANNEL_H_ */
All things Mir.
Definition: buffer_stream.h:37
int next_id()
Definition: mir_basic_rpc_channel.cpp:127
void invoke(Self *self, Server *server, void(ServerX::*function)(::google::protobuf::RpcController *controller, const ParameterMessage *request, ResultMessage *response,::google::protobuf::Closure *done), Invocation const &invocation)
Definition: template_protobuf_message_processor.h:47
MirBasicRpcChannel()
Definition: mir_basic_rpc_channel.cpp:96
Definition: mir_basic_rpc_channel.h:52
void complete_response(mir::protobuf::wire::Result &result)
Definition: mir_basic_rpc_channel.cpp:48
Definition: mir_basic_rpc_channel.h:91
~MirBasicRpcChannel()
Definition: mir_basic_rpc_channel.cpp:101
std::vector< uint8_t > SendBuffer
Definition: mir_basic_rpc_channel.h:50
mir::protobuf::wire::Invocation invocation_for(google::protobuf::MethodDescriptor const *method, google::protobuf::Message const *request, size_t num_side_channel_fds)
Definition: mir_basic_rpc_channel.cpp:106
void force_completion()
Definition: mir_basic_rpc_channel.cpp:74
void save_completion_details(mir::protobuf::wire::Invocation const &invoke, google::protobuf::Message *response, std::shared_ptr< google::protobuf::Closure > const &complete)
Definition: mir_basic_rpc_channel.cpp:38
PendingCallCache(std::shared_ptr< RpcReport > const &rpc_report)
Definition: mir_basic_rpc_channel.cpp:32
bool empty() const
Definition: mir_basic_rpc_channel.cpp:88

Copyright © 2012,2013 Canonical Ltd.
Generated on Tue Mar 24 16:15:19 UTC 2015