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 
62 {
63 public:
64  DefaultInputDeviceHub(std::shared_ptr<frontend::EventSink> const& sink,
65  std::shared_ptr<Seat> const& seat,
66  std::shared_ptr<dispatch::MultiplexingDispatchable> const& input_multiplexer,
67  std::shared_ptr<ServerActionQueue> const& observer_queue,
68  std::shared_ptr<cookie::Authority> const& cookie_authority);
69 
70  // InputDeviceRegistry - calls from mi::Platform
71  void add_device(std::shared_ptr<InputDevice> const& device) override;
72  void remove_device(std::shared_ptr<InputDevice> const& device) override;
73 
74  // InputDeviceHub - calls from server components / shell
75  void add_observer(std::shared_ptr<InputDeviceObserver> const&) override;
76  void remove_observer(std::weak_ptr<InputDeviceObserver> const&) override;
77  void for_each_input_device(std::function<void(Device const& device)> const& callback) override;
78 
79 private:
80  void update_spots();
81  void add_device_handle(std::shared_ptr<DefaultDevice> const& handle);
82  void remove_device_handle(MirInputDeviceId id);
83  MirInputDeviceId create_new_device_id();
84  std::shared_ptr<Seat> const seat;
85  std::shared_ptr<frontend::EventSink> const sink;
86  std::shared_ptr<dispatch::MultiplexingDispatchable> const input_dispatchable;
87  std::mutex observer_guard;
88  std::shared_ptr<ServerActionQueue> const observer_queue;
89  std::shared_ptr<dispatch::ActionQueue> const device_queue;
90  std::shared_ptr<cookie::Authority> const cookie_authority;
91 
92  struct RegisteredDevice : public InputSink
93  {
94  public:
95  RegisteredDevice(std::shared_ptr<InputDevice> const& dev,
96  MirInputDeviceId dev_id,
97  std::shared_ptr<dispatch::MultiplexingDispatchable> const& multiplexer,
98  std::shared_ptr<cookie::Authority> const& cookie_authority,
99  std::shared_ptr<DefaultDevice> const& handle);
100  void handle_input(MirEvent& event) override;
101  mir::geometry::Rectangle bounding_rectangle() const override;
102  bool device_matches(std::shared_ptr<InputDevice> const& dev) const;
103  void start(std::shared_ptr<Seat> const& seat);
104  void stop();
105  MirInputDeviceId id();
106  std::shared_ptr<Seat> seat;
107  const std::shared_ptr<DefaultDevice> handle;
108  private:
109  MirInputDeviceId device_id;
110  DefaultEventBuilder builder;
111  std::shared_ptr<InputDevice> const device;
112  std::shared_ptr<dispatch::MultiplexingDispatchable> const multiplexer;
113  };
114 
115  std::vector<std::shared_ptr<Device>> handles;
116  std::vector<std::unique_ptr<RegisteredDevice>> devices;
117  std::vector<std::shared_ptr<InputDeviceObserver>> observers;
118 
119  MirInputDeviceId device_id_generator;
120 };
121 
122 }
123 }
124 
125 #endif
All things Mir.
Definition: atomic_callback.h:25
Definition: input_device_hub.h:32
Definition: default_event_builder.h:34
Definition: input_device_registry.h:31
int64_t MirInputDeviceId
Definition: input_event.h:35
Definition: default_input_device_hub.h:61
std::promise< bool > stop
Definition: in.cpp:28
Definition: rectangle.h:33
Definition: event_private.h:181
Definition: device.h:37
Definition: input_sink.h:31

Copyright © 2012-2015 Canonical Ltd.
Generated on Wed Mar 30 00:29:56 UTC 2016