TYPE3
[iec.git] / src / type3_AndroidCloud / anbox-master / src / anbox / bridge / android_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_BRIDGE_ANDROID_API_STUB_H_
19 #define ANBOX_BRIDGE_ANDROID_API_STUB_H_
20
21 #include "anbox/application/manager.h"
22 #include "anbox/common/wait_handle.h"
23 #include "anbox/graphics/rect.h"
24
25 #include <memory>
26 #include <vector>
27
28 namespace anbox {
29 namespace protobuf {
30 namespace rpc {
31 class Void;
32 }  // namespace bridge
33 }  // namespace protobuf
34 namespace rpc {
35 class Channel;
36 }  // namespace rpc
37 namespace bridge {
38 class AndroidApiStub : public anbox::application::Manager {
39  public:
40   AndroidApiStub();
41   ~AndroidApiStub();
42
43   void set_rpc_channel(const std::shared_ptr<rpc::Channel> &channel);
44   void reset_rpc_channel();
45
46   void set_focused_task(const std::int32_t &id);
47   void remove_task(const std::int32_t &id);
48   void resize_task(const std::int32_t &id, const anbox::graphics::Rect &rect,
49                    const std::int32_t &resize_mode);
50
51   void launch(const android::Intent &intent,
52               const graphics::Rect &launch_bounds = graphics::Rect::Invalid,
53               const wm::Stack::Id &stack = wm::Stack::Id::Default) override;
54
55   core::Property<bool>& ready() override;
56
57  private:
58   void ensure_rpc_channel();
59
60   template <typename Response>
61   struct Request {
62     Request() : response(std::make_shared<Response>()), success(true) {}
63     std::shared_ptr<Response> response;
64     bool success;
65   };
66
67   void application_launched(Request<protobuf::rpc::Void> *request);
68   void focused_task_set(Request<protobuf::rpc::Void> *request);
69   void task_removed(Request<protobuf::rpc::Void> *request);
70   void task_resized(Request<protobuf::rpc::Void> *request);
71
72   mutable std::mutex mutex_;
73   std::shared_ptr<rpc::Channel> channel_;
74   common::WaitHandle launch_wait_handle_;
75   common::WaitHandle set_focused_task_handle_;
76   common::WaitHandle remove_task_handle_;
77   common::WaitHandle resize_task_handle_;
78   graphics::Rect launch_bounds_ = graphics::Rect::Invalid;
79   core::Property<bool> ready_;
80 };
81 }  // namespace bridge
82 }  // namespace anbox
83
84 #endif