Fix build failure: call to dlog API
[platform/core/base/rpm-installer.git] / frontend / src / rpm-appcore-intf.c
1 /*
2  * rpm-installer
3  *
4  * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
5  *
6  * Contact: Jayoun Lee <airjany@samsung.com>, Sewook Park <sewook7.park@samsung.com>,
7  * Jaeho Lee <jaeho81.lee@samsung.com>, Shobhit Srivastava <shobhit.s@samsung.com>
8  *
9  * Licensed under the Apache License, Version 2.0 (the "License");
10  * you may not use this file except in compliance with the License.
11  * You may obtain a copy of the License at
12  *
13  * http://www.apache.org/licenses/LICENSE-2.0
14  *
15  * Unless required by applicable law or agreed to in writing, software
16  * distributed under the License is distributed on an "AS IS" BASIS,
17  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18  * See the License for the specific language governing permissions and
19  * limitations under the License.
20  *
21  */
22
23 #include <stdio.h>
24 #include <pthread.h>
25
26 #include <Elementary.h>
27 #include <appcore-efl.h>
28 #include <string.h>
29 #include <glib-object.h>
30
31 #include "rpm-frontend.h"
32 #include "rpm-homeview.h"
33 #include "rpm-installer-util.h"
34 #include "rpm-installer.h"
35 #include <pkgmgr_installer.h>
36
37 static void __ri_start_processing(void *user_data);
38 static Eina_Bool __ri_elm_exit_cb(void *data);
39
40 int ret_val = -1;
41 struct appdata ad;
42 extern char scrolllabel[256];
43 extern ri_frontend_data front_data;
44 pkgmgr_installer *pi = NULL;
45
46 /**< Called before main loop */
47 int app_create(void *user_data)
48 {
49
50         int ret = 0;
51         struct appdata *data = (struct appdata *)user_data;
52         ri_frontend_cmdline_arg *fdata = front_data.args;
53         /*In case of downgrade, popup should be shown even if quiet mode*/
54         ret = _ri_frontend_launch_main_view(data);
55         return ret;
56 }
57
58 /**< Called after main loop */
59 int app_terminate(void *user_data)
60 {
61         struct appdata *data = (struct appdata *)user_data;
62         ri_frontend_cmdline_arg *fdata = front_data.args;
63         if (fdata->quiet == 0) {
64                 _ri_destroy_home_view(data);
65         }
66         return 0;
67 }
68
69 /**< Called when every window goes back */
70 int app_pause(void *user_data)
71 {
72         return 0;
73 }
74
75 /**< Called when any window comes on top */
76 int app_resume(void *user_data)
77 {
78         return 0;
79 }
80
81 /**< Called at the first idler*/
82 int app_reset(bundle *b, void *user_data)
83 {
84         return 0;
85 }
86
87 /**< Called at rotate device*/
88 int app_rotation(enum appcore_rm mode, void *user_data)
89 {
90         if (user_data == NULL) {
91                 _d_msg(DEBUG_ERR, "arg supplied is NULL \n");
92                 return -1;
93         }
94         struct appdata *data = (struct appdata *)user_data;
95         int angle;
96         switch (mode) {
97         case APPCORE_RM_LANDSCAPE_NORMAL:
98                 angle = -90;
99                 break;
100
101         case APPCORE_RM_LANDSCAPE_REVERSE:
102                 angle = 90;
103                 break;
104
105         case APPCORE_RM_PORTRAIT_REVERSE:
106                 angle = 180;
107                 break;
108
109         case APPCORE_RM_UNKNOWN:
110         case APPCORE_RM_PORTRAIT_NORMAL:
111         default:
112                 angle = 0;
113                 break;
114         }
115         elm_win_rotation_with_resize_set(data->win_main, angle);
116         return 0;
117 }
118
119 Eina_Bool show_popup_cb(void *data)
120 {
121         /*Avoid log printing as it is an idler function*/
122         int state = -1;
123         int ret = -1;
124         const char message[256] = {'\0'};
125         state = _ri_get_backend_state_info();
126         switch (state) {
127         case REQUEST_ACCEPTED:
128                 break;
129         case GOT_PACKAGE_INFO_SUCCESSFULLY:
130                 break;
131         case REQUEST_PENDING:
132                 strncpy(message, _("Continue Downgrade?"), 255);
133                 _ri_package_downgrade_information(message);
134                 /*request is not completed yet. We just got confirmation
135                 from user whether to downgrade or not*/
136                 _ri_set_backend_state_info(REQUEST_ACCEPTED);
137                 break;
138         case REQUEST_COMPLETED:
139         default:
140                 if (front_data.args->quiet == 0) {
141                         _ri_frontend_update_progress_info(&ad, scrolllabel);
142                         return 0;
143                 } else
144                         elm_exit();
145                 break;
146         }
147
148         return 1;
149 }
150
151 static void __ri_start_processing(void *user_data)
152 {
153         int ret = 0;
154         if (user_data == NULL) {
155                 _d_msg(DEBUG_ERR, "arg supplied is NULL \n");
156                 return -1;
157         }
158         ri_frontend_data *data = (ri_frontend_data *) user_data;
159         g_type_init();
160         ret = _ri_cmdline_process(data);
161         ret_val = ret;
162         _ri_cmdline_destroy(data);
163
164 }
165
166 int main(int argc, char *argv[])
167 {
168         int ret = 0;
169         ri_frontend_cmdline_arg *data = NULL;
170         struct appcore_ops ops;
171         ops.create = app_create;
172         ops.terminate = app_terminate;
173         ops.pause = app_pause;
174         ops.resume = app_resume;
175         ops.reset = app_reset;
176         ops.data = &ad;
177         ecore_init();
178         appcore_set_i18n(PACKAGE, LOCALE_PATH);
179         _d_msg_init("rpm-installer");
180         data = (ri_frontend_cmdline_arg *) calloc(1,
181                                                   sizeof
182                                                   (ri_frontend_cmdline_arg));
183         if (data == NULL) {
184                 _d_msg(DEBUG_ERR, "Not Enough Memory\n");
185                 ret = RPM_INSTALLER_ERR_NOT_ENOUGH_MEMORY;
186                 goto ERROR;
187         }
188         data->keyid = NULL;
189         data->pkgid = NULL;
190         data->quiet = 0;
191         data->req_cmd = INVALID_CMD;
192         data->move_type = -1;
193
194         /* We need to use pkgmgr_installer_receive request()
195            to parse the arguments */
196         if ((ret =
197              _ri_parse_cmdline(argc, argv, data)) != RPM_INSTALLER_SUCCESS) {
198                 _d_msg(DEBUG_ERR, "_ri_parse_cmdline failed \n");
199                 goto ERROR;
200         }
201
202         front_data.args = data;
203         front_data.security_cookie = NULL;
204         front_data.error = NULL;
205
206         __ri_start_processing(&front_data);
207
208         /*The installer has finished the installation/uninstallation.
209            Now, if it was a non quiet operation we need to show the popup. */
210         ecore_idler_add(show_popup_cb, NULL);
211
212         _d_msg(DEBUG_RESULT, "About to run EFL Main Loop");
213         appcore_efl_main(PACKAGE, &argc, &argv, &ops);
214         _d_msg(DEBUG_RESULT, "%d\n", ret_val);
215
216         _d_msg_deinit();
217         if (pi) {
218                 pkgmgr_installer_free(pi);
219                 pi = NULL;
220         }
221         if(!ret_val)
222                 sync();
223
224         return ret_val;
225
226  ERROR:
227         if (data) {
228                 if (data->pkgid) {
229                         free(data->pkgid);
230                         data->pkgid = NULL;
231                 }
232                 if (data->keyid) {
233                         free(data->keyid);
234                         data->keyid = NULL;
235                 }
236                 free(data);
237                 data = NULL;
238         }
239         _d_msg(DEBUG_RESULT, "%d\n", ret);
240         _d_msg_deinit();
241         return ret;
242
243 }