display: Relocate proc_condition_funcs() 01/294801/5
authorYunhee Seo <yuni.seo@samsung.com>
Mon, 26 Jun 2023 07:15:28 +0000 (16:15 +0900)
committerYunhee Seo <yuni.seo@samsung.com>
Thu, 29 Jun 2023 04:56:37 +0000 (13:56 +0900)
There are three functions to get display lock, unlock, state transition by external request.
proc_condition_lock()/proc_condition_unlock()/proc_condition()
Those functions rules are all the same, so they are relocated.

This function is added to display-lock.
- int display_lock_proc_condition(PMMsg *data);

Change-Id: I10dc0f14d3e7b2bc52a0c11fb1e256c986191eec
Signed-off-by: Yunhee Seo <yuni.seo@samsung.com>
plugins/iot-headed/display/core.c
plugins/mobile/display/core.c
plugins/tv/display/core.c
plugins/wearable/display/core.c
src/display/display-lock.c
src/display/display-lock.h

index c407545..65ac690 100644 (file)
@@ -162,149 +162,6 @@ static const char* __device_flags_to_string(enum device_flags flags)
                return UNKNOWN_STR;
 }
 
-static void proc_condition_lock(PMMsg *data)
-{
-       char pname[PATH_MAX];
-       pid_t pid = data->pid;
-       enum state_t state;
-       int ret;
-       bool value = true;
-       unsigned int flags;
-       const char *lock_type = NULL;
-
-       state = GET_COND_STATE(data->cond);
-       if (state == S_START)
-               return;
-
-       flags = GET_COND_FLAG(data->cond);
-       display_misc_get_process_name(pid, pname);
-
-       if ((state == S_LCDOFF) && (get_pm_cur_state() == S_SLEEP) &&
-           (pm_get_power_lock() == POWER_UNLOCK))
-               display_state_transition_do_proc_change_state(data->cond, INTERNAL_LOCK_PM);
-
-       ret = display_lock_request_lock(state, pid, data->timeout);
-       if (ret == -EALREADY)
-               ret = display_lock_update_lock(state, pid, data->timeout);
-
-       if (ret != 0) {
-               _E("Failed to acquire lock, state: %d, pid: %d.", state, pid);
-               return;
-       }
-
-       if (state == S_LCDOFF)
-               set_process_active(true, pid);
-
-       _I("[%s] locked by %5d with %u ms", states[state].name, pid, data->timeout);
-
-       if (pid < INTERNAL_LOCK_BASE) {
-               /* for debug */
-               if (state == S_LCDOFF)
-                       lock_type = PM_LCDOFF_STR;
-               else if (state == S_LCDDIM)
-                       lock_type = PM_LCDDIM_STR;
-               else if (state == S_NORMAL)
-                       lock_type = PM_LCDON_STR;
-
-               if (lock_type) {
-                       /* power lock signal */
-                       ret = gdbus_signal_emit(NULL,
-                                       DEVICED_PATH_DISPLAY,
-                                       DEVICED_INTERFACE_DISPLAY,
-                                       "PowerLock",
-                                       g_variant_new("(sii)", lock_type, pid, (int)data->timeout));
-                       if (ret < 0)
-                               _E("Failed to send dbus signal PowerLock.");
-               }
-       }
-
-       _SD("be requested LOCK info pname(%s), flags(%d)",
-           pname, flags);
-       set_lock_time(pid, pname, state);
-
-       device_notify(DEVICE_NOTIFIER_DISPLAY_LOCK, (void *)&value);
-}
-
-static void proc_condition_unlock(PMMsg *data)
-{
-       pid_t pid = data->pid;
-       enum state_t state;
-       char pname[PATH_MAX];
-       bool value = false;
-       unsigned int flags;
-       int ret;
-       const char *lock_type = NULL;
-
-       state = GET_COND_STATE(data->cond);
-       if (!state)
-               return;
-
-       flags = GET_COND_FLAG(data->cond);
-       display_misc_get_process_name(pid, pname);
-
-       display_lock_release_lock(state, pid);
-
-       if (state == S_LCDOFF)
-               set_process_active(false, pid);
-
-       _I("[%s] unlocked by %5d", states[state].name, pid);
-
-       if (pid < INTERNAL_LOCK_BASE) {
-               /* for debug */
-               if (state == S_LCDOFF)
-                       lock_type = PM_LCDOFF_STR;
-               else if (state == S_LCDDIM)
-                       lock_type = PM_LCDDIM_STR;
-               else if (state == S_NORMAL)
-                       lock_type = PM_LCDON_STR;
-
-               if (lock_type) {
-                       /* power unlock signal */
-                       ret = gdbus_signal_emit(NULL,
-                                       DEVICED_PATH_DISPLAY,
-                                       DEVICED_INTERFACE_DISPLAY,
-                                       "PowerUnlock",
-                                       g_variant_new("(sii)", lock_type, pid, (int)data->timeout));
-                       if (ret < 0)
-                               _E("Failed to send dbus signal PowerUnlock.");
-               }
-       }
-
-       _SD("be requested UNLOCK info pname(%s) flag(%d)", pname, flags);
-       set_unlock_time(pid, state);
-
-       device_notify(DEVICE_NOTIFIER_DISPLAY_LOCK, (void *)&value);
-}
-
-static int proc_condition(PMMsg *data)
-{
-       unsigned int flags;
-
-       if (IS_COND_REQUEST_LOCK(data->cond))
-               proc_condition_lock(data);
-
-       if (IS_COND_REQUEST_UNLOCK(data->cond))
-               proc_condition_unlock(data);
-
-       if (!display_conf.timeout_enable)
-               return 0;
-
-       flags = GET_COND_FLAG(data->cond);
-       if (flags == 0) {
-               /* guard time for suspend */
-               if (get_pm_cur_state() == S_LCDOFF)
-                       display_state_transition_reset_state_transition_timeout(states[S_LCDOFF].timeout);
-       } else {
-               if (flags & PM_FLAG_RESET_TIMER)
-                       display_state_transition_reset_state_transition_timeout(states[get_pm_cur_state()].timeout);
-       }
-
-       if (!display_state_transition_is_there_state_transition_timer())
-               display_state_transition_do_state_transition(get_pm_cur_state(), EVENT_TIMEOUT);
-
-       return 0;
-}
-
 /* SIGHUP signal handler
  * For debug... print info to syslog
  */
