Adds new APIs to send launch request asynchronous 71/124571/6
authorHwankyu Jhun <h.jhun@samsung.com>
Thu, 13 Apr 2017 08:25:40 +0000 (17:25 +0900)
committerHwankyu Jhun <h.jhun@samsung.com>
Thu, 13 Apr 2017 12:48:36 +0000 (21:48 +0900)
These APIs are for supporting implicit async launch.

Adds:
 - aul_svc_run_service_async
 - aul_svc_run_service_async_for_uid
 - aul_launch_app_with_result_async
 - aul_launch_app_with_result_async_for_uid

Change-Id: Ib27f9aa0e0f4d2ffbe89dd2b09553dcfd4c159be
Signed-off-by: Hwankyu Jhun <h.jhun@samsung.com>
include/aul_cmd.h
include/aul_svc.h
include/launch.h
src/launch.c
src/launch_with_result.c
src/service.c

index 0bdf03c..455a433 100644 (file)
@@ -122,6 +122,7 @@ enum app_cmd {
        APP_STARTUP_SIGNAL = 91,
        APP_WINDOW_ATTACH = 92,
        APP_WINDOW_DETACH = 93,
+       APP_START_RES_ASYNC = 94,
 
        APP_CMD_MAX
 };
index 9b85497..24a163e 100755 (executable)
@@ -1275,6 +1275,23 @@ const char *aul_svc_get_instance_id(bundle *b);
  */
 int aul_svc_set_instance_id(bundle *b, const char *instance_id);
 
+/**
+ * @par Description:
+ *      Sends the launch request asynchronous.
+ *
+ * @param[in]  b                Bundle object
+ * @param[in]  request_code     Request Code
+ * @param[in]  cbfunc           Callback function
+ * @param[in]  data             User data
+ *
+ * @return     a pid of the callee on success,
+ *             otherwise a negative error value
+ */
+int aul_svc_run_service_async(bundle *b, int request_code,
+               aul_svc_res_fn cbfunc, void *data);
+int aul_svc_run_service_async_for_uid(bundle *b, int request_code,
+               aul_svc_res_fn cbfunc, void *data, uid_t uid);
+
 #ifdef __cplusplus
 }
 #endif
index d8d3f7a..04893a2 100644 (file)
@@ -49,4 +49,7 @@ gboolean __aul_glib_handler(gpointer data);
 
 int app_com_recv(bundle *b);
 void app_status_event(bundle *kb);
-
+int aul_launch_app_with_result_async(const char *appid, bundle *b,
+               void (*callback)(bundle *, int, void *), void *data);
+int aul_launch_app_with_result_async_for_uid(const char *appid, bundle *b,
+               void (*callback)(bundle *, int, void *), void *data, uid_t uid);
index a64ffcf..e57f92e 100755 (executable)
@@ -332,6 +332,7 @@ int app_request_to_launchpad_for_uid(int cmd, const char *appid, bundle *kb, uid
                case APP_START_RES:
                case APP_START_ASYNC:
                case WIDGET_UPDATE:
+               case APP_START_RES_ASYNC:
                        b = bundle_dup(kb);
                        ret = __app_launch_local(b);
                        break;
@@ -449,6 +450,7 @@ int aul_sock_handler(int fd)
        case APP_START: /* run in callee */
        case APP_START_RES:
        case APP_START_ASYNC:
+       case APP_START_RES_ASYNC:
                app_start(kbundle);
                break;
 
index 0e7d63c..0c8fab9 100644 (file)
@@ -304,19 +304,11 @@ int app_result(int cmd, bundle *kb, int launched_pid)
        return 0;
 }
 
