7ddfb880874d2ff035e7132d752c96ded2665004
[iec.git] / src / type3_AndroidCloud / anbox-master / android / service / platform_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_ANDROID_PLATFORM_API_STUB_H_
19 #define ANBOX_ANDROID_PLATFORM_API_STUB_H_
20
21 #include "anbox/common/wait_handle.h"
22
23 #include <memory>
24 #include <vector>
25 #include <string>
26
27 namespace anbox {
28 namespace protobuf {
29 namespace rpc {
30 class Void;
31 } // namespace rpc
32 namespace bridge {
33 class ClipboardData;
34 } // namespace bridge
35 } // namespace protobuf
36 namespace rpc {
37 class Channel;
38 } // namespace rpc
39 class PlatformApiStub {
40 public:
41     PlatformApiStub(const std::shared_ptr<rpc::Channel> &rpc_channel);
42
43     void boot_finished();
44
45     struct WindowStateUpdate {
46         struct Window {
47             int display_id;
48             bool has_surface;
49             std::string package_name;
50             struct Frame {
51                 int left;
52                 int top;
53                 int right;
54                 int bottom;
55             };
56             Frame frame;
57             int task_id;
58             int stack_id;
59         };
60         std::vector<Window> updated_windows;
61         std::vector<Window> removed_windows;
62     };
63
64     void update_window_state(const WindowStateUpdate &state);
65
66     struct ApplicationListUpdate {
67         struct Application {
68             std::string name;
69             std::string package;
70             struct Intent {
71                 std::string action;
72                 std::string uri;
73                 std::string type;
74                 std::string package;
75                 std::string component;
76                 std::vector<std::string> categories;
77             };
78             Intent launch_intent;
79             std::vector<int8_t> icon;
80         };
81         std::vector<Application> applications;
82         std::vector<std::string> removed_applications;
83     };
84
85     void update_application_list(const ApplicationListUpdate &update);
86
87     struct ClipboardData {
88         std::string text;
89     };
90
91     void set_clipboard_data(const ClipboardData &data);
92     ClipboardData get_clipboard_data();
93
94 private:
95     template<typename Response>
96     struct Request {
97         Request() : response(std::make_shared<Response>()), success(true) { }
98         std::shared_ptr<Response> response;
99         bool success;
100         common::WaitHandle wh;
101     };
102
103     void on_clipboard_data_set(Request<protobuf::rpc::Void> *request);
104     void on_clipboard_data_get(Request<protobuf::bridge::ClipboardData> *request);
105
106     mutable std::mutex mutex_;
107     std::shared_ptr<rpc::Channel> rpc_channel_;
108
109     ClipboardData received_clipboard_data_;
110 };
111 } // namespace anbox
112
113 #endif