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);
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;
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;
}
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) {