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
50 #include <sys/types.h>
57 /** APP_SVC OPERATION TYPE*/
58 #define APPSVC_OPERATION_DEFAULT "http://tizen.org/appcontrol/operation/default"
59 /** APP_SVC OPERATION TYPE*/
60 #define APPSVC_OPERATION_EDIT "http://tizen.org/appcontrol/operation/edit"
61 /** APP_SVC OPERATION TYPE*/
62 #define APPSVC_OPERATION_VIEW "http://tizen.org/appcontrol/operation/view"
63 /** APP_SVC OPERATION TYPE*/
64 #define APPSVC_OPERATION_PICK "http://tizen.org/appcontrol/operation/pick"
65 /** APP_SVC OPERATION TYPE*/
66 #define APPSVC_OPERATION_CREATE_CONTENT "http://tizen.org/appcontrol/operation/create_content"
67 /** APP_SVC OPERATION TYPE*/
68 #define APPSVC_OPERATION_CALL "http://tizen.org/appcontrol/operation/call"
69 /** APP_SVC OPERATION TYPE*/
70 #define APPSVC_OPERATION_SEND "http://tizen.org/appcontrol/operation/send"
71 /** APP_SVC OPERATION TYPE*/
72 #define APPSVC_OPERATION_SEND_TEXT "http://tizen.org/appcontrol/operation/send_text"
73 /** APP_SVC OPERATION TYPE*/
74 #define APPSVC_OPERATION_DIAL "http://tizen.org/appcontrol/operation/dial"
75 /** APP_SVC OPERATION TYPE*/
76 #define APPSVC_OPERATION_SEARCH "http://tizen.org/appcontrol/operation/search"
77 /** APP_SVC OPERATION TYPE*/
78 #define APPSVC_OPERATION_DOWNLOAD "http://tizen.org/appcontrol/operation/download"
79 /** APP_SVC OPERATION TYPE*/
80 #define APPSVC_OPERATION_SHARE "http://tizen.org/appcontrol/operation/share"
81 /** APP_SVC OPERATION TYPE*/
82 #define APPSVC_OPERATION_MULTI_SHARE "http://tizen.org/appcontrol/operation/multi_share"
83 /** APP_SVC OPERATION TYPE*/
84 #define APPSVC_OPERATION_COMPOSE "http://tizen.org/appcontrol/opeation/compose"
85 /** APP_SVC OPERATION TYPE*/
86 #define APPSVC_OPERATION_LOCATION "http://tizen.org/appcontrol/operation/configure/location"
87 /** APP_SVC OPERATION TYPE*/
88 #define APPSVC_OPERATION_FONT_TYPE "http://tizen.org/appcontrol/operation/configure/font/type"
89 /** APP_SVC OPERATION TYPE*/
90 #define APPSVC_OPERATION_FONT_SIZE "http://tizen.org/appcontrol/operation/configure/font/size"
95 /** APP_SVC DATA SUBJECT*/
96 #define APPSVC_DATA_SUBJECT "http://tizen.org/appcontrol/data/subject"
97 /** APP_SVC DATA TYPE*/
98 #define APPSVC_DATA_TO "http://tizen.org/appcontrol/data/to"
99 /** APP_SVC DATA TYPE*/
100 #define APPSVC_DATA_CC "http://tizen.org/appcontrol/data/cc"
101 /** APP_SVC DATA TYPE*/
102 #define APPSVC_DATA_BCC "http://tizen.org/appcontrol/data/bcc"
103 /** APP_SVC DATA TYPE*/
104 #define APPSVC_DATA_TEXT "http://tizen.org/appcontrol/data/text"
105 /** APP_SVC DATA TYPE*/
106 #define APPSVC_DATA_TITLE "http://tizen.org/appcontrol/data/title"
107 /** APP_SVC DATA TYPE*/
108 #define APPSVC_DATA_SELECTED "http://tizen.org/appcontrol/data/selected"
109 /** APP_SVC DATA TYPE*/
110 #define APPSVC_DATA_KEYWORD "http://tizen.org/appcontrol/data/keyword"
111 /** APP_SVC DATA TYPE*/
112 #define APPSVC_DATA_PATH "http://tizen.org/appcontrol/data/path"
113 /** APP_SVC DATA TYPE*/
114 #define APPSVC_DATA_SELECTION_MODE "http://tizen.org/appcontrol/data/selection_mode"
115 /** APP_SVC DATA TYPE*/
116 #define APPSVC_DATA_RETURN_RESULT "http://tizen.org/appcontrol/data/return_result"
119 /** APP SVC internal private key */
120 #define APP_SVC_K_URI_R_INFO "__APP_SVC_URI_R_INFO__"
122 #define APP_SELECTOR "org.tizen.app-selector"
125 * @brief Return values in appsvc.
127 typedef enum _appsvc_return_val {
128 APPSVC_RET_EILLACC = -5, /**< Illegal Access */
129 APPSVC_RET_ELAUNCH = -4, /**< Failure on launching the app */
130 APPSVC_RET_ENOMATCH = -3, /**< No matching result Error */
131 APPSVC_RET_EINVAL = -2, /**< Invalid argument */
132 APPSVC_RET_ERROR = -1, /**< General error */
133 APPSVC_RET_OK = 0 /**< General success */
138 * @brief result values in appsvc.
140 typedef enum _appsvc_result_val {
141 APPSVC_RES_CANCEL = -2, /**< Cancel by system */
142 APPSVC_RES_NOT_OK = -1, /**< Fail by user */
143 APPSVC_RES_OK = 0 /**< Success by user */
148 * @brief appsvc_res_fn is appsvc result function
149 * @param[out] b result bundle
150 * @param[out] request_code request code
151 * @param[out] result result value
152 * @param[out] data user-supplied data
154 typedef void (*appsvc_res_fn)(bundle *b, int request_code, appsvc_result_val result, void *data);
158 * @brief iterator function running with appsvc_get_list
159 * @param[out] pkg_name package name retreived by appsvc_get_list
160 * @param[out] data user-supplied data
162 typedef int (*appsvc_info_iter_fn)(const char *appid, void *data);
164 typedef int (*appsvc_host_res_fn)(void *data);
168 * This function sets an operation to launch application based on appsvc.
170 * @param[in] b bundle object
171 * @param[in] operation operation
173 * @return 0 if success, negative value(<0) if fail
174 * @retval APPSVC_RET_OK - success
175 * @retval APPSVC_RET_ERROR - general error
176 * @retval APPSVC_RET_EINVAL - invalid argument(content)
181 * @remarks An application must call this function before using appsvc_run_service API.
193 appsvc_set_operation(b, APPSVC_OPERATION_VIEW);
198 int appsvc_set_operation(bundle *b, const char *operation);
202 * This function sets an uri to launch application based on appsvc.
204 * @param[in] b bundle object
207 * @return 0 if success, negative value(<0) if fail
208 * @retval APPSVC_RET_OK - success
209 * @retval APPSVC_RET_ERROR - general error
210 * @retval APPSVC_RET_EINVAL - invalid argument(content)
227 appsvc_set_operation(b, APPSVC_OPERATION_VIEW);
228 appsvc_set_uri(b,"http://www.samsung.com");
233 int appsvc_set_uri(bundle *b, const char *uri);
237 * This function sets a mime-type to launch application based on appsvc.
239 * @param[in] b bundle object
240 * @param[in] mime mime-type
242 * @return 0 if success, negative value(<0) if fail
243 * @retval APPSVC_RET_OK - success
244 * @retval APPSVC_RET_ERROR - general error
245 * @retval APPSVC_RET_EINVAL - invalid argument(content)
262 appsvc_set_operation(b, APPSVC_OPERATION_PICK);
263 appsvc_set_mime(b,"image/jpg");
268 int appsvc_set_mime(bundle *b, const char *mime);
272 * This function sets an extra data to launch application based on appsvc.
274 * @param[in] b bundle object
275 * @param[in] key key of extra data
276 * @param[in] val data
278 * @return 0 if success, negative value(<0) if fail
295 appsvc_set_operation(b, APPSVC_OPERATION_SEND);
296 appsvc_set_uri(b,"mailto:xxx1@xxx");
297 appsvc_add_data(b,APPSVC_DATA_CC,"xxx2@xxx");
302 int appsvc_add_data(bundle *b, const char *key, const char *val);
306 * This function sets an extra array data to launch application based on appsvc.
308 * @param[in] b bundle object
309 * @param[in] key key of extra data
310 * @param[in] val_array data
311 * @param[in] len Length of array
313 * @return 0 if success, negative value(<0) if fail
327 char *images[] = {"/opt/media/a.jpg", "/opt/media/b.jpg", "/opt/media/c.jpg"};
331 appsvc_add_data_array(b, APPSVC_DATA_SELECTED, images, 3);
336 int appsvc_add_data_array(bundle *b, const char *key, const char **val_array, int len);
341 * This function sets a package name to launch application based on appsvc.
343 * @param[in] b bundle object
344 * @param[in] pkg_name package name for explict launch
346 * @return 0 if success, negative value(<0) if fail
347 * @retval APPSVC_RET_OK - success
348 * @retval APPSVC_RET_ERROR - general error
349 * @retval APPSVC_RET_EINVAL - invalid argument(content)
366 appsvc_set_operation(b, APPSVC_OPERATION_PICK);
367 appsvc_set_mime(b,"image/jpg");
368 appsvc_set_pkgname(b, "org.tizen.mygallery");
374 int appsvc_set_pkgname(bundle *b, const char *pkg_name); // __attribute__((deprecated));
379 * This function sets a appid to launch application based on appsvc.
381 * @param[in] b bundle object
382 * @param[in] appid application id for explict launch
384 * @return 0 if success, negative value(<0) if fail
385 * @retval APPSVC_RET_OK - success
386 * @retval APPSVC_RET_ERROR - general error
387 * @retval APPSVC_RET_EINVAL - invalid argument(content)
404 appsvc_set_operation(b, APPSVC_OPERATION_PICK);
405 appsvc_set_mime(b,"image/jpg");
406 appsvc_set_appid(b, "org.tizen.mygallery");
411 int appsvc_set_appid(bundle *b, const char *appid);
416 * This function sets a appid to launch application based on appsvc.
418 * @param[in] b bundle object
419 * @param[in] application category
421 * @return 0 if success, negative value(<0) if fail
422 * @retval APPSVC_RET_OK - success
423 * @retval APPSVC_RET_ERROR - general error
424 * @retval APPSVC_RET_EINVAL - invalid argument(content)
441 appsvc_set_operation(b, APPSVC_OPERATION_VIEW);
442 appsvc_set_category(b, "http://tizen.org/category/app/browser");
447 int appsvc_set_category(bundle *b, const char *category);
451 * This API launch application based on appsvc.
453 * @param[in] b bundle to be passed to callee
454 * @param[in] request_code request code
455 * @param[in] cbfunc result callback function
456 * @param[in] data user-supplied data passed to callback function
458 * @return callee's pid if success, negative value(<0) if fail
459 * @retval callee's pid - success
460 * @retval APPSVC_RET_ERROR - general error
461 * @retval APPSVC_RET_EINVAL - invalid argument(content)
462 * @retval APPSVC_RET_ENOMATCH - no matching result Error
463 * @retval APPSVC_RET_ELAUNCH - failure on launching the app
481 appsvc_set_operation(b, APPSVC_OPERATION_PICK);
482 appsvc_set_mime(b,"image/jpg");
484 return appsvc_run_service(b, 0, cb_func, (void*)NULL);
489 int appsvc_run_service(bundle *b, int request_code, appsvc_res_fn cbfunc, void *data);
490 int appsvc_usr_run_service(bundle *b, int request_code, appsvc_res_fn cbfunc, void *data, uid_t uid);
494 * This API use to get application list that is matched with given bundle.
496 * @param[in] b bundle to resolve application
497 * @param[in] iter_fn iterator function
498 * @param[in] data user-supplied data for iter_fn
500 * @return 0 if success, negative value(<0) if fail
501 * @retval APPSVC_RET_OK - success
502 * @retval APPSVC_RET_EINVAL - invalid argument(content)
503 * @retval APPSVC_RET_ENOMATCH - no matching result Error
514 static int iter_fn(const char* pkg_name, void *data)
516 printf("\t==========================\n");
517 printf("\t pkg_name: %s\n", pkg_name);
518 printf("\t==========================\n");
529 appsvc_set_operation(b, APPSVC_OPERATION_PICK);
530 appsvc_set_mime(b,"image/jpg");
532 return appsvc_get_list(b, iter_fn, (void*)NULL);
537 int appsvc_get_list(bundle *b, appsvc_info_iter_fn iter_fn, void *data);
538 int appsvc_usr_get_list(bundle *b, appsvc_info_iter_fn iter_fn, void *data, uid_t uid);
542 * This function gets a operation from bundle.
544 * @param[in] b bundle object
546 * @return Pointer for operation string if success, NULL if fail
560 val = appsvc_get_operation(b);
565 const char *appsvc_get_operation(bundle *b);
569 * This function gets a uri from bundle.
571 * @param[in] b bundle object
573 * @return Pointer for uri string if success, NULL if fail
587 val = appsvc_get_uri(b);
592 const char *appsvc_get_uri(bundle *b);
596 * This function gets a mime-type from bundle.
598 * @param[in] b bundle object
600 * @return Pointer for mime-type string if success, NULL if fail
614 val = appsvc_get_mime(b);
619 const char *appsvc_get_mime(bundle *b);
623 * This function gets a package name from bundle.
625 * @param[in] b bundle object
627 * @return Pointer for package name string if success, NULL if fail
641 val = appsvc_get_pkgname(b);
647 const char *appsvc_get_pkgname(bundle *b); // __attribute__((deprecated));
651 * This function gets a application id from bundle.
653 * @param[in] b bundle object
655 * @return Pointer for application id string if success, NULL if fail
669 val = appsvc_get_appid(b);
674 const char *appsvc_get_appid(bundle *b);
678 * This function gets a application category from bundle.
680 * @param[in] b bundle object
682 * @return Pointer for application category string if success, NULL if fail
696 val = appsvc_get_category(b);
701 const char *appsvc_get_category(bundle *b);
705 * This function gets value from key.
707 * @param[in] b bundle object
710 * @return Pointer for value string if success, NULL if fail
724 val = appsvc_get_data(b, APPSVC_DATA_CC);
729 const char *appsvc_get_data(bundle *b, const char *key);
733 * This function gets value from key.
735 * @param[in] b bundle object
737 * @param[out] len length of array
739 * @return Pointer for value string array if success, NULL if fail
756 if(appsvc_data_is_array(b, APPSVC_DATA_SELECTED))
757 val_array = appsvc_get_data_array(b, APPSVC_DATA_SELECTED, &len);
759 val = appsvc_get_data(b, APPSVC_DATA_SELECTED);
764 const char **appsvc_get_data_array(bundle *b, const char *key, int *len);
768 * This API create appsvc result bundle based on bundle received in reset event.
770 * @param[in] inb bundle received in reset event
771 * @param[in] outb bundle to use for returning result
773 * @retval APPSVC_RET_OK - success
774 * @retval APPSVC_RET_ERROR - general error
775 * @retval APPSVC_RET_EINVAL - invalid argument(content)
779 * @see appsvc_send_result.
788 struct appdata *ad = data;
791 appsvc_create_result_bundle(ad->b,&res_bundle);
792 bundle_add(res_bundle, "result", "1");
793 appsvc_send_result(res_bundle, 0);
798 int appsvc_create_result_bundle(bundle *inb, bundle **outb);
802 * This API send appsvc result to caller with bundle.
804 * @param[in] b Result data in bundle format
805 * @param[in] result result value
807 * @retval APPSVC_RET_OK - success
808 * @retval APPSVC_RET_ERROR - general error
809 * @retval APPSVC_RET_EINVAL - invalid argument(content)
811 * @pre appsvc_create_result_bundle.
813 * @see appsvc_send_result.
822 struct appdata *ad = data;
825 appsvc_create_result_bundle(ad->b,&res_bundle);
826 bundle_add(res_bundle, "result", "1");
827 appsvc_send_result(res_bundle, 0);
832 int appsvc_send_result(bundle *b, appsvc_result_val result);
836 * This API set the default application(package name) associated with op, uri and mime-type.
838 * @param[in] op operation
839 * @param[in] mime_type mime-type
840 * @param[in] scheme scheme of uri
841 * @param[in] defapp default application
843 * @retval APPSVC_RET_OK - success
844 * @retval APPSVC_RET_ERROR - general error
845 * @retval APPSVC_RET_EINVAL - invalid argument(content)
858 appsvc_set_defapp(APPSVC_OPERATION_VIEW, NULL,"http", "org.tizen.mybrowser");
863 int appsvc_set_defapp(const char *op, const char *mime_type, const char *uri,
864 const char *defapp, uid_t uid);
868 * This API unset the default application(package name) associated with op, uri and mime-type.
870 * @param[in] defapp default application
872 * @retval APPSVC_RET_OK - success
873 * @retval APPSVC_RET_ERROR - general error
886 appsvc_unset_defapp("org.tizen.test");
891 int appsvc_unset_defapp(const char *defapp, uid_t uid);
895 * This API ask a application is default application or not.
897 * @param[in] pkg_name application package name
898 * @return true / false
899 * @retval 1 app_name is default application in appsvc.
900 * @retval 0 app_name is NOT default application in appsvc.
913 * int is_defapp_browser_app()
915 * return appsvc_is_defapp("org.tizen.browser");
923 int appsvc_is_defapp(const char *appid, uid_t uid);
927 * This API ask a extra data is array or not.
929 * @param[in] b bundle object
930 * @param[in] key key of extra data
931 * @return true / false
932 * @retval 1 a extra data is array.
933 * @retval 0 a extra data is not array.
946 * int is_defapp_browser_app(bundle *b, char *key)
948 * return appsvc_data_is_array(b, key);
956 int appsvc_data_is_array(bundle *b, const char *key);
958 int appsvc_subapp_terminate_request_pid(int pid);
972 #endif /* __APP_SVC_H__ */
974 /* vi: set ts=8 sts=8 sw=8: */