old_state->state_2 = 0;
old_state->usage_type = 0;
old_state->usage = 0;
- //TEMP: Change to 0;
old_state->battery_level = -1;
old_state->battery_status = -1;
old_state->battery_health = -1;
return BATTERY_MONITOR_ERROR_NONE;
}
+static int bd_dump_data_item_reset(dump_data_s* old_state)
+{
+ ENTER;
+ BM_CHECK_INPUT_PARAM(old_state);
+
+ old_state->time_s = -1;
+ old_state->time_current = -1;
+ old_state->dump_1 = 0;
+ old_state->dump_2 = 0;
+ old_state->state_1 = 0;
+ old_state->state_2 = 0;
+ old_state->battery_chargeUAh = 0;
+ old_state->usage_type = 0;
+ old_state->usage = 0;
+ old_state->event_code = ET_NONE;
+ old_state->event_tag = NULL;
+ old_state->wakelock_tag = NULL;
+ old_state->wakereason_tag = NULL;
+
+ EXIT;
+ return BATTERY_MONITOR_ERROR_NONE;
+}
+
+static int bd_free_history_data_memory()
+{
+ ENTER;
+
+ int ret = BATTERY_MONITOR_ERROR_NONE;
+ h_flag = false; //Lock
+ _DBG("Free History Data Memory");
+ for (int i = 0; i < h_count; i++) {
+ if (history_data[i].wakelock_tag != NULL) {
+ _DBG("WL str");
+ g_string_free (history_data[i].wakelock_tag->string_info, TRUE);
+ _DBG("WL");
+ free(history_data[i].wakelock_tag);
+ }
+ if (history_data[i].wakereason_tag != NULL) {
+ _DBG("WR str");
+ g_string_free(history_data[i].wakereason_tag->string_info, TRUE);
+ _DBG("WR");
+ free(history_data[i].wakereason_tag);
+ }
+ if (history_data[i].event_tag != NULL) {
+ _DBG("ET str");
+ g_string_free(history_data[i].event_tag->string_info, TRUE);
+ _DBG("ET");
+ free(history_data[i].event_tag);
+ }
+ ret = bd_dump_data_item_reset(&history_data[i]);
+ if (ret != BATTERY_MONITOR_ERROR_NONE)
+ _ERR("Internal error %d while freeing at idx %d", ret , i);
+ }
+
+ h_count = 0; h_flag = true;
+ EXIT;
+ return ret;
+}
+
static int bd_set_history_from_listener(history_item_s* nrec)
{
ENTER;
time_t current_time = tv.tv_sec;
-
#ifdef DUMP_DUMMY
history_data[h_count].time_s = nrec->time_s;
#else
if (nrec->wakereason_tag != NULL)
history_data[h_count].wakereason_tag = nrec->wakereason_tag;
if (nrec->event_code != ET_NONE) {
- if (nrec->event_tag == NULL)
- _ERR("IT is NULL");
+ if (nrec->event_tag == NULL) {
+ _ERR("ET is NULL but Event Code is not");
+ BM_FREE(history_data[h_count].wakelock_tag);
+ BM_FREE(history_data[h_count].wakereason_tag);
+ bd_dump_data_item_reset(&history_data[h_count]);
+ return BATTERY_MONITOR_ERROR_NO_DATA;
+ }
history_data[h_count].event_code = nrec->event_code;
history_data[h_count].event_tag = nrec->event_tag;
}
history_data[h_count].usage_type = nrec->usage_type;
history_data[h_count].usage = nrec->usage;
+ nrec->event_tag = NULL; nrec->wakereason_tag = NULL;
+ nrec->wakelock_tag = NULL;
if (h_count < HISTORY_SIZE_MAX - 1)
h_count++;
else {
h_count = 0;
return ret;
}
- h_count = 0;
+ ret = bd_free_history_data_memory();
+ if (ret != BATTERY_MONITOR_ERROR_NONE) {
+ _WARN("Error while memory free %x", ret);
+ return ret;
+ }
}
EXIT;
return BATTERY_MONITOR_ERROR_NOT_INITIALIZED;
}
+ ret = bd_free_history_data_memory();
+ if (ret != BATTERY_MONITOR_ERROR_NONE)
+ _WARN("memory free failed (%x)", ret);
+
_INFO("Battery Dump De-Init Successful");
EXIT;
ts->event_tag = (history_tag_s *)calloc(1, sizeof(history_tag_s));
if (ts->event_tag != NULL) {
_DBG("Memory created successfully");
- GString *temp = ts->event_tag->string_info;
+ GString *temp = NULL;
temp = g_string_sized_new(30);
BM_CHECK_MEM_ALLOC(temp, {});
ts->event_tag->uid = 1000; //All events are associated with tizen
} else
ts->event_tag->sp_idx = pool_idx++;
- _DBG("Value of ON is %d:" on);
- temp = g_string_append(temp, "tizen");
+ _DBG("Value of ON is %d:", on);
+ g_string_append(temp, "tizen");
ts->event_tag->string_info = temp;
_DBG("%s", ts->event_tag->string_info->str);
}
ts->wakelock_tag = (history_tag_s *)calloc(1, sizeof(history_tag_s));
if (ts->wakelock_tag != NULL) {
_DBG("Memory created successfully");
- GString *temp = ts->wakelock_tag->string_info;
+ GString *temp = NULL;
temp = g_string_sized_new(30);
BM_CHECK_MEM_ALLOC(temp, {});
ts->wakelock_tag->uid = 1000;
} else
ts->wakelock_tag->sp_idx = pool_idx++;
- _DBG("Value of ON is %d:" on);
- temp = g_string_append(temp, "tizen");
+ _DBG("Value of ON is %d:", on);
+ g_string_append(temp, "tizen");
ts->wakelock_tag->string_info = temp;
_DBG("%s", ts->wakelock_tag->string_info->str);
}