1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
|
/*
* 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;
}
|