From 92c05dab0009cba5ab478b94d1a73f8cf9bc43db Mon Sep 17 00:00:00 2001 From: Jeonghoon Park Date: Tue, 10 Apr 2018 15:13:49 +0900 Subject: [PATCH] updates installer module functions to remove dependency from other modules --- inc/installer.h | 26 +++++++++++-- src/installer.c | 113 +++++++++++++++++++++++++++++++++++++------------------- 2 files changed, 98 insertions(+), 41 deletions(-) mode change 100755 => 100644 src/installer.c diff --git a/inc/installer.h b/inc/installer.h index fdf22b4..09b0854 100644 --- a/inc/installer.h +++ b/inc/installer.h @@ -1,6 +1,24 @@ -#ifndef __INSTALLER_H__ -#define __INSTALLER_H__ +/* + * Copyright (c) 2018 Samsung Electronics Co., Ltd. + * + * Licensed under the Flora License, Version 1.1 (the License); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://floralicense.org/license/ + * + * 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. + */ -void installer_install(char *path); +#ifndef __PM_INSTALLER_H__ +#define __PM_INSTALLER_H__ -#endif /* __INSTALLER_H__ */ +typedef void (pm_installer_res_cb)(const char *package, int result, void *user_data); + +int pm_installer_install(const char *path, pm_installer_res_cb *result_cb, void *cb_data); + +#endif /* __PM_INSTALLER_H__ */ diff --git a/src/installer.c b/src/installer.c old mode 100755 new mode 100644 index 8612605..20d3e06 --- a/src/installer.c +++ b/src/installer.c @@ -1,44 +1,83 @@ -#include "installer.h" +/* + * Copyright (c) 2018 Samsung Electronics Co., Ltd. + * + * Licensed under the Flora License, Version 1.1 (the License); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://floralicense.org/license/ + * + * 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 "log.h" -#include "package-manager-result.h" +#include "installer.h" #include -#include -#include +#include -static package_manager_request_h handle; +typedef struct __pm_installer_s { + package_manager_request_h handle; + int request_id; + pm_installer_res_cb *result_cb; + void * cb_data; +} pm_installer_s; static void _install_cb(int id, const char *type, const char *package, - package_manager_event_type_e event_type, - package_manager_event_state_e event_state, int progress, - package_manager_error_e error, void *user_data) { - if (event_type == PACKAGE_MANAGER_EVENT_TYPE_INSTALL || - event_type == PACKAGE_MANAGER_EVENT_TYPE_UPDATE) { - if (event_state == PACKAGE_MANAGER_EVENT_STATE_COMPLETED) { - _D("Install Success"); - package_manager_request_destroy(handle); - package_manager_result_install(package, true); - } else if (event_state == PACKAGE_MANAGER_EVENT_STATE_FAILED) { - _D("Install Fail"); - package_manager_request_destroy(handle); - package_manager_result_install(package, false); - } - } + package_manager_event_type_e event_type, + package_manager_event_state_e event_state, int progress, + package_manager_error_e error, void *user_data) +{ + pm_installer_s *pmi_d = user_data; + + if (event_type == PACKAGE_MANAGER_EVENT_TYPE_INSTALL || + event_type == PACKAGE_MANAGER_EVENT_TYPE_UPDATE) { + if (event_state == PACKAGE_MANAGER_EVENT_STATE_COMPLETED) { + _D("Install Success"); + if (pmi_d->result_cb) + pmi_d->result_cb(package, 0, pmi_d->cb_data); + package_manager_request_destroy(pmi_d->handle); + g_free(pmi_d); + + } else if (event_state == PACKAGE_MANAGER_EVENT_STATE_FAILED) { + _E("Install Fail (%d)", error); + if (pmi_d->result_cb) + pmi_d->result_cb(package, -1, pmi_d->cb_data); /* TODO : set error code from result value */ + package_manager_request_destroy(pmi_d->handle); + g_free(pmi_d); + } + } } -void installer_install(char *path) { - int ret = 0; - int request_id = 0; - - ret = package_manager_request_create(&handle); - if (ret != PACKAGE_MANAGER_ERROR_NONE) { - _D("Fail create package manager request handle : %d(%s)", ret, - get_error_message(ret)); - return; - } - ret = package_manager_request_install_with_cb(handle, path, _install_cb, - NULL, &request_id); - if (ret != PACKAGE_MANAGER_ERROR_NONE) { - _D("Fail request package manager install : %d(%s)", ret, - get_error_message(ret)); - } -} \ No newline at end of file +int pm_installer_install(const char *path, pm_installer_res_cb *result_cb, void *cb_data) +{ + int ret = 0; + int request_id = 0; + pm_installer_s *pmi_d = NULL; + + pmi_d = g_malloc0(sizeof(pm_installer_s)); + pmi_d->result_cb = result_cb; + pmi_d->cb_data = cb_data; + + ret = package_manager_request_create(&pmi_d->handle); + if (ret != PACKAGE_MANAGER_ERROR_NONE) { + _E("Fail create package manager request handle : %d(%s)", ret, + get_error_message(ret)); + g_free(pmi_d); + return -1; + } + ret = package_manager_request_install_with_cb(pmi_d->handle, path, _install_cb, + pmi_d, &request_id); + + if (ret != PACKAGE_MANAGER_ERROR_NONE) { + _E("Fail request package manager install : %d(%s)", ret, + get_error_message(ret)); + g_free(pmi_d); + return -1; + } + + return 0; +} -- 2.7.4