Sync with tizen 2.3 code. 18/33118/4
authorJiwoong Im <jiwoong.im@samsung.com>
Tue, 6 Jan 2015 05:32:08 +0000 (14:32 +0900)
committerJiwoong Im <jiwoong.im@samsung.com>
Tue, 13 Jan 2015 10:36:39 +0000 (02:36 -0800)
JIRA ticket : TC-2338
add shortcut_add_to_home api.

Change-Id: Iac5dbdd970f3ecce528b9d09861b0ef3b282ddaf
Signed-off-by: Jiwoong Im <jiwoong.im@samsung.com>
lib/CMakeLists.txt
lib/include/shortcut.h
lib/include/shortcut_internal.h
lib/include/shortcut_manager.h [new file with mode: 0644]
lib/shortcut.pc.in
lib/src/icon.c
lib/src/main.c
packaging/libshortcut.spec

index 6204865..206ae46 100644 (file)
@@ -18,6 +18,8 @@ pkg_check_modules(svc_pkgs REQUIRED
        com-core
        vconf
        libtzplatform-config
+       capi-base-common
+       aul
 )
 
 FOREACH(flag ${svc_pkgs_CFLAGS})
@@ -45,6 +47,7 @@ SET_DIRECTORY_PROPERTIES(PROPERTIES ADDITIONAL_MAKE_CLEAN_FILES "${PROJECT_NAME}
 INSTALL(TARGETS ${PROJECT_NAME} DESTINATION ${LIB_INSTALL_DIR})
 INSTALL(FILES ${CMAKE_SOURCE_DIR}/lib/include/shortcut.h DESTINATION include/${PROJECT_NAME})
 INSTALL(FILES ${CMAKE_SOURCE_DIR}/lib/include/shortcut_PG.h DESTINATION include/${PROJECT_NAME})
+INSTALL(FILES ${CMAKE_SOURCE_DIR}/lib/include/shortcut_manager.h DESTINATION include/${PROJECT_NAME})
 INSTALL(FILES ${CMAKE_BINARY_DIR}/lib/${PROJECT_NAME}.pc DESTINATION ${LIB_INSTALL_DIR}/pkgconfig)
 INSTALL(FILES ${CMAKE_SOURCE_DIR}/lib/LICENSE DESTINATION /usr/share/license RENAME "lib${PROJECT_NAME}")
 
index 203411c..6df2b47 100644 (file)
 #ifndef __SHORTCUT_H__
 #define __SHORTCUT_H__
 
+#include <tizen.h>
+#include <shortcut_manager.h>
+
 #ifdef __cplusplus
 extern "C" {
 #endif
 
 /**
- * @addtogroup APPLICATION_FRAMEWORK
- * @{
+ * @file shortcut.h
+ * @brief This file declares the API of the libshortcut library.
  */
 
 /**
- * @defgroup SHORTCUT Add to home (shortcut)
- * @version 0.1
- * @brief To enhance the Add to home feature. Two types of API set are supported.
- *        One for the homescreen developers.
- *        The others for the application developers who should implement the Add to home feature.
+ * @addtogroup SHORTCUT_MODULE
+ * @{
  */
 
-struct shortcut_icon;
 /**
- * @brief This function prototype is used to define a callback function for the add_to_home reqeust.
- *        The homescreen should define a callback as this type and implementing the service code
+ * @internal
+ * @brief Called to the add_to_home request.
+ * @details The homescreen should define a callback as this type and implement the service code
  *        for adding a new application shortcut.
- * @param[in] appid Shortcut is added for this package.
- * @param[in] name Name for created shortcut icon.
- * @param[in] type 3 kinds of types are defined.
- * @param[in] content_info Specific information for creating a new shortcut.
- * @param[in] icon Absolute path of an icon file for this shortcut.
- * @param[in] pid Process ID of who request add_to_home.
- * @param[in] allow_duplicate 1 if shortcut can be duplicated or a shourtcut should be exists only one.
- * @param[in] data Callback data.
- * @return int Developer should returns the result of handling shortcut creation request.
- *             Returns 0, if succeed to handles the add_to_home request, or returns proper errno.
- * @see shortcut_set_request_cb
- * @pre None
- * @post None
- * @remarks None
+ * @since_tizen 2.3
+ * @param[in] appid The shortcut that is added for this package
+ * @param[in] name The name of the created shortcut icon
+ * @param[in] type One of the three defined types
+ * @param[in] content_info The specific information for creating a new shortcut
+ * @param[in] icon The absolute path of an icon file for this shortcut
+ * @param[in] pid The process ID of who request add_to_home
+ * @param[in] allow_duplicate @c 1 if the shortcut can be duplicated,
+ *                            otherwise a shourtcut should exist only once
+ * @param[in] data The callback data
+ * @return The result of handling a shortcut creation request\n
+ *             This returns @c 0 if the add_to_home request is handled successfully,
+ *             otherwise it returns a proper errno.
+ * @see shortcut_set_request_cb()
  */
 typedef int (*request_cb_t)(const char *appid, const char *name, int type, const char *content_info, const char *icon, int pid, double period, int allow_duplicate, void *data);
 
 /**
- * @brief This function prototype is used to define for receiving the result of add_to_home.
- * @param[in] ret Result value, it could be 0 if succeed to add a shortcut, or errno.
- * @param[in] pid Process ID of who handles this add_to_home request.
- * @param[in] data Callback data.
- * @return int Returns 0, if there is no error or returns errno.
+ * @brief Called to receive the result of add_to_home_shortcut().
+ * @since_tizen 2.3
+ * @param[in] ret The result value, it could be @c 0 if it succeeds to add a shortcut,
+ *                otherwise it returns an errno
+ * @param[in] pid The process ID of who handle this add_to_home request
+ * @param[in] data The callback data
+ * @return int @c 0 if there is no error,
+               otherwise errno
  * @see add_to_home_shortcut()
- * @pre None
- * @post None
- * @remarks None
  */
-typedef int (*result_cb_t)(int ret, int pid, void *data);
+typedef int (*result_internal_cb_t)(int ret, int pid, void *data);
 
 /**
- * @brief After send a request to create a icon snapshot image, this callback will be called with its result.
- * @param[in] handle Handle of requestor
- * @param[in] ret status of request
- * @param[in] data Callback data
- * @return int result state of callback call
- * @retval 0 If it is successfully completed
- * @see shortcut_icon_request_send()
- * @pre None
- * @post None
- * @remarks None
+ * @brief Enumeration for shortcut types.
+ * @details Basically, three types of shortcuts are defined.
+ *          Every homescreen developer should support these types of shortcuts.
+ *          Or return a proper errno to figure out why the application failed to add a shortcut.
+ *          #LAUNCH_BY_PACKAGE is used for adding a package itself as a shortcut.
+ *          #LAUNCH_BY_URI is used for adding a shortcut for "uri" data.
+ * @since_tizen 2.3
  */
-typedef int (*icon_request_cb_t)(struct shortcut_icon *handle, int ret, void *data);
+enum shortcut_internal_type {
+       /**< Deprecated type */
+       SHORTCUT_PACKAGE        = 0x00000000,   /**< Launch the package using the given package name */
+       SHORTCUT_DATA           = 0x00000001,   /**< Launch the related package with the given data(content_info) */
+       SHORTCUT_FILE           = 0x00000002,   /**< Launch the related package with the given filename(content_info) */
+
+       LAUNCH_BY_PACKAGE       = 0x00000000,
+
+       SHORTCUT_REMOVE         = 0x40000000,   /**< Remove a shortcut */
+       LIVEBOX_REMOVE          = 0x80000000,   /**< Remove a livebox */
+
+       LIVEBOX_TYPE_DEFAULT      = 0x10000000, /**< Type mask for the default livebox */
+       LIVEBOX_TYPE_EASY_DEFAULT = 0x30000000, /**< Type mask for the easy mode livebox */
+       LIVEBOX_TYPE_1x1          = 0x10010000, /**< 1x1 */
+       LIVEBOX_TYPE_2x1          = 0x10020000, /**< 2x1 */
+       LIVEBOX_TYPE_2x2          = 0x10040000, /**< 2x2 */
+       LIVEBOX_TYPE_4x1          = 0x10080000, /**< 4x1 */
+       LIVEBOX_TYPE_4x2          = 0x10100000, /**< 4x2 */
+       LIVEBOX_TYPE_4x3          = 0x10200000, /**< 4x3 */
+       LIVEBOX_TYPE_4x4          = 0x10400000, /**< 4x4 */
+       LIVEBOX_TYPE_4x5          = 0x11000000, /**< 4x5 */
+       LIVEBOX_TYPE_4x6          = 0x12000000, /**< 4x6 */
+       LIVEBOX_TYPE_EASY_1x1     = 0x30010000, /**< Easy mode 1x1 */
+       LIVEBOX_TYPE_EASY_3x1     = 0x30020000, /**< Easy mode 3x2 */
+       LIVEBOX_TYPE_EASY_3x3     = 0x30040000, /**< Easy mode 3x3 */
+       LIVEBOX_TYPE_UNKNOWN      = 0x1FFF0000, /**< Error */
+};
 
 /**
- * @brief Basically, three types of shortcut is defined.
- *        Every homescreen developer should support these types of shortcut.
- *        Or returns proper errno to figure out why the application failed to add a shortcut.
- *        LAUNCH_BY_PACKAGE is used for adding a package itself as a shortcut
- *        LAUNCH_BY_URI is used for adding a shortcut for "uri" data.
+ * @brief Enumeration for values of shortcut response types.
+ * @since_tizen 2.3
  */
-//! [Enumeration values for type of shortcuts]
-enum shortcut_type {
-       /*!< Deprecated type */
-       SHORTCUT_PACKAGE        = 0x00000000,   /*!< Launch the package using given pakcage name. */
-       SHORTCUT_DATA           = 0x00000001,   /*!< Launch the related package with given data(content_info). */
-       SHORTCUT_FILE           = 0x00000002,   /*!< Launch the related package with given filename(content_info). */
-
-       /*!< Use these */
-       LAUNCH_BY_PACKAGE       = 0x00000000,   /*!< Launch the package using given pakcage name. */
-       LAUNCH_BY_URI           = 0x00000001,   /*!< Launch the related package with given data(URI). */
-
-       SHORTCUT_REMOVE         = 0x40000000,   /*!< Remove a shortcut */
-       LIVEBOX_REMOVE          = 0x80000000,   /*!< Remove a livebox */
-
-       LIVEBOX_TYPE_DEFAULT      = 0x10000000, /*!< Type mask for default livebox */
-       LIVEBOX_TYPE_EASY_DEFAULT = 0x30000000, /*!< Type mask for easy mode livebox */
-       LIVEBOX_TYPE_1x1          = 0x10010000, /*!< 1x1 */
-       LIVEBOX_TYPE_2x1          = 0x10020000, /*!< 2x1 */
-       LIVEBOX_TYPE_2x2          = 0x10040000, /*!< 2x2 */
-       LIVEBOX_TYPE_4x1          = 0x10080000, /*!< 4x1 */
-       LIVEBOX_TYPE_4x2          = 0x10100000, /*!< 4x2 */
-       LIVEBOX_TYPE_4x3          = 0x10200000, /*!< 4x3 */
-       LIVEBOX_TYPE_4x4          = 0x10400000, /*!< 4x4 */
-       LIVEBOX_TYPE_4x5          = 0x11000000, /*!< 4x5 */
-       LIVEBOX_TYPE_4x6          = 0x12000000, /*!< 4x6 */
-       LIVEBOX_TYPE_EASY_1x1     = 0x30010000, /*!< Easy mode 1x1 */
-       LIVEBOX_TYPE_EASY_3x1     = 0x30020000, /*!< Easy mode 3x2 */
-       LIVEBOX_TYPE_EASY_3x3     = 0x30040000, /*!< Easy mode 3x3 */
-       LIVEBOX_TYPE_UNKNOWN      = 0x1FFF0000  /*!< Error */
-};
-//! [Enumeration values for type of shortcuts]
-
-enum shortcut_response {
-       SHORTCUT_SUCCESS = 0x00000000,                          /*!< Successfully handled */
-       SHORTCUT_ERROR = 0x80000000,                            /*!< MSB(1). Check this using SHORTCUT_STATUS_IS_ERROR macro  */
-       SHORTCUT_ERROR_NO_SPACE = SHORTCUT_ERROR | 0x0001,      /*!< There is no space to add new shortcut */
-       SHORTCUT_ERROR_EXIST = SHORTCUT_ERROR | 0x0002,         /*!< Shortcut is already added */
-       SHORTCUT_ERROR_FAULT = SHORTCUT_ERROR | 0x0004,         /*!< Failed to add a shortcut. Unrecoverable error */
-       SHORTCUT_ERROR_UNSUPPORTED = SHORTCUT_ERROR | 0x0008,   /*!< Unsupported shortcut */
-       SHORTCUT_ERROR_BUSY = SHORTCUT_ERROR | 0x0010,          /*!< Receiver is busy, try again later */
-       SHORTCUT_ERROR_INVALID = SHORTCUT_ERROR | 0x0020,       /*!< Shortcut request is not valid, invalid parameter or invalid argument value */
-       SHORTCUT_ERROR_COMM = SHORTCUT_ERROR | 0x0040,          /*!< Connection is not estabilished. or there is a problem of communication */ 
-       SHORTCUT_ERROR_MEMORY = SHORTCUT_ERROR | 0x0080,        /*!< Memory is not enough to handle new request */
-       SHORTCUT_ERROR_IO = SHORTCUT_ERROR | 0x0100,            /*!< Unable to access file or DB. Check your resource files */
-       SHORTCUT_ERROR_PERMISSION = SHORTCUT_ERROR | 0x0200,    /*!< Has no permission to add a shortcut */
-
-       SHORTCUT_STATUS_CARED = 0x08000000                      /*!< Shortcut status is already cared. check this using SHORTCUT_STATUS_IS_CARED macro */
+enum shortcut_internal_error_e {
+       SHORTCUT_ERROR = 0x80000000,                            /**< MSB(1). Check this using the #SHORTCUT_STATUS_IS_ERROR macro  */
+
+       SHORTCUT_STATUS_CARED = 0x08000000,                     /**< Shortcut status is already cared. Check this using the #SHORTCUT_STATUS_IS_CARED macro */
+
+       SHORTCUT_ERROR_BUSY = TIZEN_ERROR_RESOURCE_BUSY,                /**< Receiver is busy, try again later */
+       SHORTCUT_ERROR_UNSUPPORTED = SHORTCUT_ERROR | 0x0400    /**< Shortcut is not supported */
 };
 
-/*!
- * \brief Macro function for checking the type
- * \param[in] type Type of box
- * \return bool
- * \retval true(1) If it is a livebox
- * \retval false(0) if it is not a livebox
- * \see shortcut_type
- * \pre None
- * \post None
- * \remarks None
+/**
+ * @brief Definition for a macro to check type.
+ * @since_tizen 2.3
+ * @param[in] type The type of box
+ * @return bool
+ * @retval true(1) If it is a livebox
+ * @retval false(0) If it is not a livebox
+ * @see shortcut_type
  */
 #define ADD_TO_HOME_IS_LIVEBOX(type)   (!!((type) & 0x10000000))
 
-/*!
- * \brief Macro function for checking the request type
- * \param[in] type Request type
- * \return bool
- * \retval true(1) Shortcut remove request
- * \retval false(0) Not a remove request
- * \see shortcut_type
- * \pre None
- * \post None
- * \remarks None
- */
-#define ADD_TO_HOME_IS_REMOVE_SHORTCUT(type)   (!!((type) & SHORTCUT_REMOVE))
-
-/*!
- * \brief Macro function for checking the request type
- * \param[in] type Request type
- * \return bool
- * \retval true(1) Livebox remove request
- * \retval false(0) Not a remove request
- * \see shortcut_type
- * \pre None
- * \post None
- * \remarks None
- */
-#define ADD_TO_HOME_IS_REMOVE_LIVEBOX(type)    (!!((type) & LIVEBOX_REMOVE))
-
-/*!
- * \brief Macro function for checking the status of request
- * \param[in] type Status
- * \return bool
- * \retval true(1) Error
- * \retval false(0) Not an error
- * \see shortcut_response
- * \pre None
- * \post None
- * \remarks None
+/**
+ * @brief Definition for a macro to check the request status.
+ * @since_tizen 2.3
+ * @param[in] type The status
+ * @return bool
+ * @retval true(1) Error
+ * @retval false(0) Not an error
+ * @see shortcut_error_e
  */
 #define SHORTCUT_STATUS_IS_ERROR(type) (!!((type) & SHORTCUT_ERROR))
 
-/*!
- * \brief Macro function for checking the status of request
- * \param[in] type Status
- * \return bool
- * \retval true(1) Shortcut request is already handled by requestee (homescreen, viewer, ...)
- * \retval false(0) Request result should be cared by requestor
- * \see shortcut_response
- * \pre None
- * \post None
- * \remarks None
+/**
+ * @brief Definition for a macro to check the request status.
+ * @since_tizen 2.3
+ * @param[in] type The status
+ * @return bool
+ * @retval true(1) Shortcut request is already handled by the requestee (homescreen, viewer, ...)
+ * @retval false(0) Request result should be cared by the requestor
+ * @see shortcut_error_e
  */
 #define SHORTCUT_STATUS_IS_CARED(type) (!!((type) & SHORTCUT_STATUS_CARED))
 
-/*!
- * \brief Filtering the pure error code from given status
- * \param[in] status status
- * \return status code (error)
- * \see shortcut_response
- * \pre None
- * \post None
- * \remarks None
- *
+/**
+ * @brief Definition for filtering the pure error code from the given status.
+ * @since_tizen 2.3
+ * @param[in] status The status
+ * @return The status code (error)
+ * @see shortcut_error_e
  */
 #define SHORTCUT_ERROR_CODE(status)    ((status) & ~SHORTCUT_STATUS_CARED)
 
 /**
- * @fn int shortcut_set_request_cb(request_cb_t request_cb, void *data)
  *
- * @brief Homescreen should use this function to service the shortcut creating request.
+ * @internal
+ *
+ * @brief Supports the shortcut creating request.
  *
- * @par Sync (or) Async:
+ * @details
+ * Sync (or) Async:
  * This is an asynchronous API.
  *
- * @par Important Notes:
- * - Should be used from the homescreen.
- * - Should check the return value of this function
+ * Important Notes: \n
+ * Should be used from the homescreen.\n
+ * Should check the return value of this function.
  *
- * @param[in] request_cb Callback function pointer which will be invoked when add_to_home is requested.
- * @param[in] data Callback data to deliver to the callback function.
+ * Prospective Clients:
+ * Homescreen.
  *
- * @return Return Type (int)
- * - 0 - callback function is successfully registered
- * - < 0 - Failed to register the callback function for request.
+ * @since_tizen 2.3
  *
- * @see request_cb_t
+ * @privlevel public
+ * @privilege %http://tizen.org/privilege/shortcut
  *
- * @pre - You have to prepare a callback function
+ * @param[in] request_cb The callback function pointer that is invoked when add_to_home is requested
+ * @param[in] data The callback data to deliver to the callback function
  *
- * @post - If a request is sent from the application, the registered callback will be invoked.
+ * @return The return type (int)
+ * @retval 0 Callback function is successfully registered
+ * @retval <0 Failed to register the callback function for the request
  *
- * @remarks - None
+ * @pre You have to prepare a callback function.
  *
- * @par Prospective Clients:
- * Homescreen
+ * @post If a request is sent from the application, the registered callback will be invoked.
  *
+ * @see request_cb_t
  * @par Example
  * @code
  * #include <shortcut.h>
@@ -279,46 +228,52 @@ enum shortcut_response {
 extern int shortcut_set_request_cb(request_cb_t request_cb, void *data);
 
 /**
- * @fn add_to_home_shortcut(const char *appid, const char *name, int type, const char *content_info, const char *icon, int allow_duplicate, result_cb_t result_cb, void *data)
  *
- * @brief The application, which supporting the add_to_home feature, should invoke this.
+ * @brief Supports the add_to_home feature, should invoke this.
  *
- * @par Sync (or) Async:
+ * @details
+ * Sync (or) Async:
  * This is an asynchronous API.
  *
- * @par Important Notes:
- * - Application must check the return value of this function.
- * - Application must check the return status from the callback function
- * Application should set the callback function to get the result of this request.
+ * Important Notes:\n
+ * Application must check the return value of this function.\n
+ * Application must check the return status from the callback function.\n
+ * Application should set the callback function to get the result of this request.
  *
- * @param[in] appid Package name of owner of this shortcut.
- * @param[in] name Name for created shortcut icon.
- * @param[in] type Type of shortcuts (livebox or shortcut, and its size if it is for the livebox)
- * @param[in] content_info Specific information for delivering to the viewer for creating a shortcut.
- * @param[in] icon Absolute path of an icon file
- * @param[in] allow_duplicate set 1 If accept the duplicated shortcut or 0
- * @param[in] result_cb Address of callback function which will be called when the result comes back from the viewer.
- * @param[in] data Callback data which will be used in callback function
+ * Prospective Clients:
+ * Inhouse Apps.
  *
- * @return Return Type (int)
- * \retval 0 Succeed to send the request
- * \retval SHORTCUT_ERROR_FAULT Unrecoverable error
- * \retval SHORTCUT_ERROR_INVALID Shortcut request is not valid, invalid parameter or invalid argument value
- * \retval SHORTCUT_ERROR_COMM Connection is not estabilished. or there is a problem of communication
- * \retval SHORTCUT_ERROR_MEMORY Memory is not enough to handle new request
- * \retval SHORTCUT_ERROR_IO Unable to access file or DB. Check your resource files
- * \retval SHORTCUT_ERROR_PERMISSION Has no permission to add a shortcut
+ * @since_tizen 2.3
  *
- * @see result_cb_t
+ * @privlevel public
+ * @privilege %http://tizen.org/privilege/shortcut
  *
- * @pre You have to prepare the callback function
+ * @remarks If a homescreen does not support this feature, you will get a proper error code.
+ * @param[in] appid The package name of the owner of this shortcut
+ * @param[in] name The name of the created shortcut icon
+ * @param[in] type The type of shortcuts (livebox or shortcut, and its size if it is for the livebox)
+ * @param[in] content_info The specific information for delivering to the viewer for creating a shortcut
+ * @param[in] icon The absolute path of an icon file
+ * @param[in] allow_duplicate @c 1 if it accepts the duplicated shortcut,
+ *                            otherwise @c 0
+ * @param[in] result_cb The address of the callback function that is called when the result comes back from the viewer
+ * @param[in] data The callback data that is used in the callback function
  *
- * @post You have to check the return status from callback function which is passed by argument.
+ * @return The return type (int)
+ * @retval 0 Succeeded to send the request
+ * @retval #SHORTCUT_ERROR_FAULT Unrecoverable error
+ * @retval #SHORTCUT_ERROR_INVALID_PARAMETER Shortcut request is not valid, invalid parameter or invalid argument value
+ * @retval #SHORTCUT_ERROR_COMM Connection is not estabilished. or there is a problem in the communication
+ * @retval #SHORTCUT_ERROR_OUT_OF_MEMORY Memory is not enough to handle a new request
+ * @retval #SHORTCUT_ERROR_IO_ERROR Unable to access the file or DB. Check your resource files
+ * @retval #SHORTCUT_ERROR_PERMISSION_DENIED Has no permission to add a shortcut
+ * @retval #SHORTCUT_ERROR_NOT_SUPPORTED Shortcut is not supported
  *
- * @remarks - If a homescreen does not support this feature, you will get proper error code.
+ * @pre You have to prepare the callback function.
  *
- * @par Prospective Clients:
- * Inhouse Apps.
+ * @post You have to check the return status from the callback function which is passed by the argument.
+ *
+ * @see result_internal_cb_t
  *
  * @par Example
  * @code
@@ -350,89 +305,98 @@ extern int shortcut_set_request_cb(request_cb_t request_cb, void *data);
  *
  * @endcode
  */
-extern int add_to_home_shortcut(const char *appid, const char *name, int type, const char *content_info, const char *icon, int allow_duplicate, result_cb_t result_cb, void *data);
+extern int add_to_home_shortcut(const char *appid, const char *name, int type, const char *content_info, const char *icon, int allow_duplicate, result_internal_cb_t result_cb, void *data);
 
 /**
- * @fn shortcut_get_list(const char *appid, int (*cb)(const char *appid, const char *icon, const char *name, const char *extra_key, const char *extra_data, void *data), void *data)
  *
- * @brief Getting the installed shortcut view list
+ * @internal
+ *
+ * @brief Gets the installed shortcut view list.
  *
- * @par Sync (or) Async:
+ * @details
+ * Sync (or) Async:
  * This is a synchronous API.
  *
- * @par Important Notes:
- * - Application must check the return value of this function.
- * - Application must check the return status from the callback function
- * Application should set the callback function to get the result of this request.
+ * Important Notes:\n
+ * Application must check the return value of this function.\n
+ * Application must check the return status from the callback function.\n
+ * Application should set the callback function to get the result of this request.
  *
- * @param[in] appid Package name
- * @param[in] cb Callback function to get the shortcut item information
- * @param[in] data Callback data which will be used in callback function
+ * Prospective Clients:
+ * Inhouse Apps.
  *
- * @return Return Type (int)
- * \retval Number of items (call count of callback function) 
- * \retval SHORTCUT_ERROR_FAULT Unrecoverable error
- * \retval SHORTCUT_ERROR_IO Unable to access file or DB. Check your resource files
+ * @since_tizen 2.3
  *
- * @see result_cb_t
+ * @privlevel public
+ * @privilege %http://tizen.org/privilege/shortcut
  *
- * @pre You have to prepare the callback function
+ * @remarks If a homescreen does not support this feature, you will get a proper error code.
+ * @param[in] appid The  package name
+ * @param[in] cb The callback function to get the shortcut item information
+ * @param[in] data The callback data that is used in the callback function
  *
- * @post You have to check the return status from callback function which is passed by argument.
+ * @return The return type (int)
+ * @retval @c N Number of items (call count of the callback function)
+ * @retval #SHORTCUT_ERROR_FAULT Unrecoverable error
+ * @retval #SHORTCUT_ERROR_IO_ERROR Unable to access the file or DB. Check your resource files
  *
- * @remarks - If a homescreen does not support this feature, you will get proper error code.
+ * @pre You have to prepare the callback function.
  *
- * @par Prospective Clients:
- * Inhouse Apps.
+ * @post You have to check the return status from the callback function which is passed by the argument.
  *
- * @par Example
- * @code
- * @endcode
+ * @see result_internal_cb_t
  */
 extern int shortcut_get_list(const char *appid, int (*cb)(const char *appid, const char *icon, const char *name, const char *extra_key, const char *extra_data, void *data), void *data);
 
 /**
- * @fn add_to_home_livebox(const char *appid, const char *name, int type, const char *content, const char *icon, double period, int allow_duplicate, result_cb_t result_cb, void *data);
  *
- * @brief The application, which supporting the add_to_home feature, should invoke this.
  *
- * @par Sync (or) Async:
+ * @brief Supports the add_to_home feature, should invoke this.
+ *
+ * @details
+ * Sync (or) Async:
  * This is an asynchronous API.
  *
- * @par Important Notes:
- * - Application must check the return value of this function.
- * - Application must check the return status from the callback function
- * Application should set the callback function to get the result of this request.
+ * Important Notes:\n
+ * Application must check the return value of this function.\n
+ * Application must check the return status from the callback function.\n
+ * Application should set the callback function to get the result of this request.
  *
- * @param[in] appid Package name of owner of this shortcut.
- * @param[in] name Name for created shortcut icon.
- * @param[in] type Type of shortcuts (livebox or shortcut, and its size if it is for the livebox)
- * @param[in] content_info Specific information for delivering to the viewer for creating a shortcut.
- * @param[in] icon Absolute path of an icon file
- * @param[in] period Update period
- * @param[in] allow_duplicate set 1 If accept the duplicated shortcut or 0
- * @param[in] result_cb Address of callback function which will be called when the result comes back from the viewer.
- * @param[in] data Callback data which will be used in callback function
+ * Prospective Clients:
+ * Inhouse Apps.
  *
- * @return Return Type (int)
- * \retval 0 Succeed to send the request
- * \retval SHORTCUT_ERROR_FAULT Unrecoverable error
- * \retval SHORTCUT_ERROR_INVALID Shortcut request is not valid, invalid parameter or invalid argument value
- * \retval SHORTCUT_ERROR_COMM Connection is not estabilished. or there is a problem of communication
- * \retval SHORTCUT_ERROR_MEMORY Memory is not enough to handle new request
- * \retval SHORTCUT_ERROR_IO Unable to access file or DB. Check your resource files
- * \retval SHORTCUT_ERROR_PERMISSION Has no permission to add a shortcut
+ * @since_tizen 2.3
  *
- * @see result_cb_t
+ * @privlevel public
+ * @privilege %http://tizen.org/privilege/shortcut
  *
- * @pre You have to prepare the callback function
+ * @remarks If a homescreen does not support this feature, you will get a proper error code.
+ * @param[in] appid The package name of the owner of this shortcut
+ * @param[in] name The name of the created shortcut icon
+ * @param[in] type The type of shortcuts (livebox or shortcut, and its size if it is for the livebox)
+ * @param[in] content_info The specific information for delivering to the viewer for creating a shortcut
+ * @param[in] icon The absolute path of an icon file
+ * @param[in] period The update period
+ * @param[in] allow_duplicate @c 1 if it accepts the duplicated shortcut,
+ *                            otherwise @c 0
+ * @param[in] result_cb The address of the callback function that is called when the result comes back from the viewer
+ * @param[in] data The callback data that is used in the callback function
  *
- * @post You have to check the return status from callback function which is passed by argument.
+ * @return The return type (int)
+ * @retval 0 Succeeded to send the request
+ * @retval #SHORTCUT_ERROR_FAULT Unrecoverable error
+ * @retval #SHORTCUT_ERROR_INVALID_PARAMETER Shortcut request is not valid, invalid parameter or invalid argument value
+ * @retval #SHORTCUT_ERROR_COMM Connection is not established or there is a problem in the communication
+ * @retval #SHORTCUT_ERROR_OUT_OF_MEMORY Memory is not enough to handle a new request
+ * @retval #SHORTCUT_ERROR_IO_ERROR Unable to access the file or DB  Check your resource files
+ * @retval #SHORTCUT_ERROR_PERMISSION_DENIED Has no permission to add a shortcut
+ * @retval #SHORTCUT_ERROR_NOT_SUPPORTED Shortcut is not supported
  *
- * @remarks - If a homescreen does not support this feature, you will get proper error code.
+ * @pre You have to prepare the callback function.
  *
- * @par Prospective Clients:
- * Inhouse Apps.
+ * @post You have to check the return status from the callback function which is passed by the argument.
+ *
+ * @see result_internal_cb_t
  *
  * @par Example
  * @code
@@ -464,78 +428,21 @@ extern int shortcut_get_list(const char *appid, int (*cb)(const char *appid, con
  *
  * @endcode
  */
-extern int add_to_home_livebox(const char *appid, const char *name, int type, const char *content, const char *icon, double period, int allow_duplicate, result_cb_t result_cb, void *data);
-
-extern int add_to_home_remove_shortcut(const char *appid, const char *name, const char *content_info, result_cb_t result_cb, void *data);
-
-extern int add_to_home_remove_livebox(const char *appid, const char *name, result_cb_t result_cb, void *data);
-
+extern int add_to_home_livebox(const char *appid, const char *name, int type, const char *content, const char *icon, double period, int allow_duplicate, result_internal_cb_t result_cb, void *data);
 
+struct shortcut_icon;
 
-/*!
- * \note
- * Example)
- *
- * \code
- * static int init_cb(int status, void *data)
- * {
- *    printf("Initializer returns: %d\n", status);
- *    if (status == 0) {
- *        printf("Succeed to initialize\n");
- *    } else {
- *        printf("Failed to initialize: %d\n", status);
- *    }
- * }
- *
- * int main(int argc, char *argv[])
- * {
- *     // Initialize the service request
- *     int ret;
- *
- *     // After the init_cb is called, you can use below functions.
- *     struct shortcut_icon *handle;
- *
- *     ret = shortcut_icon_init(init_cb, NULL);
- *     if (ret < 0) {
- *        ...
- *
- *     // Create request for creating shortcut icon.
- *     handle = shortcut_icon_create();
- *     if (!handle) {
- *         ...
- *     }
- * 
- *     // Send the request to the shortcut service
- *     ret = shortcut_icon_request_set_info(handle, NULL, SHORTCUT_ICON_TYPE_IMAGE, "icon, "/usr/share/.../icon.png", NULL, NULL);
- *     if (ret < 0) {
- *        ...
- *     }
- *
- *     ret = shortcut_icon_request_set_info(handle, NULL, SHORTCUT_ICON_TYPE_TEXT, "text, "app icon", NULL, NULL);
- *     if (ret < 0) {
- *        ...
- *     }
- *
- *     ret = shortcut_icon_request_send(handle, LB_SIZE_TYPE_1x1, NULL, NULL, "/opt/usr/apps/org.tizen.cluster-home/data/out.png", result_cb, NULL);
- *     if (ret < 0) {
- *        ...
- *     }
- *
- *     ret = shortcut_icon_request_destroy(handle);
- *     if (ret < 0) {
- *        ...
- *     }
- *
- *     // Don't finalize the icon service if you don't get result callbacks of all requests
- *     ret = shortcut_icon_fini();
- *     if (ret < 0) {
- *        ...
- *     }
- *
- *     return 0;
- * }
- * \endcode
+/**
+ * @brief Called when send a request to create a icon snapshot image.
+ * @details This callback will be called with its result.
+ * @param[in] handle Handle of requestor
+ * @param[in] ret status of request
+ * @param[in] data Callback data
+ * @return int result state of callback call
+ * @retval 0 If it is successfully completed
+ * @see shortcut_icon_request_send()
  */
+typedef int (*icon_request_cb_t)(struct shortcut_icon *handle, int ret, void *data);
 
 #define DEFAULT_ICON_PART              "icon"
 #define DEFAULT_NAME_PART              "name"
@@ -543,139 +450,108 @@ extern int add_to_home_remove_livebox(const char *appid, const char *name, resul
 #define SHORTCUT_ICON_TYPE_TEXT                "text"
 #define SHORTCUT_ICON_TYPE_SCRIPT      "script"
 
-/*!
- * \brief Initialize the icon creation service
- * \remarks N/A
- * \details N/A
- * \param[in] init_cb Initialized result will be delievered via this callback
- * \param[in] data Callback data
- * \pre N/A
- * \post N/A
- * \return int
- * \retval SHORTCUT_ERROR_INVALID Already initialized
- * \retval SHORTCUT_ERROR_SUCCESS Successfully initialized
- * \see shortcut_icon_service_fini
+/**
+ * @brief Initializes the icon creation service.
+ * @param[in] init_cb Initialized result will be delievered via this callback
+ * @param[in] data Callback data
+ * @return int value
+ * @retval #SHORTCUT_ERROR_INVALID_PARAMETER Already initialized
+ * @retval #SHORTCUT_ERROR_NONE Successfully initialized
+ * @see shortcut_icon_service_fini()
  */
 extern int shortcut_icon_service_init(int (*init_cb)(int status, void *data), void *data);
 
-/*!
- * \brief Finalize the icon creation service
- * \remarks N/A
- * \details N/A
- * \pre N/A
- * \post N/A
- * \return int
- * \retval SHORTCUT_SUCCESS Successfully initialized
- * \retval SHORTCUT_ERROR_INVALID icon service is not initialized
- * \see shortcut_icon_service_init
+/**
+ * @brief Finalizes the icon creation service.
+ * @return int value
+ * @retval #SHORTCUT_ERROR_NONE Successfully initialized
+ * @retval #SHORTCUT_ERROR_INVALID_PARAMETER icon service is not initialized
+ * @see shortcut_icon_service_init()
  */
 extern int shortcut_icon_service_fini(void);
 
-/*!
- * \brief Create a request object to create a new icon image
- * \remarks N/A
- * \details N/A
- * \pre N/A
- * \post N/A
- * \return struct shortcut_icon *
- * \retval NULL If it fails to create a new handle
- * \retval pointer Handle address
- * \see shortcut_icon_request_destroy
+/**
+ * @brief Creates a request object to create a new icon image.
+ * @return struct shortcut_icon * value
+ * @retval @c NULL If it fails to create a new handle
+ * @retval pointer Handle address
+ * @see shortcut_icon_request_destroy()
  */
 extern struct shortcut_icon *shortcut_icon_request_create(void);
 
-/*!
- * \brief Set infomration for creating icon image
- * \details N/A
- * \remarks N/A
- * \param[in] handle Request handle
- * \param[in] id Target ID to be affected by this data
- * \param[in] type SHORTCUT_ICON_TYPE_IMAGE, SHORTCUT_ICON_TYPE_TEXT, SHORTCUT_ICON_TYPE_SCRIPT can be used
- * \param[in] part Target part to be affect by this data
- * \param[in] data type == IMAGE ? Image file path : type == TEXT ? text string : type == SCRIPT ? script file path : N/A
- * \param[in] option Image load option or group name of script file to be loaded
- * \param[in] subid ID for script. this ID will be used as "id"
- * \pre N/A
- * \post N/A
- * \return int
- * \retval Index of data set
- * \retval SHORTCUT_ERROR_INVALID Invalid handle
- * \retval SHORTCUT_ERROR_MEMORY Out of memory
- * \see shortcut_icon_request_create
+/**
+ * @brief Sets information for creating icon image.
+ * @param[in] handle Request handle
+ * @param[in] id Target ID to be affected by this data
+ * @param[in] type SHORTCUT_ICON_TYPE_IMAGE, SHORTCUT_ICON_TYPE_TEXT, SHORTCUT_ICON_TYPE_SCRIPT can be used
+ * @param[in] part Target part to be affect by this data
+ * @param[in] data type == IMAGE ? Image file path : type == TEXT ? text string : type == SCRIPT ? script file path : N/A
+ * @param[in] option Image load option or group name of script file to be loaded
+ * @param[in] subid ID for script. this ID will be used as "id"
+ * @return int value
+ * @retval index Index of data set
+ * @retval #SHORTCUT_ERROR_INVALID_PARAMETER Invalid handle
+ * @retval #SHORTCUT_ERROR_OUT_OF_MEMORY Out of memory
+ * @see shortcut_icon_request_create()
  */
 extern int shortcut_icon_request_set_info(struct shortcut_icon *handle, const char *id, const char *type, const char *part, const char *data, const char *option, const char *subid);
 
-/*!
- * \brief Send request to create an icon image
- * \remarks N/A
- * \details N/A
- * \param[in] handle Icon request handle
- * \param[in] size_type Size type to be created
- * \param[in] layout layout filename (edje filename)
- * \param[in] group group name
- * \param[in] outfile output image filename
- * \param[in] result_cb Result callback
- * \param[in] data Callback data
- * \pre N/A
- * \post N/A
- * \return int
- * \retval SHORTCUT_ERROR_INVALID Invalid parameters
- * \retval SHORTCUT_ERROR_MEMORY Out of memory
- * \retval SHORTCUT_ERROR_FAULT Failed to send a request
- * \retval SHORTCUT_SUCCESS Successfully sent
- * \see shortcut_icon_service_fini
+/**
+ * @brief Sends requests to create an icon image.
+ * @param[in] handle Icon request handle
+ * @param[in] size_type Size type to be created
+ * @param[in] layout Layout filename (edje filename)
+ * @param[in] group Group name
+ * @param[in] outfile Output image filename
+ * @param[in] result_cb Result callback
+ * @param[in] data Callback data
+ * @return int value
+ * @retval #SHORTCUT_ERROR_INVALID_PARAMETER Invalid parameters
+ * @retval #SHORTCUT_ERROR_OUT_OF_MEMORY Out of memory
+ * @retval #SHORTCUT_ERROR_FAULT Failed to send a request
+ * @retval #SHORTCUT_ERROR_NONE Successfully sent
+ * @see shortcut_icon_service_fini()
  */
 extern int shortcut_icon_request_send(struct shortcut_icon *handle, int size_type, const char *layout, const char *group, const char *outfile, icon_request_cb_t result_cb, void *data);
 
-/*!
- * \brief Destroy handle of creating shortcut icon request
- * \remarks N/A
- * \details N/A
- * \param[in] handle Shortcut request handle
- * \pre N/A
- * \post N/A
- * \return int
- * \retval SHORTCUT_ERROR_INVALID Invalid handle
- * \retval SHORTCUT_SUCCESS Successfully destroyed
- * \see shortcut_icon_service_fini
+/**
+ * @brief Destroys handle of creating shortcut icon request.
+ * @param[in] handle Shortcut request handle
+ * @return int value
+ * @retval #SHORTCUT_ERROR_INVALID_PARAMETER Invalid handle
+ * @retval #SHORTCUT_ERROR_NONE Successfully destroyed
+ * @see shortcut_icon_service_fini()
  */
 extern int shortcut_icon_request_destroy(struct shortcut_icon *handle);
 
 
-/*!
- * \brief Set private data to the handle to carry it with a handle.
- * \remarks N/A
- * \details N/A
- * \param[in] handle Handle to be used for carrying a data
- * \param[in] data Private data
- * \pre N/A
- * \post N/A
- * \return int
- * \retval SHORTCUT_ERROR_INVALID Invalid handle
- * \retval SHORTCUT_SUCCESS Successfully done
- * \see shortcut_icon_service_fini
+/**
+ * @brief Sets private data to the handle to carry it with a handle.
+ * @param[in] handle Handle to be used for carrying a data
+ * @param[in] data Private data
+ * @return int value
+ * @retval #SHORTCUT_ERROR_INVALID_PARAMETER Invalid handle
+ * @retval #SHORTCUT_ERROR_NONE Successfully done
+ * @see shortcut_icon_service_fini()
  */
 extern int shortcut_icon_request_set_data(struct shortcut_icon *handle, void *data);
 
-/*!
- * \brief Get the private data from handle
- * \remarks N/A
- * \details N/A
- * \param[in] handle
- * \pre N/A
- * \post N/A
- * \return int
- * \retval NULL If there is no data
- * \retval pointer data pointer
- * \see shortcut_icon_request_set_data
+/**
+ * @brief Gets the private data from handle.
+ * @param[in] handle
+ * @return int value
+ * @retval @c NULL If there is no data
+ * @retval pointer data pointer
+ * @see shortcut_icon_request_set_data()
  */
 extern void *shortcut_icon_request_data(struct shortcut_icon *handle);
 
+/**
+ * @}
+ */
+
 #ifdef __cplusplus
 }
 #endif
 
 #endif
-/* @}
- * End of a file 
- */
index c343603..51c2162 100644 (file)
@@ -37,7 +37,9 @@ extern FILE *__file_log_fp;
 #define ErrPrint(format, arg...) do { fprintf(__file_log_fp, "[ERR] [\e[32m%s/%s\e[0m:%d] " format, basename(__FILE__), __func__, __LINE__, ##arg); fflush(__file_log_fp); } while (0)
 #endif
 
+#if !defined(EAPI)
 #define EAPI __attribute__((visibility("default")))
+#endif
 
 #if !defined(VCONFKEY_MASTER_STARTED)
 #define VCONFKEY_MASTER_STARTED        "memory/data-provider-master/started"
@@ -46,4 +48,182 @@ extern FILE *__file_log_fp;
 #define DEFAULT_ICON_LAYOUT ""
 #define DEFAULT_ICON_GROUP ""
 
+/**
+ * @brief Definition for a macro to check the request type.
+ * @since_tizen 2.3
+ * @param[in] type Request type
+ * @return bool
+ * @retval true(1) Shortcut remove request
+ * @retval false(0) Not a remove request
+ * @see shortcut_type
+ */
+#define ADD_TO_HOME_IS_REMOVE_SHORTCUT(type)   (!!((type) & SHORTCUT_REMOVE))
+
+/**
+ * @brief Definition for a macro to check the request type.
+ * @since_tizen 2.3
+ * @param[in] type Request type
+ * @return bool
+ * @retval true(1) Dynamicbox remove request
+ * @retval false(0) Not a remove request
+ * @see shortcut_type
+ */
+#define ADD_TO_HOME_IS_REMOVE_LIVEBOX(type)    (!!((type) & LIVEBOX_REMOVE))
+
+/**
+ * @brief Called to receive the result of add_to_home_shortcut().
+ * @since_tizen 2.3
+ * @param[in] ret The result value, it could be @c 0 if it succeeds to add a shortcut, 
+ *                otherwise it returns an errno
+ * @param[in] pid The process ID of who handle this add_to_home request
+ * @param[in] data The callback data
+ * @return int @c 0 if there is no error,
+               otherwise errno
+ * @see add_to_home_shortcut()
+ */
+typedef int (*result_internal_cb_t)(int ret, int pid, void *data);
+
+/**
+ *
+ *
+ * @brief The application, which supporting the add_to_home feature, should invoke this.
+ *
+ * @details
+ * Sync (or) Async:
+ * This is an asynchronous API.
+ *
+ * Important Notes:\n
+ * Application must check the return value of this function.\n
+ * Application must check the return status from the callback function\n
+ * Application should set the callback function to get the result of this request.
+ *
+ * Prospective Clients:
+ * Inhouse Apps.
+ *
+ * @since_tizen 2.3
+ *
+ * @remarks - If a homescreen does not support this feature, you will get proper error code.
+ * @param[in] appid Package name of owner of this shortcut.
+ * @param[in] name Name for created shortcut icon.
+ * @param[in] content_info Specific information for delivering to the viewer for creating a shortcut.
+ * @param[in] result_cb Address of callback function which will be called when the result comes back from the viewer.
+ * @param[in] data Callback data which will be used in callback function
+ *
+ * @return Return Type (int)
+ * \retval 0 Succeed to send the request
+ * \retval #SHORTCUT_ERROR_FAULT Unrecoverable error
+ * \retval #SHORTCUT_ERROR_INVALID_PARAMETER Shortcut request is not valid, invalid parameter or invalid argument value
+ * \retval #SHORTCUT_ERROR_COMM Connection is not estabilished. or there is a problem of communication
+ * \retval #SHORTCUT_ERROR_OUT_OF_MEMORY Memory is not enough to handle new request
+ * \retval #SHORTCUT_ERROR_IO_ERROR Unable to access file or DB. Check your resource files
+ * \retval #SHORTCUT_ERROR_PERMISSION_DENIED Has no permission to add a shortcut
+ *
+ * @pre You have to prepare the callback function
+ *
+ * @post You have to check the return status from callback function which is passed by argument.
+ *
+ * @see result_internal_cb_t
+ *
+ * @par Example
+ * @code
+ *
+ * #include <stdio.h>
+ * #include <shortcut.h>
+ *
+ * static int result_cb(int ret, int pid, void *data)
+ * {
+ *     if (ret < 0)
+ *             printf("Failed to add a shortcut: %s\n", perror(ret));
+ *
+ *     printf("Processed by the %d\n", pid);
+ *     return 0;
+ * }
+ *
+ * static int app_create(void *data)
+ * {
+ *     add_to_home_remove_shortcut("org.tizen.gallery.livebox", "With friends",
+ *                                     "gallery:0000-0000",
+ *                                     result_cb, NULL);
+ *     return 0;
+ * }
+ *
+ * int main(int argc, char *argv[])
+ * {
+ *     appcore....
+ * }
+ *
+ * @endcode
+ */
+extern int add_to_home_remove_shortcut(const char *appid, const char *name, const char *content_info, result_internal_cb_t result_cb, void *data);
+
+/**
+ *
+ *
+ * @brief The application, which supporting the add_to_home feature, should invoke this.
+ *
+ * @details
+ * Sync (or) Async:
+ * This is an asynchronous API.
+ *
+ * Important Notes:\n
+ * Application must check the return value of this function.\n
+ * Application must check the return status from the callback function\n
+ * Application should set the callback function to get the result of this request.
+ *
+ * Prospective Clients:
+ * Inhouse Apps.
+ *
+ * @since_tizen 2.3
+ *
+ * @remarks - If a homescreen does not support this feature, you will get proper error code.
+ * @param[in] appid Package name of owner of this shortcut.
+ * @param[in] name Name for created shortcut icon.
+ * @param[in] result_cb Address of callback function which will be called when the result comes back from the viewer.
+ * @param[in] data Callback data which will be used in callback function
+ *
+ * @return Return Type (int)
+ * \retval 0 Succeed to send the request
+ * \retval #SHORTCUT_ERROR_FAULT Unrecoverable error
+ * \retval #SHORTCUT_ERROR_INVALID_PARAMETER Shortcut request is not valid, invalid parameter or invalid argument value
+ * \retval #SHORTCUT_ERROR_COMM Connection is not estabilished. or there is a problem of communication
+ * \retval #SHORTCUT_ERROR_OUT_OF_MEMORY Memory is not enough to handle new request
+ * \retval #SHORTCUT_ERROR_IO_ERROR Unable to access file or DB. Check your resource files
+ * \retval #SHORTCUT_ERROR_PERMISSION_DENIED Has no permission to add a shortcut
+ *
+ * @pre You have to prepare the callback function
+ *
+ * @post You have to check the return status from callback function which is passed by argument.
+ *
+ * @see result_internal_cb_t
+ *
+ * @par Example
+ * @code
+ *
+ * #include <stdio.h>
+ * #include <shortcut.h>
+ *
+ * static int result_cb(int ret, int pid, void *data)
+ * {
+ *     if (ret < 0)
+ *             printf("Failed to add a shortcut: %s\n", perror(ret));
+ *
+ *     printf("Processed by the %d\n", pid);
+ *     return 0;
+ * }
+ *
+ * static int app_create(void *data)
+ * {
+ *     add_to_home_remove_livebox("org.tizen.gallery.livebox", "With friends", result_cb, NULL);
+ *     return 0;
+ * }
+ *
+ * int main(int argc, char *argv[])
+ * {
+ *     appcore....
+ * }
+ *
+ * @endcode
+ */
+extern int add_to_home_remove_livebox(const char *appid, const char *name, result_internal_cb_t result_cb, void *data);
+
 /* End of a file */
diff --git a/lib/include/shortcut_manager.h b/lib/include/shortcut_manager.h
new file mode 100644 (file)
index 0000000..5cbab0b
--- /dev/null
@@ -0,0 +1,177 @@
+/*
+ * Copyright (c) 2000 - 2013 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+*/
+
+#ifndef __SHORTCUT_MANAGER_H__
+#define __SHORTCUT_MANAGER_H__
+
+#include <tizen.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * @file shortcut_manager.h
+ * @brief This file declares the API of the libshortcut library.
+ */
+
+/**
+ * @addtogroup SHORTCUT_MODULE
+ * @{
+ */
+
+/**
+ * @brief Called to receive the result of shortcut_add_to_home().
+ * @since_tizen 2.3
+ * @param[in] ret The result value, it could be @c 0 if it succeeds to add a shortcut, 
+ *                otherwise it returns an errno
+ * @param[in] data The callback data
+ * @return int @c 0 if there is no error,
+               otherwise errno
+ * @see shortcut_add_to_home()
+ */
+typedef int (*result_cb_t)(int ret, void *data);
+
+/**
+ * @brief Enumeration for shortcut types.
+ * @details Basically, two types of shortcuts are defined.
+ *          Every homescreen developer should support these types of shortcuts.
+ *          Or return a proper errno to figure out why the application failed to add a shortcut.
+ *          #LAUNCH_BY_APP is used for adding a package itself as a shortcut.
+ *          #LAUNCH_BY_URI is used for adding a shortcut for "uri" data.
+ * @since_tizen 2.3
+ */
+typedef enum _shortcut_type {
+       /**< Use these */
+       LAUNCH_BY_APP   = 0x00000000,   /**< Launch the application itself */
+       LAUNCH_BY_URI   = 0x00000001,   /**< Launch the application with the given data(URI) */
+} shortcut_type;
+
+/**
+ * @brief Enumeration for values of shortcut response types.
+ * @since_tizen 2.3
+ */
+enum shortcut_error_e {
+       SHORTCUT_ERROR_NONE = TIZEN_ERROR_NONE,                         /**< Successfully handled */
+       SHORTCUT_ERROR_INVALID_PARAMETER = TIZEN_ERROR_INVALID_PARAMETER,       /**< Shortcut request is not valid, invalid parameter or invalid argument value */
+       SHORTCUT_ERROR_OUT_OF_MEMORY = TIZEN_ERROR_OUT_OF_MEMORY,       /**< Memory is not enough to handle a new request */
+       SHORTCUT_ERROR_IO_ERROR = TIZEN_ERROR_IO_ERROR,         /**< Unable to access the file or DB. Check your resource files */
+       SHORTCUT_ERROR_PERMISSION_DENIED = TIZEN_ERROR_PERMISSION_DENIED,       /**< Has no permission to add a shortcut */
+       SHORTCUT_ERROR_NOT_SUPPORTED = TIZEN_ERROR_NOT_SUPPORTED,       /**< Not supported shortcut */
+       SHORTCUT_ERROR_RESOURCE_BUSY = TIZEN_ERROR_RESOURCE_BUSY,               /**< Receiver is busy, try again later */
+       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,           /**< Failed to add a shortcut. Unrecoverable error */
+       SHORTCUT_ERROR_COMM = TIZEN_ERROR_SHORTCUT | 0x0040             /**< Connection is not established. or there is a problem in the communication */
+};
+
+/**
+ *
+ * @brief Supports the add_to_home feature, should invoke this.
+ *
+ * @details
+ * Sync (or) Async:
+ * This is an asynchronous API.
+ *
+ * @since_tizen 2.3
+ *
+ * @privlevel public
+ * @privilege %http://tizen.org/privilege/shortcut
+ *
+ * @remarks Application must check the return value of this function.\n
+ * Application must check the return status from the callback function.\n
+ * Application should set the callback function to get the result of this request.
+ * @remarks If a homescreen does not support this feature, you will get a proper error code.
+ *
+ * @param[in] name The name of the created shortcut icon
+ * @param[in] type The type of shortcuts
+ * @param[in] uri The specific information for delivering to the viewer for creating a shortcut
+ * @param[in] icon The absolute path of an icon file
+ * @param[in] allow_duplicate @c 1 if it accepts the duplicated shortcut,
+ *                            otherwise @c 0
+ * @param[in] result_cb The address of the callback function that is called when the result comes back from the viewer
+ * @param[in] data The callback data that is used in the callback function
+ *
+ * @return @c 0 on success, otherwise a negative error value
+ * @retval #SHORTCUT_ERROR_NONE Successful
+ * @retval #SHORTCUT_ERROR_INVALID_PARAMETER Invalid 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_NO_SPACE No space
+ * @retval #SHORTCUT_ERROR_EXIST Already exist
+ * @retval #SHORTCUT_ERROR_FAULT Unrecoverable error
+ * @retval #SHORTCUT_ERROR_COMM Connection failed
+ *
+ * @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 <stdio.h>
+ * #include <shortcut_manager.h>
+ *
+ * static int result_cb(int ret, int pid, void *data)
+ * {
+ *     if (ret < 0)
+ *             printf("Failed to add a shortcut: %s\n", perror(ret));
+ *
+ *     printf("Processed by the %d\n", pid);
+ *     return 0;
+ * }
+ *
+ * static int app_create(void *data)
+ * {
+ *     char* data_path = app_get_data_path();
+ *     int path_len = strlen(data_path)+10;
+ *     char * path = malloc(path_len);
+ *     memset(path, 0, path_len);
+ *     strncat(path, data_path, path_len);
+ *     strncat(path, "Friend.jpg", path_len); 
+ *
+ *     shortcut_add_to_home("With friends",
+ *                                     LAUNCH_BY_URI, "gallery:0000-0000",
+ *                                     path, 0, result_cb, NULL);
+ *     free(path);
+ *
+ *     return 0;
+ * }
+ *
+ * int main(int argc, char *argv[])
+ * {
+ *     appcore....
+ * }
+ *
+ * @endcode
+ */
+extern 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);
+
+/**
+ * @}
+ */
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
index 8daf96d..060e119 100644 (file)
@@ -6,5 +6,6 @@ includedir=@INCLUDEDIR@
 Name: shortcut
 Description: shortcut server platform library
 Version: @VERSION@
+Requires: capi-base-common
 Libs: -L${libdir} -lshortcut
 Cflags: -I${includedir}
index fa2bd11..4e0619b 100644 (file)
@@ -215,13 +215,13 @@ static inline int shortcut_icon_desc_save(struct shortcut_desc *handle, const ch
        FILE *fp;
 
        if (!handle) {
-               return SHORTCUT_ERROR_INVALID;
+               return SHORTCUT_ERROR_INVALID_PARAMETER;
        }
 
        fp = fopen(filename, "w+t");
        if (!fp) {
                ErrPrint("Error: %s\n", strerror(errno));
-               return SHORTCUT_ERROR_IO;
+               return SHORTCUT_ERROR_IO_ERROR;
        }
 
        DbgPrint("Close and flush\n");
@@ -265,7 +265,7 @@ static inline int shortcut_icon_desc_save(struct shortcut_desc *handle, const ch
        if (fclose(fp) != 0) {
                ErrPrint("fclose: %s\n", strerror(errno));
        }
-       return SHORTCUT_SUCCESS;
+       return SHORTCUT_ERROR_NONE;
 }
 
 
@@ -295,7 +295,7 @@ static inline int update_block(struct block *block, const char *data, const char
                _data = strdup(data);
                if (!_data) {
                        ErrPrint("Heap: %s\n", strerror(errno));
-                       return SHORTCUT_ERROR_MEMORY;
+                       return SHORTCUT_ERROR_OUT_OF_MEMORY;
                }
        }
 
@@ -303,7 +303,8 @@ static inline int update_block(struct block *block, const char *data, const char
                _option = strdup(option);
                if (!_option) {
                        ErrPrint("Heap: %s\n", strerror(errno));
-                       return SHORTCUT_ERROR_MEMORY;
+                       free(_data);
+                       return SHORTCUT_ERROR_OUT_OF_MEMORY;
                }
        }
 
@@ -328,7 +329,7 @@ static inline int shortcut_icon_desc_add_block(struct shortcut_desc *handle, con
        struct block *block;
 
        if (!handle || !type) {
-               return SHORTCUT_ERROR_INVALID;
+               return SHORTCUT_ERROR_INVALID_PARAMETER;
        }
 
        if (!part) {
@@ -342,7 +343,7 @@ static inline int shortcut_icon_desc_add_block(struct shortcut_desc *handle, con
        if (target_id) {
                if (strcmp(type, SHORTCUT_ICON_TYPE_SCRIPT)) {
                        ErrPrint("target id only can be used for script type\n");
-                       return SHORTCUT_ERROR_INVALID;
+                       return SHORTCUT_ERROR_INVALID_PARAMETER;
                }
        }
 
@@ -351,14 +352,14 @@ static inline int shortcut_icon_desc_add_block(struct shortcut_desc *handle, con
                block = calloc(1, sizeof(*block));
                if (!block) {
                        ErrPrint("Heap: %s\n", strerror(errno));
-                       return SHORTCUT_ERROR_MEMORY;
+                       return SHORTCUT_ERROR_OUT_OF_MEMORY;
                }
 
                block->type = strdup(type);
                if (!block->type) {
                        ErrPrint("Heap: %s\n", strerror(errno));
                        free(block);
-                       return SHORTCUT_ERROR_MEMORY;
+                       return SHORTCUT_ERROR_OUT_OF_MEMORY;
                }
 
                block->part = strdup(part);
@@ -366,7 +367,7 @@ static inline int shortcut_icon_desc_add_block(struct shortcut_desc *handle, con
                        ErrPrint("Heap: %s\n", strerror(errno));
                        free(block->type);
                        free(block);
-                       return SHORTCUT_ERROR_MEMORY;
+                       return SHORTCUT_ERROR_OUT_OF_MEMORY;
                }
 
                block->data = strdup(data);
@@ -375,7 +376,7 @@ static inline int shortcut_icon_desc_add_block(struct shortcut_desc *handle, con
                        free(block->type);
                        free(block->part);
                        free(block);
-                       return SHORTCUT_ERROR_MEMORY;
+                       return SHORTCUT_ERROR_OUT_OF_MEMORY;
                }
 
                if (option) {
@@ -386,7 +387,7 @@ static inline int shortcut_icon_desc_add_block(struct shortcut_desc *handle, con
                                free(block->type);
                                free(block->part);
                                free(block);
-                               return SHORTCUT_ERROR_MEMORY;
+                               return SHORTCUT_ERROR_OUT_OF_MEMORY;
                        }
                }
 
@@ -399,7 +400,7 @@ static inline int shortcut_icon_desc_add_block(struct shortcut_desc *handle, con
                                free(block->type);
                                free(block->part);
                                free(block);
-                               return SHORTCUT_ERROR_MEMORY;
+                               return SHORTCUT_ERROR_OUT_OF_MEMORY;
                        }
                }
 
@@ -413,7 +414,7 @@ static inline int shortcut_icon_desc_add_block(struct shortcut_desc *handle, con
                                free(block->type);
                                free(block->part);
                                free(block);
-                               return SHORTCUT_ERROR_MEMORY;
+                               return SHORTCUT_ERROR_OUT_OF_MEMORY;
                        }
                }
 
@@ -422,17 +423,17 @@ static inline int shortcut_icon_desc_add_block(struct shortcut_desc *handle, con
        } else {
                if (strcmp(block->type, type)) {
                        ErrPrint("type is not valid (%s, %s)\n", block->type, type);
-                       return SHORTCUT_ERROR_INVALID;
+                       return SHORTCUT_ERROR_INVALID_PARAMETER;
                }
 
                if ((block->target_id && !target_id) || (!block->target_id && target_id)) {
                        ErrPrint("type is not valid (%s, %s)\n", block->type, type);
-                       return SHORTCUT_ERROR_INVALID;
+                       return SHORTCUT_ERROR_INVALID_PARAMETER;
                }
 
                if (block->target_id && target_id && strcmp(block->target_id, target_id)) {
                        ErrPrint("type is not valid (%s, %s)\n", block->type, type);
-                       return SHORTCUT_ERROR_INVALID;
+                       return SHORTCUT_ERROR_INVALID_PARAMETER;
                }
 
                update_block(block, data, option);
@@ -492,7 +493,7 @@ static inline int make_connection(void)
                struct pending_item *pend;
 
                if (s_info.init_cb) {
-                       s_info.init_cb(SHORTCUT_SUCCESS, s_info.cbdata);
+                       s_info.init_cb(SHORTCUT_ERROR_NONE, s_info.cbdata);
                }
 
                dlist_foreach_safe(s_info.pending_list, l, n, pend) {
@@ -511,7 +512,7 @@ static inline int make_connection(void)
                        free(pend);
                }
 
-               ret = SHORTCUT_SUCCESS;
+               ret = SHORTCUT_ERROR_NONE;
        }
 
        return ret;
@@ -527,7 +528,7 @@ static void master_started_cb(keynode_t *node, void *user_data)
                ErrPrint("Unable to get \"%s\"\n", VCONFKEY_MASTER_STARTED);
        }
 
-       if (state == 1 && make_connection() == SHORTCUT_SUCCESS) {
+       if (state == 1 && (make_connection() == SHORTCUT_ERROR_NONE)) {
                int ret;
                ret = vconf_ignore_key_changed(VCONFKEY_MASTER_STARTED, master_started_cb);
                DbgPrint("Ignore VCONF [%d]\n", ret);
@@ -541,7 +542,7 @@ EAPI int shortcut_icon_service_init(int (*init_cb)(int status, void *data), void
        int ret;
 
        if (s_info.fd >= 0) {
-               return SHORTCUT_ERROR_INVALID;
+               return SHORTCUT_ERROR_INVALID_PARAMETER;
        }
 
        if (s_info.initialized) {
@@ -560,7 +561,7 @@ EAPI int shortcut_icon_service_init(int (*init_cb)(int status, void *data), void
        }
 
        master_started_cb(NULL, NULL);
-       return SHORTCUT_SUCCESS;
+       return SHORTCUT_ERROR_NONE;
 }
 
 
@@ -577,7 +578,7 @@ EAPI int shortcut_icon_service_fini(void)
        }
 
        if (s_info.fd < 0) {
-               return SHORTCUT_ERROR_INVALID;
+               return SHORTCUT_ERROR_INVALID_PARAMETER;
        }
 
        com_core_packet_client_fini(s_info.fd);
@@ -594,7 +595,7 @@ EAPI int shortcut_icon_service_fini(void)
                free(pend->item);
                free(pend);
        }
-       return SHORTCUT_SUCCESS;
+       return SHORTCUT_ERROR_NONE;
 }
 
 
@@ -626,11 +627,11 @@ EAPI int shortcut_icon_request_set_data(struct shortcut_icon *handle, void *data
 {
        if (!handle || handle->state != CREATED) {
                ErrPrint("Handle is not valid\n");
-               return SHORTCUT_ERROR_INVALID;
+               return SHORTCUT_ERROR_INVALID_PARAMETER;
        }
 
        handle->data = data;
-       return SHORTCUT_SUCCESS;
+       return SHORTCUT_ERROR_NONE;
 }
 
 
@@ -651,7 +652,7 @@ EAPI int shortcut_icon_request_set_info(struct shortcut_icon *handle, const char
 {
        if (!handle || handle->state != CREATED) {
                ErrPrint("Handle is not valid\n");
-               return SHORTCUT_ERROR_INVALID;
+               return SHORTCUT_ERROR_INVALID_PARAMETER;
        }
 
        return shortcut_icon_desc_add_block(handle->desc, id, type, part, data, option, subid);
@@ -663,11 +664,11 @@ EAPI int shortcut_icon_request_destroy(struct shortcut_icon *handle)
 {
        if (!handle || handle->state != CREATED) {
                ErrPrint("Handle is not valid\n");
-               return SHORTCUT_ERROR_INVALID;
+               return SHORTCUT_ERROR_INVALID_PARAMETER;
        }
 
        (void)shortcut_icon_request_unref(handle);
-       return SHORTCUT_SUCCESS;
+       return SHORTCUT_ERROR_NONE;
 }
 
 
@@ -682,7 +683,7 @@ EAPI int shortcut_icon_request_send(struct shortcut_icon *handle, int size_type,
 
        if (!handle || handle->state != CREATED) {
                ErrPrint("Handle is not valid\n");
-               return SHORTCUT_ERROR_INVALID;
+               return SHORTCUT_ERROR_INVALID_PARAMETER;
        }
 
        if (!layout) {
@@ -697,7 +698,7 @@ EAPI int shortcut_icon_request_send(struct shortcut_icon *handle, int size_type,
        filename = malloc(len);
        if (!filename) {
                ErrPrint("Heap: %s\n", strerror(errno));
-               return SHORTCUT_ERROR_MEMORY;
+               return SHORTCUT_ERROR_OUT_OF_MEMORY;
        }
 
 #if defined(_USE_ECORE_TIME_GET)
@@ -751,7 +752,7 @@ EAPI int shortcut_icon_request_send(struct shortcut_icon *handle, int size_type,
                if (unlink(filename) < 0) {
                        ErrPrint("Unlink: %s\n", strerror(errno));
                }
-               ret = SHORTCUT_ERROR_MEMORY;
+               ret = SHORTCUT_ERROR_OUT_OF_MEMORY;
                goto out;
        }
 
@@ -795,7 +796,7 @@ EAPI int shortcut_icon_request_send(struct shortcut_icon *handle, int size_type,
                                ErrPrint("Unlink: %s\n", strerror(errno));
                        }
                        (void)shortcut_icon_request_unref(handle);
-                       ret = SHORTCUT_ERROR_MEMORY;
+                       ret = SHORTCUT_ERROR_OUT_OF_MEMORY;
                        goto out;
                }
 
@@ -805,7 +806,7 @@ EAPI int shortcut_icon_request_send(struct shortcut_icon *handle, int size_type,
                s_info.pending_list = dlist_append(s_info.pending_list, pend);
                DbgPrint("Request is pended\n");
 
-               ret = SHORTCUT_SUCCESS;
+               ret = SHORTCUT_ERROR_NONE;
        }
 
 out:
index ff41c28..62376c8 100644 (file)
@@ -24,6 +24,7 @@
 #include <sys/ioctl.h>
 #include <libgen.h>
 
+#include <aul.h>
 #include <dlog.h>
 #include <glib.h>
 #include <db-util.h>
@@ -39,6 +40,9 @@
 
 #include "shortcut.h"
 #include "shortcut_internal.h"
+#include "shortcut_manager.h"
+
+#define SHORTCUT_PKGNAME_LEN 512
 
 int errno;
 
@@ -206,7 +210,7 @@ static void master_started_cb(keynode_t *node, void *user_data)
                ErrPrint("Unable to get \"%s\"\n", VCONFKEY_MASTER_STARTED);
        }
 
-       if (state == 1 && make_connection() == SHORTCUT_SUCCESS) {
+       if (state == 1 && make_connection() == SHORTCUT_ERROR_NONE) {
                int ret;
                ret = vconf_ignore_key_changed(VCONFKEY_MASTER_STARTED, master_started_cb);
                DbgPrint("Ignore VCONF [%d]\n", ret);
@@ -215,6 +219,23 @@ static void master_started_cb(keynode_t *node, void *user_data)
 
 
 
+int shortcut_is_master_ready(void)
+{
+       int ret = -1, is_master_started = 0;
+
+       ret = vconf_get_bool(VCONFKEY_MASTER_STARTED, &is_master_started);
+       if (ret == 0 && is_master_started == 1) {
+               ErrPrint("the master has been started");
+       } else {
+               is_master_started = 0;
+               ErrPrint("the master has been stopped");
+       }
+
+       return is_master_started;
+}
+
+
+
 static gboolean timeout_cb(void *data)
 {
        int ret;
@@ -237,13 +258,13 @@ static gboolean timeout_cb(void *data)
 static int disconnected_cb(int handle, void *data)
 {
        if (s_info.client_fd == handle) {
-               s_info.client_fd = SHORTCUT_ERROR_INVALID;
+               s_info.client_fd = SHORTCUT_ERROR_INVALID_PARAMETER;
                return 0;
        }
 
        if (s_info.server_fd == handle) {
                if (!s_info.timer_id) {
-                       s_info.server_fd = SHORTCUT_ERROR_INVALID;
+                       s_info.server_fd = SHORTCUT_ERROR_INVALID_PARAMETER;
                        s_info.timer_id = g_timeout_add(1000, timeout_cb, NULL);
                        if (!s_info.timer_id) {
                                ErrPrint("Unable to add timer\n");
@@ -309,7 +330,7 @@ static inline int make_connection(void)
                s_info.server_fd = -1;
                ret = SHORTCUT_ERROR_COMM;
        } else {
-               ret = SHORTCUT_SUCCESS;
+               ret = SHORTCUT_ERROR_NONE;
        }
 
        DbgPrint("Server FD: %d\n", s_info.server_fd);
@@ -318,8 +339,60 @@ static inline int make_connection(void)
 
 
 
+static char *_shortcut_get_pkgname_by_pid(void)
+{
+       char pkgname[SHORTCUT_PKGNAME_LEN + 1] = { 0, };
+       int pid = 0, ret = 0;
+       int fd;
+       char  *dup_pkgname;
+
+       pid = getpid();
+
+       ret = aul_app_get_pkgname_bypid(pid, pkgname, sizeof(pkgname));
+       if (ret != 0) {
+               char buf[SHORTCUT_PKGNAME_LEN + 1] = { 0, };
+
+               snprintf(buf, sizeof(buf), "/proc/%d/cmdline", pid);
+
+               fd = open(buf, O_RDONLY);
+               if (fd < 0) {
+                       return NULL;
+               }
+
+               ret = read(fd, pkgname, sizeof(pkgname) - 1);
+               close(fd);
+
+               if (ret <= 0) {
+                       return NULL;
+               }
+
+               pkgname[ret] = '\0';
+               /*!
+                * \NOTE
+                * "ret" is not able to be larger than "sizeof(pkgname) - 1",
+                * if the system is not going wrong.
+                */
+       } else {
+               if (strlen(pkgname) <= 0) {
+                       return NULL;
+               }
+       }
+
+       dup_pkgname = strdup(pkgname);
+       if (!dup_pkgname)
+               ErrPrint("Heap: %s\n", strerror(errno));
+
+       return dup_pkgname;
+}
+
+
+
 EAPI int shortcut_set_request_cb(request_cb_t request_cb, void *data)
 {
+       if (request_cb == NULL) {
+               return SHORTCUT_ERROR_INVALID_PARAMETER;
+       }
+
        s_info.server_cb.request_cb = request_cb;
        s_info.server_cb.data = data;
 
@@ -329,6 +402,7 @@ EAPI int shortcut_set_request_cb(request_cb_t request_cb, void *data)
                ret = vconf_notify_key_changed(VCONFKEY_MASTER_STARTED, master_started_cb, NULL);
                if (ret < 0) {
                        ErrPrint("Failed to add vconf for service state [%d]\n", ret);
+                       return SHORTCUT_ERROR_COMM;
                } else {
                        DbgPrint("vconf is registered\n");
                }
@@ -336,12 +410,13 @@ EAPI int shortcut_set_request_cb(request_cb_t request_cb, void *data)
                master_started_cb(NULL, NULL);
        }
 
-       return SHORTCUT_SUCCESS;
+       return SHORTCUT_ERROR_NONE;
 }
 
 
 
 struct result_cb_item {
+       result_internal_cb_t result_internal_cb;
        result_cb_t result_cb;
        void *data;
 };
@@ -358,13 +433,15 @@ static int shortcut_send_cb(pid_t pid, int handle, const struct packet *packet,
                ret = SHORTCUT_ERROR_FAULT;
        } else if (packet_get(packet, "i", &ret) != 1) {
                ErrPrint("Packet is not valid\n");
-               ret = SHORTCUT_ERROR_INVALID;
+               ret = SHORTCUT_ERROR_INVALID_PARAMETER;
        }
 
-       if (item->result_cb) {
-               ret = item->result_cb(ret, pid, item->data);
+       if (item->result_internal_cb) {
+               ret = item->result_internal_cb(ret, pid, item->data);
+       } else if (item->result_cb) {
+               ret = item->result_cb(ret, item->data);
        } else {
-               ret = SHORTCUT_SUCCESS;
+               ret = SHORTCUT_ERROR_NONE;
        }
        free(item);
        return ret;
@@ -372,7 +449,7 @@ static int shortcut_send_cb(pid_t pid, int handle, const struct packet *packet,
 
 
 
-EAPI int add_to_home_remove_shortcut(const char *appid, const char *name, const char *content_info, result_cb_t result_cb, void *data)
+EAPI int add_to_home_remove_shortcut(const char *appid, const char *name, const char *content_info, result_internal_cb_t result_cb, void *data)
 {
        struct packet *packet;
        struct result_cb_item *item;
@@ -380,7 +457,7 @@ EAPI int add_to_home_remove_shortcut(const char *appid, const char *name, const
 
        if (!appid || !name) {
                ErrPrint("Invalid argument\n");
-               return SHORTCUT_ERROR_INVALID;
+               return SHORTCUT_ERROR_INVALID_PARAMETER;
        }
 
        if (!s_info.initialized) {
@@ -406,10 +483,11 @@ EAPI int add_to_home_remove_shortcut(const char *appid, const char *name, const
        item = malloc(sizeof(*item));
        if (!item) {
                ErrPrint("Heap: %s\n", strerror(errno));
-               return SHORTCUT_ERROR_MEMORY;
+               return SHORTCUT_ERROR_OUT_OF_MEMORY;
        }
 
-       item->result_cb = result_cb;
+       item->result_internal_cb = result_cb;
+       item->result_cb = NULL;
        item->data = data;
 
        packet = packet_create("rm_shortcut", "isss", getpid(), appid, name, content_info);
@@ -424,16 +502,16 @@ EAPI int add_to_home_remove_shortcut(const char *appid, const char *name, const
                packet_destroy(packet);
                free(item);
                com_core_packet_client_fini(s_info.client_fd);
-               s_info.client_fd = SHORTCUT_ERROR_INVALID;
+               s_info.client_fd = SHORTCUT_ERROR_INVALID_PARAMETER;
                return SHORTCUT_ERROR_COMM;
        }
 
-       return SHORTCUT_SUCCESS;
+       return SHORTCUT_ERROR_NONE;
 }
 
 
 
-EAPI int add_to_home_remove_livebox(const char *appid, const char *name, result_cb_t result_cb, void *data)
+EAPI int add_to_home_remove_livebox(const char *appid, const char *name, result_internal_cb_t result_cb, void *data)
 {
        struct packet *packet;
        struct result_cb_item *item;
@@ -441,7 +519,7 @@ EAPI int add_to_home_remove_livebox(const char *appid, const char *name, result_
 
        if (!appid || !name) {
                ErrPrint("Invalid argument\n");
-               return SHORTCUT_ERROR_INVALID;
+               return SHORTCUT_ERROR_INVALID_PARAMETER;
        }
 
        if (!s_info.initialized) {
@@ -468,10 +546,11 @@ EAPI int add_to_home_remove_livebox(const char *appid, const char *name, result_
        item = malloc(sizeof(*item));
        if (!item) {
                ErrPrint("Heap: %s\n", strerror(errno));
-               return SHORTCUT_ERROR_MEMORY;
+               return SHORTCUT_ERROR_OUT_OF_MEMORY;
        }
 
-       item->result_cb = result_cb;
+       item->result_internal_cb = result_cb;
+       item->result_cb = NULL;
        item->data = data;
 
        packet = packet_create("rm_livebox", "iss", getpid(), appid, name);
@@ -486,16 +565,16 @@ EAPI int add_to_home_remove_livebox(const char *appid, const char *name, result_
                packet_destroy(packet);
                free(item);
                com_core_packet_client_fini(s_info.client_fd);
-               s_info.client_fd = SHORTCUT_ERROR_INVALID;
+               s_info.client_fd = SHORTCUT_ERROR_INVALID_PARAMETER;
                return SHORTCUT_ERROR_COMM;
        }
 
-       return SHORTCUT_SUCCESS;
+       return SHORTCUT_ERROR_NONE;
 }
 
 
 
-EAPI int add_to_home_shortcut(const char *appid, const char *name, int type, const char *content, const char *icon, int allow_duplicate, result_cb_t result_cb, void *data)
+EAPI int add_to_home_shortcut(const char *appid, const char *name, int type, const char *content, const char *icon, int allow_duplicate, result_internal_cb_t result_cb, void *data)
 {
        struct packet *packet;
        struct result_cb_item *item;
@@ -503,6 +582,7 @@ EAPI int add_to_home_shortcut(const char *appid, const char *name, int type, con
 
        if (ADD_TO_HOME_IS_LIVEBOX(type)) {
                ErrPrint("Invalid type used for adding a shortcut\n");
+               return SHORTCUT_ERROR_INVALID_PARAMETER;
        }
 
        if (!s_info.initialized) {
@@ -528,10 +608,11 @@ EAPI int add_to_home_shortcut(const char *appid, const char *name, int type, con
        item = malloc(sizeof(*item));
        if (!item) {
                ErrPrint("Heap: %s\n", strerror(errno));
-               return SHORTCUT_ERROR_MEMORY;
+               return SHORTCUT_ERROR_OUT_OF_MEMORY;
        }
 
-       item->result_cb = result_cb;
+       item->result_internal_cb = result_cb;
+       item->result_cb = NULL;
        item->data = data;
 
        if (!appid) {
@@ -562,16 +643,111 @@ EAPI int add_to_home_shortcut(const char *appid, const char *name, int type, con
                packet_destroy(packet);
                free(item);
                com_core_packet_client_fini(s_info.client_fd);
-               s_info.client_fd = SHORTCUT_ERROR_INVALID;
+               s_info.client_fd = SHORTCUT_ERROR_INVALID_PARAMETER;
                return SHORTCUT_ERROR_COMM;
        }
 
-       return SHORTCUT_SUCCESS;
+       return SHORTCUT_ERROR_NONE;
 }
 
+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)
+{
+       struct packet *packet;
+       struct result_cb_item *item;
+       char *appid = NULL;
+       int ret;
+
+       if (ADD_TO_HOME_IS_LIVEBOX(type)) {
+               ErrPrint("Invalid type used for adding a shortcut\n");
+               return SHORTCUT_ERROR_INVALID_PARAMETER;
+       }
+
+       appid = _shortcut_get_pkgname_by_pid();
+
+       if (!s_info.initialized) {
+               s_info.initialized = 1;
+               com_core_add_event_callback(CONNECTOR_DISCONNECTED, disconnected_cb, NULL);
+       }
+
+       if (s_info.client_fd < 0) {
+               static struct method service_table[] = {
+                       {
+                               .cmd = NULL,
+                               .handler = NULL,
+                       },
+               };
+
+               s_info.client_fd = com_core_packet_client_init(s_info.socket_file, 0, service_table);
+               if (s_info.client_fd < 0) {
+                       if (appid) {
+                               free(appid);
+                       }
+                       if (shortcut_is_master_ready() == 1) {
+                               return SHORTCUT_ERROR_PERMISSION_DENIED;
+                       }
+                       else {
+                               return SHORTCUT_ERROR_COMM;
+                       }
+               }
+       }
+
+       item = malloc(sizeof(*item));
+       if (!item) {
+               if (appid) {
+                       free(appid);
+               }
+               ErrPrint("Heap: %s\n", strerror(errno));
+               return SHORTCUT_ERROR_OUT_OF_MEMORY;
+       }
+
+       item->result_cb = result_cb;
+       item->result_internal_cb = NULL;
+       item->data = data;
+
+       if (!name) {
+               name = "";
+       }
+
+       if (!uri) {
+               uri = "";
+       }
+
+       if (!icon) {
+               icon = "";
+       }
+
+       packet = packet_create("add_shortcut", "ississi", getpid(), appid, name, type, uri, icon, allow_duplicate);
+       if (!packet) {
+               ErrPrint("Failed to build a packet\n");
+               if (appid) {
+                       free(appid);
+               }
+               if (item) {
+                       free(item);
+               }
+               return SHORTCUT_ERROR_FAULT;
+       }
+
+       if (appid) {
+               free(appid);
+       }
+
+       ret = com_core_packet_async_send(s_info.client_fd, packet, 0.0f, shortcut_send_cb, item);
+       packet_destroy(packet);
+       if (ret < 0) {
+               if (item) {
+                       free(item);
+               }
+               com_core_packet_client_fini(s_info.client_fd);
+               s_info.client_fd = SHORTCUT_ERROR_INVALID_PARAMETER;
+               return SHORTCUT_ERROR_COMM;
+       }
+
+       return SHORTCUT_ERROR_NONE;
+}
 
 
-EAPI int add_to_home_livebox(const char *appid, const char *name, int type, const char *content, const char *icon, double period, int allow_duplicate, result_cb_t result_cb, void *data)
+EAPI int add_to_home_livebox(const char *appid, const char *name, int type, const char *content, const char *icon, double period, int allow_duplicate, result_internal_cb_t result_cb, void *data)
 {
        struct packet *packet;
        struct result_cb_item *item;
@@ -579,6 +755,7 @@ EAPI int add_to_home_livebox(const char *appid, const char *name, int type, cons
 
        if (!ADD_TO_HOME_IS_LIVEBOX(type)) {
                ErrPrint("Invalid type is used for adding a livebox\n");
+               return SHORTCUT_ERROR_INVALID_PARAMETER;
        }
 
        if (!s_info.initialized) {
@@ -603,10 +780,11 @@ EAPI int add_to_home_livebox(const char *appid, const char *name, int type, cons
        item = malloc(sizeof(*item));
        if (!item) {
                ErrPrint("Heap: %s\n", strerror(errno));
-               return SHORTCUT_ERROR_MEMORY;
+               return SHORTCUT_ERROR_OUT_OF_MEMORY;
        }
 
-       item->result_cb = result_cb;
+       item->result_internal_cb = result_cb;
+       item->result_cb = NULL;
        item->data = data;
 
        packet = packet_create("add_livebox", "ississdi", getpid(), appid, name, type, content, icon, period, allow_duplicate);
@@ -621,11 +799,11 @@ EAPI int add_to_home_livebox(const char *appid, const char *name, int type, cons
                packet_destroy(packet);
                free(item);
                com_core_packet_client_fini(s_info.client_fd);
-               s_info.client_fd = SHORTCUT_ERROR_INVALID;
+               s_info.client_fd = SHORTCUT_ERROR_INVALID_PARAMETER;
                return SHORTCUT_ERROR_COMM;
        }
 
-       return SHORTCUT_SUCCESS;
+       return SHORTCUT_ERROR_NONE;
 }
 
 
@@ -637,10 +815,10 @@ static inline int open_db(void)
        ret = db_util_open(s_info.dbfile, &s_info.handle, DB_UTIL_REGISTER_HOOK_METHOD);
        if (ret != SQLITE_OK) {
                DbgPrint("Failed to open a %s\n", s_info.dbfile);
-               return SHORTCUT_ERROR_IO;
+               return SHORTCUT_ERROR_IO_ERROR;
        }
 
-       return SHORTCUT_SUCCESS;
+       return SHORTCUT_ERROR_NONE;
 }
 
 
@@ -774,13 +952,17 @@ EAPI int shortcut_get_list(const char *appid, int (*cb)(const char *appid, const
        int cnt;
        char *language;
 
+       if (cb == NULL) {
+               return SHORTCUT_ERROR_INVALID_PARAMETER;
+       }
+
        if (!s_info.db_opened) {
                s_info.db_opened = (open_db() == 0);
        }
 
        if (!s_info.db_opened) {
                ErrPrint("Failed to open a DB\n");
-               return SHORTCUT_ERROR_IO;
+               return SHORTCUT_ERROR_IO_ERROR;
        }
 
        language = cur_locale();
@@ -795,7 +977,7 @@ EAPI int shortcut_get_list(const char *appid, int (*cb)(const char *appid, const
                if (ret != SQLITE_OK) {
                        ErrPrint("prepare: %s\n", sqlite3_errmsg(s_info.handle));
                        free(language);
-                       return SHORTCUT_ERROR_IO;
+                       return SHORTCUT_ERROR_IO_ERROR;
                }
 
                ret = sqlite3_bind_text(stmt, 1, appid, -1, SQLITE_TRANSIENT);
@@ -803,7 +985,7 @@ EAPI int shortcut_get_list(const char *appid, int (*cb)(const char *appid, const
                        ErrPrint("bind text: %s\n", sqlite3_errmsg(s_info.handle));
                        sqlite3_finalize(stmt);
                        free(language);
-                       return SHORTCUT_ERROR_IO;
+                       return SHORTCUT_ERROR_IO_ERROR;
                }
        } else {
                query = "SELECT id, appid, name, extra_key, extra_data, icon FROM shortcut_service";
@@ -811,7 +993,7 @@ EAPI int shortcut_get_list(const char *appid, int (*cb)(const char *appid, const
                if (ret != SQLITE_OK) {
                        ErrPrint("prepare: %s\n", sqlite3_errmsg(s_info.handle));
                        free(language);
-                       return SHORTCUT_ERROR_IO;
+                       return SHORTCUT_ERROR_IO_ERROR;
                }
        }
 
@@ -864,7 +1046,10 @@ EAPI int shortcut_get_list(const char *appid, int (*cb)(const char *appid, const
                }
 
                free(i18n_name);
+               i18n_name = NULL;
+
                free(i18n_icon);
+               i18n_icon = NULL;
        }
 
        sqlite3_reset(stmt);
index 50c4ced..8f26aac 100644 (file)
@@ -20,6 +20,8 @@ BuildRequires: pkgconfig(com-core)
 BuildRequires: pkgconfig(libxml-2.0)
 BuildRequires: pkgconfig(vconf)
 BuildRequires: pkgconfig(libtzplatform-config)
+BuildRequires: pkgconfig(capi-base-common)
+BuildRequires: pkgconfig(aul)
 
 %description
 [Shortcut] AddToHome feature supporting library for menu/home screen developers.
@@ -77,6 +79,7 @@ touch %{buildroot}%{TZ_SYS_DB}/.shortcut_service.db-journal
 %defattr(-,root,root,-)
 %{_includedir}/shortcut/shortcut_PG.h
 %{_includedir}/shortcut/shortcut.h
+%{_includedir}/shortcut/shortcut_manager.h
 %{_libdir}/pkgconfig/shortcut.pc
 
 # End of a file