Mir
android_input_receiver.h
Go to the documentation of this file.
1 /*
2  * Copyright © 2013 Canonical Ltd.
3  *
4  * This program is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU Lesser General Public License version 3 as
6  * 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 Lesser General Public License for more details.
12  *
13  * You should have received a copy of the GNU Lesser General Public License
14  * along with this program. If not, see <http://www.gnu.org/licenses/>.
15  *
16  * Authored by: Robert Carr <robert.carr@canonical.com>
17  */
18 
19 #ifndef MIR_INPUT_RECEIVER_ANDROID_INPUT_RECEIVER_H_
20 #define MIR_INPUT_RECEIVER_ANDROID_INPUT_RECEIVER_H_
21 
22 #include "mir_toolkit/event.h"
23 
26 
27 #include <utils/StrongPointer.h>
28 #include <androidfw/Input.h>
29 
30 #include <memory>
31 #include <chrono>
32 #include <functional>
33 
34 namespace droidinput = android;
35 
36 namespace android
37 {
38 class InputChannel;
39 class InputConsumer;
40 class Looper;
41 }
42 
43 namespace mir
44 {
45 namespace input
46 {
47 namespace receiver
48 {
49 class XKBMapper;
50 class InputReceiverReport;
51 
52 namespace android
53 {
54 
57 {
58 public:
59  typedef std::function<std::chrono::nanoseconds(int)> AndroidClock;
60 
61  InputReceiver(droidinput::sp<droidinput::InputChannel> const& input_channel,
62  std::shared_ptr<XKBMapper> const& keymapper,
63  std::function<void(MirEvent*)> const& event_handling_callback,
64  std::shared_ptr<InputReceiverReport> const& report,
65  AndroidClock clock = systemTime);
66  InputReceiver(int fd,
67  std::shared_ptr<XKBMapper> const& keymapper,
68  std::function<void(MirEvent*)> const& event_handling_callback,
69  std::shared_ptr<InputReceiverReport> const& report,
70  AndroidClock clock = systemTime);
71 
72  virtual ~InputReceiver();
73 
74  Fd watch_fd() const override;
75  bool dispatch(dispatch::FdEvents events) override;
76  dispatch::FdEvents relevant_events() const override;
77 
78 protected:
79  InputReceiver(const InputReceiver&) = delete;
80  InputReceiver& operator=(const InputReceiver&) = delete;
81 
82 private:
84  Fd const timer_fd;
85  Fd const wake_fd;
86 
87  droidinput::sp<droidinput::InputChannel> input_channel;
88  std::function<void(MirEvent*)> const handler;
89  std::shared_ptr<XKBMapper> const xkb_mapper;
90  std::shared_ptr<InputReceiverReport> const report;
91 
92  std::shared_ptr<droidinput::InputConsumer> input_consumer;
93  droidinput::PreallocatedInputEventFactory event_factory;
94 
95  AndroidClock const android_clock;
96  int event_rate_hz;
97 
98  void process_and_maybe_send_event();
99  static void consume_wake_notification(mir::Fd const& fd);
100  void wake();
101 };
102 
103 }
104 }
105 }
106 } // namespace mir
107 
108 #endif // MIR_INPUT_RECEIVER_ANDROID_INPUT_RECEIVER_H_
All things Mir.
Definition: atomic_callback.h:25
std::function< std::chrono::nanoseconds(int)> AndroidClock
Definition: android_input_receiver.h:59
Definition: fd.h:33
Synchronously receives input events in a blocking manner.
Definition: android_input_receiver.h:56
An adaptor that combines multiple Dispatchables into a single Dispatchable.
Definition: multiplexing_dispatchable.h:52
Definition: dispatchable.h:38
uint32_t FdEvents
Definition: dispatchable.h:36
Definition: android_input_receiver.h:36
Definition: event.h:30

Copyright © 2012-2015 Canonical Ltd.
Generated on Thu Sep 8 14:50:19 UTC 2016