865e9fe40e089a6559cfc28b4617517b789397f1
[iec.git] / src / type3_AndroidCloud / anbox-master / src / anbox / input / device.h
1 /*
2  * Copyright (C) 2016 Simon Fels <morphis@gravedo.de>
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, as published
6  * by the Free Software Foundation.
7  *
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.
12  *
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/>.
15  *
16  */
17
18 #ifndef ANBOX_INPUT_DEVICE_H_
19 #define ANBOX_INPUT_DEVICE_H_
20
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"
25
26 #include <vector>
27
28 #include <linux/input.h>
29
30 namespace anbox {
31 namespace input {
32 struct Event {
33   std::uint16_t type;
34   std::uint16_t code;
35   std::int32_t value;
36 };
37
38 class Device : public std::enable_shared_from_this<Device> {
39  public:
40   static std::shared_ptr<Device> create(
41       const std::string &path, const std::shared_ptr<Runtime> &runtime);
42
43   Device();
44   ~Device();
45
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);
49
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);
62
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);
65
66   std::string socket_path() const;
67
68  private:
69   int next_id();
70   void new_client(std::shared_ptr<
71                   boost::asio::local::stream_protocol::socket> const &socket);
72
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
76   struct Info {
77     char name[80];
78     int driver_version;
79     struct input_id id;
80     char physical_location[80];
81     char unique_id[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];
91   };
92
93   void set_bit(std::uint8_t *array, const std::uint64_t &bit);
94
95   std::shared_ptr<network::PublishedSocketConnector> connector_;
96   std::atomic<int> next_connection_id_;
97   std::shared_ptr<network::Connections<network::SocketConnection>> connections_;
98   Info info_;
99 };
100 }  // namespace input
101 }  // namespace anbox
102
103 #endif