pmqos: Add new SetScenario method for pmqos dbus interface 12/240512/2
authorChanwoo Choi <cw00.choi@samsung.com>
Thu, 6 Aug 2020 09:57:01 +0000 (18:57 +0900)
committerChanwoo Choi <cw00.choi@samsung.com>
Fri, 7 Aug 2020 06:38:03 +0000 (15:38 +0900)
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 <cw00.choi@samsung.com>
include/pass/gdbus-definition.h
scripts/pmqos-dbus.xml
src/pmqos/pmqos.c

index fbf4afd..5072341 100644 (file)
@@ -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"
index f373ddd..271d775 100644 (file)
@@ -7,6 +7,11 @@
     <method name="stop">
       <arg type="i" name="return_code" direction="out" />
     </method>
+    <method name="SetScenario">
+      <arg type="s" name="name" direction="in" />
+      <arg type="i" name="duration_ms" direction="in" />
+      <arg type="i" name="return_code" direction="out" />
+    </method>
     <method name="AppLaunch">
       <arg type="i" name="duration" direction="in" />
       <arg type="i" name="return_code" direction="out" />
index 27a3e5f..7c95054 100644 (file)
@@ -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,