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"
127 * @brief Return values in appsvc.
129 typedef enum _appsvc_return_val {
130 APPSVC_RET_EILLACC = -5, /**< Illegal Access */
131 APPSVC_RET_ELAUNCH = -4, /**< Failure on launching the app */
132 APPSVC_RET_ENOMATCH = -3, /**< No matching result Error */
133 APPSVC_RET_EINVAL = -2, /**< Invalid argument */
134 APPSVC_RET_ERROR = -1, /**< General error */
135 APPSVC_RET_OK = 0 /**< General success */
140 * @brief result values in appsvc.
142 typedef enum _appsvc_result_val {
143 APPSVC_RES_CANCEL = -2, /**< Cancel by system */
144 APPSVC_RES_NOT_OK = -1, /**< Fail by user */
145 APPSVC_RES_OK = 0 /**< Success by user */
150 * @brief appsvc_res_fn is appsvc result function
151 * @param[out] b result bundle
152 * @param[out] request_code request code
153 * @param[out] result result value
154 * @param[out] data user-supplied data
156 typedef void (*appsvc_res_fn)(bundle *b, int request_code, appsvc_result_val result, void *data);
160 * @brief iterator function running with appsvc_get_list
161 * @param[out] pkg_name package name retreived by appsvc_get_list
162 * @param[out] data user-supplied data
164 typedef int (*appsvc_info_iter_fn)(const char *appid, void *data);
166 typedef int (*appsvc_host_res_fn)(void *data);
170 * This function sets an operation to launch application based on appsvc.
172 * @param[in] b bundle object
173 * @param[in] operation operation
175 * @return 0 if success, negative value(<0) if fail
176 * @retval APPSVC_RET_OK - success
177 * @retval APPSVC_RET_ERROR - general error
178 * @retval APPSVC_RET_EINVAL - invalid argument(content)
183 * @remarks An application must call this function before using appsvc_run_service API.
195 appsvc_set_operation(b, APPSVC_OPERATION_VIEW);
200 int appsvc_set_operation(bundle *b, const char *operation);
204 * This function sets an uri to launch application based on appsvc.
206 * @param[in] b bundle object
209 * @return 0 if success, negative value(<0) if fail
210 * @retval APPSVC_RET_OK - success
211 * @retval APPSVC_RET_ERROR - general error
212 * @retval APPSVC_RET_EINVAL - invalid argument(content)
229 appsvc_set_operation(b, APPSVC_OPERATION_VIEW);
230 appsvc_set_uri(b,"http://www.samsung.com");
235 int appsvc_set_uri(bundle *b, const char *uri);
239 * This function sets a mime-type to launch application based on appsvc.
241 * @param[in] b bundle object
242 * @param[in] mime mime-type
244 * @return 0 if success, negative value(<0) if fail
245 * @retval APPSVC_RET_OK - success
246 * @retval APPSVC_RET_ERROR - general error
247 * @retval APPSVC_RET_EINVAL - invalid argument(content)
264 appsvc_set_operation(b, APPSVC_OPERATION_PICK);
265 appsvc_set_mime(b,"image/jpg");
270 int appsvc_set_mime(bundle *b, const char *mime);
274 * This function sets an extra data to launch application based on appsvc.
276 * @param[in] b bundle object
277 * @param[in] key key of extra data
278 * @param[in] val data
280 * @return 0 if success, negative value(<0) if fail
297 appsvc_set_operation(b, APPSVC_OPERATION_SEND);
298 appsvc_set_uri(b,"mailto:xxx1@xxx");
299 appsvc_add_data(b,APPSVC_DATA_CC,"xxx2@xxx");
304 int appsvc_add_data(bundle *b, const char *key, const char *val);
308 * This function sets an extra array data to launch application based on appsvc.
310 * @param[in] b bundle object
311 * @param[in] key key of extra data
312 * @param[in] val_array data
313 * @param[in] len Length of array
315 * @return 0 if success, negative value(<0) if fail
329 char *images[] = {"/opt/media/a.jpg", "/opt/media/b.jpg", "/opt/media/c.jpg"};
333 appsvc_add_data_array(b, APPSVC_DATA_SELECTED, images, 3);
338 int appsvc_add_data_array(bundle *b, const char *key, const char **val_array, int len);
343 * This function sets a package name to launch application based on appsvc.
345 * @param[in] b bundle object
346 * @param[in] pkg_name package name for explict launch
348 * @return 0 if success, negative value(<0) if fail
349 * @retval APPSVC_RET_OK - success
350 * @retval APPSVC_RET_ERROR - general error
351 * @retval APPSVC_RET_EINVAL - invalid argument(content)
368 appsvc_set_operation(b, APPSVC_OPERATION_PICK);
369 appsvc_set_mime(b,"image/jpg");
370 appsvc_set_pkgname(b, "org.tizen.mygallery");
376 int appsvc_set_pkgname(bundle *b, const char *pkg_name); // __attribute__((deprecated));
381 * This function sets a appid to launch application based on appsvc.
383 * @param[in] b bundle object
384 * @param[in] appid application id for explict launch
386 * @return 0 if success, negative value(<0) if fail
387 * @retval APPSVC_RET_OK - success
388 * @retval APPSVC_RET_ERROR - general error
389 * @retval APPSVC_RET_EINVAL - invalid argument(content)
406 appsvc_set_operation(b, APPSVC_OPERATION_PICK);
407 appsvc_set_mime(b,"image/jpg");
408 appsvc_set_appid(b, "org.tizen.mygallery");
413 int appsvc_set_appid(bundle *b, const char *appid);
418 * This function sets a appid to launch application based on appsvc.
420 * @param[in] b bundle object
421 * @param[in] application category
423 * @return 0 if success, negative value(<0) if fail
424 * @retval APPSVC_RET_OK - success
425 * @retval APPSVC_RET_ERROR - general error
426 * @retval APPSVC_RET_EINVAL - invalid argument(content)
443 appsvc_set_operation(b, APPSVC_OPERATION_VIEW);
444 appsvc_set_category(b, "http://tizen.org/category/app/browser");
449 int appsvc_set_category(bundle *b, const char *category);
453 * This API launch application based on appsvc.
455 * @param[in] b bundle to be passed to callee
456 * @param[in] request_code request code
457 * @param[in] cbfunc result callback function
458 * @param[in] data user-supplied data passed to callback function
460 * @return callee's pid if success, negative value(<0) if fail
461 * @retval callee's pid - success
462 * @retval APPSVC_RET_ERROR - general error
463 * @retval APPSVC_RET_EINVAL - invalid argument(content)
464 * @retval APPSVC_RET_ENOMATCH - no matching result Error
465 * @retval APPSVC_RET_ELAUNCH - failure on launching the app
483 appsvc_set_operation(b, APPSVC_OPERATION_PICK);
484 appsvc_set_mime(b,"image/jpg");
486 return appsvc_run_service(b, 0, cb_func, (void*)NULL);
491 int appsvc_run_service(bundle *b, int request_code, appsvc_res_fn cbfunc, void *data);
492 int appsvc_usr_run_service(bundle *b, int request_code, appsvc_res_fn cbfunc, void *data, uid_t uid);
496 * This API use to get application list that is matched with given bundle.
498 * @param[in] b bundle to resolve application
499 * @param[in] iter_fn iterator function
500 * @param[in] data user-supplied data for iter_fn
502 * @return 0 if success, negative value(<0) if fail
503 * @retval APPSVC_RET_OK - success
504 * @retval APPSVC_RET_EINVAL - invalid argument(content)
505 * @retval APPSVC_RET_ENOMATCH - no matching result Error
516 static int iter_fn(const char* pkg_name, void *data)
518 printf("\t==========================\n");
519 printf("\t pkg_name: %s\n", pkg_name);
520 printf("\t==========================\n");
531 appsvc_set_operation(b, APPSVC_OPERATION_PICK);
532 appsvc_set_mime(b,"image/jpg");
534 return appsvc_get_list(b, iter_fn, (void*)NULL);
539 int appsvc_get_list(bundle *b, appsvc_info_iter_fn iter_fn, void *data);
540 int appsvc_usr_get_list(bundle *b, appsvc_info_iter_fn iter_fn, void *data, uid_t uid);
544 * This function gets a operation from bundle.
546 * @param[in] b bundle object
548 * @return Pointer for operation string if success, NULL if fail
562 val = appsvc_get_operation(b);
567 const char *appsvc_get_operation(bundle *b);
571 * This function gets a uri from bundle.
573 * @param[in] b bundle object
575 * @return Pointer for uri string if success, NULL if fail
589 val = appsvc_get_uri(b);
594 const char *appsvc_get_uri(bundle *b);
598 * This function gets a mime-type from bundle.
600 * @param[in] b bundle object
602 * @return Pointer for mime-type string if success, NULL if fail
616 val = appsvc_get_mime(b);
621 const char *appsvc_get_mime(bundle *b);
625 * This function gets a package name from bundle.
627 * @param[in] b bundle object
629 * @return Pointer for package name string if success, NULL if fail
643 val = appsvc_get_pkgname(b);
649 const char *appsvc_get_pkgname(bundle *b); // __attribute__((deprecated));
653 * This function gets a application id from bundle.
655 * @param[in] b bundle object
657 * @return Pointer for application id string if success, NULL if fail
671 val = appsvc_get_appid(b);
676 const char *appsvc_get_appid(bundle *b);
680 * This function gets a application category from bundle.
682 * @param[in] b bundle object
684 * @return Pointer for application category string if success, NULL if fail
698 val = appsvc_get_category(b);
703 const char *appsvc_get_category(bundle *b);
707 * This function gets value from key.
709 * @param[in] b bundle object
712 * @return Pointer for value string if success, NULL if fail
726 val = appsvc_get_data(b, APPSVC_DATA_CC);
731 const char *appsvc_get_data(bundle *b, const char *key);
735 * This function gets value from key.
737 * @param[in] b bundle object
739 * @param[out] len length of array
741 * @return Pointer for value string array if success, NULL if fail
758 if(appsvc_data_is_array(b, APPSVC_DATA_SELECTED))
759 val_array = appsvc_get_data_array(b, APPSVC_DATA_SELECTED, &len);
761 val = appsvc_get_data(b, APPSVC_DATA_SELECTED);
766 const char **appsvc_get_data_array(bundle *b, const char *key, int *len);
770 * This API create appsvc result bundle based on bundle received in reset event.
772 * @param[in] inb bundle received in reset event
773 * @param[in] outb bundle to use for returning result
775 * @retval APPSVC_RET_OK - success
776 * @retval APPSVC_RET_ERROR - general error
777 * @retval APPSVC_RET_EINVAL - invalid argument(content)
781 * @see appsvc_send_result.
790 struct appdata *ad = data;
793 appsvc_create_result_bundle(ad->b,&res_bundle);
794 bundle_add(res_bundle, "result", "1");
795 appsvc_send_result(res_bundle, 0);
800 int appsvc_create_result_bundle(bundle *inb, bundle **outb);
804 * This API send appsvc result to caller with bundle.
806 * @param[in] b Result data in bundle format
807 * @param[in] result result value
809 * @retval APPSVC_RET_OK - success
810 * @retval APPSVC_RET_ERROR - general error
811 * @retval APPSVC_RET_EINVAL - invalid argument(content)
813 * @pre appsvc_create_result_bundle.
815 * @see appsvc_send_result.
824 struct appdata *ad = data;
827 appsvc_create_result_bundle(ad->b,&res_bundle);
828 bundle_add(res_bundle, "result", "1");
829 appsvc_send_result(res_bundle, 0);
834 int appsvc_send_result(bundle *b, appsvc_result_val result);
838 * This API set the default application(package name) associated with op, uri and mime-type.
840 * @param[in] op operation
841 * @param[in] mime_type mime-type
842 * @param[in] scheme scheme of uri
843 * @param[in] defapp default application
845 * @retval APPSVC_RET_OK - success
846 * @retval APPSVC_RET_ERROR - general error
847 * @retval APPSVC_RET_EINVAL - invalid argument(content)
860 appsvc_set_defapp(APPSVC_OPERATION_VIEW, NULL,"http", "org.tizen.mybrowser");
865 int appsvc_set_defapp(const char *op, const char *mime_type, const char *uri,
866 const char *defapp, uid_t uid);
870 * This API unset the default application(package name) associated with op, uri and mime-type.
872 * @param[in] defapp default application
874 * @retval APPSVC_RET_OK - success
875 * @retval APPSVC_RET_ERROR - general error
888 appsvc_unset_defapp("org.tizen.test");
893 int appsvc_unset_defapp(const char *defapp, uid_t uid);
897 * This API ask a application is default application or not.
899 * @param[in] pkg_name application package name
900 * @return true / false
901 * @retval 1 app_name is default application in appsvc.
902 * @retval 0 app_name is NOT default application in appsvc.
915 * int is_defapp_browser_app()
917 * return appsvc_is_defapp("org.tizen.browser");
925 int appsvc_is_defapp(const char *appid, uid_t uid);
929 * This API ask a extra data is array or not.
931 * @param[in] b bundle object
932 * @param[in] key key of extra data
933 * @return true / false
934 * @retval 1 a extra data is array.
935 * @retval 0 a extra data is not array.
948 * int appsvc_data_is_array(bundle *b, char *key)
950 * return appsvc_data_is_array(b, key);
958 int appsvc_data_is_array(bundle *b, const char *key);
960 int appsvc_subapp_terminate_request_pid(int pid);
964 * This function sets an uri to launch application based on appsvc.
966 * @param[in] b bundle object
967 * @param[in] char *mode
969 * @return 0 if success, negative value(<0) if fail
970 * @retval APPSVC_RET_OK - success
971 * @retval APPSVC_RET_ERROR - general error
972 * @retval APPSVC_RET_EINVAL - invalid argument(content)
985 appsvc_set_launch_mode(app_control->data, mode);
990 int appsvc_set_launch_mode(bundle *b, const char *mode);
994 * This function sets an uri to launch application based on appsvc.
996 * @param[in] b bundle object
998 * @return Pointer for launch mode string if success, NULL if fail
1011 appsvc_get_launch_mode(app_control->data);
1016 const char *appsvc_get_launch_mode(bundle *b);
1029 #endif /* __APP_SVC_H__ */
1031 /* vi: set ts=8 sts=8 sw=8: */