diff options
author | Myungki Lee <mk5004.lee@samsung.com> | 2016-11-02 20:00:24 +0900 |
---|---|---|
committer | Myungki Lee <mk5004.lee@samsung.com> | 2016-11-02 20:00:24 +0900 |
commit | 063f069a1aad76a522879b0d14aa4bfebfa650c4 (patch) | |
tree | f815157ca7d7c76479f7f7fd53dfbf7dc876fbc6 | |
parent | 94d3f6b753d51e9c9715e1f75acbf04f5af593da (diff) | |
download | shortcut-063f069a1aad76a522879b0d14aa4bfebfa650c4.tar.gz shortcut-063f069a1aad76a522879b0d14aa4bfebfa650c4.tar.bz2 shortcut-063f069a1aad76a522879b0d14aa4bfebfa650c4.zip |
Move the remove func in order to opensubmit/tizen_3.0_common/20161110.084657submit/tizen_3.0/20161104.060817submit/tizen/20161104.052856accepted/tizen/wearable/20161106.235144accepted/tizen/tv/20161106.235125accepted/tizen/mobile/20161106.235107accepted/tizen/ivi/20161106.235202accepted/tizen/common/20161104.060008accepted/tizen/3.0/wearable/20161104.104325accepted/tizen/3.0/tv/20161104.104304accepted/tizen/3.0/mobile/20161104.104248accepted/tizen/3.0/ivi/20161104.104342accepted/tizen/3.0/common/20161114.082851
Change-Id: I3497396d6fa363fbc8eb8b3f0d6d20497daebf67
Signed-off-by: Myungki Lee <mk5004.lee@samsung.com>
-rwxr-xr-x | lib/include/shortcut_error.h | 1 | ||||
-rwxr-xr-x | lib/include/shortcut_internal.h | 123 | ||||
-rwxr-xr-x | lib/include/shortcut_manager.h | 124 | ||||
-rwxr-xr-x | lib/src/shortcut_internal.c | 123 | ||||
-rwxr-xr-x | lib/src/shortcut_manager.c | 136 |
5 files changed, 278 insertions, 229 deletions
diff --git a/lib/include/shortcut_error.h b/lib/include/shortcut_error.h index f39d352..5e045d5 100755 --- a/lib/include/shortcut_error.h +++ b/lib/include/shortcut_error.h @@ -48,6 +48,7 @@ enum shortcut_error_e { SHORTCUT_ERROR_NO_SPACE = TIZEN_ERROR_SHORTCUT | 0x0001, /**< There is no space to add a new shortcut */ SHORTCUT_ERROR_EXIST = TIZEN_ERROR_SHORTCUT | 0x0002, /**< Shortcut is already added */ SHORTCUT_ERROR_FAULT = TIZEN_ERROR_SHORTCUT | 0x0004, /**< Unrecoverable error */ + SHORTCUT_ERROR_NOT_EXIST = TIZEN_ERROR_SHORTCUT | 0x0008, /**< Not exist shortcut(@b Since: 3.0) */ SHORTCUT_ERROR_COMM = TIZEN_ERROR_SHORTCUT | 0x0040 /**< Connection not established or communication problem */ }; diff --git a/lib/include/shortcut_internal.h b/lib/include/shortcut_internal.h index 060e554..a8f2800 100755 --- a/lib/include/shortcut_internal.h +++ b/lib/include/shortcut_internal.h @@ -1,5 +1,4 @@ /* - * * Copyright (c) 2000 - 2016 Samsung Electronics Co., Ltd. All rights reserved. * * Licensed under the Apache License, Version 2.0 (the License); @@ -38,131 +37,12 @@ extern "C" { * @{ */ - struct result_cb_item { result_internal_cb_t result_internal_cb; result_cb_t result_cb; void *data; }; - -/** - * @brief Enumeration for shortcut error extension. - * @since_tizen 3.0 - */ -enum shortcut_error_extension_e { - SHORTCUT_ERROR_NOT_EXIST = TIZEN_ERROR_SHORTCUT | 0x0008, /* Not exist shortcut */ -}; - - -/** - * @internal - * @brief Called to the shortcut_remove_from_home request. - * @since_tizen 3.0 - * @param[in] package_name The name of package - * @param[in] name The name of the created shortcut icon - * @param[in] sender_pid The process ID of who request shortcut_remove_from_home - * @param[in] user_data The user data passed from the callback register function - * - * @return 0 on success, otherwise a negative error value - * @retval #SHORTCUT_ERROR_NONE Successful - * @retval #SHORTCUT_ERROR_INVALID_PARAMETER Invalid function parameter - * @retval #SHORTCUT_ERROR_OUT_OF_MEMORY Out of memory - * @retval #SHORTCUT_ERROR_IO_ERROR I/O Error - * @retval #SHORTCUT_ERROR_PERMISSION_DENIED Permission denied - * @retval #SHORTCUT_ERROR_COMM Connection not established or communication problem - * @retval #SHORTCUT_ERROR_NOT_EXIST Shortcut not exist - */ -typedef int (*shortcut_remove_cb)(const char *package_name, const char *name, int sender_pid, void *user_data); - - -/** - * @internal - * @brief Registers a callback function for the shortcut removal request. - * @remarks Should be used in the homescreen.\n - * Should check the return value of this function. - * Prospective Clients: Homescreen. - * @since_tizen 3.0 - * @privlevel public - * @privilege %http://tizen.org/privilege/shortcut - * - * @param[in] request_cb The callback function pointer that is invoked when shortcut_remove_from_home is requested - * @param[in] data The callback data to deliver to the callback function - * - * @return 0 on success, otherwise a negative error value - * @retval #SHORTCUT_ERROR_NONE Successful - * @retval #SHORTCUT_ERROR_INVALID_PARAMETER Invalid function parameter - * @retval #SHORTCUT_ERROR_OUT_OF_MEMORY Out of memory - * @retval #SHORTCUT_ERROR_IO_ERROR I/O Error - * @retval #SHORTCUT_ERROR_PERMISSION_DENIED Permission denied - * @retval #SHORTCUT_ERROR_COMM Connection not established or communication problem - * @pre You have to prepare a callback function. - * - * @post If a request is sent from the application, the registered callback will be invoked. - * - * @see shortcut_remove_cb - */ -int shortcut_set_remove_cb(shortcut_remove_cb remove_cb, void *user_data); - -/** - * @internal - * @brief Removes a shortcut from home, asynchronously. - * @since_tizen 3.0 - * @privlevel public - * @privilege %http://tizen.org/privilege/shortcut - * @param[in] name The name of the created shortcut icon - * @param[in] result_cb The address of the callback function that is called when the result comes back from the viewer - * @param[in] user_data The callback data that is used in the callback function - * - * @return 0 on success, otherwise a negative error value - * @retval #SHORTCUT_ERROR_NONE Successful - * @retval #SHORTCUT_ERROR_INVALID_PARAMETER Invalid function parameter - * @retval #SHORTCUT_ERROR_OUT_OF_MEMORY Out of memory - * @retval #SHORTCUT_ERROR_IO_ERROR I/O Error - * @retval #SHORTCUT_ERROR_PERMISSION_DENIED Permission denied - * @retval #SHORTCUT_ERROR_NOT_SUPPORTED Not supported - * @retval #SHORTCUT_ERROR_RESOURCE_BUSY Device or resource busy - * @retval #SHORTCUT_ERROR_FAULT Unrecoverable error - * @retval #SHORTCUT_ERROR_COMM Connection not established or communication problem - * - * @pre You have to prepare the callback function. - * - * @post You have to check the return status from the callback function which is passed by the argument. - * - * @see result_cb_t - * - * @par Example - * @code - -#include <shortcut_internal.h> -... - int result_cb(int ret, void *data) - { - if (ret < 0) - dlog_print("Failed to remove a shortcut: %d\n", ret); - - return 0; - } - - ... - -{ - int result; - - result = shortcut_remove_from_home("shortcut_name", result_cb, NULL); - - if (result != SHORTCUT_ERROR_NONE) { - dlog_print("Failed to remove a shortcut: %d\n", result); - return result; - } -... - - } - - * @endcode - */ -int shortcut_remove_from_home(const char *name, result_cb_t result_cb, void *user_data); - int _dbus_init(void); int _dbus_signal_init(); char *_shortcut_get_pkgname_by_pid(void); @@ -171,6 +51,9 @@ int _send_service_register(); int _send_async_shortcut(GVariant *body, struct result_cb_item *cb_item, char *cmd); int _check_privilege(void); void _set_request_cb(shortcut_request_cb request_cb, void *data); +void _set_remove_cb(shortcut_remove_cb remove_cb, void *data); +void _unset_request_cb(void); +void _unset_remove_cb(void); int _dbus_set_watch_name(); /** diff --git a/lib/include/shortcut_manager.h b/lib/include/shortcut_manager.h index 540a4be..4e377fd 100755 --- a/lib/include/shortcut_manager.h +++ b/lib/include/shortcut_manager.h @@ -227,6 +227,63 @@ int shortcut_add_to_home(const char *name, shortcut_type type, const char *uri, */ int shortcut_add_to_home_widget(const char *name, shortcut_widget_size_e size, const char *widget_id, const char *icon, double period, int allow_duplicate, result_cb_t result_cb, void *data); +/** + * @brief Removes a shortcut from home, asynchronously. + * @details If the callback function registered for a widget, the shortcut deletion is possible. + * @since_tizen 3.0 + * @privlevel public + * @privilege %http://tizen.org/privilege/shortcut + * @param[in] name The name of the created shortcut icon + * @param[in] result_cb The address of the callback function that is called when the result comes back from the viewer + * @param[in] user_data The callback data that is used in the callback function + * + * @return 0 on success, otherwise a negative error value + * @retval #SHORTCUT_ERROR_NONE Successful + * @retval #SHORTCUT_ERROR_INVALID_PARAMETER Invalid function parameter + * @retval #SHORTCUT_ERROR_OUT_OF_MEMORY Out of memory + * @retval #SHORTCUT_ERROR_IO_ERROR I/O Error + * @retval #SHORTCUT_ERROR_PERMISSION_DENIED Permission denied + * @retval #SHORTCUT_ERROR_COMM Connection not established or communication problem + * + * @pre You have to prepare the callback function. + * + * @post You have to check the return status from the callback function which is passed by the argument. + * + * @see result_cb_t + * + * @par Example + * @code + +#include <shortcut_manager.h> + +... + +int result_cb(int ret, void *data) +{ + if (ret < 0) + dlog_print("Failed to remove a shortcut: %d\n", ret); + + return 0; +} + +... + +{ + int result; + + result = shortcut_remove_from_home("shortcut_name", result_cb, NULL); + + if (result != SHORTCUT_ERROR_NONE) { + dlog_print("Failed to remove a shortcut: %d\n", result); + return result; + } +... + +} + + * @endcode + */ +int shortcut_remove_from_home(const char *name, result_cb_t result_cb, void *user_data); /** * @brief Called to receive the result of shortcut_get_list(). @@ -292,11 +349,25 @@ int shortcut_get_list(const char *package_name, shortcut_list_cb list_cb, void * typedef int (*shortcut_request_cb)(const char *package_name, const char *name, int type, const char *content_info, const char *icon, int pid, double period, int allow_duplicate, void *data); /** - * @brief Registers a callback function to listen requests from applications. + * @brief Called to the shortcut_remove_from_home request. + * @since_tizen 3.0 + * @param[in] package_name The name of package + * @param[in] name The name of the created shortcut icon + * @param[in] sender_pid The process ID of who request shortcut_remove_from_home + * @param[in] user_data The user data passed from the callback register function + * @return The result of handling a shortcut remove request\n + * This returns @c 0 if the remove_from_home request is handled successfully, + * otherwise it returns a proper errno. + * @see shortcut_set_remove_cb() + */ +typedef int (*shortcut_remove_cb)(const char *package_name, const char *name, int sender_pid, void *user_data); + +/** + * @brief Registers a callback function to listen the add requests from applications. * @remarks Should be used in the homescreen.\n * Should check the return value of this function. - * Prospective Clients: Homescreen. - * @since_tizen 2.4 + * Prospective Clients: Homescreen. + * @since_tizen 2.4 * @privlevel public * @privilege %http://tizen.org/privilege/shortcut * @@ -319,6 +390,53 @@ typedef int (*shortcut_request_cb)(const char *package_name, const char *name, i */ int shortcut_set_request_cb(shortcut_request_cb request_cb, void *data); +/** + * @brief Unregisters a callback for the shortcut request. + * @since_tizen 3.0 + * @privlevel public + * @privilege %http://tizen.org/privilege/shortcut + * + * @see shortcut_set_request_cb + */ +void shortcut_unset_request_cb(void); + +/** + * @brief Registers the callback function to listen the remove requests from applications. + * @remarks Should be used in the homescreen.\n + * Should check the return value of this function. + * Prospective Clients: Homescreen. + * @since_tizen 3.0 + * @privlevel public + * @privilege %http://tizen.org/privilege/shortcut + * + * @param[in] remove_cb The callback function pointer that is invoked when remove_from_home is requested + * @param[in] data The callback data to deliver to the callback function + * + * @return 0 on success, otherwise a negative error value + * @retval #SHORTCUT_ERROR_NONE Successful + * @retval #SHORTCUT_ERROR_INVALID_PARAMETER Invalid function parameter + * @retval #SHORTCUT_ERROR_OUT_OF_MEMORY Out of memory + * @retval #SHORTCUT_ERROR_IO_ERROR I/O Error + * @retval #SHORTCUT_ERROR_PERMISSION_DENIED Permission denied + * @retval #SHORTCUT_ERROR_COMM Connection not established or communication problem + * @pre You have to prepare a callback function. + * + * @post If a request is sent from the application, the registered callback will be invoked. + * + * @see remove_cb_t + * @see shortcut_error_e + */ +int shortcut_set_remove_cb(shortcut_remove_cb remove_cb, void *data); + +/** + * @brief Unregisters a callback for the shortcut remove. + * @since_tizen 3.0 + * @privlevel public + * @privilege %http://tizen.org/privilege/shortcut + * + * @see shortcut_set_remove_cb + */ +void shortcut_unset_remove_cb(void); /** * @} diff --git a/lib/src/shortcut_internal.c b/lib/src/shortcut_internal.c index 26fb8f9..0bd82b7 100755 --- a/lib/src/shortcut_internal.c +++ b/lib/src/shortcut_internal.c @@ -435,6 +435,24 @@ void _set_request_cb(shortcut_request_cb request_cb, void *data) _request_callback_info.data = data; } +void _unset_request_cb(void) +{ + _request_callback_info.request_cb = NULL; + _request_callback_info.data = NULL; +} + +void _set_remove_cb(shortcut_remove_cb remove_cb, void *data) +{ + _remove_callback_info.remove_cb = remove_cb; + _remove_callback_info.data = data; +} + +void _unset_remove_cb(void) +{ + _remove_callback_info.remove_cb = NULL; + _remove_callback_info.data = NULL; +} + int _dbus_set_watch_name() { if (provider_monitor_id == 0) { @@ -457,108 +475,3 @@ int _dbus_set_watch_name() return SHORTCUT_ERROR_NONE; } - -EXPORT_API int shortcut_set_remove_cb(shortcut_remove_cb remove_cb, void *user_data) -{ - int ret; - - if (remove_cb == NULL) - return SHORTCUT_ERROR_INVALID_PARAMETER; - - ret = _dbus_init(); - if (ret != SHORTCUT_ERROR_NONE) { - /* LCOV_EXCL_START */ - ErrPrint("Can't init dbus %d", ret); - return ret; - /* LCOV_EXCL_STOP */ - } - - ret = _dbus_signal_init(); - if (ret != SHORTCUT_ERROR_NONE) { - /* LCOV_EXCL_START */ - ErrPrint("Can't init dbus_signal %d", ret); - return ret; - /* LCOV_EXCL_STOP */ - } - - ret = _send_service_register(); - if (ret != SHORTCUT_ERROR_NONE) { - /* LCOV_EXCL_START */ - ErrPrint("Can't init ipc_monitor_register %d", ret); - return ret; - /* LCOV_EXCL_STOP */ - } - - ret = _dbus_set_watch_name(); - if (ret != SHORTCUT_ERROR_NONE) { - /* LCOV_EXCL_START */ - ErrPrint("Can't init _dbus_set_watch_name %d", ret); - return ret; - /* LCOV_EXCL_STOP */ - } - - _remove_callback_info.remove_cb = remove_cb; - _remove_callback_info.data = user_data; - - return SHORTCUT_ERROR_NONE; -} - -EXPORT_API int shortcut_remove_from_home(const char *name, result_cb_t result_cb, void *user_data) -{ - struct result_cb_item *item; - char *appid; - int ret; - GVariant *body; - - if (name == NULL) { - ErrPrint("name is NULL."); - return SHORTCUT_ERROR_INVALID_PARAMETER; - } - - ret = _dbus_init(); - if (ret != SHORTCUT_ERROR_NONE) { - /* LCOV_EXCL_START */ - ErrPrint("Can't init dbus %d", ret); - return ret; - /* LCOV_EXCL_STOP */ - } - - ret = _check_privilege(); - if (ret != SHORTCUT_ERROR_NONE) - return ret; - - appid = _shortcut_get_pkgname_by_pid(); - item = malloc(sizeof(struct result_cb_item)); - if (!item) { - /* LCOV_EXCL_START */ - if (appid) - free(appid); - - ErrPrint("Heap: %d\n", errno); - return SHORTCUT_ERROR_OUT_OF_MEMORY; - /* LCOV_EXCL_STOP */ - } - - item->result_cb = result_cb; - item->result_internal_cb = NULL; - item->data = user_data; - - body = g_variant_new("(iss)", getpid(), appid, name); - - ret = _send_async_shortcut(body, item, "remove_shortcut"); - if (ret != SHORTCUT_ERROR_NONE) { - /* LCOV_EXCL_START */ - free(item); - item = NULL; - /* LCOV_EXCL_STOP */ - } - - if (appid) - free(appid); - if (body) - g_variant_unref(body); - - return ret; - -} - diff --git a/lib/src/shortcut_manager.c b/lib/src/shortcut_manager.c index 38be559..bbfd676 100755 --- a/lib/src/shortcut_manager.c +++ b/lib/src/shortcut_manager.c @@ -36,11 +36,12 @@ EAPI int shortcut_set_request_cb(shortcut_request_cb request_cb, void *data) { - int ret = _dbus_init(); + int ret; if (request_cb == NULL) return SHORTCUT_ERROR_INVALID_PARAMETER; /* LCOV_EXCL_LINE */ + ret = _dbus_init(); if (ret != SHORTCUT_ERROR_NONE) { /* LCOV_EXCL_START */ ErrPrint("Can't init dbus %d", ret); @@ -77,6 +78,60 @@ EAPI int shortcut_set_request_cb(shortcut_request_cb request_cb, void *data) return SHORTCUT_ERROR_NONE; } +EAPI void shortcut_unset_request_cb(void) +{ + _unset_request_cb(); +} + +EAPI int shortcut_set_remove_cb(shortcut_remove_cb remove_cb, void *data) +{ + int ret; + + if (remove_cb == NULL) + return SHORTCUT_ERROR_INVALID_PARAMETER; + + ret = _dbus_init(); + if (ret != SHORTCUT_ERROR_NONE) { + /* LCOV_EXCL_START */ + ErrPrint("Can't init dbus %d", ret); + return ret; + /* LCOV_EXCL_STOP */ + } + + ret = _dbus_signal_init(); + if (ret != SHORTCUT_ERROR_NONE) { + /* LCOV_EXCL_START */ + ErrPrint("Can't init dbus_signal %d", ret); + return ret; + /* LCOV_EXCL_STOP */ + } + + ret = _send_service_register(); + if (ret != SHORTCUT_ERROR_NONE) { + /* LCOV_EXCL_START */ + ErrPrint("Can't init ipc_monitor_register %d", ret); + return ret; + /* LCOV_EXCL_STOP */ + } + + ret = _dbus_set_watch_name(); + if (ret != SHORTCUT_ERROR_NONE) { + /* LCOV_EXCL_START */ + ErrPrint("Can't init _dbus_set_watch_name %d", ret); + return ret; + /* LCOV_EXCL_STOP */ + } + + _set_remove_cb(remove_cb, data); + + return SHORTCUT_ERROR_NONE; +} + +EAPI void shortcut_unset_remove_cb(void) +{ + _unset_remove_cb(); +} + EAPI int shortcut_add_to_home(const char *name, shortcut_type type, const char *uri, const char *icon, int allow_duplicate, result_cb_t result_cb, void *data) { @@ -105,6 +160,13 @@ EAPI int shortcut_add_to_home(const char *name, shortcut_type type, const char * return ret; appid = _shortcut_get_pkgname_by_pid(); + if (appid == NULL) { + /* LCOV_EXCL_START */ + ErrPrint("Can't get appid"); + return SHORTCUT_ERROR_IO_ERROR; + /* LCOV_EXCL_STOP */ + } + item = malloc(sizeof(struct result_cb_item)); if (!item) { /* LCOV_EXCL_START */ @@ -180,6 +242,13 @@ EAPI int shortcut_add_to_home_widget(const char *name, shortcut_widget_size_e si return ret; appid = _shortcut_get_pkgname_by_pid(); + if (appid == NULL) { + /* LCOV_EXCL_START */ + ErrPrint("Can't get appid"); + return SHORTCUT_ERROR_IO_ERROR; + /* LCOV_EXCL_STOP */ + } + item = malloc(sizeof(struct result_cb_item)); if (!item) { /* LCOV_EXCL_START */ @@ -213,6 +282,71 @@ EAPI int shortcut_add_to_home_widget(const char *name, shortcut_widget_size_e si return ret; } +EAPI int shortcut_remove_from_home(const char *name, result_cb_t result_cb, void *user_data) +{ + struct result_cb_item *item; + char *appid; + int ret; + GVariant *body; + + if (name == NULL) { + ErrPrint("name is NULL."); + return SHORTCUT_ERROR_INVALID_PARAMETER; + } + + ret = _dbus_init(); + if (ret != SHORTCUT_ERROR_NONE) { + /* LCOV_EXCL_START */ + ErrPrint("Can't init dbus %d", ret); + return ret; + /* LCOV_EXCL_STOP */ + } + + ret = _check_privilege(); + if (ret != SHORTCUT_ERROR_NONE) + return ret; + + appid = _shortcut_get_pkgname_by_pid(); + if (appid == NULL) { + /* LCOV_EXCL_START */ + ErrPrint("Can't get appid"); + return SHORTCUT_ERROR_IO_ERROR; + /* LCOV_EXCL_STOP */ + } + + item = malloc(sizeof(struct result_cb_item)); + if (!item) { + /* LCOV_EXCL_START */ + if (appid) + free(appid); + + ErrPrint("Heap: %d\n", errno); + return SHORTCUT_ERROR_OUT_OF_MEMORY; + /* LCOV_EXCL_STOP */ + } + + item->result_cb = result_cb; + item->result_internal_cb = NULL; + item->data = user_data; + + body = g_variant_new("(iss)", getpid(), appid, name); + + ret = _send_async_shortcut(body, item, "remove_shortcut"); + if (ret != SHORTCUT_ERROR_NONE) { + /* LCOV_EXCL_START */ + free(item); + item = NULL; + /* LCOV_EXCL_STOP */ + } + + if (appid) + free(appid); + if (body) + g_variant_unref(body); + + return ret; +} + EAPI int shortcut_get_list(const char *package_name, shortcut_list_cb list_cb, void *data) { GDBusMessage *reply = NULL; |