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 notify_receiver_fd;
85  Fd notify_sender_fd;
86  Fd timer_fd;
87 
88  droidinput::sp<droidinput::InputChannel> input_channel;
89  std::function<void(MirEvent*)> const handler;
90  std::shared_ptr<XKBMapper> const xkb_mapper;
91  std::shared_ptr<InputReceiverReport> const report;
92 
93  std::shared_ptr<droidinput::InputConsumer> input_consumer;
94  droidinput::PreallocatedInputEventFactory event_factory;
95 
96  AndroidClock const android_clock;
97  int event_rate_hz;
98 
99  void process_and_maybe_send_event();
100  static void consume_wake_notification(mir::Fd const& fd);
101  void wake();
102 };
103 
104 }
105 }
106 }
107 } // namespace mir
108 
109 #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
bool dispatch(dispatch::FdEvents events) override
Dispatch one pending event.
Definition: fd.h:33
InputReceiver(droidinput::sp< droidinput::InputChannel > const &input_channel, std::shared_ptr< XKBMapper > const &keymapper, std::function< void(MirEvent *)> const &event_handling_callback, std::shared_ptr< InputReceiverReport > const &report, AndroidClock clock=systemTime)
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
dispatch::FdEvents relevant_events() const override
The set of file-descriptor events this Dispatchable handles.
Definition: dispatchable.h:38
uint32_t FdEvents
Definition: dispatchable.h:36
Definition: android_input_receiver.h:36
Definition: event_private.h:178
Fd watch_fd() const override
Get a poll()able file descriptor.
InputReceiver & operator=(const InputReceiver &)=delete

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