@@ -339,7 +196,7 @@ int poll_callback(int condition, PMMsg *data)
        }
 
        if (condition == PM_CONTROL_EVENT) {
-               proc_condition(data);
+               display_lock_proc_condition(data);
 
                if (IS_COND_REQUEST_CHANGE(data->cond))
                        display_state_transition_do_proc_change_state(data->cond, data->pid);
index ea1349b..3fdf1f6 100644 (file)
@@ -220,148 +220,6 @@ static int default_proc_change_state(unsigned int cond, pid_t pid)
        return 0;
 }
 
-static void proc_condition_lock(PMMsg *data)
-{
-       char pname[PATH_MAX];
-       pid_t pid = data->pid;
-       enum state_t state;
-       int ret;
-       bool value = true;
-       unsigned int flags;
-       const char *lock_type = NULL;
-
-       state = GET_COND_STATE(data->cond);
-       if (state == S_START)
-               return;
-
-       flags = GET_COND_FLAG(data->cond);
-       display_misc_get_process_name(pid, pname);
-
-       if ((state == S_LCDOFF) && (get_pm_cur_state() == S_SLEEP) &&
-           (pm_get_power_lock() == POWER_UNLOCK))
-               display_state_transition_do_proc_change_state(data->cond, INTERNAL_LOCK_PM);
-
-       ret = display_lock_request_lock(state, pid, data->timeout);
-       if (ret == -EALREADY)
-               ret = display_lock_update_lock(state, pid, data->timeout);
-
-       if (ret != 0) {
-               _E("Failed to acquire lock, state: %d, pid: %d.", state, pid);
-               return;
-       }
-
-       if (state == S_LCDOFF)
-               set_process_active(true, pid);
-
-       _I("[%s] locked by %5d with %u ms", states[state].name, pid, data->timeout);
-
-       if (pid < INTERNAL_LOCK_BASE) {
-               /* for debug */
-               if (state == S_LCDOFF)
-                       lock_type = PM_LCDOFF_STR;
-               else if (state == S_LCDDIM)
-                       lock_type = PM_LCDDIM_STR;
-               else if (state == S_NORMAL)
-                       lock_type = PM_LCDON_STR;
-
-               if (lock_type) {
-                       /* power lock signal */
-                       ret = gdbus_signal_emit(NULL,
-                                       DEVICED_PATH_DISPLAY,
-                                       DEVICED_INTERFACE_DISPLAY,
-                                       "PowerLock",
-                                       g_variant_new("(sii)", lock_type, pid, (int)data->timeout));
-                       if (ret < 0)
-                               _E("Failed to send dbus signal PowerLock.");
-               }
-       }
-       _SD("be requested LOCK info pname(%s), flags(%d)",
-           pname, flags);
-       set_lock_time(pid, pname, state);
-
-       device_notify(DEVICE_NOTIFIER_DISPLAY_LOCK, (void *)&value);
-}
-
-static void proc_condition_unlock(PMMsg *data)
-{
-       pid_t pid = data->pid;
-       enum state_t state;
-       char pname[PATH_MAX];
-       bool value = false;
-       unsigned int flags;
-       int ret;
-       const char *lock_type = NULL;
-
-       state = GET_COND_STATE(data->cond);
-       if (!state)
-               return;
-
-       flags = GET_COND_FLAG(data->cond);
-       display_misc_get_process_name(pid, pname);
-
-       display_lock_release_lock(state, pid);
-
-       if (state == S_LCDOFF)
-               set_process_active(false, pid);
-
-       _I("[%s] unlocked by %5d", states[state].name, pid);
-
-       if (pid < INTERNAL_LOCK_BASE) {
-               /* for debug */
-               if (state == S_LCDOFF)
-                       lock_type =  PM_LCDOFF_STR;
-               else if (state == S_LCDDIM)
-                       lock_type = PM_LCDDIM_STR;
-               else if (state == S_NORMAL)
-                       lock_type = PM_LCDON_STR;
-
-               if (lock_type) {
-                       /* power unlock signal */
-                       ret = gdbus_signal_emit(NULL,
-                                       DEVICED_PATH_DISPLAY,
-                                       DEVICED_INTERFACE_DISPLAY,
-                                       "PowerUnlock",
-                                       g_variant_new("(sii)", lock_type, pid, (int)data->timeout));
-                       if (ret < 0)
-                               _E("Failed to send dbus signal PowerUnlock.");
-               }
-       }
-
-       _SD("be requested UNLOCK info pname(%s) flag(%d)", pname, flags);
-       set_unlock_time(pid, state);
-
-       device_notify(DEVICE_NOTIFIER_DISPLAY_LOCK, (void *)&value);
-}
-
-static int proc_condition(PMMsg *data)
-{
-       unsigned int flags;
-
-       if (IS_COND_REQUEST_LOCK(data->cond))
-               proc_condition_lock(data);
-
-       if (IS_COND_REQUEST_UNLOCK(data->cond))
-               proc_condition_unlock(data);
-
-       if (!display_conf.timeout_enable)
-               return 0;
-
-       flags = GET_COND_FLAG(data->cond);
-       if (flags == 0) {
-               /* guard time for suspend */
-               if (get_pm_cur_state() == S_LCDOFF)
-                       display_state_transition_reset_state_transition_timeout(states[S_LCDOFF].timeout);
-       } else {
-               if (flags & PM_FLAG_RESET_TIMER)
-                       display_state_transition_reset_state_transition_timeout(states[get_pm_cur_state()].timeout);
-       }
-
-       if (!display_state_transition_is_there_state_transition_timer())
-               display_state_transition_do_state_transition(get_pm_cur_state(), EVENT_TIMEOUT);
-
-       return 0;
-}
-
 /* SIGHUP signal handler
  * For debug... print info to syslog
  */
