Mir
input_sender.h
Go to the documentation of this file.
1 /*
2  * Copyright © 2014 Canonical Ltd.
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,
6  * as published by the Free Software Foundation.
7  *
8  * This program is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * GNU General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License
14  * along with this program. If not, see <http://www.gnu.org/licenses/>.
15  *
16  * Authored by: Andreas Pokorny <andreas.pokorny@canonical.com>
17  */
18 
19 #ifndef MIR_INPUT_ANDROID_INPUT_SENDER_H_
20 #define MIR_INPUT_ANDROID_INPUT_SENDER_H_
21 
22 #include "mir/input/input_sender.h"
24 #include "mir_toolkit/event.h"
26 
27 #include "androidfw/InputTransport.h"
28 
29 #include <memory>
30 #include <unordered_map>
31 #include <mutex>
32 #include <vector>
33 #include <atomic>
34 
35 namespace droidinput = android;
36 
37 namespace mir
38 {
39 class MainLoop;
40 namespace compositor
41 {
42 class Scene;
43 }
44 namespace scene
45 {
46 class InputRegistrar;
47 }
48 namespace input
49 {
50 class InputReport;
51 class Surface;
52 namespace android
53 {
54 
56 {
57 public:
58  InputSender(std::shared_ptr<compositor::Scene> const& scene,
59  std::shared_ptr<MainLoop> const& main_loop,
60  std::shared_ptr<InputReport> const& report);
61 
62  void send_event(MirEvent const& event, std::shared_ptr<InputChannel> const& channel) override;
63 
64 private:
65  struct InputSenderState;
66 
67  class SceneObserver : public scene::NullObserver
68  {
69  public:
70  explicit SceneObserver(InputSenderState & state);
71  private:
72  void surface_added(scene::Surface* surface) override;
73  void surface_removed(scene::Surface* surface) override;
74  void surface_exists(scene::Surface* surface) override;
75  void scene_changed() override;
76 
77  void remove_transfer_for(input::Surface* surface);
78  InputSenderState & state;
79  };
80 
81  class ActiveTransfer
82  {
83  public:
84  ActiveTransfer(InputSenderState & state, std::shared_ptr<InputChannel> const& channel, input::Surface* surface);
85  ~ActiveTransfer();
86  void send(uint32_t sequence_id, MirEvent const& event);
87  bool used_for_surface(input::Surface const* surface) const;
88  void subscribe();
89  void unsubscribe();
90 
91  private:
92  void on_finish_signal();
93  droidinput::status_t send_key_event(uint32_t sequence_id, MirEvent const& event);
94  droidinput::status_t send_touch_event(uint32_t sequence_id, MirEvent const& event);
95  droidinput::status_t send_pointer_event(uint32_t sequence_id, MirEvent const& event);
96 
97  InputSenderState & state;
98  droidinput::InputPublisher publisher;
99  input::Surface const* surface;
100  std::shared_ptr<InputChannel> const channel;
101  std::atomic<bool> subscribed{false};
102 
103  ActiveTransfer& operator=(ActiveTransfer const&) = delete;
104  ActiveTransfer(ActiveTransfer const&) = delete;
105  };
106 
107  struct InputSenderState
108  {
109  InputSenderState(std::shared_ptr<MainLoop> const& main_loop,
110  std::shared_ptr<InputReport> const& report);
111  void send_event(std::shared_ptr<InputChannel> const& channel, MirEvent const& event);
112  void add_transfer(std::shared_ptr<InputChannel> const& channel, input::Surface* surface);
113  void remove_transfer(int fd);
114 
115  std::shared_ptr<MainLoop> const main_loop;
116  std::shared_ptr<InputReport> const report;
117 
118  private:
119  std::shared_ptr<ActiveTransfer> get_transfer(int fd);
120  uint32_t next_seq();
121  uint32_t seq;
122 
123  std::unordered_map<int,std::shared_ptr<ActiveTransfer>> transfers;
124  std::mutex sender_mutex;
125  };
126 
127  InputSenderState state;
128  std::shared_ptr<compositor::Scene> scene;
129 };
130 
131 }
132 }
133 }
134 
135 #endif
All things Mir.
Definition: atomic_callback.h:25
Definition: surface.h:47
Definition: null_observer.h:28
Definition: input_sender.h:55
surface_removed
Definition: scene_report_tp.h:46
surface_added
Definition: scene_report_tp.h:41
Definition: android_input_receiver.h:36
Definition: event_private.h:181
Definition: surface.h:47
Definition: input_sender.h:32

Copyright © 2012-2015 Canonical Ltd.
Generated on Wed Mar 30 00:29:56 UTC 2016