-API int aul_launch_app_with_result(const char *pkgname, bundle *kb,
-                              void (*cbfunc) (bundle *, int, void *),
-                              void *data)
-{
-       return aul_launch_app_with_result_for_uid(pkgname, kb, cbfunc, data, getuid());
-}
-
-API int aul_launch_app_with_result_for_uid(const char *pkgname, bundle *kb,
-                              void (*cbfunc) (bundle *, int, void *),
-                              void *data, uid_t uid)
+static int __launch_app_with_result(int cmd, const char *appid, bundle *kb,
+               void (*callback)(bundle *, int, void *), void *data, uid_t uid)
 {
        int ret;
-       char num_str[MAX_LOCAL_BUFSZ] = { 0, };
+       char num_str[MAX_LOCAL_BUFSZ];
        int num;
 
        if (!aul_is_initialized()) {
@@ -324,22 +316,36 @@ API int aul_launch_app_with_result_for_uid(const char *pkgname, bundle *kb,
                        return AUL_R_ENOINIT;
        }
 
-       if (pkgname == NULL || cbfunc == NULL || kb == NULL)
+       if (appid == NULL || callback == NULL || kb == NULL)
                return AUL_R_EINVAL;
 
        num = __gen_seq_num();
-       snprintf(num_str, MAX_LOCAL_BUFSZ, "%d", num);
+       snprintf(num_str, sizeof(num_str), "%d", num);
        bundle_del(kb, AUL_K_SEQ_NUM);
        bundle_add(kb, AUL_K_SEQ_NUM, num_str);
 
-       ret = app_request_to_launchpad_for_uid(APP_START_RES, pkgname, kb, uid);
-
+       ret = app_request_to_launchpad_for_uid(cmd, appid, kb, uid);
        if (ret > 0)
-               __add_resultcb(ret, cbfunc, data, num);
+               __add_resultcb(ret, callback, data, num);
 
        return ret;
 }
 
+API int aul_launch_app_with_result(const char *pkgname, bundle *kb,
+                              void (*cbfunc) (bundle *, int, void *),
+                              void *data)
+{
+       return __launch_app_with_result(APP_START_RES, pkgname, kb, cbfunc,
+                       data, getuid());
+}
+
+API int aul_launch_app_with_result_for_uid(const char *pkgname, bundle *kb,
+               void (*cbfunc) (bundle *, int, void *), void *data, uid_t uid)
+{
+       return __launch_app_with_result(APP_START_RES, pkgname, kb, cbfunc,
+                       data, uid);
+}
+
 void __iterate(const char *key, const char *val, void *data)
 {
        static int i = 0;
@@ -645,3 +651,17 @@ API int aul_invoke_caller_cb(void *data)
 
        return 0;
 }
+
+API int aul_launch_app_with_result_async(const char *appid, bundle *b,
+               void (*callback)(bundle *, int, void *), void *data)
+{
+       return __launch_app_with_result(APP_START_RES_ASYNC, appid, b, callback,
+                       data, getuid());
+}
+
+API int aul_launch_app_with_result_async_for_uid(const char *appid, bundle *b,
+               void (*callback)(bundle *, int, void *), void *data, uid_t uid)
+{
+       return __launch_app_with_result(APP_START_RES_ASYNC, appid, b, callback,
+                       data, uid);
+}
index 48a497b..d86a99d 100755 (executable)
@@ -77,7 +77,7 @@ static void __remove_rescb(aul_svc_cb_info_t *info);
 static int __set_bundle(bundle *b, const char *key, const char *value);
 static void __aul_cb(bundle *b, int is_cancel, void *data);
 static int __run_svc_with_pkgname(char *pkgname, bundle *b, int request_code,
-                               aul_svc_res_fn cbfunc, void *data, uid_t uid);
+               aul_svc_res_fn cbfunc, void *data, uid_t uid, bool sync);
 static int __get_resolve_info(bundle *b, aul_svc_resolve_info_t *info);
 static int __free_resolve_info_data(aul_svc_resolve_info_t *info);
 
