[battery-stats] Remove expired log & Version 0.9.11 72/106572/3
authorSomin Kim <somin926.kim@samsung.com>
Thu, 22 Dec 2016 05:36:58 +0000 (14:36 +0900)
committerSomin Kim <somin926.kim@samsung.com>
Thu, 22 Dec 2016 07:32:17 +0000 (23:32 -0800)
Change-Id: I95508ae62154f37c88a02d5748c46580776e6ef3
Signed-off-by: Somin Kim <somin926.kim@samsung.com>
packaging/context-provider.spec
src/battery-stats/BatteryMonitor.cpp
src/battery-stats/BatteryMonitor.h

index cc39fd3..d973523 100644 (file)
@@ -1,6 +1,6 @@
 Name:       context-provider
 Summary:    Context Provider
-Version:    0.9.10
+Version:    0.9.11
 Release:    1
 Group:      Service/Context
 License:    Apache-2.0
index d7dee42..4c34e8c 100644 (file)
@@ -15,6 +15,7 @@
  */
 
 #include <map>
+#include <sstream>
 #include <sqlite3.h>
 #include <time.h>
 #include <glib.h>
@@ -25,6 +26,7 @@
 
 #define DEFAULT_ROW_ID_STR "1"
 #define HEART_DB_QUERY_INTERVAL 10 * 60 * 1000
+#define ONE_DAY_IN_SEC 86400
 
 using namespace ctx;
 
@@ -227,6 +229,8 @@ bool BatteryMonitor::__processBatteryUsage()
        ret = __updateLastCpuUsageLog(lastHeartCpuLog);
        IF_FAIL_RETURN_TAG(ret, false, _E, "Failed to update last cpu log");
 
+       __removeExpiredLog();
+
        return true;
 }
 
@@ -263,6 +267,21 @@ bool BatteryMonitor::__insertBatteryUsageLog(std::vector<Json>& usage)
        return __dbMgr.executeSync(query.c_str(), NULL);
 }
 
+void BatteryMonitor::__removeExpiredLog()
+{
+       static int lastCleanupTime = 0;
+
+       int currentTime = CURRENT_TIME;
+       IF_FAIL_VOID(currentTime - lastCleanupTime >= ONE_DAY_IN_SEC);
+       lastCleanupTime = currentTime;
+
+       std::stringstream query;
+       query << "DELETE FROM " BATTERY_USAGE_TABLE " WHERE " \
+               "EndTime < strftime('%s', 'now') - " << LOG_RETENTION_PERIOD;
+       __dbMgr.execute(0, query.str().c_str(), NULL);
+       _D("Remove expired log");
+}
+
 bool BatteryMonitor::__updateLastCpuUsageLog(CpuUsageMap& usage)
 {
        IF_FAIL_RETURN_TAG(usage.size(), true, _W, "No data");
index 89bf7f0..4127b09 100644 (file)
@@ -46,6 +46,7 @@ namespace ctx {
                bool __insertBatteryUsageLog(std::vector<Json>& usage);
                bool __updateLastCpuUsageLog(CpuUsageMap& usage);
                bool __getLastCpuUsageTable(CpuUsageMap* lastCpuUsage);
+               void __removeExpiredLog();
 
                static void __chargerChangeCb(device_callback_e type, void* value, void* userData);
                static int __timeoutCb(void* data);