pass: thermal: Add GetCoolDownStatus DBUS method 39/208239/2 accepted/tizen/unified/20190627.014836 submit/tizen/20190624.013748
authorDongwoo Lee <dwoo08.lee@samsung.com>
Thu, 20 Jun 2019 06:20:37 +0000 (15:20 +0900)
committerDongwoo Lee <dwoo08.lee@samsung.com>
Fri, 21 Jun 2019 05:56:13 +0000 (14:56 +0900)
This patch adds a new DBUS method for providing the current status of
CoolDownMode.

 Method description:
 - Destination: org.tizen.system.thermal
 - Path: /Org/Tizen/System/Thermal
 - Interface: org.tizen.system.thermal.GetCoolDownStatus
 - Parameter: IN: none, OUT: string

Change-Id: I89be8758bda57f265f4cb6a03c1a3d6d559aa2f4
Signed-off-by: Dongwoo Lee <dwoo08.lee@samsung.com>
include/pass/gdbus-definition.h
scripts/thermal-dbus.xml
src/thermal/thermal.c
src/thermal/thermal.h

index 2eaaa824b996f536e0552cf49e64cf4d3f280f48..fbf4afd1303ca3b2c326d631dfbf69e894964b30 100644 (file)
@@ -47,6 +47,7 @@ typedef enum {
 #define DBUS_THERMAL_I_START_HANDLER           "handle_start"
 #define DBUS_THERMAL_I_STOP_HANDLER            "handle_stop"
 #define DBUS_THERMAL_SIGNAL                    "CoolDownModeChanged"
+#define DBUS_THERMAL_METHOD                    "handle_get_cool_down_status"
 
 /* Dbus definition for systemd */
 #define SYSTEMD_DBUS_NAME                      "org.freedesktop.systemd1"
index 535a33f9e5da6e36e8a3814ebaa240eccd09ed43..4a935fe6f8f7bb32993814de547f159e4f550f27 100644 (file)
@@ -7,5 +7,8 @@
     <method name="stop">
       <arg type="i" name="return_code" direction="out" />
     </method>
+    <method name="GetCoolDownStatus">
+      <arg type="s" name="status" direction="out" />
+    </method>
   </interface>
 </node>
index 9669d8da10287c39b44996f4f8548346c7a5064f..211d3cac2988c9656d4d6eccd55f95c55e9cd34f 100644 (file)
@@ -52,6 +52,33 @@ static SystemThermal *g_gdbus_instance = NULL;
  */
 static struct thermal_scenario *g_thermal = NULL;
 
+static gboolean dbus_cb_thermal_method(SystemThermal *obj,
+               GDBusMethodInvocation *invoc, gpointer user_data)
+{
+       GVariant *status;
+       int scenario_idx;
+
+       if (!g_thermal || !g_thermal->support) {
+               _E("Thermal service is not available");
+               return FALSE;
+       }
+
+       scenario_idx = g_thermal->cur_scenario_idx;
+       if (scenario_idx < 0) {
+               _E("CoolDownMode is not set yet");
+               return FALSE;
+       } else if (scenario_idx >= g_thermal->num) {
+               _E("CoolDownMode index is invalid: %d", scenario_idx);
+               return FALSE;
+       }
+
+       status = g_variant_new("(s)", g_thermal->list[scenario_idx].name);
+
+       g_dbus_method_invocation_return_value(invoc, status);
+
+       return TRUE;
+}
+
 /**
  * @brief      Free the resources of Thermal Monitor feature.
  * @return     N/A
@@ -118,6 +145,8 @@ static int thermal_init_done(void *data, void *user_data)
                return ret;
        }
 
+       g_thermal->cur_scenario_idx = -1;
+
        for (i = 0; i < g_thermal->num; i++)
                if (g_thermal->list[i].support)
                        _I("Support \'%s\' scenario", g_thermal->list[i].name);
@@ -192,6 +221,11 @@ static struct pass_gdbus_signal_info g_gdbus_signal_infos[] = {
                .cb = G_CALLBACK(dbus_cb_thermal_stop),
                .cb_data = NULL,
                .ret_id = 0,
+       }, {
+               .handler = DBUS_THERMAL_METHOD,
+               .cb = G_CALLBACK(dbus_cb_thermal_method),
+               .cb_data = NULL,
+               .ret_id = 0,
        },
 };
 
@@ -230,6 +264,8 @@ static int thermal_notifier_cb(void *data, void *user_data)
                return 0;
        }
 
+       g_thermal->cur_scenario_idx = i;
+
        /* If there is available thermal scenario, send the broadcast signal */
        gvar = g_variant_new("(s)", data);
        ret = pass_gdbus_send_broadcast_signal(PASS_DBUS_THERMAL,
index 836fa20061875988f9f82c527b83797b84018e37..c65ec75d42b6c1dc6a5152810ae03f55ad113a6d 100644 (file)
@@ -48,6 +48,8 @@ struct thermal_scenario {
        int num;
        /** State of Thermal Monitor feature is either supported or not*/
        bool support;
+       /** Represent current idx of thermal scenario */
+       int cur_scenario_idx;
 };
 
 int thermal_get_scenario(const char *path, struct thermal_scenario *scenarios);