}
typedef struct _event_cb_context_ {
+ aul_app_event_h handle;
GHashTable *pid_table;
app_manager_app_context_event_cb callback;
void *user_data;
static bool __load_all_app_context_cb_locked(app_context_h app_context,
void *user_data)
{
- app_context_h app_context_cloned;
char *app_id = NULL;
int pid;
- int ret;
-
- ret = app_context_clone(&app_context_cloned, app_context);
- if (ret != APP_MANAGER_ERROR_NONE) {
- _E("Failed to clone app context");
- return false;
- }
app_context_get_app_id(app_context, &app_id);
app_context_get_pid(app_context, &pid);
free(app_id);
g_hash_table_insert(event_cb_context->pid_table, GINT_TO_POINTER(pid),
- app_context_cloned);
+ GINT_TO_POINTER(pid));
return true;
}
-static int app_context_launched_event_cb(pid_t pid, const char *app_id,
- void *data)
+static void __app_context_launched_event_cb(aul_app_context_h app_context,
+ void *user_data)
{
- app_context_h app_context;
- int ret;
-
- if (pid < 0 || app_id == NULL) {
- _E("Invalid parameter");
- return -1;
- }
-
- ret = app_context_get_app_context_by_pid(pid, &app_context);
- if (ret != APP_MANAGER_ERROR_NONE) {
- _E("Failed to create app context. pid(%d), error(%d)",
- pid, ret);
- return ret;
- }
+ int pid;
+ aul_app_context_get_pid(app_context, &pid);
app_context_lock_event_cb_context();
-
if (event_cb_context && event_cb_context->pid_table) {
g_hash_table_insert(event_cb_context->pid_table,
- GINT_TO_POINTER(pid), app_context);
- event_cb_context->callback(app_context,
+ GINT_TO_POINTER(pid), GINT_TO_POINTER(pid));
+ event_cb_context->callback((app_context_h)app_context,
APP_CONTEXT_EVENT_LAUNCHED,
event_cb_context->user_data);
} else {
- _E("Invalid context");
- app_context_destroy(app_context);
+ _E("Invalid context. pid(%d)", pid);
}
-
app_context_unlock_event_cb_context();
-
- return 0;
}
-static int app_context_terminated_event_cb(pid_t pid, void *data)
+static void __app_context_terminated_event_cb(aul_app_context_h app_context,
+ void *user_data)
{
- app_context_h app_context;
+ int pid;
+ aul_app_context_get_pid(app_context, &pid);
app_context_lock_event_cb_context();
-
if (event_cb_context && event_cb_context->pid_table) {
- app_context = g_hash_table_lookup(event_cb_context->pid_table,
- GINT_TO_POINTER(pid));
- if (app_context) {
+ if (g_hash_table_contains(event_cb_context->pid_table,
+ GINT_TO_POINTER(pid))) {
event_cb_context->callback(app_context,
APP_CONTEXT_EVENT_TERMINATED,
event_cb_context->user_data);
GINT_TO_POINTER(pid));
}
} else {
- _E("Invalid context");
+ _E("Invalid context. pid(%d)", pid);
}
-
app_context_unlock_event_cb_context();
-
- return 0;
}
static void __event_cb_context_fini(void)
if (!event_cb_context)
return;
- aul_listen_app_dead_signal(NULL, NULL);
- aul_listen_app_launch_signal_v2(NULL, NULL);
+ if (event_cb_context->handle)
+ aul_app_event_destroy(event_cb_context->handle);
if (event_cb_context->pid_table)
g_hash_table_destroy(event_cb_context->pid_table);
static int __event_cb_context_init(void)
{
+ int ret;
+
if (event_cb_context)
return APP_MANAGER_ERROR_NONE;
return APP_MANAGER_ERROR_OUT_OF_MEMORY;
}
- event_cb_context->pid_table = g_hash_table_new_full(g_direct_hash,
- g_direct_equal, NULL,
- (GDestroyNotify)app_context_destroy);
+ event_cb_context->pid_table = g_hash_table_new(g_direct_hash,
+ g_direct_equal);
if (event_cb_context->pid_table == NULL) {
_E("Failed to create hash table");
__event_cb_context_fini();
}
app_context_foreach_app_context(__load_all_app_context_cb_locked, NULL);
- aul_listen_app_dead_signal(app_context_terminated_event_cb, NULL);
- aul_listen_app_launch_signal_v2(app_context_launched_event_cb, NULL);
+
+ ret = aul_app_event_create(__app_context_launched_event_cb,
+ __app_context_terminated_event_cb,
+ NULL,
+ &event_cb_context->handle);
+ if (ret != AUL_R_OK) {
+ _E("aul_app_context_create() is failed. error(%d)", ret);
+ __event_cb_context_fini();
+ return APP_MANAGER_ERROR_OUT_OF_MEMORY;
+ }
return APP_MANAGER_ERROR_NONE;
}
if (!info)
return APP_MANAGER_ERROR_OUT_OF_MEMORY;
- ret = aul_app_event_create(appid,
+ ret = aul_app_event_create_with_appid(appid,
__aul_app_event_launched_cb,
__aul_app_event_terminated_cb,
info,