2 * Copyright 2012 Samsung Electronics Co., Ltd
4 * Licensed under the Flora License, Version 1.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.tizenopensource.org/license
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 #ifndef __SHORTCUT_H__
18 #define __SHORTCUT_H__
25 * @addtogroup APPLICATION_FRAMEWORK
30 * @defgroup SHORTCUT Add to home (shortcut)
31 * @author Sung-jae Park <nicesj.park@samsung.com>
33 * @brief To enhance the Add to home feature. Two types of API set are supported.
34 * One for the homescreen developers.
35 * The others for the application developers who should implement the Add to home feature.
39 * @brief This function prototype is used to define a callback function for the add_to_home reqeust.
40 * The homescreen should define a callback as this type and implementing the service code
41 * for adding a new application shortcut.
42 * @param[in] pkgname Shortcut is added for this package.
43 * @param[in] name Name for created shortcut icon.
44 * @param[in] type 3 kinds of types are defined.
45 * @param[in] content_info Specific information for creating a new shortcut.
46 * @param[in] icon Absolute path of an icon file for this shortcut.
47 * @param[in] pid Process ID of who request add_to_home.
48 * @param[in] data Callback data.
49 * @return int Developer should returns the result of handling shortcut creation request.
50 * Returns 0, if succeed to handles the add_to_home request, or returns proper errno.
51 * @see shortcut_set_request_cb
56 typedef int (*request_cb_t)(const char *pkgname, const char *name, int type, const char *content_info, const char *icon, int pid, void *data);
59 * @brief This function prototype is used to define for receiving the result of add_to_home.
60 * @param[in] ret Result value, it could be 0 if succeed to add a shortcut, or errno.
61 * @param[in] pid Process ID of who handles this add_to_home request.
62 * @param[in] data Callback data.
63 * @return int Returns 0, if there is no error or returns errno.
64 * @see shortcut_add_to_home()
69 typedef int (*result_cb_t)(int ret, int pid, void *data);
72 * @brief Basically, three types of shortcut is defined.
73 * Every homescreen developer should support these types of shortcut.
74 * Or returns proper errno to figure out why the application failed to add a shortcut.
75 * SHORTCUT_PACKAGE is used for adding a package itself as a shortcut
76 * SHORTCUT_DATA is used for adding a shortcut for "content" data.
77 * SHORTCUT_FILE is used for adding a shortcut for "file".
80 SHORTCUT_PACKAGE = 0x0, /**< Launch the package using given pakcage name. */
81 SHORTCUT_DATA = 0x01, /**< Launch the related package with given data(content_info). */
82 SHORTCUT_FILE = 0x02, /** < Launch the related package with given filename(content_info). */
86 * @fn int shortcut_set_request_cb(request_cb_t request_cb, void *data)
88 * @brief Homescreen should use this function to service the shortcut creating request.
90 * @par Sync (or) Async:
91 * This is an asynchronous API.
93 * @par Important Notes:
94 * - Should be used from the homescreen.
95 * - Should check the return value of this function
97 * @param[in] request_cb Callback function pointer which will be invoked when add_to_home is requested.
98 * @param[in] data Callback data to deliver to the callback function.
100 * @return Return Type (int)
101 * - 0 - callback function is successfully registered
102 * - < 0 - Failed to register the callback function for request.
106 * @pre - You have to prepare a callback function
108 * @post - If a request is sent from the application, the registered callback will be invoked.
112 * @par Prospective Clients:
117 * #include <shortcut.h>
119 * static int request_cb(const char *pkgname, const char *name, int type, const char *content_info, const char *icon, int pid, void *data)
121 * printf("Package name: %s\n", pkgname);
122 * printf("Name: %s\n", name);
123 * printf("Type: %d\n", type);
124 * printf("Content: %s\n", content_info);
125 * printf("Icon: %s\n", icon);
126 * printf("Requested from: %d\n", pid);
127 * printf("CBDATA: %p\n", data);
128 * return 0; // returns success.
131 * static int app_create(void *data)
133 * shortcut_set_request_cb(request_cb, NULL);
137 * int main(int argc, char *argv[])
144 extern int shortcut_set_request_cb(request_cb_t request_cb, void *data);
147 * @fn int shortcut_add_to_home(const char *pkgname, const char *name, int type, const char *content_info, const char *icon, result_cb_t result_cb, void *data)
149 * @brief The application, which supporting the add_to_home feature, should invoke this.
151 * @par Sync (or) Async:
152 * This is an asynchronous API.
154 * @par Important Notes:
155 * - Application should check the return value of this function.
156 * - Application should check the return status from the callback function
157 * - Application should set the callback function to get the result of this request.
159 * @param[in] pkgname Package name of owner of this shortcut.
160 * @param[in] name Name for created shortcut icon.
161 * @param[in] type 3 kinds of types are defined.
162 * @param[in] content_info Specific information for delivering to the creating shortcut.
163 * @param[in] icon Absolute path of an icon file
164 * @param[in] result_cb Callback function pointer which will be invoked after add_to_home request.
165 * @param[in] data Callback data to deliver to the callback function.
167 * @return Return Type (int)
168 * - 0 - Succeed to send the request
169 * - <0 - Failed to send the request
173 * @pre - You have to prepare the callback function
175 * @post - You have to check the return status from callback function which is passed by argument.
177 * @remarks - If a homescreen does not support this feature, you will get proper error code.
179 * @par Prospective Clients:
186 * #include <shortcut.h>
188 * static int result_cb(int ret, int pid, void *data)
191 * printf("Failed to add a shortcut: %s\n", perror(ret));
193 * printf("Processed by the %d\n", pid);
197 * static int app_create(void *data)
199 * shortcut_add_to_home("com.samsung.gallery", "With friends",
200 * SHORTCUT_DATA, "gallery:0000-0000",
201 * "/opt/media/Pictures/Friends.jpg", result_cb, NULL);
205 * int main(int argc, char *argv[])
212 extern int shortcut_add_to_home(const char *pkgname, const char *name, int type, const char *content_info, const char *icon, result_cb_t result_cb, void *data);
214 extern int add_to_home_shortcut(const char *pkgname, const char *name, int type, const char *content_info, const char *icon, result_cb_t result_cb, void *data);