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"
78 /** APP_SVC OPERATION TYPE*/
79 #define APPSVC_OPERATION_SHARE "http://tizen.org/appcontrol/operation/share"
80 /** APP_SVC OPERATION TYPE*/
81 #define APPSVC_OPERATION_MULTI_SHARE "http://tizen.org/appcontrol/operation/multi_share"
82 /** APP_SVC OPERATION TYPE*/
83 #define APPSVC_OPERATION_COMPOSE "http://tizen.org/appcontorl/opeation/compose"
84 /** APP_SVC OPERATION TYPE*/
85 #define APPSVC_OPERATION_LOCATION "http://tizen.org/appcontrol/operation/configure/location"
86 /** APP_SVC OPERATION TYPE*/
87 #define APPSVC_OPERATION_FONT_TYPE "http://tizen.org/appcontrol/operation/configure/font/type"
88 /** APP_SVC OPERATION TYPE*/
89 #define APPSVC_OPERATION_FONT_SIZE "http://tizen.org/appcontrol/operation/configure/font/size"
94 /** APP_SVC DATA SUBJECT*/
95 #define APPSVC_DATA_SUBJECT "http://tizen.org/appcontrol/data/subject"
96 /** APP_SVC DATA TYPE*/
97 #define APPSVC_DATA_TO "http://tizen.org/appcontrol/data/to"
98 /** APP_SVC DATA TYPE*/
99 #define APPSVC_DATA_CC "http://tizen.org/appcontrol/data/cc"
100 /** APP_SVC DATA TYPE*/
101 #define APPSVC_DATA_BCC "http://tizen.org/appcontrol/data/bcc"
102 /** APP_SVC DATA TYPE*/
103 #define APPSVC_DATA_TEXT "http://tizen.org/appcontrol/data/text"
104 /** APP_SVC DATA TYPE*/
105 #define APPSVC_DATA_TITLE "http://tizen.org/appcontrol/data/title"
106 /** APP_SVC DATA TYPE*/
107 #define APPSVC_DATA_SELECTED "http://tizen.org/appcontrol/data/selected"
108 /** APP_SVC DATA TYPE*/
109 #define APPSVC_DATA_KEYWORD "http://tizen.org/appcontrol/data/keyword"
110 /** APP_SVC DATA TYPE*/
111 #define APPSVC_DATA_PATH "http://tizen.org/appcontrol/data/path"
112 /** APP_SVC DATA TYPE*/
113 #define APPSVC_DATA_SELECTION_MODE "http://tizen.org/appcontrol/data/selection_mode"
114 /** APP_SVC DATA TYPE*/
115 #define APPSVC_DATA_RETURN_RESULT "http://tizen.org/appcontrol/data/return_result"
118 /** APP SVC internal private key */
119 #define APP_SVC_K_URI_R_INFO "__APP_SVC_URI_R_INFO__"
123 * @brief Return values in appsvc.
125 typedef enum _appsvc_return_val {
126 APPSVC_RET_EILLACC = -5, /**< Illegal Access */
127 APPSVC_RET_ELAUNCH = -4, /**< Failure on launching the app */
128 APPSVC_RET_ENOMATCH = -3, /**< No matching result Error */
129 APPSVC_RET_EINVAL = -2, /**< Invalid argument */
130 APPSVC_RET_ERROR = -1, /**< General error */
131 APPSVC_RET_OK = 0 /**< General success */
136 * @brief result values in appsvc.
138 typedef enum _appsvc_result_val {
139 APPSVC_RES_CANCEL = -2, /**< Cancel by system */
140 APPSVC_RES_NOT_OK = -1, /**< Fail by user */
141 APPSVC_RES_OK = 0 /**< Success by user */
146 * @brief appsvc_res_fn is appsvc result function
147 * @param[out] b result bundle
148 * @param[out] request_code request code
149 * @param[out] result result value
150 * @param[out] data user-supplied data
152 typedef void (*appsvc_res_fn)(bundle *b, int request_code, appsvc_result_val result, void *data);
156 * @brief iterator function running with appsvc_get_list
157 * @param[out] pkg_name package name retreived by appsvc_get_list
158 * @param[out] data user-supplied data
160 typedef int (*appsvc_info_iter_fn)(const char *appid, void *data);
162 typedef int (*appsvc_host_res_fn)(void *data);
166 * This function sets an operation to launch application based on appsvc.
168 * @param[in] b bundle object
169 * @param[in] operation operation
171 * @return 0 if success, negative value(<0) if fail
172 * @retval APPSVC_RET_OK - success
173 * @retval APPSVC_RET_ERROR - general error
174 * @retval APPSVC_RET_EINVAL - invalid argument(content)
179 * @remarks An application must call this function before using appsvc_run_service API.
191 appsvc_set_operation(b, APPSVC_OPERATION_VIEW);
196 int appsvc_set_operation(bundle *b, const char *operation);
200 * This function sets an uri to launch application based on appsvc.
202 * @param[in] b bundle object
205 * @return 0 if success, negative value(<0) if fail
206 * @retval APPSVC_RET_OK - success
207 * @retval APPSVC_RET_ERROR - general error
208 * @retval APPSVC_RET_EINVAL - invalid argument(content)
225 appsvc_set_operation(b, APPSVC_OPERATION_VIEW);
226 appsvc_set_uri(b,"http://www.samsung.com");
231 int appsvc_set_uri(bundle *b, const char *uri);
235 * This function sets a mime-type to launch application based on appsvc.
237 * @param[in] b bundle object
238 * @param[in] mime mime-type
240 * @return 0 if success, negative value(<0) if fail
241 * @retval APPSVC_RET_OK - success
242 * @retval APPSVC_RET_ERROR - general error
243 * @retval APPSVC_RET_EINVAL - invalid argument(content)
260 appsvc_set_operation(b, APPSVC_OPERATION_PICK);
261 appsvc_set_mime(b,"image/jpg");
266 int appsvc_set_mime(bundle *b, const char *mime);
270 * This function sets an extra data to launch application based on appsvc.
272 * @param[in] b bundle object
273 * @param[in] key key of extra data
274 * @param[in] val data
276 * @return 0 if success, negative value(<0) if fail
293 appsvc_set_operation(b, APPSVC_OPERATION_SEND);
294 appsvc_set_uri(b,"mailto:xxx1@xxx");
295 appsvc_add_data(b,APPSVC_DATA_CC,"xxx2@xxx");
300 int appsvc_add_data(bundle *b, const char *key, const char *val);
304 * This function sets an extra array data to launch application based on appsvc.
306 * @param[in] b bundle object
307 * @param[in] key key of extra data
308 * @param[in] val_array data
309 * @param[in] len Length of array
311 * @return 0 if success, negative value(<0) if fail
325 char *images[] = {"/opt/media/a.jpg", "/opt/media/b.jpg", "/opt/media/c.jpg"};
329 appsvc_add_data_array(b, APPSVC_DATA_SELECTED, images, 3);
334 int appsvc_add_data_array(bundle *b, const char *key, const char **val_array, int len);
339 * This function sets a package name to launch application based on appsvc.
341 * @param[in] b bundle object
342 * @param[in] pkg_name package name for explict launch
344 * @return 0 if success, negative value(<0) if fail
345 * @retval APPSVC_RET_OK - success
346 * @retval APPSVC_RET_ERROR - general error
347 * @retval APPSVC_RET_EINVAL - invalid argument(content)
364 appsvc_set_operation(b, APPSVC_OPERATION_PICK);
365 appsvc_set_mime(b,"image/jpg");
366 appsvc_set_pkgname(b, "org.tizen.mygallery");
372 int appsvc_set_pkgname(bundle *b, const char *pkg_name); // __attribute__((deprecated));
377 * This function sets a appid to launch application based on appsvc.
379 * @param[in] b bundle object
380 * @param[in] appid application id for explict launch
382 * @return 0 if success, negative value(<0) if fail
383 * @retval APPSVC_RET_OK - success
384 * @retval APPSVC_RET_ERROR - general error
385 * @retval APPSVC_RET_EINVAL - invalid argument(content)
402 appsvc_set_operation(b, APPSVC_OPERATION_PICK);
403 appsvc_set_mime(b,"image/jpg");
404 appsvc_set_appid(b, "org.tizen.mygallery");
409 int appsvc_set_appid(bundle *b, const char *appid);
414 * This function sets a appid to launch application based on appsvc.
416 * @param[in] b bundle object
417 * @param[in] application category
419 * @return 0 if success, negative value(<0) if fail
420 * @retval APPSVC_RET_OK - success
421 * @retval APPSVC_RET_ERROR - general error
422 * @retval APPSVC_RET_EINVAL - invalid argument(content)
439 appsvc_set_operation(b, APPSVC_OPERATION_VIEW);
440 appsvc_set_category(b, "http://tizen.org/category/app/browser");
445 int appsvc_set_category(bundle *b, const char *category);
449 * This API launch application based on appsvc.
451 * @param[in] b bundle to be passed to callee
452 * @param[in] request_code request code
453 * @param[in] cbfunc result callback function
454 * @param[in] data user-supplied data passed to callback function
456 * @return callee's pid if success, negative value(<0) if fail
457 * @retval callee's pid - success
458 * @retval APPSVC_RET_ERROR - general error
459 * @retval APPSVC_RET_EINVAL - invalid argument(content)
460 * @retval APPSVC_RET_ENOMATCH - no matching result Error
461 * @retval APPSVC_RET_ELAUNCH - failure on launching the app
479 appsvc_set_operation(b, APPSVC_OPERATION_PICK);
480 appsvc_set_mime(b,"image/jpg");
482 return appsvc_run_service(b, 0, cb_func, (void*)NULL);
487 int appsvc_run_service(bundle *b, int request_code, appsvc_res_fn cbfunc, void *data);
491 * This API use to get application list that is matched with given bundle.
493 * @param[in] b bundle to resolve application
494 * @param[in] iter_fn iterator function
495 * @param[in] data user-supplied data for iter_fn
497 * @return 0 if success, negative value(<0) if fail
498 * @retval APPSVC_RET_OK - success
499 * @retval APPSVC_RET_EINVAL - invalid argument(content)
500 * @retval APPSVC_RET_ENOMATCH - no matching result Error
511 static int iter_fn(const char* pkg_name, void *data)
513 printf("\t==========================\n");
514 printf("\t pkg_name: %s\n", pkg_name);
515 printf("\t==========================\n");
526 appsvc_set_operation(b, APPSVC_OPERATION_PICK);
527 appsvc_set_mime(b,"image/jpg");
529 return appsvc_get_list(b, iter_fn, (void*)NULL);
534 int appsvc_get_list(bundle *b, appsvc_info_iter_fn iter_fn, void *data);
538 * This function gets a operation from bundle.
540 * @param[in] b bundle object
542 * @return Pointer for operation string if success, NULL if fail
556 val = appsvc_get_operation(b);
561 const char *appsvc_get_operation(bundle *b);
565 * This function gets a uri from bundle.
567 * @param[in] b bundle object
569 * @return Pointer for uri string if success, NULL if fail
583 val = appsvc_get_uri(b);
588 const char *appsvc_get_uri(bundle *b);
592 * This function gets a mime-type from bundle.
594 * @param[in] b bundle object
596 * @return Pointer for mime-type string if success, NULL if fail
610 val = appsvc_get_mime(b);
615 const char *appsvc_get_mime(bundle *b);
619 * This function gets a package name from bundle.
621 * @param[in] b bundle object
623 * @return Pointer for package name string if success, NULL if fail
637 val = appsvc_get_pkgname(b);
643 const char *appsvc_get_pkgname(bundle *b); // __attribute__((deprecated));
647 * This function gets a application id from bundle.
649 * @param[in] b bundle object
651 * @return Pointer for application id string if success, NULL if fail
665 val = appsvc_get_appid(b);
670 const char *appsvc_get_appid(bundle *b);
674 * This function gets a application category from bundle.
676 * @param[in] b bundle object
678 * @return Pointer for application category string if success, NULL if fail
692 val = appsvc_get_category(b);
697 const char *appsvc_get_category(bundle *b);
701 * This function gets value from key.
703 * @param[in] b bundle object
706 * @return Pointer for value string if success, NULL if fail
720 val = appsvc_get_data(b, APPSVC_DATA_CC);
725 const char *appsvc_get_data(bundle *b, const char *key);
729 * This function gets value from key.
731 * @param[in] b bundle object
733 * @param[out] len length of array
735 * @return Pointer for value string array if success, NULL if fail
752 if(appsvc_data_is_array(b, APPSVC_DATA_SELECTED))
753 val_array = appsvc_get_data_array(b, APPSVC_DATA_SELECTED, &len);
755 val = appsvc_get_data(b, APPSVC_DATA_SELECTED);
760 const char **appsvc_get_data_array(bundle *b, const char *key, int *len);
764 * This API create appsvc result bundle based on bundle received in reset event.
766 * @param[in] inb bundle received in reset event
767 * @param[in] outb bundle to use for returning result
769 * @retval APPSVC_RET_OK - success
770 * @retval APPSVC_RET_ERROR - general error
771 * @retval APPSVC_RET_EINVAL - invalid argument(content)
775 * @see appsvc_send_result.
784 struct appdata *ad = data;
787 appsvc_create_result_bundle(ad->b,&res_bundle);
788 bundle_add(res_bundle, "result", "1");
789 appsvc_send_result(res_bundle, 0);
794 int appsvc_create_result_bundle(bundle *inb, bundle **outb);
798 * This API send appsvc result to caller with bundle.
800 * @param[in] b Result data in bundle format
801 * @param[in] result result value
803 * @retval APPSVC_RET_OK - success
804 * @retval APPSVC_RET_ERROR - general error
805 * @retval APPSVC_RET_EINVAL - invalid argument(content)
807 * @pre appsvc_create_result_bundle.
809 * @see appsvc_send_result.
818 struct appdata *ad = data;
821 appsvc_create_result_bundle(ad->b,&res_bundle);
822 bundle_add(res_bundle, "result", "1");
823 appsvc_send_result(res_bundle, 0);
828 int appsvc_send_result(bundle *b, appsvc_result_val result);
832 * This API set the default application(package name) associated with op, uri and mime-type.
834 * @param[in] op operation
835 * @param[in] mime_type mime-type
836 * @param[in] scheme scheme of uri
837 * @param[in] defapp default application
839 * @retval APPSVC_RET_OK - success
840 * @retval APPSVC_RET_ERROR - general error
841 * @retval APPSVC_RET_EINVAL - invalid argument(content)
854 appsvc_set_defapp(APPSVC_OPERATION_VIEW, NULL,"http", "org.tizen.mybrowser");
859 int appsvc_set_defapp(const char *op, const char *mime_type, const char *uri,
864 * This API unset the default application(package name) associated with op, uri and mime-type.
866 * @param[in] defapp default application
868 * @retval APPSVC_RET_OK - success
869 * @retval APPSVC_RET_ERROR - general error
882 appsvc_unset_defapp("org.tizen.test");
887 int appsvc_unset_defapp(const char *defapp);
891 * This API ask a application is default application or not.
893 * @param[in] pkg_name application package name
894 * @return true / false
895 * @retval 1 app_name is default application in appsvc.
896 * @retval 0 app_name is NOT default application in appsvc.
909 * int is_defapp_browser_app()
911 * return appsvc_is_defapp("org.tizen.browser");
919 int appsvc_is_defapp(const char *appid);
924 * This API ask a extra data is array or not.
926 * @param[in] b bundle object
927 * @param[in] key key of extra data
928 * @return true / false
929 * @retval 1 a extra data is array.
930 * @retval 0 a extra data is not array.
943 * int is_defapp_browser_app(bundle *b, char *key)
945 * return appsvc_data_is_array(b, key);
953 int appsvc_data_is_array(bundle *b, const char *key);
968 #endif /* __APP_SVC_H__ */
970 /* vi: set ts=8 sts=8 sw=8: */