Initialize Tizen 2.3
[framework/system/oma-dm-agent.git] / src / agent / framework / ui-event-handler / ipc_agent.c
1 /*
2  * oma-dm-agent
3  * Copyright (c) 2012 Samsung Electronics Co., Ltd.
4  *
5  * Licensed under the Apache License, Version 2.0 (the License);
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  *     http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */
17
18 /*lib*/
19 #include <stdio.h>
20 #include <aul.h>
21
22 #include <vconf.h>
23 #include <vconf-keys.h>
24
25 /*sync-agent*/
26 #include <sync_agent.h>
27
28 /*dm-agent*/
29 #include "common/dm_common.h"
30 #include "common/util/util.h"
31 #include "framework/platform-event-handler/dm_platform_event_handler_internal.h"
32 #include "framework/task/oma_dm_task_request.h"
33 #include "dm-engine/fumo/fumo_account.h"
34 #include "dm-engine/fumo/fumo_engine_internal.h"
35 #include "dm-engine/cp/dm_cp_processor.h"
36 #include "mo-handler/dm_mo_common.h"
37 #include "mo-handler/dm_mo_common_internal.h"
38 #include "ipc_common.h"
39 #include "ipc_agent.h"
40
41 #ifndef OMADM_AGENT_LOG
42 #undef LOG_TAG
43 #define LOG_TAG "OMA_DM_IPC"
44 #endif
45
46 static gint64 timeout;
47 static GMutex mutex;
48 static GCond cond;
49
50 #define TIMEOUT_VAL_UIC 60      //uic time out time
51 #define REST_TIMEOUT_VAL 10
52
53 static gint64 uic_timeout_val = 0;
54
55 static uic_res_data *res_uic_data = NULL;
56
57 static int (*_get_event_callback(int event_id)) (sync_agent_event_data_s * request, sync_agent_event_data_s * response);
58
59 static int __event_callback_software_update(sync_agent_event_data_s * request, sync_agent_event_data_s * response);
60 static int __event_callback_cancel(sync_agent_event_data_s * request, sync_agent_event_data_s * response);
61 static int __event_callback_download(sync_agent_event_data_s * request, sync_agent_event_data_s * response);
62 static int __event_callback_install(sync_agent_event_data_s * request, sync_agent_event_data_s * response);
63 static int __event_callback_set_interval(sync_agent_event_data_s * request, sync_agent_event_data_s * response);
64
65 static int __event_callback_account_registration(sync_agent_event_data_s * request, sync_agent_event_data_s * response);
66
67 static int __event_callback_get_profile(sync_agent_event_data_s * request, sync_agent_event_data_s * response);
68 static int __event_callback_set_profile(sync_agent_event_data_s * request, sync_agent_event_data_s * response);
69 static int __event_callback_reset_profile(sync_agent_event_data_s * request, sync_agent_event_data_s * response);
70
71 static int __event_callback_uic_alert(sync_agent_event_data_s * request, sync_agent_event_data_s * response);
72
73 static int __event_callback_get_fumo_config(sync_agent_event_data_s * request, sync_agent_event_data_s * response);
74 static int __event_callback_set_fumo_config_wifi_only(sync_agent_event_data_s * request, sync_agent_event_data_s * response);
75
76 static int __event_callback_check_pin_code(sync_agent_event_data_s * request, sync_agent_event_data_s * response);
77 static int __event_callback_default(sync_agent_event_data_s * request, sync_agent_event_data_s * response);
78
79 static int __event_add_dmacc(sync_agent_event_data_s * request, sync_agent_event_data_s * response);
80 static int __event_remove_dmacc(sync_agent_event_data_s * request, sync_agent_event_data_s * response);
81
82 static int _IPC_noti(int noti_type, int noti_id, int input_param, char *input_string, void *user_data);
83 static sync_agent_event_ipc_cancel_e __dm_task_process_check_cancel_flag(void *user_data);
84
85 static int __check_ui_mode(char **ui_mode, char *input_string);
86 static int __launch_ui(char *ui_mode, int noti_type);
87
88 static int __uic_response(int noti_id, void *user_data);
89
90 static int __check_ui_mode(char **ui_mode, char *input_string)
91 {
92         _INNER_FUNC_ENTER;
93
94         if (*ui_mode == NULL) {
95                 _DEBUG_VERBOSE("ui mode is NULL");
96                 if (input_string != NULL) {
97                         _DEBUG_VERBOSE("input_string : %s", input_string);
98                         if (strcmp(input_string, OMADM_ALERT_UI_TYPE) == 0 || strcmp(input_string, OMADM_FUMO_NOTI_UI_TYPE) == 0 || strcmp(input_string, OMADM_FUMO_UI_TYPE) == 0 || strcmp(input_string, OMADM_FUMO_BACKGROUND_UI_TYPE) == 0) {
99
100                                 *ui_mode = strdup(input_string);
101                         } else {
102                                 //do nothing
103                         }
104                 } else {
105                         _DEBUG_VERBOSE("ERROR UI MODE NULL");
106                         _INNER_FUNC_EXIT;
107                         return RESPONSE_TYPE_CANCEL;
108                 }
109         } else {
110                 _DEBUG_VERBOSE("ui mode : %s", *ui_mode);
111                 _DEBUG_VERBOSE("input_string : %s", input_string);
112                 if (input_string != NULL) {
113                         if (strcmp(input_string, OMADM_ALERT_UI_TYPE) == 0 || strcmp(input_string, OMADM_FUMO_NOTI_UI_TYPE) == 0 || strcmp(input_string, OMADM_FUMO_UI_TYPE) == 0 || strcmp(input_string, OMADM_FUMO_BACKGROUND_UI_TYPE) == 0) {
114
115                                 str_free(ui_mode);
116                                 *ui_mode = strdup(input_string);
117                         } else {
118                                 //do nothing
119                         }
120                 } else {
121                         //do nothing
122                 }
123         }
124
125         _INNER_FUNC_EXIT;
126         return RESPONSE_TYPE_OK;
127 }
128
129 //static int __launch_ui(char *ui_mode, int noti_type)
130 static int __launch_ui(char *ui_mode, int noti_id)
131 {
132         _INNER_FUNC_ENTER;
133
134         int ui_ret = 1;
135
136         if (ui_mode != NULL) {
137                 //_DEBUG_INFO("ui_mode[%s], noti_type[%d]", ui_mode, noti_type);
138                 _DEBUG_INFO("ui_mode[%s], noti_id[%d]", ui_mode, noti_id);
139
140                 if (strcmp(ui_mode, OMADM_FUMO_UI_TYPE) == 0) {
141                         ui_ret = launch_oma_dm_fumo_ui();
142                         _DEBUG_INFO("fumo ui : %d", ui_ret);
143                 } else if (strcmp(ui_mode, OMADM_FUMO_NOTI_UI_TYPE) == 0) {
144                         DM_ERROR ret_poll = DM_OK;
145                         char *server_id = NULL;
146                         ret_poll = get_Serverid(SAMSUNG_FUMO_TYPE, &server_id);
147                         if (ret_poll!= DM_OK || server_id == NULL) {
148                                 ui_ret = launch_om_dm_fumo_noti_ui(NOTI_TYPE_USERINTERACTION, NULL, NULL, POLL_EVENT);
149                         } else {
150                                 ui_ret = launch_om_dm_fumo_noti_ui(NOTI_TYPE_USERINTERACTION, NULL, server_id, POLL_EVENT);
151                                 free(server_id);
152                         }
153                         _DEBUG_INFO("noti ui : %d", ui_ret);
154                 } else if (strcmp(ui_mode, OMADM_FUMO_BACKGROUND_UI_TYPE) == 0) {
155                         //if (noti_type == NOTI_INSTALL) {
156                         if (noti_id == NOTI_INSTALL) {
157                                 ui_ret = launch_om_dm_fumo_noti_ui(NOTI_TYPE_BACKGRUOUND, NULL, NULL, 0);
158                                 _DEBUG_INFO("noti ui : %d", ui_ret);
159                         }
160                         _DEBUG_INFO("background ui");
161                         _INNER_FUNC_EXIT;
162                         return 0;
163                 } else if (strcmp(ui_mode, OMADM_ALERT_UI_TYPE) == 0) {
164                         ui_ret = launch_om_dm_fumo_alert_ui();
165                         _DEBUG_INFO("alert ui : %d", ui_ret);
166                 } else {
167                         _INNER_FUNC_EXIT;
168                         return -1;
169                 }
170
171                 if (ui_ret == 0) {
172                         _DEBUG_INFO("UI launch fail");
173                         _INNER_FUNC_EXIT;
174                         return -1;
175                 }
176
177         } else {
178                 _DEBUG_INFO("ERROR UI MODE NULL");
179                 _INNER_FUNC_EXIT;
180                 return -1;
181         }
182         _INNER_FUNC_EXIT;
183         return 1;
184 }
185
186 static int (*_get_event_callback(int event_id)) (sync_agent_event_data_s * request, sync_agent_event_data_s * response) {
187         _DEBUG_TRACE("%s: start (event_id:%d)\n", __func__, event_id);
188
189         switch (event_id) {
190         case EVENT_SOFTWARE_UPDATE:     // Type 0, Replies Exist
191
192                 return __event_callback_software_update;
193                 break;
194
195         case EVENT_CANCEL:      // Type 0, No Reply
196
197                 return __event_callback_cancel;
198                 break;
199
200         case EVENT_DOWNLOAD:    // Type 0, No Reply
201
202                 return __event_callback_download;
203                 break;
204
205         case EVENT_INSTALL:     // Type 0, No Reply
206                 return __event_callback_install;
207                 break;
208
209         case EVENT_SET_INTERVAL:
210                 return __event_callback_set_interval;
211                 break;
212
213         case EVENT_ACCOUNT_REGISTRATION:
214                 return __event_callback_account_registration;
215                 break;
216
217         case EVENT_GET_FUMO_CONFIG:
218                 return __event_callback_get_fumo_config;
219                 break;
220
221         case EVENT_SET_FUMO_CONFIG:
222                 return __event_callback_set_fumo_config_wifi_only;
223                 break;
224
225         case EVENT_GET_PROFILE:
226                 return __event_callback_get_profile;
227                 break;
228
229         case EVENT_SET_PROFILE:
230                 return __event_callback_set_profile;
231                 break;
232
233         case EVENT_SET_RESET_PROFILE:
234                 return __event_callback_reset_profile;
235                 break;
236
237         case EVENT_UIC_ALERT:
238                 return __event_callback_uic_alert;
239                 break;
240
241         case EVENT_CHECK_PIN_CODE:
242                 return __event_callback_check_pin_code;
243                 break;
244
245         case EVENT_ADD_DMACC:
246                 return __event_add_dmacc;
247                 break;
248
249         case EVENT_REMOVE_DMACC:
250                 return __event_remove_dmacc;
251                 break;
252
253         default:
254                 return __event_callback_default;
255                 break;
256         }
257
258 }
259
260 // Type 0, No Reply
261 static int __event_callback_software_update(sync_agent_event_data_s * request, sync_agent_event_data_s * response)
262 {
263         _INNER_FUNC_ENTER;
264         //2012.11.20
265         EVENT_RESPONSE ev_response = EVENT_RESPONSE_OK;
266
267 #if 1
268         //      IPC_EVENT_TYPE_0;
269         /*sleep(10); // for test */
270
271         DM_ERROR ret;
272         retvm_if((request) == NULL, 0, "request is NULL!!");
273
274         UI_TYPE ui_type;
275         char *session_id = NULL;
276         char *fota_ui_type = NULL;
277         char *server_id = NULL;
278         Event_Type triger_type = POLL_EVENT;
279         int task_id = 0;
280         SERVICE_SERVER_TYPE server_type = SAMSUNG_FUMO_TYPE;
281         OPER_MODE operationMode = OPER_UNKNOWN;
282         NotI_Type noti_type = NOTI_TYPE_NOT_SPECIFIED;
283
284         sync_agent_get_event_data_param_int(request, (int*) &ui_type);
285         _DEBUG_INFO("UI TYPE : %d\n", ui_type);
286
287         switch (ui_type) {
288         case FOTA_COMMON_UI:
289                 _DEBUG_INFO("common ui");
290                 fota_ui_type = OMADM_FUMO_UI_TYPE;
291                 sync_agent_get_event_data_param_int(request, &task_id);
292                 _DEBUG_INFO("get task id : %d", task_id);
293                 sync_agent_get_event_data_param_int(request, (int*) &server_type);
294                 triger_type = UI_EVENT;
295                 ret = get_Serverid(server_type, &server_id);
296                 //ret =get_Serverid(SAMSUNG_FUMO_TYPE , &server_id);
297                 //ret =get_Serverid(GCF_TYPE , &server_id);
298                 _DEBUG_INFO("get server id : %s : %d", server_id, ret);
299                 operationMode = OPER_USER_INITIATION;
300                 break;
301         case FOTA_NOTI_UI:
302                 _DEBUG_INFO("noti ui");
303                 fota_ui_type = OMADM_FUMO_NOTI_UI_TYPE;
304                 sync_agent_get_event_data_param_str(request, &session_id);
305                 sync_agent_get_event_data_param_str(request, &server_id);
306                 sync_agent_get_event_data_param_int(request,(int*) &triger_type);
307                 _DEBUG_INFO("get session id : %s", session_id);
308                 _DEBUG_INFO("get server id : %s", server_id);
309                 _DEBUG_INFO("get triger_type : %d", triger_type);
310
311                 operationMode = OPER_SERVER_INITIATION_FROM_IP;
312                 break;
313         case FOTA_BACKGROUND_UI:
314                 _DEBUG_INFO("background ui");
315                 break;
316         case ADMIN_UI:
317                 _DEBUG_INFO("admin ui");
318                 fota_ui_type = OMADM_ADMIN_UI_TYPE;
319                 sync_agent_get_event_data_param_int(request, (int*) &server_type);
320                 ret = get_Serverid(server_type, &server_id);
321                 _DEBUG_INFO("get server id : %s : %d", server_id, ret);
322                 operationMode = OPER_USER_INITIATION;
323                 break;
324         case CP_UI:
325                 _DEBUG_INFO("cp ui");
326                 break;
327         default:
328                 _DEBUG_INFO("not use ui");
329                 break;
330         }
331
332         if (server_id != NULL) {
333                 _DEBUG_INFO("fumo server id = %s", server_id);
334                 Event_Contents *ev_data = (Event_Contents *) calloc(1, sizeof(Event_Contents));
335                 if (ev_data == NULL) {
336                         _DEBUG_INFO("alloc fail");
337                         goto error;
338                 }
339                 //ev_data->type = UI_EVENT;
340                 //ev_data->type = IP_PUSH_EVENT;
341                 ev_data->type = triger_type;
342                 _DEBUG_INFO("get triger_type : %d", triger_type);
343                 if (session_id != NULL)
344                         ev_data->session_id = strdup(session_id);
345                 if (server_id != NULL) {
346                         ev_data->server_id = strdup(server_id);
347                         str_free(&server_id);
348                 }
349                 ev_data->noti_type = noti_type;
350                 ev_data->ui_mode = strdup(fota_ui_type);
351
352                 ret = dm_fumo_common_task_request(ev_data);
353                 if (ret != DM_OK) {
354                         event_data_free((void *)ev_data);
355                         goto error;
356                 }
357         } else {
358                 goto error;
359         }
360
361         //2012.11.20
362         sync_agent_append_event_data_param(response, SYNC_AGENT_EVENT_PARAM_TYPE_INTEGER, &ev_response);
363
364 #else
365
366         // IPC_EVENT_TYPE_1;
367         int response_int = REPLY_FAIL_TO_CONNECT;       //initial value
368
369         //Todo ------------------------------------------------------------------------------------------------------------------------    (from here)
370         sleep(10);              // for test
371
372         response_int = REPLY_SUCCESS_TO_CONNECT;        // resulted value
373         // ----------------------------------------------------------------------------------------------------------------------------------    (end)
374         sync_agent_append_event_data_param(response, SYNC_AGENT_EVENT_PARAM_TYPE_INTEGER, &response_int);
375 #endif
376
377         str_free(&(session_id));
378         str_free(&(server_id));
379         _INNER_FUNC_EXIT;
380         return 0;
381  error:
382         //2012.11.20
383         ev_response = EVENT_RESPONSE_FAIL;
384         sync_agent_append_event_data_param(response, SYNC_AGENT_EVENT_PARAM_TYPE_INTEGER, &ev_response);
385
386         str_free(&(session_id));
387         str_free(&(server_id));
388         return 0;
389
390 }
391
392 // Type 0, No Reply
393 static int __event_callback_cancel(sync_agent_event_data_s * request, sync_agent_event_data_s * response)
394 {
395         _INNER_FUNC_ENTER;
396
397         retvm_if((request) == NULL, 0, "request is NULL!!");
398
399         //2012.11.20
400         EVENT_RESPONSE ev_response = EVENT_RESPONSE_OK;
401         _DEBUG_VERBOSE(">>> >>> >>> Connect to server    CANCELED !!!\n");
402
403         int task_id;
404         sync_agent_get_event_data_param_int(request, &task_id);
405         _DEBUG_VERBOSE("task id : %d\n", task_id);
406
407         /*sync_agent_cancel_task(task_id); */
408         cancel_task(task_id);
409
410         //2012.11.20
411         sync_agent_append_event_data_param(response, SYNC_AGENT_EVENT_PARAM_TYPE_INTEGER, &ev_response);
412
413         _INNER_FUNC_EXIT;
414         return 0;
415 }
416
417 // Type 0, No Reply
418 static int __event_callback_download(sync_agent_event_data_s * request, sync_agent_event_data_s * response)
419 {
420         _INNER_FUNC_ENTER;
421
422         retvm_if((request) == NULL, 0, "request is NULL!!");
423
424         DM_ERROR ret = DM_OK;
425
426         //2012.11.20
427         EVENT_RESPONSE ev_response = EVENT_RESPONSE_OK;
428         int response_type = 0;
429         RESUME_STATUS download_clicked = 0;
430
431         sync_agent_get_event_data_param_int(request, &response_type);
432         _DEBUG_INFO("DOWNLOAD BUTTON TYPE : %d\n", response_type);
433
434         ret = DB_Open();
435         _DEBUG_INFO("db open : %d", ret);
436
437         if (response_type == RESPONSE_TYPE_OK) {
438                 /*download button clicked */
439                 download_clicked = RESUME_STATUS_DOWNLOAD;
440                 ret = Update_Engine_Status_Column(FUMO_SERVICE_ENGINE, VALUE_DOWNLOAD_CLICK, &download_clicked);
441                 _DEBUG_INFO("update engine status clolumn download click : %d", ret);
442
443         } else if (RESPONSE_TYPE_CANCEL) {
444                 /*later button clicked */
445                 download_clicked = RESUME_STATUS_DOWNLOAD_LATER;
446                 ret = Update_Engine_Status_Column(FUMO_SERVICE_ENGINE, VALUE_DOWNLOAD_CLICK, &download_clicked);
447                 _DEBUG_INFO("update engine status clolumn download click : %d", ret);
448         }
449         DB_Close();
450
451         if (response_type == RESPONSE_TYPE_OK) {
452                 ret = fumo_serviceEngine_task_request();
453                 if (ret != DM_OK) {
454                         goto error;
455                 }
456         }
457         //2012.11.20
458         sync_agent_append_event_data_param(response, SYNC_AGENT_EVENT_PARAM_TYPE_INTEGER, &ev_response);
459         _INNER_FUNC_EXIT;
460         return 0;
461  error:
462         //2012.11.20
463         ev_response = EVENT_RESPONSE_FAIL;
464         sync_agent_append_event_data_param(response, SYNC_AGENT_EVENT_PARAM_TYPE_INTEGER, &ev_response);
465         _INNER_FUNC_EXIT;
466         return 0;
467 }
468
469 // Type 0, No Reply
470 static int __event_callback_install(sync_agent_event_data_s * request, sync_agent_event_data_s * response)
471 {
472         _INNER_FUNC_ENTER;
473
474         retvm_if((request) == NULL, 0, "request is NULL!!");
475
476         DM_ERROR ret = DM_OK;
477
478         //2012.11.20
479         EVENT_RESPONSE ev_response = EVENT_RESPONSE_OK;
480         int response_type = 0;
481         RESUME_STATUS download_clicked = 0;
482
483         sync_agent_get_event_data_param_int(request, &response_type);
484         _DEBUG_VERBOSE("INSTALL BUTTON TYPE : %d\n", response_type);
485
486         ret = DB_Open();
487         _DEBUG_VERBOSE("db open : %d", ret);
488
489         if (response_type == RESPONSE_TYPE_OK) {
490                 /*download button clicked */
491                 download_clicked = RESUME_STATUS_INSTALL;
492                 ret = Update_Engine_Status_Column(FUMO_SERVICE_ENGINE, VALUE_DOWNLOAD_CLICK, &download_clicked);
493                 _DEBUG_VERBOSE("update engine status clolumn install click : %d", ret);
494
495         } else if (RESPONSE_TYPE_CANCEL) {
496                 /*later button clicked */
497                 download_clicked = RESUME_STATUS_INSTALL_LATER;
498                 ret = Update_Engine_Status_Column(FUMO_SERVICE_ENGINE, VALUE_DOWNLOAD_CLICK, &download_clicked);
499                 _DEBUG_VERBOSE("update engine status clolumn install click : %d", ret);
500         }
501         DB_Close();
502
503         ret = fumo_serviceEngine_task_request();
504         if (ret != DM_OK) {
505                 goto error;
506         }
507         //2012.11.20
508         sync_agent_append_event_data_param(response, SYNC_AGENT_EVENT_PARAM_TYPE_INTEGER, &ev_response);
509
510         _INNER_FUNC_EXIT;
511         return 0;
512  error:
513         //2012.11.20
514         ev_response = EVENT_RESPONSE_FAIL;
515         sync_agent_append_event_data_param(response, SYNC_AGENT_EVENT_PARAM_TYPE_INTEGER, &ev_response);
516         _INNER_FUNC_EXIT;
517         return 0;
518 }
519
520 // Type 0, No Reply
521 static int __event_callback_set_interval(sync_agent_event_data_s * request, sync_agent_event_data_s * response)
522 {
523         _INNER_FUNC_ENTER;
524
525         retvm_if((request) == NULL, 0, "request is NULL!!");
526
527         DM_ERROR ret = DM_OK;
528         //2012.11.20
529         EVENT_RESPONSE ev_response = EVENT_RESPONSE_OK;
530         int request_param = INTERVAL_CANCEL;
531
532         sync_agent_get_event_data_param_int(request, &request_param);
533         _DEBUG_INFO("interval val from UI : %d\n", request_param);
534
535         switch (request_param) {
536         case RESPONSE_TYPE_REMINDER_INTERVAL_1_HOUR:
537                 request_param = INTERVAL_1HOUR;
538                 break;
539         case RESPONSE_TYPE_REMINDER_INTERVAL_3_HOURS:
540                 request_param = INTERVAL_3HOURS;
541                 break;
542         case RESPONSE_TYPE_REMINDER_INTERVAL_6_HOURS:
543                 request_param = INTERVAL_6HOURS;
544                 break;
545         case RESPONSE_TYPE_REMINDER_INTERVAL_12_HOURS:
546                 request_param = INTERVAL_12HOURS;
547                 break;
548         case RESPONSE_TYPE_REMINDER_INTERVAL_1_DAY:
549                 request_param = INTERVAL_1DAY;
550                 break;
551         case RESPONSE_TYPE_CANCEL:
552                 request_param = INTERVAL_CANCEL;
553                 break;
554         default:
555                 break;
556         }
557
558         _DEBUG_INFO(" interval val in fumo engine : %d\n", request_param);
559         if (request_param != INTERVAL_CANCEL) {
560                 ret = fumo_schedule_task_request(request_param);
561                 if (ret != DM_OK) {
562                         goto error;
563                 }
564                 _DEBUG_INFO("fumo schedule task result  : %d\n", ret);
565         } else {
566 /*
567                 ret = fumo_schedule_task_request(request_param);
568                 if (ret != DM_OK) {
569                         goto error;
570                 }
571 */
572                 ret = DB_Open();
573                 _DEBUG_INFO("db open : %d", ret);
574
575                 int engine_return = FUMO_USER_CANCELLED;// 401;
576                 ret = Update_Engine_Status_Column(FUMO_SERVICE_ENGINE, VALUE_RESULT_STATUS, &engine_return);
577                 _DEBUG_INFO("ret[%d] service engine status generic alert status : %d", ret, engine_return);
578                 DB_Close();
579
580                 ret = fumo_serviceEngine_task_request();
581                 if (ret != DM_OK) {
582                         goto error;
583                 }
584                 _DEBUG_INFO("fumo schedule cancel : %d \n", ret);
585         }
586
587         //2012.11.20
588         sync_agent_append_event_data_param(response, SYNC_AGENT_EVENT_PARAM_TYPE_INTEGER, &ev_response);
589
590         _INNER_FUNC_EXIT;
591         return 0;
592
593  error:
594         //2012.11.20
595         ev_response = EVENT_RESPONSE_FAIL;
596         sync_agent_append_event_data_param(response, SYNC_AGENT_EVENT_PARAM_TYPE_INTEGER, &ev_response);
597
598         _INNER_FUNC_EXIT;
599         return 1;
600 }
601
602 // Type 0, No Reply
603 static int __event_callback_account_registration(sync_agent_event_data_s * request, sync_agent_event_data_s * response)
604 {
605         _INNER_FUNC_ENTER;
606
607         retvm_if((request) == NULL, 0, "request is NULL!!");
608
609    /*
610         DM_ERROR push_ret = DM_OK;
611         push_ret = register_fumo_ip_push();
612         if (push_ret == -1) {
613                 _DEBUG_INFO("fail register fumo ip push : %d ", push_ret);
614         } else {
615                 _DEBUG_INFO("success register fumo ip push : %d ", push_ret);
616         }
617    */
618
619         //2012.11.20
620         EVENT_RESPONSE ev_response = EVENT_RESPONSE_OK;
621
622         int ret = -1;
623         //temp code
624         int db_ret = 0;
625         db_ret = sync_agent_open_agent();
626         _DEBUG_INFO("OPEN DACI : %d", db_ret);
627
628         ret = register_fota_account();
629
630         if (ret == 0) {
631                 _DEBUG_INFO("fail register fota account : %d ", ret);
632                 goto error;
633         } else {
634                 _DEBUG_INFO("success register fota account : %d ", ret);
635
636                 char * str_version_url = NULL;
637                 str_version_url = vconf_get_str(VERSION_URL_KEY);
638                 if(str_version_url == NULL) {
639                         _DEBUG_ERROR("vconf_get_str[%s] failed", VERSION_URL_KEY);
640                         ret = EVENT_RESPONSE_FAIL;
641                         _INNER_FUNC_EXIT;
642                         goto error;
643                 }
644                 char * str_version_filename = NULL;
645                 str_version_filename = vconf_get_str(VERSION_FILENAME_KEY);
646                 if(str_version_filename == NULL) {
647                         _DEBUG_ERROR("vconf_get_str[%s] failed", VERSION_FILENAME_KEY);
648                         ret = EVENT_RESPONSE_FAIL;
649                         goto error;
650                 }
651
652                 int exist_version = -1;
653                 //ret = register_fota_polling(str_version_url, str_version_filename, &exist_version);
654                 _DEBUG_INFO("exist_version [%d]", exist_version);
655
656         }
657
658         db_ret = sync_agent_close_agent();
659         _DEBUG_INFO("CLOSE DACI : %d", db_ret);
660
661         //2012.11.20
662         sync_agent_append_event_data_param(response, SYNC_AGENT_EVENT_PARAM_TYPE_INTEGER, &ev_response);
663
664         _INNER_FUNC_EXIT;
665         return 0;
666
667  error:
668         db_ret = sync_agent_close_agent();
669         _DEBUG_INFO("CLOSE DACI : %d", db_ret);
670
671         //2012.11.20
672         ev_response = EVENT_RESPONSE_FAIL;
673         sync_agent_append_event_data_param(response, SYNC_AGENT_EVENT_PARAM_TYPE_INTEGER, &ev_response);
674         _INNER_FUNC_EXIT;
675         return 0;
676 }
677
678 // Type 1, Fumo setting data Reply
679 static int __event_callback_get_profile(sync_agent_event_data_s * request, sync_agent_event_data_s * response)
680 {
681         _INNER_FUNC_ENTER;
682
683         retvm_if((request) == NULL, 0, "request is NULL!!");
684
685         EVENT_RESPONSE ev_response = EVENT_RESPONSE_OK;
686
687         char *profile_name = NULL;
688         SERVICE_SERVER_TYPE sv_type = NO_ENGINE_TYPE;
689
690         char *client_id = NULL;
691         char *client_pwd = NULL;
692         char *client_sourceUrl = NULL;
693         char *client_targetUrl = NULL;
694         int client_isBase64 = 0;
695         char *client_nextNonce = NULL;
696         char *client_authType = NULL;
697
698         char *server_url = NULL;
699         char *server_pwd = NULL;
700         char *server_sourceUrl = NULL;
701         char *server_targetUrl = NULL;
702         int server_isBase64 = 0;
703         char *server_nextNonce = NULL;
704         char *server_authType = NULL;
705
706         sync_agent_dm_mo_error_e db_ret = SYNC_AGENT_DM_MO_SUCCESS;
707         char *server_id = NULL;
708
709         sync_agent_get_event_data_param_int(request, (int*) &sv_type);
710         _DEBUG_VERBOSE("server type : %d\n", sv_type);
711
712         db_ret = sync_agent_open_mo();
713         _DEBUG_VERBOSE("mo db open : %d", db_ret);
714
715         switch (sv_type) {
716         case SAMSUNG_FUMO_TYPE:
717                 {
718                         profile_name = "Fumo";
719                 }
720                 break;
721         case SAMSUNG_FMM_TYPE:
722                 {
723                         profile_name = "Lawmo";
724                 }
725                 break;
726         case GCF_TYPE:
727                 {
728                         profile_name = "gcf";
729                 }
730                 break;
731         default:
732                 {
733                         _DEBUG_VERBOSE("not exist server id error");
734                         goto error;
735                 }
736         }
737
738         get_Serverid(sv_type, &server_id);
739         _DEBUG_VERBOSE("server id : %s", server_id);
740
741         if (server_id != NULL) {
742                 DM_ERROR err = get_client_dmacc(server_id, &client_id, &client_pwd, &client_sourceUrl, &client_targetUrl, &client_isBase64, &client_nextNonce, &client_authType);
743                 if (err != DM_OK) {
744                         _DEBUG_VERBOSE("get_client_dmacc() fail !!");
745                         goto error;
746                 } else {
747                         _DEBUG_VERBOSE("get_client_dmacc() success !!");
748                 }
749
750                 err = get_server_dmacc(server_id, &server_url, &server_pwd, &server_sourceUrl, &server_targetUrl, &server_isBase64, &server_nextNonce, &server_authType);
751                 if (err != DM_OK) {
752                         _DEBUG_VERBOSE("get_server_dmacc() fail !!");
753                         goto error;
754                 } else {
755                         _DEBUG_VERBOSE("get_server_dmacc() success !!");
756                 }
757
758                 db_ret = sync_agent_close_mo();
759                 _DEBUG_VERBOSE("mo db close : %d", db_ret);
760
761                 _DEBUG_VERBOSE("profile_name : %s", profile_name);
762                 _DEBUG_VERBOSE("client_targetUrl : %s", client_targetUrl);
763                 _DEBUG_VERBOSE("server_id : %s", server_url);
764                 _DEBUG_VERBOSE("server_pwd : %s", server_pwd);
765                 _DEBUG_VERBOSE("client_id : %s", client_id);
766                 _DEBUG_VERBOSE("client_pwd : %s", client_pwd);
767                 _DEBUG_VERBOSE("client_authType : %s", client_authType);
768                 _DEBUG_VERBOSE("server_authType : %s", server_authType);
769
770                 //2012.11.20
771                 sync_agent_append_event_data_param(response, SYNC_AGENT_EVENT_PARAM_TYPE_INTEGER, &ev_response);
772
773                 sync_agent_append_event_data_param(response, SYNC_AGENT_EVENT_PARAM_TYPE_STRING, profile_name);
774                 sync_agent_append_event_data_param(response, SYNC_AGENT_EVENT_PARAM_TYPE_STRING, client_targetUrl);
775                 sync_agent_append_event_data_param(response, SYNC_AGENT_EVENT_PARAM_TYPE_STRING, server_url);
776                 sync_agent_append_event_data_param(response, SYNC_AGENT_EVENT_PARAM_TYPE_STRING, server_pwd);
777                 sync_agent_append_event_data_param(response, SYNC_AGENT_EVENT_PARAM_TYPE_STRING, client_id);
778                 sync_agent_append_event_data_param(response, SYNC_AGENT_EVENT_PARAM_TYPE_STRING, client_pwd);
779                 sync_agent_append_event_data_param(response, SYNC_AGENT_EVENT_PARAM_TYPE_STRING, client_authType);
780                 sync_agent_append_event_data_param(response, SYNC_AGENT_EVENT_PARAM_TYPE_STRING, server_authType);
781
782                 str_free(&server_nextNonce);
783                 str_free(&client_nextNonce);
784                 str_free(&client_sourceUrl);
785                 str_free(&server_sourceUrl);
786                 str_free(&server_targetUrl);
787                 str_free(&client_targetUrl);
788                 str_free(&server_url);
789                 str_free(&server_pwd);
790                 str_free(&client_id);
791                 str_free(&client_pwd);
792                 str_free(&client_authType);
793                 str_free(&server_authType);
794         } else {
795                 _DEBUG_VERBOSE("not exist server id error");
796                 goto error;
797         }
798
799         _INNER_FUNC_EXIT;
800         return 0;
801  error:
802
803         db_ret = sync_agent_close_mo();
804         _DEBUG_VERBOSE("mo db close : %d", db_ret);
805         //2012.11.20
806         ev_response = EVENT_RESPONSE_FAIL;
807         sync_agent_append_event_data_param(response, SYNC_AGENT_EVENT_PARAM_TYPE_INTEGER, &ev_response);
808         _INNER_FUNC_EXIT;
809         return 0;
810 }
811
812 static int __event_callback_set_profile(sync_agent_event_data_s * request, sync_agent_event_data_s * response)
813 {
814         _INNER_FUNC_ENTER;
815
816         retvm_if((request) == NULL, 0, "request is NULL!!");
817
818         //2012.11.20
819         EVENT_RESPONSE ev_response = EVENT_RESPONSE_OK;
820
821         int ret = -1;
822         SERVICE_SERVER_TYPE sv_type = NO_ENGINE_TYPE;
823         char *server_id = NULL;
824
825         dm_acc *dmaccount = (dm_acc *) calloc(1, sizeof(dm_acc));
826         if (dmaccount == NULL) {
827                 _DEBUG_VERBOSE("alloc fail");
828                 goto error;
829         }
830         //update 2012.11.20
831         sync_agent_get_event_data_param_int(request, (int*) &sv_type);
832         _DEBUG_VERBOSE("server profile type : %d", sv_type);
833         sync_agent_get_event_data_param_str(request, &(dmaccount->server_url));
834         _DEBUG_VERBOSE("server url : %s", (dmaccount->server_url));
835         sync_agent_get_event_data_param_str(request, &(dmaccount->server_id));
836         _DEBUG_VERBOSE("server id : %s", dmaccount->server_id);
837         sync_agent_get_event_data_param_str(request, &(dmaccount->server_pw));
838         _DEBUG_VERBOSE("server_pw : %s", dmaccount->server_pw);
839         sync_agent_get_event_data_param_str(request, &(dmaccount->user_id));
840         _DEBUG_VERBOSE("user_id : %s", dmaccount->user_id);
841         sync_agent_get_event_data_param_str(request, &(dmaccount->user_pw));
842         _DEBUG_VERBOSE("user_pw : %s", dmaccount->user_pw);
843         sync_agent_get_event_data_param_str(request, &(dmaccount->user_auth_type));
844         _DEBUG_VERBOSE("user_auth_type : %s", dmaccount->user_auth_type);
845         sync_agent_get_event_data_param_str(request, &(dmaccount->server_auth_type));
846         _DEBUG_VERBOSE("server_auth_type : %s", dmaccount->server_auth_type);
847
848         get_Serverid(sv_type, &server_id);
849         _DEBUG_VERBOSE("server id : %s", server_id);
850
851         if (server_id != NULL) {
852                 ret = update_dmacc(server_id, dmaccount);
853                 if (ret != 1) {
854                         _DEBUG_VERBOSE("update dm acc fail", ret);
855                         goto error;
856
857                 } else {
858                         _DEBUG_VERBOSE("update dm acc success", ret);
859                 }
860
861         } else {
862                 goto error;
863         }
864
865         _DEBUG_VERBOSE("update dm acc : %d", ret);
866         free_dm_acc(dmaccount);
867
868         sync_agent_append_event_data_param(response, SYNC_AGENT_EVENT_PARAM_TYPE_INTEGER, &ev_response);
869
870         _INNER_FUNC_EXIT;
871         return 0;
872  error:
873         //2012.11.20
874         free_dm_acc(dmaccount);
875         ev_response = EVENT_RESPONSE_FAIL;
876         sync_agent_append_event_data_param(response, SYNC_AGENT_EVENT_PARAM_TYPE_INTEGER, &ev_response);
877         _INNER_FUNC_EXIT;
878         return 0;
879 }
880
881 static int __event_callback_reset_profile(sync_agent_event_data_s * request, sync_agent_event_data_s * response)
882 {
883         _INNER_FUNC_ENTER;
884         retvm_if((request) == NULL, 0, "request is NULL!!");
885
886         //2012.11.20
887         EVENT_RESPONSE ev_response = EVENT_RESPONSE_OK;
888         SERVICE_SERVER_TYPE sv_type = NO_ENGINE_TYPE;
889
890         sync_agent_get_event_data_param_int(request, (int*) &sv_type);
891         _DEBUG_VERBOSE("PROFILE TYPE : %d\n", sv_type);
892
893         switch (sv_type) {
894         case SAMSUNG_FUMO_TYPE:
895                 {
896                         reset_dmacc_msctestserver();
897                 }
898                 break;
899         case SAMSUNG_FMM_TYPE:
900                 {
901                         reset_dmacc_mscserver();
902                 }
903                 break;
904         case GCF_TYPE:
905                 {
906                         reset_dmacc_gcf();
907                 }
908                 break;
909         default:
910                 {
911                         goto error;
912                 }
913         }
914
915         sync_agent_append_event_data_param(response, SYNC_AGENT_EVENT_PARAM_TYPE_INTEGER, &ev_response);
916         _INNER_FUNC_EXIT;
917         return 0;
918  error:
919         //2012.11.20
920         ev_response = EVENT_RESPONSE_FAIL;
921         sync_agent_append_event_data_param(response, SYNC_AGENT_EVENT_PARAM_TYPE_INTEGER, &ev_response);
922         _INNER_FUNC_EXIT;
923         return 0;
924 }
925
926 static int __event_callback_uic_alert(sync_agent_event_data_s * request, sync_agent_event_data_s * response)
927 {
928         _INNER_FUNC_ENTER;
929
930         uic_type type = UIC_NONE_TYPE;
931         RESPONSE_TYPE response_ret = EVENT_RESPONSE_FAIL;
932         char *input_text = NULL;
933         int count = 0;
934         int i = 0;
935
936         /*
937         if (type == UIC_DISPLAY_TYPE) {
938                 return 0;
939         }
940         */
941         free_res_data(res_uic_data);
942
943         sync_agent_get_event_data_param_int(request, (int*) &response_ret);
944         _DEBUG_TRACE("response is %d", response_ret);
945
946         sync_agent_get_event_data_param_int(request, (int*) &type);
947         _DEBUG_TRACE("uic type %d", type);
948
949         /*alloc reponse data */
950         res_uic_data = calloc(1, sizeof(uic_res_data) + 1);
951         res_uic_data->status = response_ret;
952
953         if (response_ret == RESPONSE_TYPE_OK) {
954
955                 _DEBUG_TRACE("response ok");
956
957                 switch (type) {
958                 case UIC_CONFIRMATION_TYPE:
959                         break;
960                 case UIC_INPUT_TEXT_TYPE:{
961                                 sync_agent_get_event_data_param_str(request, &input_text);
962                                 _DEBUG_TRACE("input text %s", input_text);
963
964                                 res_uic_data->input_text = strdup(input_text);
965                         }
966                         break;
967                 case UIC_SINGLE_CHOICE_TYPE:
968                 case UIC_MULTIPLE_CHOICE_TYPE:{
969                                 sync_agent_get_event_data_param_int(request, &count);
970                                 _DEBUG_TRACE("count  is %d\n", count);
971
972                                 if (count != 0) {
973                                         /*single, multiple choice */
974                                         for (i = 0; i < count; ++i) {
975                                                 char *input = NULL;
976                                                 char *value = NULL;
977                                                 sync_agent_get_event_data_param_str(request, &input);
978                                                 _DEBUG_TRACE(" choice : %s", input);
979                                                 if (input == NULL) {
980                                                         input = strdup("NULL");
981                                                         res_uic_data->res_multi_data = g_list_append(res_uic_data->res_multi_data, input);
982                                                 } else {
983                                                         _DEBUG_TRACE("value data : %s", input);
984                                                         value = strdup(input);
985                                                         res_uic_data->res_multi_data = g_list_append(res_uic_data->res_multi_data, value);
986                                                 }
987                                         }
988                                 } else {
989                                         _DEBUG_TRACE("not choice");
990                                 }
991                         }
992                         break;
993                 case UIC_DISPLAY_TYPE:
994                 default:
995                         break;
996                 }
997         } else {
998                 /*
999                  * time out
1000                  * error
1001                  * ...
1002                  */
1003                 _DEBUG_TRACE("response fail");
1004         }
1005
1006         //signal off
1007         g_mutex_lock(&(mutex));
1008         g_cond_signal(&(cond));
1009         g_mutex_unlock(&(mutex));
1010
1011         EVENT_RESPONSE ev_response = EVENT_RESPONSE_OK;
1012         sync_agent_append_event_data_param(response, SYNC_AGENT_EVENT_PARAM_TYPE_INTEGER, &ev_response);
1013
1014         _INNER_FUNC_EXIT;
1015         return 0;
1016 }
1017
1018 static int __event_callback_get_fumo_config(sync_agent_event_data_s * request, sync_agent_event_data_s * response)
1019 {
1020         _INNER_FUNC_ENTER;
1021         retvm_if((request) == NULL, 0, "request is NULL!!");
1022
1023         //2012.11.20
1024         EVENT_RESPONSE ev_response = EVENT_RESPONSE_OK;
1025
1026         int wifi_only = -1;
1027         sync_agent_open_agent();
1028
1029         wifi_only = get_wifi_only_config();
1030         sync_agent_close_agent();
1031
1032         if (wifi_only == -1) {
1033                 _DEBUG_VERBOSE("get wifi only config fail\n");
1034                 goto error;
1035         } else {
1036                 _DEBUG_VERBOSE("get wifi only config success\n");
1037         }
1038
1039         sync_agent_append_event_data_param(response, SYNC_AGENT_EVENT_PARAM_TYPE_INTEGER, &ev_response);
1040
1041         _DEBUG_VERBOSE("wifi only : %d", wifi_only);
1042         sync_agent_append_event_data_param(response, SYNC_AGENT_EVENT_PARAM_TYPE_INTEGER, &wifi_only);
1043
1044         _INNER_FUNC_EXIT;
1045         return 0;
1046  error:
1047         //2012.11.20
1048         ev_response = EVENT_RESPONSE_FAIL;
1049         sync_agent_append_event_data_param(response, SYNC_AGENT_EVENT_PARAM_TYPE_INTEGER, &ev_response);
1050         _INNER_FUNC_EXIT;
1051         return 0;
1052 }
1053
1054 static int __event_callback_set_fumo_config_wifi_only(sync_agent_event_data_s * request, sync_agent_event_data_s * response)
1055 {
1056         _INNER_FUNC_ENTER;
1057         retvm_if((request) == NULL, 0, "request is NULL!!");
1058
1059         //2012.11.20
1060         EVENT_RESPONSE ev_response = EVENT_RESPONSE_OK;
1061         int ret = 1;
1062         int wifi_only_param;
1063
1064         sync_agent_get_event_data_param_int(request, &wifi_only_param);
1065
1066         sync_agent_open_agent();
1067         ret = set_wifi_only_config(wifi_only_param);
1068         sync_agent_close_agent();
1069         if (ret != 1) {
1070                 goto error;
1071         }
1072
1073         sync_agent_append_event_data_param(response, SYNC_AGENT_EVENT_PARAM_TYPE_INTEGER, &ev_response);
1074         _INNER_FUNC_EXIT;
1075         return 0;
1076  error:
1077         //2012.11.20
1078         ev_response = EVENT_RESPONSE_FAIL;
1079         sync_agent_append_event_data_param(response, SYNC_AGENT_EVENT_PARAM_TYPE_INTEGER, &ev_response);
1080         _INNER_FUNC_EXIT;
1081         return 0;
1082 }
1083
1084 static int __event_callback_check_pin_code(sync_agent_event_data_s * request, sync_agent_event_data_s * response)
1085 {
1086         _INNER_FUNC_ENTER;
1087         retvm_if((request) == NULL, 0, "request is NULL!!");
1088
1089         //2012.11.20
1090         EVENT_RESPONSE ev_response = EVENT_RESPONSE_OK;
1091
1092         CP_ERROR err = CP_ERROR_SUCCESS;
1093
1094         int ext_id = 0;
1095         sync_agent_get_event_data_param_int(request, &ext_id);
1096         _DEBUG_VERBOSE("ext id : %d", ext_id);
1097
1098         char *user_pin = NULL;
1099
1100         int response_type = RESPONSE_TYPE_NONE;
1101         sync_agent_get_event_data_param_int(request, &response_type);
1102         _DEBUG_VERBOSE("response type :  %d", response_type);
1103
1104         int response_value = 0;
1105
1106         if (response_type == RESPONSE_TYPE_OK) {
1107                 _DEBUG_VERBOSE("check pin code !!");
1108                 sync_agent_get_event_data_param_str(request, &user_pin);
1109                 _DEBUG_VERBOSE("user pin : %s", user_pin);
1110
1111                 int is_correct = 0;
1112                 err = process_Check_Pincode(0, user_pin, &is_correct, ext_id);
1113                 if (err != CP_ERROR_SUCCESS) {
1114                         _DEBUG_VERBOSE("process_Check_Pincode() fail !!");
1115                         sync_agent_append_event_data_param(response, SYNC_AGENT_EVENT_PARAM_TYPE_INTEGER, &ev_response);
1116
1117                         response_value = 0;
1118                         /* todo : exception handling */
1119                         sync_agent_append_event_data_param(response, SYNC_AGENT_EVENT_PARAM_TYPE_INTEGER, &response_value);
1120                 } else {
1121                         _DEBUG_VERBOSE("process_Check_Pincode() success !!");
1122
1123                         sync_agent_append_event_data_param(response, SYNC_AGENT_EVENT_PARAM_TYPE_INTEGER, &ev_response);
1124
1125                         if (is_correct != 0) {
1126                                 response_value = 1;
1127                         } else {
1128                                 response_value = 0;
1129                         }
1130                         sync_agent_append_event_data_param(response, SYNC_AGENT_EVENT_PARAM_TYPE_INTEGER, &response_value);
1131
1132                         /* process_Setting_CP() */
1133                         if (is_correct == 1) {
1134                                 _DEBUG_VERBOSE("Valid PIN !!");
1135
1136                                 err = process_Setting_CP(ext_id);
1137                                 if (err != CP_ERROR_SUCCESS) {
1138                                         _DEBUG_VERBOSE("process_Setting_CP() fail !!");
1139                                 } else {
1140                                         _DEBUG_VERBOSE("process_Setting_CP() success !!");
1141                                 }
1142                         } else if (is_correct == 0) {
1143                                 _DEBUG_VERBOSE("Invalid PIN !!");
1144                         }
1145                 }
1146         } else {                /* response_type == RESPONSE_TYPE_CANCEL */
1147                 sync_agent_append_event_data_param(response, SYNC_AGENT_EVENT_PARAM_TYPE_INTEGER, &ev_response);
1148
1149                 response_value = 1;     /* meaningless value */
1150                 sync_agent_append_event_data_param(response, SYNC_AGENT_EVENT_PARAM_TYPE_INTEGER, &response_value);
1151
1152                 if (ext_id != -1) {
1153                         _DEBUG_VERBOSE("fail logic !!");
1154                         err = process_Invalid_Pincode(ext_id);
1155                         if (err != CP_ERROR_SUCCESS) {
1156                                 _DEBUG_VERBOSE("process_Invalid_Pincode() fail !!");
1157                                 /* todo : exception handling */
1158                         } else {
1159                                 _DEBUG_VERBOSE("process_Invalid_Pincode() success !!");
1160                         }
1161                 } else {
1162                         _DEBUG_VERBOSE("cancel logic !!");
1163                         /* do nothing !! */
1164                 }
1165         }
1166
1167         str_free(&(user_pin));
1168         _INNER_FUNC_EXIT;
1169         return 0;
1170 }
1171
1172 static int __event_add_dmacc(sync_agent_event_data_s * request, sync_agent_event_data_s * response)
1173 {
1174         _INNER_FUNC_ENTER;
1175
1176         sync_agent_dm_mo_error_e db_ret = SYNC_AGENT_DM_MO_SUCCESS;
1177         DM_ERROR ret = DM_OK;
1178
1179         EVENT_RESPONSE ev_response = EVENT_RESPONSE_OK;
1180         SERVICE_SERVER_TYPE sv_type = NO_ENGINE_TYPE;
1181
1182         sync_agent_get_event_data_param_int(request, (int*) &sv_type);
1183         _DEBUG_VERBOSE("server type : %d\n", sv_type);
1184
1185         db_ret = sync_agent_open_mo();
1186         _DEBUG_VERBOSE("mo db open : %d", db_ret);
1187
1188         ret = DB_Open();
1189         _DEBUG_VERBOSE("dm status open : %d", db_ret);
1190
1191         ret = DB_Begin_Transaction();
1192         _DEBUG_VERBOSE("begin transaction : %d", ret);
1193
1194         switch (sv_type) {
1195                 //todo will change ipc refactoring
1196         case SAMSUNG_FUMO_TYPE:
1197                 {
1198                         _DEBUG_VERBOSE("add mscservertest dmacc");
1199                         ret = add_dm_acc(sv_type);
1200                 }
1201                 break;
1202         case SAMSUNG_FMM_TYPE:
1203                 {
1204                         _DEBUG_VERBOSE("add mscserver dmacc");
1205                         ret = add_dm_acc(sv_type);
1206                 }
1207                 break;
1208         case GCF_TYPE:
1209                 {
1210                         _DEBUG_VERBOSE("add gcf dmacc");
1211                         ret = add_dm_acc(sv_type);
1212                 }
1213                 break;
1214         default:
1215                 {
1216                         _DEBUG_VERBOSE("not exist server id error");
1217                 }
1218         }
1219
1220         _DEBUG_VERBOSE("add dm acc error :%d", ret);
1221
1222         if (ret != DM_OK) {
1223                 ev_response = EVENT_RESPONSE_FAIL;
1224                 goto error;
1225         }
1226
1227         ret = DB_End_Transaction(TRANSACTION_COMMIT_);
1228         _DEBUG_VERBOSE("end transaction : %d", ret);
1229
1230         db_ret = sync_agent_close_mo();
1231         _DEBUG_VERBOSE("mo db close : %d", db_ret);
1232
1233         DB_Close();
1234
1235         sync_agent_append_event_data_param(response, SYNC_AGENT_EVENT_PARAM_TYPE_INTEGER, &ev_response);
1236
1237         _INNER_FUNC_EXIT;
1238         return 0;
1239
1240  error:
1241
1242         ret = DB_End_Transaction(TRANSACTION_ROLLBACK_);
1243         _DEBUG_VERBOSE("end transaction : %d", ret);
1244
1245         db_ret = sync_agent_end_transaction_mo(SYNC_AGENT_DM_MO_TRANSACTION_ROLLBACK);
1246         _DEBUG_VERBOSE("end transaction : %d", db_ret);
1247
1248         db_ret = sync_agent_close_mo();
1249         _DEBUG_VERBOSE("mo db close : %d", db_ret);
1250
1251         DB_Close();
1252
1253         sync_agent_append_event_data_param(response, SYNC_AGENT_EVENT_PARAM_TYPE_INTEGER, &ev_response);
1254
1255         _INNER_FUNC_EXIT;
1256         return 0;
1257 }
1258
1259 static int __event_remove_dmacc(sync_agent_event_data_s * request, sync_agent_event_data_s * response)
1260 {
1261         _INNER_FUNC_ENTER;
1262
1263         sync_agent_dm_mo_error_e db_ret = SYNC_AGENT_DM_MO_SUCCESS;
1264         DM_ERROR ret = DM_OK;
1265         engine_status *status = NULL;
1266         ENGINE_STATUS engine_status = DM_IDLE;
1267
1268         EVENT_RESPONSE ev_response = EVENT_RESPONSE_OK;
1269         SERVICE_SERVER_TYPE sv_type = NO_ENGINE_TYPE;
1270
1271         sync_agent_get_event_data_param_int(request, (int*) &sv_type);
1272         _DEBUG_VERBOSE("server type : %d\n", sv_type);
1273
1274         //mo db
1275         db_ret = sync_agent_open_mo();
1276         _DEBUG_VERBOSE("mo db open : %d", db_ret);
1277
1278         //config, alram db
1279         ret = DB_Open();
1280         _DEBUG_VERBOSE("config alarm open : %d", db_ret);
1281
1282         int is_exist = IsExist_Engine_id(IDLE_ENGINE);
1283         if (is_exist == 0)
1284                 goto error;
1285
1286         ret = Get_Engine_Status(IDLE_ENGINE, &status);
1287         if (ret != DM_OK) {
1288                 _DEBUG_ERROR("Get_Engine_Status is not DM_OK");
1289                 goto error;
1290         }
1291
1292         if(status == NULL) {
1293                 _DEBUG_ERROR("status is null");
1294                 goto error;
1295         }
1296
1297         _DEBUG_VERBOSE("STATUS VALUE : %d ", status->engine_status);
1298         engine_status = status->engine_status;
1299
1300         if (engine_status == DM_BEFORE_BOOTSTRAP) {
1301                 _DEBUG_VERBOSE("not bootstrap");
1302                 goto error;
1303         }
1304
1305         db_ret = sync_agent_begin_transaction_mo();
1306         _DEBUG_VERBOSE("end transaction : %d", db_ret);
1307
1308         ret = DB_Begin_Transaction();
1309         _DEBUG_VERBOSE("end transaction : %d", ret);
1310
1311         switch (sv_type) {
1312
1313         case UI_SAMSUNG_FUMO_TYPE:
1314                 {
1315                         _DEBUG_VERBOSE("remove mscservertest dmacc");
1316                         ret = remove_dm_acc(DM_DMACC_MSCTESTSERVER);
1317                         if (ret != DM_OK) {
1318                                 _DEBUG_ERROR("remove dm acc error :%d", ret);
1319                                 goto error;
1320                         } else {
1321                                 //config db
1322                                 int is_exist = IsExist_Engine_id(FUMO_SERVICE_ENGINE);
1323                                 if (is_exist == 0) {
1324                                         _DEBUG_VERBOSE("not exist fumo engine");
1325                                 }
1326
1327                                 ret = Delete_Engine_Status(FUMO_SERVICE_ENGINE);
1328                                 if (ret != DM_OK) {
1329                                         _DEBUG_ERROR("delete engine status :%d", ret);
1330                                         goto error;
1331                                 }
1332                                 //alarm db
1333                                 delete_alarm_item(FUMO_INTERVAL, FUMO_INTERVAL_TYPE);
1334                                 _DEBUG_TRACE(" delete fumo reminder in config db ");
1335
1336                                 //delete delta file
1337                                 delete_fumo_contents(MEMORY_INTERNAL);
1338                                 delete_fumo_contents(MEMORY_SD_CARD);
1339
1340                                 //change fumo state 10
1341                                 char *fumo_state = NULL;
1342                                 fumo_state = g_strdup_printf("%s%s%s%s", MO_ROOT, MO_SEPERATOR, FUMO_SERVICE, DM_FUMO_STATE_OP);
1343                                 set_current_fumo_state(fumo_state, IDLE_START);
1344                                 str_free(&fumo_state);
1345                         }
1346                 }
1347                 break;
1348         case UI_SAMSUNG_FMM_TYPE:
1349                 {
1350                         _DEBUG_VERBOSE("remove mscserver dmacc");
1351                         ret = remove_dm_acc(DM_DMACC_MSCSERVER);
1352                         if (ret != DM_OK) {
1353                                 _DEBUG_ERROR("remove dm acc error :%d", ret);
1354                                 goto error;
1355                         } else {
1356
1357                                 //config db
1358                                 int is_exist = IsExist_Engine_id(LAWMO_SERVICE_ENGINE);
1359                                 if (is_exist == 0) {
1360                                         _DEBUG_VERBOSE("not exist fumo engine");
1361                                 }
1362
1363                                 ret = Delete_Engine_Status(LAWMO_SERVICE_ENGINE);
1364                                 if (ret != DM_OK) {
1365                                         _DEBUG_ERROR("delete engine status :%d", ret);
1366                                         goto error;
1367                                 }
1368
1369                         }
1370                 }
1371                 break;
1372         case UI_GCF_TYPE:
1373                 {
1374                         _DEBUG_VERBOSE("remove gcf dmacc");
1375                         ret = remove_dm_acc(DM_DMACC_GCF);
1376                         if (ret != DM_OK) {
1377                                 _DEBUG_ERROR("remove dm acc error :%d", ret);
1378                                 goto error;
1379                         } else {
1380                                 _DEBUG_VERBOSE("remove dm acc");
1381                         }
1382                 }
1383                 break;
1384         default:
1385                 {
1386                         _DEBUG_VERBOSE("not exist server id error");
1387                 }
1388         }
1389
1390         ret = DB_End_Transaction(TRANSACTION_COMMIT_);
1391         _DEBUG_VERBOSE("end transaction : %d", ret);
1392
1393         db_ret = sync_agent_end_transaction_mo(SYNC_AGENT_DM_MO_TRANSACTION_COMMIT);
1394         _DEBUG_VERBOSE("end transaction : %d", db_ret);
1395
1396         _DEBUG_VERBOSE("remove dm acc error :%d", ret);
1397
1398         db_ret = sync_agent_close_mo();
1399         _DEBUG_VERBOSE("mo db close : %d", db_ret);
1400
1401         DB_Close();
1402
1403         if (status != NULL) {
1404                 Free_Memory_Engine_Status(&status, 1);
1405         }
1406
1407         sync_agent_append_event_data_param(response, SYNC_AGENT_EVENT_PARAM_TYPE_INTEGER, &ev_response);
1408
1409         _INNER_FUNC_EXIT;
1410         return 0;
1411  error:
1412
1413         ret = DB_End_Transaction(TRANSACTION_ROLLBACK_);
1414         _DEBUG_VERBOSE("end transaction : %d", ret);
1415
1416         db_ret = sync_agent_end_transaction_mo(SYNC_AGENT_DM_MO_TRANSACTION_ROLLBACK);
1417         _DEBUG_VERBOSE("end transaction : %d", db_ret);
1418
1419         db_ret = sync_agent_close_mo();
1420         _DEBUG_VERBOSE("mo db close : %d", db_ret);
1421
1422         DB_Close();
1423
1424         if (status != NULL) {
1425                 Free_Memory_Engine_Status(&status, 1);
1426         }
1427
1428         ev_response = EVENT_RESPONSE_FAIL;
1429         sync_agent_append_event_data_param(response, SYNC_AGENT_EVENT_PARAM_TYPE_INTEGER, &ev_response);
1430
1431         _INNER_FUNC_EXIT;
1432         return 0;
1433 }
1434
1435 static int __event_callback_default(sync_agent_event_data_s * request, sync_agent_event_data_s * response)
1436 {
1437         _INNER_FUNC_ENTER;
1438         retvm_if((request) == NULL, 0, "request is NULL!!");
1439
1440         _DEBUG_VERBOSE("Undefined Event !!! \n");
1441
1442         _INNER_FUNC_EXIT;
1443         return 0;
1444 }
1445
1446 int set_IPC()
1447 {
1448         _EXTERN_FUNC_ENTER;
1449
1450         sync_agent_event_error_e error = SYNC_AGENT_EVENT_IPC_ERR;
1451         int event_id = 0;
1452         for (event_id = 1; event_id < EVENT_NUM; event_id++) {
1453                 error = sync_agent_set_event_callback(event_id, _get_event_callback(event_id));
1454                 if (error != SYNC_AGENT_EVENT_SUCCESS) {
1455                         _DEBUG_INFO("FAILURE: sync_agent_set_event_callback (event id: %d)\n", event_id);
1456                         break;
1457                 } else {
1458                         _DEBUG_INFO("SUCCESS: sync_agent_set_event_callback (event id: %d)\n", event_id);
1459
1460                         g_mutex_init(&(mutex));
1461                         g_cond_init(&(cond));
1462                 }
1463         }
1464
1465         _DEBUG_INFO("%s: end (error:%d, event_id:%d) \n", __func__, error, event_id);
1466         _EXTERN_FUNC_EXIT;
1467         return error;
1468 }
1469
1470 int noti_start(char *ui_mode)
1471 {
1472         _EXTERN_FUNC_ENTER;
1473         _DEBUG_INFO("-----------------------------------------------------------------------noti start-------------------------------------------------------------------------------------");
1474         _EXTERN_FUNC_EXIT;
1475         return _IPC_noti(IPC_NOTI_TYPE_0, NOTI_ENGINE_START, 0, ui_mode, NULL);
1476 }
1477
1478 int noti_download(int file_size)
1479 {
1480         _EXTERN_FUNC_ENTER;
1481         _DEBUG_INFO("-----------------------------------------------------------------------noti_connect_to_server-------------------------------------------------------------------------------------");
1482         _EXTERN_FUNC_EXIT;
1483         return _IPC_noti(IPC_NOTI_TYPE_0, NOTI_DOWNLOAD, file_size, NULL, NULL);
1484 }
1485
1486 int noti_install()
1487 {
1488         _EXTERN_FUNC_ENTER;
1489         _DEBUG_INFO("-----------------------------------------------------------------------noti_install-------------------------------------------------------------------------------------");
1490         _EXTERN_FUNC_EXIT;
1491         return _IPC_noti(IPC_NOTI_TYPE_0, NOTI_INSTALL, 0, NULL, NULL);
1492 }
1493
1494 int noti_send_download_info(int filesize, char *path)
1495 {
1496         _EXTERN_FUNC_ENTER;
1497         _DEBUG_INFO("-----------------------------------------------------------------------noti_send_download_info-------------------------------------------------------------------------------------");
1498         _EXTERN_FUNC_EXIT;
1499         return _IPC_noti(IPC_NOTI_TYPE_0, NOTI_DOWNLOAD_INFO, filesize, path, NULL);
1500 }
1501
1502 int noti_low_battery(char *battery_level)
1503 {
1504         _EXTERN_FUNC_ENTER;
1505         _DEBUG_INFO("-----------------------------------------------------------------------noti_low_battery-------------------------------------------------------------------------------------");
1506         _EXTERN_FUNC_EXIT;
1507         return _IPC_noti(IPC_NOTI_TYPE_0, NOTI_LOW_BATTERY, 0, battery_level, NULL);
1508 }
1509
1510 int noti_update_result(int result)
1511 {
1512         _EXTERN_FUNC_ENTER;
1513         _DEBUG_INFO("-----------------------------------------------------------------------noti_update_result-------------------------------------------------------------------------------------");
1514         _EXTERN_FUNC_EXIT;
1515         return _IPC_noti(IPC_NOTI_TYPE_0, NOTI_UPDATE_RESULT, result, NULL, NULL);
1516 }
1517
1518 int alert_uic_display(uic_data * uic_value)
1519 {
1520         _EXTERN_FUNC_ENTER;
1521         _DEBUG_INFO("-----------------------------------------------------------------------noti_alert_ui_display-------------------------------------------------------------------------------------");
1522         _EXTERN_FUNC_EXIT;
1523         return _IPC_noti(IPC_NOTI_TYPE_0, NOTI_ALERT_DISPLAY, 0, OMADM_ALERT_UI_TYPE, uic_value);
1524 }
1525
1526 int alert_uic_confirmation(uic_data * uic_value)
1527 {
1528         _EXTERN_FUNC_ENTER;
1529         _DEBUG_INFO("-----------------------------------------------------------------------noti_alert_ui_confirmation-------------------------------------------------------------------------------------");
1530         _EXTERN_FUNC_EXIT;
1531         return _IPC_noti(IPC_NOTI_TYPE_0, NOTI_ALERT_CONFIRMATION, 0, OMADM_ALERT_UI_TYPE, uic_value);
1532 }
1533
1534 int alert_uic_inputText(uic_data * uic_value)
1535 {
1536         _EXTERN_FUNC_ENTER;
1537         _DEBUG_INFO("-----------------------------------------------------------------------noti_alert_ui_inputText-------------------------------------------------------------------------------------");
1538         _EXTERN_FUNC_EXIT;
1539         return _IPC_noti(IPC_NOTI_TYPE_0, NOTI_ALERT_INPUTTEXT, 0, OMADM_ALERT_UI_TYPE, uic_value);
1540 }
1541
1542 int alert_uic_single_choice(uic_data * uic_value)
1543 {
1544         _EXTERN_FUNC_ENTER;
1545         _DEBUG_INFO("-----------------------------------------------------------------------noti_alert_ui_single_choice-------------------------------------------------------------------------------------");
1546         _EXTERN_FUNC_EXIT;
1547         return _IPC_noti(IPC_NOTI_TYPE_0, NOTI_ALERT_SINGLE_CHOICE, 0, OMADM_ALERT_UI_TYPE, uic_value);
1548 }
1549
1550 int alert_uic_multiple_choice(uic_data * uic_value)
1551 {
1552         _EXTERN_FUNC_ENTER;
1553         _DEBUG_INFO("-----------------------------------------------------------------------noti_alert_ui_multi_choice-------------------------------------------------------------------------------------");
1554         _EXTERN_FUNC_EXIT;
1555         return _IPC_noti(IPC_NOTI_TYPE_0, NOTI_ALERT_MULTIPLE_CHOICE, 0, OMADM_ALERT_UI_TYPE, uic_value);
1556 }
1557
1558 int noti_engine_fail(int prev_noti_id, int fail_type)
1559 {
1560         _EXTERN_FUNC_ENTER;
1561         _DEBUG_INFO("-----------------------------------------------------------------------noti_engine_fail-------------------------------------------------------------------------------------");
1562         _EXTERN_FUNC_EXIT;
1563         return _IPC_noti(IPC_NOTI_TYPE_0, NOTI_ENGINE_FAIL, prev_noti_id, 0, &fail_type);
1564 }
1565
1566 int noti_wifi_only_download_fail()
1567 {
1568         _EXTERN_FUNC_ENTER;
1569         _DEBUG_INFO("-----------------------------------------------------------------------noti_wifi_only_download_fail-------------------------------------------------------------------------------------");
1570         _EXTERN_FUNC_EXIT;
1571         return _IPC_noti(IPC_NOTI_TYPE_0, NOTI_WIFI_ONLY_DOWNLOAD_FAIL, 0, 0, 0);
1572 }
1573
1574 int noti_memory_full(int file_size)
1575 {
1576         _EXTERN_FUNC_ENTER;
1577         _DEBUG_INFO("-----------------------------------------------------------------------noti_memory_full-------------------------------------------------------------------------------------");
1578         _EXTERN_FUNC_EXIT;
1579         return _IPC_noti(IPC_NOTI_TYPE_0, NOTI_MEMORY_FULL, file_size, 0, 0);
1580 }
1581
1582 int noti_over_max_file_size(int file_size)
1583 {
1584         _EXTERN_FUNC_ENTER;
1585         _DEBUG_INFO("-----------------------------------------------------------------------noti_over_max_file_size-------------------------------------------------------------------------------------");
1586         _EXTERN_FUNC_EXIT;
1587 //      return _IPC_noti(IPC_NOTI_TYPE_0, NOTI_OVER_BIG_SIZE, 0, 0, 0);
1588         return _IPC_noti(IPC_NOTI_TYPE_0, NOTI_OVER_BIG_SIZE, file_size, 0, 0);
1589 }
1590
1591 static int _IPC_noti(int noti_type, int noti_id, int input_param, char *input_string, void *user_data)
1592 {
1593         _INNER_FUNC_ENTER;
1594
1595         int ret = RESPONSE_TYPE_NONE;
1596         int task_id = -1;
1597         char *ui_mode = NULL;
1598         int count = 0;
1599         GList *iter = NULL;
1600         uic_data *uic_value = NULL;
1601         sync_agent_event_data_s *noti = NULL;
1602         sync_agent_event_data_s *reply_msg = NULL;
1603         sync_agent_event_error_e err = SYNC_AGENT_EVENT_FAIL;
1604
1605         task_id = sync_agent_get_self_request_id();
1606         _DEBUG_TRACE("task : id %d ", task_id);
1607         if (task_id == -1) {
1608                 ret = RESPONSE_TYPE_CANCEL;
1609                 _INNER_FUNC_EXIT;
1610                 goto return_part;
1611         }
1612
1613         ret = get_fumo_ui_mode(&ui_mode);
1614         _DEBUG_TRACE("get ui mode : %d", ret);
1615         if (ret != DM_OK) {
1616                 ret = RESPONSE_TYPE_CANCEL;
1617                 _INNER_FUNC_EXIT;
1618                 return ret;
1619         }
1620
1621         _DEBUG_TRACE("ui mode : %s", ui_mode);
1622         ret = __check_ui_mode(&ui_mode, input_string);
1623         if (ret != RESPONSE_TYPE_OK) {
1624                 str_free(&(ui_mode));
1625                 _INNER_FUNC_EXIT;
1626                 return RESPONSE_TYPE_CANCEL;
1627         }
1628         _DEBUG_TRACE("ui mode : %s", ui_mode);
1629
1630         //ret = __launch_ui(ui_mode, noti_type);
1631         ret = __launch_ui(ui_mode, noti_id);
1632         if (ret == -1) {
1633                 str_free(&(ui_mode));
1634                 _INNER_FUNC_EXIT;
1635                 return RESPONSE_TYPE_CANCEL;
1636         } else if (ret == 0) {
1637                 str_free(&(ui_mode));
1638                 _INNER_FUNC_EXIT;
1639                 return RESPONSE_TYPE_OK;
1640         }
1641
1642         _DEBUG_TRACE("ui mode : %s", ui_mode);
1643         _DEBUG_TRACE("create noti  noti_id : %d", noti_id);
1644
1645         noti = sync_agent_create_noti(noti_id);
1646         if (noti == NULL) {
1647                 _DEBUG_TRACE("failed to sync_agent_create_noti");
1648                 str_free(&(ui_mode));
1649                 _INNER_FUNC_EXIT;
1650                 return ret;
1651         }
1652
1653         _DEBUG_TRACE("append_eventdata");
1654         switch (noti_id) {
1655         case NOTI_UNKNOWN:
1656                 break;
1657         case NOTI_DOWNLOAD:     //Type 0
1658                 {
1659                         _DEBUG_TRACE("download file size : %d", input_param);
1660                         sync_agent_append_event_data_param(noti, SYNC_AGENT_EVENT_PARAM_TYPE_INTEGER, &input_param);
1661                 }
1662                 break;
1663         case NOTI_INSTALL:      //Type 0
1664                 break;
1665         case NOTI_DOWNLOAD_INFO:        //Type 0
1666                 {
1667                         if (&input_param == NULL || input_string == NULL) {
1668                                 _DEBUG_TRACE("Error: input param: NULL\n");
1669                                 ret = RESPONSE_TYPE_CANCEL;
1670                                 _INNER_FUNC_EXIT;
1671                                 goto return_part;
1672                         }
1673                         _DEBUG_TRACE("agent noti: filesize:%d, path:%s\n", input_param, input_string);
1674
1675                         sync_agent_append_event_data_param(noti, SYNC_AGENT_EVENT_PARAM_TYPE_INTEGER, &input_param);
1676                         sync_agent_append_event_data_param(noti, SYNC_AGENT_EVENT_PARAM_TYPE_STRING, input_string);
1677                         sync_agent_append_event_data_param(noti, SYNC_AGENT_EVENT_PARAM_TYPE_INTEGER, &task_id);
1678                 }
1679                 break;
1680         case NOTI_ENGINE_START: //Type 0
1681                 {
1682                         sync_agent_append_event_data_param(noti, SYNC_AGENT_EVENT_PARAM_TYPE_INTEGER, &task_id);
1683                 }
1684                 break;
1685         case NOTI_ENGINE_FAIL:  //Type 0
1686                 {
1687                         int *fail_type = (int *)(user_data);
1688
1689                         _DEBUG_TRACE("noti id : %d\n", input_param);
1690                         _DEBUG_TRACE("fail  : %d\n", *fail_type);
1691
1692                         sync_agent_append_event_data_param(noti, SYNC_AGENT_EVENT_PARAM_TYPE_INTEGER, &input_param);
1693                         sync_agent_append_event_data_param(noti, SYNC_AGENT_EVENT_PARAM_TYPE_INTEGER, fail_type);
1694                 }
1695                 break;
1696         case NOTI_WIFI_ONLY_DOWNLOAD_FAIL:      //Type 0
1697                 {
1698                         _DEBUG_TRACE("wifi only downlaod fail ipc");
1699                 }
1700                 break;
1701         case NOTI_MEMORY_FULL:  //Type 0
1702                 {
1703                         _DEBUG_TRACE("memory full ipc : %d", input_param);
1704                         sync_agent_append_event_data_param(noti, SYNC_AGENT_EVENT_PARAM_TYPE_INTEGER, &input_param);
1705
1706                 }
1707                 break;
1708         case NOTI_OVER_BIG_SIZE:        //Type 0
1709                 {
1710                         _DEBUG_TRACE("over max size : %d", input_param);
1711                         sync_agent_append_event_data_param(noti, SYNC_AGENT_EVENT_PARAM_TYPE_INTEGER, &input_param);
1712                 }
1713                 break;
1714         case NOTI_LOW_BATTERY:  //Type 0
1715                 {
1716                         if (input_string == NULL) {
1717
1718                                 _DEBUG_TRACE("Error : input string : NULL\n");
1719                                 ret = RESPONSE_TYPE_CANCEL;
1720                                 _INNER_FUNC_EXIT;
1721                                 goto return_part;
1722                         }
1723
1724                         _DEBUG_TRACE("agent noti - battery level : %s\n", input_string);
1725                         sync_agent_append_event_data_param(noti, SYNC_AGENT_EVENT_PARAM_TYPE_STRING, input_string);
1726                 }
1727                 break;
1728         case NOTI_UPDATE_RESULT:
1729                 {
1730                         _DEBUG_TRACE("fota update result : %d", input_param);
1731                         sync_agent_append_event_data_param(noti, SYNC_AGENT_EVENT_PARAM_TYPE_INTEGER, &input_param);
1732                 }
1733                 break;
1734         case NOTI_ALERT_DISPLAY:        //Type 2, response event
1735         case NOTI_ALERT_CONFIRMATION:   //Type 2, response event
1736         case NOTI_ALERT_INPUTTEXT:      //Type 2, response event
1737                 {
1738                         _DEBUG_TRACE("uic flow noti type : %d", noti_id);
1739                         uic_value = (uic_data *) user_data;
1740
1741                         uic_timeout_val = atoi(uic_value->pUic_option->max_t);
1742
1743                         sync_agent_append_event_data_param(noti, SYNC_AGENT_EVENT_PARAM_TYPE_STRING, uic_value->pUic_option->min_t);
1744                         sync_agent_append_event_data_param(noti, SYNC_AGENT_EVENT_PARAM_TYPE_STRING, uic_value->pUic_option->max_t);
1745                         sync_agent_append_event_data_param(noti, SYNC_AGENT_EVENT_PARAM_TYPE_STRING, uic_value->pUic_option->default_data);
1746                         sync_agent_append_event_data_param(noti, SYNC_AGENT_EVENT_PARAM_TYPE_STRING, uic_value->pUic_option->maxlen);
1747                         sync_agent_append_event_data_param(noti, SYNC_AGENT_EVENT_PARAM_TYPE_STRING, uic_value->pUic_option->input_type);
1748                         sync_agent_append_event_data_param(noti, SYNC_AGENT_EVENT_PARAM_TYPE_STRING, uic_value->pUic_option->echo_type);
1749
1750                         _DEBUG_TRACE("display : %s\n", uic_value->display);
1751                         sync_agent_append_event_data_param(noti, SYNC_AGENT_EVENT_PARAM_TYPE_STRING, uic_value->display);
1752                 }
1753                 break;
1754         case NOTI_ALERT_SINGLE_CHOICE:  //Type 2, response event
1755         case NOTI_ALERT_MULTIPLE_CHOICE:        //Type 2, response event
1756                 {
1757                         uic_value = (uic_data *) user_data;
1758
1759                         uic_timeout_val = atoi(uic_value->pUic_option->max_t);
1760
1761                         sync_agent_append_event_data_param(noti, SYNC_AGENT_EVENT_PARAM_TYPE_STRING, uic_value->pUic_option->min_t);
1762                         sync_agent_append_event_data_param(noti, SYNC_AGENT_EVENT_PARAM_TYPE_STRING, uic_value->pUic_option->max_t);
1763                         sync_agent_append_event_data_param(noti, SYNC_AGENT_EVENT_PARAM_TYPE_STRING, uic_value->pUic_option->default_data);
1764                         sync_agent_append_event_data_param(noti, SYNC_AGENT_EVENT_PARAM_TYPE_STRING, uic_value->pUic_option->maxlen);
1765                         sync_agent_append_event_data_param(noti, SYNC_AGENT_EVENT_PARAM_TYPE_STRING, uic_value->pUic_option->input_type);
1766                         sync_agent_append_event_data_param(noti, SYNC_AGENT_EVENT_PARAM_TYPE_STRING, uic_value->pUic_option->echo_type);
1767
1768                         _DEBUG_TRACE("display : %s\n", uic_value->display);
1769                         sync_agent_append_event_data_param(noti, SYNC_AGENT_EVENT_PARAM_TYPE_STRING, uic_value->display);
1770
1771                         count = g_list_length(uic_value->multi_data);
1772                         _DEBUG_TRACE("choice data count : %d\n", count);
1773                         sync_agent_append_event_data_param(noti, SYNC_AGENT_EVENT_PARAM_TYPE_INTEGER, &count);
1774
1775                         for (iter = uic_value->multi_data; iter != NULL; iter = g_list_next(iter)) {
1776                                 _DEBUG_TRACE("choice data : %s", (char *)(iter->data));
1777                                 sync_agent_append_event_data_param(noti, SYNC_AGENT_EVENT_PARAM_TYPE_STRING, (char *)(iter->data));
1778                         }
1779                 }
1780                 break;
1781
1782         default:
1783                 break;
1784         }
1785
1786         if (noti_id != NOTI_ALERT_DISPLAY && noti_id != NOTI_ALERT_CONFIRMATION && noti_id != NOTI_ALERT_INPUTTEXT && noti_id != NOTI_ALERT_SINGLE_CHOICE && noti_id != NOTI_ALERT_MULTIPLE_CHOICE) {
1787                 DB_Begin_Transaction();
1788
1789                 ret = Update_Engine_Status_Column(FUMO_SERVICE_ENGINE, VALUE_UI_NOTI_TYPE, &noti_id);
1790                 if (ret != DM_OK) {
1791                         _DEBUG_TRACE("update engine status column : %d, %d\n", ret, noti_id);
1792                         ret = RESPONSE_TYPE_CANCEL;
1793                         goto return_part;
1794                 }
1795         }
1796
1797         _DEBUG_TRACE("sendNoti");
1798         reply_msg = sync_agent_send_noti(ui_mode, noti, __dm_task_process_check_cancel_flag, ui_mode, &err);
1799         if(reply_msg == NULL) {
1800                 _DEBUG_TRACE("sendNoti return : %d", err);
1801         } else {
1802                 _DEBUG_TRACE("sendNoti return : %d , event_num[%d] , reply_msg data[%s]", err, reply_msg->event_num, reply_msg->data);
1803         }
1804         if (err != SYNC_AGENT_EVENT_SUCCESS) {
1805                 if (err == SYNC_AGENT_EVENT_IPC_ERR) {
1806                         //todo : ui off
1807                         if (noti_id != NOTI_ALERT_DISPLAY && noti_id != NOTI_ALERT_CONFIRMATION && noti_id != NOTI_ALERT_INPUTTEXT && noti_id != NOTI_ALERT_SINGLE_CHOICE && noti_id != NOTI_ALERT_MULTIPLE_CHOICE) {
1808                                 DB_End_Transaction(TRANSACTION_ROLLBACK_);
1809                         }
1810                 }
1811
1812                 _DEBUG_TRACE("sendNoti (noti id:%d), FAIL\n", noti_id);
1813                 ret = RESPONSE_TYPE_CANCEL;
1814                 goto return_part;
1815
1816         } else {
1817
1818                 _DEBUG_TRACE("sendNoti (noti id:%d), success\n", noti_id);
1819                 _DEBUG_TRACE("IPC RESPONSE\n");
1820
1821                 if (noti_id != NOTI_ALERT_DISPLAY && noti_id != NOTI_ALERT_CONFIRMATION && noti_id != NOTI_ALERT_INPUTTEXT && noti_id != NOTI_ALERT_SINGLE_CHOICE && noti_id != NOTI_ALERT_MULTIPLE_CHOICE) {
1822                         DB_End_Transaction(TRANSACTION_COMMIT_);
1823                 } else {
1824                         ret = __uic_response(noti_id, user_data);
1825                         _DEBUG_TRACE("uic_response ret : %d", ret);
1826                 }
1827         }
1828
1829         if (ret == DM_OK) {
1830                 ret = RESPONSE_TYPE_OK;
1831         }
1832
1833         str_free(&(ui_mode));
1834         sync_agent_free_noti(noti);
1835         _INNER_FUNC_EXIT;
1836         return ret;
1837
1838  return_part:
1839
1840         str_free(&(ui_mode));
1841         sync_agent_free_noti(noti);
1842         _DEBUG_TRACE("%s : end : %d\n", __func__, ret);
1843         _INNER_FUNC_EXIT;
1844         return ret;
1845 }
1846
1847 sync_agent_event_ipc_cancel_e __dm_task_process_check_cancel_flag(void *user_data)
1848 {
1849         _INNER_FUNC_ENTER;
1850
1851         retvm_if((user_data) == NULL, SYNC_AGENT_EVENT_IPC_CANCEL_NEED_CANCEL, "user_data is NULL!!");
1852
1853         sync_agent_ec_boolean cancel_flag = sync_agent_check_cancel_flag();
1854         sync_agent_event_ipc_cancel_e result_cancel;
1855         int result_ui;
1856         char *ui_mode = (char *)user_data;
1857
1858         if (cancel_flag == 0) {
1859                 result_cancel = SYNC_AGENT_EVENT_IPC_CANCEL_UN_NEED_CANCEL;
1860                 _DEBUG_VERBOSE("%s : cancel_flag = %d\n", __func__, result_cancel);
1861         } else {
1862                 result_cancel = SYNC_AGENT_EVENT_IPC_CANCEL_NEED_CANCEL;
1863                 _DEBUG_VERBOSE("%s : cancel_flag = %d\n", __func__, result_cancel);
1864         }
1865
1866         if (strcmp(ui_mode, OMADM_FUMO_UI_TYPE) == 0) {
1867                 result_ui = aul_app_is_running(OMA_DM_FUMO_UI_PKG);
1868                 if (result_ui == 0) {
1869                         _DEBUG_VERBOSE("oma dm fumo ui process off \n");
1870                         result_cancel = SYNC_AGENT_EVENT_IPC_CANCEL_NEED_CANCEL;
1871                 }
1872         } else if (strcmp(ui_mode, OMADM_FUMO_NOTI_UI_TYPE) == 0) {
1873                 result_ui = aul_app_is_running(OMA_DM_FUMO_NOTI_UI_PKG);
1874                 if (result_ui == 0) {
1875                         _DEBUG_VERBOSE("oma dm noti ui process off \n");
1876                         result_cancel = SYNC_AGENT_EVENT_IPC_CANCEL_NEED_CANCEL;
1877                 }
1878         }
1879
1880         _INNER_FUNC_EXIT;
1881
1882         return result_cancel;
1883 }
1884
1885 static int __uic_response(int noti_id, void *user_data)
1886 {
1887         _INNER_FUNC_ENTER;
1888         int ret = RESPONSE_TYPE_NONE;
1889
1890         switch (noti_id) {
1891         case NOTI_ALERT_DISPLAY:        //Type 0
1892                 {
1893                         _DEBUG_TRACE("display alert response ");
1894                         ret = RESPONSE_TYPE_OK;
1895                 }
1896                 break;
1897         case NOTI_ALERT_CONFIRMATION:   //Type 0
1898                 {
1899                         _DEBUG_TRACE("confirmation alert response ");
1900
1901                         //signal on
1902                         if (uic_timeout_val == TIMEOUT_VAL_UIC) {
1903                                 uic_timeout_val = TIMEOUT_VAL_UIC + REST_TIMEOUT_VAL;
1904                         } else {
1905                                 uic_timeout_val += REST_TIMEOUT_VAL;
1906                         }
1907
1908                         timeout = g_get_monotonic_time() + uic_timeout_val * G_TIME_SPAN_SECOND;
1909
1910                         _DEBUG_TRACE("timeout : %d ", timeout);
1911
1912                         g_mutex_lock(&(mutex));
1913                         g_cond_wait_until(&(cond), &(mutex), timeout);
1914                         g_mutex_unlock(&(mutex));
1915
1916                         if (res_uic_data == NULL) {
1917                                 /*signal by timeout */
1918                                 ret = RESPONSE_TYPE_TIMEOVER;
1919                         } else {
1920                                 ret = res_uic_data->status;
1921                                 _DEBUG_TRACE("response is %d\n", ret);
1922
1923                                 free_res_data(res_uic_data);
1924                                 res_uic_data = NULL;
1925                         }
1926                 }
1927                 break;
1928         case NOTI_ALERT_INPUTTEXT:      //Type 0
1929                 {
1930                         //signal on
1931                         if (uic_timeout_val == TIMEOUT_VAL_UIC) {
1932                                 uic_timeout_val = TIMEOUT_VAL_UIC + REST_TIMEOUT_VAL;
1933                         } else {
1934                                 uic_timeout_val += REST_TIMEOUT_VAL;
1935                         }
1936
1937                         timeout = g_get_monotonic_time() + uic_timeout_val * G_TIME_SPAN_SECOND;
1938
1939                         _DEBUG_TRACE("timeout : %d ", timeout);
1940
1941                         g_mutex_lock(&(mutex));
1942                         g_cond_wait_until(&(cond), &(mutex), timeout);
1943                         g_mutex_unlock(&(mutex));
1944
1945                         uic_data *uic_value = (uic_data *) user_data;
1946
1947                         if (res_uic_data == NULL) {
1948                                 /*signal by timeout */
1949                                 uic_value->res_data->input_text = strdup("NULL");
1950                                 _DEBUG_TRACE("INPUT TEXT CANCEL / TIMEOVER");
1951                                 ret = RESPONSE_TYPE_TIMEOVER;
1952                         } else {
1953                                 ret = res_uic_data->status;
1954                                 _DEBUG_TRACE("response is %d\n", ret);
1955                                 _DEBUG_TRACE("input text alert response ");
1956
1957                                 if (ret == RESPONSE_TYPE_OK) {
1958                                         if (res_uic_data->input_text == NULL) {
1959                                                 res_uic_data->input_text = strdup("NULL");
1960                                         }
1961
1962                                         uic_value->res_data->input_text = strdup(res_uic_data->input_text);
1963
1964                                 } else {
1965                                         uic_value->res_data->input_text = strdup("NULL");
1966                                         _DEBUG_TRACE("INPUT TEXT CANCEL / TIMEOVER");
1967                                 }
1968
1969                                 free_res_data(res_uic_data);
1970                                 res_uic_data = NULL;
1971                         }
1972                 }
1973                 break;
1974         case NOTI_ALERT_SINGLE_CHOICE:  //Type 0
1975         case NOTI_ALERT_MULTIPLE_CHOICE:        //Type 0
1976                 {
1977
1978                         //signal on
1979                         if (uic_timeout_val == TIMEOUT_VAL_UIC) {
1980                                 uic_timeout_val = TIMEOUT_VAL_UIC + REST_TIMEOUT_VAL;
1981                         } else {
1982                                 uic_timeout_val += REST_TIMEOUT_VAL;
1983                         }
1984
1985                         timeout = g_get_monotonic_time() + uic_timeout_val * G_TIME_SPAN_SECOND;
1986                         _DEBUG_TRACE("timeout : %d ", timeout);
1987
1988                         g_mutex_lock(&(mutex));
1989                         g_cond_wait_until(&(cond), &(mutex), timeout);
1990                         g_mutex_unlock(&(mutex));
1991
1992                         _DEBUG_TRACE("choice alert response ");
1993
1994                         uic_data *uic_value = (uic_data *) user_data;
1995                         int count = 0;
1996                         char *input = NULL;
1997
1998                         if (res_uic_data == NULL) {
1999                                 /*signal by timeout */
2000                                 ret = RESPONSE_TYPE_TIMEOVER;
2001                                 input = strdup("NULL");
2002                                 uic_value->res_data->res_multi_data = g_list_append(uic_value->res_data->res_multi_data, input);
2003                                 _DEBUG_TRACE("CHOICE CANCEL / TIMEOVER");
2004                         } else {
2005                                 ret = res_uic_data->status;
2006                                 _DEBUG_TRACE("response is %d\n", ret);
2007
2008                                 if (ret == RESPONSE_TYPE_OK) {
2009
2010                                         if (res_uic_data->res_multi_data != NULL) {
2011                                                 count = g_list_length(res_uic_data->res_multi_data);
2012
2013                                                 if (count == 0) {
2014                                                         input = strdup("NULL");
2015                                                         uic_value->res_data->res_multi_data = g_list_append(uic_value->res_data->res_multi_data, input);
2016                                                 } else {
2017                                                         GList *iter = NULL;
2018                                                         for (iter = res_uic_data->res_multi_data; iter != NULL; iter = g_list_next(iter)) {
2019                                                                 input = NULL;
2020                                                                 input = strdup(iter->data);
2021                                                                 uic_value->res_data->res_multi_data = g_list_append(uic_value->res_data->res_multi_data, input);
2022                                                         }
2023                                                 }
2024                                         } else {
2025                                                 input = strdup("NULL");
2026                                                 uic_value->res_data->res_multi_data = g_list_append(uic_value->res_data->res_multi_data, input);
2027                                                 _DEBUG_TRACE("CHOICE CANCEL / TIMEOVER");
2028                                         }
2029                                 }
2030
2031                                 free_res_data(res_uic_data);
2032                                 res_uic_data = NULL;
2033                         }
2034                 }
2035                 break;
2036         case NOTI_DOWNLOAD:
2037         case NOTI_INSTALL:
2038         case NOTI_DOWNLOAD_INFO:
2039         case NOTI_ENGINE_START:
2040         case NOTI_LOW_BATTERY:
2041         case NOTI_OVER_BIG_SIZE:
2042                 break;
2043
2044         default:
2045                 break;
2046         }
2047
2048         _INNER_FUNC_EXIT;
2049         return ret;
2050 }