#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
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);
}
}
-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)
/* 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;
#define mount_root_path_tmpfs() 0
#endif
-static guint id_block_poweroff;
-
static void block_init(void *data)
{
int ret_val;
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)
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);
/* 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;
}