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