From: Hwankyu Jhun Date: Sun, 3 Feb 2019 10:57:01 +0000 (+0900) Subject: Support handling of each app-control action X-Git-Tag: submit/tizen/20190308.063359~1^2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=409d18ac8e7f793bfd7e4aa55ef6d7ca9a8dfbfe;p=platform%2Fcore%2Fapi%2Fapp-control.git Support handling of each app-control action Requires: - https://review.tizen.org/gerrit/#/c/platform/core/appfw/aul-1/+/199252/ - https://review.tizen.org/gerrit/#/c/platform/core/appfw/app-core/+/199104/ - https://review.tizen.org/gerrit/#/c/platform/core/api/app-control/+/199105/ Change-Id: Id13c7eb322b6f47926388fc64df96eae2e07775e Signed-off-by: Hwankyu Jhun --- diff --git a/include/app_control.h b/include/app_control.h index a4d4597..4750a2b 100755 --- a/include/app_control.h +++ b/include/app_control.h @@ -715,6 +715,28 @@ typedef bool (*app_control_app_matched_cb)(app_control_h app_control, const char */ typedef void (*app_control_result_cb)(app_control_h request, app_control_error_e result, void *user_data); +/** + * @brief The application control action handle. + * @since_tizen 5.5 + */ +typedef struct app_control_action_s *app_control_action_h; + +/** + * @brief Called when another application sends a launch request to the application. + * @details Before calling app_control_cb() function, this callback function is called. + * @since_tizen 5.5 + * @remarks After this callback function returns, the handle of the app_control is released. + * Therefore, if you want to use the handle after returning this callback function, you MUST copy it by using app_control_clone() function. + * @remarks The @a action must not be deallocated by the application. The platform frees the string when the app_control action handle is removed. + * + * @param[in] action The name of the app_control action + * @param[in] app_control The handle of the app_control + * @param[in] user_data The user data passed from the callback registration function + * @see app_control_add_action_handler() + * @see @ref CAPI_APP_APPLICATION_MODULE API + */ +typedef void (*app_control_action_cb)(const char *action, + app_control_h app_control, void *user_data); /** * @brief Creates an app_control handle. @@ -750,8 +772,8 @@ int app_control_create(app_control_h *app_control); * @param[in] mime The explicit MIME type of the data this app_control is operating on * @param[in] category The explicit category * @param[in] app_id The ID of the application to explicitly launch - * @param[in] mode The launch mode of the application - * @param[in] extra_data_count The count of a extra data + * @param[in] mode The launch mode of the application + * @param[in] extra_data_count The count of a extra data * @param[in] ... The key-value pair list of app control extra data * @return @c 0 on success, * otherwise a negative error value @@ -1217,7 +1239,7 @@ int app_control_send_terminate_request(app_control_h app_control); * @remarks The function is not allowed to send reply #APP_CONTROL_RESULT_APP_STARTED as @a result which is reserved for platform developers. * * @param[in] reply The app_control handle in which the results of the callee are contained - * @param[in] request The app_control handle sent by the caller + * @param[in] request The app_control handle sent by the caller * @param[in] result The result code of the launch request * @return @c 0 on success, * otherwise a negative error value @@ -1411,6 +1433,42 @@ int app_control_send_launch_request_async(app_control_h app_control, int app_control_send_launch_request_sync(app_control_h app_control, app_control_h *reply, app_control_result_e *result); +/** + * @brief Adds the app_control action handle. + * @since_tizen 5.5 + * @remarks You should release @a handle using app_control_remove_action_handler(). + * + * @param[in] action The name of the app_control action + * @param[in] callback The callback function + * @param[in] user_data The user data to be passed to the callback function + * @param[out] handle The app_control action handle + * @return @c 0 on success, + * otherwise a negative error value + * @retval #APP_CONTROL_ERROR_NONE Successful + * @retval #APP_CONTROL_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #APP_CONTROL_ERROR_OUT_OF_MEMORY Out of memory + * @retval #APP_CONTROL_ERROR_KEY_NOT_FOUND Specified app_control ID not found + * @retval #APP_CONTROL_ERROR_IO_ERROR IO error + * @see app_control_action_cb() + * @see app_control_remove_action_handler() + */ +int app_control_add_action_handler(const char *action, + app_control_action_cb callback, void *user_data, + app_control_action_h *handle); + +/** + * @brief Removes registered app_control action handle. + * @since_tizen 5.5 + * + * @param[in] handle The app_control action handle + * @return @c 0 on success, + * otherwise a negative error value + * @retval #APP_CONTROL_ERROR_NONE Successful + * @retval #APP_CONTROL_ERROR_INVALID_PARAMETER Invalid parameter + * @see app_control_add_action_handler() + */ +int app_control_remove_action_handler(app_control_action_h handle); + /** * @} */ diff --git a/packaging/capi-appfw-app-control.spec b/packaging/capi-appfw-app-control.spec index ab1f38a..5d38b58 100644 --- a/packaging/capi-appfw-app-control.spec +++ b/packaging/capi-appfw-app-control.spec @@ -11,6 +11,7 @@ BuildRequires: pkgconfig(dlog) BuildRequires: pkgconfig(bundle) BuildRequires: pkgconfig(aul) BuildRequires: pkgconfig(capi-base-common) +BuildRequires: pkgconfig(appcore-common) Recommends: amd-mod-share %description diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index ed06e63..5b96b47 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -9,7 +9,7 @@ SET(PREFIX ${CMAKE_INSTALL_PREFIX}) SET(INC_DIR ${CMAKE_SOURCE_DIR}/include) INCLUDE_DIRECTORIES(${INC_DIR}) -SET(requires "dlog bundle aul capi-base-common") +SET(requires "dlog bundle aul capi-base-common appcore-common") SET(pc_requires "capi-base-common") INCLUDE(FindPkgConfig) diff --git a/src/app_control.c b/src/app_control.c index 2370eed..a6326ff 100644 --- a/src/app_control.c +++ b/src/app_control.c @@ -20,11 +20,13 @@ #include #include +#include #include #include #include #include #include +#include #include #include @@ -87,6 +89,13 @@ struct launch_request_s { app_control_result_e result; }; +struct app_control_action_s { + char *action; + appcore_base_control_h handle; + app_control_action_cb callback; + void *user_data; +}; + typedef int (*launch_request_handler)(struct launch_request_s *req); static int app_control_create_reply(bundle *data, struct app_control_s **app_control); @@ -1667,3 +1676,101 @@ int app_control_send_launch_request_sync(app_control_h app_control, return __send_launch_request_sync(app_control, reply, result); } + +static void __appcore_base_control_cb(bundle *b, void *user_data) +{ + struct app_control_action_s *h; + app_control_h app_control; + int r; + + h = (struct app_control_action_s *)user_data; + r = app_control_create_event(b, &app_control); + if (r != APP_CONTROL_ERROR_NONE) { + LOGE("Failed to create app-control handle"); + return; + } + + h->callback(h->action, app_control, h->user_data); + app_control_destroy(app_control); +} + +int app_control_add_action_handler(const char *action, + app_control_action_cb callback, void *user_data, + app_control_action_h *handle) +{ + struct app_control_action_s *h; + int r; + + if (!action || !callback || !handle) { + return app_control_error(APP_CONTROL_ERROR_INVALID_PARAMETER, + __FUNCTION__, "Invalid parameter"); + } + + h = calloc(1, sizeof(struct app_control_action_s)); + if (!h) { + return app_control_error(APP_CONTROL_ERROR_OUT_OF_MEMORY, + __FUNCTION__, "Out of memory"); + } + + h->action = strdup(action); + if (!h->action) { + free(h); + return app_control_error(APP_CONTROL_ERROR_OUT_OF_MEMORY, + __FUNCTION__, + "Failed to duplicate app-control action"); + } + + r = appcore_base_control_add(h->action, __appcore_base_control_cb, h, + &h->handle); + if (r != APPCORE_BASE_ERROR_NONE) { + free(h->action); + free(h); + switch (r) { + case APPCORE_BASE_ERROR_INVALID_PARAMETER: + return app_control_error( + APP_CONTROL_ERROR_INVALID_PARAMETER, + __FUNCTION__, + "Invalid parameter"); + case APPCORE_BASE_ERROR_KEY_NOT_FOUND: + return app_control_error( + APP_CONTROL_ERROR_KEY_NOT_FOUND, + __FUNCTION__, + "AppControl ID is not found"); + case APPCORE_BASE_ERROR_IO_ERROR: + return app_control_error( + APP_CONTROL_ERROR_IO_ERROR, + __FUNCTION__, + "IO error"); + default: + return app_control_error( + APP_CONTROL_ERROR_OUT_OF_MEMORY, + __FUNCTION__, + "Out of memory"); + } + } + + h->callback = callback; + h->user_data = user_data; + + *handle = h; + + return APP_CONTROL_ERROR_NONE; +} + +int app_control_remove_action_handler(app_control_action_h handle) +{ + if (!handle) { + return app_control_error(APP_CONTROL_ERROR_INVALID_PARAMETER, + __FUNCTION__, "Invalid parameter"); + } + + if (handle->handle) + appcore_base_control_remove(handle->handle); + + if (handle->action) + free(handle->action); + + free(handle); + + return APP_CONTROL_ERROR_NONE; +}