platform_api_stub.h 3.1 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
/*
 * Copyright (C) 2016 Simon Fels <morphis@gravedo.de>
 *
 * This program is free software: you can redistribute it and/or modify it
 * under the terms of the GNU General Public License version 3, as published
 * by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranties of
 * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
 * PURPOSE.  See the GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License along
 * with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 */

18 19
#ifndef ANBOX_ANDROID_PLATFORM_API_STUB_H_
#define ANBOX_ANDROID_PLATFORM_API_STUB_H_
20

21
#include "anbox/common/wait_handle.h"
22

23
#include <memory>
24 25
#include <vector>
#include <string>
26 27 28

namespace anbox {
namespace protobuf {
29
namespace rpc {
30
class Void;
31
} // namespace rpc
32 33 34
namespace bridge {
class ClipboardData;
} // namespace bridge
35
} // namespace protobuf
36 37 38
namespace rpc {
class Channel;
} // namespace rpc
39
class PlatformApiStub {
40
public:
41
    PlatformApiStub(const std::shared_ptr<rpc::Channel> &rpc_channel);
42

43
    void boot_finished();
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64

    struct WindowStateUpdate {
        struct Window {
            int display_id;
            bool has_surface;
            std::string package_name;
            struct Frame {
                int left;
                int top;
                int right;
                int bottom;
            };
            Frame frame;
            int task_id;
            int stack_id;
        };
        std::vector<Window> updated_windows;
        std::vector<Window> removed_windows;
    };

    void update_window_state(const WindowStateUpdate &state);
65

66 67 68 69 70 71 72 73 74 75 76 77 78
    struct ApplicationListUpdate {
        struct Application {
            std::string name;
            std::string package;
            struct Intent {
                std::string action;
                std::string uri;
                std::string type;
                std::string package;
                std::string component;
                std::vector<std::string> categories;
            };
            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 86
    };

    void update_application_list(const ApplicationListUpdate &update);

87 88 89 90 91 92 93
    struct ClipboardData {
        std::string text;
    };

    void set_clipboard_data(const ClipboardData &data);
    ClipboardData get_clipboard_data();

94
private:
95 96 97 98 99
    template<typename Response>
    struct Request {
        Request() : response(std::make_shared<Response>()), success(true) { }
        std::shared_ptr<Response> response;
        bool success;
100
        common::WaitHandle wh;
101 102
    };

103 104
    void on_clipboard_data_set(Request<protobuf::rpc::Void> *request);
    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 112 113
};
} // namespace anbox

#endif