2 * Copyright (C) 2011 The Android Open Source Project
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 #define LOG_TAG "InputListener"
19 //#define LOG_NDEBUG 0
21 #include "InputListener.h"
23 #include <cutils/log.h>
27 // --- NotifyConfigurationChangedArgs ---
29 NotifyConfigurationChangedArgs::NotifyConfigurationChangedArgs(nsecs_t eventTime) :
30 eventTime(eventTime) {
33 NotifyConfigurationChangedArgs::NotifyConfigurationChangedArgs(
34 const NotifyConfigurationChangedArgs& other) :
35 eventTime(other.eventTime) {
38 void NotifyConfigurationChangedArgs::notify(const sp<InputListenerInterface>& listener) const {
39 listener->notifyConfigurationChanged(this);
43 // --- NotifyKeyArgs ---
45 NotifyKeyArgs::NotifyKeyArgs(nsecs_t eventTime, int32_t deviceId, uint32_t source,
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) {
54 NotifyKeyArgs::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) {
62 void NotifyKeyArgs::notify(const sp<InputListenerInterface>& listener) const {
63 listener->notifyKey(this);
67 // --- NotifyMotionArgs ---
69 NotifyMotionArgs::NotifyMotionArgs(nsecs_t eventTime, int32_t deviceId, uint32_t source,
71 int32_t action, int32_t actionButton, int32_t flags, int32_t metaState,
72 int32_t buttonState, int32_t edgeFlags, int32_t displayId, uint32_t pointerCount,
73 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), actionButton(actionButton),
77 flags(flags), metaState(metaState), buttonState(buttonState),
78 edgeFlags(edgeFlags), displayId(displayId), pointerCount(pointerCount),
79 xPrecision(xPrecision), yPrecision(yPrecision), downTime(downTime) {
80 for (uint32_t i = 0; i < pointerCount; i++) {
81 this->pointerProperties[i].copyFrom(pointerProperties[i]);
82 this->pointerCoords[i].copyFrom(pointerCoords[i]);
86 NotifyMotionArgs::NotifyMotionArgs(const NotifyMotionArgs& other) :
87 eventTime(other.eventTime), deviceId(other.deviceId), source(other.source),
88 policyFlags(other.policyFlags),
89 action(other.action), actionButton(other.actionButton), flags(other.flags),
90 metaState(other.metaState), buttonState(other.buttonState),
91 edgeFlags(other.edgeFlags), displayId(other.displayId), pointerCount(other.pointerCount),
92 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]);
99 void NotifyMotionArgs::notify(const sp<InputListenerInterface>& listener) const {
100 listener->notifyMotion(this);
104 // --- NotifySwitchArgs ---
106 NotifySwitchArgs::NotifySwitchArgs(nsecs_t eventTime, uint32_t policyFlags,
107 uint32_t switchValues, uint32_t switchMask) :
108 eventTime(eventTime), policyFlags(policyFlags),
109 switchValues(switchValues), switchMask(switchMask) {
112 NotifySwitchArgs::NotifySwitchArgs(const NotifySwitchArgs& other) :
113 eventTime(other.eventTime), policyFlags(other.policyFlags),
114 switchValues(other.switchValues), switchMask(other.switchMask) {
117 void NotifySwitchArgs::notify(const sp<InputListenerInterface>& listener) const {
118 listener->notifySwitch(this);
122 // --- NotifyDeviceResetArgs ---
124 NotifyDeviceResetArgs::NotifyDeviceResetArgs(nsecs_t eventTime, int32_t deviceId) :
125 eventTime(eventTime), deviceId(deviceId) {
128 NotifyDeviceResetArgs::NotifyDeviceResetArgs(const NotifyDeviceResetArgs& other) :
129 eventTime(other.eventTime), deviceId(other.deviceId) {
132 void NotifyDeviceResetArgs::notify(const sp<InputListenerInterface>& listener) const {
133 listener->notifyDeviceReset(this);
137 // --- QueuedInputListener ---
139 QueuedInputListener::QueuedInputListener(const sp<InputListenerInterface>& innerListener) :
140 mInnerListener(innerListener) {
143 QueuedInputListener::~QueuedInputListener() {
144 size_t count = mArgsQueue.size();
145 for (size_t i = 0; i < count; i++) {
146 delete mArgsQueue[i];
150 void QueuedInputListener::notifyConfigurationChanged(
151 const NotifyConfigurationChangedArgs* args) {
152 mArgsQueue.push(new NotifyConfigurationChangedArgs(*args));
155 void QueuedInputListener::notifyKey(const NotifyKeyArgs* args) {
156 mArgsQueue.push(new NotifyKeyArgs(*args));
159 void QueuedInputListener::notifyMotion(const NotifyMotionArgs* args) {
160 mArgsQueue.push(new NotifyMotionArgs(*args));
163 void QueuedInputListener::notifySwitch(const NotifySwitchArgs* args) {
164 mArgsQueue.push(new NotifySwitchArgs(*args));
167 void QueuedInputListener::notifyDeviceReset(const NotifyDeviceResetArgs* args) {
168 mArgsQueue.push(new NotifyDeviceResetArgs(*args));
171 void 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);
182 } // namespace android