blob: b4c90943a8a3c2004ebaef533233f51a5c7d1a2d [file] [log] [blame]
Michael Wright6f783602015-02-13 17:35:16 -08001/*
2 * Copyright (C) 2015 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
Prabir Pradhan48108662022-09-09 21:22:04 +000017#pragma once
Michael Wright6f783602015-02-13 17:35:16 -080018
19#include <stdint.h>
20#include <sys/types.h>
21
22#include "InputHost.h"
23
24#include <hardware/input.h>
25#include <utils/RefBase.h>
26#include <utils/String8.h>
27
Tim Kilbourn2e7f0142015-09-09 16:11:54 -070028// Declare a concrete type for the HAL
29struct input_host {
30};
31
Michael Wright6f783602015-02-13 17:35:16 -080032namespace android {
33
Tim Kilbourn2e7f0142015-09-09 16:11:54 -070034class InputDriverInterface : public input_host_t, public virtual RefBase {
Michael Wright6f783602015-02-13 17:35:16 -080035protected:
36 InputDriverInterface() = default;
37 virtual ~InputDriverInterface() = default;
38
39public:
Tim Kilbourn2e7f0142015-09-09 16:11:54 -070040 virtual void init() = 0;
41
42 virtual input_device_identifier_t* createDeviceIdentifier(
43 const char* name, int32_t productId, int32_t vendorId,
44 input_bus_t bus, const char* uniqueId) = 0;
45 virtual input_device_definition_t* createDeviceDefinition() = 0;
46 virtual input_report_definition_t* createInputReportDefinition() = 0;
47 virtual input_report_definition_t* createOutputReportDefinition() = 0;
48 virtual void freeReportDefinition(input_report_definition_t* reportDef) = 0;
49
50 virtual void inputDeviceDefinitionAddReport(input_device_definition_t* d,
51 input_report_definition_t* r) = 0;
52 virtual void inputReportDefinitionAddCollection(input_report_definition_t* report,
53 input_collection_id_t id, int32_t arity) = 0;
54 virtual void inputReportDefinitionDeclareUsageInt(input_report_definition_t* report,
55 input_collection_id_t id, input_usage_t usage, int32_t min, int32_t max,
56 float resolution) = 0;
57 virtual void inputReportDefinitionDeclareUsagesBool(input_report_definition_t* report,
58 input_collection_id_t id, input_usage_t* usage, size_t usageCount) = 0;
59
60 virtual input_device_handle_t* registerDevice(input_device_identifier_t* id,
61 input_device_definition_t* d) = 0;
62 virtual void unregisterDevice(input_device_handle_t* handle) = 0;
63
64 virtual input_report_t* inputAllocateReport(input_report_definition_t* r) = 0;
65 virtual void inputReportSetUsageInt(input_report_t* r, input_collection_id_t id,
66 input_usage_t usage, int32_t value, int32_t arity_index) = 0;
67 virtual void inputReportSetUsageBool(input_report_t* r, input_collection_id_t id,
68 input_usage_t usage, bool value, int32_t arity_index) = 0;
69 virtual void reportEvent(input_device_handle_t* d, input_report_t* report) = 0;
70
71 virtual input_property_map_t* inputGetDevicePropertyMap(input_device_identifier_t* id) = 0;
72 virtual input_property_t* inputGetDeviceProperty(input_property_map_t* map,
73 const char* key) = 0;
74 virtual const char* inputGetPropertyKey(input_property_t* property) = 0;
75 virtual const char* inputGetPropertyValue(input_property_t* property) = 0;
76 virtual void inputFreeDeviceProperty(input_property_t* property) = 0;
77 virtual void inputFreeDevicePropertyMap(input_property_map_t* map) = 0;
Michael Wright6f783602015-02-13 17:35:16 -080078
79 virtual void dump(String8& result) = 0;
80};
81
82class InputDriver : public InputDriverInterface {
83public:
Chih-Hung Hsieh6d2ede12016-09-01 11:28:23 -070084 explicit InputDriver(const char* name);
Michael Wright6f783602015-02-13 17:35:16 -080085 virtual ~InputDriver() = default;
86
Tim Kilbourn2e7f0142015-09-09 16:11:54 -070087 virtual void init() override;
88
89 virtual input_device_identifier_t* createDeviceIdentifier(
90 const char* name, int32_t productId, int32_t vendorId,
91 input_bus_t bus, const char* uniqueId) override;
92 virtual input_device_definition_t* createDeviceDefinition() override;
93 virtual input_report_definition_t* createInputReportDefinition() override;
94 virtual input_report_definition_t* createOutputReportDefinition() override;
95 virtual void freeReportDefinition(input_report_definition_t* reportDef) override;
96
97 virtual void inputDeviceDefinitionAddReport(input_device_definition_t* d,
98 input_report_definition_t* r) override;
99 virtual void inputReportDefinitionAddCollection(input_report_definition_t* report,
100 input_collection_id_t id, int32_t arity) override;
101 virtual void inputReportDefinitionDeclareUsageInt(input_report_definition_t* report,
102 input_collection_id_t id, input_usage_t usage, int32_t min, int32_t max,
103 float resolution) override;
104 virtual void inputReportDefinitionDeclareUsagesBool(input_report_definition_t* report,
105 input_collection_id_t id, input_usage_t* usage, size_t usageCount) override;
106
107 virtual input_device_handle_t* registerDevice(input_device_identifier_t* id,
108 input_device_definition_t* d) override;
109 virtual void unregisterDevice(input_device_handle_t* handle) override;
110
111 virtual input_report_t* inputAllocateReport(input_report_definition_t* r) override;
112 virtual void inputReportSetUsageInt(input_report_t* r, input_collection_id_t id,
113 input_usage_t usage, int32_t value, int32_t arity_index) override;
114 virtual void inputReportSetUsageBool(input_report_t* r, input_collection_id_t id,
115 input_usage_t usage, bool value, int32_t arity_index) override;
116 virtual void reportEvent(input_device_handle_t* d, input_report_t* report) override;
117
118 virtual input_property_map_t* inputGetDevicePropertyMap(input_device_identifier_t* id) override;
119 virtual input_property_t* inputGetDeviceProperty(input_property_map_t* map,
120 const char* key) override;
121 virtual const char* inputGetPropertyKey(input_property_t* property) override;
122 virtual const char* inputGetPropertyValue(input_property_t* property) override;
123 virtual void inputFreeDeviceProperty(input_property_t* property) override;
124 virtual void inputFreeDevicePropertyMap(input_property_map_t* map) override;
Michael Wright6f783602015-02-13 17:35:16 -0800125
126 virtual void dump(String8& result) override;
127
128private:
129 String8 mName;
130 const input_module_t* mHal;
131};
132
133
134extern "C" {
135
136input_device_identifier_t* create_device_identifier(input_host_t* host,
137 const char* name, int32_t product_id, int32_t vendor_id,
138 input_bus_t bus, const char* unique_id);
139
140input_device_definition_t* create_device_definition(input_host_t* host);
141
142input_report_definition_t* create_input_report_definition(input_host_t* host);
143
144input_report_definition_t* create_output_report_definition(input_host_t* host);
145
Tim Kilbournc4729862015-05-08 17:13:43 -0700146void free_report_definition(input_host_t* host, input_report_definition_t* report_def);
147
Michael Wright6f783602015-02-13 17:35:16 -0800148void input_device_definition_add_report(input_host_t* host,
149 input_device_definition_t* d, input_report_definition_t* r);
150
151void input_report_definition_add_collection(input_host_t* host,
152 input_report_definition_t* report, input_collection_id_t id, int32_t arity);
153
154void input_report_definition_declare_usage_int(input_host_t* host,
155 input_report_definition_t* report, input_collection_id_t id,
156 input_usage_t usage, int32_t min, int32_t max, float resolution);
157
158void input_report_definition_declare_usages_bool(input_host_t* host,
159 input_report_definition_t* report, input_collection_id_t id,
160 input_usage_t* usage, size_t usage_count);
161
162
163input_device_handle_t* register_device(input_host_t* host,
164 input_device_identifier_t* id, input_device_definition_t* d);
165
166void unregister_device(input_host_t* host, input_device_handle_t* handle);
167
168input_report_t* input_allocate_report(input_host_t* host, input_report_definition_t* r);
169
Tim Kilbourn8943ce32015-02-27 15:09:34 -0800170void input_report_set_usage_int(input_host_t* host, input_report_t* r,
171 input_collection_id_t id, input_usage_t usage, int32_t value, int32_t arity_index);
172
173void input_report_set_usage_bool(input_host_t* host, input_report_t* r,
174 input_collection_id_t id, input_usage_t usage, bool value, int32_t arity_index);
175
Michael Wright6f783602015-02-13 17:35:16 -0800176void report_event(input_host_t* host, input_device_handle_t* d, input_report_t* report);
177
Tim Kilbourne5364c82015-04-06 13:48:50 -0700178input_property_map_t* input_get_device_property_map(input_host_t* host,
179 input_device_identifier_t* id);
180
181input_property_t* input_get_device_property(input_host_t* host, input_property_map_t* map,
182 const char* key);
183
184const char* input_get_property_key(input_host_t* host, input_property_t* property);
185
186const char* input_get_property_value(input_host_t* host, input_property_t* property);
187
188void input_free_device_property(input_host_t* host, input_property_t* property);
189
190void input_free_device_property_map(input_host_t* host, input_property_map_t* map);
Michael Wright6f783602015-02-13 17:35:16 -0800191}
192
193} // namespace android