summaryrefslogtreecommitdiff
path: root/src/pm_installer.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/pm_installer.c')
-rw-r--r--src/pm_installer.c84
1 files changed, 84 insertions, 0 deletions
diff --git a/src/pm_installer.c b/src/pm_installer.c
new file mode 100644
index 0000000..85ce1af
--- /dev/null
+++ b/src/pm_installer.c
@@ -0,0 +1,84 @@
+/*
+ * 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 "pm_installer.h"
+#include <package_manager.h>
+#include <glib.h>
+
+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)
+{
+ 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);
+ }
+ }
+}
+
+int pm_installer_install(const char *path, pm_installer_res_cb result_cb, void *cb_data)
+{
+ _D("Install Start");
+ 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;
+}