#include "dd-deviced.h"
#include "core/log.h"
#include "core/launch.h"
+#include "core/config-parser.h"
#include "core/device-notifier.h"
#include "core/device-idler.h"
#include "core/common.h"
#define POWER_FLAG_POWEROFF "/run/"POWER_POWEROFF
#define POWER_FLAG_REBOOT "/run/"POWER_REBOOT
+#define POWER_CONF_FILE "/etc/deviced/power.conf"
+
struct power_flag {
enum poweroff_type type;
const char *path;
static struct timeval tv_start_poweroff;
+static dd_list *poweroff_options;
+
static int telephony_off(enum poweroff_type type)
{
const struct device_ops *tele;
/* Add methods here */
};
+static int add_poweroff_option(enum poweroff_type type, char *option)
+{
+ struct power_option *opt;
+ static int index = 0;
+ char *name;
+
+ if (type == POWER_OFF_POPUP)
+ name = PWROFF_POPUP;
+ else if (type == POWER_OFF_DIRECT)
+ name = POWER_POWEROFF;
+ else if (type == POWER_OFF_RESTART)
+ name = POWER_REBOOT;
+ else {
+ _E("Invalid type (%d)", type);
+ return -EINVAL;
+ }
+
+ opt = calloc(1, sizeof(struct power_option));
+ if (!opt) {
+ _E("calloc() failed");
+ return -ENOMEM;
+ }
+
+ opt->type = type;
+ opt->name = strdup(name);
+ opt->option = (option ? strdup(option) : NULL);
+ opt->index = index++;
+
+ DD_LIST_APPEND(poweroff_options, opt);
+
+ _I("Add %s option (%s)", opt->name, opt->option);
+
+ return 0;
+}
+
+static int load_config(struct parse_result *result, void *user_data)
+{
+ enum poweroff_type type;
+ int ret;
+
+ if (MATCH(result->section, "Poweroff"))
+ type = POWER_OFF_DIRECT;
+ else if (MATCH(result->section, "Reboot"))
+ type = POWER_OFF_RESTART;
+ else
+ return 0;
+
+ if (!MATCH(result->name, "Option"))
+ return 0;
+
+ ret = add_poweroff_option(type, result->value);
+ if (ret < 0) {
+ _E("Failed to add %s option (%s)", result->section, result->value);
+ return ret;
+ }
+
+ return 0;
+}
+
static void power_init(void *data)
{
int ret;
add_booting_done_handler(NULL);
register_notifier(DEVICE_NOTIFIER_BOOTING_DONE, booting_done);
+
+ add_poweroff_option(POWER_OFF_DIRECT, NULL);
+ add_poweroff_option(POWER_OFF_RESTART, NULL);
+ add_poweroff_option(POWER_OFF_POPUP, NULL);
+
+ ret = config_parse(POWER_CONF_FILE, load_config, NULL);
+ if (ret < 0)
+ _E("Failed to load power off config (%d)", ret);
}
static const struct device_ops power_device_ops = {