• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
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 #pragma once
18 
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 
28 // Declare a concrete type for the HAL
29 struct input_host {
30 };
31 
32 namespace android {
33 
34 class InputDriverInterface : public input_host_t, public virtual RefBase {
35 protected:
36     InputDriverInterface() = default;
37     virtual ~InputDriverInterface() = default;
38 
39 public:
40     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;
78 
79     virtual void dump(String8& result) = 0;
80 };
81 
82 class InputDriver : public InputDriverInterface {
83 public:
84     explicit InputDriver(const char* name);
85     virtual ~InputDriver() = default;
86 
87     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;
125 
126     virtual void dump(String8& result) override;
127 
128 private:
129     String8 mName;
130     const input_module_t* mHal;
131 };
132 
133 
134 extern "C" {
135 
136 input_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 
140 input_device_definition_t* create_device_definition(input_host_t* host);
141 
142 input_report_definition_t* create_input_report_definition(input_host_t* host);
143 
144 input_report_definition_t* create_output_report_definition(input_host_t* host);
145 
146 void free_report_definition(input_host_t* host, input_report_definition_t* report_def);
147 
148 void input_device_definition_add_report(input_host_t* host,
149         input_device_definition_t* d, input_report_definition_t* r);
150 
151 void input_report_definition_add_collection(input_host_t* host,
152         input_report_definition_t* report, input_collection_id_t id, int32_t arity);
153 
154 void 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 
158 void 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 
163 input_device_handle_t* register_device(input_host_t* host,
164         input_device_identifier_t* id, input_device_definition_t* d);
165 
166 void unregister_device(input_host_t* host, input_device_handle_t* handle);
167 
168 input_report_t* input_allocate_report(input_host_t* host, input_report_definition_t* r);
169 
170 void 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 
173 void 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 
176 void report_event(input_host_t* host, input_device_handle_t* d, input_report_t* report);
177 
178 input_property_map_t* input_get_device_property_map(input_host_t* host,
179         input_device_identifier_t* id);
180 
181 input_property_t* input_get_device_property(input_host_t* host, input_property_map_t* map,
182         const char* key);
183 
184 const char* input_get_property_key(input_host_t* host, input_property_t* property);
185 
186 const char* input_get_property_value(input_host_t* host, input_property_t* property);
187 
188 void input_free_device_property(input_host_t* host, input_property_t* property);
189 
190 void input_free_device_property_map(input_host_t* host, input_property_map_t* map);
191 }
192 
193 } // namespace android
194