block: apply new poweroff handler 98/274998/5 accepted/tizen/unified/20220601.141609 submit/tizen/20220531.085748
authorYoungjae Cho <y0.cho@samsung.com>
Fri, 13 May 2022 07:27:45 +0000 (16:27 +0900)
committerYoungjae Cho <y0.cho@samsung.com>
Thu, 26 May 2022 06:19:07 +0000 (15:19 +0900)
Change-Id: I32530e4e3614944227c9398960e8ae4aafbb275a
Signed-off-by: Youngjae Cho <y0.cho@samsung.com>
src/block/block.c

index bdf6e78..8115a98 100644 (file)
@@ -46,6 +46,7 @@
 #include <libsyscommon/libgdbus.h>
 #include <libsyscommon/ini-parser.h>
 #include <libsyscommon/list.h>
+#include <device/power-internal.h>
 #ifdef EXTENDED_STORAGE
 #include <ode/luks.h>
 #endif
@@ -230,7 +231,6 @@ static fd_handler_h phandler;
 static bool block_control = false;
 static bool block_boot = false;
 static pthread_mutex_t pipe_mutex = PTHREAD_MUTEX_INITIALIZER;
-static bool add_poweroff_wait = false;
 
 static int block_start(void *data);
 static int block_stop(void *data);
@@ -2889,20 +2889,20 @@ static void remove_whole_block_device(void)
        }
 }
 
-static void add_poweroff_wait_cb(GVariant *var, void *user_data, GError *err)
+static void block_poweroff_cb(const struct device_change_state_info *info, void *udata)
 {
-       int ret_val = -ENOMSG;
-
-       if (!var)
-               return ;
-
-       if (!g_variant_get_safe(var, "(i)", &ret_val))
-               _E("Failed to get(%s): no message", g_variant_get_type_string(var));
+       static int status = 0;
 
-       if (ret_val >= 0)
-               add_poweroff_wait = true;
+       if (status > 0)
+               return;
+       status = 1;
+       _I("Power off.");
+       /* unregister mmc uevent control routine */
+       unregister_udev_uevent_control(&uh);
+       remove_whole_block_device();
+       terminate_threads();
 
-       g_variant_unref(var);
+       device_power_change_state_wait_done(info->id);
 }
 
 static void booting_done(void)
@@ -2924,52 +2924,14 @@ static void booting_done(void)
        /* if there is the attached device, try to mount */
        block_init_from_udev_enumerate();
 
-       ret_val = gdbus_call_async_with_reply(DEVICED_BUS_NAME,
-               DEVICED_PATH_POWEROFF,
-               DEVICED_INTERFACE_POWEROFF,
-               METHOD_ADD_POWEROFF_WAIT,
-               NULL,
-               add_poweroff_wait_cb,
-               -1, NULL);
+       ret_val = device_power_add_change_state_wait_callback(POWER_STATE_POWEROFF | POWER_STATE_REBOOT | POWER_STATE_EXIT,
+               block_poweroff_cb, NULL);
        if (ret_val < 0)
-               _E("Failed to call "METHOD_ADD_POWEROFF_WAIT" method.");
+               _E("Failed to call poweroff wait callback.");
 
        block_boot = true;
 }
 
-static void block_poweroff(GDBusConnection  *conn,
-               const gchar *sender,
-               const gchar *path,
-               const gchar *iface,
-               const gchar *name,
-               GVariant *param,
-               gpointer data)
-{
-       static int status = 0;
-       int ret_dbus;
-
-       if (status > 0)
-               return;
-       status = 1;
-       _I("Power off.");
-       /* unregister mmc uevent control routine */
-       unregister_udev_uevent_control(&uh);
-       remove_whole_block_device();
-       terminate_threads();
-
-       if (add_poweroff_wait) {
-               ret_dbus = gdbus_call_sync_with_reply_int(DEVICED_BUS_NAME,
-                       DEVICED_PATH_POWEROFF,
-                       DEVICED_INTERFACE_POWEROFF,
-                       METHOD_REMOVE_POWEROFF_WAIT,
-                       NULL, NULL);
-               if (ret_dbus < 0)
-                       _E("Failed to call "METHOD_REMOVE_POWEROFF_WAIT" method.");
-               else
-                       add_poweroff_wait = false;
-       }
-}
-
 static void uevent_block_handler(struct udev_device *dev)
 {
        const char *devnode = NULL;
@@ -3891,8 +3853,6 @@ static int mount_root_path_tmpfs(void)
 #define mount_root_path_tmpfs() 0
 #endif
 
-static guint id_block_poweroff;
-
 static void block_init(void *data)
 {
        int ret_val;
@@ -3946,11 +3906,6 @@ static void block_init(void *data)
        if (ret_val < 0)
                _E("Failed to get internal storage number.");
 
-       id_block_poweroff = gdbus_signal_subscribe(NULL, DEVICED_PATH_POWEROFF,
-                       DEVICED_INTERFACE_POWEROFF,
-                       SIGNAL_POWEROFF_STATE,
-                       block_poweroff, NULL, NULL);
-
        booting_done();
 }
 static void terminate_threads(void)
@@ -3985,7 +3940,7 @@ static void block_exit(void *data)
        udev_exit(NULL);
 
        /* unregister notifier for below each event */
-       gdbus_signal_unsubscribe(NULL, id_block_poweroff);
+       device_power_remove_change_state_wait_callback(POWER_STATE_POWEROFF | POWER_STATE_REBOOT | POWER_STATE_EXIT);
 
        /* unregister mmc uevent control routine */
        ret_val = unregister_udev_uevent_control(&uh);
@@ -4000,18 +3955,6 @@ static void block_exit(void *data)
        /* exit pipe */
        pipe_exit();
 
-       if (add_poweroff_wait) {
-               ret_val = gdbus_call_sync_with_reply_int(DEVICED_BUS_NAME,
-                       DEVICED_PATH_POWEROFF,
-                       DEVICED_INTERFACE_POWEROFF,
-                       METHOD_REMOVE_POWEROFF_WAIT,
-                       NULL, NULL);
-               if (ret_val < 0)
-                       _E("Failed to call "METHOD_REMOVE_POWEROFF_WAIT" method.");
-               else
-                       add_poweroff_wait = false;
-       }
-
        block_control = false;
 }