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

Copyright © 2012,2013 Canonical Ltd.
Generated on Tue Mar 24 16:15:19 UTC 2015