#include "launch.h"
typedef struct _app_status_cb_info_t {
- int (*handler) (int status, void *data);
+ int (*handler)(int status, void *data);
void *data;
- struct _app_status_cb_info_t *next;
} app_status_cb_info_t;
static int (*_aul_status_listen_handler)(const char *appid, const char *pkgid,
int pid, int status, int is_sub_app, void *data);
static void *_aul_status_listen_data;
-static app_status_cb_info_t *app_status_cb;
static int app_status = STATUS_LAUNCHING;
extern int aul_launch_fini();
+static GList *app_status_cb_list;
API int aul_status_update(int status)
{
int ret;
- app_status_cb_info_t *cb = app_status_cb;
+ app_status_cb_info_t *cb;
+ GList *iter;
app_status = status;
(unsigned char *)&status, sizeof(status), AUL_SOCK_NOREPLY);
if (!ret) {
- while (cb) {
- if (cb->handler) {
- if (cb->handler(app_status, cb->data) < 0)
- aul_remove_status_local_cb(cb->handler, cb->data);
+ iter = g_list_first(app_status_cb_list);
+ while (iter) {
+ cb = (app_status_cb_info_t *)iter->data;
+ iter = g_list_next(iter);
+ if (cb && cb->handler) {
+ if (cb->handler(app_status, cb->data) < 0) {
+ app_status_cb_list = g_list_remove(
+ app_status_cb_list, cb);
+ free(cb);
+ }
}
-
- if(cb != NULL)
- cb = cb->next;
}
}
API int aul_add_status_local_cb(int (*func)(int status, void *data), void *data)
{
- app_status_cb_info_t *cb = app_status_cb;
+ app_status_cb_info_t *cb;
+ GList *iter;
if (func == NULL)
return -1;
- /* check known callback */
- while (cb) {
+ iter = g_list_first(app_status_cb_list);
+ while (iter) {
+ cb = (app_status_cb_info_t *)iter->data;
if (cb && cb->handler == func && cb->data == data) {
- /* already in list */
+ _D("Already exists");
return 0;
}
- cb = cb->next;
+
+ iter = g_list_next(iter);
}
cb = (app_status_cb_info_t *)malloc(sizeof(app_status_cb_info_t));
- if (cb == NULL)
+ if (cb == NULL) {
+ _E("out of memory");
return -1;
+ }
cb->handler = func;
cb->data = data;
- cb->next = app_status_cb;
- app_status_cb = cb;
+ app_status_cb_list = g_list_append(app_status_cb_list, cb);
return 0;
}
API int aul_remove_status_local_cb(int (*func)(int status, void *data), void *data)
{
- app_status_cb_info_t *cb = app_status_cb;
- app_status_cb_info_t *tmp = NULL;
-
- if (app_status_cb
- && app_status_cb->handler == func
- && app_status_cb->data == data) {
- cb = app_status_cb->next;
- free(app_status_cb);
- app_status_cb = cb;
- return 0;
- }
+ app_status_cb_info_t *cb;
+ GList *iter;
- while (cb) {
- if (cb->next
- && cb->next->handler == func
- && cb->next->data == data) {
- tmp = cb->next->next;
- free(cb->next);
- cb->next = tmp;
+ iter = g_list_first(app_status_cb_list);
+ while (iter) {
+ cb = (app_status_cb_info_t *)iter->data;
+ iter = g_list_next(iter);
+ if (cb && cb->handler == func && cb->data == data) {
+ app_status_cb_list = g_list_remove(app_status_cb_list, cb);
+ free(cb);
return 0;
}
-
- cb = cb->next;
}
return -1;
API int aul_invoke_status_local_cb(int status)
{
- app_status_cb_info_t *cb = app_status_cb;
-
- while (cb) {
- if (cb->handler) {
- if (cb->handler(status, cb->data) < 0)
- aul_remove_status_local_cb(cb->handler, cb->data);
+ app_status_cb_info_t *cb;
+ GList *iter;
+
+ iter = g_list_first(app_status_cb_list);
+ while (iter) {
+ cb = (app_status_cb_info_t *)iter->data;
+ iter = g_list_next(iter);
+ if (cb && cb->handler) {
+ if (cb->handler(status, cb->data) < 0) {
+ app_status_cb_list = g_list_remove(
+ app_status_cb_list, cb);
+ free(cb);
+ }
}
-
- if(cb != NULL)
- cb = cb->next;
}
return 0;