blob: 8d5a31e0c51faddba627f9c6dd9c3b0cc1549e22 [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
17#ifndef ANDROID_INPUT_DRIVER_H
18#define ANDROID_INPUT_DRIVER_H
19
20#include <stdint.h>
21#include <sys/types.h>
22
23#include "InputHost.h"
24
25#include <hardware/input.h>
26#include <utils/RefBase.h>
27#include <utils/String8.h>
28
Tim Kilbourn2e7f0142015-09-09 16:11:54 -070029// Declare a concrete type for the HAL
30struct input_host {
31};
32
Michael Wright6f783602015-02-13 17:35:16 -080033namespace android {
34
Tim Kilbourn2e7f0142015-09-09 16:11:54 -070035class InputDriverInterface : public input_host_t, public virtual RefBase {
Michael Wright6f783602015-02-13 17:35:16 -080036protected:
37 InputDriverInterface() = default;
38 virtual ~InputDriverInterface() = default;
39
40public:
Tim Kilbourn2e7f0142015-09-09 16:11:54 -070041 virtual void init() = 0;
42
43 virtual input_device_identifier_t* createDeviceIdentifier(
44 const char* name, int32_t productId, int32_t vendorId,
45 input_bus_t bus, const char* uniqueId) = 0;
46 virtual input_device_definition_t* createDeviceDefinition() = 0;
47 virtual input_report_definition_t* createInputReportDefinition() = 0;
48 virtual input_report_definition_t* createOutputReportDefinition() = 0;
49 virtual void freeReportDefinition(input_report_definition_t* reportDef) = 0;
50
51 virtual void inputDeviceDefinitionAddReport(input_device_definition_t* d,
52 input_report_definition_t* r) = 0;
53 virtual void inputReportDefinitionAddCollection(input_report_definition_t* report,
54 input_collection_id_t id, int32_t arity) = 0;
55 virtual void inputReportDefinitionDeclareUsageInt(input_report_definition_t* report,
56 input_collection_id_t id, input_usage_t usage, int32_t min, int32_t max,
57 float resolution) = 0;
58 virtual void inputReportDefinitionDeclareUsagesBool(input_report_definition_t* report,
59 input_collection_id_t id, input_usage_t* usage, size_t usageCount) = 0;
60
61 virtual input_device_handle_t* registerDevice(input_device_identifier_t* id,
62 input_device_definition_t* d) = 0;
63 virtual void unregisterDevice(input_device_handle_t* handle) = 0;
64
65 virtual input_report_t* inputAllocateReport(input_report_definition_t* r) = 0;
66 virtual void inputReportSetUsageInt(input_report_t* r, input_collection_id_t id,
67 input_usage_t usage, int32_t value, int32_t arity_index) = 0;
68 virtual void inputReportSetUsageBool(input_report_t* r, input_collection_id_t id,
69 input_usage_t usage, bool value, int32_t arity_index) = 0;
70 virtual void reportEvent(input_device_handle_t* d, input_report_t* report) = 0;
71
72 virtual input_property_map_t* inputGetDevicePropertyMap(input_device_identifier_t* id) = 0;
73 virtual input_property_t* inputGetDeviceProperty(input_property_map_t* map,
74 const char* key) = 0;
75 virtual const char* inputGetPropertyKey(input_property_t* property) = 0;
76 virtual const char* inputGetPropertyValue(input_property_t* property) = 0;
77 virtual void inputFreeDeviceProperty(input_property_t* property) = 0;
78 virtual void inputFreeDevicePropertyMap(input_property_map_t* map) = 0;
Michael Wright6f783602015-02-13 17:35:16 -080079
80 virtual void dump(String8& result) = 0;
81};
82
83class InputDriver : public InputDriverInterface {
84public:
85 InputDriver(const char* name);
86 virtual ~InputDriver() = default;
87
Tim Kilbourn2e7f0142015-09-09 16:11:54 -070088 virtual void init() override;
89
90 virtual input_device_identifier_t* createDeviceIdentifier(
91 const char* name, int32_t productId, int32_t vendorId,
92 input_bus_t bus, const char* uniqueId) override;
93 virtual input_device_definition_t* createDeviceDefinition() override;
94 virtual input_report_definition_t* createInputReportDefinition() override;
95 virtual input_report_definition_t* createOutputReportDefinition() override;
96 virtual void freeReportDefinition(input_report_definition_t* reportDef) override;
97
98 virtual void inputDeviceDefinitionAddReport(input_device_definition_t* d,
99 input_report_definition_t* r) override;
100 virtual void inputReportDefinitionAddCollection(input_report_definition_t* report,
101 input_collection_id_t id, int32_t arity) override;
102 virtual void inputReportDefinitionDeclareUsageInt(input_report_definition_t* report,
103 input_collection_id_t id, input_usage_t usage, int32_t min, int32_t max,
104 float resolution) override;
105 virtual void inputReportDefinitionDeclareUsagesBool(input_report_definition_t* report,
106 input_collection_id_t id, input_usage_t* usage, size_t usageCount) override;
107
108 virtual input_device_handle_t* registerDevice(input_device_identifier_t* id,
109 input_device_definition_t* d) override;
110 virtual void unregisterDevice(input_device_handle_t* handle) override;
111
112 virtual input_report_t* inputAllocateReport(input_report_definition_t* r) override;
113 virtual void inputReportSetUsageInt(input_report_t* r, input_collection_id_t id,
114 input_usage_t usage, int32_t value, int32_t arity_index) override;
115 virtual void inputReportSetUsageBool(input_report_t* r, input_collection_id_t id,
116 input_usage_t usage, bool value, int32_t arity_index) override;
117 virtual void reportEvent(input_device_handle_t* d, input_report_t* report) override;
118
119 virtual input_property_map_t* inputGetDevicePropertyMap(input_device_identifier_t* id) override;
120 virtual input_property_t* inputGetDeviceProperty(input_property_map_t* map,
121 const char* key) override;
122 virtual const char* inputGetPropertyKey(input_property_t* property) override;
123 virtual const char* inputGetPropertyValue(input_property_t* property) override;
124 virtual void inputFreeDeviceProperty(input_property_t* property) override;
125 virtual void inputFreeDevicePropertyMap(input_property_map_t* map) override;
Michael Wright6f783602015-02-13 17:35:16 -0800126
127 virtual void dump(String8& result) override;
128
129private:
130 String8 mName;
131 const input_module_t* mHal;
132};
133
134
135extern "C" {
136
137input_device_identifier_t* create_device_identifier(input_host_t* host,
138 const char* name, int32_t product_id, int32_t vendor_id,
139 input_bus_t bus, const char* unique_id);
140
141input_device_definition_t* create_device_definition(input_host_t* host);
142
143input_report_definition_t* create_input_report_definition(input_host_t* host);
144
145input_report_definition_t* create_output_report_definition(input_host_t* host);
146
Tim Kilbournc4729862015-05-08 17:13:43 -0700147void free_report_definition(input_host_t* host, input_report_definition_t* report_def);
148
Michael Wright6f783602015-02-13 17:35:16 -0800149void input_device_definition_add_report(input_host_t* host,
150 input_device_definition_t* d, input_report_definition_t* r);
151
152void input_report_definition_add_collection(input_host_t* host,
153 input_report_definition_t* report, input_collection_id_t id, int32_t arity);
154
155void input_report_definition_declare_usage_int(input_host_t* host,
156 input_report_definition_t* report, input_collection_id_t id,
157 input_usage_t usage, int32_t min, int32_t max, float resolution);
158
159void input_report_definition_declare_usages_bool(input_host_t* host,
160 input_report_definition_t* report, input_collection_id_t id,
161 input_usage_t* usage, size_t usage_count);
162
163
164input_device_handle_t* register_device(input_host_t* host,
165 input_device_identifier_t* id, input_device_definition_t* d);
166
167void unregister_device(input_host_t* host, input_device_handle_t* handle);
168
169input_report_t* input_allocate_report(input_host_t* host, input_report_definition_t* r);
170
Tim Kilbourn8943ce32015-02-27 15:09:34 -0800171void input_report_set_usage_int(input_host_t* host, input_report_t* r,
172 input_collection_id_t id, input_usage_t usage, int32_t value, int32_t arity_index);
173
174void input_report_set_usage_bool(input_host_t* host, input_report_t* r,
175 input_collection_id_t id, input_usage_t usage, bool value, int32_t arity_index);
176
Michael Wright6f783602015-02-13 17:35:16 -0800177void report_event(input_host_t* host, input_device_handle_t* d, input_report_t* report);
178
Tim Kilbourne5364c82015-04-06 13:48:50 -0700179input_property_map_t* input_get_device_property_map(input_host_t* host,
180 input_device_identifier_t* id);
181
182input_property_t* input_get_device_property(input_host_t* host, input_property_map_t* map,
183 const char* key);
184
185const char* input_get_property_key(input_host_t* host, input_property_t* property);
186
187const char* input_get_property_value(input_host_t* host, input_property_t* property);
188
189void input_free_device_property(input_host_t* host, input_property_t* property);
190
191void input_free_device_property_map(input_host_t* host, input_property_map_t* map);
Michael Wright6f783602015-02-13 17:35:16 -0800192}
193
194} // namespace android
195#endif // ANDROID_INPUT_DRIVER_H