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