int launched_pid;
void (*cb_func) (bundle *kb, int is_cancel, void *data);
void *priv_data;
+ void (*caller_cb) (int launched_pid, void *data);
+ void *caller_data;
struct _app_resultcb_info_t *next;
} app_resultcb_info_t;
app_resultcb_info_t *info;
info = (app_resultcb_info_t *) malloc(sizeof(app_resultcb_info_t));
- if(info == NULL)
+ if (info == NULL)
return;
info->launched_pid = pid;
info->cb_func = cbfunc;
info->priv_data = data;
+ info->caller_cb = NULL;
+ info->caller_data = NULL;
info->next = rescb_head;
rescb_head = info;
return -1;
/* In case of aul_forward_app, update the callback data */
- if(is_cancel == 1 &&
- (fwdpid_str = (char *)bundle_get_val(kb, AUL_K_FWD_CALLEE_PID)))
- {
+ if (is_cancel == 1 &&
+ (fwdpid_str = (char *)bundle_get_val(kb, AUL_K_FWD_CALLEE_PID))) {
app_resultcb_info_t newinfo;
newinfo.launched_pid = atoi(fwdpid_str);
newinfo.cb_func = info->cb_func;
newinfo.priv_data = info->priv_data;
+ newinfo.caller_cb = NULL;
+ newinfo.caller_data = NULL;
+
+ if (info->caller_cb) {
+ info->caller_cb(newinfo.launched_pid, info->caller_data);
+ }
__remove_resultcb(info);
__add_resultcb(newinfo.launched_pid, newinfo.cb_func, newinfo.priv_data);
- _D("change callback - %s\n",AUL_K_FWD_CALLEE_PID);
+ _D("change callback, fwd pid: %d", newinfo.launched_pid);
goto end;
}
int pid;
pid_str = bundle_get_val(kb, AUL_K_ORG_CALLER_PID);
- if(pid_str)
+ if (pid_str)
goto end;
pid_str = bundle_get_val(kb, AUL_K_CALLER_PID);
return 0;
str = bundle_get_val(kb, AUL_K_NO_CANCEL);
- if( str && strncmp("1", str, 1) == 0) {
+ if ( str && strncmp("1", str, 1) == 0) {
_D("no cancel");
return 0;
}
bundle *outb;
char tmp_pid[MAX_PID_STR_BUFSZ];
- if(pkgname == NULL || kb == NULL)
+ if (pkgname == NULL || kb == NULL)
return AUL_R_EINVAL;
caller = (char *)bundle_get_val(kb, AUL_K_CALLER_PID);
- if(caller == NULL) {
+ if (caller == NULL) {
_E("original msg doest not have caller pid");
return AUL_R_EINVAL;
}
bundle_add(kb, AUL_K_ORG_CALLER_PID, caller);
dupb = bundle_dup(kb);
- if(dupb == NULL) {
+ if (dupb == NULL) {
_E("bundle duplicate fail");
return AUL_R_EINVAL;
}
- if(bundle_get_val(kb, AUL_K_WAIT_RESULT) != NULL) {
+ if (bundle_get_val(kb, AUL_K_WAIT_RESULT) != NULL) {
ret = app_request_to_launchpad(APP_START_RES, pkgname, kb);
- if(ret < 0)
+ if (ret < 0)
goto end;
} else {
ret = app_request_to_launchpad(APP_START, pkgname, kb);
snprintf(tmp_pid, MAX_PID_STR_BUFSZ,"%d",ret);
ret = aul_create_result_bundle(dupb, &outb);
- if(ret < 0)
+ if (ret < 0)
goto end;
bundle_del(outb, AUL_K_FWD_CALLEE_PID);
*outb = NULL;
- if(inb == NULL){
+ if (inb == NULL){
_E("return msg create fail");
return AUL_R_EINVAL;
}
return AUL_R_ERROR;
}
- if(bundle_get_val(inb, AUL_K_WAIT_RESULT) != NULL) {
+ if (bundle_get_val(inb, AUL_K_WAIT_RESULT) != NULL) {
bundle_add(*outb, AUL_K_SEND_RESULT, "1");
_D("original msg is msg with result");
} else {
pid_str = bundle_get_val(inb, AUL_K_ORG_CALLER_PID);
- if(pid_str) {
+ if (pid_str) {
bundle_add(*outb, AUL_K_ORG_CALLER_PID, pid_str);
goto end;
}
bundle_add(kb, AUL_K_CALLEE_PID, tmp_pid);
ret = aul_app_get_appid_bypid(callee_pid, callee_appid, sizeof(callee_appid));
- if(ret == 0) {
+ if (ret == 0) {
bundle_add(kb, AUL_K_CALLEE_APPID, callee_appid);
} else {
_W("fail(%d) to get callee appid by pid", ret);
_D("app_send_cmd_with_noreply : %d", ret);
- if(latest_caller_pid == pid)
+ if (latest_caller_pid == pid)
latest_caller_pid = -1;
return ret;
int app_subapp_terminate_request()
{
- if(is_subapp) {
+ if (is_subapp) {
subapp_cb(subapp_data);
return 0;
return AUL_R_EINVAL;
info = __find_resultcb(pid);
- if(info)
+ if (info)
__remove_resultcb(info);
snprintf(pid_str, MAX_PID_STR_BUFSZ, "%d", pid);
{
return is_subapp;
}
+
+SLPAPI int aul_add_caller_cb(int pid, void (*caller_cb) (int, void *), void *data)
+{
+ app_resultcb_info_t *info;
+
+ if (pid <= 0)
+ return AUL_R_EINVAL;
+
+ info = __find_resultcb(pid);
+ if (info == NULL)
+ return AUL_E_ERROR;
+
+ info->caller_cb = caller_cb;
+ info->caller_data = data;
+
+ return AUL_R_OK;
+}
+
+SLPAPI int aul_remove_caller_cb(int pid)
+{
+ app_resultcb_info_t *info;
+
+ if (pid <= 0)
+ return AUL_R_EINVAL;
+
+ info = __find_resultcb(pid);
+ if (info == NULL)
+ return AUL_E_ERROR;
+
+ info->caller_cb = NULL;
+ info->caller_data = NULL;
+
+ return AUL_R_OK;
+}
+
+static gboolean __invoke_caller_cb(gpointer data)
+{
+ int launched_pid = 0;
+ app_resultcb_info_t *info;
+
+ if (data == NULL)
+ return G_SOURCE_REMOVE;
+
+ launched_pid = GPOINTER_TO_INT(data);
+
+ info = __find_resultcb(launched_pid);
+
+ if (info && info->caller_cb)
+ info->caller_cb(info->launched_pid, info->caller_data);
+
+ return G_SOURCE_REMOVE;
+}
+
+SLPAPI int aul_invoke_caller_cb(int pid)
+{
+ if (g_idle_add_full(G_PRIORITY_DEFAULT, __invoke_caller_cb, GINT_TO_POINTER(pid), NULL) > 0)
+ return -1;
+
+ return 0;
+}