TYPE3
[iec.git] / src / type3_AndroidCloud / anbox-master / src / anbox / rpc / pending_call_cache.h
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 ANBOX_RPC_PENDING_CALL_CACHE_
20 #define ANBOX_RPC_PENDING_CALL_CACHE_
21
22 #include <functional>
23 #include <map>
24 #include <mutex>
25
26 namespace google {
27 namespace protobuf {
28 class Closure;
29 class MessageLite;
30 }  // namespace protobuf
31 }  // namespace google
32
33 namespace anbox {
34 namespace protobuf {
35 namespace rpc {
36 class Invocation;
37 class Result;
38 }  // namespace rpc
39 }  // namespace protobuf
40 namespace rpc {
41 class PendingCallCache {
42  public:
43   PendingCallCache();
44
45   void save_completion_details(
46       anbox::protobuf::rpc::Invocation const &invocation,
47       google::protobuf::MessageLite *response,
48       google::protobuf::Closure *complete);
49   void populate_message_for_result(
50       anbox::protobuf::rpc::Result &result,
51       std::function<void(google::protobuf::MessageLite *)> const &populator);
52   void complete_response(anbox::protobuf::rpc::Result &result);
53   void force_completion();
54   bool empty() const;
55
56  private:
57   struct PendingCall {
58     PendingCall(google::protobuf::MessageLite *response,
59                 google::protobuf::Closure *target)
60         : response(response), complete(target) {}
61
62     PendingCall() : response(0), complete() {}
63
64     google::protobuf::MessageLite *response;
65     google::protobuf::Closure *complete;
66   };
67
68   std::mutex mutable mutex_;
69   std::map<int, PendingCall> pending_calls_;
70 };
71 }  // namespace rpc
72 }  // namespace anbox
73
74 #endif