android_api_stub.h 2.8 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_BRIDGE_ANDROID_API_STUB_H_
#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 26 27 28 29

#include <memory>
#include <vector>

namespace anbox {
namespace protobuf {
30
namespace rpc {
31
class Void;
32 33
}  // namespace bridge
}  // namespace protobuf
34 35
namespace rpc {
class Channel;
36
}  // namespace rpc
37 38 39
namespace platform {
class Platform;
}  // namespace platform
40
namespace bridge {
41
class AndroidApiStub : public anbox::application::Manager {
42 43 44
 public:
  AndroidApiStub();
  ~AndroidApiStub();
45

46 47
  void set_rpc_channel(const std::shared_ptr<rpc::Channel> &channel);
  void reset_rpc_channel();
48

49
  void set_focused_task(const std::int32_t &id);
50
  void remove_task(const std::int32_t &id);
S
Simon Fels 已提交
51 52
  void resize_task(const std::int32_t &id, const anbox::graphics::Rect &rect,
                   const std::int32_t &resize_mode);
53

54
  void set_platform(const std::shared_ptr<platform::BasePlatform>&base_platform);
55 56 57 58
  void launch(const android::Intent &intent,
              const graphics::Rect &launch_bounds = graphics::Rect::Invalid,
              const wm::Stack::Id &stack = wm::Stack::Id::Default) override;

59 60
  core::Property<bool>& ready() override;

61 62
 private:
  void ensure_rpc_channel();
63

64 65 66 67 68 69
  template <typename Response>
  struct Request {
    Request() : response(std::make_shared<Response>()), success(true) {}
    std::shared_ptr<Response> response;
    bool success;
  };
70

71 72
  void application_launched(Request<protobuf::rpc::Void> *request);
  void focused_task_set(Request<protobuf::rpc::Void> *request);
73 74
  void task_removed(Request<protobuf::rpc::Void> *request);
  void task_resized(Request<protobuf::rpc::Void> *request);
75

76
  mutable std::mutex mutex_;
77
  std::shared_ptr<platform::BasePlatform> platform_;
78 79 80
  std::shared_ptr<rpc::Channel> channel_;
  common::WaitHandle launch_wait_handle_;
  common::WaitHandle set_focused_task_handle_;
81 82
  common::WaitHandle remove_task_handle_;
  common::WaitHandle resize_task_handle_;
83
  graphics::Rect launch_bounds_ = graphics::Rect::Invalid;
84
  core::Property<bool> ready_;
85
};
86 87
}  // namespace bridge
}  // namespace anbox
88 89

#endif