diff options
author | Jiwoong Im <jiwoong.im@samsung.com> | 2015-12-17 15:44:03 +0900 |
---|---|---|
committer | Jiwoong Im <jiwoong.im@samsung.com> | 2015-12-17 15:46:22 +0900 |
commit | eca37187bb8bef9f882b011ba04372759d8faca2 (patch) | |
tree | 2e07c69c02265dbf79b3631d40ba01ae04e0d893 | |
parent | 6cd7148715b2e3e28f19e3522550250bf592ce7d (diff) | |
download | application-eca37187bb8bef9f882b011ba04372759d8faca2.tar.gz application-eca37187bb8bef9f882b011ba04372759d8faca2.tar.bz2 application-eca37187bb8bef9f882b011ba04372759d8faca2.zip |
Remove source about app_servicesubmit/tizen_common/20151229.154718submit/tizen_common/20151229.144031submit/tizen_common/20151229.142028submit/tizen/20151217.080037accepted/tizen/wearable/20151218.044002accepted/tizen/tv/20151218.043952accepted/tizen/mobile/20151218.043957
Change-Id: Iaad58e366bc9d31353542c403df78b58cf17420c
Signed-off-by: Jiwoong Im <jiwoong.im@samsung.com>
-rw-r--r-- | app_common/app_package.c | 1 | ||||
-rw-r--r-- | include/app.h | 1 | ||||
-rw-r--r-- | include/app_service.h | 759 | ||||
-rw-r--r-- | include/app_service_private.h | 35 | ||||
-rw-r--r-- | src/app_device.c | 1 | ||||
-rw-r--r-- | src/app_main.c | 1 | ||||
-rw-r--r-- | src/service.c | 1025 |
7 files changed, 0 insertions, 1823 deletions
diff --git a/app_common/app_package.c b/app_common/app_package.c index f46ec35..eb8c973 100644 --- a/app_common/app_package.c +++ b/app_common/app_package.c @@ -24,7 +24,6 @@ #include <dlog.h> #include <app_internal.h> -#include <app_service_private.h> #ifdef LOG_TAG #undef LOG_TAG diff --git a/include/app.h b/include/app.h index 4c4a7bb..be26f5c 100644 --- a/include/app.h +++ b/include/app.h @@ -19,7 +19,6 @@ #define __TIZEN_APPFW_APP_H__ #include <tizen.h> -#include <app_service.h> #include <app_control.h> #include <app_alarm.h> #include <app_common.h> diff --git a/include/app_service.h b/include/app_service.h deleted file mode 100644 index fc8bab3..0000000 --- a/include/app_service.h +++ /dev/null @@ -1,759 +0,0 @@ -/* - * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved - * - * Licensed under the Apache License, Version 2.0 (the License); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an AS IS BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -#ifndef __TIZEN_APPFW_SERVICE_H__ -#define __TIZEN_APPFW_SERVICE_H__ - -#include <sys/types.h> -#include <tizen.h> - -#ifdef __cplusplus -extern "C" { -#endif - -/** - * @addtogroup CAPI_SERVICE_MODULE - * @{ - */ - - -typedef struct _bundle_t bundle; - - -/** - * @brief Service handle. - */ -typedef struct service_s *service_h; - - -/** - * @brief Enumerations of error code for Service. - */ -typedef enum -{ - SERVICE_ERROR_NONE = TIZEN_ERROR_NONE, /**< Successful */ - SERVICE_ERROR_INVALID_PARAMETER = TIZEN_ERROR_INVALID_PARAMETER, /**< Invalid parameter */ - SERVICE_ERROR_OUT_OF_MEMORY = TIZEN_ERROR_OUT_OF_MEMORY, /**< Out of memory */ - SERVICE_ERROR_APP_NOT_FOUND = TIZEN_ERROR_APPLICATION_CLASS | 0x21, /**< The application was not found */ - SERVICE_ERROR_KEY_NOT_FOUND = TIZEN_ERROR_KEY_NOT_AVAILABLE, /**< Specified key not found */ - SERVICE_ERROR_KEY_REJECTED = TIZEN_ERROR_KEY_REJECTED, /**< Not available key */ - SERVICE_ERROR_INVALID_DATA_TYPE = TIZEN_ERROR_APPLICATION_CLASS | 0x22, /**< Invalid data type */ - SERVICE_ERROR_LAUNCH_REJECTED = TIZEN_ERROR_UNKNOWN, /**< Internal launch error*/ -} service_error_e; - - -/** - * @brief Enumeration of service result. - */ -typedef enum -{ - SERVICE_RESULT_SUCCEEDED = 0, /**< Operation succeeded */ - SERVICE_RESULT_FAILED = -1, /**< Operation failed by the callee */ - SERVICE_RESULT_CANCELED = -2, /**< Operation canceled by the framework */ -} service_result_e; - - -/** - * @brief Service operation : default operation for explicit launch - */ -#define SERVICE_OPERATION_DEFAULT "http://tizen.org/appcontrol/operation/default" - - -/** - * @brief Service operation : provide explicit editable access to the given data. - */ -#define SERVICE_OPERATION_EDIT "http://tizen.org/appcontrol/operation/edit" - - -/** - * @brief Service operation : display the data. - */ -#define SERVICE_OPERATION_VIEW "http://tizen.org/appcontrol/operation/view" - - -/** - * @brief Service operation : pick an item from the data, returning what was selected. - */ -#define SERVICE_OPERATION_PICK "http://tizen.org/appcontrol/operation/pick" - - -/** - * @brief Service operation : create a content, returning what was created. - */ -#define SERVICE_OPERATION_CREATE_CONTENT "http://tizen.org/appcontrol/operation/create_content" - - -/** - * @brief Service operation : perform a call to someone specified by the data. - */ -#define SERVICE_OPERATION_CALL "http://tizen.org/appcontrol/operation/call" - - -/** - * @brief Service operation : deliver some data to someone else. - */ -#define SERVICE_OPERATION_SEND "http://tizen.org/appcontrol/operation/send" - - -/** - * @brief Service operation : deliver text data to someone else. - */ -#define SERVICE_OPERATION_SEND_TEXT "http://tizen.org/appcontrol/operation/send_text" - - -/** - * @brief Service operation : share a item to someone else. - */ -#define SERVICE_OPERATION_SHARE "http://tizen.org/appcontrol/operation/share" - - -/** - * @brief Service operation : share multiple items to someone else. - */ -#define SERVICE_OPERATION_MULTI_SHARE "http://tizen.org/appcontrol/operation/multi_share" - - -/** - * @brief Service operation : share text data to someone else. - */ -#define SERVICE_OPERATION_SHARE_TEXT "http://tizen.org/appcontrol/operation/share_text" - - -/** - * @brief Service operation : dial a number as specified by the data. - */ -#define SERVICE_OPERATION_DIAL "http://tizen.org/appcontrol/operation/dial" - - -/** - * @brief Service operation : perform a search. - */ -#define SERVICE_OPERATION_SEARCH "http://tizen.org/appcontrol/operation/search" - - -/** - * @brief Service operation : download a item. - */ -#define SERVICE_OPERATION_DOWNLOAD "http://tizen.org/appcontrol/operation/download" - - -/** - * @brief Service operation : print content. - */ -#define SERVICE_OPERATION_PRINT "http://tizen.org/appcontrol/operation/print" - -/** - * @brief Service operation : compose. - */ -#define SERVICE_OPERATION_COMPOSE "http://tizen.org/appcontrol/operation/compose" - -/** - * @brief Service optional data : the subject of a message. - */ -#define SERVICE_DATA_SUBJECT "http://tizen.org/appcontrol/data/subject" - - -/** - * @brief Service optional data : e-mail addresses. - */ -#define SERVICE_DATA_TO "http://tizen.org/appcontrol/data/to" - - -/** - * @brief Service optional data : e-mail addresses that should be carbon copied. - */ -#define SERVICE_DATA_CC "http://tizen.org/appcontrol/data/cc" - - -/** - * @brief Service optional data : e-mail addresses that should be blind carbon copied. - */ -#define SERVICE_DATA_BCC "http://tizen.org/appcontrol/data/bcc" - - -/** - * @brief Service optional data : the content of the data is associated with #SERVICE_OPERATION_SEND. - */ -#define SERVICE_DATA_TEXT "http://tizen.org/appcontrol/data/text" - - -/** - * @brief Service optional data : the title of the data - */ -#define SERVICE_DATA_TITLE "http://tizen.org/appcontrol/data/title" - - -/** - * @brief Service optional data : the path of selected item. - */ -#define SERVICE_DATA_SELECTED "http://tizen.org/appcontrol/data/selected" - - -/** - * @brief Service optional data : multiple item path to deliver. - */ -#define SERVICE_DATA_PATH "http://tizen.org/appcontrol/data/path" - - -/** - * @brief Called when the reply of the launch request is delivered. - * - * @remarks The @a request and @a reply must not be deallocated by an application. - * - * @param [in] request The service handle of the launch request that has sent - * @param [in] reply The service handle in which the results of the callee are contained - * @param [in] result The result code of the launch request - * @param [in] user_data The user data passed from the callback registration function - * @pre When the callee replies to the launch request, this callback will be invoked. - * @see service_send_launch_request() - * @see service_reply_to_launch_request() - */ -typedef void (*service_reply_cb) (service_h request, service_h reply, service_result_e result, void *user_data); - - -/** -* @brief Called to retrieve the extra data that are contained in the service -* -* @remarks The @a key must not be deallocated by an application. -* -* @param[in] service The service handle -* @param[in] key The key of the value contained in the service -* @param[in] user_data The user data passed from the foreach function -* @return @c true to continue with the next iteration of the loop, \n @c false to break out of the loop. -* @pre service_foreach_extra_data() will invoke this callback. -* @see service_foreach_extra_data() -*/ -typedef bool (*service_extra_data_cb)(service_h service, const char *key, void *user_data); - - -/** -* @brief Called once for each matched application that can be launched to handle the given service request. -* -* @param [in] service The service handle -* @param [in] package The package name of the application that can handle the launch request of the given service. -* @param [in] user_data The user data passed from the foreach function -* @return @c true to continue with the next iteration of the loop, \n @c false to break out of the loop. -* @pre service_foreach_app_matched() will invoke this callback. -* @see service_foreach_app_matched() -*/ -typedef bool (*service_app_matched_cb)(service_h service, const char *appid, void *user_data); - - -/** - * @brief Creates a service handle. - * - * @remarks The @a service must be released with service_destroy() by you. - * @param [out] service A service handle to be newly created on success - * @return 0 on success, otherwise a negative error value. - * @retval #SERVICE_ERROR_NONE Successful - * @retval #SERVICE_ERROR_INVALID_PARAMETER Invalid parameter - * @retval #SERVICE_ERROR_OUT_OF_MEMORY Out of memory - * @see service_destroy() - */ -int service_create(service_h *service); - - -/** - * @brief Destroys the service handle and releases all its resources. - * - * @param [in] service The service handle - * @return 0 on success, otherwise a negative error value. - * @retval #SERVICE_ERROR_NONE Successful - * @retval #SERVICE_ERROR_INVALID_PARAMETER Invalid parameter - * @retval #SERVICE_ERROR_OUT_OF_MEMORY Out of memory - * @see service_create() - */ -int service_destroy(service_h service); - - -/** - * @brief Converts the service handle to bundle data. - * - * @param [in] service The service handle - * @param [out] data a bundle data on success - * @return 0 on success, otherwise a negative error value. - * @retval #SERVICE_ERROR_NONE Successful - * @retval #SERVICE_ERROR_INVALID_PARAMETER Invalid parameter - */ -int service_to_bundle(service_h service, bundle **data); - -/** - * @brief Sets the operation to be performed. - * - * @details The @a operation is the mandatory information for the launch request. - * If the operation is not specified, #SERVICE_OPERATION_DEFAULT is used for the launch request. - * If the operation is #SERVICE_OPERATION_DEFAULT, the package information is mandatory to explicitly launch the application - * @param [in] service The service handle - * @param [in] operation The operation to be performed \n - * If the @a operation is NULL, it clears the previous value. - * @return 0 on success, otherwise a negative error value. - * @retval #SERVICE_ERROR_NONE Successful - * @retval #SERVICE_ERROR_INVALID_PARAMETER Invalid parameter - * @see service_get_operation() - * @see SERVICE_OPERATION_DEFAULT - * @see SERVICE_OPERATION_EDIT - * @see SERVICE_OPERATION_VIEW - * @see SERVICE_OPERATION_PICK - * @see SERVICE_OPERATION_CREATE_CONTENT - * @see SERVICE_OPERATION_CALL - * @see SERVICE_OPERATION_SEND - * @see SERVICE_OPERATION_SEND_TEXT - * @see SERVICE_OPERATION_DIAL - * @see SERVICE_OPERATION_SEARCH - */ -int service_set_operation(service_h service, const char *operation); - - -/** - * @brief Gets the operation to be performed. - * - * @remarks The @a operation must be released with free() by you. - * @param [in] service The service handle - * @param [out] operation The operation to be performed - * @return 0 on success, otherwise a negative error value. - * @retval #SERVICE_ERROR_NONE Successful - * @retval #SERVICE_ERROR_INVALID_PARAMETER Invalid parameter - * @retval #SERVICE_ERROR_OUT_OF_MEMORY Out of memory - * @see service_set_operation() - */ -int service_get_operation(service_h service, char **operation); - - -/** - * @brief Sets the URI of the data. - * - * @param [in] service The service handle - * @param [in] uri The URI of the data this service is operating on \n - * If the @a uri is NULL, it clears the previous value. - * @return 0 on success, otherwise a negative error value. - * @retval #SERVICE_ERROR_NONE Successful - * @retval #SERVICE_ERROR_INVALID_PARAMETER Invalid parameter - * @see service_get_uri() - */ -int service_set_uri(service_h service, const char *uri); - - -/** - * @brief Gets the URI of the data. - * - * @remarks The @a uri must be released with free() by you. - * @param [in] service The service handle - * @param [out] uri The URI of the data this service is operating on - * @return 0 on success, otherwise a negative error value. - * @retval #SERVICE_ERROR_NONE Successful - * @retval #SERVICE_ERROR_INVALID_PARAMETER Invalid parameter - * @retval #SERVICE_ERROR_OUT_OF_MEMORY Out of memory - * @see service_set_uri() - */ -int service_get_uri(service_h service, char **uri); - - -/** - * @brief Sets the explicit MIME type of the data - * - * @param [in] service The service handle - * @param [in] mime the explicit MIME type of the data this service is operating on \n - * If the @a mime is NULL, it clears the previous value. - * @return 0 on success, otherwise a negative error value. - * @retval #SERVICE_ERROR_NONE Successful - * @retval #SERVICE_ERROR_INVALID_PARAMETER Invalid parameter - * @see service_get_mime() - */ -int service_set_mime(service_h service, const char *mime); - - -/** - * @brief Gets the explicit MIME type of the data. - * - * @remarks The @a uri must be released with free() by you. - * @param [in] service The service handle - * @param [out] mime The explicit MIME type of the data this service is operating on - * @return 0 on success, otherwise a negative error value. - * @retval #SERVICE_ERROR_NONE Successful - * @retval #SERVICE_ERROR_INVALID_PARAMETER Invalid parameter - * @retval #SERVICE_ERROR_OUT_OF_MEMORY Out of memory - * @see service_set_mime() - */ -int service_get_mime(service_h service, char **mime); - - -/** - * @brief Sets the explicit category - * - * @param [in] service The service handle - * @param [in] category the explicit category - * If the @a category is NULL, it clears the previous value. - * @return 0 on success, otherwise a negative error value. - * @retval #SERVICE_ERROR_NONE Successful - * @retval #SERVICE_ERROR_INVALID_PARAMETER Invalid parameter - * @see service_get_category() - */ -int service_set_category(service_h service, const char *category); - - -/** - * @brief Gets the explicit category - * - * @remarks The @a category must be released with free() by you. - * @param [in] service The service handle - * @param [out] category The explicit category - * @return 0 on success, otherwise a negative error value. - * @retval #SERVICE_ERROR_NONE Successful - * @retval #SERVICE_ERROR_INVALID_PARAMETER Invalid parameter - * @retval #SERVICE_ERROR_OUT_OF_MEMORY Out of memory - * @see service_set_category() - */ -int service_get_category(service_h service, char **category); - - -/** - * @brief Sets the package name of the application to explicitly launch - * - * @remark This function is @b deprecated. Use service_set_app_id() instead. - * @param [in] service The service handle - * @param [in] package The package name of the application to explicitly launch \n - * If the @a package is NULL, it clears the previous value. - * @return 0 on success, otherwise a negative error value. - * @retval #SERVICE_ERROR_NONE Successful - * @retval #SERVICE_ERROR_INVALID_PARAMETER Invalid parameter - * @retval #SERVICE_ERROR_OUT_OF_MEMORY Out of memory - * @see service_get_package() - */ -/* Deprecated API */ -int service_set_package(service_h service, const char *package); // __attribute__((deprecated)); - - -/** - * @brief Gets the package name of the application to explicitly launch - * - * @remark This function is @b deprecated. Use service_get_app_id() instead. - * @remarks The @a package must be released with free() by you. - * @param [in] service The service handle - * @param [out] package The package name of the application to explicitly launch - * @return 0 on success, otherwise a negative error value. - * @retval #SERVICE_ERROR_NONE Successful - * @retval #SERVICE_ERROR_INVALID_PARAMETER Invalid parameter - * @retval #SERVICE_ERROR_OUT_OF_MEMORY Out of memory - * @see service_set_package() - */ -/* Deprecated API */ -int service_get_package(service_h service, char **package); // __attribute__((deprecated)); - - -/** - * @brief Sets the ID of the application to explicitly launch - * - * @param [in] service The service handle - * @param [in] app_id The ID of the application to explicitly launch \n - * If the @a app_id is NULL, it clears the previous value. - * @return 0 on success, otherwise a negative error value. - * @retval #SERVICE_ERROR_NONE Successful - * @retval #SERVICE_ERROR_INVALID_PARAMETER Invalid parameter - * @retval #SERVICE_ERROR_OUT_OF_MEMORY Out of memory - * @see service_get_app_id() - */ -int service_set_app_id(service_h service, const char *app_id); - - -/** - * @brief Gets the ID of the application to explicitly launch - * - * @remarks The @a app_id must be released with free() by you. - * @param [in] service The service handle - * @param [out] app_id The ID of the application to explicitly launch - * @return 0 on success, otherwise a negative error value. - * @retval #SERVICE_ERROR_NONE Successful - * @retval #SERVICE_ERROR_INVALID_PARAMETER Invalid parameter - * @retval #SERVICE_ERROR_OUT_OF_MEMORY Out of memory - * @see service_set_app_id() - */ -int service_get_app_id(service_h service, char **app_id); - -/** - * @brief Sets the window id of the application - * - * @param [in] service The service handle - * @param [in] id the window id of caller application \n - * If the @a id is not positive, it clears the previous value. - * @return 0 on success, otherwise a negative error value. - * @retval #SERVICE_ERROR_NONE Successful - * @retval #SERVICE_ERROR_INVALID_PARAMETER Invalid parameter - * @retval #SERVICE_ERROR_OUT_OF_MEMORY Out of memory - * @see service_get_window() - */ -int service_set_window(service_h service, unsigned int id); - - -/** -* @brief Gets the window id of the application -* -* @param [in] service The service handle -* @param [out] id The window id of caller application -* @return 0 on success, otherwise a negative error value. -* @retval #SERVICE_ERROR_NONE Successful -* @retval #SERVICE_ERROR_INVALID_PARAMETER Invalid parameter -* @retval #SERVICE_ERROR_OUT_OF_MEMORY Out of memory -* @see service_set_app_id() -*/ -int service_get_window(service_h service, unsigned int *id); - - -/** - * @brief Adds the extra data to the service. - * - * @remarks The function replaces any existing value for the given key. - * @remarks The function returns #SERVICE_ERROR_INVALID_PARAMETER if key or value is zero-length string. - * @remarks The function returns #SERVICE_ERROR_KEY_REJECTED if the application tries to use same key with system-defined key - * @param [in] service The service handle - * @param [in] key The name of the extra data - * @param [in] value The value associated with given key - * @return 0 on success, otherwise a negative error value. - * @retval #SERVICE_ERROR_NONE Successful - * @retval #SERVICE_ERROR_INVALID_PARAMETER Invalid parameter - * @retval #SERVICE_ERROR_KEY_REJECTED Not available key - * @see service_add_extra_data_array() - * @see service_remove_extra_data() - * @see service_get_extra_data() - */ -int service_add_extra_data(service_h service, const char *key, const char *value); - - -/** - * @brief Adds the extra data array to the service. - * - * @remarks The function replaces any existing value for the given key. - * @remarks The function returns #SERVICE_ERROR_INVALID_PARAMETER if key is zero-length string. - * @remarks The function returns #SERVICE_ERROR_KEY_REJECTED if the application tries to use same key with system-defined key - * @param [in] service The service handle - * @param [in] key The name of the extra data - * @param [in] value The array value associated with given key - * @param [in] length The length of the array - * @return 0 on success, otherwise a negative error value. - * @retval #SERVICE_ERROR_NONE Successful - * @retval #SERVICE_ERROR_INVALID_PARAMETER Invalid parameter - * @retval #SERVICE_ERROR_KEY_REJECTED Not available key - * @see service_add_extra_data() - * @see service_remove_extra_data() - * @see service_get_extra_data() - */ -int service_add_extra_data_array(service_h service, const char *key, const char* value[], int length); - - -/** - * @brief Removes the extra data from the service. - * - * @param [in] service The service handle - * @param [in] key The name of the extra data - * @return 0 on success, otherwise a negative error value. - * @retval #SERVICE_ERROR_NONE Successful - * @retval #SERVICE_ERROR_INVALID_PARAMETER Invalid parameter - * @retval #SERVICE_ERROR_KEY_NOT_FOUND Specified key not found - * @see service_add_extra_data() - * @see service_add_extra_data_array() - * @see service_get_extra_data() - */ -int service_remove_extra_data(service_h service, const char *key); - - -/** - * @brief Gets the extra data from the service. - * - * @remarks The @a value must be released with free() by you. - * @remarks The function returns #SERVICE_ERROR_INVALID_DATA_TYPE if the value is array data type. - * @param [in] service The service handle - * @param [int] key The name of the extra data - * @param [out] value The value associated with given key - * @return 0 on success, otherwise a negative error value. - * @retval #SERVICE_ERROR_NONE Successful - * @retval #SERVICE_ERROR_INVALID_PARAMETER Invalid parameter - * @retval #SERVICE_ERROR_KEY_NOT_FOUND Specified key not found - * @retval #SERVICE_ERROR_OUT_OF_MEMORY Out of memory - * @retval #SERVICE_ERROR_INVALID_DATA_TYPE Invalid data type - * @see service_add_extra_data() - * @see service_add_extra_data_array() - * @see service_get_extra_data() - * @see service_remove_extra_data() - * @see service_foreach_extra_data() - */ -int service_get_extra_data(service_h service, const char *key, char **value); - - -/** - * @brief Gets the extra data array from the service. - * - * @remarks The @a value must be released with free() by you. - * @remarks The function returns #SERVICE_ERROR_INVALID_DATA_TYPE if the value is not array data type. - * @param [in] service The service handle - * @param [int] key The name of the extra data - * @param [out] value The array value associated with given key - * @param [out] length The length of the array - * @return 0 on success, otherwise a negative error value. - * @retval #SERVICE_ERROR_NONE Successful - * @retval #SERVICE_ERROR_INVALID_PARAMETER Invalid parameter - * @retval #SERVICE_ERROR_KEY_NOT_FOUND Specified key not found - * @retval #SERVICE_ERROR_OUT_OF_MEMORY Out of memory - * @retval #SERVICE_ERROR_INVALID_DATA_TYPE Invalid data type - * @see service_add_extra_data() - * @see service_add_extra_data_array() - * @see service_remove_extra_data() - * @see service_foreach_extra_data() - */ -int service_get_extra_data_array(service_h service, const char *key, char ***value, int *length); - - -/** - * @brief Checks whether if the extra data associated with given @a key is array data type. - * - * @param [in] service The service handle - * @param [int] key The name of the extra data - * @param [out] array @c True if the extra data is array data type, otherwise @c false - * @return 0 on success, otherwise a negative error value. - * @retval #SERVICE_ERROR_NONE Successful - * @retval #SERVICE_ERROR_INVALID_PARAMETER Invalid parameter - * @see service_add_extra_data() - * @see service_add_extra_data_array() - * @see service_remove_extra_data() - * @see service_foreach_extra_data() - */ -int service_is_extra_data_array(service_h service, const char *key, bool *array); - - -/** - * @brief Retrieves all extra data contained in service. - * @details This function calls service_extra_data_cb() once for each key-value pair for extra data contained in service. \n - * If service_extra_data_cb() callback function returns false, then iteration will be finished. - * - * @param [in] service The service handle - * @param [in] callback The iteration callback function - * @param [in] user_data The user data to be passed to the callback function - * @return 0 on success, otherwise a negative error value. - * @retval #SERVICE_ERROR_NONE Successful - * @retval #SERVICE_ERROR_INVALID_PARAMETER Invalid parameter - * @post This function invokes service_extra_data_cb(). - * @see service_extra_data_cb() - */ -int service_foreach_extra_data(service_h service, service_extra_data_cb callback, void *user_data); - - -/** - * @brief Retrieves all applications that can be launched to handle the given service request. - * - * @param [in] service The service handle - * @param [in] callback The iteration callback function - * @param [in] user_data The user data to be passed to the callback function - * @return 0 on success, otherwise a negative error value. - * @retval #SERVICE_ERROR_NONE Success - * @retval #SERVICE_ERROR_INVALID_PARAMETER Invalid parameter - * @post This function invokes service_app_matched_cb(). - * @see service_app_matched_cb() - */ -int service_foreach_app_matched(service_h service, service_app_matched_cb callback, void *user_data); - - -/** - * @brief Sends the launch request. - * - * @details The operation is mandatory information for the launch request. \n - * If the operation is not specified, #SERVICE_OPERATION_DEFAULT is used by default. - * If the operation is #SERVICE_OPERATION_DEFAULT, the application ID is mandatory to explicitly launch the application - * @param [in] service The service handle - * @param [in] callback The callback function to be called when the reply is delivered - * @param [in] user_data The user data to be passed to the callback function - * @return 0 on success, otherwise a negative error value. - * @retval #SERVICE_ERROR_NONE Successful - * @retval #SERVICE_ERROR_INVALID_PARAMETER Invalid parameter - * @retval #SERVICE_ERROR_OUT_OF_MEMORY Out of memory - * @retval #SERVICE_ERROR_APP_NOT_FOUND The application was not found to run the given launch request - * @retval #SERVICE_ERROR_LAUNCH_REJECTED The application launch is rejected due to timeout, continuous launch request while launching and application hang - * @post If the launch request is sent for the result, the result will come back through service_reply_cb() from the callee application - * @see service_reply_to_launch_request() - * @see service_reply_cb() - */ -int service_send_launch_request(service_h service, service_reply_cb callback, void *user_data); - - -/** - * @brief Replies to the launch request that the caller sent - * @details If the caller application sent the launch request to receive the result, the callee application can return the result back to the caller. - * - * @param [in] reply The service handle in which the results of the callee are contained - * @param [in] request The service handle that the caller sent - * @param [in] result The result code of the launch request - * @return 0 on success, otherwise a negative error value. - * @retval #SERVICE_ERROR_NONE Successful - * @retval #SERVICE_ERROR_INVALID_PARAMETER Invalid parameter - * @retval #SERVICE_ERROR_OUT_OF_MEMORY Out of memory - * @see service_send_launch_request() - */ -int service_reply_to_launch_request(service_h reply, service_h request, service_result_e result); - - -/** - * @brief Creates and returns a copy of the given service handle. - * - * @remarks A newly created service should be destroyed by calling service_destroy() if it is no longer needed. - * - * @param [out] clone If successful, a newly created service handle will be returned. - * @param [in] service The service handle - * @return 0 on success, otherwise a negative error value. - * @retval #SERVICE_ERROR_NONE Successful - * @retval #SERVICE_ERROR_INVALID_PARAMETER Invalid parameter - * @retval #SERVICE_ERROR_OUT_OF_MEMORY Out of memory - * @see service_destroy() - */ -int service_clone(service_h *clone, service_h service); - - -/** - * @brief Gets the application ID of the caller from the launch request - * - * @remarks The @a service must be the launch reqeust from app_service_cb(). - * @remarks This function returns #SERVICE_ERROR_INVALID_PARAMETER if the given service is not the launch request. - * @remarks The @a id must be released with free() by you. - * @param [in] service The service handle from app_service_cb() - * @param [out] id The application ID of the caller - * @return 0 on success, otherwise a negative error value. - * @retval #SERVICE_ERROR_NONE Successful - * @retval #SERVICE_ERROR_INVALID_PARAMETER Invalid parameter - * @retval #SERVICE_ERROR_OUT_OF_MEMORY Out of memory - */ -int service_get_caller(service_h service, char **id); - - -/** - * @brief Check whether the caller is requesting a reply from the launch reqeust - * - * @remarks The @a service must be the launch reqeust from app_service_cb(). - * @remarks This function returns #SERVICE_ERROR_INVALID_PARAMETER if the given service is not the launch request. - * @param [in] service The service handle from app_service_cb() - * @param [out] requested whether a reply is requested by the caller - * @return 0 on success, otherwise a negative error value. - * @retval #SERVICE_ERROR_NONE Successful - * @retval #SERVICE_ERROR_INVALID_PARAMETER Invalid parameter - * @retval #SERVICE_ERROR_OUT_OF_MEMORY Out of memory - */ -int service_is_reply_requested(service_h service, bool *requested); - -/** - * @} - */ - -#ifdef __cplusplus -} -#endif - -#endif /* __TIZEN_APPFW_SERVICE_H__ */ diff --git a/include/app_service_private.h b/include/app_service_private.h deleted file mode 100644 index f5a4963..0000000 --- a/include/app_service_private.h +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved - * - * Licensed under the Apache License, Version 2.0 (the License); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an AS IS BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -#ifndef __TIZEN_APPFW_SERVICE_PRIVATE_H__ -#define __TIZEN_APPFW_SERVICE_PRIVATE_H__ - -#include <bundle.h> - -#ifdef __cplusplus -extern "C" { -#endif - -int service_create_request(bundle *data, service_h *service); - -int service_create_event(bundle *data, service_h *service); - -#ifdef __cplusplus -} -#endif - -#endif /* __TIZEN_APPFW_SERVICE_PRIVATE_H__ */ diff --git a/src/app_device.c b/src/app_device.c index bc8c264..4aba0ac 100644 --- a/src/app_device.c +++ b/src/app_device.c @@ -30,7 +30,6 @@ #include <vconf.h> #include <app_internal.h> -#include <app_service_private.h> #ifdef LOG_TAG #undef LOG_TAG diff --git a/src/app_main.c b/src/app_main.c index 4c48d34..bd0594e 100644 --- a/src/app_main.c +++ b/src/app_main.c @@ -31,7 +31,6 @@ #include <Elementary.h> #include <app_internal.h> -#include <app_service_private.h> #include <app_control_internal.h> #ifdef LOG_TAG diff --git a/src/service.c b/src/service.c deleted file mode 100644 index adba675..0000000 --- a/src/service.c +++ /dev/null @@ -1,1025 +0,0 @@ -/* - * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved - * - * Licensed under the Apache License, Version 2.0 (the License); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an AS IS BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -#include <stdio.h> -#include <stdlib.h> -#include <unistd.h> -#include <string.h> -#include <errno.h> - -#include <bundle.h> -#include <bundle_internal.h> -#include <aul.h> -#include <appsvc.h> -#include <dlog.h> - -#include <app_service.h> -#include <app_service_private.h> - -#ifdef LOG_TAG -#undef LOG_TAG -#endif - -#define LOG_TAG "CAPI_APPFW_APPLICATION_SERVICE" - -#ifndef TIZEN_PATH_MAX -#define TIZEN_PATH_MAX 1024 -#endif - -#define BUNDLE_KEY_PREFIX_AUL "__AUL_" -#define BUNDLE_KEY_PREFIX_SERVICE "__APP_SVC_" - -#define BUNDLE_KEY_OPERATION "__APP_SVC_OP_TYPE__" -#define BUNDLE_KEY_URI "__APP_SVC_URI__" -#define BUNDLE_KEY_MIME "__APP_SVC_MIME_TYPE__" -#define BUNDLE_KEY_DATA "__APP_SVC_DATA__" -#define BUNDLE_KEY_PACKAGE "__APP_SVC_PKG_NAME__" -#define BUNDLE_KEY_WINDOW "__APP_SVC_K_WIN_ID__" - - -typedef enum { - SERVICE_TYPE_REQUEST, - SERVICE_TYPE_EVENT, - SERVICE_TYPE_REPLY, -} service_type_e; - -struct service_s { - int id; - service_type_e type; - bundle *data; - int launch_pid; -}; - -typedef struct service_request_context_s { - service_h service; - service_reply_cb reply_cb; - void *user_data; -} *service_request_context_h; - -extern int appsvc_allow_transient_app(bundle *b, unsigned int id); - -static int service_create_reply(bundle *data, struct service_s **service); - -static const char* service_error_to_string(service_error_e error) -{ - switch (error) { - case SERVICE_ERROR_NONE: - return "NONE"; - - case SERVICE_ERROR_INVALID_PARAMETER: - return "INVALID_PARAMETER"; - - case SERVICE_ERROR_OUT_OF_MEMORY: - return "OUT_OF_MEMORY"; - - case SERVICE_ERROR_APP_NOT_FOUND: - return "APP_NOT_FOUND"; - - case SERVICE_ERROR_KEY_NOT_FOUND: - return "KEY_NOT_FOUND"; - - case SERVICE_ERROR_KEY_REJECTED: - return "KEY_REJECTED"; - - case SERVICE_ERROR_INVALID_DATA_TYPE: - return "INVALID_DATA_TYPE"; - - case SERVICE_ERROR_LAUNCH_REJECTED: - return "LAUNCH_REJECTED"; - - default: - return "UNKNOWN"; - } -} - -int service_error(service_error_e error, const char* function, const char *description) -{ - if (description) - LOGE("[%s] %s(0x%08x) : %s", function, service_error_to_string(error), error, description); - else - LOGE("[%s] %s(0x%08x)", function, service_error_to_string(error), error); - - return error; -} - -static int service_validate_extra_data(const char *data) -{ - if (data == NULL || data[0] == '\0') - return SERVICE_ERROR_INVALID_PARAMETER; - - return SERVICE_ERROR_NONE; -} - -static int service_valiate_service(service_h service) -{ - if (service == NULL || service->data == NULL) - return SERVICE_ERROR_INVALID_PARAMETER; - - return SERVICE_ERROR_NONE; -} - -static int service_new_id() -{ - static int sid = 0; - return sid++; -} - -int service_validate_internal_key(const char *key) -{ - if (strncmp(BUNDLE_KEY_PREFIX_AUL, key, strlen(BUNDLE_KEY_PREFIX_AUL)) == 0) - return -1; - - if (strncmp(BUNDLE_KEY_PREFIX_SERVICE, key, strlen(BUNDLE_KEY_PREFIX_SERVICE)) == 0) - return -1; - - return 0; -} - -static void service_request_result_broker(bundle *appsvc_bundle, int appsvc_request_code, appsvc_result_val appsvc_result, void *appsvc_data) -{ - service_request_context_h request_context; - service_h request; - service_h reply = NULL; - service_result_e result; - void *user_data; - service_reply_cb reply_cb; - - if (appsvc_data == NULL) { - service_error(SERVICE_ERROR_INVALID_PARAMETER, __FUNCTION__, "invalid service reply"); - return; - } - - if (service_create_reply(appsvc_bundle, &reply) != 0) { - service_error(SERVICE_ERROR_INVALID_PARAMETER, __FUNCTION__, "failed to create service reply"); - return; - } - - request_context = appsvc_data; - request = request_context->service; - - switch (appsvc_result) { - case APPSVC_RES_OK: - result = SERVICE_RESULT_SUCCEEDED; - break; - - case APPSVC_RES_NOT_OK: - result = SERVICE_RESULT_FAILED; - break; - - case APPSVC_RES_CANCEL: - result = SERVICE_RESULT_CANCELED; - break; - - default: - result = SERVICE_RESULT_CANCELED; - break; - } - - user_data = request_context->user_data; - reply_cb = request_context->reply_cb; - - if (reply_cb != NULL) - reply_cb(request, reply, result, user_data); - else - service_error(SERVICE_ERROR_INVALID_PARAMETER, __FUNCTION__, "invalid callback "); - - service_destroy(reply); - - if (request_context->service != NULL) - service_destroy(request_context->service); - - free(request_context); -} - - -int service_create(service_h *service) -{ - return service_create_request(NULL, service); -} - -int service_create_request(bundle *data, service_h *service) -{ - struct service_s *service_request; - - if (service == NULL) - return service_error(SERVICE_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL); - - service_request = malloc(sizeof(struct service_s)); - - if (service_request == NULL) - return service_error(SERVICE_ERROR_OUT_OF_MEMORY, __FUNCTION__, "failed to create a service handle"); - - service_request->type = SERVICE_TYPE_REQUEST; - - if (data != NULL) - service_request->data = bundle_dup(data); - else - service_request->data = bundle_create(); - - if (service_request->data == NULL) { - free(service_request); - return service_error(SERVICE_ERROR_OUT_OF_MEMORY, __FUNCTION__, "failed to create a bundle"); - } - - service_request->id = service_new_id(); - service_request->launch_pid = -1; - - *service = service_request; - - return SERVICE_ERROR_NONE; -} - -int service_create_event(bundle *data, struct service_s **service) -{ - struct service_s *service_event; - - const char *operation; - - if (data == NULL || service == NULL) - return service_error(SERVICE_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL); - - service_event = malloc(sizeof(struct service_s)); - - if (service_event == NULL) - return service_error(SERVICE_ERROR_OUT_OF_MEMORY, __FUNCTION__, "failed to create a service handle"); - - service_event->type = SERVICE_TYPE_EVENT; - service_event->data = bundle_dup(data); - service_event->id = service_new_id(); - - operation = appsvc_get_operation(service_event->data); - - if (operation == NULL) - appsvc_set_operation(service_event->data, SERVICE_OPERATION_DEFAULT); - - *service = service_event; - - return SERVICE_ERROR_NONE; -} - -static int service_create_reply(bundle *data, struct service_s **service) -{ - struct service_s *service_reply; - - if (data == NULL || service == NULL) - return service_error(SERVICE_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL); - - service_reply = malloc(sizeof(struct service_s)); - - if (service_reply == NULL) - return service_error(SERVICE_ERROR_OUT_OF_MEMORY, __FUNCTION__, "failed to create a service handle"); - - service_reply->type = SERVICE_TYPE_REPLY; - service_reply->data = bundle_dup(data); - service_reply->id = service_new_id(); - - *service = service_reply; - - return SERVICE_ERROR_NONE; -} - -int service_destroy(service_h service) -{ - if (service_valiate_service(service)) - return service_error(SERVICE_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL); - - bundle_free(service->data); - service->data = NULL; - free(service); - - return SERVICE_ERROR_NONE; -} - -int service_to_bundle(service_h service, bundle **data) -{ - if (service_valiate_service(service) || data == NULL) - return service_error(SERVICE_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL); - - *data = service->data; - - return SERVICE_ERROR_NONE; -} - -int service_set_operation(service_h service, const char *operation) -{ - if (service_valiate_service(service)) - return service_error(SERVICE_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL); - - if (operation != NULL) { - if (appsvc_set_operation(service->data, operation) != 0) - return service_error(SERVICE_ERROR_INVALID_PARAMETER, __FUNCTION__, "invalid operation"); - } else { - bundle_del(service->data, BUNDLE_KEY_OPERATION); - } - - return SERVICE_ERROR_NONE; -} - -int service_get_operation(service_h service, char **operation) -{ - const char *operation_value; - - if (service_valiate_service(service) || operation == NULL) - return service_error(SERVICE_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL); - - operation_value = appsvc_get_operation(service->data); - - if (operation_value != NULL) - *operation = strdup(operation_value); - else - *operation = NULL; - - return SERVICE_ERROR_NONE; -} - - -int service_set_uri(service_h service, const char *uri) -{ - if (service_valiate_service(service)) - return service_error(SERVICE_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL); - - if (uri != NULL) { - if (appsvc_set_uri(service->data, uri) != 0) - return service_error(SERVICE_ERROR_INVALID_PARAMETER, __FUNCTION__, "invalid URI"); - } else { - bundle_del(service->data, BUNDLE_KEY_URI); - } - - return SERVICE_ERROR_NONE; -} - - -int service_get_uri(service_h service, char **uri) -{ - const char *uri_value; - - if (service_valiate_service(service) || uri == NULL) - return service_error(SERVICE_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL); - - uri_value = appsvc_get_uri(service->data); - - if (uri_value != NULL) - *uri = strdup(uri_value); - else - *uri = NULL; - - return SERVICE_ERROR_NONE; -} - - -int service_set_mime(service_h service, const char *mime) -{ - if (service_valiate_service(service)) - return service_error(SERVICE_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL); - - if (mime != NULL) { - if (appsvc_set_mime(service->data, mime) != 0) - return service_error(SERVICE_ERROR_INVALID_PARAMETER, __FUNCTION__, "invalid MIME type"); - } else { - bundle_del(service->data, BUNDLE_KEY_MIME); - } - - return SERVICE_ERROR_NONE; -} - - -int service_get_mime(service_h service, char **mime) -{ - const char *mime_value; - - if (service_valiate_service(service) || mime == NULL) - return service_error(SERVICE_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL); - - mime_value = appsvc_get_mime(service->data); - - if (mime_value != NULL) - *mime = strdup(mime_value); - else - *mime = NULL; - - return SERVICE_ERROR_NONE; -} - - -int service_set_category(service_h service, const char *category) -{ - if (service_valiate_service(service)) - return service_error(SERVICE_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL); - - if (category != NULL) { - if (appsvc_set_category(service->data, category) != 0) - return service_error(SERVICE_ERROR_INVALID_PARAMETER, __FUNCTION__, "invalid MIME type"); - } else { - bundle_del(service->data, BUNDLE_KEY_MIME); - } - - return SERVICE_ERROR_NONE; -} - - -int service_get_category(service_h service, char **category) -{ - const char *category_value; - - if (service_valiate_service(service) || category == NULL) - return service_error(SERVICE_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL); - - category_value = appsvc_get_category(service->data); - - if (category_value != NULL) - *category = strdup(category_value); - else - *category = NULL; - - return SERVICE_ERROR_NONE; -} - - -int service_set_package(service_h service, const char *package) -{ - /* - * TODO: this function must be deprecated - */ - return service_set_app_id(service, package); -} - -int service_get_package(service_h service, char **package) -{ - /* - * TODO: this function must be deprecated - */ - return service_get_app_id(service, package); -} - - -int service_set_app_id(service_h service, const char *app_id) -{ - if (service_valiate_service(service)) - return service_error(SERVICE_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL); - - if (app_id != NULL) { - if (appsvc_set_appid(service->data, app_id) != 0) - return service_error(SERVICE_ERROR_INVALID_PARAMETER, __FUNCTION__, "invalid application ID"); - } else { - bundle_del(service->data, BUNDLE_KEY_PACKAGE); - } - - return SERVICE_ERROR_NONE; -} - - -int service_get_app_id(service_h service, char **app_id) -{ - const char *app_id_value; - - if (service_valiate_service(service) || app_id == NULL) - return service_error(SERVICE_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL); - - app_id_value = appsvc_get_appid(service->data); - - if (app_id_value != NULL) - *app_id = strdup(app_id_value); - else - *app_id = NULL; - - return SERVICE_ERROR_NONE; -} - -int service_set_window(service_h service, unsigned int id) -{ - if (service_valiate_service(service)) - return service_error(SERVICE_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL); - - if (id > 0) { - if (appsvc_allow_transient_app(service->data, id) != 0) - return service_error(SERVICE_ERROR_INVALID_PARAMETER, __FUNCTION__, "invalid id"); - } else { - bundle_del(service->data, BUNDLE_KEY_WINDOW); - } - - return SERVICE_ERROR_NONE; -} - -int service_get_window(service_h service, unsigned int *id) -{ - const char *window_id; - - if (service_valiate_service(service) || id == NULL) - return service_error(SERVICE_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL); - - window_id = bundle_get_val(service->data, BUNDLE_KEY_WINDOW); - - if (window_id != NULL) - *id = atoi(window_id); - else - *id = 0; - - return SERVICE_ERROR_NONE; -} - -int service_clone(service_h *clone, service_h service) -{ - service_h service_clone; - - if (service_valiate_service(service) || clone == NULL) - return service_error(SERVICE_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL); - - service_clone = malloc(sizeof(struct service_s)); - - if (service_clone == NULL) - return service_error(SERVICE_ERROR_OUT_OF_MEMORY, __FUNCTION__, "failed to create a service handle"); - - service_clone->id = service_new_id(); - service_clone->type = service->type; - service_clone->data = bundle_dup(service->data); - - *clone = service_clone; - - return SERVICE_ERROR_NONE; -} - - -int service_send_launch_request(service_h service, service_reply_cb callback, void *user_data) -{ - const char *operation; - const char *appid; - - bool implicit_default_operation = false; - int launch_pid; - - service_request_context_h request_context = NULL; - - if (service_valiate_service(service)) - return service_error(SERVICE_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL); - - operation = appsvc_get_operation(service->data); - - if (operation == NULL) { - implicit_default_operation = true; - operation = SERVICE_OPERATION_DEFAULT; - } - - appid = appsvc_get_appid(service->data); - - if (!strcmp(operation, SERVICE_OPERATION_DEFAULT)) { - if (appid == NULL) - return service_error(SERVICE_ERROR_APP_NOT_FOUND, __FUNCTION__, "package must be specified if the operation is default value"); - } - - if (callback != NULL) { - service_h request_clone = NULL; - - request_context = calloc(1, sizeof(struct service_request_context_s)); - - if (request_context == NULL) - return service_error(SERVICE_ERROR_OUT_OF_MEMORY, __FUNCTION__, NULL); - - request_context->reply_cb = callback; - - if (service_clone(&request_clone, service) != SERVICE_ERROR_NONE) { - free(request_context); - return service_error(SERVICE_ERROR_INVALID_PARAMETER, __FUNCTION__, "failed to clone the service request handle"); - } - - request_context->service = request_clone; - request_context->user_data = user_data; - } - - if (implicit_default_operation == true) - appsvc_set_operation(service->data, SERVICE_OPERATION_DEFAULT); - - launch_pid = appsvc_usr_run_service(service->data, service->id, callback ? service_request_result_broker : NULL, request_context, getuid()); - - if (implicit_default_operation == true) - bundle_del(service->data, BUNDLE_KEY_OPERATION); - - if (launch_pid < 0) { - if (launch_pid == APPSVC_RET_ENOMATCH) - return service_error(SERVICE_ERROR_APP_NOT_FOUND, __FUNCTION__, NULL); - else - return service_error(SERVICE_ERROR_LAUNCH_REJECTED, __FUNCTION__, NULL); - } - - service->launch_pid = launch_pid; - - return SERVICE_ERROR_NONE; -} - - -int service_send_terminate_request(service_h service) -{ - if (service_valiate_service(service)) - return service_error(SERVICE_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL); - - if (service->type != SERVICE_TYPE_REQUEST || service->launch_pid < 0) - return service_error(SERVICE_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL); - - appsvc_subapp_terminate_request_pid(service->launch_pid); - - return SERVICE_ERROR_NONE; -} - -static bool service_copy_reply_data_cb(service_h service, const char *key, void *user_data) -{ - bundle *reply_data = user_data; - char *value = NULL; - char **value_array = NULL; - int value_array_length = 0; - int value_array_index = 0; - - if (reply_data == NULL) { - service_error(SERVICE_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL); - return false; - } - - if (appsvc_data_is_array(service->data, key)) { - service_get_extra_data_array(service, key, &value_array, &value_array_length); - appsvc_add_data_array(reply_data, key, (const char**)value_array, value_array_length); - - for (value_array_index = 0; value_array_index < value_array_length; value_array_index++) - free(value_array[value_array_index]); - free(value_array); - } else { - service_get_extra_data(service, key, &value); - appsvc_add_data(reply_data, key, value); - free(value); - } - - return true; -} - -int service_reply_to_launch_request(service_h reply, service_h request, service_result_e result) -{ - bundle *reply_data; - int appsvc_result; - - if (service_valiate_service(reply) || service_valiate_service(request)) - return service_error(SERVICE_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL); - - if (appsvc_create_result_bundle(request->data, &reply_data) != 0) - return service_error(SERVICE_ERROR_INVALID_PARAMETER, __FUNCTION__, "failed to create a result bundle"); - - service_foreach_extra_data(reply, service_copy_reply_data_cb, reply_data); - - switch (result) { - case SERVICE_RESULT_SUCCEEDED: - appsvc_result = APPSVC_RES_OK; - break; - - case SERVICE_RESULT_FAILED: - appsvc_result = APPSVC_RES_NOT_OK; - break; - - case SERVICE_RESULT_CANCELED: - appsvc_result = APPSVC_RES_CANCEL; - break; - - default: - appsvc_result = APPSVC_RES_CANCEL; - break; - } - - appsvc_send_result(reply_data, appsvc_result); - - return SERVICE_ERROR_NONE; -} - - -int service_add_extra_data(service_h service, const char *key, const char *value) -{ - if (service_valiate_service(service) || service_validate_extra_data(key) || service_validate_extra_data(value)) - return service_error(SERVICE_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL); - - if (service_validate_internal_key(key)) - return service_error(SERVICE_ERROR_KEY_REJECTED, __FUNCTION__, "the given key is reserved as internal use"); - - if (appsvc_get_data(service->data, key) != NULL) - bundle_del(service->data, key); - - if (appsvc_add_data(service->data, key, value) != 0) - return service_error(SERVICE_ERROR_KEY_REJECTED, __FUNCTION__, "failed to add data to the appsvc handle"); - - return SERVICE_ERROR_NONE; -} - - -int service_add_extra_data_array(service_h service, const char *key, const char* value[], int length) -{ - if (service_valiate_service(service) || service_validate_extra_data(key)) - return service_error(SERVICE_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL); - - if (value == NULL || length <= 0) - return service_error(SERVICE_ERROR_INVALID_PARAMETER, __FUNCTION__, "invalid array"); - - if (service_validate_internal_key(key)) - return service_error(SERVICE_ERROR_KEY_REJECTED, __FUNCTION__, "the given key is reserved as internal use"); - - if (appsvc_get_data_array(service->data, key, NULL) != NULL) - bundle_del(service->data, key); - - if (appsvc_add_data_array(service->data, key, value, length) != 0) - return service_error(SERVICE_ERROR_KEY_REJECTED, __FUNCTION__, "failed to add array data to the appsvc handle"); - - return SERVICE_ERROR_NONE; -} - - -int service_remove_extra_data(service_h service, const char *key) -{ - if (service_valiate_service(service) || service_validate_extra_data(key)) - return service_error(SERVICE_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL); - - if (service_validate_internal_key(key)) - return service_error(SERVICE_ERROR_KEY_REJECTED, __FUNCTION__, "the given key is reserved as internal use"); - - if (bundle_del(service->data, key)) - return service_error(SERVICE_ERROR_KEY_NOT_FOUND, __FUNCTION__, NULL); - - return SERVICE_ERROR_NONE; -} - - -int service_get_extra_data(service_h service, const char *key, char **value) -{ - const char *data_value; - - if (service_valiate_service(service) || service_validate_extra_data(key) || value == NULL) - return service_error(SERVICE_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL); - - - if (service_validate_internal_key(key)) - return service_error(SERVICE_ERROR_KEY_REJECTED, __FUNCTION__, "the given key is reserved as internal use"); - - data_value = appsvc_get_data(service->data, key); - - if (data_value == NULL) { - if (errno == ENOTSUP) - return service_error(SERVICE_ERROR_INVALID_DATA_TYPE, __FUNCTION__, NULL); - else - return service_error(SERVICE_ERROR_KEY_NOT_FOUND, __FUNCTION__, NULL); - } - - *value = strdup(data_value); - - return SERVICE_ERROR_NONE; -} - - -int service_get_extra_data_array(service_h service, const char *key, char ***value, int *length) -{ - const char **array_data; - int array_data_length; - char **array_data_clone; - int i; - - if (service_valiate_service(service) || service_validate_extra_data(key)) - return service_error(SERVICE_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL); - - if (value == NULL || length == 0) - return service_error(SERVICE_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL); - - if (service_validate_internal_key(key)) - return service_error(SERVICE_ERROR_KEY_REJECTED, __FUNCTION__, "the given key is reserved as internal use"); - - array_data = appsvc_get_data_array(service->data, key, &array_data_length); - - if (array_data == NULL) { - if (errno == ENOTSUP) - return service_error(SERVICE_ERROR_INVALID_DATA_TYPE, __FUNCTION__, NULL); - else - return service_error(SERVICE_ERROR_KEY_NOT_FOUND, __FUNCTION__, NULL); - } - - array_data_clone = calloc(array_data_length, sizeof(char*)); - - if (array_data_clone == NULL) - return service_error(SERVICE_ERROR_OUT_OF_MEMORY, __FUNCTION__, NULL); - - for (i = 0; i < array_data_length; i++) { - if (array_data[i] != NULL) - array_data_clone[i] = strdup(array_data[i]); - } - - *value = array_data_clone; - *length = array_data_length; - - return SERVICE_ERROR_NONE; -} - - -int service_is_extra_data_array(service_h service, const char *key, bool *array) -{ - if (service_valiate_service(service) || service_validate_extra_data(key) || array == NULL) - return service_error(SERVICE_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL); - - if (service_validate_internal_key(key)) - return service_error(SERVICE_ERROR_KEY_REJECTED, __FUNCTION__, "the given key is reserved as internal use"); - - if (!appsvc_data_is_array(service->data, key)) - *array = false; - else - *array = true; - - return SERVICE_ERROR_NONE; -} - - -typedef struct { - service_h service; - service_extra_data_cb callback; - void* user_data; - bool foreach_break; -} foreach_context_extra_data_t; - -static void service_cb_broker_bundle_iterator(const char *key, const int type, const bundle_keyval_t *kv, void *user_data) -{ - foreach_context_extra_data_t* foreach_context = NULL; - service_extra_data_cb extra_data_cb; - - if (key == NULL || !(type == BUNDLE_TYPE_STR || type == BUNDLE_TYPE_STR_ARRAY)) - return; - - foreach_context = (foreach_context_extra_data_t*)user_data; - - if (foreach_context->foreach_break == true) - return; - - if (service_validate_internal_key(key)) - return; - - extra_data_cb = foreach_context->callback; - - if (extra_data_cb != NULL) { - bool stop_foreach = false; - stop_foreach = !extra_data_cb(foreach_context->service, key, foreach_context->user_data); - foreach_context->foreach_break = stop_foreach; - } - -} - - -int service_foreach_extra_data(service_h service, service_extra_data_cb callback, void *user_data) -{ - foreach_context_extra_data_t foreach_context = { - .service = service, - .callback = callback, - .user_data = user_data, - .foreach_break = false - }; - - if (service_valiate_service(service) || callback == NULL) - return service_error(SERVICE_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL); - - bundle_foreach(service->data, service_cb_broker_bundle_iterator, &foreach_context); - - return SERVICE_ERROR_NONE; -} - -typedef struct { - service_h service; - service_app_matched_cb callback; - void* user_data; - bool foreach_break; -} foreach_context_launchable_app_t; - -int service_cb_broker_foreach_app_matched(const char *package, void *data) -{ - foreach_context_launchable_app_t *foreach_context; - service_app_matched_cb app_matched_cb; - - if (package == NULL || data == NULL) { - service_error(SERVICE_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL); - return -1; - } - - foreach_context = (foreach_context_launchable_app_t*)data; - - if (foreach_context->foreach_break == true) - return -1; - - app_matched_cb = foreach_context->callback; - - if (app_matched_cb != NULL) { - bool stop_foreach = false; - stop_foreach = !app_matched_cb(foreach_context->service, package, foreach_context->user_data); - foreach_context->foreach_break = stop_foreach; - } - - return 0; -} - -int service_foreach_app_matched(service_h service, service_app_matched_cb callback, void *user_data) -{ - foreach_context_launchable_app_t foreach_context = { - .service = service, - .callback = callback, - .user_data = user_data, - .foreach_break = false - }; - - if (service_valiate_service(service) || callback == NULL) - return service_error(SERVICE_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL); - - appsvc_usr_get_list(service->data, service_cb_broker_foreach_app_matched, &foreach_context, getuid()); - - return SERVICE_ERROR_NONE; -} - - -int service_get_caller(service_h service, char **package) -{ - const char *bundle_value; - char *package_dup; - - if (service_valiate_service(service) || package == NULL) - return service_error(SERVICE_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL); - - if (service->type != SERVICE_TYPE_EVENT) - return service_error(SERVICE_ERROR_INVALID_PARAMETER, __FUNCTION__, "invalid service handle type"); - - bundle_value = bundle_get_val(service->data, AUL_K_CALLER_APPID); - if (bundle_value == NULL) - return service_error(SERVICE_ERROR_INVALID_PARAMETER, __FUNCTION__, "failed to retrieve the appid of the caller"); - - package_dup = strdup(bundle_value); - - if (package_dup == NULL) - return service_error(SERVICE_ERROR_OUT_OF_MEMORY, __FUNCTION__, NULL); - - *package = package_dup; - - return SERVICE_ERROR_NONE; -} - - -int service_is_reply_requested(service_h service, bool *requested) -{ - const char *bundle_value; - - if (service_valiate_service(service) || requested == NULL) - return service_error(SERVICE_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL); - - if (service->type != SERVICE_TYPE_EVENT) - return service_error(SERVICE_ERROR_INVALID_PARAMETER, __FUNCTION__, "invalid service handle type"); - - bundle_value = bundle_get_val(service->data, AUL_K_WAIT_RESULT); - - if (bundle_value != NULL) - *requested = true; - else - *requested = false; - - return SERVICE_ERROR_NONE; -} - -int service_import_from_bundle(service_h service, bundle *data) -{ - bundle *data_dup = NULL; - - if (service_valiate_service(service) || data == NULL) - return service_error(SERVICE_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL); - - data_dup = bundle_dup(data); - - if (data_dup == NULL) - return service_error(SERVICE_ERROR_INVALID_PARAMETER, __FUNCTION__, "failed to duplicate the bundle"); - - if (service->data != NULL) - bundle_free(service->data); - - service->data = data_dup; - - return SERVICE_ERROR_NONE; -} - -int service_export_as_bundle(service_h service, bundle **data) -{ - bundle *data_dup = NULL; - - if (service_valiate_service(service) || data == NULL) - return service_error(SERVICE_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL); - - data_dup = bundle_dup(service->data); - - if (data_dup == NULL) - return service_error(SERVICE_ERROR_INVALID_PARAMETER, __FUNCTION__, "failed to duplicate the bundle"); - - *data = data_dup; - - return SERVICE_ERROR_NONE; -} - |