Tim Kilbourn | 73475a4 | 2015-02-13 10:35:20 -0800 | [diff] [blame] | 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 "InputHost.h" |
| 18 | |
| 19 | namespace android { |
| 20 | |
Tim Kilbourn | 4f3145d | 2015-05-04 17:26:30 -0700 | [diff] [blame] | 21 | void InputReport::setIntUsage(InputCollectionId id, InputUsage usage, int32_t value, |
| 22 | int32_t arityIndex) { |
| 23 | mCallbacks.input_report_set_usage_int(mHost, mReport, id, usage, value, arityIndex); |
| 24 | } |
| 25 | |
| 26 | void InputReport::setBoolUsage(InputCollectionId id, InputUsage usage, bool value, |
| 27 | int32_t arityIndex) { |
| 28 | mCallbacks.input_report_set_usage_bool(mHost, mReport, id, usage, value, arityIndex); |
| 29 | } |
| 30 | |
| 31 | void InputReport::reportEvent(InputDeviceHandle* d) { |
Tim Kilbourn | 73475a4 | 2015-02-13 10:35:20 -0800 | [diff] [blame] | 32 | mCallbacks.report_event(mHost, d, mReport); |
| 33 | } |
| 34 | |
| 35 | void InputReportDefinition::addCollection(InputCollectionId id, int32_t arity) { |
| 36 | mCallbacks.input_report_definition_add_collection(mHost, mReportDefinition, id, arity); |
| 37 | } |
| 38 | |
| 39 | void InputReportDefinition::declareUsage(InputCollectionId id, InputUsage usage, |
| 40 | int32_t min, int32_t max, float resolution) { |
| 41 | mCallbacks.input_report_definition_declare_usage_int(mHost, mReportDefinition, |
| 42 | id, usage, min, max, resolution); |
| 43 | } |
| 44 | |
Tim Kilbourn | 4f3145d | 2015-05-04 17:26:30 -0700 | [diff] [blame] | 45 | void InputReportDefinition::declareUsages(InputCollectionId id, InputUsage* usage, |
Tim Kilbourn | 73475a4 | 2015-02-13 10:35:20 -0800 | [diff] [blame] | 46 | size_t usageCount) { |
| 47 | mCallbacks.input_report_definition_declare_usages_bool(mHost, mReportDefinition, |
| 48 | id, usage, usageCount); |
| 49 | } |
| 50 | |
Tim Kilbourn | 4f3145d | 2015-05-04 17:26:30 -0700 | [diff] [blame] | 51 | InputReport* InputReportDefinition::allocateReport() { |
| 52 | return new InputReport(mHost, mCallbacks, |
Tim Kilbourn | 73475a4 | 2015-02-13 10:35:20 -0800 | [diff] [blame] | 53 | mCallbacks.input_allocate_report(mHost, mReportDefinition)); |
| 54 | } |
| 55 | |
Tim Kilbourn | 4f3145d | 2015-05-04 17:26:30 -0700 | [diff] [blame] | 56 | void InputDeviceDefinition::addReport(InputReportDefinition* r) { |
| 57 | mCallbacks.input_device_definition_add_report(mHost, mDeviceDefinition, *r); |
Tim Kilbourn | 3186e7b | 2015-04-16 15:32:08 -0700 | [diff] [blame] | 58 | } |
| 59 | |
| 60 | const char* InputProperty::getKey() const { |
Tim Kilbourn | 6fa8248 | 2015-04-06 13:49:40 -0700 | [diff] [blame] | 61 | return mCallbacks.input_get_property_key(mHost, mProperty); |
| 62 | } |
| 63 | |
Tim Kilbourn | 3186e7b | 2015-04-16 15:32:08 -0700 | [diff] [blame] | 64 | const char* InputProperty::getValue() const { |
Tim Kilbourn | 6fa8248 | 2015-04-06 13:49:40 -0700 | [diff] [blame] | 65 | return mCallbacks.input_get_property_value(mHost, mProperty); |
| 66 | } |
| 67 | |
Tim Kilbourn | 4f3145d | 2015-05-04 17:26:30 -0700 | [diff] [blame] | 68 | InputProperty* InputPropertyMap::getDeviceProperty(const char* key) const { |
| 69 | return new InputProperty(mHost, mCallbacks, |
Tim Kilbourn | 6fa8248 | 2015-04-06 13:49:40 -0700 | [diff] [blame] | 70 | mCallbacks.input_get_device_property(mHost, mMap, key)); |
| 71 | } |
| 72 | |
Tim Kilbourn | 4f3145d | 2015-05-04 17:26:30 -0700 | [diff] [blame] | 73 | void InputPropertyMap::freeDeviceProperty(InputProperty* property) const { |
| 74 | mCallbacks.input_free_device_property(mHost, *property); |
| 75 | } |
| 76 | |
| 77 | InputDeviceIdentifier* InputHost::createDeviceIdentifier(const char* name, int32_t productId, |
Tim Kilbourn | 73475a4 | 2015-02-13 10:35:20 -0800 | [diff] [blame] | 78 | int32_t vendorId, InputBus bus, const char* uniqueId) { |
Tim Kilbourn | 4f3145d | 2015-05-04 17:26:30 -0700 | [diff] [blame] | 79 | return mCallbacks.create_device_identifier( |
| 80 | mHost, name, productId, vendorId, bus, uniqueId); |
Tim Kilbourn | 73475a4 | 2015-02-13 10:35:20 -0800 | [diff] [blame] | 81 | } |
| 82 | |
Tim Kilbourn | 4f3145d | 2015-05-04 17:26:30 -0700 | [diff] [blame] | 83 | InputDeviceDefinition* InputHost::createDeviceDefinition() { |
| 84 | return new InputDeviceDefinition(mHost, mCallbacks, mCallbacks.create_device_definition(mHost)); |
Tim Kilbourn | 73475a4 | 2015-02-13 10:35:20 -0800 | [diff] [blame] | 85 | } |
| 86 | |
Tim Kilbourn | 4f3145d | 2015-05-04 17:26:30 -0700 | [diff] [blame] | 87 | InputReportDefinition* InputHost::createInputReportDefinition() { |
| 88 | return new InputReportDefinition(mHost, mCallbacks, |
Tim Kilbourn | 73475a4 | 2015-02-13 10:35:20 -0800 | [diff] [blame] | 89 | mCallbacks.create_input_report_definition(mHost)); |
| 90 | } |
| 91 | |
Tim Kilbourn | 4f3145d | 2015-05-04 17:26:30 -0700 | [diff] [blame] | 92 | InputReportDefinition* InputHost::createOutputReportDefinition() { |
| 93 | return new InputReportDefinition(mHost, mCallbacks, |
Tim Kilbourn | 73475a4 | 2015-02-13 10:35:20 -0800 | [diff] [blame] | 94 | mCallbacks.create_output_report_definition(mHost)); |
| 95 | } |
| 96 | |
Tim Kilbourn | 4f3145d | 2015-05-04 17:26:30 -0700 | [diff] [blame] | 97 | void InputHost::freeReportDefinition(InputReportDefinition* reportDef) { |
| 98 | mCallbacks.free_report_definition(mHost, *reportDef); |
Tim Kilbourn | 73475a4 | 2015-02-13 10:35:20 -0800 | [diff] [blame] | 99 | } |
| 100 | |
Tim Kilbourn | 4f3145d | 2015-05-04 17:26:30 -0700 | [diff] [blame] | 101 | InputDeviceHandle* InputHost::registerDevice(InputDeviceIdentifier* id, |
| 102 | InputDeviceDefinition* d) { |
| 103 | return mCallbacks.register_device(mHost, id, *d); |
Tim Kilbourn | 73475a4 | 2015-02-13 10:35:20 -0800 | [diff] [blame] | 104 | } |
| 105 | |
Tim Kilbourn | 4f3145d | 2015-05-04 17:26:30 -0700 | [diff] [blame] | 106 | void InputHost::unregisterDevice(InputDeviceHandle* handle) { |
| 107 | mCallbacks.unregister_device(mHost, handle); |
| 108 | } |
| 109 | |
| 110 | InputPropertyMap* InputHost::getDevicePropertyMap(InputDeviceIdentifier* id) { |
| 111 | return new InputPropertyMap(mHost, mCallbacks, |
Tim Kilbourn | 6fa8248 | 2015-04-06 13:49:40 -0700 | [diff] [blame] | 112 | mCallbacks.input_get_device_property_map(mHost, id)); |
| 113 | } |
| 114 | |
Tim Kilbourn | 4f3145d | 2015-05-04 17:26:30 -0700 | [diff] [blame] | 115 | void InputHost::freeDevicePropertyMap(InputPropertyMap* propertyMap) { |
| 116 | mCallbacks.input_free_device_property_map(mHost, *propertyMap); |
| 117 | } |
| 118 | |
Tim Kilbourn | 73475a4 | 2015-02-13 10:35:20 -0800 | [diff] [blame] | 119 | } // namespace android |