@@ -396,7 +254,7 @@ int poll_callback(int condition, PMMsg *data)
        }
 
        if (condition == PM_CONTROL_EVENT) {
-               proc_condition(data);
+               display_lock_proc_condition(data);
 
                if (IS_COND_REQUEST_CHANGE(data->cond))
                        display_state_transition_do_proc_change_state(data->cond, data->pid);
index 6609df9..eb0d2c5 100644 (file)
@@ -162,149 +162,6 @@ static const char* __device_flags_to_string(enum device_flags flags)
                return UNKNOWN_STR;
 }
 
-static void proc_condition_lock(PMMsg *data)
-{
-       char pname[PATH_MAX];
-       pid_t pid = data->pid;
-       enum state_t state;
-       int ret;
-       bool value = true;
-       unsigned int flags;
-       const char *lock_type = NULL;
-
-       state = GET_COND_STATE(data->cond);
-       if (state == S_START)
-               return;
-
-       flags = GET_COND_FLAG(data->cond);
-       display_misc_get_process_name(pid, pname);
-
-       if ((state == S_LCDOFF) && (get_pm_cur_state() == S_SLEEP) &&
-           (pm_get_power_lock() == POWER_UNLOCK))
-               display_state_transition_do_proc_change_state(data->cond, INTERNAL_LOCK_PM);
-
-       ret = display_lock_request_lock(state, pid, data->timeout);
-       if (ret == -EALREADY)
-               ret = display_lock_update_lock(state, pid, data->timeout);
-
-       if (ret != 0) {
-               _E("Failed to acquire lock, state: %d, pid: %d.", state, pid);
-               return;
-       }
-
-       if (state == S_LCDOFF)
-               set_process_active(true, pid);
-
-       _I("[%s] locked by %5d with %u ms", states[state].name, pid, data->timeout);
-
-       if (pid < INTERNAL_LOCK_BASE) {
-               /* for debug */
-               if (state == S_LCDOFF)
-                       lock_type = PM_LCDOFF_STR;
-               else if (state == S_LCDDIM)
-                       lock_type = PM_LCDDIM_STR;
-               else if (state == S_NORMAL)
-                       lock_type = PM_LCDON_STR;
-
-               if (lock_type) {
-                       /* power lock signal */
-                       ret = gdbus_signal_emit(NULL,
-                                       DEVICED_PATH_DISPLAY,
-                                       DEVICED_INTERFACE_DISPLAY,
-                                       "PowerLock",
-                                       g_variant_new("(sii)", lock_type, pid, (int)data->timeout));
-                       if (ret < 0)
-                               _E("Failed to send dbus signal PowerLock.");
-               }
-       }
-
-       _SD("be requested LOCK info pname(%s), flags(%d)",
-           pname, flags);
-       set_lock_time(pid, pname, state);
-
-       device_notify(DEVICE_NOTIFIER_DISPLAY_LOCK, (void *)&value);
-}
-
-static void proc_condition_unlock(PMMsg *data)
-{
-       pid_t pid = data->pid;
-       enum state_t state;
-       char pname[PATH_MAX];
-       bool value = false;
-       unsigned int flags;
-       int ret;
-       const char *lock_type = NULL;
-
-       state = GET_COND_STATE(data->cond);
-       if (!state)
-               return;
-
-       flags = GET_COND_FLAG(data->cond);
-       display_misc_get_process_name(pid, pname);
-
-       display_lock_release_lock(state, pid);
-
-       if (state == S_LCDOFF)
-               set_process_active(false, pid);
-
-       _I("[%s] unlocked by %5d", states[state].name, pid);
-
-       if (pid < INTERNAL_LOCK_BASE) {
-               /* for debug */
-               if (state == S_LCDOFF)
-                       lock_type = PM_LCDOFF_STR;
-               else if (state == S_LCDDIM)
-                       lock_type = PM_LCDDIM_STR;
-               else if (state == S_NORMAL)
-                       lock_type = PM_LCDON_STR;
-
-               if (lock_type) {
-                       /* power unlock signal */
-                       ret = gdbus_signal_emit(NULL,
-                                       DEVICED_PATH_DISPLAY,
-                                       DEVICED_INTERFACE_DISPLAY,
-                                       "PowerUnlock",
-                                       g_variant_new("(sii)", lock_type, pid, (int)data->timeout));
-                       if (ret < 0)
-                               _E("Failed to send dbus signal PowerUnlock.");
-               }
-       }
-
-       _SD("be requested UNLOCK info pname(%s) flag(%d)", pname, flags);
-       set_unlock_time(pid, state);
-
-       device_notify(DEVICE_NOTIFIER_DISPLAY_LOCK, (void *)&value);
-}
-
-static int proc_condition(PMMsg *data)
-{
-       unsigned int flags;
-
-       if (IS_COND_REQUEST_LOCK(data->cond))
-               proc_condition_lock(data);
-
-       if (IS_COND_REQUEST_UNLOCK(data->cond))
-               proc_condition_unlock(data);
-
-       if (!display_conf.timeout_enable)
-               return 0;
-
-       flags = GET_COND_FLAG(data->cond);
-       if (flags == 0) {
-               /* guard time for suspend */
-               if (get_pm_cur_state() == S_LCDOFF)
-                       display_state_transition_reset_state_transition_timeout(states[S_LCDOFF].timeout);
-       } else {
-               if (flags & PM_FLAG_RESET_TIMER)
-                       display_state_transition_reset_state_transition_timeout(states[get_pm_cur_state()].timeout);
-       }
-
-       if (!display_state_transition_is_there_state_transition_timer())
-               display_state_transition_do_state_transition(get_pm_cur_state(), EVENT_TIMEOUT);
-
-       return 0;
-}
-
 /* SIGHUP signal handler
  * For debug... print info to syslog
  */
