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 
65  mir::protobuf::wire::Invocation const& invoke,
66  google::protobuf::MessageLite* response,
67  google::protobuf::Closure* complete);
68 
69 
70  google::protobuf::MessageLite* message_for_result(mir::protobuf::wire::Result& result);
71 
72  void complete_response(mir::protobuf::wire::Result& result);
73 
74  void force_completion();
75 
76  bool empty() const;
77 
78 private:
79 
80  struct PendingCall
81  {
82  PendingCall(
83  google::protobuf::MessageLite* response,
84  google::protobuf::Closure* target)
85  : response(response), complete(target) {}
86 
87  PendingCall()
88  : response(0), complete() {}
89 
90  google::protobuf::MessageLite* response;
91  google::protobuf::Closure* complete;
92  };
93 
94  std::mutex mutable mutex;
95  std::map<int, PendingCall> pending_calls;
96  std::shared_ptr<RpcReport> const rpc_report;
97 };
98 }
99 
101 {
102 public:
103  virtual ~MirBasicRpcChannel();
104 
105  virtual void call_method(
106  std::string const& method_name,
107  google::protobuf::MessageLite const* parameters,
108  google::protobuf::MessageLite* response,
109  google::protobuf::Closure* complete) = 0;
110 
111 protected:
113  mir::protobuf::wire::Invocation invocation_for(
114  std::string const& method_name,
115  google::protobuf::MessageLite const* request,
116  size_t num_side_channel_fds);
117  int next_id();
118 
119 private:
120  std::atomic<int> next_message_id;
121  int const protocol_version;
122 };
123 
124 }
125 }
126 }
127 
128 #endif /* MIR_CLIENT_RPC_MIR_BASIC_RPC_CHANNEL_H_ */
All things Mir.
Definition: atomic_callback.h:25
int next_id()
Definition: mir_basic_rpc_channel.cpp:151
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:47
MirBasicRpcChannel()
Definition: mir_basic_rpc_channel.cpp:122
Definition: mir_basic_rpc_channel.h:59
void complete_response(mir::protobuf::wire::Result &result)
Definition: mir_basic_rpc_channel.cpp:75
Definition: mir_basic_rpc_channel.h:100
std::vector< uint8_t > SendBuffer
Definition: mir_basic_rpc_channel.h:57
void save_completion_details(mir::protobuf::wire::Invocation const &invoke, google::protobuf::MessageLite *response, google::protobuf::Closure *complete)
Definition: mir_basic_rpc_channel.cpp:59
void force_completion()
Definition: mir_basic_rpc_channel.cpp:100
google::protobuf::MessageLite * message_for_result(mir::protobuf::wire::Result &result)
Definition: mir_basic_rpc_channel.cpp:69
Definition: mir_basic_rpc_channel.h:28
virtual void call_method(std::string const &method_name, google::protobuf::MessageLite const *parameters, google::protobuf::MessageLite *response, google::protobuf::Closure *complete)=0
PendingCallCache(std::shared_ptr< RpcReport > const &rpc_report)
Definition: mir_basic_rpc_channel.cpp:53
bool empty() const
Definition: mir_basic_rpc_channel.cpp:114
mir::protobuf::wire::Invocation invocation_for(std::string const &method_name, google::protobuf::MessageLite const *request, size_t num_side_channel_fds)
Definition: mir_basic_rpc_channel.cpp:130

Copyright © 2012-2015 Canonical Ltd.
Generated on Thu Oct 8 16:20:16 UTC 2015