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"
91 /** APP_SVC OPERATION TYPE*/
92 #define APPSVC_OPERATION_LAUNCH_ON_EVENT "http://tizen.org/appcontrol/operation/launch_on_event"
97 /** APP_SVC DATA SUBJECT*/
98 #define APPSVC_DATA_SUBJECT "http://tizen.org/appcontrol/data/subject"
99 /** APP_SVC DATA TYPE*/
100 #define APPSVC_DATA_TO "http://tizen.org/appcontrol/data/to"
101 /** APP_SVC DATA TYPE*/
102 #define APPSVC_DATA_CC "http://tizen.org/appcontrol/data/cc"
103 /** APP_SVC DATA TYPE*/
104 #define APPSVC_DATA_BCC "http://tizen.org/appcontrol/data/bcc"
105 /** APP_SVC DATA TYPE*/
106 #define APPSVC_DATA_TEXT "http://tizen.org/appcontrol/data/text"
107 /** APP_SVC DATA TYPE*/
108 #define APPSVC_DATA_TITLE "http://tizen.org/appcontrol/data/title"
109 /** APP_SVC DATA TYPE*/
110 #define APPSVC_DATA_SELECTED "http://tizen.org/appcontrol/data/selected"
111 /** APP_SVC DATA TYPE*/
112 #define APPSVC_DATA_KEYWORD "http://tizen.org/appcontrol/data/keyword"
113 /** APP_SVC DATA TYPE*/
114 #define APPSVC_DATA_PATH "http://tizen.org/appcontrol/data/path"
115 /** APP_SVC DATA TYPE*/
116 #define APPSVC_DATA_SELECTION_MODE "http://tizen.org/appcontrol/data/selection_mode"
117 /** APP_SVC DATA TYPE*/
118 #define APPSVC_DATA_RETURN_RESULT "http://tizen.org/appcontrol/data/return_result"
121 /** APP SVC internal private key */
122 #define APP_SVC_K_URI_R_INFO "__APP_SVC_URI_R_INFO__"
124 #define APP_SELECTOR "org.tizen.app-selector"
126 #define APPSVC_K_LAUNCH_RESULT_APP_STARTED "__K_LAUNCH_RESULT_APP_STARTED__"
129 * @brief Return values in appsvc.
131 typedef enum _appsvc_return_val {
132 APPSVC_RET_EILLACC = -5, /**< Illegal Access */
133 APPSVC_RET_ELAUNCH = -4, /**< Failure on launching the app */
134 APPSVC_RET_ENOMATCH = -3, /**< No matching result Error */
135 APPSVC_RET_EINVAL = -2, /**< Invalid argument */
136 APPSVC_RET_ERROR = -1, /**< General error */
137 APPSVC_RET_OK = 0 /**< General success */
142 * @brief result values in appsvc.
144 typedef enum _appsvc_result_val {
145 APPSVC_RES_CANCEL = -2, /**< Cancel by system */
146 APPSVC_RES_NOT_OK = -1, /**< Fail by user */
147 APPSVC_RES_OK = 0 /**< Success by user */
152 * @brief appsvc_res_fn is appsvc result function
153 * @param[out] b result bundle
154 * @param[out] request_code request code
155 * @param[out] result result value
156 * @param[out] data user-supplied data
158 typedef void (*appsvc_res_fn)(bundle *b, int request_code, appsvc_result_val result, void *data);
162 * @brief iterator function running with appsvc_get_list
163 * @param[out] pkg_name package name retreived by appsvc_get_list
164 * @param[out] data user-supplied data
166 typedef int (*appsvc_info_iter_fn)(const char *appid, void *data);
168 typedef int (*appsvc_host_res_fn)(void *data);
172 * This function sets an operation to launch application based on appsvc.
174 * @param[in] b bundle object
175 * @param[in] operation operation
177 * @return 0 if success, negative value(<0) if fail
178 * @retval APPSVC_RET_OK - success
179 * @retval APPSVC_RET_ERROR - general error
180 * @retval APPSVC_RET_EINVAL - invalid argument(content)
185 * @remarks An application must call this function before using appsvc_run_service API.
197 appsvc_set_operation(b, APPSVC_OPERATION_VIEW);
202 int appsvc_set_operation(bundle *b, const char *operation);
206 * This function sets an uri to launch application based on appsvc.
208 * @param[in] b bundle object
211 * @return 0 if success, negative value(<0) if fail
212 * @retval APPSVC_RET_OK - success
213 * @retval APPSVC_RET_ERROR - general error
214 * @retval APPSVC_RET_EINVAL - invalid argument(content)
231 appsvc_set_operation(b, APPSVC_OPERATION_VIEW);
232 appsvc_set_uri(b,"http://www.samsung.com");
237 int appsvc_set_uri(bundle *b, const char *uri);
241 * This function sets a mime-type to launch application based on appsvc.
243 * @param[in] b bundle object
244 * @param[in] mime mime-type
246 * @return 0 if success, negative value(<0) if fail
247 * @retval APPSVC_RET_OK - success
248 * @retval APPSVC_RET_ERROR - general error
249 * @retval APPSVC_RET_EINVAL - invalid argument(content)
266 appsvc_set_operation(b, APPSVC_OPERATION_PICK);
267 appsvc_set_mime(b,"image/jpg");
272 int appsvc_set_mime(bundle *b, const char *mime);
276 * This function sets an extra data to launch application based on appsvc.
278 * @param[in] b bundle object
279 * @param[in] key key of extra data
280 * @param[in] val data
282 * @return 0 if success, negative value(<0) if fail
299 appsvc_set_operation(b, APPSVC_OPERATION_SEND);
300 appsvc_set_uri(b,"mailto:xxx1@xxx");
301 appsvc_add_data(b,APPSVC_DATA_CC,"xxx2@xxx");
306 int appsvc_add_data(bundle *b, const char *key, const char *val);
310 * This function sets an extra array data to launch application based on appsvc.
312 * @param[in] b bundle object
313 * @param[in] key key of extra data
314 * @param[in] val_array data
315 * @param[in] len Length of array
317 * @return 0 if success, negative value(<0) if fail
331 char *images[] = {"/opt/media/a.jpg", "/opt/media/b.jpg", "/opt/media/c.jpg"};
335 appsvc_add_data_array(b, APPSVC_DATA_SELECTED, images, 3);
340 int appsvc_add_data_array(bundle *b, const char *key, const char **val_array, int len);
345 * This function sets a package name to launch application based on appsvc.
347 * @param[in] b bundle object
348 * @param[in] pkg_name package name for explict launch
350 * @return 0 if success, negative value(<0) if fail
351 * @retval APPSVC_RET_OK - success
352 * @retval APPSVC_RET_ERROR - general error
353 * @retval APPSVC_RET_EINVAL - invalid argument(content)
370 appsvc_set_operation(b, APPSVC_OPERATION_PICK);
371 appsvc_set_mime(b,"image/jpg");
372 appsvc_set_pkgname(b, "org.tizen.mygallery");
378 int appsvc_set_pkgname(bundle *b, const char *pkg_name); // __attribute__((deprecated));
383 * This function sets a appid to launch application based on appsvc.
385 * @param[in] b bundle object
386 * @param[in] appid application id for explict launch
388 * @return 0 if success, negative value(<0) if fail
389 * @retval APPSVC_RET_OK - success
390 * @retval APPSVC_RET_ERROR - general error
391 * @retval APPSVC_RET_EINVAL - invalid argument(content)
408 appsvc_set_operation(b, APPSVC_OPERATION_PICK);
409 appsvc_set_mime(b,"image/jpg");
410 appsvc_set_appid(b, "org.tizen.mygallery");
415 int appsvc_set_appid(bundle *b, const char *appid);
420 * This function sets a appid to launch application based on appsvc.
422 * @param[in] b bundle object
423 * @param[in] application category
425 * @return 0 if success, negative value(<0) if fail
426 * @retval APPSVC_RET_OK - success
427 * @retval APPSVC_RET_ERROR - general error
428 * @retval APPSVC_RET_EINVAL - invalid argument(content)
445 appsvc_set_operation(b, APPSVC_OPERATION_VIEW);
446 appsvc_set_category(b, "http://tizen.org/category/app/browser");
451 int appsvc_set_category(bundle *b, const char *category);
455 * This API launch application based on appsvc.
457 * @param[in] b bundle to be passed to callee
458 * @param[in] request_code request code
459 * @param[in] cbfunc result callback function
460 * @param[in] data user-supplied data passed to callback function
462 * @return callee's pid if success, negative value(<0) if fail
463 * @retval callee's pid - success
464 * @retval APPSVC_RET_ERROR - general error
465 * @retval APPSVC_RET_EINVAL - invalid argument(content)
466 * @retval APPSVC_RET_ENOMATCH - no matching result Error
467 * @retval APPSVC_RET_ELAUNCH - failure on launching the app
485 appsvc_set_operation(b, APPSVC_OPERATION_PICK);
486 appsvc_set_mime(b,"image/jpg");
488 return appsvc_run_service(b, 0, cb_func, (void*)NULL);
493 int appsvc_run_service(bundle *b, int request_code, appsvc_res_fn cbfunc, void *data);
494 int appsvc_usr_run_service(bundle *b, int request_code, appsvc_res_fn cbfunc, void *data, uid_t uid);
498 * This API use to get application list that is matched with given bundle.
500 * @param[in] b bundle to resolve application
501 * @param[in] iter_fn iterator function
502 * @param[in] data user-supplied data for iter_fn
504 * @return 0 if success, negative value(<0) if fail
505 * @retval APPSVC_RET_OK - success
506 * @retval APPSVC_RET_EINVAL - invalid argument(content)
507 * @retval APPSVC_RET_ENOMATCH - no matching result Error
518 static int iter_fn(const char* pkg_name, void *data)
520 printf("\t==========================\n");
521 printf("\t pkg_name: %s\n", pkg_name);
522 printf("\t==========================\n");
533 appsvc_set_operation(b, APPSVC_OPERATION_PICK);
534 appsvc_set_mime(b,"image/jpg");
536 return appsvc_get_list(b, iter_fn, (void*)NULL);
541 int appsvc_get_list(bundle *b, appsvc_info_iter_fn iter_fn, void *data);
542 int appsvc_usr_get_list(bundle *b, appsvc_info_iter_fn iter_fn, void *data, uid_t uid);
546 * This function gets a operation from bundle.
548 * @param[in] b bundle object
550 * @return Pointer for operation string if success, NULL if fail
564 val = appsvc_get_operation(b);
569 const char *appsvc_get_operation(bundle *b);
573 * This function gets a uri from bundle.
575 * @param[in] b bundle object
577 * @return Pointer for uri string if success, NULL if fail
591 val = appsvc_get_uri(b);
596 const char *appsvc_get_uri(bundle *b);
600 * This function gets a mime-type from bundle.
602 * @param[in] b bundle object
604 * @return Pointer for mime-type string if success, NULL if fail
618 val = appsvc_get_mime(b);
623 const char *appsvc_get_mime(bundle *b);
627 * This function gets a package name from bundle.
629 * @param[in] b bundle object
631 * @return Pointer for package name string if success, NULL if fail
645 val = appsvc_get_pkgname(b);
651 const char *appsvc_get_pkgname(bundle *b); // __attribute__((deprecated));
655 * This function gets a application id from bundle.
657 * @param[in] b bundle object
659 * @return Pointer for application id string if success, NULL if fail
673 val = appsvc_get_appid(b);
678 const char *appsvc_get_appid(bundle *b);
682 * This function gets a application category from bundle.
684 * @param[in] b bundle object
686 * @return Pointer for application category string if success, NULL if fail
700 val = appsvc_get_category(b);
705 const char *appsvc_get_category(bundle *b);
709 * This function gets value from key.
711 * @param[in] b bundle object
714 * @return Pointer for value string if success, NULL if fail
728 val = appsvc_get_data(b, APPSVC_DATA_CC);
733 const char *appsvc_get_data(bundle *b, const char *key);
737 * This function gets value from key.
739 * @param[in] b bundle object
741 * @param[out] len length of array
743 * @return Pointer for value string array if success, NULL if fail
760 if(appsvc_data_is_array(b, APPSVC_DATA_SELECTED))
761 val_array = appsvc_get_data_array(b, APPSVC_DATA_SELECTED, &len);
763 val = appsvc_get_data(b, APPSVC_DATA_SELECTED);
768 const char **appsvc_get_data_array(bundle *b, const char *key, int *len);
772 * This API create appsvc result bundle based on bundle received in reset event.
774 * @param[in] inb bundle received in reset event
775 * @param[in] outb bundle to use for returning result
777 * @retval APPSVC_RET_OK - success
778 * @retval APPSVC_RET_ERROR - general error
779 * @retval APPSVC_RET_EINVAL - invalid argument(content)
783 * @see appsvc_send_result.
792 struct appdata *ad = data;
795 appsvc_create_result_bundle(ad->b,&res_bundle);
796 bundle_add(res_bundle, "result", "1");
797 appsvc_send_result(res_bundle, 0);
802 int appsvc_create_result_bundle(bundle *inb, bundle **outb);
806 * This API send appsvc result to caller with bundle.
808 * @param[in] b Result data in bundle format
809 * @param[in] result result value
811 * @retval APPSVC_RET_OK - success
812 * @retval APPSVC_RET_ERROR - general error
813 * @retval APPSVC_RET_EINVAL - invalid argument(content)
815 * @pre appsvc_create_result_bundle.
817 * @see appsvc_send_result.
826 struct appdata *ad = data;
829 appsvc_create_result_bundle(ad->b,&res_bundle);
830 bundle_add(res_bundle, "result", "1");
831 appsvc_send_result(res_bundle, 0);
836 int appsvc_send_result(bundle *b, appsvc_result_val result);
840 * This API set the default application(package name) associated with op, uri and mime-type.
842 * @param[in] op operation
843 * @param[in] mime_type mime-type
844 * @param[in] scheme scheme of uri
845 * @param[in] defapp default application
847 * @retval APPSVC_RET_OK - success
848 * @retval APPSVC_RET_ERROR - general error
849 * @retval APPSVC_RET_EINVAL - invalid argument(content)
862 appsvc_set_defapp(APPSVC_OPERATION_VIEW, NULL,"http", "org.tizen.mybrowser");
867 int appsvc_set_defapp(const char *op, const char *mime_type, const char *uri,
868 const char *defapp, uid_t uid);
872 * This API unset the default application(package name) associated with op, uri and mime-type.
874 * @param[in] defapp default application
876 * @retval APPSVC_RET_OK - success
877 * @retval APPSVC_RET_ERROR - general error
890 appsvc_unset_defapp("org.tizen.test");
895 int appsvc_unset_defapp(const char *defapp, uid_t uid);
899 * This API ask a application is default application or not.
901 * @param[in] pkg_name application package name
902 * @return true / false
903 * @retval 1 app_name is default application in appsvc.
904 * @retval 0 app_name is NOT default application in appsvc.
917 * int is_defapp_browser_app()
919 * return appsvc_is_defapp("org.tizen.browser");
927 int appsvc_is_defapp(const char *appid, uid_t uid);
931 * This API ask a extra data is array or not.
933 * @param[in] b bundle object
934 * @param[in] key key of extra data
935 * @return true / false
936 * @retval 1 a extra data is array.
937 * @retval 0 a extra data is not array.
950 * int appsvc_data_is_array(bundle *b, char *key)
952 * return appsvc_data_is_array(b, key);
960 int appsvc_data_is_array(bundle *b, const char *key);
962 int appsvc_subapp_terminate_request_pid(int pid);
966 * This function sets an uri to launch application based on appsvc.
968 * @param[in] b bundle object
969 * @param[in] char *mode
971 * @return 0 if success, negative value(<0) if fail
972 * @retval APPSVC_RET_OK - success
973 * @retval APPSVC_RET_ERROR - general error
974 * @retval APPSVC_RET_EINVAL - invalid argument(content)
987 appsvc_set_launch_mode(app_control->data, mode);
992 int appsvc_set_launch_mode(bundle *b, const char *mode);
996 * This function sets an uri to launch application based on appsvc.
998 * @param[in] b bundle object
1000 * @return Pointer for launch mode string if success, NULL if fail
1013 appsvc_get_launch_mode(app_control->data);
1018 const char *appsvc_get_launch_mode(bundle *b);
1020 int aul_svc_subscribe_launch_result(bundle *b, const char *event);
1033 #endif /* __APP_SVC_H__ */
1035 /* vi: set ts=8 sts=8 sw=8: */