/*
* PASS (Power Aware System Service)
*
- * Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2012 - 2018 Samsung Electronics Co., Ltd.
*
* Licensed under the Apache License, Version 2.0 (the License);
* you may not use this file except in compliance with the License.
#define DBUS_PMQOS_PATH "/Org/Tizen/System/Pass/Pmqos"
static SystemPassPmqos *g_gdbus_instance = NULL;
-static struct pmqos_scenario *g_pmqos_scenarios = NULL;
-static bool g_initialized = false;
+static struct pmqos_scenario *g_pmqos = NULL;
struct pmqos_cpu {
char name[NAME_MAX];
int ret = 0;
int booting_done = 1;
- if (g_initialized)
+ if (g_pmqos)
_I("PASS PMQoS is already started\n");
else
ret = pmqos_init_done(&booting_done, NULL);
static gboolean dbus_cb_pmqos_stop(SystemPassPmqos *obj,
GDBusMethodInvocation *invoc, gpointer user_data)
{
- if (!g_initialized)
+ if (!g_pmqos)
_I("PASS PMQoS is already stopped\n");
else
pmqos_free();
int i, ret = 0;
gboolean ret_out = TRUE;
- if (!g_initialized) {
+ if (!g_pmqos) {
_E("PASS PMQoS is stopped\n");
ret_out = FALSE;
goto out;
} else {
name_from = g_dbus_method_invocation_get_method_name(invoc);
ret = -ENOTSUP;
- if (g_pmqos_scenarios != NULL) {
- for (i = 0; i < g_pmqos_scenarios->num; i++) {
- name = g_pmqos_scenarios->list[i].name;
- support = g_pmqos_scenarios->list[i].support;
+ if (g_pmqos) {
+ for (i = 0; i < g_pmqos->num; i++) {
+ name = g_pmqos->list[i].name;
+ support = g_pmqos->list[i].support;
if (!strncmp(name, name_from, strlen(name)) &&
support) {
ret = 0;
char scenario[100];
if (val)
- _D("Set pm scenario : [Lock ]%s", name);
+ _D("Set pm scenario : Lock \'%s\'", name);
else
- _D("Set pm scenario : [Unlock]%s", name);
+ _D("Set pm scenario : Unlock \'%s\'", name);
snprintf(scenario, sizeof(scenario), "%s%s", name, (val ? "Lock" : "Unlock"));
device_notify(DEVICE_NOTIFIER_PMQOS, (void *)scenario);
return ret;
}
-static int get_methods_from_conf(const char *path,
- struct pmqos_scenario **pmqos_scenarios)
+static int pmqos_init_done(void *data, void *user_data)
{
- struct pmqos_scenario *scenarios;
- int i, ret, count = 0;
+ int *booting_done;
+ int ret;
+ int i;
+
+ /*
+ * As a callback function for the booting-done event, it is notified
+ * with the result of the booting_finished() function by using the
+ * first argument, void *data. When it is successfully booted up, an int
+ * value, 1 is passed with the first argument.
+ */
+ booting_done = (int *)data;
+ if (!(*booting_done))
+ return -EINVAL;
- scenarios = malloc(sizeof(*scenarios));
- if (scenarios == NULL)
+ if (g_pmqos)
+ return 0;
+
+ g_pmqos = calloc(1, sizeof(*g_pmqos));
+ if (!g_pmqos)
return -ENOMEM;
- /* get pmqos table from conf */
- ret = pmqos_get_scenario(path, scenarios);
+ ret = pmqos_get_scenario(PMQOS_CONF_PATH, g_pmqos);
if (ret < 0) {
- pmqos_put_scenario(scenarios);
+ _E("failed to get PMQoS scenario\n");
return ret;
}
- /* if do not support scenario */
- if (!scenarios->support)
- return 0;
-
- /* if do not have scenarios */
- if (scenarios->num <= 0)
- return 0;
+ if (!g_pmqos->support || g_pmqos->num <= 0) {
+ ret = pmqos_put_scenario(g_pmqos);
+ if (ret < 0)
+ _E("failed to put PMQoS scenario\n");
+ return ret;
+ }
- /* set edbus_methods structure */
- for (i = 0; i < scenarios->num; ++i) {
- /* if this scenario does not support */
- if (!scenarios->list[i].support)
- continue;
+ for (i = 0; i < g_pmqos->num; ++i)
+ if (g_pmqos->list[i].support)
+ _I("Support \'%s\' scenario", g_pmqos->list[i].name);
- count++;
- _I("support [%s] scenario", scenarios->list[i].name);
- }
/*
* Set maximum timeout for the sceanrio by using the parsed data from
* pass-pmqos.conf. But, if there is no setting from pass-pmqos.conf
* pmqos uses the default timeout value (3000 millisecond).
*/
- if (scenarios->max_timeout_ms)
- unlock_max_timeout_ms = scenarios->max_timeout_ms;
+ if (g_pmqos->max_timeout_ms)
+ unlock_max_timeout_ms = g_pmqos->max_timeout_ms;
else
unlock_max_timeout_ms = DEFAULT_PMQOS_TIMER;
- ret = count;
- *pmqos_scenarios = scenarios;
-
- return ret;
-}
-
-static int pmqos_init_done(void *data, void *user_data)
-{
- int *booting_done;
- int size;
-
- /*
- * As a callback function for the booting-done event, it is notified
- * with the result of the booting_finished() function by using the
- * first argument, void *data. When it is successfully booted up, an int
- * value, 1 is passed with the first argument.
- */
- booting_done = (int *)data;
- if (!(*booting_done))
- return -EINVAL;
-
- size = get_methods_from_conf(PMQOS_CONF_PATH, &g_pmqos_scenarios);
- if (size < 0) {
- _E("failed to load configuration file(%s)", PMQOS_CONF_PATH);
- return -EINVAL;
- }
-
- g_initialized = true;
-
return 0;
}
static void pmqos_free(void)
{
- /* Assign 0 to static variables */
+ int ret;
+
memset(&unlock_timer_start_st, 0, sizeof(struct timespec));
memset(&unlock_timer_end_st, 0, sizeof(struct timespec));
memset(&unlock_timer_owner, 0, sizeof(struct pmqos_cpu));
- /* Clean up pmqos_head */
if (pmqos_head) {
g_list_free_full(pmqos_head, free);
pmqos_head = NULL;
}
- free(g_pmqos_scenarios);
- g_pmqos_scenarios = NULL;
+ ret = pmqos_put_scenario(g_pmqos);
+ if (ret < 0)
+ _E("failed to put PMQoS scenario\n");
+
+ free(g_pmqos);
+ g_pmqos = NULL;
if (g_unlock_timeout_id) {
g_source_remove(g_unlock_timeout_id);
g_unlock_timeout_id = 0;
}
-
- g_initialized = false;
}
static void pmqos_exit(void *data)
int ret = 0;
g_gdbus_instance = pass_gdbus_get_instance_pmqos();
- if (g_gdbus_instance == NULL) {
+ if (!g_gdbus_instance) {
_E("cannot get a dbus instance for the %s interface\n",
DBUS_PMQOS_INTERFACE);
return -ENOSYS;