4 * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
6 * Contact: Jayoun Lee <airjany@samsung.com>, Sewook Park <sewook7.park@samsung.com>, Jaeho Lee <jaeho81.lee@samsung.com>
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
30 * @brief This file contains APIs of the appsvc library
34 * @addtogroup APPLICATION_FRAMEWORK
37 * @defgroup appsvc Application Service
39 * @brief Application Service library
56 /** APP_SVC OPERATION TYPE*/
57 #define APPSVC_OPERATION_DEFAULT "http://tizen.org/appcontrol/operation/default"
58 /** APP_SVC OPERATION TYPE*/
59 #define APPSVC_OPERATION_EDIT "http://tizen.org/appcontrol/operation/edit"
60 /** APP_SVC OPERATION TYPE*/
61 #define APPSVC_OPERATION_VIEW "http://tizen.org/appcontrol/operation/view"
62 /** APP_SVC OPERATION TYPE*/
63 #define APPSVC_OPERATION_PICK "http://tizen.org/appcontrol/operation/pick"
64 /** APP_SVC OPERATION TYPE*/
65 #define APPSVC_OPERATION_CREATE_CONTENT "http://tizen.org/appcontrol/operation/create_content"
66 /** APP_SVC OPERATION TYPE*/
67 #define APPSVC_OPERATION_CALL "http://tizen.org/appcontrol/operation/call"
68 /** APP_SVC OPERATION TYPE*/
69 #define APPSVC_OPERATION_SEND "http://tizen.org/appcontrol/operation/send"
70 /** APP_SVC OPERATION TYPE*/
71 #define APPSVC_OPERATION_SEND_TEXT "http://tizen.org/appcontrol/operation/send_text"
72 /** APP_SVC OPERATION TYPE*/
73 #define APPSVC_OPERATION_DIAL "http://tizen.org/appcontrol/operation/dial"
74 /** APP_SVC OPERATION TYPE*/
75 #define APPSVC_OPERATION_SEARCH "http://tizen.org/appcontrol/operation/search"
76 /** APP_SVC OPERATION TYPE*/
77 #define APPSVC_OPERATION_DOWNLOAD "http://tizen.org/appcontrol/operation/download"
80 /** APP_SVC DATA SUBJECT*/
81 #define APPSVC_DATA_SUBJECT "http://tizen.org/appcontrol/data/subject"
82 /** APP_SVC DATA TYPE*/
83 #define APPSVC_DATA_TO "http://tizen.org/appcontrol/data/to"
84 /** APP_SVC DATA TYPE*/
85 #define APPSVC_DATA_CC "http://tizen.org/appcontrol/data/cc"
86 /** APP_SVC DATA TYPE*/
87 #define APPSVC_DATA_BCC "http://tizen.org/appcontrol/data/bcc"
88 /** APP_SVC DATA TYPE*/
89 #define APPSVC_DATA_TEXT "http://tizen.org/appcontrol/data/text"
90 /** APP_SVC DATA TYPE*/
91 #define APPSVC_DATA_TITLE "http://tizen.org/appcontrol/data/title"
92 /** APP_SVC DATA TYPE*/
93 #define APPSVC_DATA_SELECTED "http://tizen.org/appcontrol/data/selected"
94 /** APP_SVC DATA TYPE*/
95 #define APPSVC_DATA_KEYWORD "http://tizen.org/appcontrol/data/keyword"
97 /** APP SVC internal private key */
98 #define APP_SVC_K_URI_R_INFO "__APP_SVC_URI_R_INFO__"
100 /** APP SVC internal private value */
101 #define APP_SVC_V_SCHEME_AND_HOST "__SCHEME_AND_HOST__"
102 /** APP SVC internal private value */
103 #define APP_SVC_V_SCHEME "__SCHEME__"
107 * @brief Return values in appsvc.
109 typedef enum _appsvc_return_val {
110 APPSVC_RET_ELAUNCH = -4, /**< Failure on launching the app */
111 APPSVC_RET_ENOMATCH = -3, /**< No matching result Error */
112 APPSVC_RET_EINVAL = -2, /**< Invalid argument */
113 APPSVC_RET_ERROR = -1, /**< General error */
114 APPSVC_RET_OK = 0 /**< General success */
119 * @brief result values in appsvc.
121 typedef enum _appsvc_result_val {
122 APPSVC_RES_CANCEL = -2, /**< Cancel by system */
123 APPSVC_RES_NOT_OK = -1, /**< Fail by user */
124 APPSVC_RES_OK = 0 /**< Success by user */
129 * @brief appsvc_res_fn is appsvc result function
130 * @param[out] b result bundle
131 * @param[out] request_code request code
132 * @param[out] result result value
133 * @param[out] data user-supplied data
135 typedef void (*appsvc_res_fn)(bundle *b, int request_code, appsvc_result_val result, void *data);
139 * @brief iterator function running with appsvc_get_list
140 * @param[out] pkg_name package name retreived by appsvc_get_list
141 * @param[out] data user-supplied data
143 typedef int (*appsvc_info_iter_fn)(const char *appid, void *data);
145 typedef int (*appsvc_host_res_fn)(void *data);
149 * This function sets an operation to launch application based on appsvc.
151 * @param[in] b bundle object
152 * @param[in] operation operation
154 * @return 0 if success, negative value(<0) if fail
155 * @retval APPSVC_RET_OK - success
156 * @retval APPSVC_RET_ERROR - general error
157 * @retval APPSVC_RET_EINVAL - invalid argument(content)
162 * @remarks An application must call this function before using appsvc_run_service API.
174 appsvc_set_operation(b, APPSVC_OPERATION_VIEW);
179 int appsvc_set_operation(bundle *b, const char *operation);
183 * This function sets an uri to launch application based on appsvc.
185 * @param[in] b bundle object
188 * @return 0 if success, negative value(<0) if fail
189 * @retval APPSVC_RET_OK - success
190 * @retval APPSVC_RET_ERROR - general error
191 * @retval APPSVC_RET_EINVAL - invalid argument(content)
208 appsvc_set_operation(b, APPSVC_OPERATION_VIEW);
209 appsvc_set_uri(b,"http://www.samsung.com");
214 int appsvc_set_uri(bundle *b, const char *uri);
218 * This function sets a mime-type to launch application based on appsvc.
220 * @param[in] b bundle object
221 * @param[in] mime mime-type
223 * @return 0 if success, negative value(<0) if fail
224 * @retval APPSVC_RET_OK - success
225 * @retval APPSVC_RET_ERROR - general error
226 * @retval APPSVC_RET_EINVAL - invalid argument(content)
243 appsvc_set_operation(b, APPSVC_OPERATION_PICK);
244 appsvc_set_mime(b,"image/jpg");
249 int appsvc_set_mime(bundle *b, const char *mime);
253 * This function sets an extra data to launch application based on appsvc.
255 * @param[in] b bundle object
256 * @param[in] key key of extra data
257 * @param[in] val data
259 * @return 0 if success, negative value(<0) if fail
276 appsvc_set_operation(b, APPSVC_OPERATION_SEND);
277 appsvc_set_uri(b,"mailto:xxx1@xxx");
278 appsvc_add_data(b,APPSVC_DATA_CC,"xxx2@xxx");
283 int appsvc_add_data(bundle *b, const char *key, const char *val);
287 * This function sets an extra array data to launch application based on appsvc.
289 * @param[in] b bundle object
290 * @param[in] key key of extra data
291 * @param[in] val_array data
292 * @param[in] len Length of array
294 * @return 0 if success, negative value(<0) if fail
308 char *images[] = {"/opt/media/a.jpg", "/opt/media/b.jpg", "/opt/media/c.jpg"};
312 appsvc_add_data_array(b, APPSVC_DATA_SELECTED, images, 3);
317 int appsvc_add_data_array(bundle *b, const char *key, const char **val_array, int len);
322 * This function sets a package name to launch application based on appsvc.
324 * @param[in] b bundle object
325 * @param[in] pkg_name package name for explict launch
327 * @return 0 if success, negative value(<0) if fail
328 * @retval APPSVC_RET_OK - success
329 * @retval APPSVC_RET_ERROR - general error
330 * @retval APPSVC_RET_EINVAL - invalid argument(content)
347 appsvc_set_operation(b, APPSVC_OPERATION_PICK);
348 appsvc_set_mime(b,"image/jpg");
349 appsvc_set_pkgname(b, "org.tizen.mygallery");
355 int appsvc_set_pkgname(bundle *b, const char *pkg_name); // __attribute__((deprecated));
360 * This function sets a appid to launch application based on appsvc.
362 * @param[in] b bundle object
363 * @param[in] appid application id for explict launch
365 * @return 0 if success, negative value(<0) if fail
366 * @retval APPSVC_RET_OK - success
367 * @retval APPSVC_RET_ERROR - general error
368 * @retval APPSVC_RET_EINVAL - invalid argument(content)
385 appsvc_set_operation(b, APPSVC_OPERATION_PICK);
386 appsvc_set_mime(b,"image/jpg");
387 appsvc_set_appid(b, "org.tizen.mygallery");
392 int appsvc_set_appid(bundle *b, const char *appid);
397 * This function sets a appid to launch application based on appsvc.
399 * @param[in] b bundle object
400 * @param[in] application category
402 * @return 0 if success, negative value(<0) if fail
403 * @retval APPSVC_RET_OK - success
404 * @retval APPSVC_RET_ERROR - general error
405 * @retval APPSVC_RET_EINVAL - invalid argument(content)
422 appsvc_set_operation(b, APPSVC_OPERATION_VIEW);
423 appsvc_set_category(b, "http://tizen.org/category/app/browser");
428 int appsvc_set_category(bundle *b, const char *category);
432 * This API launch application based on appsvc.
434 * @param[in] b bundle to be passed to callee
435 * @param[in] request_code request code
436 * @param[in] cbfunc result callback function
437 * @param[in] data user-supplied data passed to callback function
439 * @return callee's pid if success, negative value(<0) if fail
440 * @retval callee's pid - success
441 * @retval APPSVC_RET_ERROR - general error
442 * @retval APPSVC_RET_EINVAL - invalid argument(content)
443 * @retval APPSVC_RET_ENOMATCH - no matching result Error
444 * @retval APPSVC_RET_ELAUNCH - failure on launching the app
462 appsvc_set_operation(b, APPSVC_OPERATION_PICK);
463 appsvc_set_mime(b,"image/jpg");
465 return appsvc_run_service(b, 0, cb_func, (void*)NULL);
470 int appsvc_run_service(bundle *b, int request_code, appsvc_res_fn cbfunc, void *data);
474 * This API use to get application list that is matched with given bundle.
476 * @param[in] b bundle to resolve application
477 * @param[in] iter_fn iterator function
478 * @param[in] data user-supplied data for iter_fn
480 * @return 0 if success, negative value(<0) if fail
481 * @retval APPSVC_RET_OK - success
482 * @retval APPSVC_RET_EINVAL - invalid argument(content)
483 * @retval APPSVC_RET_ENOMATCH - no matching result Error
494 static int iter_fn(const char* pkg_name, void *data)
496 printf("\t==========================\n");
497 printf("\t pkg_name: %s\n", pkg_name);
498 printf("\t==========================\n");
509 appsvc_set_operation(b, APPSVC_OPERATION_PICK);
510 appsvc_set_mime(b,"image/jpg");
512 return appsvc_get_list(b, iter_fn, (void*)NULL);
517 int appsvc_get_list(bundle *b, appsvc_info_iter_fn iter_fn, void *data);
521 * This function gets a operation from bundle.
523 * @param[in] b bundle object
525 * @return Pointer for operation string if success, NULL if fail
539 val = appsvc_get_operation(b);
544 const char *appsvc_get_operation(bundle *b);
548 * This function gets a uri from bundle.
550 * @param[in] b bundle object
552 * @return Pointer for uri string if success, NULL if fail
566 val = appsvc_get_uri(b);
571 const char *appsvc_get_uri(bundle *b);
575 * This function gets a mime-type from bundle.
577 * @param[in] b bundle object
579 * @return Pointer for mime-type string if success, NULL if fail
593 val = appsvc_get_mime(b);
598 const char *appsvc_get_mime(bundle *b);
602 * This function gets a package name from bundle.
604 * @param[in] b bundle object
606 * @return Pointer for package name string if success, NULL if fail
620 val = appsvc_get_pkgname(b);
626 const char *appsvc_get_pkgname(bundle *b); // __attribute__((deprecated));
630 * This function gets a application id from bundle.
632 * @param[in] b bundle object
634 * @return Pointer for application id string if success, NULL if fail
648 val = appsvc_get_appid(b);
653 const char *appsvc_get_appid(bundle *b);
657 * This function gets a application category from bundle.
659 * @param[in] b bundle object
661 * @return Pointer for application category string if success, NULL if fail
675 val = appsvc_get_category(b);
680 const char *appsvc_get_category(bundle *b);
684 * This function gets value from key.
686 * @param[in] b bundle object
689 * @return Pointer for value string if success, NULL if fail
703 val = appsvc_get_data(b, APPSVC_DATA_CC);
708 const char *appsvc_get_data(bundle *b, const char *key);
712 * This function gets value from key.
714 * @param[in] b bundle object
716 * @param[out] len length of array
718 * @return Pointer for value string array if success, NULL if fail
735 if(appsvc_data_is_array(b, APPSVC_DATA_SELECTED))
736 val_array = appsvc_get_data_array(b, APPSVC_DATA_SELECTED, &len);
738 val = appsvc_get_data(b, APPSVC_DATA_SELECTED);
743 const char **appsvc_get_data_array(bundle *b, const char *key, int *len);
747 * This API create appsvc result bundle based on bundle received in reset event.
749 * @param[in] inb bundle received in reset event
750 * @param[in] outb bundle to use for returning result
752 * @retval APPSVC_RET_OK - success
753 * @retval APPSVC_RET_ERROR - general error
754 * @retval APPSVC_RET_EINVAL - invalid argument(content)
758 * @see appsvc_send_result.
767 struct appdata *ad = data;
770 appsvc_create_result_bundle(ad->b,&res_bundle);
771 bundle_add(res_bundle, "result", "1");
772 appsvc_send_result(res_bundle, 0);
777 int appsvc_create_result_bundle(bundle *inb, bundle **outb);
781 * This API send appsvc result to caller with bundle.
783 * @param[in] b Result data in bundle format
784 * @param[in] result result value
786 * @retval APPSVC_RET_OK - success
787 * @retval APPSVC_RET_ERROR - general error
788 * @retval APPSVC_RET_EINVAL - invalid argument(content)
790 * @pre appsvc_create_result_bundle.
792 * @see appsvc_send_result.
801 struct appdata *ad = data;
804 appsvc_create_result_bundle(ad->b,&res_bundle);
805 bundle_add(res_bundle, "result", "1");
806 appsvc_send_result(res_bundle, 0);
811 int appsvc_send_result(bundle *b, appsvc_result_val result);
815 * This API set the default application(package name) associated with op, uri and mime-type.
817 * @param[in] op operation
818 * @param[in] mime_type mime-type
819 * @param[in] scheme scheme of uri
820 * @param[in] defapp default application
822 * @retval APPSVC_RET_OK - success
823 * @retval APPSVC_RET_ERROR - general error
824 * @retval APPSVC_RET_EINVAL - invalid argument(content)
837 appsvc_set_defapp(APPSVC_OPERATION_VIEW, NULL,"http", "org.tizen.mybrowser");
842 int appsvc_set_defapp(const char *op, const char *mime_type, const char *uri,
847 * This API unset the default application(package name) associated with op, uri and mime-type.
849 * @param[in] defapp default application
851 * @retval APPSVC_RET_OK - success
852 * @retval APPSVC_RET_ERROR - general error
865 appsvc_unset_defapp("org.tizen.test");
870 int appsvc_unset_defapp(const char *defapp);
874 * This API ask a application is default application or not.
876 * @param[in] pkg_name application package name
877 * @return true / false
878 * @retval 1 app_name is default application in appsvc.
879 * @retval 0 app_name is NOT default application in appsvc.
892 * int is_defapp_browser_app()
894 * return appsvc_is_defapp("org.tizen.browser");
902 int appsvc_is_defapp(const char *appid);
907 * This API ask a extra data is array or not.
909 * @param[in] b bundle object
910 * @param[in] key key of extra data
911 * @return true / false
912 * @retval 1 a extra data is array.
913 * @retval 0 a extra data is not array.
926 * int is_defapp_browser_app(bundle *b, char *key)
928 * return appsvc_data_is_array(b, key);
936 int appsvc_data_is_array(bundle *b, const char *key);
951 #endif /* __APP_SVC_H__ */
953 /* vi: set ts=8 sts=8 sw=8: */