Mir
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
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 
24 #include <utils/StrongPointer.h>
25 #include <androidfw/Input.h>
26 
27 #include <memory>
28 #include <chrono>
29 
30 namespace droidinput = android;
31 
32 namespace android
33 {
34 class InputChannel;
35 class InputConsumer;
36 class Looper;
37 }
38 
39 namespace mir
40 {
41 namespace input
42 {
43 namespace receiver
44 {
45 class XKBMapper;
46 class InputReceiverReport;
47 
48 namespace android
49 {
50 
53 {
54 public:
55  typedef std::function<nsecs_t(int)> AndroidClock;
56 
57  InputReceiver(droidinput::sp<droidinput::InputChannel> const& input_channel,
58  std::shared_ptr<InputReceiverReport> const& report,
59  AndroidClock clock = systemTime);
60  InputReceiver(int fd,
61  std::shared_ptr<InputReceiverReport> const& report,
62  AndroidClock clock = systemTime);
63 
64  virtual ~InputReceiver();
65  int fd() const;
66 
69  virtual bool next_event(std::chrono::milliseconds const& timeout, MirEvent &ev);
70  virtual bool next_event(MirEvent &ev) { return next_event(std::chrono::milliseconds(-1), ev); }
71 
73  virtual void wake();
74 
75 protected:
76  InputReceiver(const InputReceiver&) = delete;
77  InputReceiver& operator=(const InputReceiver&) = delete;
78 
79 private:
80  droidinput::sp<droidinput::InputChannel> input_channel;
81  std::shared_ptr<InputReceiverReport> const report;
82 
83  std::shared_ptr<droidinput::InputConsumer> input_consumer;
84  droidinput::PreallocatedInputEventFactory event_factory;
85  droidinput::sp<droidinput::Looper> looper;
86 
87  bool fd_added;
88 
89  std::shared_ptr<XKBMapper> xkb_mapper;
90 
91  AndroidClock const android_clock;
92 
93  bool try_next_event(MirEvent &ev);
94 };
95 
96 }
97 }
98 }
99 } // namespace mir
100 
101 #endif // MIR_INPUT_RECEIVER_ANDROID_INPUT_RECEIVER_H_
All things Mir.
Definition: aging_buffer.h:24
int fd() const
Definition: android_input_receiver.cpp:63
virtual ~InputReceiver()
Definition: android_input_receiver.cpp:59
std::function< nsecs_t(int)> AndroidClock
Definition: android_input_receiver.h:55
virtual void wake()
May be used from any thread to wake an InputReceiver blocked in next_event.
Definition: android_input_receiver.cpp:168
virtual bool next_event(MirEvent &ev)
Definition: android_input_receiver.h:70
virtual bool next_event(std::chrono::milliseconds const &timeout, MirEvent &ev)
Synchronously receive an event with millisecond timeout. A negative timeout value is used to request ...
Definition: android_input_receiver.cpp:135
Synchronously receives input events in a blocking manner.
Definition: android_input_receiver.h:52
InputReceiver(droidinput::sp< droidinput::InputChannel > const &input_channel, std::shared_ptr< InputReceiverReport > const &report, AndroidClock clock=systemTime)
Definition: android_input_receiver.h:32
Definition: event.h:227
InputReceiver & operator=(const InputReceiver &)=delete

Copyright © 2012,2013 Canonical Ltd.
Generated on Fri Oct 10 14:07:14 UTC 2014