TYPE3
[iec.git] / src / type3_AndroidCloud / anbox-master / src / anbox / rpc / channel.h
1 /*
2  * Copyright (C) 2016 Simon Fels <morphis@gravedo.de>
3  *
4  * This program is free software: you can redistribute it and/or modify it
5  * under the terms of the GNU General Public License version 3, as published
6  * by the Free Software Foundation.
7  *
8  * This program is distributed in the hope that it will be useful, but
9  * WITHOUT ANY WARRANTY; without even the implied warranties of
10  * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
11  * PURPOSE.  See the GNU General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License along
14  * with this program.  If not, see <http://www.gnu.org/licenses/>.
15  *
16  */
17
18 #ifndef ANBOX_RPC_CHANNEL_H_
19 #define ANBOX_RPC_CHANNEL_H_
20
21 #include <atomic>
22 #include <memory>
23 #include <mutex>
24
25 namespace google {
26 namespace protobuf {
27 class Closure;
28 class MessageLite;
29 }  // namespace protobuf
30 }  // namespace google
31
32 namespace anbox {
33 namespace protobuf {
34 namespace rpc {
35 class Invocation;
36 }  // namespace rpc
37 }  // namespace protobuf
38 namespace network {
39 class MessageSender;
40 }  // namespace network
41 namespace rpc {
42 class PendingCallCache;
43 class Channel {
44  public:
45   Channel(const std::shared_ptr<PendingCallCache> &pending_calls,
46           const std::shared_ptr<network::MessageSender> &sender);
47   ~Channel();
48
49   void call_method(std::string const &method_name,
50                    google::protobuf::MessageLite const *parameters,
51                    google::protobuf::MessageLite *response,
52                    google::protobuf::Closure *complete);
53
54   void send_event(google::protobuf::MessageLite const &event);
55
56  private:
57   protobuf::rpc::Invocation invocation_for(
58       std::string const &method_name,
59       google::protobuf::MessageLite const *request);
60   void send_message(const std::uint8_t &type,
61                     google::protobuf::MessageLite const &message);
62   std::uint32_t next_id();
63   void notify_disconnected();
64
65   std::shared_ptr<PendingCallCache> pending_calls_;
66   std::shared_ptr<network::MessageSender> sender_;
67   std::mutex write_mutex_;
68 };
69 }  // namespace rpc
70 }  // namespace anbox
71
72 #endif