fdd9d184b8713ab59c2b9eba8ace825cb3dd9321
[iec.git] / src / type3_AndroidCloud / anbox-master / src / anbox / container / client.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_CONTAINER_CLIENT_H_
19 #define ANBOX_CONTAINER_CLIENT_H_
20
21 #include "anbox/container/configuration.h"
22 #include "anbox/runtime.h"
23
24 namespace anbox {
25 namespace rpc {
26 class PendingCallCache;
27 class Channel;
28 class MessageProcessor;
29 }  // namespace rpc
30 namespace network {
31 class LocalSocketMessenger;
32 }  // namespace network
33 namespace container {
34 class ManagementApiStub;
35 class Client {
36  public:
37   typedef std::function<void()> TerminateCallback;
38
39   Client(const std::shared_ptr<Runtime> &rt);
40   ~Client();
41
42   void start(const Configuration &configuration);
43   void stop();
44
45   void register_terminate_handler(const TerminateCallback &callback);
46
47  private:
48   void read_next_message();
49   void on_read_size(const boost::system::error_code &ec,
50                     std::size_t bytes_read);
51
52   std::shared_ptr<network::LocalSocketMessenger> messenger_;
53   std::shared_ptr<rpc::PendingCallCache> pending_calls_;
54   std::shared_ptr<rpc::Channel> rpc_channel_;
55   std::shared_ptr<ManagementApiStub> management_api_;
56   std::shared_ptr<rpc::MessageProcessor> processor_;
57   std::array<std::uint8_t, 8192> buffer_;
58   TerminateCallback terminate_callback_;
59 };
60 }  // namespace container
61 }  // namespace anbox
62
63 #endif