michael@0: /* michael@0: * Copyright (C) 2011 The Android Open Source Project michael@0: * michael@0: * Licensed under the Apache License, Version 2.0 (the "License"); michael@0: * you may not use this file except in compliance with the License. michael@0: * You may obtain a copy of the License at michael@0: * michael@0: * http://www.apache.org/licenses/LICENSE-2.0 michael@0: * michael@0: * Unless required by applicable law or agreed to in writing, software michael@0: * distributed under the License is distributed on an "AS IS" BASIS, michael@0: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. michael@0: * See the License for the specific language governing permissions and michael@0: * limitations under the License. michael@0: */ michael@0: michael@0: #define LOG_TAG "InputListener" michael@0: michael@0: //#define LOG_NDEBUG 0 michael@0: michael@0: #include "InputListener.h" michael@0: michael@0: #include "cutils_log.h" michael@0: michael@0: namespace android { michael@0: michael@0: // --- NotifyConfigurationChangedArgs --- michael@0: michael@0: NotifyConfigurationChangedArgs::NotifyConfigurationChangedArgs(nsecs_t eventTime) : michael@0: eventTime(eventTime) { michael@0: } michael@0: michael@0: NotifyConfigurationChangedArgs::NotifyConfigurationChangedArgs( michael@0: const NotifyConfigurationChangedArgs& other) : michael@0: eventTime(other.eventTime) { michael@0: } michael@0: michael@0: void NotifyConfigurationChangedArgs::notify(const sp& listener) const { michael@0: listener->notifyConfigurationChanged(this); michael@0: } michael@0: michael@0: michael@0: // --- NotifyKeyArgs --- michael@0: michael@0: NotifyKeyArgs::NotifyKeyArgs(nsecs_t eventTime, int32_t deviceId, uint32_t source, michael@0: uint32_t policyFlags, michael@0: int32_t action, int32_t flags, int32_t keyCode, int32_t scanCode, michael@0: int32_t metaState, nsecs_t downTime) : michael@0: eventTime(eventTime), deviceId(deviceId), source(source), policyFlags(policyFlags), michael@0: action(action), flags(flags), keyCode(keyCode), scanCode(scanCode), michael@0: metaState(metaState), downTime(downTime) { michael@0: } michael@0: michael@0: NotifyKeyArgs::NotifyKeyArgs(const NotifyKeyArgs& other) : michael@0: eventTime(other.eventTime), deviceId(other.deviceId), source(other.source), michael@0: policyFlags(other.policyFlags), michael@0: action(other.action), flags(other.flags), michael@0: keyCode(other.keyCode), scanCode(other.scanCode), michael@0: metaState(other.metaState), downTime(other.downTime) { michael@0: } michael@0: michael@0: void NotifyKeyArgs::notify(const sp& listener) const { michael@0: listener->notifyKey(this); michael@0: } michael@0: michael@0: michael@0: // --- NotifyMotionArgs --- michael@0: michael@0: NotifyMotionArgs::NotifyMotionArgs(nsecs_t eventTime, int32_t deviceId, uint32_t source, michael@0: uint32_t policyFlags, michael@0: int32_t action, int32_t flags, int32_t metaState, int32_t buttonState, michael@0: int32_t edgeFlags, int32_t displayId, uint32_t pointerCount, michael@0: const PointerProperties* pointerProperties, const PointerCoords* pointerCoords, michael@0: float xPrecision, float yPrecision, nsecs_t downTime) : michael@0: eventTime(eventTime), deviceId(deviceId), source(source), policyFlags(policyFlags), michael@0: action(action), flags(flags), metaState(metaState), buttonState(buttonState), michael@0: edgeFlags(edgeFlags), displayId(displayId), pointerCount(pointerCount), michael@0: xPrecision(xPrecision), yPrecision(yPrecision), downTime(downTime) { michael@0: for (uint32_t i = 0; i < pointerCount; i++) { michael@0: this->pointerProperties[i].copyFrom(pointerProperties[i]); michael@0: this->pointerCoords[i].copyFrom(pointerCoords[i]); michael@0: } michael@0: } michael@0: michael@0: NotifyMotionArgs::NotifyMotionArgs(const NotifyMotionArgs& other) : michael@0: eventTime(other.eventTime), deviceId(other.deviceId), source(other.source), michael@0: policyFlags(other.policyFlags), michael@0: action(other.action), flags(other.flags), michael@0: metaState(other.metaState), buttonState(other.buttonState), michael@0: edgeFlags(other.edgeFlags), displayId(other.displayId), michael@0: pointerCount(other.pointerCount), michael@0: xPrecision(other.xPrecision), yPrecision(other.yPrecision), downTime(other.downTime) { michael@0: for (uint32_t i = 0; i < pointerCount; i++) { michael@0: pointerProperties[i].copyFrom(other.pointerProperties[i]); michael@0: pointerCoords[i].copyFrom(other.pointerCoords[i]); michael@0: } michael@0: } michael@0: michael@0: void NotifyMotionArgs::notify(const sp& listener) const { michael@0: listener->notifyMotion(this); michael@0: } michael@0: michael@0: michael@0: // --- NotifySwitchArgs --- michael@0: michael@0: NotifySwitchArgs::NotifySwitchArgs(nsecs_t eventTime, uint32_t policyFlags, michael@0: uint32_t switchValues, uint32_t switchMask) : michael@0: eventTime(eventTime), policyFlags(policyFlags), michael@0: switchValues(switchValues), switchMask(switchMask) { michael@0: } michael@0: michael@0: NotifySwitchArgs::NotifySwitchArgs(const NotifySwitchArgs& other) : michael@0: eventTime(other.eventTime), policyFlags(other.policyFlags), michael@0: switchValues(other.switchValues), switchMask(other.switchMask) { michael@0: } michael@0: michael@0: void NotifySwitchArgs::notify(const sp& listener) const { michael@0: listener->notifySwitch(this); michael@0: } michael@0: michael@0: michael@0: // --- NotifyDeviceResetArgs --- michael@0: michael@0: NotifyDeviceResetArgs::NotifyDeviceResetArgs(nsecs_t eventTime, int32_t deviceId) : michael@0: eventTime(eventTime), deviceId(deviceId) { michael@0: } michael@0: michael@0: NotifyDeviceResetArgs::NotifyDeviceResetArgs(const NotifyDeviceResetArgs& other) : michael@0: eventTime(other.eventTime), deviceId(other.deviceId) { michael@0: } michael@0: michael@0: void NotifyDeviceResetArgs::notify(const sp& listener) const { michael@0: listener->notifyDeviceReset(this); michael@0: } michael@0: michael@0: michael@0: // --- QueuedInputListener --- michael@0: michael@0: QueuedInputListener::QueuedInputListener(const sp& innerListener) : michael@0: mInnerListener(innerListener) { michael@0: } michael@0: michael@0: QueuedInputListener::~QueuedInputListener() { michael@0: size_t count = mArgsQueue.size(); michael@0: for (size_t i = 0; i < count; i++) { michael@0: delete mArgsQueue[i]; michael@0: } michael@0: } michael@0: michael@0: void QueuedInputListener::notifyConfigurationChanged( michael@0: const NotifyConfigurationChangedArgs* args) { michael@0: mArgsQueue.push(new NotifyConfigurationChangedArgs(*args)); michael@0: } michael@0: michael@0: void QueuedInputListener::notifyKey(const NotifyKeyArgs* args) { michael@0: mArgsQueue.push(new NotifyKeyArgs(*args)); michael@0: } michael@0: michael@0: void QueuedInputListener::notifyMotion(const NotifyMotionArgs* args) { michael@0: mArgsQueue.push(new NotifyMotionArgs(*args)); michael@0: } michael@0: michael@0: void QueuedInputListener::notifySwitch(const NotifySwitchArgs* args) { michael@0: mArgsQueue.push(new NotifySwitchArgs(*args)); michael@0: } michael@0: michael@0: void QueuedInputListener::notifyDeviceReset(const NotifyDeviceResetArgs* args) { michael@0: mArgsQueue.push(new NotifyDeviceResetArgs(*args)); michael@0: } michael@0: michael@0: void QueuedInputListener::flush() { michael@0: size_t count = mArgsQueue.size(); michael@0: for (size_t i = 0; i < count; i++) { michael@0: NotifyArgs* args = mArgsQueue[i]; michael@0: args->notify(mInnerListener); michael@0: delete args; michael@0: } michael@0: mArgsQueue.clear(); michael@0: } michael@0: michael@0: michael@0: } // namespace android