Change battery_state to prevent duplicated work 86/205386/2 accepted/tizen/unified/20190503.075109 submit/tizen/20190503.045829
authorlokilee73 <changjoo.lee@samsung.com>
Fri, 3 May 2019 02:53:45 +0000 (11:53 +0900)
committerlokilee73 <changjoo.lee@samsung.com>
Fri, 3 May 2019 03:05:20 +0000 (12:05 +0900)
Usage of battery_state was to print battery information.
But change it to prevent duplicated work in battery_changed.
Battery related information will be printed in process_power_supply.

Change-Id: I313fd6c2ecad348b7ce228b20592b09ab1f9c09d
Signed-off-by: lokilee73 <changjoo.lee@samsung.com>
src/battery/power-supply.c

index 67ddf6f..f602701 100644 (file)
@@ -696,33 +696,43 @@ static void process_power_supply(void *data)
        device_notify(DEVICE_NOTIFIER_BATTERY_CHARGING, &battery.charge_now);
 }
 
-static void battery_state(struct battery_info *info)
+static int battery_state(struct battery_info *info)
 {
-       if (!info)
-               return;
+       static struct battery_status prev_status;
 
-       _I("status=%s(%s) power_source=%s(%d) capa=%d health=%s present=%d current=%d(%d) volt=%d(%d) temp=%d",
-                       info->status,
-                       battery.charge_now == CHARGER_CHARGING ? "Charging"
-                               : (battery.charge_now == CHARGER_DISCHARGING ? "Discharging" : "Abnormal"),
-                       info->power_source,
-                       info->online,
-                       info->capacity,
-                       info->health,
-                       info->present,
-                       info->current_now,
-                       info->current_average,
-                       info->voltage_now,
-                       info->voltage_average,
-                       info->temperature);
+       if (!info) {
+               memcpy(&prev_status, &battery, sizeof(battery));
+               return 0;
+       }
+
+       if (prev_status.capacity == battery.capacity &&
+           prev_status.charge_status == battery.charge_status &&
+           prev_status.charge_full == battery.charge_full &&
+           prev_status.charge_now == battery.charge_now &&
+           prev_status.health == battery.health &&
+           prev_status.present == battery.present &&
+           prev_status.online == battery.online)
+               return 0;
+
+       prev_status.capacity = battery.capacity;
+       prev_status.charge_status = battery.charge_status;
+       prev_status.charge_full = battery.charge_full;
+       prev_status.charge_now = battery.charge_now;
+       prev_status.health = battery.health;
+       prev_status.present = battery.present;
+       prev_status.online = battery.online;
+
+       return 1;
 }
 
 static void battery_changed(struct battery_info *info, void *data)
 {
        int ret;
 
-       if (!info)
+       if (!info) {
+               (void)battery_state(NULL);
                return;
+       }
 
        if (info->status) {
                snprintf(battery.status_s, sizeof(battery.status_s),
@@ -753,7 +763,9 @@ static void battery_changed(struct battery_info *info, void *data)
        battery.voltage_average = info->voltage_average;
        battery.temperature = info->temperature;
 
-       battery_state(info);
+       ret = battery_state(info);
+       if (ret != 1)
+               return;
 
        ret = booting_done(NULL);
        if (ret) {