From d2b218e6256ebee02626f1d6594c17dba958bb56 Mon Sep 17 00:00:00 2001 From: Sangyoon Jang Date: Thu, 1 Sep 2016 14:42:21 +0900 Subject: [PATCH] Code refactoring - Rename comm_* -> pkgmgr_client_connection_* - Simplify callback logic - Move internal headers to source directory - Remove unused files Change-Id: I44e9211dddd27e00cc1b908733f0ccb71efc71d1 Signed-off-by: Sangyoon Jang --- client/CMakeLists.txt | 5 +- client/include/comm_client.h | 44 - client/include/package-manager.h | 4 +- client/include/pkgmgr-dbinfo.h | 225 ---- client/src/comm_client_gdbus.c | 340 ----- client/src/pkgmgr.c | 1399 ++++++++------------ client/src/pkgmgr_client_connection.c | 317 +++++ .../pkgmgr-debug.h => src/pkgmgr_client_debug.h} | 8 +- ...{pkgmgr-internal.c => pkgmgr_client_internal.c} | 7 +- .../pkgmgr_client_internal.h} | 47 +- 10 files changed, 886 insertions(+), 1510 deletions(-) delete mode 100644 client/include/comm_client.h delete mode 100644 client/include/pkgmgr-dbinfo.h delete mode 100644 client/src/comm_client_gdbus.c create mode 100644 client/src/pkgmgr_client_connection.c rename client/{include/pkgmgr-debug.h => src/pkgmgr_client_debug.h} (94%) rename client/src/{pkgmgr-internal.c => pkgmgr_client_internal.c} (99%) rename client/{include/pkgmgr-internal.h => src/pkgmgr_client_internal.h} (68%) diff --git a/client/CMakeLists.txt b/client/CMakeLists.txt index 99e9d91..0076596 100644 --- a/client/CMakeLists.txt +++ b/client/CMakeLists.txt @@ -1,6 +1,9 @@ # package manager client library -SET(SRCS src/pkgmgr-internal.c src/pkgmgr.c src/comm_client_gdbus.c) +SET(SRCS + src/pkgmgr.c + src/pkgmgr_client_connection.c + src/pkgmgr_client_internal.c) pkg_check_modules(CLIENT_DEPS REQUIRED glib-2.0 diff --git a/client/include/comm_client.h b/client/include/comm_client.h deleted file mode 100644 index b295351..0000000 --- a/client/include/comm_client.h +++ /dev/null @@ -1,44 +0,0 @@ -/* - * slp-pkgmgr - * - * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. - * - * Contact: Jayoun Lee , Sewook Park , - * Jaeho Lee , Shobhit Srivastava - * - * 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 __COMM_CLIENT_H__ -#define __COMM_CLIENT_H__ - -#include - -#include "package-manager.h" - -typedef struct comm_client comm_client; -typedef void (*status_cb) (void *cb_data, uid_t target_uid, const char *req_id, - const char *pkg_type, const char *pkgid, - const char *appid, const char *key, - const char *val); - -comm_client *comm_client_new(client_type type); -int comm_client_free(comm_client *cc); - -int comm_client_request(comm_client *cc, const char *method, GVariant *params, GVariant **result); - -int comm_client_set_status_callback(int comm_status_type, comm_client *cc, status_cb cb, void *cb_data); - -#endif /* __COMM_CLIENT_H__ */ diff --git a/client/include/package-manager.h b/client/include/package-manager.h index f7fdeb5..ccfe901 100644 --- a/client/include/package-manager.h +++ b/client/include/package-manager.h @@ -296,7 +296,7 @@ typedef enum { PC_REQUEST = 0, PC_LISTENING, PC_BROADCAST, -} client_type; +} pkgmgr_client_type; typedef enum { PM_DEFAULT, @@ -354,7 +354,7 @@ typedef enum { * @return pkgmgr_client object * @retval NULL on failure creating an object */ -pkgmgr_client *pkgmgr_client_new(client_type ctype); +pkgmgr_client *pkgmgr_client_new(pkgmgr_client_type ctype); /** * @brief This API deletes pkgmgr client. diff --git a/client/include/pkgmgr-dbinfo.h b/client/include/pkgmgr-dbinfo.h deleted file mode 100644 index bb9543b..0000000 --- a/client/include/pkgmgr-dbinfo.h +++ /dev/null @@ -1,225 +0,0 @@ -/* - * slp-pkgmgr - * - * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. - * - * Contact: Jayoun Lee , Sewook Park , - * Jaeho Lee , Shobhit Srivastava - * - * 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. - * - */ - - -/** - * @file pkgmgr-dbinfo.h - * @author Shobhit Srivastava - * @version 0.1 - * @brief This file declares db set API for backend installers - * - * @addtogroup APPLICATION_FRAMEWORK - * @{ - * - * @defgroup PackageManager - * @section Header to use them: - * @code - * #include "pkgmgr-dbinfo.h" - * @endcode - * - * @addtogroup PackageManager - * @{ - */ - -#ifndef __PKGMGR_DBINFO_H__ -#define __PKGMGR_DBINFO_H__ - -#include -#include - -#define GLOBAL_USER tzplatform_getuid(TZ_SYS_GLOBALAPP_USER) - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef DEPRECATED -#define DEPRECATED __attribute__ ((__deprecated__)) -#endif - -typedef enum { - PM_INSTALL_INTERNAL = 0, - PM_INSTALL_EXTERNAL, -} PM_INSTALL_LOCATION; - -typedef void *pkgmgr_pkgdbinfo_h; - -/** - * @brief This API creates package info handle to set info in the db. - * - * This API is for backend installers.\n - * - * @param[in] pkgid package id. - * @param[in] uid the addressee user id of the instruction - * @param[out] handle package info handle. - * @return 0 if success, error code(<0) if fail\n -*/ -int pkgmgr_create_pkgdbinfo(const char *pkgid, pkgmgr_pkgdbinfo_h *handle); -int pkgmgr_create_pkgusrdbinfo(const char *pkgid, uid_t uid, pkgmgr_pkgdbinfo_h *handle); -/** - * @brief This API sets the package type in DB. - * - * This API is for backend installers.\n - * - * @param[in] handle package info handle. - * @param[in] type package type. - * @return 0 if success, error code(<0) if fail\n -*/ -int pkgmgr_set_type_to_pkgdbinfo(pkgmgr_pkgdbinfo_h handle, const char *type); - -/** - * @brief This API sets the package version in DB. - * - * This API is for backend installers.\n - * - * @param[in] handle package info handle. - * @param[in] version package version. - * @return 0 if success, error code(<0) if fail\n -*/ -int pkgmgr_set_version_to_pkgdbinfo(pkgmgr_pkgdbinfo_h handle, const char *version); - -/** - * @brief This API sets install location in DB - * - * This API is for backend installers.\n - * - * @param[in] handle package info handle. - * @param[in] location install location. - * @return 0 if success, error code(<0) if fail\n -*/ -int pkgmgr_set_install_location_to_pkgdbinfo(pkgmgr_pkgdbinfo_h handle, PM_INSTALL_LOCATION location); - -/** - * @brief This API sets package size in DB - * - * This API is for backend installers.\n - * - * @param[in] handle package info handle. - * @param[in] size package size. - * @return 0 if success, error code(<0) if fail\n -*/ -int pkgmgr_set_size_to_pkgdbinfo(pkgmgr_pkgdbinfo_h handle, const char *size); - -/** - * @brief This API sets label in DB. - * - * This API is for backend installers.\n - * - * @param[in] handle package info handle. - * @param[in] label label text. - * @param[in] locale locale (NULL for default). - * @return 0 if success, error code(<0) if fail\n -*/ -int pkgmgr_set_label_to_pkgdbinfo(pkgmgr_pkgdbinfo_h handle, const char *label, const char *locale); - -/** - * @brief This API sets icon in DB. - * - * This API is for backend installers.\n - * - * @param[in] handle package info handle. - * @param[in] icon icon name. - * @param[in] locale locale (NULL for default). - * @return 0 if success, error code(<0) if fail\n -*/ -int pkgmgr_set_icon_to_pkgdbinfo(pkgmgr_pkgdbinfo_h handle, const char *icon, const char *locale); - -/** - * @brief This API sets description in DB. - * - * This API is for backend installers.\n - * - * @param[in] handle package info handle. - * @param[in] description description of the package. - * @param[in] locale locale (NULL for default). - * @return 0 if success, error code(<0) if fail\n -*/ -int pkgmgr_set_description_to_pkgdbinfo(pkgmgr_pkgdbinfo_h handle, const char *description, const char *locale); - -/** - * @brief This API sets author's name, email, href in DB. - * - * This API is for backend installers.\n - * - * @param[in] handle package info handle. - * @param[in] author_name author' name. - * @param[in] author_email author's email. - * @param[in] author_href author's href. - * @param[in] locale locale (NULL for default). - * @return 0 if success, error code(<0) if fail\n -*/ -int pkgmgr_set_author_to_pkgdbinfo(pkgmgr_pkgdbinfo_h handle, const char *author_name, - const char *author_email, const char *author_href, const char *locale); - -/** - * @brief This API sets removable in DB. - * - * This API is for backend installers.\n - * - * @param[in] handle package info handle. - * @param[in] removable removable (0 | 1) - * @return 0 if success, error code(<0) if fail\n -*/ -int pkgmgr_set_removable_to_pkgdbinfo(pkgmgr_pkgdbinfo_h handle, int removable); - -/** - * @brief This API sets preload in DB. - * - * This API is for backend installers.\n - * - * @param[in] handle package info handle. - * @param[in] preload preload (0 | 1) - * @return 0 if success, error code(<0) if fail\n -*/ -int pkgmgr_set_preload_to_pkgdbinfo(pkgmgr_pkgdbinfo_h handle, int preload); - -/** - * @brief This API save pakage info entry into the db. - * - * This API is for backend installers.\n - * - * @param[in] handle package info handle. - * @param[in] uid the addressee user id of the instruction - * @return 0 if success, error code(<0) if fail\n -*/ -int pkgmgr_save_pkgdbinfo(pkgmgr_pkgdbinfo_h handle); -int pkgmgr_save_pkgusrdbinfo(pkgmgr_pkgdbinfo_h handle, uid_t uid); - -/** - * @brief This API destroy pakage info handle and free the resources. - * - * This API is for backend installers.\n - * - * @param[in] handle package info handle. - * @return 0 if success, error code(<0) if fail\n -*/ -int pkgmgr_destroy_pkgdbinfo(pkgmgr_pkgdbinfo_h handle); - -#ifdef __cplusplus -} -#endif -#endif /* __PKGMGR_DBINFO_H__ */ -/** - * @} - * @} - */ - diff --git a/client/src/comm_client_gdbus.c b/client/src/comm_client_gdbus.c deleted file mode 100644 index 1f46042..0000000 --- a/client/src/comm_client_gdbus.c +++ /dev/null @@ -1,340 +0,0 @@ -/* - * slp-pkgmgr - * - * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. - * - * Contact: Jayoun Lee , Sewook Park , - * Jaeho Lee , Shobhit Srivastava - * - * 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 -#include -#include -#include - -#include -#include - -#include "comm_client.h" -#include "pkgmgr-debug.h" -#include "package-manager.h" -#include "../../installer/pkgmgr_installer.h" -#include "../../installer/pkgmgr_installer_config.h" - -#define COMM_CLIENT_RETRY_MAX 5 -#define COMM_CLIENT_WAIT_USEC (1000000 / 2) /* 0.5 sec */ - -/******************* - * ADT description - */ - -/* Storing status_cb */ -struct signal_callback_data { - int type; - status_cb cb; - void *cb_data; -}; - -/* comm_client ADT */ -struct comm_client { - guint subscription_id; - GDBusConnection *conn; - struct signal_callback_data *sig_cb_data; -}; - -static int __get_signal_type(const char *name) -{ - if (name == NULL) - return -1; - - if (strcmp(name, PKGMGR_INSTALLER_INSTALL_EVENT_STR) == 0) - return PKGMGR_CLIENT_STATUS_INSTALL; - else if (strcmp(name, PKGMGR_INSTALLER_UNINSTALL_EVENT_STR) == 0) - return PKGMGR_CLIENT_STATUS_UNINSTALL; - else if (strcmp(name, PKGMGR_INSTALLER_CLEAR_EVENT_STR) == 0) - return PKGMGR_CLIENT_STATUS_CLEAR_DATA; - else if (strcmp(name, PKGMGR_INSTALLER_MOVE_EVENT_STR) == 0) - return PKGMGR_CLIENT_STATUS_MOVE; - else if (strcmp(name, PKGMGR_INSTALLER_INSTALL_PERCENT_KEY_STR) == 0) - return PKGMGR_CLIENT_STATUS_INSTALL_PROGRESS; - else if (strcmp(name, PKGMGR_INSTALLER_UPGRADE_EVENT_STR) == 0) - return PKGMGR_CLIENT_STATUS_UPGRADE; - else if (strcmp(name, PKGMGR_INSTALLER_GET_SIZE_KEY_STR) == 0) - return PKGMGR_CLIENT_STATUS_GET_SIZE; - else if (strcmp(name, PKGMGR_INSTALLER_APP_ENABLE_EVENT_STR) == 0) - return PKGMGR_CLIENT_STATUS_ENABLE_APP; - else if (strcmp(name, PKGMGR_INSTALLER_APP_DISABLE_EVENT_STR) == 0) - return PKGMGR_CLIENT_STATUS_DISABLE_APP; - else if (strcmp(name, PKGMGR_INSTALLER_APP_ENABLE_SPLASH_SCREEN_EVENT_STR) == 0) - return PKGMGR_CLIENT_STATUS_ENABLE_APP_SPLASH_SCREEN; - else if (strcmp(name, PKGMGR_INSTALLER_APP_DISABLE_SPLASH_SCREEN_EVENT_STR) == 0) - return PKGMGR_CLIENT_STATUS_DISABLE_APP_SPLASH_SCREEN; - else - return -1; -} - -/** - * signal handler filter - * Filter signal, and run user callback - */ -void _on_signal_handle_filter(GDBusConnection *conn, - const gchar *sender_name, - const gchar *object_path, - const gchar *interface_name, - const gchar *signal_name, - GVariant *parameters, - gpointer user_data) -{ - if (interface_name && strcmp(interface_name, PKGMGR_INSTALLER_DBUS_INTERFACE)) { - DBG("Interface name did not match. Drop the message"); - return; - } - - int status_type; - /* Values to be received by signal */ - uid_t target_uid; - char *req_id; - char *pkg_type = NULL; - char *pkgid = NULL; - char *key = NULL; - char *val = NULL; - char *appid = NULL; - - /* User's signal handler */ - struct signal_callback_data *sig_cb_data; - if (user_data) - sig_cb_data = (struct signal_callback_data *)user_data; - else - return; - - status_type = __get_signal_type(signal_name); - if (status_type < 0 || !(status_type & sig_cb_data->type)) - return; - - g_variant_get(parameters, "(u&s&s&s&s&s&s)", - &target_uid, &req_id, &pkg_type, &pkgid, &appid, &key, &val); - - /* Run signal callback if exist */ - if (sig_cb_data && sig_cb_data->cb) - sig_cb_data->cb(sig_cb_data->cb_data, target_uid, req_id, - pkg_type, pkgid, appid, key, val); - - return; -} - -/** - * signal_callback_data free function - * Just free it! - */ -void _free_sig_cb_data(void *data) -{ - struct signal_callback_data *sig_cb_data = NULL; - sig_cb_data = (struct signal_callback_data *)data; - free(sig_cb_data); -} - -#define REGULAR_USER 5000 -static int _is_system_user(void) -{ - uid_t uid = getuid(); - - if (uid < REGULAR_USER) - return 1; - else - return 0; -} - -static GBusType _get_bus_type(client_type type) -{ - if (type == PC_REQUEST || _is_system_user()) - return G_BUS_TYPE_SYSTEM; - else - return G_BUS_TYPE_SESSION; -} - -/******************* - * API description - */ - -/** - * Create a new comm_client object - */ -comm_client *comm_client_new(client_type type) -{ - GError *error = NULL; - comm_client *cc = NULL; - - /* Allocate memory for ADT:comm_client */ -#if !GLIB_CHECK_VERSION(2, 35, 0) - g_type_init(); -#endif - cc = calloc(1, sizeof(comm_client)); - if (NULL == cc) { - ERR("No memory"); - return NULL; - } - - /* Connect to gdbus. Gets shared BUS */ - cc->conn = g_bus_get_sync(_get_bus_type(type), NULL, &error); - if (error) { - ERR("gdbus connection error (%s)", error->message); - g_error_free(error); - goto ERROR_CLEANUP; - } - if (NULL == cc->conn) { - ERR("gdbus connection is not set, even gdbus error isn't raised"); - goto ERROR_CLEANUP; - } - return cc; - - ERROR_CLEANUP: - if (cc) - free(cc); - return NULL; -} - -/** - * Free comm_client object - */ -int comm_client_free(comm_client *cc) -{ - if (!cc) - return -1; - if (!(cc->conn) || g_dbus_connection_is_closed(cc->conn)) { - ERR("Invalid gdbus connection"); - return -2; - } - - if (cc->sig_cb_data) { - g_dbus_connection_signal_unsubscribe(cc->conn, cc->subscription_id); - /* TODO: Is it needed to free cc->sig_cb_data here? */ - /* _free_sig_cb_data(cc->sig_cb_data); */ - } - - /* Cleanup ADT */ - /* flush remaining buffer: blocking mode */ - g_dbus_connection_flush_sync(cc->conn, NULL, NULL); - - /* Free signal filter if signal callback is exist */ - - /* just unref because it is shared BUS. - If ref count is 0 it will get free'd automatically - */ - g_object_unref(cc->conn); - free(cc); - - return 0; -} - -/** - * Request a message - */ -int comm_client_request(comm_client *cc, const char *method, GVariant *params, - GVariant **result) -{ - GError *error = NULL; - GDBusProxy *proxy; - GVariant *r = NULL; - int retry_cnt = 0; - int ret = PKGMGR_R_ECOMM; - - /* convert floating ref into normal ref */ - g_variant_ref_sink(params); - - do { - proxy = g_dbus_proxy_new_sync(cc->conn, G_DBUS_PROXY_FLAGS_NONE, - NULL, PKGMGR_DBUS_SERVICE, - PKGMGR_DBUS_OBJECT_PATH, - PKGMGR_DBUS_INTERFACE, NULL, &error); - if (proxy == NULL) { - ERR("failed to get proxy object, sleep and retry[%s]", - error->message); - g_error_free(error); - error = NULL; - usleep(COMM_CLIENT_WAIT_USEC); - retry_cnt++; - continue; - } - - r = g_dbus_proxy_call_sync(proxy, method, params, - G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error); - g_object_unref(proxy); - if (error && error->code == G_DBUS_ERROR_ACCESS_DENIED) { - ERR("failed to send request, privilege denied[%s]", - error->message); - ret = PKGMGR_R_EPRIV; - break; - } - if (r) { - *result = r; - ret = PKGMGR_R_OK; - break; - } - - ERR("failed to send request, sleep and retry[%s]", - error->message); - g_error_free(error); - error = NULL; - usleep(COMM_CLIENT_WAIT_USEC); - retry_cnt++; - } while (retry_cnt <= COMM_CLIENT_RETRY_MAX); - - /* decrease ref count to 0 to free resource */ - g_variant_unref(params); - - return ret; -} - -/** - * Set a callback for status signal - */ -int -comm_client_set_status_callback(int comm_status_type, comm_client *cc, status_cb cb, void *cb_data) -{ - int r = PKGMGR_R_OK; - - if (cc == NULL) - return PKGMGR_R_ERROR; - - /* Create new sig_cb_data */ - cc->sig_cb_data = calloc(1, sizeof(struct signal_callback_data)); - if (cc->sig_cb_data) { - (cc->sig_cb_data)->type = comm_status_type; - (cc->sig_cb_data)->cb = cb; - (cc->sig_cb_data)->cb_data = cb_data; - } else { - r = PKGMGR_R_ERROR; - goto ERROR_CLEANUP; - } - /* Add a filter for signal */ - cc->subscription_id = g_dbus_connection_signal_subscribe(cc->conn, NULL, - PKGMGR_INSTALLER_DBUS_INTERFACE, NULL, - PKGMGR_INSTALLER_DBUS_OBJECT_PATH, NULL, - G_DBUS_SIGNAL_FLAGS_NONE, _on_signal_handle_filter, - (gpointer)cc->sig_cb_data, _free_sig_cb_data); - if (!cc->subscription_id) { - ERR("Failed to add filter\n"); - r = PKGMGR_R_ERROR; - goto ERROR_CLEANUP; - } - - return PKGMGR_R_OK; - -ERROR_CLEANUP: - ERR("General error"); - return r; -} - diff --git a/client/src/pkgmgr.c b/client/src/pkgmgr.c index 6c1c941..c9094d0 100644 --- a/client/src/pkgmgr.c +++ b/client/src/pkgmgr.c @@ -38,9 +38,8 @@ #include #include "package-manager.h" -#include "pkgmgr-internal.h" -#include "pkgmgr-debug.h" -#include "comm_client.h" +#include "pkgmgr_client_debug.h" +#include "pkgmgr_client_internal.h" /* API export macro */ #ifndef API @@ -72,347 +71,91 @@ static int _get_request_id() return internal_req_id++; } -typedef struct _req_cb_info { - int request_id; - char *req_key; - pkgmgr_handler event_cb; - pkgmgr_app_handler app_event_cb; - void *data; - struct _req_cb_info *next; -} req_cb_info; - -typedef struct _listen_cb_info { - int request_id; - pkgmgr_handler event_cb; - pkgmgr_app_handler app_event_cb; - void *data; - struct _listen_cb_info *next; -} listen_cb_info; - -typedef struct _pkgmgr_client_t { - client_type ctype; - int status_type; - union { - struct _request { - comm_client *cc; - req_cb_info *rhead; - } request; - struct _listening { - comm_client *cc; - listen_cb_info *lhead; - } listening; - } info; - void *new_event_cb; - char *tep_path; - bool tep_move; -} pkgmgr_client_t; - -typedef struct _iter_data { - pkgmgr_iter_fn iter_fn; - void *data; -} iter_data; - -static void __add_op_cbinfo(pkgmgr_client_t *pc, int request_id, - const char *req_key, pkgmgr_handler event_cb, void *new_event_cb, - void *data) -{ - req_cb_info *cb_info; - req_cb_info *current; - req_cb_info *prev; - - cb_info = (req_cb_info *) calloc(1, sizeof(req_cb_info)); - if (cb_info == NULL) { - DBG("calloc failed"); - return; - } - cb_info->request_id = request_id; - cb_info->req_key = strdup(req_key); - cb_info->event_cb = event_cb; - cb_info->data = data; - cb_info->next = NULL; - cb_info->app_event_cb = NULL; - pc->new_event_cb = new_event_cb; - - if (pc->info.request.rhead == NULL) - pc->info.request.rhead = cb_info; - else { - current = prev = pc->info.request.rhead; - while (current) { - prev = current; - current = current->next; - } - - prev->next = cb_info; - } -} - -static void __add_op_app_cbinfo(pkgmgr_client_t *pc, int request_id, - const char *req_key, pkgmgr_app_handler app_event_cb, void *data) +static struct cb_info *__create_event_cb_info(struct pkgmgr_client_t *client, + pkgmgr_handler event_cb, void *data, const char *req_key) { - req_cb_info *cb_info; - req_cb_info *current; - req_cb_info *prev; + struct cb_info *cb_info; - cb_info = (req_cb_info *) calloc(1, sizeof(req_cb_info)); + cb_info = calloc(1, sizeof(struct cb_info)); if (cb_info == NULL) { - DBG("calloc failed"); - return; + ERR("out of memory"); + return NULL; } - cb_info->request_id = request_id; - cb_info->req_key = strdup(req_key); - cb_info->event_cb = NULL; - cb_info->app_event_cb = app_event_cb; + cb_info->client = client; + cb_info->event_cb = event_cb; cb_info->data = data; - cb_info->next = NULL; - pc->new_event_cb = NULL; - - if (pc->info.request.rhead == NULL) - pc->info.request.rhead = cb_info; - else { - current = prev = pc->info.request.rhead; - while (current) { - prev = current; - current = current->next; + cb_info->req_id = _get_request_id(); + if (req_key != NULL) { + cb_info->req_key = strdup(req_key); + if (cb_info->req_key == NULL) { + ERR("out of memory"); + free(cb_info); + return NULL; } - - prev->next = cb_info; } -} - -static req_cb_info *__find_op_cbinfo(pkgmgr_client_t *pc, const char *req_key) -{ - req_cb_info *tmp; - - tmp = pc->info.request.rhead; - if (tmp == NULL) { - ERR("tmp is NULL"); - return NULL; - } - - DBG("tmp->req_key %s, req_key %s", tmp->req_key, req_key); - - while (tmp) { - if (strncmp(tmp->req_key, req_key, strlen(tmp->req_key)) == 0) - return tmp; - tmp = tmp->next; - } - return NULL; + return cb_info; } -static int __remove_stat_cbinfo(pkgmgr_client_t *pc) +static struct cb_info *__create_app_event_cb_info( + struct pkgmgr_client_t *client, pkgmgr_app_handler app_event_cb, + void *data, const char *req_key) { - listen_cb_info *info = pc->info.listening.lhead; - listen_cb_info *next = NULL; + struct cb_info *cb_info; - while (info != NULL) { - next = info->next; - free(info); - info = next; - } - - pc->info.listening.lhead = NULL; - return 0; -} - -static void __add_app_stat_cbinfo(pkgmgr_client_t *pc, int request_id, - pkgmgr_app_handler event_cb, void *data) -{ - listen_cb_info *cb_info; - listen_cb_info *current; - listen_cb_info *prev; - - cb_info = (listen_cb_info *) calloc(1, sizeof(listen_cb_info)); + cb_info = calloc(1, sizeof(struct cb_info)); if (cb_info == NULL) { - DBG("calloc failed"); - return; + ERR("out of memory"); + return NULL; } - cb_info->request_id = request_id; - cb_info->app_event_cb = event_cb; + cb_info->client = client; + cb_info->app_event_cb = app_event_cb; cb_info->data = data; - cb_info->next = NULL; - - if (pc->info.listening.lhead == NULL) - pc->info.listening.lhead = cb_info; - else { - current = prev = pc->info.listening.lhead; - while (current) { - prev = current; - current = current->next; + cb_info->req_id = _get_request_id(); + if (req_key != NULL) { + cb_info->req_key = strdup(req_key); + if (cb_info->req_key == NULL) { + ERR("out of memory"); + free(cb_info); + return NULL; } - - prev->next = cb_info; - } -} - -static void __add_stat_cbinfo(pkgmgr_client_t *pc, int request_id, - pkgmgr_handler event_cb, void *data) -{ - listen_cb_info *cb_info; - listen_cb_info *current; - listen_cb_info *prev; - - cb_info = (listen_cb_info *) calloc(1, sizeof(listen_cb_info)); - if (cb_info == NULL) { - DBG("calloc failed"); - return; } - cb_info->request_id = request_id; - cb_info->event_cb = event_cb; - cb_info->data = data; - cb_info->next = NULL; - - /* TODO - check the order of callback - FIFO or LIFO => Should be changed to LIFO */ - if (pc->info.listening.lhead == NULL) - pc->info.listening.lhead = cb_info; - else { - current = prev = pc->info.listening.lhead; - while (current) { - prev = current; - current = current->next; - } - prev->next = cb_info; - } + return cb_info; } -static void __operation_callback(void *cb_data, uid_t target_uid, - const char *req_id, const char *pkg_type, - const char *pkgid, const char *appid, - const char *key, const char *val) +static struct cb_info *__create_size_info_cb_info( + struct pkgmgr_client_t *client, + pkgmgr_pkg_size_info_receive_cb size_info_cb, + void *data, const char *req_key) { - pkgmgr_client_t *pc; - req_cb_info *cb_info; + struct cb_info *cb_info; - pc = (pkgmgr_client_t *) cb_data; - - /* find callback info */ - cb_info = __find_op_cbinfo(pc, req_id); + cb_info = calloc(1, sizeof(struct cb_info)); if (cb_info == NULL) { - ERR("cannot find cb_info for req_id:%s", req_id); - return; - } - - /* call callback */ - if (appid != NULL && strlen(appid) != 0 && cb_info->app_event_cb) { - /* run app callback */ - if (pc->new_event_cb) - cb_info->app_event_cb(target_uid, cb_info->request_id, - pkg_type, pkgid, appid, key, val, pc, - cb_info->data); - else - cb_info->app_event_cb(target_uid, cb_info->request_id, - pkg_type, pkgid, appid, key, val, NULL, - cb_info->data); - } else if (cb_info->event_cb) { - /* run pkg callback */ - if (pc->new_event_cb) - cb_info->event_cb(target_uid, cb_info->request_id, - pkg_type, pkgid, key, val, pc, - cb_info->data); - else - cb_info->event_cb(target_uid, cb_info->request_id, - pkg_type, pkgid, key, val, NULL, - cb_info->data); + ERR("out of memory"); + return NULL; } - - return; -} - -static void __status_callback(void *cb_data, uid_t target_uid, - const char *req_id, const char *pkg_type, - const char *pkgid, const char *appid, - const char *key, const char *val) -{ - pkgmgr_client_t *pc; - listen_cb_info *tmp; - - pc = (pkgmgr_client_t *) cb_data; - - tmp = pc->info.listening.lhead; - while (tmp) { - if (appid != NULL && strlen(appid) != 0) { - /* run app callback */ - if (tmp->app_event_cb && tmp->app_event_cb( - target_uid, tmp->request_id, pkg_type, pkgid, - appid, key, val, NULL, tmp->data) != 0) - break; - } else { - /* run pkg callback */ - if (tmp->event_cb && tmp->event_cb( - target_uid, tmp->request_id, pkg_type, pkgid, - key, val, NULL, tmp->data) != 0) - break; + cb_info->client = client; + cb_info->size_info_cb = size_info_cb; + cb_info->data = data; + cb_info->req_id = _get_request_id(); + if (req_key != NULL) { + cb_info->req_key = strdup(req_key); + if (cb_info->req_key == NULL) { + ERR("out of memory"); + free(cb_info); + return NULL; } - tmp = tmp->next; } - return; + return cb_info; } -static inline int __read_proc(const char *path, char *buf, int size) +static void __free_cb_info(struct cb_info *cb_info) { - int fd = 0; - int ret = 0; - - if (buf == NULL || path == NULL) - return -1; - - fd = open(path, O_RDONLY); - if (fd < 0) - return -1; - - ret = read(fd, buf, size - 1); - if (ret <= 0) { - close(fd); - return -1; - } else - buf[ret] = 0; - - close(fd); - - return ret; -} - -char *__proc_get_cmdline_bypid(int pid) -{ - char buf[PKG_STRING_LEN_MAX] = {'\0', }; - int ret = 0; - - snprintf(buf, sizeof(buf), "/proc/%d/cmdline", pid); - ret = __read_proc(buf, buf, sizeof(buf)); - if (ret <= 0) - return NULL; - - /* support app launched by shell script*/ - if (strncmp(buf, BINSH_NAME, BINSH_SIZE) == 0) - return strdup(&buf[BINSH_SIZE + 1]); - else - return strdup(buf); -} - -static inline int __pkgmgr_read_proc(const char *path, char *buf, int size) -{ - int fd; - int ret; - - if (buf == NULL || path == NULL) - return -1; - - fd = open(path, O_RDONLY); - if (fd < 0) - return -1; - - ret = read(fd, buf, size - 1); - if (ret <= 0) { - close(fd); - return -1; - } else - buf[ret] = 0; - - close(fd); - - return ret; + free(cb_info->req_key); + free(cb_info); } static int __sync_process(const char *req_key) @@ -471,19 +214,19 @@ static int __get_size_process(pkgmgr_client *pc, const char *pkgid, uid_t uid, GVariant *result; int ret = PKGMGR_R_ECOMM; char *req_key = NULL; - pkgmgr_client_t *mpc = (pkgmgr_client_t *)pc; + struct pkgmgr_client_t *client = (struct pkgmgr_client_t *)pc; if (pc == NULL || pkgid == NULL) { ERR("invalid parameter"); return PKGMGR_R_EINVAL; } - if (mpc->ctype != PC_REQUEST) { - ERR("mpc->ctype is not PC_REQUEST"); + if (client->pc_type != PC_REQUEST) { + ERR("client->pc_type is not PC_REQUEST"); return PKGMGR_R_EINVAL; } - ret = comm_client_request(mpc->info.request.cc, "getsize", + ret = pkgmgr_client_connection_send_request(client, "getsize", g_variant_new("(usi)", uid, pkgid, get_type), &result); if (ret != PKGMGR_R_OK) { ERR("request failed: %d", ret); @@ -531,9 +274,9 @@ static int __check_app_process(pkgmgr_request_service_type service_type, int ret = PKGMGR_R_ECOMM; pkgmgrinfo_pkginfo_h handle; int pid = -1; - pkgmgr_client_t *mpc = (pkgmgr_client_t *) pc; + struct pkgmgr_client_t *client = (struct pkgmgr_client_t *)pc; - retvm_if(mpc->ctype != PC_REQUEST, PKGMGR_R_EINVAL, "mpc->ctype is not PC_REQUEST\n"); + retvm_if(client->pc_type != PC_REQUEST, PKGMGR_R_EINVAL, "client->pc_type is not PC_REQUEST\n"); if (uid != GLOBAL_USER) ret = pkgmgrinfo_pkginfo_get_usr_pkginfo(pkgid, uid, &handle); @@ -542,10 +285,10 @@ static int __check_app_process(pkgmgr_request_service_type service_type, retvm_if(ret < 0, PKGMGR_R_ERROR, "pkgmgrinfo_pkginfo_get_pkginfo failed"); if (service_type == PM_REQUEST_KILL_APP) - ret = comm_client_request(mpc->info.request.cc, "kill", + ret = pkgmgr_client_connection_send_request(client, "kill", g_variant_new("(us)", uid, pkgid), &result); else if (service_type == PM_REQUEST_CHECK_APP) - ret = comm_client_request(mpc->info.request.cc, "check", + ret = pkgmgr_client_connection_send_request(client, "check", g_variant_new("(us)", uid, pkgid), &result); if (ret != PKGMGR_R_OK) { ERR("request failed: %d", ret); @@ -573,254 +316,85 @@ static int __request_size_info(pkgmgr_client *pc, uid_t uid) { GVariant *result; int ret = PKGMGR_R_ECOMM; - char *req_key = NULL; - pkgmgr_client_t *mpc = (pkgmgr_client_t *) pc; +// char *req_key = NULL; + struct pkgmgr_client_t *client = (struct pkgmgr_client_t *)pc; if (pc == NULL) { ERR("invalid parameter"); return PKGMGR_R_EINVAL; } - if (mpc->ctype != PC_REQUEST) { - ERR("mpc->ctype is not PC_REQUEST"); + if (client->pc_type != PC_REQUEST) { + ERR("client->pc_type is not PC_REQUEST"); return PKGMGR_R_EINVAL; } - ret = comm_client_request(mpc->info.request.cc, "getsize", + ret = pkgmgr_client_connection_send_request(client, "getsize", g_variant_new("(usi)", uid, "size_info", - PM_GET_SIZE_INFO), - &result); + PM_GET_SIZE_INFO), &result); if (ret != PKGMGR_R_OK) { ERR("request failed: %d", ret); return ret; } +/* g_variant_get(result, "(i&s)", &ret, &req_key); if (req_key == NULL) { g_variant_unref(result); return PKGMGR_R_ECOMM; } +*/ g_variant_unref(result); return ret; } -static int __change_op_cb_for_getsize(pkgmgr_client *pc) -{ - int ret = -1; - - retvm_if(pc == NULL, PKGMGR_R_EINVAL, "package manager client pc is NULL"); - pkgmgr_client_t *mpc = (pkgmgr_client_t *) pc; - - /* free listening head */ - req_cb_info *tmp = NULL; - req_cb_info *prev = NULL; - for (tmp = mpc->info.request.rhead; tmp;) { - prev = tmp; - tmp = tmp->next; - free(prev); - } - - /* free dbus connection */ - ret = comm_client_free(mpc->info.request.cc); - retvm_if(ret < 0, PKGMGR_R_ERROR, "comm_client_free() failed - %d", ret); - - /* Manage pc for seperated event */ - mpc->ctype = PC_REQUEST; - mpc->status_type = PKGMGR_CLIENT_STATUS_GET_SIZE; - - - mpc->info.request.cc = comm_client_new(PC_REQUEST); - retvm_if(mpc->info.request.cc == NULL, PKGMGR_R_ERROR, "client creation failed"); - - ret = comm_client_set_status_callback(PKGMGR_CLIENT_STATUS_GET_SIZE, mpc->info.request.cc, __operation_callback, pc); - retvm_if(ret < 0, PKGMGR_R_ERROR, "set_status_callback() failed - %d", ret); - - return PKGMGR_R_OK; -} - -static int __change_op_cb_for_enable_disable(pkgmgr_client *pc, bool is_disable) +API pkgmgr_client *pkgmgr_client_new(pkgmgr_client_type pc_type) { - int ret = -1; - - retvm_if(pc == NULL, PKGMGR_R_EINVAL, "package manager client pc is NULL"); - pkgmgr_client_t *mpc = (pkgmgr_client_t *) pc; + struct pkgmgr_client_t *client; - /* free listening head */ - req_cb_info *tmp = NULL; - req_cb_info *prev = NULL; - for (tmp = mpc->info.request.rhead; tmp;) { - prev = tmp; - tmp = tmp->next; - free(prev); + if (pc_type == PC_BROADCAST) { + ERR("broadcast type is not supported"); + return NULL; } - /* free dbus connection */ - ret = comm_client_free(mpc->info.request.cc); - retvm_if(ret < 0, PKGMGR_R_ERROR, "comm_client_free() failed - %d", ret); - - /* Manage pc for seperated event */ - mpc->ctype = PC_REQUEST; - if (is_disable) - mpc->status_type = PKGMGR_CLIENT_STATUS_DISABLE_APP; - else - mpc->status_type = PKGMGR_CLIENT_STATUS_ENABLE_APP; - - - mpc->info.request.cc = comm_client_new(PC_REQUEST); - retvm_if(mpc->info.request.cc == NULL, PKGMGR_R_ERROR, "client creation failed"); - - ret = comm_client_set_status_callback(mpc->status_type, mpc->info.request.cc, __operation_callback, pc); - retvm_if(ret < 0, PKGMGR_R_ERROR, "set_status_callback() failed - %d", ret); - - return PKGMGR_R_OK; -} - -static int __get_pkg_size_info_cb(uid_t target_uid, int req_id, const char *req_type, - const char *pkgid, const char *key, - const char *value, const void *pc, void *user_data) -{ - int ret = 0; - DBG("target_uid: %u, reqid: %d, req type: %s, pkgid: %s, unused key: %s, size info: %s", - target_uid, req_id, req_type, pkgid, key, value); - - pkg_size_info_t *size_info = (pkg_size_info_t *)malloc(sizeof(pkg_size_info_t)); - retvm_if(size_info == NULL, -1, "The memory is insufficient."); - - char *save_ptr = NULL; - char *token = strtok_r((char *)value, ":", &save_ptr); - tryvm_if(token == NULL, ret = -1, "failed to parse sizeinfo"); - size_info->data_size = atoll(token); - token = strtok_r(NULL, ":", &save_ptr); - tryvm_if(token == NULL, ret = -1, "failed to parse sizeinfo"); - size_info->cache_size = atoll(token); - token = strtok_r(NULL, ":", &save_ptr); - tryvm_if(token == NULL, ret = -1, "failed to parse sizeinfo"); - size_info->app_size = atoll(token); - token = strtok_r(NULL, ":", &save_ptr); - tryvm_if(token == NULL, ret = -1, "failed to parse sizeinfo"); - size_info->ext_data_size = atoll(token); - token = strtok_r(NULL, ":", &save_ptr); - tryvm_if(token == NULL, ret = -1, "failed to parse sizeinfo"); - size_info->ext_cache_size = atoll(token); - token = strtok_r(NULL, ":", &save_ptr); - tryvm_if(token == NULL, ret = -1, "failed to parse sizeinfo"); - size_info->ext_app_size = atoll(token); - - DBG("data: %lld, cache: %lld, app: %lld, ext_data: %lld, ext_cache: %lld, ext_app: %lld", - size_info->data_size, size_info->cache_size, size_info->app_size, - size_info->ext_data_size, size_info->ext_cache_size, size_info->ext_app_size); - - pkgmgr_client_t *pmc = (pkgmgr_client_t *)pc; - tryvm_if(pmc == NULL, ret = -1, "pkgmgr_client instance is null."); - - if (strcmp(pkgid, PKG_SIZE_INFO_TOTAL) == 0) { /* total package size info */ - pkgmgr_total_pkg_size_info_receive_cb callback = (pkgmgr_total_pkg_size_info_receive_cb)(pmc->new_event_cb); - callback((pkgmgr_client *)pc, size_info, user_data); - } else { - pkgmgr_pkg_size_info_receive_cb callback = (pkgmgr_pkg_size_info_receive_cb)(pmc->new_event_cb); - callback((pkgmgr_client *)pc, pkgid, size_info, user_data); + if (pc_type != PC_REQUEST && pc_type != PC_LISTENING) { + ERR("invalid parameter"); + return NULL; } -catch: - - if (size_info) { - free(size_info); - size_info = NULL; + client = calloc(1, sizeof(struct pkgmgr_client_t)); + if (client == NULL) { + ERR("out of memory"); + return NULL; } - return ret; -} - -API pkgmgr_client *pkgmgr_client_new(client_type ctype) -{ - pkgmgr_client_t *pc = NULL; - int ret = -1; - - retvm_if(ctype == PC_BROADCAST, NULL, "broadcast type is not supported"); - retvm_if(ctype != PC_REQUEST && ctype != PC_LISTENING, NULL, "ctype is not client_type"); - /* Allocate memory for ADT:pkgmgr_client */ - pc = calloc(1, sizeof(pkgmgr_client_t)); - retvm_if(pc == NULL, NULL, "No memory"); + client->pc_type = pc_type; + client->status_type = PKGMGR_CLIENT_STATUS_ALL; - /* Manage pc */ - pc->ctype = ctype; - pc->status_type = PKGMGR_CLIENT_STATUS_ALL; - pc->tep_path = NULL; - - if (pc->ctype == PC_REQUEST) { - pc->info.request.cc = comm_client_new(PC_REQUEST); - trym_if(pc->info.request.cc == NULL, "client creation failed"); - - ret = comm_client_set_status_callback(PKGMGR_CLIENT_STATUS_ALL, pc->info.request.cc, __operation_callback, pc); - trym_if(ret < 0L, "comm_client_set_status_callback() failed - %d", ret); - } else if (pc->ctype == PC_LISTENING) { - pc->info.listening.cc = comm_client_new(PC_LISTENING); - trym_if(pc->info.listening.cc == NULL, "client creation failed"); - - ret = comm_client_set_status_callback(PKGMGR_CLIENT_STATUS_ALL, pc->info.listening.cc, __status_callback, pc); - trym_if(ret < 0L, "comm_client_set_status_callback() failed - %d", ret); - } - - return (pkgmgr_client *)pc; + if (pkgmgr_client_connection_connect(client)) + return NULL; - catch: - if (pc) - free(pc); - return NULL; + return (pkgmgr_client *)client; } API int pkgmgr_client_free(pkgmgr_client *pc) { - int ret = -1; - pkgmgr_client_t *mpc = (pkgmgr_client_t *) pc; - retvm_if(mpc == NULL, PKGMGR_R_EINVAL, "Invalid argument"); - - if (mpc->ctype == PC_REQUEST) { - req_cb_info *tmp; - req_cb_info *prev; - for (tmp = mpc->info.request.rhead; tmp;) { - prev = tmp; - tmp = tmp->next; - free(prev); - } - - ret = comm_client_free(mpc->info.request.cc); - tryvm_if(ret < 0, ret = PKGMGR_R_ERROR, "comm_client_free() failed"); - } else if (mpc->ctype == PC_LISTENING) { - listen_cb_info *tmp; - listen_cb_info *prev; - for (tmp = mpc->info.listening.lhead; tmp;) { - prev = tmp; - tmp = tmp->next; - free(prev); - } + struct pkgmgr_client_t *client = (struct pkgmgr_client_t *)pc; - ret = comm_client_free(mpc->info.listening.cc); - tryvm_if(ret < 0, ret = PKGMGR_R_ERROR, "comm_client_free() failed"); - } else if (mpc->ctype == PC_BROADCAST) { - ret = 0; - } else { - ERR("Invalid client type\n"); + if (pc == NULL) { + ERR("invalid argument"); return PKGMGR_R_EINVAL; } - if (mpc->tep_path) { - free(mpc->tep_path); - mpc->tep_path = NULL; - } + pkgmgr_client_remove_listen_status(client); + pkgmgr_client_connection_disconnect(client); + if (client->tep_path) + free(client->tep_path); + free(client); - free(mpc); - mpc = NULL; return PKGMGR_R_OK; - - catch: - if (mpc) { - free(mpc); - mpc = NULL; - } - return PKGMGR_R_ERROR; } static char *__get_type_from_path(const char *pkg_path) @@ -852,64 +426,21 @@ static char *__get_type_from_path(const char *pkg_path) return strdup(pkg_type); } -static int __change_op_cb_for_enable_disable_splash_screen(pkgmgr_client *pc, - bool is_enable) +API int pkgmgr_client_set_tep_path(pkgmgr_client *pc, char *tep_path, + bool tep_move) { - int ret; - pkgmgr_client_t *mpc = (pkgmgr_client_t *)pc; - req_cb_info *tmp; - req_cb_info *prev; + struct pkgmgr_client_t *client = (struct pkgmgr_client_t *) pc; - if (mpc == NULL) { - ERR("package mananger client pc is NULL"); + if (pc == NULL || tep_path == NULL) { + ERR("invalied parameter"); return PKGMGR_R_EINVAL; } - for (tmp = mpc->info.request.rhead; tmp;) { - prev = tmp; - tmp = tmp->next; - free(prev); - } - - ret = comm_client_free(mpc->info.request.cc); - if (ret < 0) { - ERR("comm_client_free() failed - %d", ret); - return PKGMGR_R_ERROR; - } - - mpc->ctype = PC_REQUEST; - if (is_enable) - mpc->status_type = PKGMGR_CLIENT_STATUS_ENABLE_APP_SPLASH_SCREEN; - else - mpc->status_type = PKGMGR_CLIENT_STATUS_DISABLE_APP_SPLASH_SCREEN; - - mpc->info.request.cc = comm_client_new(PC_REQUEST); - if (mpc->info.request.cc == NULL) { - ERR("client creation failed"); - return PKGMGR_R_ENOMEM; - } - - ret = comm_client_set_status_callback(mpc->status_type, - mpc->info.request.cc, __operation_callback, pc); - if (ret < 0) { - ERR("set_status_callback() failed - %d", ret); - return PKGMGR_R_ERROR; - } - - return PKGMGR_R_OK; -} - -API int pkgmgr_client_set_tep_path(pkgmgr_client *pc, char *tep_path, bool tep_move) -{ - retvm_if(pc == NULL, PKGMGR_R_EINVAL, "package manager client pc is NULL"); - retvm_if(tep_path == NULL, PKGMGR_R_EINVAL, "tep path is NULL"); - pkgmgr_client_t *mpc = (pkgmgr_client_t *) pc; - - if (mpc->tep_path) - free(mpc->tep_path); + if (client->tep_path) + free(client->tep_path); - mpc->tep_path = strdup(tep_path); - mpc->tep_move = tep_move; + client->tep_path = strdup(tep_path); + client->tep_move = tep_move; return PKGMGR_R_OK; } @@ -924,17 +455,17 @@ API int pkgmgr_client_usr_install(pkgmgr_client *pc, const char *pkg_type, char *req_key = NULL; GVariantBuilder *builder = NULL; GVariant *args = NULL; - int req_id; - pkgmgr_client_t *mpc = (pkgmgr_client_t *)pc; + struct pkgmgr_client_t *client = (struct pkgmgr_client_t *)pc; char *pkgtype; + struct cb_info *cb_info; if (pc == NULL || pkg_path == NULL) { ERR("invalid parameter"); return PKGMGR_R_EINVAL; } - if (mpc->ctype != PC_REQUEST) { - ERR("mpc->ctype is not PC_REQUEST"); + if (client->pc_type != PC_REQUEST) { + ERR("client type is not PC_REQUEST"); return PKGMGR_R_EINVAL; } @@ -943,8 +474,8 @@ API int pkgmgr_client_usr_install(pkgmgr_client *pc, const char *pkg_type, return PKGMGR_R_EINVAL; } - if (mpc->tep_path != NULL && access(mpc->tep_path, F_OK) != 0) { - ERR("failed to access: %s", mpc->tep_path); + if (client->tep_path != NULL && access(client->tep_path, F_OK) != 0) { + ERR("failed to access: %s", client->tep_path); return PKGMGR_R_EINVAL; } @@ -956,19 +487,19 @@ API int pkgmgr_client_usr_install(pkgmgr_client *pc, const char *pkg_type, /* build arguments */ builder = g_variant_builder_new(G_VARIANT_TYPE("as")); - if (mpc->tep_path) { + if (client->tep_path) { g_variant_builder_add(builder, "s", "-e"); - g_variant_builder_add(builder, "s", mpc->tep_path); + g_variant_builder_add(builder, "s", client->tep_path); g_variant_builder_add(builder, "s", "-M"); /* TODO: revise tep_move */ g_variant_builder_add(builder, "s", - mpc->tep_move ? "tep_move" : "tep_copy"); + client->tep_move ? "tep_move" : "tep_copy"); } args = g_variant_new("as", builder); g_variant_builder_unref(builder); - ret = comm_client_request(mpc->info.request.cc, "install", + ret = pkgmgr_client_connection_send_request(client, "install", g_variant_new("(uss@as)", uid, pkgtype, pkg_path, args), &result); if (ret != PKGMGR_R_OK) { @@ -986,12 +517,20 @@ API int pkgmgr_client_usr_install(pkgmgr_client *pc, const char *pkg_type, return ret; } - req_id = _get_request_id(); - __add_op_cbinfo(mpc, req_id, req_key, event_cb, NULL, data); - + cb_info = __create_event_cb_info(client, event_cb, data, req_key); + if (cb_info == NULL) { + g_variant_unref(result); + return PKGMGR_R_ENOMEM; + } g_variant_unref(result); + ret = pkgmgr_client_connection_set_callback(client, cb_info); + if (ret != PKGMGR_R_OK) { + __free_cb_info(cb_info); + return ret; + } + client->cb_info_list = g_list_append(client->cb_info_list, cb_info); - return req_id; + return cb_info->req_id; } API int pkgmgr_client_install(pkgmgr_client *pc, const char *pkg_type, @@ -1019,18 +558,18 @@ API int pkgmgr_client_usr_reinstall(pkgmgr_client *pc, const char *pkg_type, GVariant *result; int ret = PKGMGR_R_ECOMM; char *req_key = NULL; - int req_id; - pkgmgr_client_t *mpc = (pkgmgr_client_t *)pc; + struct pkgmgr_client_t *client = (struct pkgmgr_client_t *)pc; char *pkgtype; pkgmgrinfo_pkginfo_h handle; + struct cb_info *cb_info; if (pc == NULL || pkgid == NULL) { ERR("invalid parameter"); return PKGMGR_R_EINVAL; } - if (mpc->ctype != PC_REQUEST) { - ERR("mpc->ctype is not PC_REQUEST"); + if (client->pc_type != PC_REQUEST) { + ERR("client->pc_type is not PC_REQUEST"); return PKGMGR_R_EINVAL; } @@ -1044,7 +583,7 @@ API int pkgmgr_client_usr_reinstall(pkgmgr_client *pc, const char *pkg_type, return PKGMGR_R_ERROR; } - ret = comm_client_request(mpc->info.request.cc, "reinstall", + ret = pkgmgr_client_connection_send_request(client, "reinstall", g_variant_new("(uss)", uid, pkgtype, pkgid), &result); pkgmgrinfo_pkginfo_destroy_pkginfo(handle); if (ret != PKGMGR_R_OK) { @@ -1062,12 +601,20 @@ API int pkgmgr_client_usr_reinstall(pkgmgr_client *pc, const char *pkg_type, return ret; } - req_id = _get_request_id(); - __add_op_cbinfo(mpc, req_id, req_key, event_cb, NULL, data); - + cb_info = __create_event_cb_info(client, event_cb, data, req_key); + if (cb_info == NULL) { + g_variant_unref(result); + return PKGMGR_R_ENOMEM; + } g_variant_unref(result); + ret = pkgmgr_client_connection_set_callback(client, cb_info); + if (ret != PKGMGR_R_OK) { + __free_cb_info(cb_info); + return ret; + } + client->cb_info_list = g_list_append(client->cb_info_list, cb_info); - return req_id; + return cb_info->req_id; } API int pkgmgr_client_usr_mount_install(pkgmgr_client *pc, const char *pkg_type, @@ -1080,17 +627,17 @@ API int pkgmgr_client_usr_mount_install(pkgmgr_client *pc, const char *pkg_type, char *req_key = NULL; GVariantBuilder *builder = NULL; GVariant *args = NULL; - int req_id; - pkgmgr_client_t *mpc = (pkgmgr_client_t *)pc; + struct pkgmgr_client_t *client = (struct pkgmgr_client_t *)pc; char *pkgtype; + struct cb_info *cb_info; if (pc == NULL || pkg_path == NULL) { ERR("invalid parameter"); return PKGMGR_R_EINVAL; } - if (mpc->ctype != PC_REQUEST) { - ERR("mpc->ctype is not PC_REQUEST"); + if (client->pc_type != PC_REQUEST) { + ERR("client->pc_type is not PC_REQUEST"); return PKGMGR_R_EINVAL; } @@ -1099,8 +646,8 @@ API int pkgmgr_client_usr_mount_install(pkgmgr_client *pc, const char *pkg_type, return PKGMGR_R_EINVAL; } - if (mpc->tep_path != NULL && access(mpc->tep_path, F_OK) != 0) { - ERR("failed to access: %s", mpc->tep_path); + if (client->tep_path != NULL && access(client->tep_path, F_OK) != 0) { + ERR("failed to access: %s", client->tep_path); return PKGMGR_R_EINVAL; } @@ -1112,19 +659,19 @@ API int pkgmgr_client_usr_mount_install(pkgmgr_client *pc, const char *pkg_type, /* build arguments */ builder = g_variant_builder_new(G_VARIANT_TYPE("as")); - if (mpc->tep_path) { + if (client->tep_path) { g_variant_builder_add(builder, "s", "-e"); - g_variant_builder_add(builder, "s", mpc->tep_path); + g_variant_builder_add(builder, "s", client->tep_path); g_variant_builder_add(builder, "s", "-M"); /* TODO: revise tep_move */ g_variant_builder_add(builder, "s", - mpc->tep_move ? "tep_move" : "tep_copy"); + client->tep_move ? "tep_move" : "tep_copy"); } args = g_variant_new("as", builder); g_variant_builder_unref(builder); - ret = comm_client_request(mpc->info.request.cc, "mount_install", + ret = pkgmgr_client_connection_send_request(client, "mount_install", g_variant_new("(uss@as)", uid, pkgtype, pkg_path, args), &result); if (ret != PKGMGR_R_OK) { @@ -1142,12 +689,20 @@ API int pkgmgr_client_usr_mount_install(pkgmgr_client *pc, const char *pkg_type, return ret; } - req_id = _get_request_id(); - __add_op_cbinfo(mpc, req_id, req_key, event_cb, NULL, data); - + cb_info = __create_event_cb_info(client, event_cb, data, req_key); + if (cb_info == NULL) { + g_variant_unref(result); + return PKGMGR_R_ENOMEM; + } g_variant_unref(result); + ret = pkgmgr_client_connection_set_callback(client, cb_info); + if (ret != PKGMGR_R_OK) { + __free_cb_info(cb_info); + return ret; + } + client->cb_info_list = g_list_append(client->cb_info_list, cb_info); - return req_id; + return cb_info->req_id; } API int pkgmgr_client_mount_install(pkgmgr_client *pc, const char *pkg_type, @@ -1175,18 +730,18 @@ API int pkgmgr_client_usr_uninstall(pkgmgr_client *pc, const char *pkg_type, GVariant *result; int ret = PKGMGR_R_ECOMM; char *req_key = NULL; - int req_id; - pkgmgr_client_t *mpc = (pkgmgr_client_t *)pc; + struct pkgmgr_client_t *client = (struct pkgmgr_client_t *)pc; char *pkgtype; pkgmgrinfo_pkginfo_h handle; + struct cb_info *cb_info; if (pc == NULL || pkgid == NULL) { ERR("invalid parameter"); return PKGMGR_R_EINVAL; } - if (mpc->ctype != PC_REQUEST) { - ERR("mpc->ctype is not PC_REQUEST"); + if (client->pc_type != PC_REQUEST) { + ERR("client->pc_type is not PC_REQUEST"); return PKGMGR_R_EINVAL; } @@ -1200,7 +755,7 @@ API int pkgmgr_client_usr_uninstall(pkgmgr_client *pc, const char *pkg_type, return PKGMGR_R_ERROR; } - ret = comm_client_request(mpc->info.request.cc, "uninstall", + ret = pkgmgr_client_connection_send_request(client, "uninstall", g_variant_new("(uss)", uid, pkgtype, pkgid), &result); if (ret != PKGMGR_R_OK) { ERR("request failed: %d", ret); @@ -1220,13 +775,22 @@ API int pkgmgr_client_usr_uninstall(pkgmgr_client *pc, const char *pkg_type, return ret; } - req_id = _get_request_id(); - __add_op_cbinfo(mpc, req_id, req_key, event_cb, NULL, data); - + cb_info = __create_event_cb_info(client, event_cb, data, req_key); + if (cb_info == NULL) { + g_variant_unref(result); + return PKGMGR_R_ENOMEM; + } g_variant_unref(result); + ret = pkgmgr_client_connection_set_callback(client, cb_info); + if (ret != PKGMGR_R_OK) { + __free_cb_info(cb_info); + return ret; + } + client->cb_info_list = g_list_append(client->cb_info_list, cb_info); + pkgmgrinfo_pkginfo_destroy_pkginfo(handle); - return req_id; + return cb_info->req_id; } API int pkgmgr_client_move(pkgmgr_client *pc, const char *pkg_type, @@ -1242,25 +806,27 @@ API int pkgmgr_client_usr_move(pkgmgr_client *pc, const char *pkg_type, { GVariant *result; int ret = PKGMGR_R_ECOMM; - int req_id; char *req_key = NULL; - pkgmgr_client_t *mpc = (pkgmgr_client_t *)pc; + struct pkgmgr_client_t *client = (struct pkgmgr_client_t *)pc; + struct cb_info *cb_info; if (pc == NULL || pkg_type == NULL || pkgid == NULL) { ERR("invalid parameter"); return PKGMGR_R_EINVAL; } - if ((move_type < PM_MOVE_TO_INTERNAL) || (move_type > PM_MOVE_TO_SDCARD)) + if ((move_type < PM_MOVE_TO_INTERNAL) || + (move_type > PM_MOVE_TO_SDCARD)) return PKGMGR_R_EINVAL; - if (mpc->ctype != PC_REQUEST) { - ERR("mpc->ctype is not PC_REQUEST"); + if (client->pc_type != PC_REQUEST) { + ERR("client->pc_type is not PC_REQUEST"); return PKGMGR_R_EINVAL; } - ret = comm_client_request(mpc->info.request.cc, "move", - g_variant_new("(ussi)", uid, pkg_type, pkgid, move_type), &result); + ret = pkgmgr_client_connection_send_request(client, "move", + g_variant_new("(ussi)", uid, pkg_type, pkgid, + move_type), &result); if (ret != PKGMGR_R_OK) { ERR("request failed: %d", ret); return ret; @@ -1276,11 +842,20 @@ API int pkgmgr_client_usr_move(pkgmgr_client *pc, const char *pkg_type, return ret; } - req_id = _get_request_id(); - __add_op_cbinfo(mpc, req_id, req_key, event_cb, NULL, data); + cb_info = __create_event_cb_info(client, event_cb, data, req_key); + if (cb_info == NULL) { + g_variant_unref(result); + return PKGMGR_R_ERROR; + } g_variant_unref(result); + ret = pkgmgr_client_connection_set_callback(client, cb_info); + if (ret != PKGMGR_R_OK) { + __free_cb_info(cb_info); + return ret; + } + client->cb_info_list = g_list_append(client->cb_info_list, cb_info); - return ret; + return cb_info->req_id; } API int pkgmgr_client_usr_activate(pkgmgr_client *pc, const char *pkg_type, @@ -1288,14 +863,14 @@ API int pkgmgr_client_usr_activate(pkgmgr_client *pc, const char *pkg_type, { GVariant *result; int ret = PKGMGR_R_ECOMM; - pkgmgr_client_t *mpc = (pkgmgr_client_t *)pc; + struct pkgmgr_client_t *client = (struct pkgmgr_client_t *)pc; if (pc == NULL || pkgid == NULL || pkg_type == NULL) { ERR("invalid parameter"); return PKGMGR_R_EINVAL; } - ret = comm_client_request(mpc->info.request.cc, "enable_pkg", + ret = pkgmgr_client_connection_send_request(client, "enable_pkg", g_variant_new("(uss)", uid, pkg_type, pkgid), &result); if (ret != PKGMGR_R_OK) { ERR("request failed: %d", ret); @@ -1319,14 +894,14 @@ API int pkgmgr_client_usr_deactivate(pkgmgr_client *pc, const char *pkg_type, { GVariant *result; int ret = PKGMGR_R_ECOMM; - pkgmgr_client_t *mpc = (pkgmgr_client_t *)pc; + struct pkgmgr_client_t *client = (struct pkgmgr_client_t *)pc; if (pc == NULL || pkgid == NULL || pkg_type == NULL) { ERR("invalid parameter"); return PKGMGR_R_EINVAL; } - ret = comm_client_request(mpc->info.request.cc, "disable_pkg", + ret = pkgmgr_client_connection_send_request(client, "disable_pkg", g_variant_new("(uss)", uid, pkg_type, pkgid), &result); if (ret != PKGMGR_R_OK) { ERR("request failed: %d", ret); @@ -1350,21 +925,16 @@ API int pkgmgr_client_usr_activate_app(pkgmgr_client *pc, const char *appid, { GVariant *result; int ret = PKGMGR_R_ECOMM; - int req_id; char *req_key = NULL; - pkgmgr_client_t *mpc = (pkgmgr_client_t *)pc; + struct pkgmgr_client_t *client = (struct pkgmgr_client_t *)pc; + struct cb_info *cb_info; if (pc == NULL || appid == NULL) { ERR("invalid parameter"); return PKGMGR_R_EINVAL; } - if (__change_op_cb_for_enable_disable(mpc, false) < 0) { - ERR("__change_op_cb_for_enable_disable failed"); - return PKGMGR_R_ESYSTEM; - } - - ret = comm_client_request(mpc->info.request.cc, "enable_app", + ret = pkgmgr_client_connection_send_request(client, "enable_app", g_variant_new("(us)", uid, appid), &result); if (ret != PKGMGR_R_OK) { ERR("request failed: %d", ret); @@ -1381,37 +951,46 @@ API int pkgmgr_client_usr_activate_app(pkgmgr_client *pc, const char *appid, return ret; } - req_id = _get_request_id(); - __add_op_app_cbinfo(pc, req_id, req_key, app_event_cb, NULL); + cb_info = __create_app_event_cb_info(client, app_event_cb, NULL, + req_key); + if (cb_info == NULL) { + g_variant_unref(result); + return PKGMGR_R_ENOMEM; + } g_variant_unref(result); - return ret; + ret = pkgmgr_client_connection_set_callback(client, cb_info); + if (ret != PKGMGR_R_OK) { + __free_cb_info(cb_info); + return ret; + } + client->cb_info_list = g_list_append(client->cb_info_list, cb_info); + + return PKGMGR_R_OK; } -API int pkgmgr_client_activate_app(pkgmgr_client *pc, const char *appid, pkgmgr_app_handler app_event_cb) +API int pkgmgr_client_activate_app(pkgmgr_client *pc, const char *appid, + pkgmgr_app_handler app_event_cb) { - return pkgmgr_client_usr_activate_app(pc, appid, app_event_cb, _getuid()); + return pkgmgr_client_usr_activate_app(pc, appid, app_event_cb, + _getuid()); } API int pkgmgr_client_activate_global_app_for_uid(pkgmgr_client *pc, - const char *appid, pkgmgr_app_handler app_event_cb, uid_t uid) + const char *appid, pkgmgr_app_handler app_event_cb, uid_t uid) { GVariant *result; int ret = PKGMGR_R_ECOMM; - int req_id; char *req_key = NULL; - pkgmgr_client_t *mpc = (pkgmgr_client_t *)pc; + struct pkgmgr_client_t *client = (struct pkgmgr_client_t *)pc; + struct cb_info *cb_info; if (pc == NULL || appid == NULL) { ERR("invalid parameter"); return PKGMGR_R_EINVAL; } - if (__change_op_cb_for_enable_disable(mpc, false) < 0) { - ERR("__change_op_cb_for_enable_disable failed"); - return PKGMGR_R_ESYSTEM; - } - - ret = comm_client_request(mpc->info.request.cc, "enable_global_app_for_uid", + ret = pkgmgr_client_connection_send_request(client, + "enable_global_app_for_uid", g_variant_new("(us)", uid, appid), &result); if (ret != PKGMGR_R_OK) { ERR("request failed: %d", ret); @@ -1428,10 +1007,21 @@ API int pkgmgr_client_activate_global_app_for_uid(pkgmgr_client *pc, return ret; } - req_id = _get_request_id(); - __add_op_app_cbinfo(pc, req_id, req_key, app_event_cb, NULL); + cb_info = __create_app_event_cb_info(client, app_event_cb, NULL, + req_key); + if (cb_info == NULL) { + g_variant_unref(result); + return PKGMGR_R_ENOMEM; + } + g_variant_unref(result); + ret = pkgmgr_client_connection_set_callback(client, cb_info); + if (ret != PKGMGR_R_OK) { + __free_cb_info(cb_info); + return ret; + } + client->cb_info_list = g_list_append(client->cb_info_list, cb_info); - return ret; + return PKGMGR_R_OK; } API int pkgmgr_client_usr_deactivate_app(pkgmgr_client *pc, const char *appid, @@ -1439,22 +1029,16 @@ API int pkgmgr_client_usr_deactivate_app(pkgmgr_client *pc, const char *appid, { GVariant *result; int ret = PKGMGR_R_ECOMM; - pkgmgr_client_t *mpc = (pkgmgr_client_t *)pc; - int req_id; char *req_key = NULL; + struct pkgmgr_client_t *client = (struct pkgmgr_client_t *)pc; + struct cb_info *cb_info; if (pc == NULL || appid == NULL) { ERR("invalid parameter"); return PKGMGR_R_EINVAL; } - /* FIXME */ - if (__change_op_cb_for_enable_disable(mpc, true) < 0) { - ERR("__change_op_cb_for_enable_disable failed"); - return PKGMGR_R_ESYSTEM; - } - - ret = comm_client_request(mpc->info.request.cc, "disable_app", + ret = pkgmgr_client_connection_send_request(client, "disable_app", g_variant_new("(us)", uid, appid), &result); if (ret != PKGMGR_R_OK) { ERR("request failed: %d", ret); @@ -1471,38 +1055,46 @@ API int pkgmgr_client_usr_deactivate_app(pkgmgr_client *pc, const char *appid, return ret; } - req_id = _get_request_id(); - __add_op_app_cbinfo(pc, req_id, req_key, app_event_cb, NULL); - + cb_info = __create_app_event_cb_info(client, app_event_cb, NULL, + req_key); + if (cb_info == NULL) { + g_variant_unref(result); + return PKGMGR_R_ENOMEM; + } g_variant_unref(result); - return ret; + ret = pkgmgr_client_connection_set_callback(client, cb_info); + if (ret != PKGMGR_R_OK) { + __free_cb_info(cb_info); + return ret; + } + client->cb_info_list = g_list_append(client->cb_info_list, cb_info); + + return PKGMGR_R_OK; } -API int pkgmgr_client_deactivate_app(pkgmgr_client *pc, const char *appid, pkgmgr_app_handler app_event_cb) +API int pkgmgr_client_deactivate_app(pkgmgr_client *pc, const char *appid, + pkgmgr_app_handler app_event_cb) { - return pkgmgr_client_usr_deactivate_app(pc, appid, app_event_cb, _getuid()); + return pkgmgr_client_usr_deactivate_app(pc, appid, app_event_cb, + _getuid()); } API int pkgmgr_client_deactivate_global_app_for_uid(pkgmgr_client *pc, - const char *appid, pkgmgr_app_handler app_event_cb, uid_t uid) + const char *appid, pkgmgr_app_handler app_event_cb, uid_t uid) { GVariant *result; int ret = PKGMGR_R_ECOMM; - int req_id; char *req_key = NULL; - pkgmgr_client_t *mpc = (pkgmgr_client_t *)pc; + struct pkgmgr_client_t *client = (struct pkgmgr_client_t *)pc; + struct cb_info *cb_info; if (pc == NULL || appid == NULL) { ERR("invalid parameter"); return PKGMGR_R_EINVAL; } - if (__change_op_cb_for_enable_disable(mpc, true) < 0) { - ERR("__change_op_cb_for_enable_disable failed"); - return PKGMGR_R_ESYSTEM; - } - - ret = comm_client_request(mpc->info.request.cc, "disable_global_app_for_uid", + ret = pkgmgr_client_connection_send_request(client, + "disable_global_app_for_uid", g_variant_new("(us)", uid, appid), &result); if (ret != PKGMGR_R_OK) { ERR("request failed: %d", ret); @@ -1519,9 +1111,21 @@ API int pkgmgr_client_deactivate_global_app_for_uid(pkgmgr_client *pc, return ret; } - req_id = _get_request_id(); - __add_op_app_cbinfo(pc, req_id, req_key, app_event_cb, NULL); - return ret; + cb_info = __create_app_event_cb_info(client, app_event_cb, NULL, + req_key); + if (cb_info == NULL) { + g_variant_unref(result); + return PKGMGR_R_ENOMEM; + } + g_variant_unref(result); + ret = pkgmgr_client_connection_set_callback(client, cb_info); + if (ret != PKGMGR_R_OK) { + __free_cb_info(cb_info); + return ret; + } + client->cb_info_list = g_list_append(client->cb_info_list, cb_info); + + return PKGMGR_R_OK; } API int pkgmgr_client_usr_clear_user_data(pkgmgr_client *pc, @@ -1529,20 +1133,20 @@ API int pkgmgr_client_usr_clear_user_data(pkgmgr_client *pc, uid_t uid) { GVariant *result; - int ret = PKGMGR_R_ECOMM; - pkgmgr_client_t *mpc = (pkgmgr_client_t *)pc; + int ret; + struct pkgmgr_client_t *client = (struct pkgmgr_client_t *)pc; if (pc == NULL || pkg_type == NULL || appid == NULL) { ERR("invalid parameter"); return PKGMGR_R_EINVAL; } - if (mpc->ctype != PC_REQUEST) { - ERR("mpc->ctype is not PC_REQUEST"); + if (client->pc_type != PC_REQUEST) { + ERR("client->pc_type is not PC_REQUEST"); return PKGMGR_R_EINVAL; } - ret = comm_client_request(mpc->info.request.cc, "cleardata", + ret = pkgmgr_client_connection_send_request(client, "cleardata", g_variant_new("(uss)", uid, pkg_type, appid), &result); if (ret == PKGMGR_R_OK) { ERR("request failed: %d", ret); @@ -1564,112 +1168,129 @@ API int pkgmgr_client_clear_user_data(pkgmgr_client *pc, const char *pkg_type, API int pkgmgr_client_set_status_type(pkgmgr_client *pc, int status_type) { - int ret = -1; + struct pkgmgr_client_t *client = (struct pkgmgr_client_t *)pc; - retvm_if(pc == NULL, PKGMGR_R_EINVAL, "package manager client pc is NULL"); - retvm_if(status_type == PKGMGR_CLIENT_STATUS_ALL, PKGMGR_R_OK, "status_type is PKGMGR_CLIENT_STATUS_ALL"); - pkgmgr_client_t *mpc = (pkgmgr_client_t *)pc; - - /* free listening head */ - listen_cb_info *tmp = NULL; - listen_cb_info *prev = NULL; - for (tmp = mpc->info.listening.lhead; tmp;) { - prev = tmp; - tmp = tmp->next; - free(prev); + if (pc == NULL) { + ERR("invalid parameter"); + return PKGMGR_R_EINVAL; } - /* free dbus connection */ - ret = comm_client_free(mpc->info.listening.cc); - retvm_if(ret < 0, PKGMGR_R_ERROR, "comm_client_free() failed - %d", ret); - - /* Manage pc for seperated event */ - mpc->ctype = PC_LISTENING; - mpc->status_type = status_type; - - mpc->info.listening.cc = comm_client_new(PC_LISTENING); - retvm_if(mpc->info.listening.cc == NULL, PKGMGR_R_EINVAL, "client creation failed"); - - ret = comm_client_set_status_callback(status_type, mpc->info.listening.cc, __status_callback, pc); - retvm_if(ret < 0, PKGMGR_R_ECOMM, "comm_client_set_status_callback failed - %d", ret); + client->status_type = status_type; return PKGMGR_R_OK; } API int pkgmgr_client_listen_status(pkgmgr_client *pc, pkgmgr_handler event_cb, - void *data) + void *data) { - int req_id; - /* Check for NULL value of pc */ - retvm_if(pc == NULL, PKGMGR_R_EINVAL, "package manager client pc is NULL"); - pkgmgr_client_t *mpc = (pkgmgr_client_t *) pc; + int ret; + struct pkgmgr_client_t *client = (struct pkgmgr_client_t *)pc; + struct cb_info *cb_info; - /* 0. check input */ - retvm_if(mpc->ctype != PC_LISTENING, PKGMGR_R_EINVAL, "ctype is not PC_LISTENING"); - retvm_if(event_cb == NULL, PKGMGR_R_EINVAL, "event_cb is NULL"); + if (pc == NULL || event_cb == NULL) { + ERR("invalid parameter"); + return PKGMGR_R_EINVAL; + } - /* 1. get id */ - req_id = _get_request_id(); + if (client->pc_type != PC_LISTENING) { + ERR("client->pc_type is not PC_LISTENING"); + return PKGMGR_R_EINVAL; + } - /* 2. add callback info to pkgmgr_client */ - __add_stat_cbinfo(mpc, req_id, event_cb, data); - return req_id; + cb_info = __create_event_cb_info(client, event_cb, data, NULL); + if (cb_info == NULL) + return PKGMGR_R_ENOMEM; + cb_info->status_type = client->status_type; + ret = pkgmgr_client_connection_set_callback(client, cb_info); + if (ret != PKGMGR_R_OK) { + __free_cb_info(cb_info); + return ret; + } + client->cb_info_list = g_list_append(client->cb_info_list, cb_info); + + return cb_info->req_id; } -API int pkgmgr_client_listen_app_status(pkgmgr_client *pc, pkgmgr_app_handler event_cb, - void *data) +API int pkgmgr_client_listen_app_status(pkgmgr_client *pc, + pkgmgr_app_handler app_event_cb, void *data) { - int req_id; - /* Check for NULL value of pc */ - retvm_if(pc == NULL, PKGMGR_R_EINVAL, "package manager client pc is NULL"); - pkgmgr_client_t *mpc = (pkgmgr_client_t *) pc; + int ret; + struct pkgmgr_client_t *client = (struct pkgmgr_client_t *)pc; + struct cb_info *cb_info; - /* 0. check input */ - retvm_if(mpc->ctype != PC_LISTENING, PKGMGR_R_EINVAL, "ctype is not PC_LISTENING"); - retvm_if(event_cb == NULL, PKGMGR_R_EINVAL, "event_cb is NULL"); + if (pc == NULL || app_event_cb == NULL) { + ERR("invalid parameter"); + return PKGMGR_R_EINVAL; + } - /* 1. get id */ - req_id = _get_request_id(); + if (client->pc_type != PC_LISTENING) { + ERR("client->pc_type is not PC_LISTENING"); + return PKGMGR_R_EINVAL; + } - /* 2. add app callback info to pkgmgr_client */ - __add_app_stat_cbinfo(mpc, req_id, event_cb, data); - return req_id; + cb_info = __create_app_event_cb_info(client, app_event_cb, data, NULL); + if (cb_info == NULL) + return PKGMGR_R_ENOMEM; + cb_info->status_type = client->status_type; + ret = pkgmgr_client_connection_set_callback(client, cb_info); + if (ret != PKGMGR_R_OK) { + __free_cb_info(cb_info); + return ret; + } + client->cb_info_list = g_list_append(client->cb_info_list, cb_info); + + return cb_info->req_id; } API int pkgmgr_client_remove_listen_status(pkgmgr_client *pc) { - int ret = -1; + struct pkgmgr_client_t *client = (struct pkgmgr_client_t *)pc; + GList *tmp; + GList *next; + struct cb_info *cb_info; - retvm_if(pc == NULL, PKGMGR_R_EINVAL, "package manager client pc is NULL"); - pkgmgr_client_t *mpc = (pkgmgr_client_t *) pc; + if (pc == NULL) { + ERR("invalid parameter"); + return PKGMGR_R_EINVAL; + } - ret = __remove_stat_cbinfo(mpc); - if (ret != 0) { - ERR("failed to remove status callback"); - return PKGMGR_R_ERROR; + /* unset all callback */ + tmp = client->cb_info_list; + while (tmp != NULL) { + next = tmp->next; + cb_info = (struct cb_info *)tmp->data; + pkgmgr_client_connection_unset_callback(pc, cb_info); + client->cb_info_list = g_list_delete_link(client->cb_info_list, + tmp); + tmp = next; } return PKGMGR_R_OK; } API int pkgmgr_client_broadcast_status(pkgmgr_client *pc, const char *pkg_type, - const char *pkgid, const char *key, - const char *val) + const char *pkgid, const char *key, const char *val) { /* client cannot broadcast signal */ return PKGMGR_R_OK; } -API int pkgmgr_client_request_service(pkgmgr_request_service_type service_type, int service_mode, - pkgmgr_client *pc, const char *pkg_type, const char *pkgid, - const char *custom_info, pkgmgr_handler event_cb, void *data) +/* TODO: deprecate(or remove) */ +API int pkgmgr_client_request_service(pkgmgr_request_service_type service_type, + int service_mode, pkgmgr_client *pc, const char *pkg_type, + const char *pkgid, const char *custom_info, + pkgmgr_handler event_cb, void *data) { - return pkgmgr_client_usr_request_service(service_type, service_mode, pc, pkg_type, pkgid, _getuid(), custom_info, event_cb, data); + return pkgmgr_client_usr_request_service(service_type, service_mode, + pc, pkg_type, pkgid, _getuid(), custom_info, event_cb, + data); } -API int pkgmgr_client_usr_request_service(pkgmgr_request_service_type service_type, int service_mode, - pkgmgr_client *pc, const char *pkg_type, const char *pkgid, uid_t uid, - const char *custom_info, pkgmgr_handler event_cb, void *data) +API int pkgmgr_client_usr_request_service( + pkgmgr_request_service_type service_type, int service_mode, + pkgmgr_client *pc, const char *pkg_type, const char *pkgid, + uid_t uid, const char *custom_info, pkgmgr_handler event_cb, + void *data) { int ret = 0; @@ -1721,43 +1342,47 @@ catch: API int pkgmgr_client_usr_request_size_info(uid_t uid) { - int ret = 0; - pkgmgr_client *pc = NULL; + int ret; + struct pkgmgr_client *client; - pc = pkgmgr_client_new(PC_REQUEST); - retvm_if(pc == NULL, PKGMGR_R_EINVAL, "request pc is null\n"); + client = pkgmgr_client_new(PC_REQUEST); + if (client == NULL) { + ERR("out of memory"); + return PKGMGR_R_ENOMEM; + } - ret = __request_size_info(pc, uid); + ret = __request_size_info(client, uid); if (ret < 0) - ERR("__request_size_info fail \n"); + ERR("__request_size_info fail"); - pkgmgr_client_free(pc); + pkgmgr_client_free(client); return ret; } -API int pkgmgr_client_request_size_info(void) /* get all package size (data, total) */ +API int pkgmgr_client_request_size_info(void) { + /* get all package size (data, total) */ return pkgmgr_client_usr_request_size_info(_getuid()); } API int pkgmgr_client_usr_clear_cache_dir(const char *pkgid, uid_t uid) { GVariant *result; - int ret = PKGMGR_R_ECOMM; - pkgmgr_client_t *pc; + int ret; + struct pkgmgr_client_t *client; if (pkgid == NULL) { ERR("invalid parameter"); return PKGMGR_R_EINVAL; } - pc = pkgmgr_client_new(PC_REQUEST); - if (pc == NULL) { + client = pkgmgr_client_new(PC_REQUEST); + if (client == NULL) { ERR("out of memory"); - return PKGMGR_R_ESYSTEM; + return PKGMGR_R_ENOMEM; } - ret = comm_client_request(pc->info.request.cc, "clearcache", + ret = pkgmgr_client_connection_send_request(client, "clearcache", g_variant_new("(us)", uid, pkgid), &result); if (ret != PKGMGR_R_OK) { ERR("request failed: %d", ret); @@ -1782,7 +1407,8 @@ API int pkgmgr_client_clear_usr_all_cache_dir(uid_t uid) API int pkgmgr_client_clear_all_cache_dir(void) { - return pkgmgr_client_usr_clear_cache_dir(PKG_CLEAR_ALL_CACHE, _getuid()); + return pkgmgr_client_usr_clear_cache_dir( + PKG_CLEAR_ALL_CACHE, getuid()); } API int pkgmgr_client_get_size(pkgmgr_client *pc, const char *pkgid, @@ -1793,6 +1419,7 @@ API int pkgmgr_client_get_size(pkgmgr_client *pc, const char *pkgid, _getuid()); } +/* TODO: deprecate(or remove) */ API int pkgmgr_client_usr_get_size(pkgmgr_client *pc, const char *pkgid, pkgmgr_getsize_type get_type, pkgmgr_handler event_cb, void *data, uid_t uid) @@ -1800,16 +1427,16 @@ API int pkgmgr_client_usr_get_size(pkgmgr_client *pc, const char *pkgid, GVariant *result; int ret = PKGMGR_R_ECOMM; char *req_key = NULL; - int req_id; - pkgmgr_client_t *mpc = (pkgmgr_client_t *)pc; + struct pkgmgr_client_t *client = (struct pkgmgr_client_t *)pc; + struct cb_info *cb_info; if (pc == NULL || pkgid == NULL || event_cb == NULL) { ERR("invalid parameter"); return PKGMGR_R_EINVAL; } - if (mpc->ctype != PC_REQUEST) { - ERR("mpc->ctype is not PC_REQUEST"); + if (client->pc_type != PC_REQUEST) { + ERR("client->pc_type is not PC_REQUEST"); return PKGMGR_R_EINVAL; } @@ -1819,7 +1446,7 @@ API int pkgmgr_client_usr_get_size(pkgmgr_client *pc, const char *pkgid, else get_type = PM_GET_PKG_SIZE_INFO; - ret = comm_client_request(mpc->info.request.cc, "getsize", + ret = pkgmgr_client_connection_send_request(client, "getsize", g_variant_new("(usi)", uid, pkgid, get_type), &result); if (ret != PKGMGR_R_OK) { ERR("request failed: %d", ret); @@ -1836,10 +1463,18 @@ API int pkgmgr_client_usr_get_size(pkgmgr_client *pc, const char *pkgid, return ret; } - req_id = _get_request_id(); - __add_op_cbinfo(mpc, req_id, req_key, event_cb, NULL, data); - + cb_info = __create_event_cb_info(client, event_cb, data, req_key); + if (cb_info == NULL) { + g_variant_unref(result); + return PKGMGR_R_ENOMEM; + } g_variant_unref(result); + ret = pkgmgr_client_connection_set_callback(client, cb_info); + if (ret != PKGMGR_R_OK) { + __free_cb_info(cb_info); + return ret; + } + client->cb_info_list = g_list_append(client->cb_info_list, cb_info); return PKGMGR_R_OK; } @@ -1851,32 +1486,26 @@ API int pkgmgr_client_usr_get_package_size_info(pkgmgr_client *pc, GVariant *result; int ret = PKGMGR_R_ECOMM; char *req_key = NULL; - int req_id; int get_type; - pkgmgr_client_t *mpc = (pkgmgr_client_t *)pc; + struct pkgmgr_client_t *client = (struct pkgmgr_client_t *)pc; + struct cb_info *cb_info; if (pc == NULL || pkgid == NULL || event_cb == NULL) { ERR("invalid parameter"); return PKGMGR_R_EINVAL; } - if (mpc->ctype != PC_REQUEST) { - ERR("mpc->ctype is not PC_REQUEST"); + if (client->pc_type != PC_REQUEST) { + ERR("client->pc_type is not PC_REQUEST"); return PKGMGR_R_EINVAL; } - /* FIXME */ - if (__change_op_cb_for_getsize(mpc) < 0) { - ERR("__change_op_cb_for_getsize failed"); - return PKGMGR_R_ESYSTEM; - } - if (strcmp(pkgid, PKG_SIZE_INFO_TOTAL) == 0) get_type = PM_GET_TOTAL_PKG_SIZE_INFO; else get_type = PM_GET_PKG_SIZE_INFO; - ret = comm_client_request(mpc->info.request.cc, "getsize", + ret = pkgmgr_client_connection_send_request(client, "getsize", g_variant_new("(usi)", uid, pkgid, get_type), &result); if (ret != PKGMGR_R_OK) { ERR("request failed: %d", ret); @@ -1893,28 +1522,46 @@ API int pkgmgr_client_usr_get_package_size_info(pkgmgr_client *pc, return ret; } - req_id = _get_request_id(); - __add_op_cbinfo(mpc, req_id, req_key, __get_pkg_size_info_cb, event_cb, - user_data); - + cb_info = __create_size_info_cb_info(client, event_cb, user_data, + req_key); + if (cb_info == NULL) { + g_variant_unref(result); + return PKGMGR_R_ENOMEM; + } g_variant_unref(result); + ret = pkgmgr_client_connection_set_callback(client, cb_info); + if (ret != PKGMGR_R_OK) { + __free_cb_info(cb_info); + return ret; + } + client->cb_info_list = g_list_append(client->cb_info_list, cb_info); return PKGMGR_R_OK; } -API int pkgmgr_client_get_package_size_info(pkgmgr_client *pc, const char *pkgid, pkgmgr_pkg_size_info_receive_cb event_cb, void *user_data) +API int pkgmgr_client_get_package_size_info(pkgmgr_client *pc, + const char *pkgid, pkgmgr_pkg_size_info_receive_cb event_cb, + void *user_data) { - return pkgmgr_client_usr_get_package_size_info(pc, pkgid, event_cb, user_data, _getuid()); + return pkgmgr_client_usr_get_package_size_info(pc, pkgid, event_cb, + user_data, _getuid()); } -API int pkgmgr_client_usr_get_total_package_size_info(pkgmgr_client *pc, pkgmgr_total_pkg_size_info_receive_cb event_cb, void *user_data, uid_t uid) +API int pkgmgr_client_usr_get_total_package_size_info(pkgmgr_client *pc, + pkgmgr_total_pkg_size_info_receive_cb event_cb, + void *user_data, uid_t uid) { /* total package size info */ - return pkgmgr_client_usr_get_package_size_info(pc, PKG_SIZE_INFO_TOTAL, (pkgmgr_pkg_size_info_receive_cb)event_cb, user_data, uid); + return pkgmgr_client_usr_get_package_size_info(pc, PKG_SIZE_INFO_TOTAL, + (pkgmgr_pkg_size_info_receive_cb)event_cb, + user_data, uid); } -API int pkgmgr_client_get_total_package_size_info(pkgmgr_client *pc, pkgmgr_total_pkg_size_info_receive_cb event_cb, void *user_data) +API int pkgmgr_client_get_total_package_size_info(pkgmgr_client *pc, + pkgmgr_total_pkg_size_info_receive_cb event_cb, void *user_data) { - return pkgmgr_client_usr_get_package_size_info(pc, PKG_SIZE_INFO_TOTAL, (pkgmgr_pkg_size_info_receive_cb)event_cb, user_data, _getuid()); + return pkgmgr_client_usr_get_package_size_info(pc, PKG_SIZE_INFO_TOTAL, + (pkgmgr_pkg_size_info_receive_cb)event_cb, + user_data, _getuid()); } API int pkgmgr_client_generate_license_request(pkgmgr_client *pc, @@ -1924,7 +1571,7 @@ API int pkgmgr_client_generate_license_request(pkgmgr_client *pc, int ret; char *data; char *url; - pkgmgr_client_t *mpc = (pkgmgr_client_t *)pc; + struct pkgmgr_client_t *client = (struct pkgmgr_client_t *)pc; if (pc == NULL || resp_data == NULL || req_data == NULL || license_url == NULL) { @@ -1932,12 +1579,12 @@ API int pkgmgr_client_generate_license_request(pkgmgr_client *pc, return PKGMGR_R_EINVAL; } - if (mpc->ctype != PC_REQUEST) { - ERR("mpc->ctype is not PC_REQUEST"); + if (client->pc_type != PC_REQUEST) { + ERR("client->pc_type is not PC_REQUEST"); return PKGMGR_R_EINVAL; } - ret = comm_client_request(mpc->info.request.cc, + ret = pkgmgr_client_connection_send_request(client, "generate_license_request", g_variant_new("(s)", resp_data), &result); if (ret != PKGMGR_R_OK) { @@ -1964,21 +1611,20 @@ API int pkgmgr_client_register_license(pkgmgr_client *pc, const char *resp_data) { GVariant *result; int ret; - pkgmgr_client_t *mpc = (pkgmgr_client_t *)pc; + struct pkgmgr_client_t *client = (struct pkgmgr_client_t *)pc; if (pc == NULL || resp_data == NULL) { ERR("invalid parameter"); return PKGMGR_R_EINVAL; } - if (mpc->ctype != PC_REQUEST) { - ERR("mpc->ctype is not PC_REQUEST"); + if (client->pc_type != PC_REQUEST) { + ERR("client->pc_type is not PC_REQUEST"); return PKGMGR_R_EINVAL; } - ret = comm_client_request(mpc->info.request.cc, - "register_license", g_variant_new("(s)", resp_data), - &result); + ret = pkgmgr_client_connection_send_request(client, "register_license", + g_variant_new("(s)", resp_data), &result); if (ret != PKGMGR_R_OK) { ERR("request failed: %d", ret); return ret; @@ -1986,12 +1632,10 @@ API int pkgmgr_client_register_license(pkgmgr_client *pc, const char *resp_data) g_variant_get(result, "(i)", &ret); g_variant_unref(result); - if (ret != PKGMGR_R_OK) { + if (ret != PKGMGR_R_OK) ERR("register license failed: %d", ret); - return ret; - } - return PKGMGR_R_OK; + return ret; } API int pkgmgr_client_decrypt_package(pkgmgr_client *pc, @@ -1999,7 +1643,7 @@ API int pkgmgr_client_decrypt_package(pkgmgr_client *pc, { GVariant *result; int ret; - pkgmgr_client_t *mpc = (pkgmgr_client_t *)pc; + struct pkgmgr_client_t *client = (struct pkgmgr_client_t *)pc; if (pc == NULL || drm_file_path == NULL || decrypted_file_path == NULL) { @@ -2007,16 +1651,14 @@ API int pkgmgr_client_decrypt_package(pkgmgr_client *pc, return PKGMGR_R_EINVAL; } - if (mpc->ctype != PC_REQUEST) { - ERR("mpc->ctype is not PC_REQUEST"); + if (client->pc_type != PC_REQUEST) { + ERR("client->pc_type is not PC_REQUEST"); return PKGMGR_R_EINVAL; } - ret = comm_client_request(mpc->info.request.cc, - "decrypt_package", + ret = pkgmgr_client_connection_send_request(client, "decrypt_package", g_variant_new("(ss)", drm_file_path, - decrypted_file_path), - &result); + decrypted_file_path), &result); if (ret != PKGMGR_R_OK) { ERR("request failed: %d", ret); return ret; @@ -2024,12 +1666,10 @@ API int pkgmgr_client_decrypt_package(pkgmgr_client *pc, g_variant_get(result, "(i)", &ret); g_variant_unref(result); - if (ret != PKGMGR_R_OK) { + if (ret != PKGMGR_R_OK) ERR("decrypt_package failed: %d", ret); - return ret; - } - return PKGMGR_R_OK; + return ret; } API int pkgmgr_client_enable_splash_screen(pkgmgr_client *pc, const char *appid) @@ -2042,20 +1682,14 @@ API int pkgmgr_client_usr_enable_splash_screen(pkgmgr_client *pc, { int ret; GVariant *result; - pkgmgr_client_t *mpc = (pkgmgr_client_t *)pc; + struct pkgmgr_client_t *client = (struct pkgmgr_client_t *)pc; if (pc == NULL || appid == NULL) { ERR("Invalid parameter"); return PKGMGR_R_EINVAL; } - ret = __change_op_cb_for_enable_disable_splash_screen(mpc, true); - if (ret < 0) { - ERR("__change_op_cb_for_enable_disable_splash_screen failed"); - return PKGMGR_R_ESYSTEM; - } - - ret = comm_client_request(mpc->info.request.cc, + ret = pkgmgr_client_connection_send_request(client, "enable_app_splash_screen", g_variant_new("(us)", uid, appid), &result); if (ret != PKGMGR_R_OK) { @@ -2064,12 +1698,9 @@ API int pkgmgr_client_usr_enable_splash_screen(pkgmgr_client *pc, } g_variant_get(result, "(i)", &ret); - if (ret != PKGMGR_R_OK) { - g_variant_unref(result); - return ret; - } - g_variant_unref(result); + if (ret != PKGMGR_R_OK) + ERR("enable splash screen failed: %d", ret); return ret; } @@ -2086,20 +1717,14 @@ API int pkgmgr_client_usr_disable_splash_screen(pkgmgr_client *pc, { int ret; GVariant *result; - pkgmgr_client_t *mpc = (pkgmgr_client_t *)pc; + struct pkgmgr_client_t *client = (struct pkgmgr_client_t *)pc; if (pc == NULL || appid == NULL) { ERR("Invalid parameter"); return PKGMGR_R_EINVAL; } - ret = __change_op_cb_for_enable_disable_splash_screen(mpc, false); - if (ret < 0) { - ERR("__change_op_cb_for_enable_disable_splash_screen failed"); - return ret; - } - - ret = comm_client_request(mpc->info.request.cc, + ret = pkgmgr_client_connection_send_request(client, "disable_app_splash_screen", g_variant_new("(us)", uid, appid), &result); if (ret != PKGMGR_R_OK) { @@ -2108,28 +1733,27 @@ API int pkgmgr_client_usr_disable_splash_screen(pkgmgr_client *pc, } g_variant_get(result, "(i)", &ret); - if (ret != PKGMGR_R_OK) { - g_variant_unref(result); - return ret; - } - g_variant_unref(result); + if (ret != PKGMGR_R_OK) + ERR("disable splash screen failed: %d", ret); return ret; } -static int __set_pkg_restriction_mode(pkgmgr_client *pc, const char *pkgid, int mode, uid_t uid) +static int __set_pkg_restriction_mode(pkgmgr_client *pc, const char *pkgid, + int mode, uid_t uid) { GVariant *result; int ret = PKGMGR_R_ECOMM; - pkgmgr_client_t *mpc = (pkgmgr_client_t *)pc; + struct pkgmgr_client_t *client = (struct pkgmgr_client_t *)pc; if (pc == NULL || pkgid == NULL || strlen(pkgid) == 0 || mode <= 0) { ERR("invalid parameter"); return PKGMGR_R_EINVAL; } - ret = comm_client_request(mpc->info.request.cc, "set_restriction_mode", + ret = pkgmgr_client_connection_send_request(client, + "set_restriction_mode", g_variant_new("(usi)", uid, pkgid, mode), &result); if (ret != PKGMGR_R_OK) { ERR("request failed: %d", ret); @@ -2142,28 +1766,32 @@ static int __set_pkg_restriction_mode(pkgmgr_client *pc, const char *pkgid, int return ret; } -API int pkgmgr_client_usr_set_pkg_restriction_mode(pkgmgr_client *pc, const char *pkgid, int mode, uid_t uid) +API int pkgmgr_client_usr_set_pkg_restriction_mode(pkgmgr_client *pc, + const char *pkgid, int mode, uid_t uid) { return __set_pkg_restriction_mode(pc, pkgid, mode, uid); } -API int pkgmgr_client_set_pkg_restriction_mode(pkgmgr_client *pc, const char *pkgid, int mode) +API int pkgmgr_client_set_pkg_restriction_mode(pkgmgr_client *pc, + const char *pkgid, int mode) { - return pkgmgr_client_usr_set_pkg_restriction_mode(pc, pkgid, mode, _getuid()); + return pkgmgr_client_usr_set_pkg_restriction_mode(pc, pkgid, mode, + _getuid()); } -static int __unset_pkg_restriction_mode(pkgmgr_client *pc, const char *pkgid, int mode, uid_t uid) +static int __unset_pkg_restriction_mode(pkgmgr_client *pc, const char *pkgid, + int mode, uid_t uid) { GVariant *result; int ret = PKGMGR_R_ECOMM; - pkgmgr_client_t *mpc = (pkgmgr_client_t *)pc; + struct pkgmgr_client_t *client = (struct pkgmgr_client_t *)pc; if (pc == NULL || pkgid == NULL || strlen(pkgid) == 0 || mode <= 0) { ERR("invalid parameter"); return PKGMGR_R_EINVAL; } - ret = comm_client_request(mpc->info.request.cc, + ret = pkgmgr_client_connection_send_request(client, "unset_restriction_mode", g_variant_new("(usi)", uid, pkgid, mode), &result); if (ret != PKGMGR_R_OK) { @@ -2178,29 +1806,33 @@ static int __unset_pkg_restriction_mode(pkgmgr_client *pc, const char *pkgid, in } -API int pkgmgr_client_usr_unset_pkg_restriction_mode(pkgmgr_client *pc, const char *pkgid, int mode, uid_t uid) +API int pkgmgr_client_usr_unset_pkg_restriction_mode(pkgmgr_client *pc, + const char *pkgid, int mode, uid_t uid) { return __unset_pkg_restriction_mode(pc, pkgid, mode, uid); } -API int pkgmgr_client_unset_pkg_restriction_mode(pkgmgr_client *pc, const char *pkgid, int mode) +API int pkgmgr_client_unset_pkg_restriction_mode(pkgmgr_client *pc, + const char *pkgid, int mode) { - return pkgmgr_client_usr_unset_pkg_restriction_mode(pc, pkgid, mode, _getuid()); + return pkgmgr_client_usr_unset_pkg_restriction_mode(pc, pkgid, mode, + _getuid()); } -static int __get_pkg_restriction_mode(pkgmgr_client *pc, const char *pkgid, int *mode, uid_t uid) +static int __get_pkg_restriction_mode(pkgmgr_client *pc, const char *pkgid, + int *mode, uid_t uid) { GVariant *result; int ret = PKGMGR_R_ECOMM; gint m; - pkgmgr_client_t *mpc = (pkgmgr_client_t *)pc; + struct pkgmgr_client_t *client = (struct pkgmgr_client_t *)pc; if (pc == NULL || pkgid == NULL || strlen(pkgid) == 0) { ERR("invalid parameter"); return PKGMGR_R_EINVAL; } - ret = comm_client_request(mpc->info.request.cc, + ret = pkgmgr_client_connection_send_request(client, "get_restriction_mode", g_variant_new("(us)", uid, pkgid), &result); if (ret != PKGMGR_R_OK) { @@ -2218,14 +1850,17 @@ static int __get_pkg_restriction_mode(pkgmgr_client *pc, const char *pkgid, int return PKGMGR_R_OK; } -API int pkgmgr_client_usr_get_pkg_restriction_mode(pkgmgr_client *pc, const char *pkgid, int *mode, uid_t uid) +API int pkgmgr_client_usr_get_pkg_restriction_mode(pkgmgr_client *pc, + const char *pkgid, int *mode, uid_t uid) { return __get_pkg_restriction_mode(pc, pkgid, mode, uid); } -API int pkgmgr_client_get_pkg_restriction_mode(pkgmgr_client *pc, const char *pkgid, int *mode) +API int pkgmgr_client_get_pkg_restriction_mode(pkgmgr_client *pc, + const char *pkgid, int *mode) { - return pkgmgr_client_usr_get_pkg_restriction_mode(pc, pkgid, mode, _getuid()); + return pkgmgr_client_usr_get_pkg_restriction_mode(pc, pkgid, mode, + _getuid()); } API int pkgmgr_client_usr_set_restriction_mode(pkgmgr_client *pc, int mode, @@ -2233,14 +1868,15 @@ API int pkgmgr_client_usr_set_restriction_mode(pkgmgr_client *pc, int mode, { GVariant *result; int ret = PKGMGR_R_ECOMM; - pkgmgr_client_t *mpc = (pkgmgr_client_t *)pc; + struct pkgmgr_client_t *client = (struct pkgmgr_client_t *)pc; if (pc == NULL) { ERR("invalid parameter"); return PKGMGR_R_EINVAL; } - ret = comm_client_request(mpc->info.request.cc, "set_restriction_mode", + ret = pkgmgr_client_connection_send_request(client, + "set_restriction_mode", g_variant_new("(usi)", uid, "", mode), &result); if (ret != PKGMGR_R_OK) { ERR("request failed: %d", ret); @@ -2263,14 +1899,14 @@ API int pkgmgr_client_usr_unset_restriction_mode(pkgmgr_client *pc, int mode, { GVariant *result; int ret = PKGMGR_R_ECOMM; - pkgmgr_client_t *mpc = (pkgmgr_client_t *)pc; + struct pkgmgr_client_t *client = (struct pkgmgr_client_t *)pc; if (pc == NULL) { ERR("invalid parameter"); return PKGMGR_R_EINVAL; } - ret = comm_client_request(mpc->info.request.cc, + ret = pkgmgr_client_connection_send_request(client, "unset_restriction_mode", g_variant_new("(usi)", uid, "", mode), &result); if (ret != PKGMGR_R_OK) { @@ -2295,14 +1931,14 @@ API int pkgmgr_client_usr_get_restriction_mode(pkgmgr_client *pc, GVariant *result; int ret = PKGMGR_R_ECOMM; gint m; - pkgmgr_client_t *mpc = (pkgmgr_client_t *)pc; + struct pkgmgr_client_t *client = (struct pkgmgr_client_t *)pc; if (pc == NULL) { ERR("invalid parameter"); return PKGMGR_R_EINVAL; } - ret = comm_client_request(mpc->info.request.cc, + ret = pkgmgr_client_connection_send_request(client, "get_restriction_mode", g_variant_new("(us)", uid, ""), &result); if (ret != PKGMGR_R_OK) { @@ -2320,8 +1956,7 @@ API int pkgmgr_client_usr_get_restriction_mode(pkgmgr_client *pc, return PKGMGR_R_OK; } -API int pkgmgr_client_get_restriction_mode(pkgmgr_client *pc, - int *mode) +API int pkgmgr_client_get_restriction_mode(pkgmgr_client *pc, int *mode) { return pkgmgr_client_usr_get_restriction_mode(pc, mode, _getuid()); } diff --git a/client/src/pkgmgr_client_connection.c b/client/src/pkgmgr_client_connection.c new file mode 100644 index 0000000..6a179a0 --- /dev/null +++ b/client/src/pkgmgr_client_connection.c @@ -0,0 +1,317 @@ +/* + * Copyright (c) 2016 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 +#include +#include +#include + +#include +#include + +#include "package-manager.h" +#include "pkgmgr_client_debug.h" +#include "pkgmgr_client_internal.h" +#include "../../installer/pkgmgr_installer.h" +#include "../../installer/pkgmgr_installer_config.h" + +#define CONNECTION_RETRY_MAX 5 +#define CONNECTION_WAIT_USEC (1000000 / 2) /* 0.5 sec */ +#define REGULAR_USER 5000 + +static int _is_system_user(void) +{ + uid_t uid = getuid(); + + if (uid < REGULAR_USER) + return 1; + else + return 0; +} + +static GBusType __get_bus_type(pkgmgr_client_type type) +{ + if (type == PC_REQUEST || _is_system_user()) + return G_BUS_TYPE_SYSTEM; + else + return G_BUS_TYPE_SESSION; +} + +int pkgmgr_client_connection_connect(struct pkgmgr_client_t *pc) +{ + GError *error = NULL; + GBusType bus_type; + +#if !GLIB_CHECK_VERSION(2, 35, 0) + g_type_init(); +#endif + bus_type = __get_bus_type(pc->pc_type); + pc->conn = g_bus_get_sync(bus_type, NULL, &error); + if (error) { + ERR("gdbus connection error (%s)", error->message); + g_error_free(error); + return PKGMGR_R_ECOMM; + } + + return PKGMGR_R_OK; +} + +void pkgmgr_client_connection_disconnect(struct pkgmgr_client_t *pc) +{ + /* flush remaining buffer: blocking mode */ + g_dbus_connection_flush_sync(pc->conn, NULL, NULL); + g_object_unref(pc->conn); + pc->conn = NULL; +} + +struct signal_map { + const char *signal_str; + int signal_type; +}; + +struct signal_map map[] = { + {PKGMGR_INSTALLER_INSTALL_EVENT_STR, PKGMGR_CLIENT_STATUS_INSTALL}, + {PKGMGR_INSTALLER_UNINSTALL_EVENT_STR, PKGMGR_CLIENT_STATUS_UNINSTALL}, + {PKGMGR_INSTALLER_UPGRADE_EVENT_STR, PKGMGR_CLIENT_STATUS_UPGRADE}, + {PKGMGR_INSTALLER_CLEAR_EVENT_STR, PKGMGR_CLIENT_STATUS_CLEAR_DATA}, + {PKGMGR_INSTALLER_MOVE_EVENT_STR, PKGMGR_CLIENT_STATUS_MOVE}, + {PKGMGR_INSTALLER_INSTALL_PERCENT_KEY_STR, + PKGMGR_CLIENT_STATUS_INSTALL_PROGRESS}, + {PKGMGR_INSTALLER_GET_SIZE_KEY_STR, PKGMGR_CLIENT_STATUS_GET_SIZE}, + {PKGMGR_INSTALLER_APP_ENABLE_EVENT_STR, + PKGMGR_CLIENT_STATUS_ENABLE_APP}, + {PKGMGR_INSTALLER_APP_DISABLE_EVENT_STR, + PKGMGR_CLIENT_STATUS_DISABLE_APP}, + {PKGMGR_INSTALLER_APP_ENABLE_SPLASH_SCREEN_EVENT_STR, + PKGMGR_CLIENT_STATUS_ENABLE_APP_SPLASH_SCREEN}, + {PKGMGR_INSTALLER_APP_DISABLE_SPLASH_SCREEN_EVENT_STR, + PKGMGR_CLIENT_STATUS_DISABLE_APP_SPLASH_SCREEN}, + {NULL, -1} +}; + +static int __get_signal_type(const char *name) +{ + int i; + + if (name == NULL) + return -1; + + for (i = 0; map[i].signal_str != NULL; i++) { + if (strcmp(map[i].signal_str, name) == 0) + return map[i].signal_type; + } + + return -1; +} + +static void __handle_size_info_callback(struct cb_info *cb_info, + const char *pkgid, const char *val) +{ + pkg_size_info_t size_info; + char buf[BUFMAX]; + char *saveptr; + char *token; + pkgmgr_total_pkg_size_info_receive_cb callback; + + snprintf(buf, sizeof(buf), "%s", val); + + DBG("%s, %s", pkgid, val); + + token = strtok_r(buf, ":", &saveptr); + if (token == NULL) { + ERR("failed to parse size info"); + return; + } + size_info.data_size = atoll(token); + token = strtok_r(NULL, ":", &saveptr); + if (token == NULL) { + ERR("failed to parse size info"); + return; + } + size_info.cache_size = atoll(token); + token = strtok_r(NULL, ":", &saveptr); + if (token == NULL) { + ERR("failed to parse size info"); + return; + } + size_info.app_size = atoll(token); + token = strtok_r(NULL, ":", &saveptr); + if (token == NULL) { + ERR("failed to parse size info"); + return; + } + size_info.ext_data_size = atoll(token); + token = strtok_r(NULL, ":", &saveptr); + if (token == NULL) { + ERR("failed to parse size info"); + return; + } + size_info.ext_cache_size = atoll(token); + token = strtok_r(NULL, ":", &saveptr); + if (token == NULL) { + ERR("failed to parse size info"); + return; + } + size_info.ext_app_size = atoll(token); + + DBG("data: %lld, cache: %lld, app: %lld, ext_data: %lld, " + "ext_cache: %lld, ext_app: %lld", + size_info.data_size, size_info.cache_size, + size_info.app_size, size_info.ext_data_size, + size_info.ext_cache_size, size_info.ext_app_size); + + if (strcmp(pkgid, PKG_SIZE_INFO_TOTAL) == 0) { + callback = (pkgmgr_total_pkg_size_info_receive_cb) + cb_info->size_info_cb; + callback(cb_info->client, &size_info, cb_info->data); + } else { + cb_info->size_info_cb(cb_info->client, pkgid, &size_info, + cb_info->data); + } +} + +static void __signal_handler(GDBusConnection *conn, const gchar *sender_name, + const gchar *object_path, const gchar *interface_name, + const gchar *signal_name, GVariant *parameters, + gpointer user_data) +{ + uid_t target_uid; + char *req_id; + char *pkg_type = NULL; + char *pkgid = NULL; + char *key = NULL; + char *val = NULL; + char *appid = NULL; + int signal_type; + struct cb_info *cb_info = (struct cb_info *)user_data; + + g_variant_get(parameters, "(u&s&s&s&s&s&s)", + &target_uid, &req_id, &pkg_type, + &pkgid, &appid, &key, &val); + + /* in case of request, check reqkey */ + if (cb_info->req_key) { + if (strcmp(cb_info->req_key, req_id) != 0) + return; + } else { + signal_type = __get_signal_type(signal_name); + if (signal_type < 0 || !(cb_info->status_type & signal_type)) + return; + } + + /* each cb_data can only has one callback */ + if (cb_info->event_cb) + cb_info->event_cb(target_uid, cb_info->req_id, + pkg_type, pkgid, key, val, NULL, cb_info->data); + else if (cb_info->app_event_cb) + cb_info->app_event_cb(target_uid, cb_info->req_id, + pkg_type, pkgid, appid, key, val, NULL, + cb_info->data); + else if (cb_info->size_info_cb) + __handle_size_info_callback(cb_info, pkgid, val); + + /* for request, unsubscribe if end signal received */ + if (cb_info->req_key && + (strcmp(key, "end") == 0 || strcmp(val, "end") == 0)) { + g_dbus_connection_signal_unsubscribe(cb_info->client->conn, + cb_info->sid); + cb_info->client->cb_info_list = g_list_remove( + cb_info->client->cb_info_list, + cb_info); + free(cb_info->req_key); + free(cb_info); + } +} + +int pkgmgr_client_connection_set_callback(struct pkgmgr_client_t *pc, + struct cb_info *cb_info) +{ + cb_info->sid = g_dbus_connection_signal_subscribe(pc->conn, NULL, + PKGMGR_INSTALLER_DBUS_INTERFACE, NULL, + PKGMGR_INSTALLER_DBUS_OBJECT_PATH, NULL, + G_DBUS_SIGNAL_FLAGS_NONE, __signal_handler, + (gpointer)cb_info, NULL); + if (!cb_info->sid) { + ERR("failed to subscribe singal"); + return PKGMGR_R_ERROR; + } + + return PKGMGR_R_OK; +} + +void pkgmgr_client_connection_unset_callback(struct pkgmgr_client_t *pc, + struct cb_info *cb_info) +{ + g_dbus_connection_signal_unsubscribe(pc->conn, cb_info->sid); +} + +int pkgmgr_client_connection_send_request(struct pkgmgr_client_t *pc, + const char *method, GVariant *params, GVariant **result) +{ + GError *error = NULL; + GDBusProxy *proxy; + GVariant *r = NULL; + int retry_cnt = 0; + int ret = PKGMGR_R_ECOMM; + + /* convert floating ref into normal ref */ + g_variant_ref_sink(params); + + do { + proxy = g_dbus_proxy_new_sync(pc->conn, G_DBUS_PROXY_FLAGS_NONE, + NULL, PKGMGR_DBUS_SERVICE, + PKGMGR_DBUS_OBJECT_PATH, + PKGMGR_DBUS_INTERFACE, NULL, &error); + if (proxy == NULL) { + ERR("failed to get proxy object, sleep and retry[%s]", + error->message); + g_error_free(error); + error = NULL; + usleep(CONNECTION_WAIT_USEC); + retry_cnt++; + continue; + } + + r = g_dbus_proxy_call_sync(proxy, method, params, + G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error); + g_object_unref(proxy); + if (error && error->code == G_DBUS_ERROR_ACCESS_DENIED) { + ERR("failed to send request, privilege denied[%s]", + error->message); + g_error_free(error); + ret = PKGMGR_R_EPRIV; + break; + } + if (r) { + *result = r; + ret = PKGMGR_R_OK; + break; + } + + ERR("failed to send request, sleep and retry[%s]", + error->message); + g_error_free(error); + error = NULL; + usleep(CONNECTION_WAIT_USEC); + retry_cnt++; + } while (retry_cnt <= CONNECTION_RETRY_MAX); + + /* decrease ref count to 0 to free resource */ + g_variant_unref(params); + + return ret; +} diff --git a/client/include/pkgmgr-debug.h b/client/src/pkgmgr_client_debug.h similarity index 94% rename from client/include/pkgmgr-debug.h rename to client/src/pkgmgr_client_debug.h index 5badc7c..b81f948 100644 --- a/client/include/pkgmgr-debug.h +++ b/client/src/pkgmgr_client_debug.h @@ -1,6 +1,4 @@ /* - * pkgmgr-debug - * * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. * * Contact: junsuk. oh @@ -19,8 +17,8 @@ * */ -#ifndef __PKGMGR_DEBUG_H__ -#define __PKGMGR_DEBUG_H__ +#ifndef __PKGMGR_CLIENT_DEBUG_H__ +#define __PKGMGR_CLIENT_DEBUG_H__ #include @@ -90,4 +88,4 @@ } \ } while (0) -#endif /* __PKGMGR_DEBUG_H__ */ +#endif /* __PKGMGR_CLIENT_DEBUG_H__ */ diff --git a/client/src/pkgmgr-internal.c b/client/src/pkgmgr_client_internal.c similarity index 99% rename from client/src/pkgmgr-internal.c rename to client/src/pkgmgr_client_internal.c index d8cb2f4..0712202 100644 --- a/client/src/pkgmgr-internal.c +++ b/client/src/pkgmgr_client_internal.c @@ -30,16 +30,15 @@ #include #include -#include "pkgmgr-internal.h" -#include "pkgmgr-debug.h" - #include #include #include #include +#include #include "package-manager.h" -#include +#include "pkgmgr_client_debug.h" +#include "pkgmgr_client_internal.h" #define GLOBAL_USER tzplatform_getuid(TZ_SYS_GLOBALAPP_USER) diff --git a/client/include/pkgmgr-internal.h b/client/src/pkgmgr_client_internal.h similarity index 68% rename from client/include/pkgmgr-internal.h rename to client/src/pkgmgr_client_internal.h index 7955c30..fd9ba51 100644 --- a/client/include/pkgmgr-internal.h +++ b/client/src/pkgmgr_client_internal.h @@ -20,17 +20,50 @@ * */ - - - - -#ifndef __PKG_MANAGER_INTERNAL_H__ -#define __PKG_MANAGER_INTERNAL_H__ +#ifndef __PKGMGR_CLIENT_INTERNAL_H__ +#define __PKGMGR_CLIENT_INTERNAL_H__ #include #include +#include +#include + #include "package-manager-plugin.h" +#include "package-manager.h" + +#define BUFMAX 4096 + +struct cb_info { + int req_id; + char *req_key; + int status_type; + pkgmgr_handler event_cb; + pkgmgr_app_handler app_event_cb; + pkgmgr_pkg_size_info_receive_cb size_info_cb; + void *data; + struct pkgmgr_client_t *client; + guint sid; +}; + +struct pkgmgr_client_t { + pkgmgr_client_type pc_type; + int status_type; + GDBusConnection *conn; + GList *cb_info_list; + char *tep_path; + bool tep_move; +}; + +int pkgmgr_client_connection_connect(struct pkgmgr_client_t *pc); +void pkgmgr_client_connection_disconnect(struct pkgmgr_client_t *pc); +int pkgmgr_client_connection_set_callback(struct pkgmgr_client_t *pc, + struct cb_info *cb_info); +void pkgmgr_client_connection_unset_callback(struct pkgmgr_client_t *pc, + struct cb_info *cb_info); +int pkgmgr_client_connection_send_request(struct pkgmgr_client_t *pc, + const char *method, GVariant *params, GVariant **result); + typedef package_manager_pkg_info_t package_manager_app_info_t; @@ -77,4 +110,4 @@ char *_get_backend_path_with_type(const char *type); int _get_mime_from_file(const char *filename, char *mimetype, int len); int _get_mime_extension(const char *mimetype, char *ext, int len); -#endif /* __PKG_MANAGER_INTERNAL_H__ */ +#endif /* __PKGMGR_CLIENT_INTERNAL_H__ */ -- 2.7.4