@@ -339,7 +196,7 @@ int poll_callback(int condition, PMMsg *data)
        }
 
        if (condition == PM_CONTROL_EVENT) {
-               proc_condition(data);
+               display_lock_proc_condition(data);
 
                if (IS_COND_REQUEST_CHANGE(data->cond))
                        display_state_transition_do_proc_change_state(data->cond, data->pid);
index 2f4d3f0..7ebd0c6 100644 (file)
@@ -628,149 +628,6 @@ static int default_proc_change_state(unsigned int cond, pid_t pid)
        return 0;
 }
 
-static void proc_condition_lock(PMMsg *data)
-{
-       char pname[PATH_MAX];
-       pid_t pid = data->pid;
-       enum state_t state;
-       int ret;
-       bool value = true;
-       unsigned int flags;
-       const char *lock_type = NULL;
-
-       state = GET_COND_STATE(data->cond);
-       if (state == S_START)
-               return;
-
-       flags = GET_COND_FLAG(data->cond);
-       display_misc_get_process_name(pid, pname);
-
-       if ((state == S_LCDOFF) && (get_pm_cur_state() == S_SLEEP) &&
-           (pm_get_power_lock() == POWER_UNLOCK))
-               display_state_transition_do_proc_change_state(data->cond, INTERNAL_LOCK_PM);
-
-       ret = display_lock_request_lock(state, pid, data->timeout);
-       if (ret == -EALREADY)
-               ret = display_lock_update_lock(state, pid, data->timeout);
-
-       if (ret != 0) {
-               _E("Failed to acquire lock, state: %d, pid: %d.", state, pid);
-               return;
-       }
-
-       if (state == S_LCDOFF)
-               set_process_active(true, pid);
-
-       _I("[%s] locked by %5d with %u ms", states[state].name, pid, data->timeout);
-
-       if (pid < INTERNAL_LOCK_BASE) {
-               /* for debug */
-               if (state == S_LCDOFF)
-                       lock_type = PM_LCDOFF_STR;
-               else if (state == S_LCDDIM)
-                       lock_type = PM_LCDDIM_STR;
-               else if (state == S_NORMAL)
-                       lock_type = PM_LCDON_STR;
-
-               if (lock_type) {
-                       /* power lock signal */
-                       ret = gdbus_signal_emit(NULL,
-                                       DEVICED_PATH_DISPLAY,
-                                       DEVICED_INTERFACE_DISPLAY,
-                                       "PowerLock",
-                                       g_variant_new("(sii)", lock_type, pid, (int)data->timeout));
-                       if (ret < 0)
-                               _E("Failed to send dbus signal PowerLock.");
-               }
-       }
-
-       _SD("be requested LOCK info pname(%s), flags(%d)",
-               pname, flags);
-       set_lock_time(pid, pname, state);
-
-       device_notify(DEVICE_NOTIFIER_DISPLAY_LOCK, (void *)&value);
-}
-
-static void proc_condition_unlock(PMMsg *data)
-{
-       pid_t pid = data->pid;
-       enum state_t state;
-       char pname[PATH_MAX];
-       bool value = false;
-       unsigned int flags;
-       int ret;
-       const char *lock_type = NULL;
-
-       state = GET_COND_STATE(data->cond);
-       if (!state)
-               return;
-
-       flags = GET_COND_FLAG(data->cond);
-       display_misc_get_process_name(pid, pname);
-
-       display_lock_release_lock(state, pid);
-
-       if (state == S_LCDOFF)
-               set_process_active(false, pid);
-
-       _I("[%s] unlocked by %5d", states[state].name, pid);
-
-       if (pid < INTERNAL_LOCK_BASE) {
-               /* for debug */
-               if (state == S_LCDOFF)
-                       lock_type = PM_LCDOFF_STR;
-               else if (state == S_LCDDIM)
-                       lock_type =  PM_LCDDIM_STR;
-               else if (state == S_NORMAL)
-                       lock_type = PM_LCDON_STR;
-
-               if (lock_type) {
-                       /* power unlock signal */
-                       ret = gdbus_signal_emit(NULL,
-                                       DEVICED_PATH_DISPLAY,
-                                       DEVICED_INTERFACE_DISPLAY,
-                                       "PowerUnlock",
-                                       g_variant_new("(sii)", lock_type, pid, (int)data->timeout));
-                       if (ret < 0)
-                               _E("Failed to send dbus signal PowerUnlock.");
-               }
-       }
-
-       _SD("be requested UNLOCK info pname(%s) flag(%d)", pname, flags);
-       set_unlock_time(pid, state);
-
-       device_notify(DEVICE_NOTIFIER_DISPLAY_LOCK, (void *)&value);
-}
-
-static int proc_condition(PMMsg *data)
-{
-       unsigned int flags;
-
-       if (IS_COND_REQUEST_LOCK(data->cond))
-               proc_condition_lock(data);
-
-       if (IS_COND_REQUEST_UNLOCK(data->cond))
-               proc_condition_unlock(data);
-
-       if (!display_conf.timeout_enable)
-               return 0;
-
-       flags = GET_COND_FLAG(data->cond);
-       if (flags == 0) {
-               /* guard time for suspend */
-               if (get_pm_cur_state() == S_LCDOFF)
-                       display_state_transition_reset_state_transition_timeout(states[S_LCDOFF].timeout);
-       } else {
-               if (flags & PM_FLAG_RESET_TIMER)
-                       display_state_transition_reset_state_transition_timeout(states[get_pm_cur_state()].timeout);
-       }
-
-       if (!display_state_transition_is_there_state_transition_timer())
-               states[get_pm_cur_state()].trans(EVENT_TIMEOUT);
-
-       return 0;
-}
-
 /* SIGHUP signal handler
  * For debug... print info to syslog
  */
