From: Jiyoung Yun Date: Tue, 31 Mar 2015 13:57:37 +0000 (+0900) Subject: display: Use libinput to get input events X-Git-Tag: accepted/tizen/common/20150408.102937~12 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=dc32715ebc426f7874b737b80ad301c205235324;p=platform%2Fcore%2Fsystem%2Fdeviced.git display: Use libinput to get input events Remove the exisiting input code and use libinput for getting input events It's for common use with wayland input system. Change-Id: I2de534b73250e8d1fdfccd3b02f64eb13efcb45a Signed-off-by: Seunghun Pi --- diff --git a/CMakeLists.txt b/CMakeLists.txt index 49a76c6..9e72a84 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -102,6 +102,7 @@ SET(SRCS ${SRCS} src/display/lock-detector.c src/display/poll.c src/display/setting.c + src/display/input.c ) ENDIF(TIZEN_DISPLAY) @@ -134,6 +135,7 @@ SET(PKG_MODULES libtzplatform-config notification hwcommon + libinput ) IF(X11_SUPPORT) @@ -157,7 +159,6 @@ MESSAGE("FLAGS: ${CMAKE_C_FLAGS}") ADD_DEFINITIONS("-DPREFIX=\"${CMAKE_INSTALL_PREFIX}\"") ADD_DEFINITIONS("-DFACTORYFS=\"$ENV{FACTORYFS}\"") ADD_DEFINITIONS("-DLIBPATH=\"${LIB_INSTALL_DIR}\"") -ADD_DEFINITIONS("-DENABLE_KEY_FILTER") ADD_DEFINITIONS("-DENABLE_DEVICED_DLOG") ADD_DEFINITIONS("-DENABLE_LIBDEVICED_DLOG") ADD_DEFINITIONS("-DENABLE_PM_LOG") diff --git a/packaging/deviced.spec b/packaging/deviced.spec index 79f179f..5d851ec 100755 --- a/packaging/deviced.spec +++ b/packaging/deviced.spec @@ -46,6 +46,7 @@ BuildRequires: pkgconfig(dbus-1) BuildRequires: pkgconfig(libtzplatform-config) BuildRequires: pkgconfig(notification) BuildRequires: pkgconfig(hwcommon) +BuildRequires: pkgconfig(libinput) %{?systemd_requires} Requires(preun): /usr/bin/systemctl diff --git a/scripts/device-daemon.in b/scripts/device-daemon.in deleted file mode 100644 index 7260d7e..0000000 --- a/scripts/device-daemon.in +++ /dev/null @@ -1,53 +0,0 @@ -#!/bin/sh - -KERNVER=`uname -r` - -export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/lib -export PATH=$PATH:/usr/bin -export ELM_FONT_PATH=@PREFIX@/share/SLP/fonts:@PREFIX@/share/SLP/licensed_fonts:@PREFIX@/share/fonts/truetype/ttf-bitstream-vera -export PM_EXEC_PRG=@PREFIX@/bin/@IDLE_LOCK@ - -export PM_TO_NORMAL=600 # normal state timeout seconds -export PM_TO_LCDDIM=5 # dim state timeout seconds -export PM_TO_LCDOFF=1 # off state timeout seconds -#export PM_TO_LCDOFF=0 # prevent suspend mode - -export PM_SYS_DIMBRT=0 - -DEV_INPUT= -ABS_POSITION_X=0x15 -ABS_POSITION_Y=0x16 -for file in /sys/class/input/event*; do - if [ -e $file ]; then - dev_keytype=`cat ${file}/device/capabilities/key` - if [ "$dev_keytype" != 0 ]; then - DEV_INPUT=$DEV_INPUT:/dev/input/${file#/sys/class/input/} - continue - fi - abs_num=`cat ${file}/device/capabilities/abs | wc -w | cut -d ' ' -f 1` - if [ $abs_num != 2 ]; then - continue - fi - abs_val=`cat ${file}/device/capabilities/abs | cut -d ' ' -f 1` - if [ $(((0x$abs_val >> $ABS_POSITION_X) & 0x1)) != 1 ]; then - continue - fi - if [ $(((0x$abs_val >> $ABS_POSITION_Y) & 0x1)) != 1 ]; then - continue - fi - DEV_INPUT=$DEV_INPUT:/dev/input/${file#/sys/class/input/} - fi -done - -export PM_INPUT=$DEV_INPUT - -PMD=@PREFIX@/bin/@EXEC@ - -echo "Input Event: $PM_INPUT" -OPT_X_DPMS="-x" -echo "LCD Power: X-DPMS enabled" - -/usr/bin/system_server & - -exit 0 - diff --git a/scripts/deviced-pre.sh b/scripts/deviced-pre.sh index f714a95..0238c05 100755 --- a/scripts/deviced-pre.sh +++ b/scripts/deviced-pre.sh @@ -6,7 +6,6 @@ DEVICED_ENV_F=/run/deviced/deviced_env echo "LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/lib" >> $DEVICED_ENV_F -DEV_INPUT= TOUCHSCREEN=400 TOUCHKEY=200 @@ -14,7 +13,6 @@ for file in /sys/class/input/event*; do if [ -e $file ]; then dev_keytype=`/bin/cat ${file}/device/capabilities/key` if [ "$dev_keytype" != 0 ]; then - DEV_INPUT=$DEV_INPUT:/dev/input/${file#/sys/class/input/} var=${dev_keytype%%' '*} if [ $var == $TOUCHSCREEN ]; then DEV_TOUCHSCREEN=/sys/class/input/${file#/sys/class/input/}/device/enabled @@ -31,7 +29,6 @@ for file in /sys/class/input/event*; do fi done -echo "PM_INPUT=$DEV_INPUT" >> $DEVICED_ENV_F echo "PM_TOUCHSCREEN=$DEV_TOUCHSCREEN" >> $DEVICED_ENV_F echo "PM_TOUCHKEY=$DEV_TOUCHKEY" >> $DEVICED_ENV_F echo "PM_TO_NORMAL=30000" >> $DEVICED_ENV_F diff --git a/src/core/common.h b/src/core/common.h index 9eb56be..eabb0b3 100644 --- a/src/core/common.h +++ b/src/core/common.h @@ -87,6 +87,9 @@ #ifndef SEC_TO_MSEC #define SEC_TO_MSEC(x) ((x)*1000) #endif +#ifndef MSEC_TO_USEC +#define MSEC_TO_USEC(x) ((unsigned int)(x)*1000) +#endif #ifndef NSEC_TO_MSEC #define NSEC_TO_MSEC(x) ((double)x/1000000) #endif diff --git a/src/core/device-change-handler.c b/src/core/device-change-handler.c index 794a9f9..9881dcb 100644 --- a/src/core/device-change-handler.c +++ b/src/core/device-change-handler.c @@ -54,7 +54,6 @@ #define MOVINAND_MOUNT_POINT "/opt/media" #define BUFF_MAX 255 -#define SYS_CLASS_INPUT "/sys/class/input" #define USB_STATE_PLATFORM_PATH "/sys/devices/platform/jack/usb_online" #define USB_STATE_SWITCH_PATH "/sys/devices/virtual/switch/usb_cable/state" @@ -65,13 +64,6 @@ static E_DBus_Connection *conn; #endif /* ENABLE_EDBUS_USE */ -struct input_event { - long dummy[2]; - unsigned short type; - unsigned short code; - int value; -}; - enum snd_jack_types { SND_JACK_HEADPHONE = 0x0001, SND_JACK_MICROPHONE = 0x0002, @@ -140,8 +132,6 @@ struct siop_data { static int ss_flags = 0; -static int input_device_number; - /* Uevent */ static struct udev *udev = NULL; /* Kernel Uevent */ @@ -151,7 +141,6 @@ static int ufd = -1; static int hdmi_status = 0; enum udev_subsystem_type { - UDEV_INPUT, UDEV_PLATFORM, UDEV_SWITCH, }; @@ -161,7 +150,6 @@ static const struct udev_subsystem { const char *str; const char *devtype; } udev_subsystems[] = { - { UDEV_INPUT, INPUT_SUBSYSTEM, NULL }, { UDEV_PLATFORM, PLATFORM_SUBSYSTEM, NULL }, { UDEV_SWITCH, SWITCH_SUBSYSTEM, NULL }, }; @@ -725,7 +713,6 @@ static int booting_done(void *data) _I("booting done"); /* set initial state for devices */ - input_device_number = 0; cradle_chgdet_cb(NULL); keyboard_chgdet_cb(NULL); hdmi_chgdet_cb(NULL); @@ -764,18 +751,6 @@ static Eina_Bool uevent_kernel_control_cb(void *data, Ecore_Fd_Handler *fd_handl devpath = udev_device_get_devpath(dev); switch (udev_subsystems[i].type) { - case UDEV_INPUT: - /* check new input device */ - if (!fnmatch(INPUT_PATH, devpath, 0)) { - action = udev_device_get_action(dev); - devnode = udev_device_get_devnode(dev); - if (!strcmp(action, UDEV_ADD)) - device_notify(DEVICE_NOTIFIER_INPUT_ADD, (void *)devnode); - else if (!strcmp(action, UDEV_REMOVE)) - device_notify(DEVICE_NOTIFIER_INPUT_REMOVE, (void *)devnode); - goto out; - } - break; case UDEV_SWITCH: env_name = udev_device_get_property_value(dev, "SWITCH_NAME"); env_value = udev_device_get_property_value(dev, "SWITCH_STATE"); diff --git a/src/core/device-notifier.h b/src/core/device-notifier.h index 597217a..5a4d6d4 100644 --- a/src/core/device-notifier.h +++ b/src/core/device-notifier.h @@ -28,8 +28,6 @@ enum device_notifier_type { DEVICE_NOTIFIER_TA, DEVICE_NOTIFIER_LOWBAT, DEVICE_NOTIFIER_TOUCH_HARDKEY, - DEVICE_NOTIFIER_INPUT_ADD, - DEVICE_NOTIFIER_INPUT_REMOVE, DEVICE_NOTIFIER_PROCESS_TERMINATED, DEVICE_NOTIFIER_POWER_SUPPLY, DEVICE_NOTIFIER_POWEROFF, diff --git a/src/core/udev.h b/src/core/udev.h index 45680a5..c8c846c 100644 --- a/src/core/udev.h +++ b/src/core/udev.h @@ -52,10 +52,6 @@ #define CHARGE_STATUS "POWER_SUPPLY_STATUS" #define CHARGE_ONLINE "POWER_SUPPLY_ONLINE" -/* input device */ -#define INPUT_SUBSYSTEM "input" -#define INPUT_PATH "*/input[0-9]*/event[0-9]*" - /* switch device */ #define SWITCH_SUBSYSTEM "switch" diff --git a/src/display/core.c b/src/display/core.c index c7cdd94..a4a68af 100644 --- a/src/display/core.c +++ b/src/display/core.c @@ -1313,29 +1313,6 @@ void pm_history_print(int fd, int count) } #endif -/* logging indev_list for debug */ -void print_dev_list(int fd) -{ - int i; - unsigned int total = 0; - indev *tmp; - - total = eina_list_count(indev_list); - _I("***** total list : %d *****", total); - for (i = 0; i < total; i++) { - tmp = (indev*)eina_list_nth(indev_list, i); - _I("* %d | path:%s, fd:%d, dev_fd:%d", - i, tmp->dev_path, tmp->fd, tmp->dev_fd); - if (fd >= 0) { - char buf[255]; - snprintf(buf, sizeof(buf), " %2d| path:%s, fd:%d, dev_fd:%d\n", - i, tmp->dev_path, tmp->fd, tmp->dev_fd); - write(fd, buf, strlen(buf)); - } - } - _I("***************************\n"); -} - void print_info(int fd) { int s_index = 0; @@ -1386,8 +1363,6 @@ void print_info(int fd) } } - print_dev_list(fd); - if (standby_mode) { snprintf(buf, sizeof(buf), "\n\nstandby mode is on\n"); write(fd, buf, strlen(buf)); @@ -2092,32 +2067,6 @@ static const char *errMSG[INIT_END] = { [INIT_DBUS] = "d-bus init error", }; -static int input_action(char* input_act, char* input_path) -{ - int ret = 0; - Eina_List *l = NULL; - Eina_List *l_next = NULL; - indev *data = NULL; - - if (!strcmp("add", input_act)) { - _I("add input path : %s", input_path); - ret = init_pm_poll_input(poll_callback, input_path); - } else if (!strcmp("remove", input_act)) { - EINA_LIST_FOREACH_SAFE(indev_list, l, l_next, data) - if (!strcmp(input_path, data->dev_path)) { - _I("remove %s", input_path); - ecore_main_fd_handler_del(data->dev_fd); - close(data->fd); - free(data->dev_path); - free(data); - indev_list = eina_list_remove_list(indev_list, l); - } - } else { - ret = -EINVAL; - } - return ret; -} - int set_lcd_timeout(int on, int dim, int holdkey_block, char *name) { if (on == 0 && dim == 0) { @@ -2220,30 +2169,6 @@ static int hall_ic_open(void *data) return 0; } -static int input_device_add(void *data) -{ - char *path = (char *)data; - - if (!path) - return -EINVAL; - - input_action(UDEV_ADD, path); - - return 0; -} - -static int input_device_remove(void *data) -{ - char *path = (char *)data; - - if (!path) - return -EINVAL; - - input_action(UDEV_REMOVE, path); - - return 0; -} - static int booting_done(void *data) { static bool done = false; @@ -2340,8 +2265,6 @@ static void display_init(void *data) signal(SIGHUP, sig_hup); power_saving_func = default_saving_mode; - /* noti init for new input device like bt mouse */ - indev_list = NULL; /* load configutation */ ret = config_parse(DISPLAY_CONF_FILE, display_load_config, &display_conf); @@ -2349,8 +2272,6 @@ static void display_init(void *data) _W("Failed to load %s, %d Use default value!", DISPLAY_CONF_FILE, ret); - register_notifier(DEVICE_NOTIFIER_INPUT_ADD, input_device_add); - register_notifier(DEVICE_NOTIFIER_INPUT_REMOVE, input_device_remove); register_notifier(DEVICE_NOTIFIER_BOOTING_DONE, booting_done); register_notifier(DEVICE_NOTIFIER_HDMI, hdmi_changed); @@ -2364,8 +2285,8 @@ static void display_init(void *data) ret = init_sysfs(flags); break; case INIT_POLL: - _I("poll init"); - ret = init_pm_poll(poll_callback); + _I("input init"); + ret = init_input(poll_callback); break; case INIT_DBUS: _I("dbus init"); @@ -2442,15 +2363,11 @@ static void display_exit(void *data) exit_sysfs(); break; case INIT_POLL: - unregister_notifier(DEVICE_NOTIFIER_INPUT_ADD, - input_device_add); - unregister_notifier(DEVICE_NOTIFIER_INPUT_REMOVE, - input_device_remove); unregister_notifier(DEVICE_NOTIFIER_BOOTING_DONE, booting_done); unregister_notifier(DEVICE_NOTIFIER_HDMI, hdmi_changed); - exit_pm_poll(); + exit_input(); break; } } diff --git a/src/display/core.h b/src/display/core.h index 32d99ea..2629d6e 100644 --- a/src/display/core.h +++ b/src/display/core.h @@ -145,7 +145,7 @@ extern struct display_function_info display_info; struct display_keyfilter_ops { void (*init)(void); void (*exit)(void); - int (*check)(int, char[], int); + int (*check)(void *, int); void (*set_powerkey_ignore)(int); int (*powerkey_lcdoff)(void); void (*backlight_enable)(bool); diff --git a/src/display/input.c b/src/display/input.c new file mode 100644 index 0000000..28f4de3 --- /dev/null +++ b/src/display/input.c @@ -0,0 +1,213 @@ +/* + * deviced + * + * Copyright (c) 2015 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the License); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + +#include +#include +#include +#include +#include "util.h" +#include "core.h" +#include "poll.h" + +#define SEAT_NAME "seat0" + +static struct udev *udev; +static struct libinput *li; +static Ecore_Fd_Handler *efd; + +int (*pm_callback) (int, PMMsg *); + +static inline void process_event(struct libinput_event *ev) +{ + static const struct device_ops *display_device_ops; + struct input_event input; + struct libinput *li; + struct libinput_event_keyboard *k; + unsigned int time; + int fd; + + if (!pm_callback) + return; + + if (!display_device_ops) { + display_device_ops = find_device("display"); + if (!display_device_ops) + return; + } + + /* do not operate when display stops */ + if (device_get_status(display_device_ops) + != DEVICE_OPS_STATUS_START) { + _E("display status is stop"); + return; + } + + switch (libinput_event_get_type(ev)) { + case LIBINPUT_EVENT_KEYBOARD_KEY: + k = libinput_event_get_keyboard_event(ev); + time = libinput_event_keyboard_get_time(k); + li = libinput_event_get_context(ev); + + input.time.tv_sec = MSEC_TO_SEC(time); + input.time.tv_usec = MSEC_TO_USEC(time % 1000); + input.type = EV_KEY; + input.code = libinput_event_keyboard_get_key(k); + input.value = libinput_event_keyboard_get_key_state(k); + + fd = libinput_get_fd(li); + _D("time %d.%d type %d code %d value %d fd %d", + input.time.tv_sec, input.time.tv_usec, input.type, + input.code, input.value, fd); + + if (CHECK_OPS(keyfilter_ops, check) && + keyfilter_ops->check(&input, fd) != 0) + return; + break; + case LIBINPUT_EVENT_POINTER_MOTION: + case LIBINPUT_EVENT_POINTER_BUTTON: + case LIBINPUT_EVENT_POINTER_AXIS: + input.type = EV_REL; + if (CHECK_OPS(keyfilter_ops, check) && + keyfilter_ops->check(&input, fd) != 0) + return; + break; + case LIBINPUT_EVENT_TOUCH_DOWN: + case LIBINPUT_EVENT_TOUCH_UP: + case LIBINPUT_EVENT_TOUCH_MOTION: + case LIBINPUT_EVENT_TOUCH_FRAME: + break; + default: + break; + } + + /* lcd on or update lcd timeout */ + (*pm_callback) (INPUT_POLL_EVENT, NULL); +} + +static Eina_Bool input_handler(void *data, Ecore_Fd_Handler *fd_handler) +{ + struct libinput_event *ev; + struct libinput *li = (struct libinput *)data; + + if (!li) + return ECORE_CALLBACK_RENEW; + + libinput_dispatch(li); + + while ((ev = libinput_get_event(li))) { + process_event(ev); + + libinput_event_destroy(ev); + libinput_dispatch(li); + } + + return ECORE_CALLBACK_RENEW; +} + +static int open_restricted(const char *path, int flags, void *user_data) +{ + int fd; + unsigned int clockid = CLOCK_MONOTONIC; + + if (!path) + return -EINVAL; + + fd = open(path, flags); + if (fd >= 0) { + /* TODO Why does fd change the clock? */ + if (ioctl(fd, EVIOCSCLOCKID, &clockid) < 0) + _E("fail to change clock %s", path); + } + + return fd < 0 ? -errno : fd; +} + +static void close_restricted(int fd, void *user_data) +{ + close(fd); +} + +static const struct libinput_interface interface = { + .open_restricted = open_restricted, + .close_restricted = close_restricted, +}; + +int init_input(int (*callback)(int , PMMsg * )) +{ + int ret; + int fd; + + if (!callback) { + _E("invalid parameter : callback(NULL)"); + return -EINVAL; + } + + pm_callback = callback; + + udev = udev_new(); + if (!udev) { + _E("fail to create udev library context"); + return -EPERM; + } + + li = libinput_udev_create_context(&interface, NULL, udev); + if (!li) { + _E("fail to create a new libinput context from udev"); + return -EPERM; + } + + ret = libinput_udev_assign_seat(li, SEAT_NAME); + if (ret < 0) { + _E("fail to assign a seat"); + return -EPERM; + } + + fd = libinput_get_fd(li); + if (fd < 0) { + _E("fail to get file descriptor from libinput context"); + return -EPERM; + } + + /* add to poll handler */ + efd = ecore_main_fd_handler_add(fd, ECORE_FD_READ|ECORE_FD_ERROR, + input_handler, + (void *)((intptr_t)li), NULL, NULL); + if (!efd) { + _E("fail to add fd handler"); + /* TODO Does it really need close()? */ + close(fd); + return -EPERM; + } + + return 0; +} + +int exit_input(void) +{ + if (efd) + ecore_main_fd_handler_del(efd); + + if (li) + libinput_unref(li); + + if (udev) + udev_unref(udev); + + return 0; +} diff --git a/src/display/key-filter.c b/src/display/key-filter.c index ab3f48d..23573a1 100644 --- a/src/display/key-filter.c +++ b/src/display/key-filter.c @@ -21,10 +21,9 @@ #include #include #include - +#include #include #include - #include "util.h" #include "core.h" #include "poll.h" @@ -134,8 +133,8 @@ static void longkey_pressed() /* change state - LCD on */ recv_data.pid = getpid(); recv_data.cond = 0x100; - (*g_pm_callback)(PM_CONTROL_EVENT, &recv_data); - (*g_pm_callback)(INPUT_POLL_EVENT, NULL); + (*pm_callback)(PM_CONTROL_EVENT, &recv_data); + (*pm_callback)(INPUT_POLL_EVENT, NULL); } if (!display_has_caps(caps, DISPLAY_CAPA_LCDOFF)) { @@ -344,7 +343,7 @@ static int lcdoff_powerkey(void) update_lcdoff_source(VCONFKEY_PM_LCDOFF_BY_POWERKEY); recv_data.pid = getpid(); recv_data.cond = 0x400; - (*g_pm_callback)(PM_CONTROL_EVENT, &recv_data); + (*pm_callback)(PM_CONTROL_EVENT, &recv_data); } } else { ignore = false; @@ -469,7 +468,7 @@ static int process_screenlock_key(struct input_event *pinput) /* LCD off forcly */ recv_data.pid = -1; recv_data.cond = 0x400; - (*g_pm_callback)(PM_CONTROL_EVENT, &recv_data); + (*pm_callback)(PM_CONTROL_EVENT, &recv_data); } return true; @@ -599,8 +598,6 @@ static int check_key(struct input_event *pinput, int fd) if (current_state_in_on()) { process_hardkey_backlight(pinput); ignore = false; - } else if (!check_pre_install(fd)) { - ignore = false; } break; case KEY_VOLUMEUP: @@ -641,72 +638,70 @@ static int check_key(struct input_event *pinput, int fd) return ignore; } -static int check_key_filter(int length, char buf[], int fd) +static int check_key_filter(void *data, int fd) { - struct input_event *pinput; + struct input_event *pinput = data; int ignore = true; - int idx = 0; static int old_fd, code, value; - do { - pinput = (struct input_event *)&buf[idx]; - switch (pinput->type) { - case EV_KEY: - if (pinput->code == BTN_TOUCH && - pinput->value == KEY_RELEASED) - touch_pressed = false; - /* - * Normally, touch press/release events don't occur - * in lcd off state. But touch release events can occur - * in the state abnormally. Then touch events are ignored - * when lcd is off state. - */ - if (pinput->code == BTN_TOUCH && !current_state_in_on()) - break; - if (get_standby_state() && pinput->code != KEY_POWER) { - _D("standby mode,key ignored except powerkey"); - break; - } - if (pinput->code == code && pinput->value == value) { - _E("Same key(%d, %d) is polled [%d,%d]", - code, value, old_fd, fd); - } - old_fd = fd; - code = pinput->code; - value = pinput->value; + assert(pinput); + + switch (pinput->type) { + case EV_KEY: + if (pinput->code == BTN_TOUCH && + pinput->value == KEY_RELEASED) + touch_pressed = false; + /* + * Normally, touch press/release events don't occur + * in lcd off state. But touch release events can occur + * in the state abnormally. Then touch events are ignored + * when lcd is off state. + */ + if (pinput->code == BTN_TOUCH && !current_state_in_on()) + break; + if (get_standby_state() && pinput->code != KEY_POWER) { + _D("standby mode,key ignored except powerkey"); + break; + } + if (pinput->code == code && pinput->value == value) { + _E("Same key(%d, %d) is polled [%d,%d]", + code, value, old_fd, fd); + } + old_fd = fd; + code = pinput->code; + value = pinput->value; - ignore = check_key(pinput, fd); - restore_custom_brightness(); + ignore = check_key(pinput, fd); + restore_custom_brightness(); + break; + case EV_REL: + if (get_standby_state()) break; - case EV_REL: - if (get_standby_state()) - break; - ignore = false; - break; - case EV_ABS: - if (get_standby_state()) - break; - if (current_state_in_on()) - ignore = false; - restore_custom_brightness(); - - touch_pressed = - (pinput->value == TOUCH_RELEASE ? false : true); + ignore = false; + break; + case EV_ABS: + if (get_standby_state()) break; - case EV_SW: - if (!get_glove_state || !switch_glove_key) - break; - if (pinput->code == SW_GLOVE && - get_glove_state() == GLOVE_MODE) { - switch_glove_key(pinput->value); - } + if (current_state_in_on()) + ignore = false; + restore_custom_brightness(); + + touch_pressed = + (pinput->value == TOUCH_RELEASE ? false : true); + break; + case EV_SW: + if (!get_glove_state || !switch_glove_key) break; + if (pinput->code == SW_GLOVE && + get_glove_state() == GLOVE_MODE) { + switch_glove_key(pinput->value); } - idx += sizeof(struct input_event); - if (ignore == true && length <= idx) - return 1; - } while (length > idx); + break; + } + + if (ignore) + return 1; return 0; } diff --git a/src/display/poll.c b/src/display/poll.c index 2ea191b..9052d3c 100644 --- a/src/display/poll.c +++ b/src/display/poll.c @@ -19,27 +19,12 @@ /** * @file poll.c - * @brief Power Manager poll implementation (input devices & a domain socket file) + * @brief Power Manager poll implementation * - * This file includes the input device poll implementation. - * Default input devices are /dev/event0 and /dev/event1 - * User can use "PM_INPUT" for setting another input device poll in an environment file (/etc/profile). - * (ex: PM_INPUT=/dev/event0:/dev/event1:/dev/event5 ) */ #include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include +#include "core/device-handler.h" #include "util.h" #include "core.h" #include "poll.h" @@ -54,273 +39,6 @@ #define HOLDKEY_BLOCK_BIT (__HOLDKEY_BLOCK_BIT << LOCK_FLAG_SHIFT) #define STANDBY_MODE_BIT (__STANDBY_MODE_BIT << LOCK_FLAG_SHIFT) -#define DEV_PATH_DLM ":" - -PMMsg recv_data; -int (*g_pm_callback) (int, PMMsg *); - -#ifdef ENABLE_KEY_FILTER -extern int check_key_filter(int length, char buf[], int fd); -# define CHECK_KEY_FILTER(a, b, c) \ - do { \ - if (CHECK_OPS(keyfilter_ops, check) && \ - keyfilter_ops->check(a, b, c) != 0) \ - return EINA_TRUE;\ - } while (0); -#else -# define CHECK_KEY_FILTER(a, b, c) -#endif - -#define DEFAULT_DEV_PATH "/dev/event1:/dev/event0" - -static Eina_Bool pm_handler(void *data, Ecore_Fd_Handler *fd_handler) -{ - char buf[1024]; - struct sockaddr_un clientaddr; - int fd; - int ret; - static const struct device_ops *display_device_ops = NULL; - - if (!data) - return EINA_FALSE; - - FIND_DEVICE_INT(display_device_ops, "display"); - - if (device_get_status(display_device_ops) != DEVICE_OPS_STATUS_START) { - _E("display is not started!"); - return EINA_FALSE; - } - - if (g_pm_callback == NULL) { - return EINA_FALSE; - } - - /* A passed data is a fd type data, not a 64bit data. */ - fd = (int)((intptr_t)data); - ret = read(fd, buf, sizeof(buf)); - CHECK_KEY_FILTER(ret, buf, fd); - (*g_pm_callback) (INPUT_POLL_EVENT, NULL); - - return EINA_TRUE; -} - -int init_pm_poll(int (*pm_callback) (int, PMMsg *)) -{ - char *dev_paths, *path_tok, *pm_input_env, *save_ptr; - int dev_paths_size; - - Ecore_Fd_Handler *fd_handler; - int fd = -1; - indev *new_dev = NULL; - - g_pm_callback = pm_callback; - - _I("initialize pm poll - input devices(deviced)"); - - pm_input_env = getenv("PM_INPUT"); - if ((pm_input_env != NULL) && (strlen(pm_input_env) < 1024)) { - _I("Getting input device path from environment: %s", - pm_input_env); - /* Add 2 bytes for following strncat() */ - dev_paths_size = strlen(pm_input_env) + 2; - dev_paths = (char *)malloc(dev_paths_size); - if (!dev_paths) { - _E("Fail to malloc for dev path"); - return -ENOMEM; - } - snprintf(dev_paths, dev_paths_size, "%s", pm_input_env); - } else { - /* Add 2 bytes for following strncat() */ - dev_paths_size = strlen(DEFAULT_DEV_PATH) + 2; - dev_paths = (char *)malloc(dev_paths_size); - if (!dev_paths) { - _E("Fail to malloc for dev path"); - return -ENOMEM; - } - snprintf(dev_paths, dev_paths_size, "%s", DEFAULT_DEV_PATH); - } - - /* add the UNIX domain socket file path */ - strncat(dev_paths, DEV_PATH_DLM, strlen(DEV_PATH_DLM)); - - path_tok = strtok_r(dev_paths, DEV_PATH_DLM, &save_ptr); - if (path_tok == NULL) { - _E("Device Path Tokeninzing Failed"); - free(dev_paths); - return -1; - } - - do { - char *path, *new_path; - int len; - - fd = open(path_tok, O_RDONLY); - path = path_tok; - _I("pm_poll input device file: %s, fd: %d", path_tok, fd); - - if (fd == -1) { - _E("Cannot open the file: %s", path_tok); - goto out1; - } - - /* - * To pass a fd data through the fd hander infrastructure - * without memory allocation, a fd data becomes typecast - * to intptr_t and void *(64bit) type. - */ - fd_handler = ecore_main_fd_handler_add(fd, - ECORE_FD_READ|ECORE_FD_ERROR, - pm_handler, (void *)((intptr_t)fd), NULL, NULL); - if (fd_handler == NULL) { - _E("Failed ecore_main_handler_add() in init_pm_poll()"); - goto out2; - } - - new_dev = (indev *)malloc(sizeof(indev)); - - if (!new_dev) { - _E("Fail to malloc for new_dev %s", path); - goto out3; - } - - memset(new_dev, 0, sizeof(indev)); - - len = strlen(path) + 1; - new_path = (char*) malloc(len); - if (!new_path) { - _E("Fail to malloc for dev_path %s", path); - goto out4; - } - - strncpy(new_path, path, len); - new_dev->dev_path = new_path; - new_dev->fd = fd; - new_dev->dev_fd = fd_handler; - new_dev->pre_install = true; - indev_list = eina_list_append(indev_list, new_dev); - - } while ((path_tok = strtok_r(NULL, DEV_PATH_DLM, &save_ptr))); - - free(dev_paths); - return 0; - -out4: - free(new_dev); -out3: - ecore_main_fd_handler_del(fd_handler); -out2: - close(fd); -out1: - free(dev_paths); - - return -ENOMEM; -} - -int exit_pm_poll(void) -{ - Eina_List *l = NULL; - Eina_List *l_next = NULL; - indev *data = NULL; - - EINA_LIST_FOREACH_SAFE(indev_list, l, l_next, data) { - ecore_main_fd_handler_del(data->dev_fd); - close(data->fd); - free(data->dev_path); - free(data); - indev_list = eina_list_remove_list(indev_list, l); - } - - _I("pm_poll is finished"); - return 0; -} - -int init_pm_poll_input(int (*pm_callback)(int , PMMsg * ), const char *path) -{ - indev *new_dev = NULL; - indev *data = NULL; - Ecore_Fd_Handler *fd_handler = NULL; - Eina_List *l = NULL; - Eina_List *l_next = NULL; - int fd = -1; - char *dev_path = NULL; - - if (!pm_callback || !path) { - _E("argument is NULL! (%x,%x)", pm_callback, path); - return -1; - } - - EINA_LIST_FOREACH_SAFE(indev_list, l, l_next, data) - if(!strcmp(path, data->dev_path)) { - _E("%s is already polled!", path); - return -1; - } - - _I("initialize pm poll for bt %s", path); - - g_pm_callback = pm_callback; - - fd = open(path, O_RDONLY); - if (fd == -1) { - _E("Cannot open the file for BT: %s", path); - return -1; - } - - dev_path = (char*)malloc(strlen(path) + 1); - if (!dev_path) { - _E("Fail to malloc for dev_path"); - close(fd); - return -1; - } - strncpy(dev_path, path, strlen(path) +1); - - /* - * To pass a fd data through the fd hander infrastructure - * without memory allocation, a fd data becomes typecast - * to intptr_t and void *(64bit) type. - */ - fd_handler = ecore_main_fd_handler_add(fd, - ECORE_FD_READ|ECORE_FD_ERROR, - pm_handler, (void *)((intptr_t)fd), NULL, NULL); - if (!fd_handler) { - _E("Fail to ecore fd handler add! %s", path); - close(fd); - free(dev_path); - return -1; - } - - new_dev = (indev *)malloc(sizeof(indev)); - if (!new_dev) { - _E("Fail to malloc for new_dev %s", path); - ecore_main_fd_handler_del(fd_handler); - close(fd); - free(dev_path); - return -1; - } - new_dev->dev_path = dev_path; - new_dev->fd = fd; - new_dev->dev_fd = fd_handler; - new_dev->pre_install = false; - - _I("pm_poll for BT input device file(path: %s, fd: %d", - new_dev->dev_path, new_dev->fd); - indev_list = eina_list_append(indev_list, new_dev); - - return 0; -} - -int check_pre_install(int fd) -{ - indev *data = NULL; - Eina_List *l = NULL; - Eina_List *l_next = NULL; - - EINA_LIST_FOREACH_SAFE(indev_list, l, l_next, data) - if(fd == data->fd) { - return data->pre_install; - } - - return -ENODEV; -} int check_dimstay(int next_state, int flag) { @@ -338,7 +56,7 @@ int check_dimstay(int next_state, int flag) int pm_lock_internal(pid_t pid, int s_bits, int flag, int timeout) { - if (!g_pm_callback) + if (!pm_callback) return -1; switch (s_bits) { @@ -363,14 +81,14 @@ int pm_lock_internal(pid_t pid, int s_bits, int flag, int timeout) recv_data.cond = s_bits; recv_data.timeout = timeout; - (*g_pm_callback)(PM_CONTROL_EVENT, &recv_data); + (*pm_callback)(PM_CONTROL_EVENT, &recv_data); return 0; } int pm_unlock_internal(pid_t pid, int s_bits, int flag) { - if (!g_pm_callback) + if (!pm_callback) return -1; switch (s_bits) { @@ -388,14 +106,14 @@ int pm_unlock_internal(pid_t pid, int s_bits, int flag) recv_data.pid = pid; recv_data.cond = s_bits; - (*g_pm_callback)(PM_CONTROL_EVENT, &recv_data); + (*pm_callback)(PM_CONTROL_EVENT, &recv_data); return 0; } int pm_change_internal(pid_t pid, int s_bits) { - if (!g_pm_callback) + if (!pm_callback) return -1; switch (s_bits) { @@ -411,7 +129,7 @@ int pm_change_internal(pid_t pid, int s_bits) recv_data.pid = pid; recv_data.cond = s_bits << SHIFT_CHANGE_STATE; - (*g_pm_callback)(PM_CONTROL_EVENT, &recv_data); + (*pm_callback)(PM_CONTROL_EVENT, &recv_data); return 0; } diff --git a/src/display/poll.h b/src/display/poll.h index 48b7a46..de5aebf 100644 --- a/src/display/poll.h +++ b/src/display/poll.h @@ -21,10 +21,6 @@ * @file poll.h * @brief Power Manager input device poll implementation * - * This file includes the input device poll implementation. - * Default input devices are /dev/event0 and /dev/event1 - * User can use "PM_INPUT_DEV" for setting another input device poll in an environment file (/etc/profile). - * (ex: PM_INPUT_DEV=/dev/event0:/dev/event1:/dev/event5 ) */ #ifndef __PM_POLL_H__ @@ -103,21 +99,11 @@ typedef struct { unsigned int timeout2; } PMMsg; -typedef struct { - char *dev_path; - int fd; - Ecore_Fd_Handler *dev_fd; - int pre_install; -} indev; - -Eina_List *indev_list; - PMMsg recv_data; -int (*g_pm_callback) (int, PMMsg *); +int (*pm_callback) (int, PMMsg *); -extern int init_pm_poll(int (*pm_callback) (int, PMMsg *)); -extern int exit_pm_poll(); -extern int init_pm_poll_input(int (*pm_callback)(int , PMMsg * ), const char *path); +int init_input(int (*pm_callback) (int, PMMsg *)); +int exit_input(void); extern int pm_lock_internal(pid_t pid, int s_bits, int flag, int timeout); extern int pm_unlock_internal(pid_t pid, int s_bits, int flag);