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: #ifndef _UI_INPUT_LISTENER_H michael@0: #define _UI_INPUT_LISTENER_H michael@0: michael@0: #include "Input.h" michael@0: #include michael@0: #include michael@0: michael@0: namespace android { michael@0: michael@0: class InputListenerInterface; michael@0: michael@0: michael@0: /* Superclass of all input event argument objects */ michael@0: struct NotifyArgs { michael@0: virtual ~NotifyArgs() { } michael@0: michael@0: virtual void notify(const sp& listener) const = 0; michael@0: }; michael@0: michael@0: michael@0: /* Describes a configuration change event. */ michael@0: struct NotifyConfigurationChangedArgs : public NotifyArgs { michael@0: nsecs_t eventTime; michael@0: michael@0: inline NotifyConfigurationChangedArgs() { } michael@0: michael@0: NotifyConfigurationChangedArgs(nsecs_t eventTime); michael@0: michael@0: NotifyConfigurationChangedArgs(const NotifyConfigurationChangedArgs& other); michael@0: michael@0: virtual ~NotifyConfigurationChangedArgs() { } michael@0: michael@0: virtual void notify(const sp& listener) const; michael@0: }; michael@0: michael@0: michael@0: /* Describes a key event. */ michael@0: struct NotifyKeyArgs : public NotifyArgs { michael@0: nsecs_t eventTime; michael@0: int32_t deviceId; michael@0: uint32_t source; michael@0: uint32_t policyFlags; michael@0: int32_t action; michael@0: int32_t flags; michael@0: int32_t keyCode; michael@0: int32_t scanCode; michael@0: int32_t metaState; michael@0: nsecs_t downTime; michael@0: michael@0: inline NotifyKeyArgs() { } michael@0: michael@0: NotifyKeyArgs(nsecs_t eventTime, int32_t deviceId, uint32_t source, 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: michael@0: NotifyKeyArgs(const NotifyKeyArgs& other); michael@0: michael@0: virtual ~NotifyKeyArgs() { } michael@0: michael@0: virtual void notify(const sp& listener) const; michael@0: }; michael@0: michael@0: michael@0: /* Describes a motion event. */ michael@0: struct NotifyMotionArgs : public NotifyArgs { michael@0: nsecs_t eventTime; michael@0: int32_t deviceId; michael@0: uint32_t source; michael@0: uint32_t policyFlags; michael@0: int32_t action; michael@0: int32_t flags; michael@0: int32_t metaState; michael@0: int32_t buttonState; michael@0: int32_t edgeFlags; michael@0: int32_t displayId; michael@0: uint32_t pointerCount; michael@0: PointerProperties pointerProperties[MAX_POINTERS]; michael@0: PointerCoords pointerCoords[MAX_POINTERS]; michael@0: float xPrecision; michael@0: float yPrecision; michael@0: nsecs_t downTime; michael@0: michael@0: inline NotifyMotionArgs() { } michael@0: michael@0: NotifyMotionArgs(nsecs_t eventTime, int32_t deviceId, uint32_t source, 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: michael@0: NotifyMotionArgs(const NotifyMotionArgs& other); michael@0: michael@0: virtual ~NotifyMotionArgs() { } michael@0: michael@0: virtual void notify(const sp& listener) const; michael@0: }; michael@0: michael@0: michael@0: /* Describes a switch event. */ michael@0: struct NotifySwitchArgs : public NotifyArgs { michael@0: nsecs_t eventTime; michael@0: uint32_t policyFlags; michael@0: uint32_t switchValues; michael@0: uint32_t switchMask; michael@0: michael@0: inline NotifySwitchArgs() { } michael@0: michael@0: NotifySwitchArgs(nsecs_t eventTime, uint32_t policyFlags, michael@0: uint32_t switchValues, uint32_t switchMask); michael@0: michael@0: NotifySwitchArgs(const NotifySwitchArgs& other); michael@0: michael@0: virtual ~NotifySwitchArgs() { } michael@0: michael@0: virtual void notify(const sp& listener) const; michael@0: }; michael@0: michael@0: michael@0: /* Describes a device reset event, such as when a device is added, michael@0: * reconfigured, or removed. */ michael@0: struct NotifyDeviceResetArgs : public NotifyArgs { michael@0: nsecs_t eventTime; michael@0: int32_t deviceId; michael@0: michael@0: inline NotifyDeviceResetArgs() { } michael@0: michael@0: NotifyDeviceResetArgs(nsecs_t eventTime, int32_t deviceId); michael@0: michael@0: NotifyDeviceResetArgs(const NotifyDeviceResetArgs& other); michael@0: michael@0: virtual ~NotifyDeviceResetArgs() { } michael@0: michael@0: virtual void notify(const sp& listener) const; michael@0: }; michael@0: michael@0: michael@0: /* michael@0: * The interface used by the InputReader to notify the InputListener about input events. michael@0: */ michael@0: class InputListenerInterface : public virtual RefBase { michael@0: protected: michael@0: InputListenerInterface() { } michael@0: virtual ~InputListenerInterface() { } michael@0: michael@0: public: michael@0: virtual void notifyConfigurationChanged(const NotifyConfigurationChangedArgs* args) = 0; michael@0: virtual void notifyKey(const NotifyKeyArgs* args) = 0; michael@0: virtual void notifyMotion(const NotifyMotionArgs* args) = 0; michael@0: virtual void notifySwitch(const NotifySwitchArgs* args) = 0; michael@0: virtual void notifyDeviceReset(const NotifyDeviceResetArgs* args) = 0; michael@0: }; michael@0: michael@0: michael@0: /* michael@0: * An implementation of the listener interface that queues up and defers dispatch michael@0: * of decoded events until flushed. michael@0: */ michael@0: class QueuedInputListener : public InputListenerInterface { michael@0: protected: michael@0: virtual ~QueuedInputListener(); michael@0: michael@0: public: michael@0: QueuedInputListener(const sp& innerListener); michael@0: michael@0: virtual void notifyConfigurationChanged(const NotifyConfigurationChangedArgs* args); michael@0: virtual void notifyKey(const NotifyKeyArgs* args); michael@0: virtual void notifyMotion(const NotifyMotionArgs* args); michael@0: virtual void notifySwitch(const NotifySwitchArgs* args); michael@0: virtual void notifyDeviceReset(const NotifyDeviceResetArgs* args); michael@0: michael@0: void flush(); michael@0: michael@0: private: michael@0: sp mInnerListener; michael@0: Vector mArgsQueue; michael@0: }; michael@0: michael@0: } // namespace android michael@0: michael@0: #endif // _UI_INPUT_LISTENER_H