Mir
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
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<char> SendBuffer;
51 
53 {
54 public:
55  PendingCallCache(std::shared_ptr<RpcReport> const& rpc_report);
56 
58  mir::protobuf::wire::Invocation& 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  SendBuffer send_buffer;
82  google::protobuf::Message* response;
83  std::shared_ptr<google::protobuf::Closure> complete;
84  };
85 
86  std::mutex mutable mutex;
87  std::map<int, PendingCall> pending_calls;
88  std::shared_ptr<RpcReport> const rpc_report;
89 };
90 }
91 
92 class MirBasicRpcChannel : public google::protobuf::RpcChannel
93 {
94 public:
97 
98 protected:
99  mir::protobuf::wire::Invocation invocation_for(const google::protobuf::MethodDescriptor* method,
100  const google::protobuf::Message* request);
101  int next_id();
102 
103 private:
104  std::atomic<int> next_message_id;
105 };
106 
107 }
108 }
109 }
110 
111 #endif /* MIR_CLIENT_RPC_MIR_BASIC_RPC_CHANNEL_H_ */

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