@@ -196,7 +196,7 @@ static void __aul_cb(bundle *b, int is_cancel, void *data)
 }
 
 static int __run_svc_with_pkgname(char *pkgname, bundle *b, int request_code,
-                               aul_svc_res_fn cbfunc, void *data, uid_t uid)
+               aul_svc_res_fn cbfunc, void *data, uid_t uid, bool sync)
 {
        aul_svc_cb_info_t *cb_info = NULL;
        int ret = -1;
@@ -222,8 +222,13 @@ static int __run_svc_with_pkgname(char *pkgname, bundle *b, int request_code,
                SECURE_LOGD("pkg_name : %s - with result", pkgname);
 
                cb_info = __create_rescb(request_code, cbfunc, data);
-               ret = aul_launch_app_with_result_for_uid(pkgname, b, __aul_cb,
-                               cb_info, uid);
+               if (sync) {
+                       ret = aul_launch_app_with_result_for_uid(pkgname, b,
+                                       __aul_cb, cb_info, uid);
+               } else {
+                       ret = aul_launch_app_with_result_async_for_uid(pkgname,
+                                       b, __aul_cb, cb_info, uid);
+               }
        } else {
                SECURE_LOGD("pkg_name : %s - no result", pkgname);
 
@@ -232,12 +237,25 @@ static int __run_svc_with_pkgname(char *pkgname, bundle *b, int request_code,
                if (data)
                        SECURE_LOGD("multi_instance value = %s", data);
 
-               if (data && strncmp(data, "TRUE", strlen("TRUE")) == 0)
-                       ret = aul_launch_app_for_multi_instance(pkgname, b);
-               else
-                       ret = aul_launch_app(pkgname, b);
+               if (data && strncmp(data, "TRUE", strlen("TRUE")) == 0) {
+                       if (sync) {
+                               ret = aul_launch_app_for_multi_instance(pkgname,
+                                               b);
+                       } else {
+                               ret = aul_launch_app_for_multi_instance_async(
+                                               pkgname, b);
+                       }
+               } else {
+                       if (sync)
+                               ret = aul_launch_app(pkgname, b);
+                       else
+                               ret = aul_launch_app_async(pkgname, b, uid);
+               }
 #else
-               ret = aul_launch_app_for_uid(pkgname, b, uid);
+               if (sync)
+                       ret = aul_launch_app_for_uid(pkgname, b, uid);
+               else
+                       ret = aul_launch_app_async_for_uid(pkgname, b, uid);
 #endif
        }
 
@@ -824,14 +842,8 @@ API int aul_svc_set_launch_mode(bundle *b, const char *mode)
        return __set_bundle(b, AUL_SVC_K_LAUNCH_MODE, mode);
 }
 
-API int aul_svc_run_service(bundle *b, int request_code,
-                                       aul_svc_res_fn cbfunc, void *data)
-{
-       return aul_svc_run_service_for_uid(b, request_code, cbfunc, data, getuid());
-}
-
-API int aul_svc_run_service_for_uid(bundle *b, int request_code,
-                               aul_svc_res_fn cbfunc, void *data, uid_t uid)
+static int __run_service(bundle *b, int request_code,
+               aul_svc_res_fn cbfunc, void *data, uid_t uid, bool sync)
 {
        aul_svc_resolve_info_t info;
        char *pkgname;
@@ -840,7 +852,6 @@ API int aul_svc_run_service_for_uid(bundle *b, int request_code,
        int ret = -1;
        char *appid;
        int l;
-
        GSList *pkg_list = NULL;
        char *query = NULL;
        gchar *checksum;
@@ -858,7 +869,7 @@ API int aul_svc_run_service_for_uid(bundle *b, int request_code,
                if (operation == NULL)
                        aul_svc_set_operation(b, AUL_SVC_OPERATION_DEFAULT);
                ret = __run_svc_with_pkgname(pkgname, b, request_code, cbfunc,
-                               data, uid);
+                               data, uid, sync);
                return ret;
        }
 
@@ -867,7 +878,7 @@ API int aul_svc_run_service_for_uid(bundle *b, int request_code,
                || strcmp(operation, AUL_SVC_OPERATION_MULTI_SHARE) == 0
                || strcmp(operation, AUL_SVC_OPERATION_SHARE_TEXT) == 0)) {
                ret = __run_svc_with_pkgname(SHARE_PANEL, b, request_code,
-                               cbfunc, data, uid);
+                               cbfunc, data, uid, sync);
                return ret;
        }
 
@@ -890,12 +901,12 @@ API int aul_svc_run_service_for_uid(bundle *b, int request_code,
                if (!strncmp("@APP_SELECTOR ", appid, l)) {
                        bundle_add(b, AUL_SVC_K_URI_R_INFO, &appid[l]);
                        ret = __run_svc_with_pkgname(APP_SELECTOR, b, request_code,
-                               cbfunc, data, uid);
+                               cbfunc, data, uid, sync);
                } else if (!strcmp(appid, "^")) {
                        ret = AUL_SVC_RET_ENOMATCH;
                } else {
                        ret = __run_svc_with_pkgname(appid, b, request_code,
-                               cbfunc, data, uid);
+                               cbfunc, data, uid, sync);
                }
                free(appid);
                g_free(checksum);
@@ -915,7 +926,7 @@ API int aul_svc_run_service_for_uid(bundle *b, int request_code,
        if (pkgname != NULL) {
                __put_cache(checksum, pkgname, uid);
                ret = __run_svc_with_pkgname(pkgname, b, request_code,
-                       cbfunc, data, uid);
+                       cbfunc, data, uid, sync);
                free(pkgname);
                goto end;
        }
