input.cpp revision a95e4cb62f3642cb190d032dbf7dc40d9ecc6973
1a95e4cb62f3642cb190d032dbf7dc40d9ecc6973Dianne Hackborn/* 2a95e4cb62f3642cb190d032dbf7dc40d9ecc6973Dianne Hackborn * Copyright (C) 2009 The Android Open Source Project 3a95e4cb62f3642cb190d032dbf7dc40d9ecc6973Dianne Hackborn * 4a95e4cb62f3642cb190d032dbf7dc40d9ecc6973Dianne Hackborn * Licensed under the Apache License, Version 2.0 (the "License"); 5a95e4cb62f3642cb190d032dbf7dc40d9ecc6973Dianne Hackborn * you may not use this file except in compliance with the License. 6a95e4cb62f3642cb190d032dbf7dc40d9ecc6973Dianne Hackborn * You may obtain a copy of the License at 7a95e4cb62f3642cb190d032dbf7dc40d9ecc6973Dianne Hackborn * 8a95e4cb62f3642cb190d032dbf7dc40d9ecc6973Dianne Hackborn * http://www.apache.org/licenses/LICENSE-2.0 9a95e4cb62f3642cb190d032dbf7dc40d9ecc6973Dianne Hackborn * 10a95e4cb62f3642cb190d032dbf7dc40d9ecc6973Dianne Hackborn * Unless required by applicable law or agreed to in writing, software 11a95e4cb62f3642cb190d032dbf7dc40d9ecc6973Dianne Hackborn * distributed under the License is distributed on an "AS IS" BASIS, 12a95e4cb62f3642cb190d032dbf7dc40d9ecc6973Dianne Hackborn * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13a95e4cb62f3642cb190d032dbf7dc40d9ecc6973Dianne Hackborn * See the License for the specific language governing permissions and 14a95e4cb62f3642cb190d032dbf7dc40d9ecc6973Dianne Hackborn * limitations under the License. 15a95e4cb62f3642cb190d032dbf7dc40d9ecc6973Dianne Hackborn */ 16a95e4cb62f3642cb190d032dbf7dc40d9ecc6973Dianne Hackborn 17a95e4cb62f3642cb190d032dbf7dc40d9ecc6973Dianne Hackborn#define LOG_TAG "input" 18a95e4cb62f3642cb190d032dbf7dc40d9ecc6973Dianne Hackborn#include <utils/Log.h> 19a95e4cb62f3642cb190d032dbf7dc40d9ecc6973Dianne Hackborn 20a95e4cb62f3642cb190d032dbf7dc40d9ecc6973Dianne Hackborn#include <android/input.h> 21a95e4cb62f3642cb190d032dbf7dc40d9ecc6973Dianne Hackborn#include <ui/Input.h> 22a95e4cb62f3642cb190d032dbf7dc40d9ecc6973Dianne Hackborn#include <ui/InputTransport.h> 23a95e4cb62f3642cb190d032dbf7dc40d9ecc6973Dianne Hackborn 24a95e4cb62f3642cb190d032dbf7dc40d9ecc6973Dianne Hackborn#include <poll.h> 25a95e4cb62f3642cb190d032dbf7dc40d9ecc6973Dianne Hackborn 26a95e4cb62f3642cb190d032dbf7dc40d9ecc6973Dianne Hackbornusing android::InputEvent; 27a95e4cb62f3642cb190d032dbf7dc40d9ecc6973Dianne Hackbornusing android::KeyEvent; 28a95e4cb62f3642cb190d032dbf7dc40d9ecc6973Dianne Hackbornusing android::MotionEvent; 29a95e4cb62f3642cb190d032dbf7dc40d9ecc6973Dianne Hackborn 30a95e4cb62f3642cb190d032dbf7dc40d9ecc6973Dianne Hackbornint32_t input_event_get_type(const input_event_t* event) { 31a95e4cb62f3642cb190d032dbf7dc40d9ecc6973Dianne Hackborn return static_cast<const InputEvent*>(event)->getType(); 32a95e4cb62f3642cb190d032dbf7dc40d9ecc6973Dianne Hackborn} 33a95e4cb62f3642cb190d032dbf7dc40d9ecc6973Dianne Hackborn 34a95e4cb62f3642cb190d032dbf7dc40d9ecc6973Dianne Hackbornint32_t input_event_get_device_id(const input_event_t* event) { 35a95e4cb62f3642cb190d032dbf7dc40d9ecc6973Dianne Hackborn return static_cast<const InputEvent*>(event)->getDeviceId(); 36a95e4cb62f3642cb190d032dbf7dc40d9ecc6973Dianne Hackborn} 37a95e4cb62f3642cb190d032dbf7dc40d9ecc6973Dianne Hackborn 38a95e4cb62f3642cb190d032dbf7dc40d9ecc6973Dianne Hackbornint32_t input_event_get_nature(const input_event_t* event) { 39a95e4cb62f3642cb190d032dbf7dc40d9ecc6973Dianne Hackborn return static_cast<const InputEvent*>(event)->getNature(); 40a95e4cb62f3642cb190d032dbf7dc40d9ecc6973Dianne Hackborn} 41a95e4cb62f3642cb190d032dbf7dc40d9ecc6973Dianne Hackborn 42a95e4cb62f3642cb190d032dbf7dc40d9ecc6973Dianne Hackbornint32_t key_event_get_action(const input_event_t* key_event) { 43a95e4cb62f3642cb190d032dbf7dc40d9ecc6973Dianne Hackborn return static_cast<const KeyEvent*>(key_event)->getAction(); 44a95e4cb62f3642cb190d032dbf7dc40d9ecc6973Dianne Hackborn} 45a95e4cb62f3642cb190d032dbf7dc40d9ecc6973Dianne Hackborn 46a95e4cb62f3642cb190d032dbf7dc40d9ecc6973Dianne Hackbornint32_t key_event_get_flags(const input_event_t* key_event) { 47a95e4cb62f3642cb190d032dbf7dc40d9ecc6973Dianne Hackborn return static_cast<const KeyEvent*>(key_event)->getFlags(); 48a95e4cb62f3642cb190d032dbf7dc40d9ecc6973Dianne Hackborn} 49a95e4cb62f3642cb190d032dbf7dc40d9ecc6973Dianne Hackborn 50a95e4cb62f3642cb190d032dbf7dc40d9ecc6973Dianne Hackbornint32_t key_event_get_key_code(const input_event_t* key_event) { 51a95e4cb62f3642cb190d032dbf7dc40d9ecc6973Dianne Hackborn return static_cast<const KeyEvent*>(key_event)->getKeyCode(); 52a95e4cb62f3642cb190d032dbf7dc40d9ecc6973Dianne Hackborn} 53a95e4cb62f3642cb190d032dbf7dc40d9ecc6973Dianne Hackborn 54a95e4cb62f3642cb190d032dbf7dc40d9ecc6973Dianne Hackbornint32_t key_event_get_scan_code(const input_event_t* key_event) { 55a95e4cb62f3642cb190d032dbf7dc40d9ecc6973Dianne Hackborn return static_cast<const KeyEvent*>(key_event)->getScanCode(); 56a95e4cb62f3642cb190d032dbf7dc40d9ecc6973Dianne Hackborn} 57a95e4cb62f3642cb190d032dbf7dc40d9ecc6973Dianne Hackborn 58a95e4cb62f3642cb190d032dbf7dc40d9ecc6973Dianne Hackbornint32_t key_event_get_meta_state(const input_event_t* key_event) { 59a95e4cb62f3642cb190d032dbf7dc40d9ecc6973Dianne Hackborn return static_cast<const KeyEvent*>(key_event)->getMetaState(); 60a95e4cb62f3642cb190d032dbf7dc40d9ecc6973Dianne Hackborn} 61a95e4cb62f3642cb190d032dbf7dc40d9ecc6973Dianne Hackbornint32_t key_event_get_repeat_count(const input_event_t* key_event) { 62a95e4cb62f3642cb190d032dbf7dc40d9ecc6973Dianne Hackborn return static_cast<const KeyEvent*>(key_event)->getRepeatCount(); 63a95e4cb62f3642cb190d032dbf7dc40d9ecc6973Dianne Hackborn} 64a95e4cb62f3642cb190d032dbf7dc40d9ecc6973Dianne Hackborn 65a95e4cb62f3642cb190d032dbf7dc40d9ecc6973Dianne Hackbornint64_t key_event_get_down_time(const input_event_t* key_event) { 66a95e4cb62f3642cb190d032dbf7dc40d9ecc6973Dianne Hackborn return static_cast<const KeyEvent*>(key_event)->getDownTime(); 67a95e4cb62f3642cb190d032dbf7dc40d9ecc6973Dianne Hackborn} 68a95e4cb62f3642cb190d032dbf7dc40d9ecc6973Dianne Hackborn 69a95e4cb62f3642cb190d032dbf7dc40d9ecc6973Dianne Hackbornint64_t key_event_get_event_time(const input_event_t* key_event) { 70a95e4cb62f3642cb190d032dbf7dc40d9ecc6973Dianne Hackborn return static_cast<const KeyEvent*>(key_event)->getEventTime(); 71a95e4cb62f3642cb190d032dbf7dc40d9ecc6973Dianne Hackborn} 72a95e4cb62f3642cb190d032dbf7dc40d9ecc6973Dianne Hackborn 73a95e4cb62f3642cb190d032dbf7dc40d9ecc6973Dianne Hackbornint32_t motion_event_get_action(const input_event_t* motion_event) { 74a95e4cb62f3642cb190d032dbf7dc40d9ecc6973Dianne Hackborn return static_cast<const MotionEvent*>(motion_event)->getAction(); 75a95e4cb62f3642cb190d032dbf7dc40d9ecc6973Dianne Hackborn} 76a95e4cb62f3642cb190d032dbf7dc40d9ecc6973Dianne Hackborn 77a95e4cb62f3642cb190d032dbf7dc40d9ecc6973Dianne Hackbornint32_t motion_event_get_meta_state(const input_event_t* motion_event) { 78a95e4cb62f3642cb190d032dbf7dc40d9ecc6973Dianne Hackborn return static_cast<const MotionEvent*>(motion_event)->getMetaState(); 79a95e4cb62f3642cb190d032dbf7dc40d9ecc6973Dianne Hackborn} 80a95e4cb62f3642cb190d032dbf7dc40d9ecc6973Dianne Hackborn 81a95e4cb62f3642cb190d032dbf7dc40d9ecc6973Dianne Hackbornint32_t motion_event_get_edge_flags(const input_event_t* motion_event) { 82a95e4cb62f3642cb190d032dbf7dc40d9ecc6973Dianne Hackborn return reinterpret_cast<const MotionEvent*>(motion_event)->getEdgeFlags(); 83a95e4cb62f3642cb190d032dbf7dc40d9ecc6973Dianne Hackborn} 84a95e4cb62f3642cb190d032dbf7dc40d9ecc6973Dianne Hackborn 85a95e4cb62f3642cb190d032dbf7dc40d9ecc6973Dianne Hackbornint64_t motion_event_get_down_time(const input_event_t* motion_event) { 86a95e4cb62f3642cb190d032dbf7dc40d9ecc6973Dianne Hackborn return static_cast<const MotionEvent*>(motion_event)->getDownTime(); 87a95e4cb62f3642cb190d032dbf7dc40d9ecc6973Dianne Hackborn} 88a95e4cb62f3642cb190d032dbf7dc40d9ecc6973Dianne Hackborn 89a95e4cb62f3642cb190d032dbf7dc40d9ecc6973Dianne Hackbornint64_t motion_event_get_event_time(const input_event_t* motion_event) { 90a95e4cb62f3642cb190d032dbf7dc40d9ecc6973Dianne Hackborn return static_cast<const MotionEvent*>(motion_event)->getEventTime(); 91a95e4cb62f3642cb190d032dbf7dc40d9ecc6973Dianne Hackborn} 92a95e4cb62f3642cb190d032dbf7dc40d9ecc6973Dianne Hackborn 93a95e4cb62f3642cb190d032dbf7dc40d9ecc6973Dianne Hackbornfloat motion_event_get_x_offset(const input_event_t* motion_event) { 94a95e4cb62f3642cb190d032dbf7dc40d9ecc6973Dianne Hackborn return static_cast<const MotionEvent*>(motion_event)->getXOffset(); 95a95e4cb62f3642cb190d032dbf7dc40d9ecc6973Dianne Hackborn} 96a95e4cb62f3642cb190d032dbf7dc40d9ecc6973Dianne Hackborn 97a95e4cb62f3642cb190d032dbf7dc40d9ecc6973Dianne Hackbornfloat motion_event_get_y_offset(const input_event_t* motion_event) { 98a95e4cb62f3642cb190d032dbf7dc40d9ecc6973Dianne Hackborn return static_cast<const MotionEvent*>(motion_event)->getYOffset(); 99a95e4cb62f3642cb190d032dbf7dc40d9ecc6973Dianne Hackborn} 100a95e4cb62f3642cb190d032dbf7dc40d9ecc6973Dianne Hackborn 101a95e4cb62f3642cb190d032dbf7dc40d9ecc6973Dianne Hackbornfloat motion_event_get_x_precision(const input_event_t* motion_event) { 102a95e4cb62f3642cb190d032dbf7dc40d9ecc6973Dianne Hackborn return static_cast<const MotionEvent*>(motion_event)->getXPrecision(); 103a95e4cb62f3642cb190d032dbf7dc40d9ecc6973Dianne Hackborn} 104a95e4cb62f3642cb190d032dbf7dc40d9ecc6973Dianne Hackborn 105a95e4cb62f3642cb190d032dbf7dc40d9ecc6973Dianne Hackbornfloat motion_event_get_y_precision(const input_event_t* motion_event) { 106a95e4cb62f3642cb190d032dbf7dc40d9ecc6973Dianne Hackborn return static_cast<const MotionEvent*>(motion_event)->getYPrecision(); 107a95e4cb62f3642cb190d032dbf7dc40d9ecc6973Dianne Hackborn} 108a95e4cb62f3642cb190d032dbf7dc40d9ecc6973Dianne Hackborn 109a95e4cb62f3642cb190d032dbf7dc40d9ecc6973Dianne Hackbornsize_t motion_event_get_pointer_count(const input_event_t* motion_event) { 110a95e4cb62f3642cb190d032dbf7dc40d9ecc6973Dianne Hackborn return static_cast<const MotionEvent*>(motion_event)->getPointerCount(); 111a95e4cb62f3642cb190d032dbf7dc40d9ecc6973Dianne Hackborn} 112a95e4cb62f3642cb190d032dbf7dc40d9ecc6973Dianne Hackborn 113a95e4cb62f3642cb190d032dbf7dc40d9ecc6973Dianne Hackbornint32_t motion_event_get_pointer_id(const input_event_t* motion_event, size_t pointer_index) { 114a95e4cb62f3642cb190d032dbf7dc40d9ecc6973Dianne Hackborn return static_cast<const MotionEvent*>(motion_event)->getPointerId(pointer_index); 115a95e4cb62f3642cb190d032dbf7dc40d9ecc6973Dianne Hackborn} 116a95e4cb62f3642cb190d032dbf7dc40d9ecc6973Dianne Hackborn 117a95e4cb62f3642cb190d032dbf7dc40d9ecc6973Dianne Hackbornfloat motion_event_get_raw_x(const input_event_t* motion_event, size_t pointer_index) { 118a95e4cb62f3642cb190d032dbf7dc40d9ecc6973Dianne Hackborn return static_cast<const MotionEvent*>(motion_event)->getRawX(pointer_index); 119a95e4cb62f3642cb190d032dbf7dc40d9ecc6973Dianne Hackborn} 120a95e4cb62f3642cb190d032dbf7dc40d9ecc6973Dianne Hackborn 121a95e4cb62f3642cb190d032dbf7dc40d9ecc6973Dianne Hackbornfloat motion_event_get_raw_y(const input_event_t* motion_event, size_t pointer_index) { 122a95e4cb62f3642cb190d032dbf7dc40d9ecc6973Dianne Hackborn return static_cast<const MotionEvent*>(motion_event)->getRawY(pointer_index); 123a95e4cb62f3642cb190d032dbf7dc40d9ecc6973Dianne Hackborn} 124a95e4cb62f3642cb190d032dbf7dc40d9ecc6973Dianne Hackborn 125a95e4cb62f3642cb190d032dbf7dc40d9ecc6973Dianne Hackbornfloat motion_event_get_x(const input_event_t* motion_event, size_t pointer_index) { 126a95e4cb62f3642cb190d032dbf7dc40d9ecc6973Dianne Hackborn return static_cast<const MotionEvent*>(motion_event)->getX(pointer_index); 127a95e4cb62f3642cb190d032dbf7dc40d9ecc6973Dianne Hackborn} 128a95e4cb62f3642cb190d032dbf7dc40d9ecc6973Dianne Hackborn 129a95e4cb62f3642cb190d032dbf7dc40d9ecc6973Dianne Hackbornfloat motion_event_get_y(const input_event_t* motion_event, size_t pointer_index) { 130a95e4cb62f3642cb190d032dbf7dc40d9ecc6973Dianne Hackborn return static_cast<const MotionEvent*>(motion_event)->getY(pointer_index); 131a95e4cb62f3642cb190d032dbf7dc40d9ecc6973Dianne Hackborn} 132a95e4cb62f3642cb190d032dbf7dc40d9ecc6973Dianne Hackborn 133a95e4cb62f3642cb190d032dbf7dc40d9ecc6973Dianne Hackbornfloat motion_event_get_pressure(const input_event_t* motion_event, size_t pointer_index) { 134a95e4cb62f3642cb190d032dbf7dc40d9ecc6973Dianne Hackborn return static_cast<const MotionEvent*>(motion_event)->getPressure(pointer_index); 135a95e4cb62f3642cb190d032dbf7dc40d9ecc6973Dianne Hackborn} 136a95e4cb62f3642cb190d032dbf7dc40d9ecc6973Dianne Hackborn 137a95e4cb62f3642cb190d032dbf7dc40d9ecc6973Dianne Hackbornfloat motion_event_get_size(const input_event_t* motion_event, size_t pointer_index) { 138a95e4cb62f3642cb190d032dbf7dc40d9ecc6973Dianne Hackborn return static_cast<const MotionEvent*>(motion_event)->getSize(pointer_index); 139a95e4cb62f3642cb190d032dbf7dc40d9ecc6973Dianne Hackborn} 140a95e4cb62f3642cb190d032dbf7dc40d9ecc6973Dianne Hackborn 141a95e4cb62f3642cb190d032dbf7dc40d9ecc6973Dianne Hackbornsize_t motion_event_get_history_size(const input_event_t* motion_event) { 142a95e4cb62f3642cb190d032dbf7dc40d9ecc6973Dianne Hackborn return static_cast<const MotionEvent*>(motion_event)->getHistorySize(); 143a95e4cb62f3642cb190d032dbf7dc40d9ecc6973Dianne Hackborn} 144a95e4cb62f3642cb190d032dbf7dc40d9ecc6973Dianne Hackborn 145a95e4cb62f3642cb190d032dbf7dc40d9ecc6973Dianne Hackbornint64_t motion_event_get_historical_event_time(input_event_t* motion_event, 146a95e4cb62f3642cb190d032dbf7dc40d9ecc6973Dianne Hackborn size_t history_index) { 147a95e4cb62f3642cb190d032dbf7dc40d9ecc6973Dianne Hackborn return static_cast<const MotionEvent*>(motion_event)->getHistoricalEventTime( 148a95e4cb62f3642cb190d032dbf7dc40d9ecc6973Dianne Hackborn history_index); 149a95e4cb62f3642cb190d032dbf7dc40d9ecc6973Dianne Hackborn} 150a95e4cb62f3642cb190d032dbf7dc40d9ecc6973Dianne Hackborn 151a95e4cb62f3642cb190d032dbf7dc40d9ecc6973Dianne Hackbornfloat motion_event_get_historical_raw_x(input_event_t* motion_event, size_t pointer_index, 152a95e4cb62f3642cb190d032dbf7dc40d9ecc6973Dianne Hackborn size_t history_index) { 153a95e4cb62f3642cb190d032dbf7dc40d9ecc6973Dianne Hackborn return static_cast<const MotionEvent*>(motion_event)->getHistoricalRawX( 154a95e4cb62f3642cb190d032dbf7dc40d9ecc6973Dianne Hackborn pointer_index, history_index); 155a95e4cb62f3642cb190d032dbf7dc40d9ecc6973Dianne Hackborn} 156a95e4cb62f3642cb190d032dbf7dc40d9ecc6973Dianne Hackborn 157a95e4cb62f3642cb190d032dbf7dc40d9ecc6973Dianne Hackbornfloat motion_event_get_historical_raw_y(input_event_t* motion_event, size_t pointer_index, 158a95e4cb62f3642cb190d032dbf7dc40d9ecc6973Dianne Hackborn size_t history_index) { 159a95e4cb62f3642cb190d032dbf7dc40d9ecc6973Dianne Hackborn return static_cast<const MotionEvent*>(motion_event)->getHistoricalRawY( 160a95e4cb62f3642cb190d032dbf7dc40d9ecc6973Dianne Hackborn pointer_index, history_index); 161a95e4cb62f3642cb190d032dbf7dc40d9ecc6973Dianne Hackborn} 162a95e4cb62f3642cb190d032dbf7dc40d9ecc6973Dianne Hackborn 163a95e4cb62f3642cb190d032dbf7dc40d9ecc6973Dianne Hackbornfloat motion_event_get_historical_x(input_event_t* motion_event, size_t pointer_index, 164a95e4cb62f3642cb190d032dbf7dc40d9ecc6973Dianne Hackborn size_t history_index) { 165a95e4cb62f3642cb190d032dbf7dc40d9ecc6973Dianne Hackborn return static_cast<const MotionEvent*>(motion_event)->getHistoricalX( 166a95e4cb62f3642cb190d032dbf7dc40d9ecc6973Dianne Hackborn pointer_index, history_index); 167a95e4cb62f3642cb190d032dbf7dc40d9ecc6973Dianne Hackborn} 168a95e4cb62f3642cb190d032dbf7dc40d9ecc6973Dianne Hackborn 169a95e4cb62f3642cb190d032dbf7dc40d9ecc6973Dianne Hackbornfloat motion_event_get_historical_y(input_event_t* motion_event, size_t pointer_index, 170a95e4cb62f3642cb190d032dbf7dc40d9ecc6973Dianne Hackborn size_t history_index) { 171a95e4cb62f3642cb190d032dbf7dc40d9ecc6973Dianne Hackborn return static_cast<const MotionEvent*>(motion_event)->getHistoricalY( 172a95e4cb62f3642cb190d032dbf7dc40d9ecc6973Dianne Hackborn pointer_index, history_index); 173a95e4cb62f3642cb190d032dbf7dc40d9ecc6973Dianne Hackborn} 174a95e4cb62f3642cb190d032dbf7dc40d9ecc6973Dianne Hackborn 175a95e4cb62f3642cb190d032dbf7dc40d9ecc6973Dianne Hackbornfloat motion_event_get_historical_pressure(input_event_t* motion_event, size_t pointer_index, 176a95e4cb62f3642cb190d032dbf7dc40d9ecc6973Dianne Hackborn size_t history_index) { 177a95e4cb62f3642cb190d032dbf7dc40d9ecc6973Dianne Hackborn return static_cast<const MotionEvent*>(motion_event)->getHistoricalPressure( 178a95e4cb62f3642cb190d032dbf7dc40d9ecc6973Dianne Hackborn pointer_index, history_index); 179a95e4cb62f3642cb190d032dbf7dc40d9ecc6973Dianne Hackborn} 180a95e4cb62f3642cb190d032dbf7dc40d9ecc6973Dianne Hackborn 181a95e4cb62f3642cb190d032dbf7dc40d9ecc6973Dianne Hackbornfloat motion_event_get_historical_size(input_event_t* motion_event, size_t pointer_index, 182a95e4cb62f3642cb190d032dbf7dc40d9ecc6973Dianne Hackborn size_t history_index) { 183a95e4cb62f3642cb190d032dbf7dc40d9ecc6973Dianne Hackborn return static_cast<const MotionEvent*>(motion_event)->getHistoricalSize( 184a95e4cb62f3642cb190d032dbf7dc40d9ecc6973Dianne Hackborn pointer_index, history_index); 185a95e4cb62f3642cb190d032dbf7dc40d9ecc6973Dianne Hackborn} 186a95e4cb62f3642cb190d032dbf7dc40d9ecc6973Dianne Hackborn 187a95e4cb62f3642cb190d032dbf7dc40d9ecc6973Dianne Hackbornint input_queue_get_fd(input_queue_t* queue) { 188a95e4cb62f3642cb190d032dbf7dc40d9ecc6973Dianne Hackborn return queue->getConsumer().getChannel()->getReceivePipeFd(); 189a95e4cb62f3642cb190d032dbf7dc40d9ecc6973Dianne Hackborn} 190a95e4cb62f3642cb190d032dbf7dc40d9ecc6973Dianne Hackborn 191a95e4cb62f3642cb190d032dbf7dc40d9ecc6973Dianne Hackbornint input_queue_has_events(input_queue_t* queue) { 192a95e4cb62f3642cb190d032dbf7dc40d9ecc6973Dianne Hackborn struct pollfd pfd; 193a95e4cb62f3642cb190d032dbf7dc40d9ecc6973Dianne Hackborn 194a95e4cb62f3642cb190d032dbf7dc40d9ecc6973Dianne Hackborn pfd.fd = queue->getConsumer().getChannel()->getReceivePipeFd(); 195a95e4cb62f3642cb190d032dbf7dc40d9ecc6973Dianne Hackborn pfd.events = POLLIN; 196a95e4cb62f3642cb190d032dbf7dc40d9ecc6973Dianne Hackborn pfd.revents = 0; 197a95e4cb62f3642cb190d032dbf7dc40d9ecc6973Dianne Hackborn 198a95e4cb62f3642cb190d032dbf7dc40d9ecc6973Dianne Hackborn int nfd = poll(&pfd, 1, 0); 199a95e4cb62f3642cb190d032dbf7dc40d9ecc6973Dianne Hackborn if (nfd <= 0) return nfd; 200a95e4cb62f3642cb190d032dbf7dc40d9ecc6973Dianne Hackborn return pfd.revents == POLLIN ? 1 : -1; 201a95e4cb62f3642cb190d032dbf7dc40d9ecc6973Dianne Hackborn} 202a95e4cb62f3642cb190d032dbf7dc40d9ecc6973Dianne Hackborn 203a95e4cb62f3642cb190d032dbf7dc40d9ecc6973Dianne Hackbornint32_t input_queue_get_event(input_queue_t* queue, input_event_t** outEvent) { 204a95e4cb62f3642cb190d032dbf7dc40d9ecc6973Dianne Hackborn *outEvent = NULL; 205a95e4cb62f3642cb190d032dbf7dc40d9ecc6973Dianne Hackborn 206a95e4cb62f3642cb190d032dbf7dc40d9ecc6973Dianne Hackborn int32_t res = queue->getConsumer().receiveDispatchSignal(); 207a95e4cb62f3642cb190d032dbf7dc40d9ecc6973Dianne Hackborn if (res != android::OK) { 208a95e4cb62f3642cb190d032dbf7dc40d9ecc6973Dianne Hackborn LOGE("channel '%s' ~ Failed to receive dispatch signal. status=%d", 209a95e4cb62f3642cb190d032dbf7dc40d9ecc6973Dianne Hackborn queue->getConsumer().getChannel()->getName().string(), res); 210a95e4cb62f3642cb190d032dbf7dc40d9ecc6973Dianne Hackborn return -1; 211a95e4cb62f3642cb190d032dbf7dc40d9ecc6973Dianne Hackborn } 212a95e4cb62f3642cb190d032dbf7dc40d9ecc6973Dianne Hackborn 213a95e4cb62f3642cb190d032dbf7dc40d9ecc6973Dianne Hackborn InputEvent* myEvent = NULL; 214a95e4cb62f3642cb190d032dbf7dc40d9ecc6973Dianne Hackborn res = queue->consume(&myEvent); 215a95e4cb62f3642cb190d032dbf7dc40d9ecc6973Dianne Hackborn if (res != android::OK) { 216a95e4cb62f3642cb190d032dbf7dc40d9ecc6973Dianne Hackborn LOGW("channel '%s' ~ Failed to consume input event. status=%d", 217a95e4cb62f3642cb190d032dbf7dc40d9ecc6973Dianne Hackborn queue->getConsumer().getChannel()->getName().string(), res); 218a95e4cb62f3642cb190d032dbf7dc40d9ecc6973Dianne Hackborn queue->getConsumer().sendFinishedSignal(); 219a95e4cb62f3642cb190d032dbf7dc40d9ecc6973Dianne Hackborn return -1; 220a95e4cb62f3642cb190d032dbf7dc40d9ecc6973Dianne Hackborn } 221a95e4cb62f3642cb190d032dbf7dc40d9ecc6973Dianne Hackborn 222a95e4cb62f3642cb190d032dbf7dc40d9ecc6973Dianne Hackborn *outEvent = myEvent; 223a95e4cb62f3642cb190d032dbf7dc40d9ecc6973Dianne Hackborn return 0; 224a95e4cb62f3642cb190d032dbf7dc40d9ecc6973Dianne Hackborn} 225a95e4cb62f3642cb190d032dbf7dc40d9ecc6973Dianne Hackborn 226a95e4cb62f3642cb190d032dbf7dc40d9ecc6973Dianne Hackbornvoid input_queue_finish_event(input_queue_t* queue, input_event_t* event, 227a95e4cb62f3642cb190d032dbf7dc40d9ecc6973Dianne Hackborn int handled) { 228a95e4cb62f3642cb190d032dbf7dc40d9ecc6973Dianne Hackborn int32_t res = queue->getConsumer().sendFinishedSignal(); 229a95e4cb62f3642cb190d032dbf7dc40d9ecc6973Dianne Hackborn if (res != android::OK) { 230a95e4cb62f3642cb190d032dbf7dc40d9ecc6973Dianne Hackborn LOGW("Failed to send finished signal on channel '%s'. status=%d", 231a95e4cb62f3642cb190d032dbf7dc40d9ecc6973Dianne Hackborn queue->getConsumer().getChannel()->getName().string(), res); 232a95e4cb62f3642cb190d032dbf7dc40d9ecc6973Dianne Hackborn } 233a95e4cb62f3642cb190d032dbf7dc40d9ecc6973Dianne Hackborn} 234