2 * Copyright (C) 2016 Simon Fels <morphis@gravedo.de>
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, as published
6 * by the Free Software Foundation.
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranties of
10 * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
11 * PURPOSE. See the GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License along
14 * with this program. If not, see <http://www.gnu.org/licenses/>.
18 #ifndef ANBOX_INPUT_DEVICE_H_
19 #define ANBOX_INPUT_DEVICE_H_
21 #include "anbox/network/connections.h"
22 #include "anbox/network/published_socket_connector.h"
23 #include "anbox/network/socket_connection.h"
24 #include "anbox/runtime.h"
28 #include <linux/input.h>
38 class Device : public std::enable_shared_from_this<Device> {
40 static std::shared_ptr<Device> create(
41 const std::string &path, const std::shared_ptr<Runtime> &runtime);
46 void send_events(const std::vector<Event> &events);
47 void send_event(const std::uint16_t &code, const std::uint16_t &event,
48 const std::int32_t &value);
50 void set_name(const std::string &name);
51 void set_driver_version(const int &version);
52 void set_input_id(const struct input_id &id);
53 void set_physical_location(const std::string &physical_location);
54 void set_unique_id(const std::string &unique_id);
55 void set_key_bit(const std::uint64_t &bit);
56 void set_abs_bit(const std::uint64_t &bit);
57 void set_rel_bit(const std::uint64_t &bit);
58 void set_sw_bit(const std::uint64_t &bit);
59 void set_led_bit(const std::uint64_t &bit);
60 void set_ff_bit(const std::uint64_t &bit);
61 void set_prop_bit(const std::uint64_t &bit);
63 void set_abs_min(const std::uint64_t &bit, const std::uint32_t &value);
64 void set_abs_max(const std::uint64_t &bit, const std::uint32_t &value);
66 std::string socket_path() const;
70 void new_client(std::shared_ptr<
71 boost::asio::local::stream_protocol::socket> const &socket);
73 // NOTE: If you modify this struct you have to modify the version on
74 // the Android side too. See
75 // frameworks/native/services/inputflinger/EventHub.cpp
80 char physical_location[80];
82 std::uint8_t key_bitmask[(KEY_MAX + 1) / 8];
83 std::uint8_t abs_bitmask[(ABS_MAX + 1) / 8];
84 std::uint8_t rel_bitmask[(REL_MAX + 1) / 8];
85 std::uint8_t sw_bitmask[(SW_MAX + 1) / 8];
86 std::uint8_t led_bitmask[(LED_MAX + 1) / 8];
87 std::uint8_t ff_bitmask[(FF_MAX + 1) / 8];
88 std::uint8_t prop_bitmask[(INPUT_PROP_MAX + 1) / 8];
89 std::uint32_t abs_max[ABS_CNT];
90 std::uint32_t abs_min[ABS_CNT];
93 void set_bit(std::uint8_t *array, const std::uint64_t &bit);
95 std::shared_ptr<network::PublishedSocketConnector> connector_;
96 std::atomic<int> next_connection_id_;
97 std::shared_ptr<network::Connections<network::SocketConnection>> connections_;