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 #include <stdint.h>
18 #include <sys/types.h>
19 
20 #define LOG_TAG "InputDriver"
21 
22 #define LOG_NDEBUG 0
23 
24 #include "InputDriver.h"
25 #include "InputHost.h"
26 
27 #include <hardware/input.h>
28 #include <utils/Log.h>
29 #include <utils/String8.h>
30 
31 #define INDENT2 "    "
32 
33 namespace android {
34 
35 static input_host_callbacks_t kCallbacks = {
36     .create_device_identifier = create_device_identifier,
37     .create_device_definition = create_device_definition,
38     .create_input_report_definition = create_input_report_definition,
39     .create_output_report_definition = create_output_report_definition,
40     .input_device_definition_add_report = input_device_definition_add_report,
41     .input_report_definition_add_collection = input_report_definition_add_collection,
42     .input_report_definition_declare_usage_int = input_report_definition_declare_usage_int,
43     .input_report_definition_declare_usages_bool = input_report_definition_declare_usages_bool,
44     .register_device = register_device,
45     .input_allocate_report = input_allocate_report,
46     .input_report_set_usage_int = input_report_set_usage_int,
47     .input_report_set_usage_bool = input_report_set_usage_bool,
48     .report_event = report_event,
49     .input_get_device_property_map = input_get_device_property_map,
50     .input_get_device_property = input_get_device_property,
51     .input_get_property_key = input_get_property_key,
52     .input_get_property_value = input_get_property_value,
53     .input_free_device_property = input_free_device_property,
54     .input_free_device_property_map = input_free_device_property_map,
55 };
56 
InputDriver(const char * name)57 InputDriver::InputDriver(const char* name) : mName(String8(name)) {
58     const hw_module_t* module;
59     int err = input_open(&module, name);
60     LOG_ALWAYS_FATAL_IF(err != 0, "Input module %s not found", name);
61     mHal = reinterpret_cast<const input_module_t*>(module);
62 }
63 
init(InputHostInterface * host)64 void InputDriver::init(InputHostInterface* host) {
65     mHal->init(mHal, static_cast<input_host_t*>(host), kCallbacks);
66 }
67 
dump(String8 & result)68 void InputDriver::dump(String8& result) {
69     result.appendFormat(INDENT2 "HAL Input Driver (%s)\n", mName.string());
70 }
71 
72 
73 // HAL wrapper functions
74 
create_device_identifier(input_host_t * host,const char * name,int32_t product_id,int32_t vendor_id,input_bus_t bus,const char * unique_id)75 input_device_identifier_t* create_device_identifier(input_host_t* host,
76         const char* name, int32_t product_id, int32_t vendor_id,
77         input_bus_t bus, const char* unique_id) {
78     return nullptr;
79 }
80 
create_device_definition(input_host_t * host)81 input_device_definition_t* create_device_definition(input_host_t* host) {
82     return nullptr;
83 }
84 
create_input_report_definition(input_host_t * host)85 input_report_definition_t* create_input_report_definition(input_host_t* host) {
86     return nullptr;
87 }
88 
create_output_report_definition(input_host_t * host)89 input_report_definition_t* create_output_report_definition(input_host_t* host) {
90     return nullptr;
91 }
92 
input_device_definition_add_report(input_host_t * host,input_device_definition_t * d,input_report_definition_t * r)93 void input_device_definition_add_report(input_host_t* host,
94         input_device_definition_t* d, input_report_definition_t* r) { }
95 
input_report_definition_add_collection(input_host_t * host,input_report_definition_t * report,input_collection_id_t id,int32_t arity)96 void input_report_definition_add_collection(input_host_t* host,
97         input_report_definition_t* report, input_collection_id_t id, int32_t arity) { }
98 
input_report_definition_declare_usage_int(input_host_t * host,input_report_definition_t * report,input_collection_id_t id,input_usage_t usage,int32_t min,int32_t max,float resolution)99 void input_report_definition_declare_usage_int(input_host_t* host,
100         input_report_definition_t* report, input_collection_id_t id,
101         input_usage_t usage, int32_t min, int32_t max, float resolution) { }
102 
input_report_definition_declare_usages_bool(input_host_t * host,input_report_definition_t * report,input_collection_id_t id,input_usage_t * usage,size_t usage_count)103 void input_report_definition_declare_usages_bool(input_host_t* host,
104         input_report_definition_t* report, input_collection_id_t id,
105         input_usage_t* usage, size_t usage_count) { }
106 
107 
register_device(input_host_t * host,input_device_identifier_t * id,input_device_definition_t * d)108 input_device_handle_t* register_device(input_host_t* host,
109         input_device_identifier_t* id, input_device_definition_t* d) {
110     return nullptr;
111 }
112 
input_allocate_report(input_host_t * host,input_report_definition_t * r)113 input_report_t* input_allocate_report(input_host_t* host, input_report_definition_t* r) {
114     return nullptr;
115 }
input_report_set_usage_int(input_host_t * host,input_report_t * r,input_collection_id_t id,input_usage_t usage,int32_t value,int32_t arity_index)116 void input_report_set_usage_int(input_host_t* host, input_report_t* r,
117         input_collection_id_t id, input_usage_t usage, int32_t value, int32_t arity_index) { }
118 
input_report_set_usage_bool(input_host_t * host,input_report_t * r,input_collection_id_t id,input_usage_t usage,bool value,int32_t arity_index)119 void input_report_set_usage_bool(input_host_t* host, input_report_t* r,
120         input_collection_id_t id, input_usage_t usage, bool value, int32_t arity_index) { }
121 
report_event(input_host_t * host,input_device_handle_t * d,input_report_t * report)122 void report_event(input_host_t* host, input_device_handle_t* d, input_report_t* report) { }
123 
input_get_device_property_map(input_host_t * host,input_device_identifier_t * id)124 input_property_map_t* input_get_device_property_map(input_host_t* host,
125         input_device_identifier_t* id) {
126     return nullptr;
127 }
128 
input_get_device_property(input_host_t * host,input_property_map_t * map,const char * key)129 input_property_t* input_get_device_property(input_host_t* host, input_property_map_t* map,
130         const char* key) {
131     return nullptr;
132 }
133 
input_get_property_key(input_host_t * host,input_property_t * property)134 const char* input_get_property_key(input_host_t* host, input_property_t* property) {
135     return nullptr;
136 }
137 
input_get_property_value(input_host_t * host,input_property_t * property)138 const char* input_get_property_value(input_host_t* host, input_property_t* property) {
139     return nullptr;
140 }
141 
input_free_device_property(input_host_t * host,input_property_t * property)142 void input_free_device_property(input_host_t* host, input_property_t* property) { }
143 
input_free_device_property_map(input_host_t * host,input_property_map_t * map)144 void input_free_device_property_map(input_host_t* host, input_property_map_t* map) { }
145 
146 } // namespace android
147