Home | History | Annotate | Download | only in input
      1 /*
      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 
     25 namespace android {
     26 
     27 // --- NotifyConfigurationChangedArgs ---
     28 
     29 NotifyConfigurationChangedArgs::NotifyConfigurationChangedArgs(nsecs_t eventTime) :
     30         eventTime(eventTime) {
     31 }
     32 
     33 NotifyConfigurationChangedArgs::NotifyConfigurationChangedArgs(
     34         const NotifyConfigurationChangedArgs& other) :
     35         eventTime(other.eventTime) {
     36 }
     37 
     38 void NotifyConfigurationChangedArgs::notify(const sp<InputListenerInterface>& listener) const {
     39     listener->notifyConfigurationChanged(this);
     40 }
     41 
     42 
     43 // --- NotifyKeyArgs ---
     44 
     45 NotifyKeyArgs::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 
     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) {
     60 }
     61 
     62 void NotifyKeyArgs::notify(const sp<InputListenerInterface>& listener) const {
     63     listener->notifyKey(this);
     64 }
     65 
     66 
     67 // --- NotifyMotionArgs ---
     68 
     69 NotifyMotionArgs::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,
     72         int32_t edgeFlags, 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), flags(flags), metaState(metaState), buttonState(buttonState),
     77         edgeFlags(edgeFlags), pointerCount(pointerCount),
     78         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 
     85 NotifyMotionArgs::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),
     90         edgeFlags(other.edgeFlags), pointerCount(other.pointerCount),
     91         xPrecision(other.xPrecision), yPrecision(other.yPrecision), downTime(other.downTime) {
     92     for (uint32_t i = 0; i < pointerCount; i++) {
     93         pointerProperties[i].copyFrom(other.pointerProperties[i]);
     94         pointerCoords[i].copyFrom(other.pointerCoords[i]);
     95     }
     96 }
     97 
     98 void NotifyMotionArgs::notify(const sp<InputListenerInterface>& listener) const {
     99     listener->notifyMotion(this);
    100 }
    101 
    102 
    103 // --- NotifySwitchArgs ---
    104 
    105 NotifySwitchArgs::NotifySwitchArgs(nsecs_t eventTime, uint32_t policyFlags,
    106         int32_t switchCode, int32_t switchValue) :
    107         eventTime(eventTime), policyFlags(policyFlags),
    108         switchCode(switchCode), switchValue(switchValue) {
    109 }
    110 
    111 NotifySwitchArgs::NotifySwitchArgs(const NotifySwitchArgs& other) :
    112         eventTime(other.eventTime), policyFlags(other.policyFlags),
    113         switchCode(other.switchCode), switchValue(other.switchValue) {
    114 }
    115 
    116 void NotifySwitchArgs::notify(const sp<InputListenerInterface>& listener) const {
    117     listener->notifySwitch(this);
    118 }
    119 
    120 
    121 // --- NotifyDeviceResetArgs ---
    122 
    123 NotifyDeviceResetArgs::NotifyDeviceResetArgs(nsecs_t eventTime, int32_t deviceId) :
    124         eventTime(eventTime), deviceId(deviceId) {
    125 }
    126 
    127 NotifyDeviceResetArgs::NotifyDeviceResetArgs(const NotifyDeviceResetArgs& other) :
    128         eventTime(other.eventTime), deviceId(other.deviceId) {
    129 }
    130 
    131 void NotifyDeviceResetArgs::notify(const sp<InputListenerInterface>& listener) const {
    132     listener->notifyDeviceReset(this);
    133 }
    134 
    135 
    136 // --- QueuedInputListener ---
    137 
    138 QueuedInputListener::QueuedInputListener(const sp<InputListenerInterface>& innerListener) :
    139         mInnerListener(innerListener) {
    140 }
    141 
    142 QueuedInputListener::~QueuedInputListener() {
    143     size_t count = mArgsQueue.size();
    144     for (size_t i = 0; i < count; i++) {
    145         delete mArgsQueue[i];
    146     }
    147 }
    148 
    149 void QueuedInputListener::notifyConfigurationChanged(
    150         const NotifyConfigurationChangedArgs* args) {
    151     mArgsQueue.push(new NotifyConfigurationChangedArgs(*args));
    152 }
    153 
    154 void QueuedInputListener::notifyKey(const NotifyKeyArgs* args) {
    155     mArgsQueue.push(new NotifyKeyArgs(*args));
    156 }
    157 
    158 void QueuedInputListener::notifyMotion(const NotifyMotionArgs* args) {
    159     mArgsQueue.push(new NotifyMotionArgs(*args));
    160 }
    161 
    162 void QueuedInputListener::notifySwitch(const NotifySwitchArgs* args) {
    163     mArgsQueue.push(new NotifySwitchArgs(*args));
    164 }
    165 
    166 void QueuedInputListener::notifyDeviceReset(const NotifyDeviceResetArgs* args) {
    167     mArgsQueue.push(new NotifyDeviceResetArgs(*args));
    168 }
    169 
    170 void QueuedInputListener::flush() {
    171     size_t count = mArgsQueue.size();
    172     for (size_t i = 0; i < count; i++) {
    173         NotifyArgs* args = mArgsQueue[i];
    174         args->notify(mInnerListener);
    175         delete args;
    176     }
    177     mArgsQueue.clear();
    178 }
    179 
    180 
    181 } // namespace android
    182