e40df94ead2f59e392abc99e3e273618313bf846
[iec.git] / src / type3_AndroidCloud / anbox-master / src / anbox / container / management_api_stub.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_MANAGEMENT_API_STUB_H_
19 #define ANBOX_CONTAINER_MANAGEMENT_API_STUB_H_
20
21 #include "anbox/common/wait_handle.h"
22 #include "anbox/container/configuration.h"
23 #include "anbox/do_not_copy_or_move.h"
24
25 #include <memory>
26
27 namespace anbox {
28 namespace protobuf {
29 namespace rpc {
30 class Void;
31 }  // namespace rpc
32 }  // namespace protobuf
33 namespace rpc {
34 class Channel;
35 }  // namespace rpc
36 namespace container {
37 class ManagementApiStub : public DoNotCopyOrMove {
38  public:
39   ManagementApiStub(const std::shared_ptr<rpc::Channel> &channel);
40   ~ManagementApiStub();
41
42   void start_container(const Configuration &configuration);
43   void stop_container();
44
45  private:
46   template <typename Response>
47   struct Request {
48     Request() : response(std::make_shared<Response>()), success(true) {}
49     std::shared_ptr<Response> response;
50     bool success;
51     common::WaitHandle wh;
52   };
53
54   void container_started(Request<protobuf::rpc::Void> *request);
55   void container_stopped(Request<protobuf::rpc::Void> *request);
56
57   mutable std::mutex mutex_;
58   std::shared_ptr<rpc::Channel> channel_;
59   static const std::chrono::milliseconds stop_waiting_timeout;
60 };
61 }  // namespace container
62 }  // namespace anbox
63
64 #endif