blob: 129443e884b9c39fc87d41bbb960b9a8cc879005 [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#ifndef ANDROID_INPUT_HOST_H_
18#define ANDROID_INPUT_HOST_H_
19
20#include <hardware/input.h>
21
22namespace android {
23
24/**
25 * Classes in this file wrap the corresponding interfaces in the Input HAL. They
26 * are intended to be lightweight and passed by value. It is still important not
27 * to use an object after a HAL-specific method has freed the underlying
28 * representation.
29 *
30 * See hardware/input.h for details about each of these methods.
31 */
32
33using InputBus = input_bus_t;
34using InputCollectionId = input_collection_id_t;
35using InputDeviceHandle = input_device_handle_t*;
36using InputDeviceIdentifier = input_device_identifier_t*;
37using InputUsage = input_usage_t;
38
39class InputHostBase {
40protected:
41 InputHostBase(input_host_t* host, input_host_callbacks_t cb) : mHost(host), mCallbacks(cb) {}
42 virtual ~InputHostBase() = default;
43
44 input_host_t* mHost;
45 input_host_callbacks_t mCallbacks;
46};
47
48class InputReport : private InputHostBase {
49public:
50 virtual ~InputReport() = default;
51
52 InputReport(const InputReport& rhs) = default;
53 InputReport& operator=(const InputReport& rhs) = default;
54 operator input_report_t*() const { return mReport; }
55
56 void reportEvent(InputDeviceHandle d);
57
58private:
59 friend class InputReportDefinition;
60
61 InputReport(input_host_t* host, input_host_callbacks_t cb, input_report_t* r) :
62 InputHostBase(host, cb), mReport(r) {}
63
64 input_report_t* mReport;
65};
66
67class InputReportDefinition : private InputHostBase {
68public:
69 virtual ~InputReportDefinition() = default;
70
71 InputReportDefinition(const InputReportDefinition& rhs) = default;
72 InputReportDefinition& operator=(const InputReportDefinition& rhs) = default;
73 operator input_report_definition_t*() { return mReportDefinition; }
74
75 void addCollection(InputCollectionId id, int32_t arity);
76 void declareUsage(InputCollectionId id, InputUsage usage, int32_t min, int32_t max,
77 float resolution);
78 void declareUsage(InputCollectionId id, InputUsage* usage, size_t usageCount);
79
80 InputReport allocateReport();
81
82private:
83 friend class InputHost;
84
85 InputReportDefinition(
86 input_host_t* host, input_host_callbacks_t cb, input_report_definition_t* r) :
87 InputHostBase(host, cb), mReportDefinition(r) {}
88
89 input_report_definition_t* mReportDefinition;
90};
91
92class InputDeviceDefinition : private InputHostBase {
93public:
94 virtual ~InputDeviceDefinition() = default;
95
96 InputDeviceDefinition(const InputDeviceDefinition& rhs) = default;
97 InputDeviceDefinition& operator=(const InputDeviceDefinition& rhs) = default;
98 operator input_device_definition_t*() { return mDeviceDefinition; }
99
100 void addReport(InputReportDefinition r);
101
102private:
103 friend class InputHost;
104
105 InputDeviceDefinition(
106 input_host_t* host, input_host_callbacks_t cb, input_device_definition_t* d) :
107 InputHostBase(host, cb), mDeviceDefinition(d) {}
108
109 input_device_definition_t* mDeviceDefinition;
110};
111
112class InputHost : private InputHostBase {
113public:
114 InputHost(input_host_t* host, input_host_callbacks_t cb) : InputHostBase(host, cb) {}
115 virtual ~InputHost() = default;
116
117 InputHost(const InputHost& rhs) = default;
118 InputHost& operator=(const InputHost& rhs) = default;
119
120 InputDeviceIdentifier createDeviceIdentifier(const char* name, int32_t productId,
121 int32_t vendorId, InputBus bus, const char* uniqueId);
122
123 InputDeviceDefinition createDeviceDefinition();
124 InputReportDefinition createInputReportDefinition();
125 InputReportDefinition createOutputReportDefinition();
126
127 InputDeviceHandle registerDevice(InputDeviceIdentifier id, InputDeviceDefinition d);
128 void unregisterDevice(InputDeviceHandle handle);
129};
130
131} // namespace android
132
133#endif // ANDROID_INPUT_HOST_H_