From: Youngjae Cho Date: Thu, 26 May 2022 03:06:55 +0000 (+0900) Subject: Apply new poweroff handler X-Git-Tag: accepted/tizen/7.0/unified/20221110.061728^0 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=refs%2Fchanges%2F17%2F275517%2F2;p=platform%2Fcore%2Fsystem%2Ffeedbackd.git Apply new poweroff handler Change-Id: I6ca6fc17ddcc2c16e98b939604cf93f89e4d8817 Signed-off-by: Youngjae Cho --- diff --git a/src/core/haptic.c b/src/core/haptic.c index e644f1c..4fea07d 100644 --- a/src/core/haptic.c +++ b/src/core/haptic.c @@ -24,6 +24,8 @@ #include #include #include +#include +#include #include #include #include @@ -39,7 +41,6 @@ #define VIBRATION_CONF_PATH FEEDBACK_BASE_PATH"vibration.conf" #define HAPTIC_CONF_PATH "/etc/feedbackd/haptic.conf" -#define SIGNAL_POWEROFF_STATE "ChangeState" #define SIGNAL_VIBRATOR_INITIATED "InitiateVibrator" /* hardkey vibration variable */ @@ -1133,27 +1134,12 @@ exit: return g_variant_new("(i)", ret); } -static void haptic_poweroff_cb(GDBusConnection *conn, - const gchar *sender, - const gchar *path, - const gchar *iface, - const gchar *name, - GVariant *param, - gpointer data) +static void haptic_poweroff_cb(const struct device_change_state_info *info, void *udata) { - int type = POWER_OFF_NONE; int ret, level; struct timespec time = {0,}; - if (!g_variant_get_safe(param, "(i)", &type)) { - _E("Failed to get params from gvariant. expected:%s, type:%s", "(i)", g_variant_get_type_string(param)); - return; - } - - if (type != POWER_OFF_DIRECT && type != POWER_OFF_RESTART) - return; - - _D("Poweroff: %d", type); + _D("Poweroff: %"PRIx64, info->next_state); if (hal_device_haptic_check_backend() < 0) { if (haptic_module_load() < 0) @@ -1185,6 +1171,9 @@ static void haptic_poweroff_cb(GDBusConnection *conn, /* sleep for vibration */ time.tv_nsec = POWER_OFF_VIB_DURATION * NANO_SECOND_MULTIPLIER; nanosleep(&time, NULL); + + device_power_change_state_wait_done(info->id); + return; } @@ -1301,8 +1290,6 @@ int haptic_probe(void) return haptic_module_load(); } -static guint id_sig_pwr_off_state; - void haptic_init(void) { int r; @@ -1319,15 +1306,10 @@ void haptic_init(void) if (r < 0) _E("Failed to init hdbus interface and method: %d", r); - id_sig_pwr_off_state = gdbus_signal_subscribe(NULL, - DEVICED_PATH_POWEROFF, - DEVICED_INTERFACE_POWEROFF, - SIGNAL_POWEROFF_STATE, - haptic_poweroff_cb, - NULL, - NULL); - if (id_sig_pwr_off_state <= 0) { - _E("Failed to register signal handler: %d", r); + r = device_power_add_change_state_wait_callback(POWER_STATE_POWEROFF | POWER_STATE_REBOOT, + haptic_poweroff_cb, NULL); + if (r < 0) { + _E("Failed to register poweroff handler: %d", r); return; } @@ -1360,8 +1342,7 @@ void haptic_exit(void) _W("Remove watch for VCONFKEY_RECORDER_STATE failed."); } - /* unregister notifier for below each event */ - gdbus_signal_unsubscribe(NULL, id_sig_pwr_off_state); + device_power_remove_change_state_wait_callback(POWER_STATE_POWEROFF | POWER_STATE_REBOOT); /* release haptic data memory */ safe_free(haptic_conf.level_arr);