blob: 74a5f8a3bd62b8332c234f162aec4d3fd55351a5 [file] [log] [blame]
Tim Kilbourn73475a42015-02-13 10:35:20 -08001/*
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::reportEvent(InputDeviceHandle d) {
22 mCallbacks.report_event(mHost, d, mReport);
23}
24
25void InputReportDefinition::addCollection(InputCollectionId id, int32_t arity) {
26 mCallbacks.input_report_definition_add_collection(mHost, mReportDefinition, id, arity);
27}
28
29void 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
35void 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
41InputReport InputReportDefinition::allocateReport() {
42 return InputReport(mHost, mCallbacks,
43 mCallbacks.input_allocate_report(mHost, mReportDefinition));
44}
45
46void InputDeviceDefinition::addReport(InputReportDefinition r) {
47 mCallbacks.input_device_definition_add_report(mHost, mDeviceDefinition, r);
48}
49
Tim Kilbourn6fa82482015-04-06 13:49:40 -070050InputProperty::~InputProperty() {
51 mCallbacks.input_free_device_property(mHost, mProperty);
52}
53
Tim Kilbourn3186e7b2015-04-16 15:32:08 -070054InputProperty::InputProperty(InputProperty&& rhs) :
55 InputHostBase(rhs), mProperty(std::move(rhs.mProperty)) {
56 rhs.mProperty = nullptr;
57}
58
59const char* InputProperty::getKey() const {
Tim Kilbourn6fa82482015-04-06 13:49:40 -070060 return mCallbacks.input_get_property_key(mHost, mProperty);
61}
62
Tim Kilbourn3186e7b2015-04-16 15:32:08 -070063const char* InputProperty::getValue() const {
Tim Kilbourn6fa82482015-04-06 13:49:40 -070064 return mCallbacks.input_get_property_value(mHost, mProperty);
65}
66
67InputPropertyMap::~InputPropertyMap() {
68 mCallbacks.input_free_device_property_map(mHost, mMap);
69}
70
Tim Kilbourn3186e7b2015-04-16 15:32:08 -070071InputPropertyMap::InputPropertyMap(InputPropertyMap&& rhs) :
72 InputHostBase(rhs), mMap(std::move(rhs.mMap)) {
73 rhs.mMap = nullptr;
74}
75
76InputProperty InputPropertyMap::getDeviceProperty(const char* key) const {
Tim Kilbourn6fa82482015-04-06 13:49:40 -070077 return InputProperty(mHost, mCallbacks,
78 mCallbacks.input_get_device_property(mHost, mMap, key));
79}
80
Tim Kilbourn73475a42015-02-13 10:35:20 -080081InputDeviceIdentifier 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
86InputDeviceDefinition InputHost::createDeviceDefinition() {
87 return InputDeviceDefinition(mHost, mCallbacks, mCallbacks.create_device_definition(mHost));
88}
89
90InputReportDefinition InputHost::createInputReportDefinition() {
91 return InputReportDefinition(mHost, mCallbacks,
92 mCallbacks.create_input_report_definition(mHost));
93}
94
95InputReportDefinition InputHost::createOutputReportDefinition() {
96 return InputReportDefinition(mHost, mCallbacks,
97 mCallbacks.create_output_report_definition(mHost));
98}
99
100InputDeviceHandle InputHost::registerDevice(InputDeviceIdentifier id,
101 InputDeviceDefinition d) {
102 return mCallbacks.register_device(mHost, id, d);
103}
104
105void InputHost::unregisterDevice(InputDeviceHandle handle) {
106 return mCallbacks.unregister_device(mHost, handle);
107}
108
Tim Kilbourn6fa82482015-04-06 13:49:40 -0700109InputPropertyMap InputHost::getDevicePropertyMap(InputDeviceIdentifier id) {
110 return InputPropertyMap(mHost, mCallbacks,
111 mCallbacks.input_get_device_property_map(mHost, id));
112}
113
Tim Kilbourn73475a42015-02-13 10:35:20 -0800114} // namespace android