*/
#include <map>
+#include <sstream>
#include <sqlite3.h>
#include <time.h>
#include <glib.h>
#define DEFAULT_ROW_ID_STR "1"
#define HEART_DB_QUERY_INTERVAL 10 * 60 * 1000
+#define ONE_DAY_IN_SEC 86400
using namespace ctx;
ret = __updateLastCpuUsageLog(lastHeartCpuLog);
IF_FAIL_RETURN_TAG(ret, false, _E, "Failed to update last cpu log");
+ __removeExpiredLog();
+
return true;
}
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");
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);