diff options
author | Randeep Singh <randeep.s@samsung.com> | 2021-06-09 05:06:02 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@review> | 2021-06-09 05:06:02 +0000 |
commit | 30ec80c34d130df17815757667f3523f85374c46 (patch) | |
tree | cf2811d17315cba5d0699add3a11f0abe8d8d837 | |
parent | 355ade454ee6ca74d0709803a350549a22b2e06f (diff) | |
parent | 696a63e366c7d1dd9ffdbeb6b77d06f407d73f1e (diff) | |
download | batterymonitor-30ec80c34d130df17815757667f3523f85374c46.tar.gz batterymonitor-30ec80c34d130df17815757667f3523f85374c46.tar.bz2 batterymonitor-30ec80c34d130df17815757667f3523f85374c46.zip |
Merge "Revert "[Non-ACR] hold pid always, change app_id"" into tizen
-rw-r--r-- | src/battery_dump/bm_listeners.c | 83 |
1 files changed, 33 insertions, 50 deletions
diff --git a/src/battery_dump/bm_listeners.c b/src/battery_dump/bm_listeners.c index f504b97..63c796e 100644 --- a/src/battery_dump/bm_listeners.c +++ b/src/battery_dump/bm_listeners.c @@ -108,16 +108,15 @@ static void bd_set_free_data_object(void) static void bd_get_app_id_from_table(gint pid, char **app_id) { - BD_CHECK_VALIDITY_RETURN((pid_map != NULL), {}); - - if (g_hash_table_size(pid_map) <= 0) { - _WARN("empty app_id-pid map"); + if (pid_map == NULL) { + _ERR("invalid pid_map"); return; } - _DBG("get app_id for pid[%d], table size[%d]", pid, g_hash_table_size(pid_map)); + _DBG("app_id for pid[%d], table size[%d]", pid, g_hash_table_size(pid_map)); - void *orig_pid = NULL, *orig_app_id = NULL; + void *orig_pid = NULL; + void *orig_app_id = NULL; if (g_hash_table_lookup_extended(pid_map, &pid, &orig_pid, &orig_app_id) == true) { *app_id = strdup((char *)orig_app_id); @@ -132,52 +131,22 @@ static void bd_get_app_id_from_table(gint pid, char **app_id) static void bd_insert_app_id_into_table(gint pid, char *appid) { - BD_CHECK_VALIDITY_RETURN((appid != NULL), {}); - - gint* lpid = NULL; - static bool isEmpty = true; - - _DBG("insert app_id for pid[%d], table size[%d]", pid, g_hash_table_size(pid_map)); - - if (!isEmpty) { - gpointer orig_pid = NULL, orig_app_id = NULL; - /* if not empty then check if pid-app_id is redundant */ - if (g_hash_table_lookup_extended(pid_map, &pid, &orig_pid, &orig_app_id) == true) { - /* redundant pid, check if redundant app_id */ - if (g_strcmp0(appid, (char *)orig_app_id) == 0) { - _DBG("redundant pid[%d], app_id[%s]", pid, appid); - return; - } else { - _DBG("replacing pid[%d], app_id[%s]", pid, appid); - /* app_id is not redundant, - * means this pid is assigned to new app_id - * replace old app_id with new app_id, delete old pid-app_id */ - lpid = g_new0(gint, 1); - BD_CHECK_VALIDITY_RETURN((lpid != NULL), {}); - - *lpid = pid; + if (appid == NULL) { + _ERR("invalid appid"); + return; + } - if (g_hash_table_replace(pid_map, lpid, strdup(appid)) == false) - _ERR("failed to replace old app_id"); - } - } else { - GHashTableIter iter; - gpointer stale_pid = NULL, stale_app_id = NULL; - - g_hash_table_iter_init(&iter, pid_map); - /* delete stale pid-app_id */ - while (g_hash_table_iter_next(&iter, &stale_pid, &stale_app_id)) { - if (g_strcmp0(appid, (char *)stale_app_id) == 0) { - _DBG("removed stale - pid[%d], app_id[%s]", \ - *((int *)stale_pid), (char *)stale_app_id); - g_hash_table_iter_remove(&iter); - } - } - } + /* redundant keys are not required */ + if (g_hash_table_contains(pid_map, &pid) == true) { + _DBG("key[%d] already present, no insertion required", pid); + return; } - lpid = g_new0(gint, 1); - BD_CHECK_VALIDITY_RETURN((lpid != NULL), {}); + gint* lpid = g_new0(gint, 1); + if (lpid == NULL) { + _ERR("failed to allocate memory"); + return; + } *lpid = pid; @@ -186,8 +155,19 @@ static void bd_insert_app_id_into_table(gint pid, char *appid) if (g_hash_table_insert(pid_map, lpid, strdup(appid)) == false) _WARN("key already available, replacing old value"); - isEmpty = false; + return; +} +static void bd_remove_app_id_from_table(gint pid) +{ + if (g_hash_table_contains(pid_map, &pid) != true) { + _DBG("key[%d] not present in list", pid); + return; + } + + g_hash_table_remove(pid_map, &pid); + + _DBG("removed key[%d] from table", pid); return; } @@ -2132,6 +2112,9 @@ static void _bd_listener_app_terminate_signal_cb(GDBusConnection *conn, const gc return; } + /* remove app_id from table as terminate signal is received */ + bd_remove_app_id_from_table(pid); + /* get event object */ event_pool *event = bd_listener_get_event_obj(LISTEN_APP_STATUS, val, app_id); if (event == NULL) { |