From: Chanwoo Choi Date: Thu, 6 Aug 2020 09:57:01 +0000 (+0900) Subject: pmqos: Add new SetScenario method for pmqos dbus interface X-Git-Tag: accepted/tizen/unified/20200810.123011~2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=refs%2Fchanges%2F12%2F240512%2F2;p=platform%2Fcore%2Fsystem%2Fpass.git pmqos: Add new SetScenario method for pmqos dbus interface When add new scenario to pmqos, it have to edit the code. It is not extensible. In order to improve the extensiblity without code changes, add new SetScenario method for pmqos dbus interface as following: When need to add new scenario, just add new scenario info. to scripts/pass-pmqos.conf (/etc/pass/pass-pmqos.conf) without any code changes. [Interface for new SetScenario method of pmqos dbus] - dbus interface : org.tizen.system.pass.pmqos.SetScenario - parameter 1: scenario name like AppLaunch - parameter 2: duration time like 3000 means 3 second Change-Id: I5ee8da4ec62a9cf1d55ea51f6c7fb8ca9ce7b9e7 Signed-off-by: Chanwoo Choi --- diff --git a/include/pass/gdbus-definition.h b/include/pass/gdbus-definition.h index fbf4afd..5072341 100644 --- a/include/pass/gdbus-definition.h +++ b/include/pass/gdbus-definition.h @@ -40,6 +40,7 @@ typedef enum { #define DBUS_PMQOS_I_STOP_HANDLER "handle_stop" #define DBUS_PMQOS_I_APPLAUNCH_HANDLER "handle_app_launch" #define DBUS_PMQOS_I_ULTRAPOWERSAVING_HANDLER "handle_ultra_power_saving" +#define DBUS_PMQOS_I_SET_SCENARIO_HANDLER "handle_set_scenario" #define DBUS_THERMAL_BUS_NAME "org.tizen.system.thermal" #define DBUS_THERMAL_INTERFACE "org.tizen.system.thermal" diff --git a/scripts/pmqos-dbus.xml b/scripts/pmqos-dbus.xml index f373ddd..271d775 100644 --- a/scripts/pmqos-dbus.xml +++ b/scripts/pmqos-dbus.xml @@ -7,6 +7,11 @@ + + + + + diff --git a/src/pmqos/pmqos.c b/src/pmqos/pmqos.c index 27a3e5f..7c95054 100644 --- a/src/pmqos/pmqos.c +++ b/src/pmqos/pmqos.c @@ -146,20 +146,18 @@ static gboolean dbus_cb_pmqos_stop(SystemPassPmqos *obj, * UltraPowerSaving through D-bus interface. * @param [in] obj Instance of SystemPassPmqos * @param [in] invoc Instance of GDBusMethodInvocation + * @param [in] name Specific scenario name or mode name * @param [in] duration Duration to keep scenario during demanded time * @param [in] user_data Unused parameter * @return @c true if success, otherwise @c false if fail */ -static gboolean dbus_cb_pmqos_legacy_scenario(SystemPassPmqos *obj, +static gboolean dbus_cb_pmqos_set_scenario(SystemPassPmqos *obj, GDBusMethodInvocation *invoc, + const char *name, int duration, gpointer user_data) { - const char *name_from; - char *name; - bool support; - int max_duration_ms; - int i, ret = 0; + int i, ret = -ENOTSUP; gboolean ret_out = TRUE; if (!g_pmqos) { @@ -168,43 +166,64 @@ static gboolean dbus_cb_pmqos_legacy_scenario(SystemPassPmqos *obj, goto out; } - name_from = g_dbus_method_invocation_get_method_name(invoc); - ret = -ENOTSUP; - if (g_pmqos) { - for (i = 0; i < g_pmqos->num; i++) { - name = g_pmqos->list[i].name; - support = g_pmqos->list[i].support; - max_duration_ms = g_pmqos->list[i].max_duration_ms; - - if (!strcmp(name, name_from) && support) { - ret = 0; - if (duration > max_duration_ms) - duration = max_duration_ms; - break; - } + for (i = 0; i < g_pmqos->num; i++) { + char *supported_name = g_pmqos->list[i].name; + bool support = g_pmqos->list[i].support; + + if (!strcmp(supported_name, name) && support) { + int max_duration_ms = g_pmqos->list[i].max_duration_ms; + + if (duration > max_duration_ms) + duration = max_duration_ms; + ret = 0; + break; } } if (ret < 0) { _E("cannot set the PMQoS scenario: " - "%s is not supported\n", name_from); + "%s is not supported\n", name); ret_out = FALSE; goto out_dbus; } if (duration) - ret = pmqos_request(name_from, duration); + ret = pmqos_request(name, duration); else - ret = pmqos_cancel(name_from); + ret = pmqos_cancel(name); out_dbus: g_dbus_method_invocation_return_value(invoc, g_variant_new("(i)", ret)); - out: return ret_out; } /** + * @brief Callback function when receive the scenario like AppLaunch, + * UltraPowerSaving through D-bus interface. + * @param [in] obj Instance of SystemPassPmqos + * @param [in] invoc Instance of GDBusMethodInvocation + * @param [in] duration Duration to keep scenario during demanded time + * @param [in] user_data Unused parameter + * @return @c true if success, otherwise @c false if fail + */ +static gboolean dbus_cb_pmqos_legacy_scenario(SystemPassPmqos *obj, + GDBusMethodInvocation *invoc, + int duration, + gpointer user_data) +{ + const char *name; + + if (!g_pmqos) { + _E("PASS PMQoS is stopped\n"); + return FALSE; + } + + name = g_dbus_method_invocation_get_method_name(invoc); + return dbus_cb_pmqos_set_scenario(obj, invoc, name, duration, user_data); +} + +/** * @brief Define the supported D-bus signal information for PMQoS * feature. It contains the signal name and callback function * pointer which is executed when receives the defined signal. @@ -221,6 +240,11 @@ static struct pass_gdbus_signal_info g_gdbus_signal_infos[] = { .cb_data = NULL, .ret_id = 0, }, { + .handler = DBUS_PMQOS_I_SET_SCENARIO_HANDLER, + .cb = G_CALLBACK(dbus_cb_pmqos_set_scenario), + .cb_data = NULL, + .ret_id = 0, + }, { .handler = DBUS_PMQOS_I_START_HANDLER, .cb = G_CALLBACK(dbus_cb_pmqos_start), .cb_data = NULL,