From 508c57787d7b87587fe87aa28fa4530bbff4d775 Mon Sep 17 00:00:00 2001 From: Yunhee Seo Date: Sat, 27 May 2023 15:21:48 +0900 Subject: [PATCH] display: lock: Remove del_state_cond() In the plugins/display/core.c, del_state_cond/del_(normal/dim/off)_cond() was copied to all plugins. Actually, there is no need to create a function remove cond for each state. And, del_state_cond() is used to delete the registered pmlock. These are changes in this patch related to delete cond_head. 1. Remove del_state_cond() which was used as timeout callback funtion. 2. Remove update_lock_timer() which is not necessary. 3. del_state_cond() routine is added to add_node(). 4. Change add_node() to PmLockNode *display_lock_add_pmlock_node(enum state_t s_index, pid_t pid, bool holdkey_block, unsigned int timeout); Actually, add_callback function not needs pid, state params. Because PmLockNode already has that pid, state information and callback is added when the PmLockNode is created. Thus, add callback and pmlock_node handling routine is moved to display-lock. For reference assert statement, callback function is added under the conditions. 1. When the pmlock is created 2. When the existing pmlock is updated. Exisiting callback function is removed when the pmlock is updated or removed. Change-Id: Iace657049934e531a876be971dc42e6114620f7d Signed-off-by: Yunhee Seo --- plugins/iot-headed/display/core.c | 82 ++----------------------- plugins/mobile/display/core.c | 82 ++----------------------- plugins/tv/display/core.c | 82 ++----------------------- plugins/wearable/display/core.c | 85 ++------------------------ src/display/display-lock.c | 125 +++++++++++++++++++++++++++++--------- src/display/display-lock.h | 3 +- src/display/display-plugin.c | 10 --- src/display/display-plugin.h | 2 - 8 files changed, 121 insertions(+), 350 deletions(-) diff --git a/plugins/iot-headed/display/core.c b/plugins/iot-headed/display/core.c index d357f6e..66c0ad2 100644 --- a/plugins/iot-headed/display/core.c +++ b/plugins/iot-headed/display/core.c @@ -119,18 +119,14 @@ static int default_trans(int evt); static int default_action(int timeout); static int default_check(int curr, int next); -static gboolean del_normal_cond(void *data); -static gboolean del_dim_cond(void *data); -static gboolean del_off_cond(void *data); - static int default_proc_change_state(unsigned int cond, pid_t pid); static int (*proc_change_state)(unsigned int cond, pid_t pid) = default_proc_change_state; static struct state states[S_END] = { { S_START, "S_START", NULL, NULL, NULL, NULL }, - { S_NORMAL, "S_NORMAL", default_trans, default_action, default_check, del_normal_cond }, - { S_LCDDIM, "S_LCDDIM", default_trans, default_action, default_check, del_dim_cond }, - { S_LCDOFF, "S_LCDOFF", default_trans, default_action, default_check, del_off_cond }, + { S_NORMAL, "S_NORMAL", default_trans, default_action, default_check, NULL }, + { S_LCDDIM, "S_LCDDIM", default_trans, default_action, default_check, NULL }, + { S_LCDOFF, "S_LCDOFF", default_trans, default_action, default_check, NULL }, { S_STANDBY, "S_STANDBY", NULL, NULL, NULL, NULL }, { S_SLEEP, "S_SLEEP", default_trans, default_action, default_check, NULL }, { S_POWEROFF, "S_POWEROFF", NULL, NULL, NULL, NULL }, @@ -322,51 +318,6 @@ inline void lcd_off_procedure(enum device_flags flag) enter_doze(); } -static void del_state_cond(void *data, enum state_t state) -{ - PmLockNode *tmp = NULL; - pid_t pid; - - if (!data) - return; - - /* A passed data is a pid_t type data, not a 64bit data. */ - pid = (pid_t)((intptr_t)data); - _I("delete prohibit %s condition by timeout (%d)", states[state].name, pid); - - tmp = find_node(state, pid); - del_node(state, tmp); - set_unlock_time(pid, state); - - /* Change state only when the two conditions below are satisfied. - * 1. There should be no running state-transition timer - * 2. Released lock is one of the pm_cur_state's lock - * This emulates already expired transition timer */ - if (!display_state_transition_is_there_state_transition_timer() && (get_pm_cur_state() == state)) - states[get_pm_cur_state()].trans(EVENT_TIMEOUT); - - if (state == S_LCDOFF) - set_process_active(false, pid); -} - -static gboolean del_normal_cond(void *data) -{ - del_state_cond(data, S_NORMAL); - return G_SOURCE_REMOVE; -} - -static gboolean del_dim_cond(void *data) -{ - del_state_cond(data, S_LCDDIM); - return G_SOURCE_REMOVE; -} - -static gboolean del_off_cond(void *data) -{ - del_state_cond(data, S_LCDOFF); - return G_SOURCE_REMOVE; -} - /* get configurations from setting */ static int get_lcd_timeout_from_settings(void) { @@ -721,7 +672,6 @@ static int default_proc_change_state(unsigned int cond, pid_t pid) static void proc_condition_lock(PMMsg *data) { PmLockNode *tmp; - guint cond_timeout_id = 0; char pname[PATH_MAX]; pid_t pid = data->pid; enum state_t state; @@ -741,30 +691,11 @@ static void proc_condition_lock(PMMsg *data) (pm_get_power_lock() == POWER_UNLOCK)) proc_change_state(data->cond, INTERNAL_LOCK_PM); - if (data->timeout > 0) { - /* To pass a pid_t data through the timer infrastructure - * without memory allocation, a pid_t data becomes typecast - * to intptr_t and void *(64bit) type. */ - cond_timeout_id = g_timeout_add( - data->timeout, - states[state].timeout_cb, - (void*)((intptr_t)pid)); - if (!cond_timeout_id) - _E("Failed to register display timer."); - } - holdkey_block = GET_COND_FLAG(data->cond) & PM_FLAG_BLOCK_HOLDKEY; - - tmp = find_node(state, pid); + tmp = display_lock_add_pmlock_node(state, pid, holdkey_block, data->timeout); if (!tmp) { - tmp = add_node(state, pid, cond_timeout_id, holdkey_block); - if (!tmp) { - _E("Failed to acquire lock, state: %d, pid: %d.", state, pid); - return; - } - } else { - update_lock_timer(data, tmp, cond_timeout_id); - tmp->holdkey_block = holdkey_block; + _E("Failed to acquire lock, state: %d, pid: %d.", state, pid); + return; } if (state == S_LCDOFF) @@ -1596,7 +1527,6 @@ static int display_probe(void *data) dp->config = &display_conf; init_display_states(dp); setup_display_plugin_backlight_ops(dp); - dp->delete_state_cond = del_state_cond; dp->set_dim_state = set_dim_state; dp->get_device_flags = NULL; setup_display_plugin_backlight_ops(dp); diff --git a/plugins/mobile/display/core.c b/plugins/mobile/display/core.c index ebaa6a8..279b614 100644 --- a/plugins/mobile/display/core.c +++ b/plugins/mobile/display/core.c @@ -121,18 +121,14 @@ static int default_trans(int evt); static int default_action(int timeout); static int default_check(int curr, int next); -static gboolean del_normal_cond(void *data); -static gboolean del_dim_cond(void *data); -static gboolean del_off_cond(void *data); - static int default_proc_change_state(unsigned int cond, pid_t pid); static int (*proc_change_state)(unsigned int cond, pid_t pid) = default_proc_change_state; static struct state states[S_END] = { { S_START, "S_START", NULL, NULL, NULL, NULL }, - { S_NORMAL, "S_NORMAL", default_trans, default_action, default_check, del_normal_cond }, - { S_LCDDIM, "S_LCDDIM", default_trans, default_action, default_check, del_dim_cond }, - { S_LCDOFF, "S_LCDOFF", default_trans, default_action, default_check, del_off_cond }, + { S_NORMAL, "S_NORMAL", default_trans, default_action, default_check, NULL }, + { S_LCDDIM, "S_LCDDIM", default_trans, default_action, default_check, NULL }, + { S_LCDOFF, "S_LCDOFF", default_trans, default_action, default_check, NULL }, { S_STANDBY, "S_STANDBY", NULL, NULL, NULL, NULL }, { S_SLEEP, "S_SLEEP", default_trans, default_action, default_check, NULL }, { S_POWEROFF, "S_POWEROFF", NULL, NULL, NULL, NULL }, @@ -329,51 +325,6 @@ inline void lcd_off_procedure(enum device_flags flag) enter_doze(); } -static void del_state_cond(void *data, enum state_t state) -{ - PmLockNode *tmp = NULL; - pid_t pid; - - if (!data) - return; - - /* A passed data is a pid_t type data, not a 64bit data. */ - pid = (pid_t)((intptr_t)data); - _I("delete prohibit %s condition by timeout (%d)", states[state].name, pid); - - tmp = find_node(state, pid); - del_node(state, tmp); - set_unlock_time(pid, state); - - /* Change state only when the two conditions below are satisfied. - * 1. There should be no running state-transition timer - * 2. Released lock is one of the pm_cur_state's lock - * This emulates already expired transition timer */ - if (!display_state_transition_is_there_state_transition_timer() && (get_pm_cur_state() == state)) - states[get_pm_cur_state()].trans(EVENT_TIMEOUT); - - if (state == S_LCDOFF) - set_process_active(false, pid); -} - -static gboolean del_normal_cond(void *data) -{ - del_state_cond(data, S_NORMAL); - return G_SOURCE_REMOVE; -} - -static gboolean del_dim_cond(void *data) -{ - del_state_cond(data, S_LCDDIM); - return G_SOURCE_REMOVE; -} - -static gboolean del_off_cond(void *data) -{ - del_state_cond(data, S_LCDOFF); - return G_SOURCE_REMOVE; -} - /* get configurations from setting */ static int get_lcd_timeout_from_settings(void) { @@ -732,7 +683,6 @@ static int default_proc_change_state(unsigned int cond, pid_t pid) static void proc_condition_lock(PMMsg *data) { PmLockNode *tmp; - guint cond_timeout_id = 0; char pname[PATH_MAX]; pid_t pid = data->pid; enum state_t state; @@ -752,30 +702,11 @@ static void proc_condition_lock(PMMsg *data) (pm_get_power_lock() == POWER_UNLOCK)) proc_change_state(data->cond, INTERNAL_LOCK_PM); - if (data->timeout > 0) { - /* To pass a pid_t data through the timer infrastructure - * without memory allocation, a pid_t data becomes typecast - * to intptr_t and void *(64bit) type. */ - cond_timeout_id = g_timeout_add( - data->timeout, - states[state].timeout_cb, - (void*)((intptr_t)pid)); - if (!cond_timeout_id) - _E("Failed to register display timer."); - } - holdkey_block = GET_COND_FLAG(data->cond) & PM_FLAG_BLOCK_HOLDKEY; - - tmp = find_node(state, pid); + tmp = display_lock_add_pmlock_node(state, pid, holdkey_block, data->timeout); if (!tmp) { - tmp = add_node(state, pid, cond_timeout_id, holdkey_block); - if (!tmp) { - _E("Failed to acquire lock, state: %d, pid: %d.", state, pid); - return; - } - } else { - update_lock_timer(data, tmp, cond_timeout_id); - tmp->holdkey_block = holdkey_block; + _E("Failed to acquire lock, state: %d, pid: %d.", state, pid); + return; } if (state == S_LCDOFF) @@ -1606,7 +1537,6 @@ static int display_probe(void *data) dp->config = &display_conf; init_display_states(dp); setup_display_plugin_backlight_ops(dp); - dp->delete_state_cond = del_state_cond; dp->set_dim_state = set_dim_state; dp->get_device_flags = NULL; setup_display_plugin_backlight_ops(dp); diff --git a/plugins/tv/display/core.c b/plugins/tv/display/core.c index 7b5e98a..ca50f46 100644 --- a/plugins/tv/display/core.c +++ b/plugins/tv/display/core.c @@ -119,18 +119,14 @@ static int default_trans(int evt); static int default_action(int timeout); static int default_check(int curr, int next); -static gboolean del_normal_cond(void *data); -static gboolean del_dim_cond(void *data); -static gboolean del_off_cond(void *data); - static int default_proc_change_state(unsigned int cond, pid_t pid); static int (*proc_change_state)(unsigned int cond, pid_t pid) = default_proc_change_state; static struct state states[S_END] = { { S_START, "S_START", NULL, NULL, NULL, NULL }, - { S_NORMAL, "S_NORMAL", default_trans, default_action, default_check, del_normal_cond }, - { S_LCDDIM, "S_LCDDIM", default_trans, default_action, default_check, del_dim_cond }, - { S_LCDOFF, "S_LCDOFF", default_trans, default_action, default_check, del_off_cond }, + { S_NORMAL, "S_NORMAL", default_trans, default_action, default_check, NULL }, + { S_LCDDIM, "S_LCDDIM", default_trans, default_action, default_check, NULL }, + { S_LCDOFF, "S_LCDOFF", default_trans, default_action, default_check, NULL }, { S_STANDBY, "S_STANDBY", NULL, NULL, NULL, NULL }, { S_SLEEP, "S_SLEEP", default_trans, default_action, default_check, NULL }, { S_POWEROFF, "S_POWEROFF", NULL, NULL, NULL, NULL }, @@ -322,51 +318,6 @@ inline void lcd_off_procedure(enum device_flags flag) enter_doze(); } -static void del_state_cond(void *data, enum state_t state) -{ - PmLockNode *tmp = NULL; - pid_t pid; - - if (!data) - return; - - /* A passed data is a pid_t type data, not a 64bit data. */ - pid = (pid_t)((intptr_t)data); - _I("delete prohibit %s condition by timeout (%d)", states[state].name, pid); - - tmp = find_node(state, pid); - del_node(state, tmp); - set_unlock_time(pid, state); - - /* Change state only when the two conditions below are satisfied. - * 1. There should be no running state-transition timer - * 2. Released lock is one of the pm_cur_state's lock - * This emulates already expired transition timer */ - if (!display_state_transition_is_there_state_transition_timer() && (get_pm_cur_state() == state)) - states[get_pm_cur_state()].trans(EVENT_TIMEOUT); - - if (state == S_LCDOFF) - set_process_active(false, pid); -} - -static gboolean del_normal_cond(void *data) -{ - del_state_cond(data, S_NORMAL); - return G_SOURCE_REMOVE; -} - -static gboolean del_dim_cond(void *data) -{ - del_state_cond(data, S_LCDDIM); - return G_SOURCE_REMOVE; -} - -static gboolean del_off_cond(void *data) -{ - del_state_cond(data, S_LCDOFF); - return G_SOURCE_REMOVE; -} - /* get configurations from setting */ static int get_lcd_timeout_from_settings(void) { @@ -721,7 +672,6 @@ static int default_proc_change_state(unsigned int cond, pid_t pid) static void proc_condition_lock(PMMsg *data) { PmLockNode *tmp; - guint cond_timeout_id = 0; char pname[PATH_MAX]; pid_t pid = data->pid; enum state_t state; @@ -741,30 +691,11 @@ static void proc_condition_lock(PMMsg *data) (pm_get_power_lock() == POWER_UNLOCK)) proc_change_state(data->cond, INTERNAL_LOCK_PM); - if (data->timeout > 0) { - /* To pass a pid_t data through the timer infrastructure - * without memory allocation, a pid_t data becomes typecast - * to intptr_t and void *(64bit) type. */ - cond_timeout_id = g_timeout_add( - data->timeout, - states[state].timeout_cb, - (void*)((intptr_t)pid)); - if (!cond_timeout_id) - _E("Failed to register display timer."); - } - holdkey_block = GET_COND_FLAG(data->cond) & PM_FLAG_BLOCK_HOLDKEY; - - tmp = find_node(state, pid); + tmp = display_lock_add_pmlock_node(state, pid, holdkey_block, data->timeout); if (!tmp) { - tmp = add_node(state, pid, cond_timeout_id, holdkey_block); - if (!tmp) { - _E("Failed to acquire lock, state: %d, pid: %d.", state, pid); - return; - } - } else { - update_lock_timer(data, tmp, cond_timeout_id); - tmp->holdkey_block = holdkey_block; + _E("Failed to acquire lock, state: %d, pid: %d.", state, pid); + return; } if (state == S_LCDOFF) @@ -1597,7 +1528,6 @@ static int display_probe(void *data) dp->config = &display_conf; init_display_states(dp); setup_display_plugin_backlight_ops(dp); - dp->delete_state_cond = del_state_cond; dp->set_dim_state = set_dim_state; dp->get_device_flags = NULL; setup_display_plugin_backlight_ops(dp); diff --git a/plugins/wearable/display/core.c b/plugins/wearable/display/core.c index 4365feb..48ccc0d 100644 --- a/plugins/wearable/display/core.c +++ b/plugins/wearable/display/core.c @@ -133,18 +133,14 @@ static int default_trans(int evt); static int default_action(int timeout); static int default_check(int curr, int next); -static gboolean del_normal_cond(void *data); -static gboolean del_dim_cond(void *data); -static gboolean del_off_cond(void *data); - static int default_proc_change_state(unsigned int cond, pid_t pid); static int (*proc_change_state)(unsigned int cond, pid_t pid) = default_proc_change_state; static struct state states[S_END] = { { S_START, "S_START", NULL, NULL, NULL, NULL }, - { S_NORMAL, "S_NORMAL", default_trans, default_action, default_check, del_normal_cond }, - { S_LCDDIM, "S_LCDDIM", default_trans, default_action, default_check, del_dim_cond }, - { S_LCDOFF, "S_LCDOFF", default_trans, default_action, default_check, del_off_cond }, + { S_NORMAL, "S_NORMAL", default_trans, default_action, default_check, NULL }, + { S_LCDDIM, "S_LCDDIM", default_trans, default_action, default_check, NULL }, + { S_LCDOFF, "S_LCDOFF", default_trans, default_action, default_check, NULL }, { S_STANDBY, "S_STANDBY", NULL, NULL, NULL, NULL }, { S_SLEEP, "S_SLEEP", default_trans, default_action, default_check, NULL }, { S_POWEROFF, "S_POWEROFF", NULL, NULL, NULL, NULL }, @@ -616,54 +612,6 @@ inline void lcd_off_procedure(enum device_flags flag) enter_doze(); } -static void del_state_cond(void *data, enum state_t state) -{ - PmLockNode *tmp = NULL; - pid_t pid; - - if (!data) - return; - - /* A passed data is a pid_t type data, not a 64bit data. */ - pid = (pid_t)((intptr_t)data); - _I("delete prohibit %s condition by timeout (%d)", states[state].name, pid); - - if (pid == INTERNAL_LOCK_AMBIENT) - ambient_check_invalid_state(pid); - - tmp = find_node(state, pid); - del_node(state, tmp); - set_unlock_time(pid, state); - - /* Change state only when the two conditions below are satisfied. - * 1. There should be no running state-transition timer - * 2. Released lock is one of the pm_cur_state's lock - * This emulates already expired transition timer */ - if (!display_state_transition_is_there_state_transition_timer() && (get_pm_cur_state() == state)) - states[get_pm_cur_state()].trans(EVENT_TIMEOUT); - - if (state == S_LCDOFF) - set_process_active(false, pid); -} - -static gboolean del_normal_cond(void *data) -{ - del_state_cond(data, S_NORMAL); - return G_SOURCE_REMOVE; -} - -static gboolean del_dim_cond(void *data) -{ - del_state_cond(data, S_LCDDIM); - return G_SOURCE_REMOVE; -} - -static gboolean del_off_cond(void *data) -{ - del_state_cond(data, S_LCDOFF); - return G_SOURCE_REMOVE; -} - /* get configurations from setting */ static int get_lcd_timeout_from_settings(void) { @@ -1051,7 +999,6 @@ static int default_proc_change_state(unsigned int cond, pid_t pid) static void proc_condition_lock(PMMsg *data) { PmLockNode *tmp; - guint cond_timeout_id = 0; char pname[PATH_MAX]; pid_t pid = data->pid; enum state_t state; @@ -1071,30 +1018,11 @@ static void proc_condition_lock(PMMsg *data) (pm_get_power_lock() == POWER_UNLOCK)) proc_change_state(data->cond, INTERNAL_LOCK_PM); - if (data->timeout > 0) { - /* To pass a pid_t data through the timer infrastructure - * without memory allocation, a pid_t data becomes typecast - * to intptr_t and void *(64bit) type. */ - cond_timeout_id = g_timeout_add( - data->timeout, - states[state].timeout_cb, - (void*)((intptr_t)pid)); - if (!cond_timeout_id) - _E("Failed to register display timer."); - } - holdkey_block = GET_COND_FLAG(data->cond) & PM_FLAG_BLOCK_HOLDKEY; - - tmp = find_node(state, pid); + tmp = display_lock_add_pmlock_node(state, pid, holdkey_block, data->timeout); if (!tmp) { - tmp = add_node(state, pid, cond_timeout_id, holdkey_block); - if (!tmp) { - _E("Failed to acquire lock, state: %d, pid: %d.", state, pid); - return; - } - } else { - update_lock_timer(data, tmp, cond_timeout_id); - tmp->holdkey_block = holdkey_block; + _E("Failed to acquire lock, state: %d, pid: %d.", state, pid); + return; } if (state == S_LCDOFF) @@ -1963,7 +1891,6 @@ static int display_probe(void *data) dp->config = &display_conf; init_display_states(dp); setup_display_plugin_backlight_ops(dp); - dp->delete_state_cond = del_state_cond; dp->set_dim_state = set_dim_state; dp->get_device_flags = get_device_flags; setup_display_plugin_backlight_ops(dp); diff --git a/src/display/display-lock.c b/src/display/display-lock.c index d426283..d218a19 100644 --- a/src/display/display-lock.c +++ b/src/display/display-lock.c @@ -22,6 +22,7 @@ * */ #include "shared/common.h" +#include "ambient-mode.h" #include "device-interface.h" #include "poll.h" //#include "display.h" @@ -29,6 +30,7 @@ #include "lock-detector.h" #include "display-lock.h" #include "display-panel.h" +#include "display-plugin.h" #include "display-config.h" #include "display-state-transition.h" #include "shared/log-macro.h" @@ -244,14 +246,101 @@ PmLockNode *find_node(enum state_t s_index, pid_t pid) return NULL; } -PmLockNode *add_node(enum state_t s_index, pid_t pid, guint timeout_id, - bool holdkey_block) +/* FIXME: ambient call should handled later, to be removed or changed plugin interface way */ +static gboolean delete_state_cond_callback(void *data) +{ + if (!data) + return G_SOURCE_REMOVE; + + PmLockNode *tmp = (PmLockNode *)data; + const char *state_name = NULL; + pid_t pid; + enum state_t state = tmp->state; + + + /* A passed data is a pid_t type data, not a 64bit data. */ + pid = (pid_t)((intptr_t)tmp->pid); + display_plugin_state_get_name(state, &state_name); + _I("delete prohibit %s condition by timeout (%d)", state_name, pid); + + if (pid == INTERNAL_LOCK_AMBIENT) + ambient_check_invalid_state(pid); + + tmp = find_node(state, pid); + del_node(state, tmp); + set_unlock_time(pid, state); + + /* Change state only when the two conditions below are satisfied. + * 1. There should be no running state-transition timer + * 2. Released lock is one of the pm_cur_state's lock + * This emulates already expired transition timer */ + if (!display_state_transition_is_there_state_transition_timer() && (get_pm_cur_state() == state)) + display_plugin_state_do_default_trans(get_pm_cur_state(), EVENT_TIMEOUT); + + if (state == S_LCDOFF) + set_process_active(false, pid); + + return G_SOURCE_REMOVE; +} + +static void remove_pmlock_node_timeout_callback_id(PmLockNode *target_node) +{ + if (!target_node) + return; + + if (target_node->timeout_id) + g_source_remove(target_node->timeout_id); + target_node->timeout_id = 0; +} + +static int add_delete_state_cond_callback(unsigned int timeout, PmLockNode *target_node) +{ + if (!target_node) + return -EINVAL; + + if (target_node->state < S_NORMAL || target_node->state > S_LCDOFF) + return -EINVAL; + + if (timeout <= 0) { + remove_pmlock_node_timeout_callback_id(target_node); + return 0; + } + + assert(target_node->timeout_id == 0); + target_node->timeout_id = g_timeout_add(timeout, delete_state_cond_callback, (void*)target_node); + if (!(target_node->timeout_id)) + _W("Failed to register display timer"); + + return 0; +} + +static void handle_existing_pmlock_node(bool holdkey_block, unsigned int timeout, PmLockNode *found_node) +{ + time_t now; + + remove_pmlock_node_timeout_callback_id(found_node); + if (timeout > 0) + add_delete_state_cond_callback(timeout, found_node); + + time(&now); + found_node->time = now; + found_node->holdkey_block = holdkey_block; +} + +PmLockNode *display_lock_add_pmlock_node(enum state_t s_index, pid_t pid, bool holdkey_block, unsigned int timeout) { PmLockNode *n; + PmLockNode *found_node; time_t now; assert(g_display_plugin.config); + found_node = find_node(s_index, pid); + if (found_node) { + handle_existing_pmlock_node(holdkey_block, timeout, found_node); + return found_node; + } + n = (PmLockNode *) calloc(1, sizeof(PmLockNode)); if (n == NULL) { _E("Not enough memory, failed to alloc lock node."); @@ -261,7 +350,7 @@ PmLockNode *add_node(enum state_t s_index, pid_t pid, guint timeout_id, time(&now); n->state = s_index; n->pid = pid; - n->timeout_id = timeout_id; + add_delete_state_cond_callback(timeout, n); n->time = now; n->holdkey_block = holdkey_block; /* LCDOFF lock should be maintained regardless of fg/bg state */ @@ -302,10 +391,8 @@ int del_node(enum state_t s_index, PmLockNode *n) SYS_G_LIST_REMOVE(cond_head[s_index], n); /* delete timer */ - if (n->timeout_id) { - g_source_remove(n->timeout_id); - n->timeout_id = 0; - } + remove_pmlock_node_timeout_callback_id(n); + if (n->warning_id) { g_source_remove(n->warning_id); n->warning_id = 0; @@ -383,10 +470,7 @@ int delete_condition(enum state_t state) return 0; SYS_G_LIST_FOREACH_SAFE(cond_head[state], elem, next, t) { - if (t->timeout_id > 0) { - g_source_remove(t->timeout_id); - t->timeout_id = 0; - } + remove_pmlock_node_timeout_callback_id(t); if (state == S_LCDOFF) set_process_active(false, t->pid); _I("delete node of pid(%d)", t->pid); @@ -557,22 +641,6 @@ int display_app_terminated(void *data) return 0; } -/* update transition condition for application requrements */ -void update_lock_timer(PMMsg *data, - PmLockNode *node, guint timeout_id) -{ - time_t now; - - if (data->timeout > 0) { - time(&now); - node->time = now; - } - - if (node->timeout_id) - g_source_remove(node->timeout_id); - node->timeout_id = timeout_id; -} - int display_lock_set_custom_holdkey_block(bool blocked) { custom_holdkey_block = blocked; @@ -586,5 +654,4 @@ int display_lock_get_custom_holdkey_block(bool *blocked) *blocked = custom_holdkey_block; return 0; -} - +} \ No newline at end of file diff --git a/src/display/display-lock.h b/src/display/display-lock.h index 22d3063..30e8006 100644 --- a/src/display/display-lock.h +++ b/src/display/display-lock.h @@ -56,7 +56,7 @@ bool check_lock_state(int state); bool pmlock_get_lock_state(enum state_t state); enum state_t power_lock_type_to_pmlock(power_lock_e power_lock_type); PmLockNode *find_node(enum state_t s_index, pid_t pid); -PmLockNode *add_node(enum state_t s_index, pid_t pid, guint timeout_id, bool holdkey_block); +PmLockNode *display_lock_add_pmlock_node(enum state_t s_index, pid_t pid, bool holdkey_block, unsigned int timeout); int del_node(enum state_t s_index, PmLockNode *n); int check_lock_condition(enum state_t state); int check_holdkey_block(enum state_t state); @@ -69,7 +69,6 @@ GList *get_cond_head(enum state_t s_index); int display_app_background(void *data); int display_app_foreground(void *data); int display_app_terminated(void *data); -void update_lock_timer(PMMsg *data, PmLockNode *node, guint timeout_id); int display_lock_set_custom_holdkey_block(bool blocked); int display_lock_get_custom_holdkey_block(bool *blocked); diff --git a/src/display/display-plugin.c b/src/display/display-plugin.c index 4561f79..bbbb0da 100644 --- a/src/display/display-plugin.c +++ b/src/display/display-plugin.c @@ -174,16 +174,6 @@ int display_plugin_state_do_default_check(enum state_t state, int curr, int next return -EOPNOTSUPP; } -int display_plugin_state_delete_state_cond(void *data, enum state_t s_state) -{ - if (g_display_plugin.delete_state_cond) { - g_display_plugin.delete_state_cond(data, s_state); - return 0; - } - - return -EOPNOTSUPP; -} - int display_plugin_state_get_name(enum state_t state, const char **state_name) { if (!state_name) diff --git a/src/display/display-plugin.h b/src/display/display-plugin.h index ff18ecd..5f61b75 100644 --- a/src/display/display-plugin.h +++ b/src/display/display-plugin.h @@ -65,7 +65,6 @@ struct display_plugin { const char* (*device_flags_to_string) (enum device_flags flags); int (*auto_brightness_control) (enum brightness_request_e request, int set_brightness); /* FIXME: function names will be redefined */ - void (*delete_state_cond) (void *data, enum state_t s_state); void (*set_dim_state) (bool on); int (*get_device_flags) (unsigned long *device_flags); @@ -99,7 +98,6 @@ int display_plugin_state_do_default_trans(enum state_t state, int evt); bool display_plugin_state_is_there_default_trans(enum state_t state); int display_plugin_state_do_default_action(enum state_t state, int timeout); int display_plugin_state_do_default_check(enum state_t state, int curr, int next); -int display_plugin_state_delete_state_cond(void *data, enum state_t s_state); int display_plugin_state_get_name(enum state_t state, const char **state_name); int display_plugin_state_set_timeout(enum state_t state, int state_timeout); int display_plugin_state_get_timeout(enum state_t state, int *state_timeout); -- 2.7.4