Mir
default_input_device_hub.h
Go to the documentation of this file.
1 /*
2  * Copyright © 2015 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_DEFAULT_INPUT_DEVICE_HUB_H_
20 #define MIR_INPUT_DEFAULT_INPUT_DEVICE_HUB_H_
21 
22 #include "default_event_builder.h"
23 
25 #include "mir/input/input_sink.h"
26 #include "mir/input/seat.h"
29 
30 #include "mir_toolkit/event.h"
31 
32 #include <linux/input.h>
33 #include <vector>
34 #include <memory>
35 #include <mutex>
36 
37 namespace mir
38 {
39 class ServerActionQueue;
40 namespace frontend
41 {
42 class EventSink;
43 }
44 namespace cookie
45 {
46 class Authority;
47 }
48 namespace dispatch
49 {
50 class Dispatchable;
51 class MultiplexingDispatchable;
52 class ActionQueue;
53 }
54 namespace input
55 {
56 class InputSink;
57 class InputDeviceObserver;
58 class DefaultDevice;
59 class Seat;
60 class KeyMapper;
61 
63 {
64 public:
65  DefaultInputDeviceHub(std::shared_ptr<frontend::EventSink> const& sink,
66  std::shared_ptr<Seat> const& seat,
67  std::shared_ptr<dispatch::MultiplexingDispatchable> const& input_multiplexer,
68  std::shared_ptr<ServerActionQueue> const& observer_queue,
69  std::shared_ptr<cookie::Authority> const& cookie_authority,
70  std::shared_ptr<KeyMapper> const& key_mapper);
71 
72  // InputDeviceRegistry - calls from mi::Platform
73  void add_device(std::shared_ptr<InputDevice> const& device) override;
74  void remove_device(std::shared_ptr<InputDevice> const& device) override;
75 
76  // InputDeviceHub - calls from server components / shell
77  void add_observer(std::shared_ptr<InputDeviceObserver> const&) override;
78  void remove_observer(std::weak_ptr<InputDeviceObserver> const&) override;
79  void for_each_input_device(std::function<void(Device const& device)> const& callback) override;
80 
81 private:
82  void update_spots();
83  void add_device_handle(std::shared_ptr<DefaultDevice> const& handle);
84  void remove_device_handle(MirInputDeviceId id);
85  MirInputDeviceId create_new_device_id();
86  std::shared_ptr<Seat> const seat;
87  std::shared_ptr<frontend::EventSink> const sink;
88  std::shared_ptr<dispatch::MultiplexingDispatchable> const input_dispatchable;
89  std::mutex observer_guard;
90  std::shared_ptr<ServerActionQueue> const observer_queue;
91  std::shared_ptr<dispatch::ActionQueue> const device_queue;
92  std::shared_ptr<cookie::Authority> const cookie_authority;
93  std::shared_ptr<KeyMapper> const key_mapper;
94 
95  struct RegisteredDevice : public InputSink
96  {
97  public:
98  RegisteredDevice(std::shared_ptr<InputDevice> const& dev,
99  MirInputDeviceId dev_id,
100  std::shared_ptr<dispatch::MultiplexingDispatchable> const& multiplexer,
101  std::shared_ptr<cookie::Authority> const& cookie_authority,
102  std::shared_ptr<DefaultDevice> const& handle);
103  void handle_input(MirEvent& event) override;
104  mir::geometry::Rectangle bounding_rectangle() const override;
105  bool device_matches(std::shared_ptr<InputDevice> const& dev) const;
106  void start(std::shared_ptr<Seat> const& seat);
107  void stop();
108  MirInputDeviceId id();
109  std::shared_ptr<Seat> seat;
110  const std::shared_ptr<DefaultDevice> handle;
111 
112  void key_state(std::vector<uint32_t> const& scan_codes) override;
113  void pointer_state(MirPointerButtons buttons) override;
114  private:
115  MirInputDeviceId device_id;
116  std::unique_ptr<DefaultEventBuilder> builder;
117  std::shared_ptr<cookie::Authority> cookie_authority;
118  std::shared_ptr<InputDevice> const device;
119  std::shared_ptr<dispatch::MultiplexingDispatchable> const multiplexer;
120  };
121 
122  std::vector<std::shared_ptr<Device>> handles;
123  std::vector<std::unique_ptr<RegisteredDevice>> devices;
124  std::vector<std::shared_ptr<InputDeviceObserver>> observers;
125 
126  MirInputDeviceId device_id_generator;
127 };
128 
129 }
130 }
131 
132 #endif
All things Mir.
Definition: atomic_callback.h:25
Definition: input_device_hub.h:32
Definition: input_device_registry.h:31
int64_t MirInputDeviceId
Definition: input_event.h:35
Definition: default_input_device_hub.h:62
unsigned int MirPointerButtons
Definition: pointer_event.h:85
std::promise< bool > stop
Definition: in.cpp:28
Definition: rectangle.h:33
Definition: device.h:38
Definition: event.h:30
Definition: input_sink.h:33

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