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__"
102 * @brief Return values in appsvc.
104 typedef enum _appsvc_return_val {
105 APPSVC_RET_EILLACC = -5, /**< Illegal Access */
106 APPSVC_RET_ELAUNCH = -4, /**< Failure on launching the app */
107 APPSVC_RET_ENOMATCH = -3, /**< No matching result Error */
108 APPSVC_RET_EINVAL = -2, /**< Invalid argument */
109 APPSVC_RET_ERROR = -1, /**< General error */
110 APPSVC_RET_OK = 0 /**< General success */
115 * @brief result values in appsvc.
117 typedef enum _appsvc_result_val {
118 APPSVC_RES_CANCEL = -2, /**< Cancel by system */
119 APPSVC_RES_NOT_OK = -1, /**< Fail by user */
120 APPSVC_RES_OK = 0 /**< Success by user */
125 * @brief appsvc_res_fn is appsvc result function
126 * @param[out] b result bundle
127 * @param[out] request_code request code
128 * @param[out] result result value
129 * @param[out] data user-supplied data
131 typedef void (*appsvc_res_fn)(bundle *b, int request_code, appsvc_result_val result, void *data);
135 * @brief iterator function running with appsvc_get_list
136 * @param[out] pkg_name package name retreived by appsvc_get_list
137 * @param[out] data user-supplied data
139 typedef int (*appsvc_info_iter_fn)(const char *appid, void *data);
141 typedef int (*appsvc_host_res_fn)(void *data);
145 * This function sets an operation to launch application based on appsvc.
147 * @param[in] b bundle object
148 * @param[in] operation operation
150 * @return 0 if success, negative value(<0) if fail
151 * @retval APPSVC_RET_OK - success
152 * @retval APPSVC_RET_ERROR - general error
153 * @retval APPSVC_RET_EINVAL - invalid argument(content)
158 * @remarks An application must call this function before using appsvc_run_service API.
170 appsvc_set_operation(b, APPSVC_OPERATION_VIEW);
175 int appsvc_set_operation(bundle *b, const char *operation);
179 * This function sets an uri to launch application based on appsvc.
181 * @param[in] b bundle object
184 * @return 0 if success, negative value(<0) if fail
185 * @retval APPSVC_RET_OK - success
186 * @retval APPSVC_RET_ERROR - general error
187 * @retval APPSVC_RET_EINVAL - invalid argument(content)
204 appsvc_set_operation(b, APPSVC_OPERATION_VIEW);
205 appsvc_set_uri(b,"http://www.samsung.com");
210 int appsvc_set_uri(bundle *b, const char *uri);
214 * This function sets a mime-type to launch application based on appsvc.
216 * @param[in] b bundle object
217 * @param[in] mime mime-type
219 * @return 0 if success, negative value(<0) if fail
220 * @retval APPSVC_RET_OK - success
221 * @retval APPSVC_RET_ERROR - general error
222 * @retval APPSVC_RET_EINVAL - invalid argument(content)
239 appsvc_set_operation(b, APPSVC_OPERATION_PICK);
240 appsvc_set_mime(b,"image/jpg");
245 int appsvc_set_mime(bundle *b, const char *mime);
249 * This function sets an extra data to launch application based on appsvc.
251 * @param[in] b bundle object
252 * @param[in] key key of extra data
253 * @param[in] val data
255 * @return 0 if success, negative value(<0) if fail
272 appsvc_set_operation(b, APPSVC_OPERATION_SEND);
273 appsvc_set_uri(b,"mailto:xxx1@xxx");
274 appsvc_add_data(b,APPSVC_DATA_CC,"xxx2@xxx");
279 int appsvc_add_data(bundle *b, const char *key, const char *val);
283 * This function sets an extra array data to launch application based on appsvc.
285 * @param[in] b bundle object
286 * @param[in] key key of extra data
287 * @param[in] val_array data
288 * @param[in] len Length of array
290 * @return 0 if success, negative value(<0) if fail
304 char *images[] = {"/opt/media/a.jpg", "/opt/media/b.jpg", "/opt/media/c.jpg"};
308 appsvc_add_data_array(b, APPSVC_DATA_SELECTED, images, 3);
313 int appsvc_add_data_array(bundle *b, const char *key, const char **val_array, int len);
318 * This function sets a package name to launch application based on appsvc.
320 * @param[in] b bundle object
321 * @param[in] pkg_name package name for explict launch
323 * @return 0 if success, negative value(<0) if fail
324 * @retval APPSVC_RET_OK - success
325 * @retval APPSVC_RET_ERROR - general error
326 * @retval APPSVC_RET_EINVAL - invalid argument(content)
343 appsvc_set_operation(b, APPSVC_OPERATION_PICK);
344 appsvc_set_mime(b,"image/jpg");
345 appsvc_set_pkgname(b, "org.tizen.mygallery");
351 int appsvc_set_pkgname(bundle *b, const char *pkg_name); // __attribute__((deprecated));
356 * This function sets a appid to launch application based on appsvc.
358 * @param[in] b bundle object
359 * @param[in] appid application id for explict launch
361 * @return 0 if success, negative value(<0) if fail
362 * @retval APPSVC_RET_OK - success
363 * @retval APPSVC_RET_ERROR - general error
364 * @retval APPSVC_RET_EINVAL - invalid argument(content)
381 appsvc_set_operation(b, APPSVC_OPERATION_PICK);
382 appsvc_set_mime(b,"image/jpg");
383 appsvc_set_appid(b, "org.tizen.mygallery");
388 int appsvc_set_appid(bundle *b, const char *appid);
393 * This function sets a appid to launch application based on appsvc.
395 * @param[in] b bundle object
396 * @param[in] application category
398 * @return 0 if success, negative value(<0) if fail
399 * @retval APPSVC_RET_OK - success
400 * @retval APPSVC_RET_ERROR - general error
401 * @retval APPSVC_RET_EINVAL - invalid argument(content)
418 appsvc_set_operation(b, APPSVC_OPERATION_VIEW);
419 appsvc_set_category(b, "http://tizen.org/category/app/browser");
424 int appsvc_set_category(bundle *b, const char *category);
428 * This API launch application based on appsvc.
430 * @param[in] b bundle to be passed to callee
431 * @param[in] request_code request code
432 * @param[in] cbfunc result callback function
433 * @param[in] data user-supplied data passed to callback function
435 * @return callee's pid if success, negative value(<0) if fail
436 * @retval callee's pid - success
437 * @retval APPSVC_RET_ERROR - general error
438 * @retval APPSVC_RET_EINVAL - invalid argument(content)
439 * @retval APPSVC_RET_ENOMATCH - no matching result Error
440 * @retval APPSVC_RET_ELAUNCH - failure on launching the app
458 appsvc_set_operation(b, APPSVC_OPERATION_PICK);
459 appsvc_set_mime(b,"image/jpg");
461 return appsvc_run_service(b, 0, cb_func, (void*)NULL);
466 int appsvc_run_service(bundle *b, int request_code, appsvc_res_fn cbfunc, void *data);
470 * This API use to get application list that is matched with given bundle.
472 * @param[in] b bundle to resolve application
473 * @param[in] iter_fn iterator function
474 * @param[in] data user-supplied data for iter_fn
476 * @return 0 if success, negative value(<0) if fail
477 * @retval APPSVC_RET_OK - success
478 * @retval APPSVC_RET_EINVAL - invalid argument(content)
479 * @retval APPSVC_RET_ENOMATCH - no matching result Error
490 static int iter_fn(const char* pkg_name, void *data)
492 printf("\t==========================\n");
493 printf("\t pkg_name: %s\n", pkg_name);
494 printf("\t==========================\n");
505 appsvc_set_operation(b, APPSVC_OPERATION_PICK);
506 appsvc_set_mime(b,"image/jpg");
508 return appsvc_get_list(b, iter_fn, (void*)NULL);
513 int appsvc_get_list(bundle *b, appsvc_info_iter_fn iter_fn, void *data);
517 * This function gets a operation from bundle.
519 * @param[in] b bundle object
521 * @return Pointer for operation string if success, NULL if fail
535 val = appsvc_get_operation(b);
540 const char *appsvc_get_operation(bundle *b);
544 * This function gets a uri from bundle.
546 * @param[in] b bundle object
548 * @return Pointer for uri string if success, NULL if fail
562 val = appsvc_get_uri(b);
567 const char *appsvc_get_uri(bundle *b);
571 * This function gets a mime-type from bundle.
573 * @param[in] b bundle object
575 * @return Pointer for mime-type string if success, NULL if fail
589 val = appsvc_get_mime(b);
594 const char *appsvc_get_mime(bundle *b);
598 * This function gets a package name from bundle.
600 * @param[in] b bundle object
602 * @return Pointer for package name string if success, NULL if fail
616 val = appsvc_get_pkgname(b);
622 const char *appsvc_get_pkgname(bundle *b); // __attribute__((deprecated));
626 * This function gets a application id from bundle.
628 * @param[in] b bundle object
630 * @return Pointer for application id string if success, NULL if fail
644 val = appsvc_get_appid(b);
649 const char *appsvc_get_appid(bundle *b);
653 * This function gets a application category from bundle.
655 * @param[in] b bundle object
657 * @return Pointer for application category string if success, NULL if fail
671 val = appsvc_get_category(b);
676 const char *appsvc_get_category(bundle *b);
680 * This function gets value from key.
682 * @param[in] b bundle object
685 * @return Pointer for value string if success, NULL if fail
699 val = appsvc_get_data(b, APPSVC_DATA_CC);
704 const char *appsvc_get_data(bundle *b, const char *key);
708 * This function gets value from key.
710 * @param[in] b bundle object
712 * @param[out] len length of array
714 * @return Pointer for value string array if success, NULL if fail
731 if(appsvc_data_is_array(b, APPSVC_DATA_SELECTED))
732 val_array = appsvc_get_data_array(b, APPSVC_DATA_SELECTED, &len);
734 val = appsvc_get_data(b, APPSVC_DATA_SELECTED);
739 const char **appsvc_get_data_array(bundle *b, const char *key, int *len);
743 * This API create appsvc result bundle based on bundle received in reset event.
745 * @param[in] inb bundle received in reset event
746 * @param[in] outb bundle to use for returning result
748 * @retval APPSVC_RET_OK - success
749 * @retval APPSVC_RET_ERROR - general error
750 * @retval APPSVC_RET_EINVAL - invalid argument(content)
754 * @see appsvc_send_result.
763 struct appdata *ad = data;
766 appsvc_create_result_bundle(ad->b,&res_bundle);
767 bundle_add(res_bundle, "result", "1");
768 appsvc_send_result(res_bundle, 0);
773 int appsvc_create_result_bundle(bundle *inb, bundle **outb);
777 * This API send appsvc result to caller with bundle.
779 * @param[in] b Result data in bundle format
780 * @param[in] result result value
782 * @retval APPSVC_RET_OK - success
783 * @retval APPSVC_RET_ERROR - general error
784 * @retval APPSVC_RET_EINVAL - invalid argument(content)
786 * @pre appsvc_create_result_bundle.
788 * @see appsvc_send_result.
797 struct appdata *ad = data;
800 appsvc_create_result_bundle(ad->b,&res_bundle);
801 bundle_add(res_bundle, "result", "1");
802 appsvc_send_result(res_bundle, 0);
807 int appsvc_send_result(bundle *b, appsvc_result_val result);
811 * This API set the default application(package name) associated with op, uri and mime-type.
813 * @param[in] op operation
814 * @param[in] mime_type mime-type
815 * @param[in] scheme scheme of uri
816 * @param[in] defapp default application
818 * @retval APPSVC_RET_OK - success
819 * @retval APPSVC_RET_ERROR - general error
820 * @retval APPSVC_RET_EINVAL - invalid argument(content)
833 appsvc_set_defapp(APPSVC_OPERATION_VIEW, NULL,"http", "org.tizen.mybrowser");
838 int appsvc_set_defapp(const char *op, const char *mime_type, const char *uri,
843 * This API unset the default application(package name) associated with op, uri and mime-type.
845 * @param[in] defapp default application
847 * @retval APPSVC_RET_OK - success
848 * @retval APPSVC_RET_ERROR - general error
861 appsvc_unset_defapp("org.tizen.test");
866 int appsvc_unset_defapp(const char *defapp);
870 * This API ask a application is default application or not.
872 * @param[in] pkg_name application package name
873 * @return true / false
874 * @retval 1 app_name is default application in appsvc.
875 * @retval 0 app_name is NOT default application in appsvc.
888 * int is_defapp_browser_app()
890 * return appsvc_is_defapp("org.tizen.browser");
898 int appsvc_is_defapp(const char *appid);
903 * This API ask a extra data is array or not.
905 * @param[in] b bundle object
906 * @param[in] key key of extra data
907 * @return true / false
908 * @retval 1 a extra data is array.
909 * @retval 0 a extra data is not array.
922 * int is_defapp_browser_app(bundle *b, char *key)
924 * return appsvc_data_is_array(b, key);
932 int appsvc_data_is_array(bundle *b, const char *key);
947 #endif /* __APP_SVC_H__ */
949 /* vi: set ts=8 sts=8 sw=8: */