blob: 85bb0ed5242eedcd73a45dd959dcbfdbab05ad30 [file] [log] [blame]
Jeff Brownbe1aa822011-07-27 16:04:54 -07001/*
2 * Copyright (C) 2011 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#define LOG_TAG "InputListener"
18
19//#define LOG_NDEBUG 0
20
21#include "InputListener.h"
22
23#include <cutils/log.h>
24
25namespace android {
26
27// --- NotifyConfigurationChangedArgs ---
28
29NotifyConfigurationChangedArgs::NotifyConfigurationChangedArgs(nsecs_t eventTime) :
30 eventTime(eventTime) {
31}
32
33NotifyConfigurationChangedArgs::NotifyConfigurationChangedArgs(
34 const NotifyConfigurationChangedArgs& other) :
35 eventTime(other.eventTime) {
36}
37
38void NotifyConfigurationChangedArgs::notify(const sp<InputListenerInterface>& listener) const {
39 listener->notifyConfigurationChanged(this);
40}
41
42
43// --- NotifyKeyArgs ---
44
45NotifyKeyArgs::NotifyKeyArgs(nsecs_t eventTime, int32_t deviceId, uint32_t source,
46 uint32_t policyFlags,
47 int32_t action, int32_t flags, int32_t keyCode, int32_t scanCode,
48 int32_t metaState, nsecs_t downTime) :
49 eventTime(eventTime), deviceId(deviceId), source(source), policyFlags(policyFlags),
50 action(action), flags(flags), keyCode(keyCode), scanCode(scanCode),
51 metaState(metaState), downTime(downTime) {
52}
53
54NotifyKeyArgs::NotifyKeyArgs(const NotifyKeyArgs& other) :
55 eventTime(other.eventTime), deviceId(other.deviceId), source(other.source),
56 policyFlags(other.policyFlags),
57 action(other.action), flags(other.flags),
58 keyCode(other.keyCode), scanCode(other.scanCode),
59 metaState(other.metaState), downTime(other.downTime) {
60}
61
62void NotifyKeyArgs::notify(const sp<InputListenerInterface>& listener) const {
63 listener->notifyKey(this);
64}
65
66
67// --- NotifyMotionArgs ---
68
69NotifyMotionArgs::NotifyMotionArgs(nsecs_t eventTime, int32_t deviceId, uint32_t source,
70 uint32_t policyFlags,
71 int32_t action, int32_t flags, int32_t metaState, int32_t buttonState,
Jeff Brown83d616a2012-09-09 20:33:43 -070072 int32_t edgeFlags, int32_t displayId, uint32_t pointerCount,
Jeff Brownbe1aa822011-07-27 16:04:54 -070073 const PointerProperties* pointerProperties, const PointerCoords* pointerCoords,
74 float xPrecision, float yPrecision, nsecs_t downTime) :
75 eventTime(eventTime), deviceId(deviceId), source(source), policyFlags(policyFlags),
76 action(action), flags(flags), metaState(metaState), buttonState(buttonState),
Jeff Brown83d616a2012-09-09 20:33:43 -070077 edgeFlags(edgeFlags), displayId(displayId), pointerCount(pointerCount),
Jeff Brownbe1aa822011-07-27 16:04:54 -070078 xPrecision(xPrecision), yPrecision(yPrecision), downTime(downTime) {
79 for (uint32_t i = 0; i < pointerCount; i++) {
80 this->pointerProperties[i].copyFrom(pointerProperties[i]);
81 this->pointerCoords[i].copyFrom(pointerCoords[i]);
82 }
83}
84
85NotifyMotionArgs::NotifyMotionArgs(const NotifyMotionArgs& other) :
86 eventTime(other.eventTime), deviceId(other.deviceId), source(other.source),
87 policyFlags(other.policyFlags),
88 action(other.action), flags(other.flags),
89 metaState(other.metaState), buttonState(other.buttonState),
Jeff Brown83d616a2012-09-09 20:33:43 -070090 edgeFlags(other.edgeFlags), displayId(other.displayId),
91 pointerCount(other.pointerCount),
Jeff Brownbe1aa822011-07-27 16:04:54 -070092 xPrecision(other.xPrecision), yPrecision(other.yPrecision), downTime(other.downTime) {
93 for (uint32_t i = 0; i < pointerCount; i++) {
94 pointerProperties[i].copyFrom(other.pointerProperties[i]);
95 pointerCoords[i].copyFrom(other.pointerCoords[i]);
96 }
97}
98
99void NotifyMotionArgs::notify(const sp<InputListenerInterface>& listener) const {
100 listener->notifyMotion(this);
101}
102
103
104// --- NotifySwitchArgs ---
105
106NotifySwitchArgs::NotifySwitchArgs(nsecs_t eventTime, uint32_t policyFlags,
Jeff Brownbcc046a2012-09-27 20:46:43 -0700107 uint32_t switchValues, uint32_t switchMask) :
Jeff Brownbe1aa822011-07-27 16:04:54 -0700108 eventTime(eventTime), policyFlags(policyFlags),
Jeff Brownbcc046a2012-09-27 20:46:43 -0700109 switchValues(switchValues), switchMask(switchMask) {
Jeff Brownbe1aa822011-07-27 16:04:54 -0700110}
111
112NotifySwitchArgs::NotifySwitchArgs(const NotifySwitchArgs& other) :
113 eventTime(other.eventTime), policyFlags(other.policyFlags),
Jeff Brownbcc046a2012-09-27 20:46:43 -0700114 switchValues(other.switchValues), switchMask(other.switchMask) {
Jeff Brownbe1aa822011-07-27 16:04:54 -0700115}
116
117void NotifySwitchArgs::notify(const sp<InputListenerInterface>& listener) const {
118 listener->notifySwitch(this);
119}
120
121
Jeff Brown65fd2512011-08-18 11:20:58 -0700122// --- NotifyDeviceResetArgs ---
123
124NotifyDeviceResetArgs::NotifyDeviceResetArgs(nsecs_t eventTime, int32_t deviceId) :
125 eventTime(eventTime), deviceId(deviceId) {
126}
127
128NotifyDeviceResetArgs::NotifyDeviceResetArgs(const NotifyDeviceResetArgs& other) :
129 eventTime(other.eventTime), deviceId(other.deviceId) {
130}
131
132void NotifyDeviceResetArgs::notify(const sp<InputListenerInterface>& listener) const {
133 listener->notifyDeviceReset(this);
134}
135
136
Jeff Brownbe1aa822011-07-27 16:04:54 -0700137// --- QueuedInputListener ---
138
139QueuedInputListener::QueuedInputListener(const sp<InputListenerInterface>& innerListener) :
140 mInnerListener(innerListener) {
141}
142
143QueuedInputListener::~QueuedInputListener() {
144 size_t count = mArgsQueue.size();
145 for (size_t i = 0; i < count; i++) {
146 delete mArgsQueue[i];
147 }
148}
149
150void QueuedInputListener::notifyConfigurationChanged(
151 const NotifyConfigurationChangedArgs* args) {
152 mArgsQueue.push(new NotifyConfigurationChangedArgs(*args));
153}
154
155void QueuedInputListener::notifyKey(const NotifyKeyArgs* args) {
156 mArgsQueue.push(new NotifyKeyArgs(*args));
157}
158
159void QueuedInputListener::notifyMotion(const NotifyMotionArgs* args) {
160 mArgsQueue.push(new NotifyMotionArgs(*args));
161}
162
163void QueuedInputListener::notifySwitch(const NotifySwitchArgs* args) {
164 mArgsQueue.push(new NotifySwitchArgs(*args));
165}
166
Jeff Brown65fd2512011-08-18 11:20:58 -0700167void QueuedInputListener::notifyDeviceReset(const NotifyDeviceResetArgs* args) {
168 mArgsQueue.push(new NotifyDeviceResetArgs(*args));
169}
170
Jeff Brownbe1aa822011-07-27 16:04:54 -0700171void QueuedInputListener::flush() {
172 size_t count = mArgsQueue.size();
173 for (size_t i = 0; i < count; i++) {
174 NotifyArgs* args = mArgsQueue[i];
175 args->notify(mInnerListener);
176 delete args;
177 }
178 mArgsQueue.clear();
179}
180
181
182} // namespace android