@@ -971,14 +982,14 @@ API int aul_svc_run_service_for_uid(bundle *b, int request_code,
                        if (pkgname != NULL) {
                                __put_cache(checksum, pkgname, uid);
                                ret = __run_svc_with_pkgname(pkgname, b, request_code,
-                                               cbfunc, data, uid);
+                                               cbfunc, data, uid, sync);
                                goto end;
                        }
                } else if (pkg_count > 1) {
                        bundle_add(b, AUL_SVC_K_URI_R_INFO, info.uri);
                        __put_cache_with_info(checksum, info.uri, uid);
                        ret = __run_svc_with_pkgname(APP_SELECTOR, b, request_code,
-                                       cbfunc, data, uid);
+                                       cbfunc, data, uid, sync);
                        goto end;
                }
                __free_pkg_list(pkg_list);
@@ -992,7 +1003,7 @@ API int aul_svc_run_service_for_uid(bundle *b, int request_code,
                if (pkgname != NULL) {
                        __put_cache(checksum, pkgname, uid);
                        ret = __run_svc_with_pkgname(pkgname, b, request_code,
-                                       cbfunc, data, uid);
+                                       cbfunc, data, uid, sync);
                        free(pkgname);
                        goto end;
                }
@@ -1039,14 +1050,14 @@ API int aul_svc_run_service_for_uid(bundle *b, int request_code,
                                if (pkgname != NULL) {
                                        __put_cache(checksum, pkgname, uid);
                                        ret = __run_svc_with_pkgname(pkgname, b, request_code,
-                                                       cbfunc, data, uid);
+                                                       cbfunc, data, uid, sync);
                                        goto end;
                                }
                        } else if (pkg_count > 1) {
                                bundle_add(b, AUL_SVC_K_URI_R_INFO, info.uri_r_info);
                                __put_cache_with_info(checksum, info.uri_r_info, uid);
                                ret = __run_svc_with_pkgname(APP_SELECTOR, b, request_code,
-                                       cbfunc, data, uid);
+                                       cbfunc, data, uid, sync);
                                goto end;
                        }
 
@@ -1061,7 +1072,7 @@ API int aul_svc_run_service_for_uid(bundle *b, int request_code,
        if (pkgname != NULL) {
                __put_cache(checksum, pkgname, uid);
                ret = __run_svc_with_pkgname(pkgname, b, request_code,
-                       cbfunc, data, uid);
+                       cbfunc, data, uid, sync);
                free(pkgname);
                goto end;
        }
@@ -1099,7 +1110,7 @@ API int aul_svc_run_service_for_uid(bundle *b, int request_code,
                if (pkgname != NULL) {
                        __put_cache(checksum, pkgname, uid);
                        ret = __run_svc_with_pkgname(pkgname, b, request_code,
-                                       cbfunc, data, uid);
+                                       cbfunc, data, uid, sync);
                }
        } else if (pkg_count < 1) {
                __free_resolve_info_data(&info);
@@ -1110,7 +1121,7 @@ API int aul_svc_run_service_for_uid(bundle *b, int request_code,
                bundle_add(b, AUL_SVC_K_URI_R_INFO, info.scheme);
                __put_cache_with_info(checksum, info.scheme, uid);
                ret = __run_svc_with_pkgname(APP_SELECTOR, b, request_code,
-                               cbfunc, data, uid);
+                               cbfunc, data, uid, sync);
        }
 
 end:
@@ -1121,6 +1132,18 @@ end:
        return ret;
 }
 
+API int aul_svc_run_service(bundle *b, int request_code,
+               aul_svc_res_fn cbfunc, void *data)
+{
+       return __run_service(b, request_code, cbfunc, data, getuid(), true);
+}
+
+API int aul_svc_run_service_for_uid(bundle *b, int request_code,
+               aul_svc_res_fn cbfunc, void *data, uid_t uid)
+{
+       return __run_service(b, request_code, cbfunc, data, uid, true);
+}
+
 API int aul_svc_get_list(bundle *b, aul_svc_info_iter_fn iter_fn,
                void *data)
 {
@@ -1830,3 +1853,15 @@ API int aul_svc_set_instance_id(bundle *b, const char *instance_id)
 
        return __set_bundle(b, AUL_K_INSTANCE_ID, instance_id);
 }
+
+API int aul_svc_run_service_async(bundle *b, int request_code,
+               aul_svc_res_fn cbfunc, void *data)
+{
+       return __run_service(b, request_code, cbfunc, data, getuid(), false);
+}
+
+API int aul_svc_run_service_async_for_uid(bundle *b, int request_code,
+               aul_svc_res_fn cbfunc, void *data, uid_t uid)
+{
+       return __run_service(b, request_code, cbfunc, data, uid, false);
+}