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 time
41 {
42 class Alarm;
43 }
44 namespace compositor
45 {
46 class Scene;
47 }
48 namespace scene
49 {
50 class InputRegistrar;
51 }
52 namespace input
53 {
54 class InputReport;
55 namespace android
56 {
57 class InputSendEntry;
58 class Surface;
59 
61 {
62 public:
63  InputSender(std::shared_ptr<compositor::Scene> const& scene,
64  std::shared_ptr<MainLoop> const& main_loop,
65  std::shared_ptr<InputSendObserver> const& observer,
66  std::shared_ptr<InputReport> const& report);
67 
68  void send_event(MirEvent const& event, std::shared_ptr<InputChannel> const& channel) override;
69 
70 private:
71  struct InputSenderState;
72 
73  class SceneObserver : public scene::NullObserver
74  {
75  public:
76  explicit SceneObserver(InputSenderState & state);
77  private:
78  void surface_added(scene::Surface* surface) override;
79  void surface_removed(scene::Surface* surface) override;
80  void surface_exists(scene::Surface* surface) override;
81  void scene_changed() override;
82 
83  void remove_transfer_for(input::Surface* surface);
84  InputSenderState & state;
85  };
86 
87  class ActiveTransfer
88  {
89  public:
90  ActiveTransfer(InputSenderState & state, int server_fd, input::Surface* surface);
91  ~ActiveTransfer();
92  void send(InputSendEntry && item);
93  bool used_for_surface(input::Surface const* surface) const;
94  void on_surface_disappeared();
95  void subscribe();
96  void unsubscribe();
97 
98  private:
99  void on_finish_signal();
100  void on_response_timeout();
101  void update_timer();
102  void cancel_timer();
103  droidinput::status_t send_key_event(uint32_t sequence_id, MirKeyEvent const& event);
104  droidinput::status_t send_motion_event(uint32_t sequence_id, MirMotionEvent const& event);
105  InputSendEntry unqueue_entry(uint32_t sequence_id);
106  void enqueue_entry(InputSendEntry && entry);
107 
108  InputSenderState & state;
109  droidinput::InputPublisher publisher;
110  input::Surface * surface;
111  std::vector<InputSendEntry> pending_responses;
112  std::mutex transfer_mutex;
113  std::atomic<bool> subscribed{false};
114  std::unique_ptr<time::Alarm> send_timer;
115 
116  ActiveTransfer& operator=(ActiveTransfer const&) = delete;
117  ActiveTransfer(ActiveTransfer const&) = delete;
118  };
119 
120  struct InputSenderState
121  {
122  InputSenderState(std::shared_ptr<MainLoop> const& main_loop,
123  std::shared_ptr<InputSendObserver> const& observer,
124  std::shared_ptr<InputReport> const& report);
125  void send_event(std::shared_ptr<InputChannel> const& channel, MirEvent const& event);
126  void add_transfer(int fd, input::Surface* surface);
127  void remove_transfer(int fd);
128 
129  std::shared_ptr<MainLoop> const main_loop;
130  std::shared_ptr<InputReport> const report;
131  std::shared_ptr<InputSendObserver> const observer;
132 
133  private:
134  std::shared_ptr<ActiveTransfer> get_transfer(int fd);
135  uint32_t next_seq();
136  uint32_t seq;
137 
138  std::unordered_map<int,std::shared_ptr<ActiveTransfer>> transfers;
139  std::mutex sender_mutex;
140  };
141 
142  InputSenderState state;
143  std::shared_ptr<compositor::Scene> scene;
144 };
145 
146 }
147 }
148 }
149 
150 #endif
InputSender & operator=(InputSender const &)=delete
All things Mir.
Definition: atomic_callback.h:25
Definition: input_send_entry.h:38
Definition: surface.h:47
Definition: null_observer.h:28
Definition: input_sender.h:60
Definition: event_private.h:51
surface_removed
Definition: scene_report_tp.h:46
surface_added
Definition: scene_report_tp.h:41
void send_event(MirEvent const &event, std::shared_ptr< InputChannel > const &channel) override
Definition: android_input_receiver.h:36
Definition: event_private.h:178
Definition: surface.h:47
Definition: event_private.h:91
Definition: input_sender.h:34

Copyright © 2012-2015 Canonical Ltd.
Generated on Thu Oct 8 16:20:16 UTC 2015