@@ -1018,7 +875,7 @@ int poll_callback(int condition, PMMsg *data)
        }
 
        if (condition == PM_CONTROL_EVENT) {
-               proc_condition(data);
+               display_lock_proc_condition(data);
 
                if (IS_COND_REQUEST_CHANGE(data->cond))
                        display_state_transition_do_proc_change_state(data->cond, data->pid);
index a9cbe40..2b2625f 100644 (file)
@@ -574,3 +574,157 @@ int display_lock_print_lock_info(int fd)
 
        return 0;
 }
+
+static void proc_condition_lock(PMMsg *data)
+{
+       char pname[PATH_MAX];
+       pid_t pid = data->pid;
+       enum state_t state;
+       int ret;
+       bool value = true;
+       unsigned int flags;
+       const char *lock_type = NULL;
+       const char *state_name = NULL;
+
+       state = GET_COND_STATE(data->cond);
+       if (state == S_START)
+               return;
+
+       flags = GET_COND_FLAG(data->cond);
+       display_misc_get_process_name(pid, pname);
+
+       if ((state == S_LCDOFF) && (get_pm_cur_state() == S_SLEEP) &&
+           (pm_get_power_lock() == POWER_UNLOCK))
+               display_state_transition_do_proc_change_state(data->cond, INTERNAL_LOCK_PM);
+
+       ret = display_lock_request_lock(state, pid, data->timeout);
+       if (ret == -EALREADY)
+               ret = display_lock_update_lock(state, pid, data->timeout);
+
+       if (ret != 0) {
+               _E("Failed to acquire lock, state: %d, pid: %d.", state, pid);
+               return;
+       }
+
+       if (state == S_LCDOFF)
+               set_process_active(true, pid);
+
+       display_plugin_state_get_name(state, &state_name);
+       _I("[%s] locked by %5d with %u ms", state_name, pid, data->timeout);
+
+       if (pid < INTERNAL_LOCK_BASE) {
+               /* for debug */
+               if (state == S_LCDOFF)
+                       lock_type = PM_LCDOFF_STR;
+               else if (state == S_LCDDIM)
+                       lock_type = PM_LCDDIM_STR;
+               else if (state == S_NORMAL)
+                       lock_type = PM_LCDON_STR;
+
+               if (lock_type) {
+                       /* power lock signal */
+                       ret = gdbus_signal_emit(NULL,
+                                       DEVICED_PATH_DISPLAY,
+                                       DEVICED_INTERFACE_DISPLAY,
+                                       "PowerLock",
+                                       g_variant_new("(sii)", lock_type, pid, (int)data->timeout));
+                       if (ret < 0)
+                               _E("Failed to send dbus signal PowerLock.");
+               }
+       }
+
+       _SD("be requested LOCK info pname(%s), flags(%d)", pname, flags);
+       set_lock_time(pid, pname, state);
+
+       device_notify(DEVICE_NOTIFIER_DISPLAY_LOCK, (void *)&value);
+}
+
+static void proc_condition_unlock(PMMsg *data)
+{
+       pid_t pid = data->pid;
+       enum state_t state;
+       char pname[PATH_MAX];
+       bool value = false;
+       unsigned int flags;
+       int ret;
+       const char *lock_type = NULL;
+       const char *state_name = NULL;
+
+       state = GET_COND_STATE(data->cond);
+       if (!state)
+               return;
+
+       flags = GET_COND_FLAG(data->cond);
+       display_misc_get_process_name(pid, pname);
+
+       display_lock_release_lock(state, pid);
+
+       if (state == S_LCDOFF)
+               set_process_active(false, pid);
+
+       display_plugin_state_get_name(state, &state_name);
+       _I("[%s] unlocked by %5d", state_name, pid);
+
+       if (pid < INTERNAL_LOCK_BASE) {
+               /* for debug */
+               if (state == S_LCDOFF)
+                       lock_type = PM_LCDOFF_STR;
+               else if (state == S_LCDDIM)
+                       lock_type = PM_LCDDIM_STR;
+               else if (state == S_NORMAL)
+                       lock_type = PM_LCDON_STR;
+
+               if (lock_type) {
+                       /* power unlock signal */
+                       ret = gdbus_signal_emit(NULL,
+                                       DEVICED_PATH_DISPLAY,
+                                       DEVICED_INTERFACE_DISPLAY,
+                                       "PowerUnlock",
+                                       g_variant_new("(sii)", lock_type, pid, (int)data->timeout));
+                       if (ret < 0)
+                               _E("Failed to send dbus signal PowerUnlock.");
+               }
+       }
+
+       _SD("be requested UNLOCK info pname(%s) flag(%d)", pname, flags);
+       set_unlock_time(pid, state);
+
+       device_notify(DEVICE_NOTIFIER_DISPLAY_LOCK, (void *)&value);
+}
+
+/* FIXME: This function will be refactored or divided according to role */
+int display_lock_proc_condition(PMMsg *data)
+{
+       unsigned int flags;
+       int timeout = 0;
+       bool timeout_enable = false;
+
+       if (IS_COND_REQUEST_LOCK(data->cond))
+               proc_condition_lock(data);
+
+       if (IS_COND_REQUEST_UNLOCK(data->cond))
+               proc_condition_unlock(data);
+
+       display_plugin_config_get_timeout_enable(&timeout_enable);
+       if (!timeout_enable)
+               return 0;
+
+       flags = GET_COND_FLAG(data->cond);
+       if (flags == 0) {
+               /* guard time for suspend */
+               if (get_pm_cur_state() == S_LCDOFF) {
+                       display_plugin_state_get_timeout(S_LCDOFF, &timeout);
+                       display_state_transition_reset_state_transition_timeout(timeout);
+               }
+       } else {
+               if (flags & PM_FLAG_RESET_TIMER) {
+                       display_plugin_state_get_timeout(get_pm_cur_state(), &timeout);
+                       display_state_transition_reset_state_transition_timeout(timeout);
+               }
+       }
+
+       if (!display_state_transition_is_there_state_transition_timer())
+               display_state_transition_do_state_transition(get_pm_cur_state(), EVENT_TIMEOUT);
+
+       return 0;
+}
\ No newline at end of file
index c3379b1..7f2679a 100644 (file)
@@ -41,4 +41,6 @@ void display_lock_release_lock_all(enum state_t state);
 int display_lock_is_state_locked(enum state_t state);
 int display_lock_print_lock_info(int fd);
 
+int display_lock_proc_condition(PMMsg *data);
+
 #endif /* __DISPLAY_LOCK_H__ */