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
19namespace android {
20
21void 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
26void 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
31void InputReport::reportEvent(InputDeviceHandle* d) {
32    mCallbacks.report_event(mHost, d, mReport);
33}
34
35void InputReportDefinition::addCollection(InputCollectionId id, int32_t arity) {
36    mCallbacks.input_report_definition_add_collection(mHost, mReportDefinition, id, arity);
37}
38
39void 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
45void InputReportDefinition::declareUsages(InputCollectionId id, InputUsage* usage,
46        size_t usageCount) {
47    mCallbacks.input_report_definition_declare_usages_bool(mHost, mReportDefinition,
48            id, usage, usageCount);
49}
50
51InputReport* InputReportDefinition::allocateReport() {
52    return new InputReport(mHost, mCallbacks,
53            mCallbacks.input_allocate_report(mHost, mReportDefinition));
54}
55
56void InputDeviceDefinition::addReport(InputReportDefinition* r) {
57    mCallbacks.input_device_definition_add_report(mHost, mDeviceDefinition, *r);
58}
59
60const char* InputProperty::getKey() const {
61    return mCallbacks.input_get_property_key(mHost, mProperty);
62}
63
64const char* InputProperty::getValue() const {
65    return mCallbacks.input_get_property_value(mHost, mProperty);
66}
67
68InputProperty* InputPropertyMap::getDeviceProperty(const char* key) const {
69    return new InputProperty(mHost, mCallbacks,
70            mCallbacks.input_get_device_property(mHost, mMap, key));
71}
72
73void InputPropertyMap::freeDeviceProperty(InputProperty* property) const {
74    mCallbacks.input_free_device_property(mHost, *property);
75}
76
77InputDeviceIdentifier* InputHost::createDeviceIdentifier(const char* name, int32_t productId,
78        int32_t vendorId, InputBus bus, const char* uniqueId) {
79    return mCallbacks.create_device_identifier(
80                mHost, name, productId, vendorId, bus, uniqueId);
81}
82
83InputDeviceDefinition* InputHost::createDeviceDefinition() {
84    return new InputDeviceDefinition(mHost, mCallbacks, mCallbacks.create_device_definition(mHost));
85}
86
87InputReportDefinition* InputHost::createInputReportDefinition() {
88    return new InputReportDefinition(mHost, mCallbacks,
89            mCallbacks.create_input_report_definition(mHost));
90}
91
92InputReportDefinition* InputHost::createOutputReportDefinition() {
93    return new InputReportDefinition(mHost, mCallbacks,
94            mCallbacks.create_output_report_definition(mHost));
95}
96
97void InputHost::freeReportDefinition(InputReportDefinition* reportDef) {
98    mCallbacks.free_report_definition(mHost, *reportDef);
99}
100
101InputDeviceHandle* InputHost::registerDevice(InputDeviceIdentifier* id,
102        InputDeviceDefinition* d) {
103    return mCallbacks.register_device(mHost, id, *d);
104}
105
106void InputHost::unregisterDevice(InputDeviceHandle* handle) {
107    mCallbacks.unregister_device(mHost, handle);
108}
109
110InputPropertyMap* InputHost::getDevicePropertyMap(InputDeviceIdentifier* id) {
111    return new InputPropertyMap(mHost, mCallbacks,
112            mCallbacks.input_get_device_property_map(mHost, id));
113}
114
115void InputHost::freeDevicePropertyMap(InputPropertyMap* propertyMap) {
116    mCallbacks.input_free_device_property_map(mHost, *propertyMap);
117}
118
119}  // namespace android
120