prevent from race condition when terminate msg-manager
[platform/core/messaging/msg-service.git] / manager / src / msg-manager.cpp
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <glib.h>
4
5 extern "C"
6 {
7 #include <tizen.h>
8 #include <service_app.h>
9 #include <app_event.h>
10 #include <notification_list.h>
11 #include <notification_text_domain.h>
12 #include <notification_internal.h>
13 #include <vconf.h>
14 #include <call-manager.h>
15 }
16
17 #include "msg.h"
18 #include "msg_storage.h"
19
20 #include "msg-manager-contact.h"
21 #include "msg-manager-debug.h"
22 #include "msg-manager-notification.h"
23 #include "msg-manager-sound.h"
24 #include "msg-manager-util.h"
25
26 /* below defines will be removed */
27 #define EVENT_KEY_OUT_MSG_TYPE "msg_type"
28 #define EVENT_KEY_OUT_MSG_ID "msg_id"
29
30 msg_handle_t msg_handle = NULL;
31 cm_client_h cm_handle = NULL;
32
33 pthread_mutex_t mx;
34 static int job_cnt = 0;
35 static bool terminated = false;
36
37 static int _service_app_exit(void *data)
38 {
39         MSG_MGR_INFO("kill msg-manager");
40         service_app_exit();
41
42         return 0;
43 }
44
45 static int _check_app_terminate(void *data)
46 {
47         pthread_mutex_lock(&mx);
48
49         job_cnt--;
50         MSG_MGR_DEBUG("job_cnt [%d]", job_cnt);
51         if (job_cnt == 0) {
52                 terminated = true;
53                 g_idle_add(_service_app_exit, NULL);
54         }
55
56         pthread_mutex_unlock(&mx);
57
58         return 0;
59 }
60
61 bool service_app_create(void *data)
62 {
63         MSG_MGR_INFO("app_create");
64
65         int msg_server_ready = 0;
66         for (int i = 0; i < 100; i++) {
67                 vconf_get_bool(VCONFKEY_MSG_SERVER_READY, &msg_server_ready);
68                 if (msg_server_ready == 1) {
69                         int msg_err = msg_open_msg_handle(&msg_handle);
70                         if (msg_err != MSG_SUCCESS)
71                                 MSG_MGR_DEBUG("msg_open_msg_handle() failed [%d]", msg_err);
72                         else
73                                 MSG_MGR_DEBUG("msg_open_msg_handle() success");
74
75                         break;
76                 } else {
77                         MSG_MGR_DEBUG("msg-server is not ready.");
78                         sleep(1);
79                 }
80         }
81
82         MsgMgrInitNoti();
83         initMsgMgrSoundPlayer();
84         cm_init(&cm_handle);
85
86         return true;
87 }
88
89 void service_app_terminate(void *data)
90 {
91         MSG_MGR_INFO("app_terminate");
92
93         cm_deinit(cm_handle);
94         MsgMgrCloseContactSvc();
95         msg_close_msg_handle(&msg_handle);
96
97         return;
98 }
99
100 void _incoming_msg_func(app_control_h app_control)
101 {
102         MSG_MGR_BEGIN();
103
104         int ret = 0;
105         char *rcv_msg_type = NULL;
106         char *rcv_msg_id = NULL;
107
108         ret = app_control_get_extra_data(app_control, EVENT_KEY_MSG_ID, &rcv_msg_id);
109         if (ret != APP_CONTROL_ERROR_NONE || rcv_msg_id == NULL) {
110                 MSG_MGR_ERR("app_control_get_extra_data failed");
111                 return;
112         }
113
114         ret = app_control_get_extra_data(app_control, EVENT_KEY_MSG_TYPE, &rcv_msg_type);
115         if (ret != APP_CONTROL_ERROR_NONE || rcv_msg_type == NULL) {
116                 MSG_MGR_ERR("app_control_get_extra_data failed");
117                 g_free(rcv_msg_id);
118                 return;
119         }
120
121         MSG_MGR_INFO("rcv_msg_type(%s), rcv_msg_id(%s)", rcv_msg_type, rcv_msg_id);
122
123         int msg_err = MSG_SUCCESS;
124         msg_message_id_t msg_id = atoi(rcv_msg_id);
125         msg_struct_t msg = NULL;
126         msg_struct_t opt = NULL;
127         contactInfo contact_info = {0,};
128         contact_info.msgId = msg_id;
129
130         msg = msg_create_struct(MSG_STRUCT_MESSAGE_INFO);
131         opt = msg_create_struct(MSG_STRUCT_SENDOPT);
132         msg_err = msg_get_message(msg_handle, msg_id, msg, opt);
133         if (msg_err != MSG_SUCCESS) {
134                 MSG_MGR_ERR("msg_get_message() failed [%d]", msg_err);
135                 return;
136         }
137
138         msg_get_int_value(msg, MSG_MESSAGE_TYPE_INT, &contact_info.msgType);
139         msg_get_int_value(msg, MSG_MESSAGE_FOLDER_ID_INT, &contact_info.folderId);
140         msg_get_int_value(msg, MSG_MESSAGE_SIM_INDEX_INT, &contact_info.simIndex);
141         msg_get_list_handle(msg, MSG_MESSAGE_ADDR_LIST_HND, (void **)&contact_info.addrList);
142         msg_get_str_value(msg, MSG_MESSAGE_SUBJECT_STR, contact_info.subject, MAX_CONTACT_TEXT_LEN);
143         int msgSize = 0;
144         msg_get_int_value(msg, MSG_MESSAGE_DATA_SIZE_INT, &msgSize);
145         if (msgSize > 0)
146                 msg_get_str_value(msg, MSG_MESSAGE_SMS_DATA_STR, contact_info.msgText, MAX_CONTACT_TEXT_LEN);
147
148         if ((contact_info.folderId == MSG_INBOX_ID || contact_info.folderId == MSG_SPAMBOX_ID)) {
149                 MsgMgrAddPhoneLog(&contact_info);
150         }
151
152         msg_release_struct(&msg);
153         msg_release_struct(&opt);
154
155         g_free(rcv_msg_id);
156         g_free(rcv_msg_type);
157
158         MSG_MGR_END();
159 }
160
161 void _outgoing_msg_func(app_control_h app_control)
162 {
163         MSG_MGR_BEGIN();
164
165         int ret = 0;
166         char *sent_msg_type = NULL;
167         char *sent_msg_id = NULL;
168
169         ret = app_control_get_extra_data(app_control, EVENT_KEY_OUT_MSG_ID, &sent_msg_id);
170         if (ret != APP_CONTROL_ERROR_NONE || sent_msg_id == NULL) {
171                 MSG_MGR_ERR("app_control_get_extra_data failed");
172                 return;
173         }
174
175         ret = app_control_get_extra_data(app_control, EVENT_KEY_OUT_MSG_TYPE, &sent_msg_type);
176         if (ret != APP_CONTROL_ERROR_NONE || sent_msg_type == NULL) {
177                 MSG_MGR_ERR("app_control_get_extra_data failed");
178                 g_free(sent_msg_id);
179                 return;
180         }
181
182         MSG_MGR_INFO("sent_msg_type(%s) sent_msg_id(%s)", sent_msg_type, sent_msg_id);
183
184         int msg_err = MSG_SUCCESS;
185         msg_message_id_t msg_id = atoi(sent_msg_id);
186         msg_struct_t msg = NULL;
187         msg_struct_t opt = NULL;
188         contactInfo contact_info = {0,};
189         contact_info.msgId = msg_id;
190
191         msg = msg_create_struct(MSG_STRUCT_MESSAGE_INFO);
192         opt = msg_create_struct(MSG_STRUCT_SENDOPT);
193         msg_err = msg_get_message(msg_handle, msg_id, msg, opt);
194         if (msg_err != MSG_SUCCESS) {
195                 MSG_MGR_ERR("msg_get_message() failed [%d]", msg_err);
196                 return;
197         }
198
199         msg_get_int_value(msg, MSG_MESSAGE_TYPE_INT, &contact_info.msgType);
200         msg_get_int_value(msg, MSG_MESSAGE_FOLDER_ID_INT, &contact_info.folderId);
201         msg_get_int_value(msg, MSG_MESSAGE_SIM_INDEX_INT, &contact_info.simIndex);
202         msg_get_list_handle(msg, MSG_MESSAGE_ADDR_LIST_HND, (void **)&contact_info.addrList);
203         msg_get_str_value(msg, MSG_MESSAGE_SUBJECT_STR, contact_info.subject, 100);
204         int msgSize = 0;
205         msg_get_int_value(msg, MSG_MESSAGE_DATA_SIZE_INT, &msgSize);
206         if (msgSize > 0)
207                 msg_get_str_value(msg, MSG_MESSAGE_SMS_DATA_STR, contact_info.msgText, 100);
208
209         MsgMgrAddPhoneLog(&contact_info);
210
211         msg_release_struct(&msg);
212         msg_release_struct(&opt);
213
214         g_free(sent_msg_id);
215         g_free(sent_msg_type);
216
217         MSG_MGR_END();
218 }
219
220 void _refresh_noti_func(app_control_h app_control)
221 {
222         char *type = NULL;
223         char *feedback = NULL;
224         char *active_type = NULL;
225         msg_mgr_notification_type_t noti_type = MSG_MGR_NOTI_TYPE_NORMAL;
226         bool bFeedback = true;
227         msg_mgr_active_notification_type_t active_noti_type = MSG_MGR_ACTIVE_NOTI_TYPE_NONE;
228
229         int ret = app_control_get_extra_data(app_control, "type", &type);
230         if (ret == APP_CONTROL_ERROR_NONE && type) {
231                 MSG_MGR_DEBUG("type [%s]", type);
232                 if (g_strcmp0(type, "normal") == 0)
233                         noti_type = MSG_MGR_NOTI_TYPE_NORMAL;
234
235                 g_free(type);
236         } else {
237                 MSG_MGR_ERR("app_control_get_extra_data failed");
238                 return;
239         }
240
241         ret = app_control_get_extra_data(app_control, "feedback", &feedback);
242         if (ret == APP_CONTROL_ERROR_NONE && feedback) {
243                 MSG_MGR_DEBUG("feedback [%s]", feedback);
244                 if (g_strcmp0(feedback, "false") == 0)
245                         bFeedback = false;
246                 else if (g_strcmp0(feedback, "true") == 0)
247                         bFeedback = true;
248
249                 g_free(feedback);
250         }
251
252         ret = app_control_get_extra_data(app_control, "active_type", &active_type);
253         if (ret == APP_CONTROL_ERROR_NONE && active_type) {
254                 MSG_MGR_DEBUG("active_type [%s]", active_type);
255                 if (g_strcmp0(active_type, "none") == 0)
256                         active_noti_type = MSG_MGR_ACTIVE_NOTI_TYPE_NONE;
257                 else if (g_strcmp0(active_type, "active") == 0)
258                         active_noti_type = MSG_MGR_ACTIVE_NOTI_TYPE_ACTIVE;
259                 else if (g_strcmp0(active_type, "instant") == 0)
260                         active_noti_type = MSG_MGR_ACTIVE_NOTI_TYPE_INSTANT;
261
262                 g_free(active_type);
263         }
264
265         MsgMgrRefreshNotification(noti_type, bFeedback, active_noti_type);
266 }
267
268 void _add_noti_func(app_control_h app_control)
269 {
270         char *type;
271         msg_mgr_notification_type_t noti_type = MSG_MGR_NOTI_TYPE_ALL;
272
273         int ret = app_control_get_extra_data(app_control, "type", &type);
274         if (ret == APP_CONTROL_ERROR_NONE && type) {
275                 if (g_strcmp0(type, "voice1") == 0) {
276                         noti_type = MSG_MGR_NOTI_TYPE_VOICE_1;
277                 } else if (g_strcmp0(type, "voice2") == 0) {
278                         noti_type = MSG_MGR_NOTI_TYPE_VOICE_2;
279                 } else if (g_strcmp0(type, "mwi") == 0) {
280                         noti_type = MSG_MGR_NOTI_TYPE_MWI;
281                 } else if (g_strcmp0(type, "class0") == 0) {
282                         noti_type = MSG_MGR_NOTI_TYPE_CLASS0;
283                 }
284
285                 g_free(type);
286         } else {
287                 MSG_MGR_ERR("app_control_get_extra_data failed");
288                 return;
289         }
290
291         char *msgId = NULL;
292         ret = app_control_get_extra_data(app_control, "msg_id", &msgId);
293         if (ret != APP_CONTROL_ERROR_NONE || msgId == NULL) {
294                 MSG_MGR_ERR("app_control_get_extra_data failed");
295                 return;
296         }
297
298         int msg_err = MSG_SUCCESS;
299         msg_message_id_t msg_id = atoi(msgId);
300         msg_struct_t msg = NULL;
301         msg_struct_t opt = NULL;
302         msg_list_handle_t addr_list = NULL;
303         MSG_MGR_MESSAGE_INFO_S msg_info = {0,};
304         msg_info.msgId = msg_id;
305
306         msg = msg_create_struct(MSG_STRUCT_MESSAGE_INFO);
307         opt = msg_create_struct(MSG_STRUCT_SENDOPT);
308         msg_err = msg_get_message(msg_handle, msg_id, msg, opt);
309         if (msg_err != MSG_SUCCESS) {
310                 MSG_MGR_ERR("msg_get_message() failed [%d]", msg_err);
311                 return;
312         }
313
314         msg_get_int_value(msg, MSG_MESSAGE_SIM_INDEX_INT, &msg_info.sim_idx);
315         msg_get_int_value(msg, MSG_MESSAGE_DISPLAY_TIME_INT, (int *)&msg_info.displayTime);
316         msg_get_int_value(msg, MSG_MESSAGE_NETWORK_STATUS_INT, (int *)&msg_info.networkStatus);
317         msg_get_list_handle(msg, MSG_MESSAGE_ADDR_LIST_HND, (void **)&addr_list);
318
319         msg_struct_t addr_data = msg_list_nth_data(addr_list, 0);
320         msg_get_str_value(addr_data, MSG_ADDRESS_INFO_ADDRESS_VALUE_STR, msg_info.addressVal, MAX_ADDRESS_VAL_LEN);
321         msg_get_str_value(addr_data, MSG_ADDRESS_INFO_DISPLAYNAME_STR, msg_info.displayName, MAX_DISPLAY_NAME_LEN);
322
323         if (noti_type == MSG_MGR_NOTI_TYPE_MWI || noti_type == MSG_MGR_NOTI_TYPE_CLASS0) {
324                 int msg_size = 0;
325                 msg_get_int_value(msg, MSG_MESSAGE_DATA_SIZE_INT, &msg_size);
326                 if (msg_size > 0)
327                         msg_get_str_value(msg, MSG_MESSAGE_SMS_DATA_STR, msg_info.msgText, MAX_MSG_TEXT_LEN);
328         }
329
330         msg_release_struct(&msg);
331         msg_release_struct(&opt);
332
333         g_free(msgId);
334
335         MsgMgrAddNotification(noti_type, &msg_info);
336 }
337
338 void _del_noti_func(app_control_h app_control)
339 {
340         char *type;
341         msg_mgr_notification_type_t noti_type = MSG_MGR_NOTI_TYPE_ALL;
342
343         int ret = app_control_get_extra_data(app_control, "type", &type);
344         if (ret == APP_CONTROL_ERROR_NONE && type) {
345                 if (g_strcmp0(type, "all") == 0) {
346                         noti_type = MSG_MGR_NOTI_TYPE_ALL;
347                 } else if (g_strcmp0(type, "normal") == 0) {
348                         noti_type = MSG_MGR_NOTI_TYPE_NORMAL;
349                 } else if (g_strcmp0(type, "sim") == 0) {
350                         noti_type = MSG_MGR_NOTI_TYPE_SIM;
351                 } else if (g_strcmp0(type, "voice1") == 0) {
352                         noti_type = MSG_MGR_NOTI_TYPE_VOICE_1;
353                 } else if (g_strcmp0(type, "voice2") == 0) {
354                         noti_type = MSG_MGR_NOTI_TYPE_VOICE_2;
355                 }
356
357                 g_free(type);
358         } else {
359                 MSG_MGR_ERR("app_control_get_extra_data failed");
360                 return;
361         }
362
363         char *simIndex = NULL;
364         ret = app_control_get_extra_data(app_control, "sim_index", &simIndex);
365         if (ret != APP_CONTROL_ERROR_NONE || simIndex == NULL) {
366                 MSG_MGR_ERR("app_control_get_extra_data failed");
367                 return;
368         }
369
370         int sim_index = atoi(simIndex);
371
372         MsgMgrDeleteNoti(noti_type, sim_index);
373
374         g_free(simIndex);
375 }
376
377 void _add_report_noti_func(app_control_h app_control)
378 {
379         char *type;
380         msg_mgr_notification_type_t noti_type = MSG_MGR_NOTI_TYPE_ALL;
381
382         int ret = app_control_get_extra_data(app_control, "type", &type);
383         if (ret == APP_CONTROL_ERROR_NONE && type) {
384                 if (g_strcmp0(type, "sms_delivery") == 0) {
385                         noti_type = MSG_MGR_NOTI_TYPE_SMS_DELIVERY_REPORT;
386                 } else if (g_strcmp0(type, "mms_delivery") == 0) {
387                         noti_type = MSG_MGR_NOTI_TYPE_MMS_DELIVERY_REPORT;
388                 } else if (g_strcmp0(type, "mms_read") == 0) {
389                         noti_type = MSG_MGR_NOTI_TYPE_MMS_READ_REPORT;
390                 }
391
392                 g_free(type);
393         } else {
394                 MSG_MGR_ERR("app_control_get_extra_data failed");
395                 return;
396         }
397
398         char *msgId = NULL;
399         ret = app_control_get_extra_data(app_control, "msg_id", &msgId);
400         if (ret != APP_CONTROL_ERROR_NONE || msgId == NULL) {
401                 MSG_MGR_ERR("app_control_get_extra_data failed");
402                 return;
403         }
404
405         int msg_err = MSG_SUCCESS;
406         msg_message_id_t msg_id = atoi(msgId);
407         msg_struct_t msg = NULL;
408         msg_struct_t opt = NULL;
409         msg_list_handle_t addr_list = NULL;
410         MSG_MGR_MESSAGE_INFO_S msg_info = {0,};
411         msg_info.msgId = msg_id;
412
413         msg = msg_create_struct(MSG_STRUCT_MESSAGE_INFO);
414         opt = msg_create_struct(MSG_STRUCT_SENDOPT);
415         msg_err = msg_get_message(msg_handle, msg_id, msg, opt);
416         if (msg_err != MSG_SUCCESS) {
417                 MSG_MGR_ERR("msg_get_message() failed [%d]", msg_err);
418                 return;
419         }
420
421         msg_get_int_value(msg, MSG_MESSAGE_SIM_INDEX_INT, &msg_info.sim_idx);
422         msg_get_int_value(msg, MSG_MESSAGE_DISPLAY_TIME_INT, (int *)&msg_info.displayTime);
423         msg_get_int_value(msg, MSG_MESSAGE_NETWORK_STATUS_INT, (int *)&msg_info.networkStatus);
424         msg_get_list_handle(msg, MSG_MESSAGE_ADDR_LIST_HND, (void **)&addr_list);
425
426         msg_struct_t addr_data = msg_list_nth_data(addr_list, 0);
427         msg_get_str_value(addr_data, MSG_ADDRESS_INFO_ADDRESS_VALUE_STR, msg_info.addressVal, MAX_ADDRESS_VAL_LEN);
428         msg_get_str_value(addr_data, MSG_ADDRESS_INFO_DISPLAYNAME_STR, msg_info.displayName, MAX_DISPLAY_NAME_LEN);
429
430         msg_release_struct(&msg);
431         msg_release_struct(&opt);
432
433         g_free(msgId);
434
435         MsgMgrAddReportNotification(noti_type, &msg_info);
436 }
437
438 void _del_report_noti_func(app_control_h app_control)
439 {
440         char *addr = NULL;
441         int ret = app_control_get_extra_data(app_control, "address", &addr);
442         if (ret != APP_CONTROL_ERROR_NONE || addr == NULL) {
443                 MSG_MGR_ERR("app_control_get_extra_data failed");
444                 return;
445         }
446
447         MsgMgrDeleteReportNotification(addr);
448
449         g_free(addr);
450 }
451
452 void _insert_only_active_noti_func(app_control_h app_control)
453 {
454         char *type;
455         msg_mgr_notification_type_t noti_type = MSG_MGR_NOTI_TYPE_ALL;
456
457         int ret = app_control_get_extra_data(app_control, "type", &type);
458         if (ret == APP_CONTROL_ERROR_NONE && type) {
459                 if (g_strcmp0(type, "normal") == 0) {
460                         noti_type = MSG_MGR_NOTI_TYPE_NORMAL;
461                 } else if (g_strcmp0(type, "class0") == 0) {
462                         noti_type = MSG_MGR_NOTI_TYPE_CLASS0;
463                 }
464
465                 g_free(type);
466         } else {
467                 MSG_MGR_ERR("app_control_get_extra_data failed");
468                 return;
469         }
470
471         char *msgId = NULL;
472         ret = app_control_get_extra_data(app_control, "msg_id", &msgId);
473         if (ret != APP_CONTROL_ERROR_NONE || msgId == NULL) {
474                 MSG_MGR_ERR("app_control_get_extra_data failed");
475                 return;
476         }
477
478         int msg_err = MSG_SUCCESS;
479         msg_message_id_t msg_id = atoi(msgId);
480         msg_struct_t msg = NULL;
481         msg_struct_t opt = NULL;
482         msg_list_handle_t addr_list = NULL;
483         MSG_MGR_MESSAGE_INFO_S msg_info = {0,};
484         msg_info.msgId = msg_id;
485
486         msg = msg_create_struct(MSG_STRUCT_MESSAGE_INFO);
487         opt = msg_create_struct(MSG_STRUCT_SENDOPT);
488         msg_err = msg_get_message(msg_handle, msg_id, msg, opt);
489         if (msg_err != MSG_SUCCESS) {
490                 MSG_MGR_ERR("msg_get_message() failed [%d]", msg_err);
491                 return;
492         }
493
494         msg_get_int_value(msg, MSG_MESSAGE_SIM_INDEX_INT, &msg_info.sim_idx);
495
496         if (noti_type == MSG_MGR_NOTI_TYPE_CLASS0) {
497                 msg_get_list_handle(msg, MSG_MESSAGE_ADDR_LIST_HND, (void **)&addr_list);
498
499                 msg_struct_t addr_data = msg_list_nth_data(addr_list, 0);
500                 msg_get_str_value(addr_data, MSG_ADDRESS_INFO_ADDRESS_VALUE_STR, msg_info.addressVal, MAX_ADDRESS_VAL_LEN);
501                 msg_get_str_value(addr_data, MSG_ADDRESS_INFO_DISPLAYNAME_STR, msg_info.displayName, MAX_DISPLAY_NAME_LEN);
502
503                 int msg_size = 0;
504                 msg_get_int_value(msg, MSG_MESSAGE_DATA_SIZE_INT, &msg_size);
505                 if (msg_size > 0)
506                         msg_get_str_value(msg, MSG_MESSAGE_SMS_DATA_STR, msg_info.msgText, MAX_MSG_TEXT_LEN);
507         }
508
509         msg_release_struct(&msg);
510         msg_release_struct(&opt);
511
512         g_free(msgId);
513
514         MsgMgrInsertOnlyActiveNotification(noti_type, &msg_info);
515 }
516
517 void _insert_ticker_func(app_control_h app_control)
518 {
519         char *ticker_msg = NULL;
520         char *locale_ticker_msg = NULL;
521         char *feedback_str = NULL;
522         bool feedback = false;
523         char *msg_id_str = NULL;
524         int msg_id = 0;
525
526         int ret = app_control_get_extra_data(app_control, "ticker_msg", &ticker_msg);
527         if (ret != APP_CONTROL_ERROR_NONE || ticker_msg == NULL) {
528                 MSG_MGR_ERR("app_control_get_extra_data failed [%d]", ret);
529                 goto _END_OF_INSERT_TICKER;
530         }
531
532         ret = app_control_get_extra_data(app_control, "locale_ticker_msg", &locale_ticker_msg);
533         if (ret != APP_CONTROL_ERROR_NONE || locale_ticker_msg == NULL) {
534                 MSG_MGR_ERR("app_control_get_extra_data failed [%d]", ret);
535                 goto _END_OF_INSERT_TICKER;
536         }
537
538         ret = app_control_get_extra_data(app_control, "feedback", &feedback_str);
539         if (ret != APP_CONTROL_ERROR_NONE || feedback_str == NULL) {
540                 MSG_MGR_ERR("app_control_get_extra_data failed [%d]", ret);
541                 goto _END_OF_INSERT_TICKER;
542         } else {
543                 if (g_strcmp0(feedback_str, "true") == 0)
544                         feedback = true;
545                 else
546                         feedback = false;
547         }
548
549         ret = app_control_get_extra_data(app_control, "msg_id", &msg_id_str);
550         if (ret != APP_CONTROL_ERROR_NONE || msg_id_str == NULL) {
551                 MSG_MGR_ERR("app_control_get_extra_data failed [%d]", ret);
552                 goto _END_OF_INSERT_TICKER;
553         } else {
554                 msg_id = atoi(msg_id_str);
555         }
556
557         ret = MsgMgrInsertTicker(ticker_msg, locale_ticker_msg, feedback, msg_id);
558         if (ret != 0)
559                 MSG_MGR_ERR("MsgMgrInsertTicker failed [%d]", ret);
560
561 _END_OF_INSERT_TICKER:
562         if (ticker_msg)
563                 g_free(ticker_msg);
564
565         if (locale_ticker_msg)
566                 g_free(locale_ticker_msg);
567
568         if (feedback_str)
569                 g_free(feedback_str);
570
571         if (msg_id_str)
572                 g_free(msg_id_str);
573 }
574
575 void _sound_play_start_func(app_control_h app_control)
576 {
577         char *type;
578         MSG_MGR_SOUND_TYPE_T sound_type = MSG_MGR_SOUND_PLAY_DEFAULT;
579
580         int ret = app_control_get_extra_data(app_control, "type", &type);
581         if (ret == APP_CONTROL_ERROR_NONE && type) {
582                 if (g_strcmp0(type, "default") == 0) {
583                         sound_type = MSG_MGR_SOUND_PLAY_DEFAULT;
584                 } else if (g_strcmp0(type, "user") == 0) {
585                         sound_type = MSG_MGR_SOUND_PLAY_USER;
586                 } else if (g_strcmp0(type, "emergency") == 0) {
587                         sound_type = MSG_MGR_SOUND_PLAY_EMERGENCY;
588                 } else if (g_strcmp0(type, "voicemail") == 0) {
589                         sound_type = MSG_MGR_SOUND_PLAY_VOICEMAIL;
590                 }
591
592                 g_free(type);
593         } else {
594                 MSG_MGR_ERR("app_control_get_extra_data failed");
595                 return;
596         }
597
598         char *addr = NULL;
599         ret = app_control_get_extra_data(app_control, "address", &addr);
600
601         if (addr) {
602                 MSG_MGR_ADDRESS_INFO_S addr_info = {0,};
603                 snprintf(addr_info.addressVal, MAX_ADDRESS_VAL_LEN, "%s", addr);
604
605                 MsgMgrSoundPlayStart(&addr_info, sound_type);
606
607                 g_free(addr);
608         } else {
609                 MsgMgrSoundPlayStart(NULL, sound_type);
610         }
611 }
612
613 void _change_pm_state_func(app_control_h app_control)
614 {
615         MsgMgrChangePmState();
616 }
617
618 void service_app_control(app_control_h app_control, void *data)
619 {
620         MSG_MGR_INFO("service_app_control called");
621
622         pthread_mutex_lock(&mx);
623         job_cnt++;
624         pthread_mutex_unlock(&mx);
625
626         int ret = 0;
627         char *operation = NULL;
628         char *cmd = NULL;
629
630         ret = app_control_get_operation(app_control, &operation);
631         if (ret == APP_CONTROL_ERROR_NONE && operation) {
632                 if (g_strcmp0(operation, APP_CONTROL_OPERATION_DEFAULT) == 0) {
633                         ret = app_control_get_extra_data(app_control, "cmd", &cmd);
634                         if (ret == APP_CONTROL_ERROR_NONE && cmd) {
635                                 MSG_MGR_DEBUG("cmd [%s]", cmd);
636
637                                 if (g_strcmp0(cmd, "incoming_msg") == 0) {
638                                         _incoming_msg_func(app_control);
639                                 } else if (g_strcmp0(cmd, "outgoing_msg") == 0) {
640                                         _outgoing_msg_func(app_control);
641                                 } else if (g_strcmp0(cmd, "refresh_noti") == 0) {
642                                         _refresh_noti_func(app_control);
643                                 } else if (g_strcmp0(cmd, "add_noti") == 0) {
644                                         _add_noti_func(app_control);
645                                 } else if (g_strcmp0(cmd, "del_noti") == 0) {
646                                         _del_noti_func(app_control);
647                                 } else if (g_strcmp0(cmd, "add_report_noti") == 0) {
648                                         _add_report_noti_func(app_control);
649                                 } else if (g_strcmp0(cmd, "del_report_noti") == 0) {
650                                         _del_report_noti_func(app_control);
651                                 } else if (g_strcmp0(cmd, "insert_only_active_noti") == 0) {
652                                         _insert_only_active_noti_func(app_control);
653                                 } else if (g_strcmp0(cmd, "insert_ticker") == 0) {
654                                         _insert_ticker_func(app_control);
655                                 } else if (g_strcmp0(cmd, "sound_play_start") == 0) {
656                                         _sound_play_start_func(app_control);
657                                 } else if (g_strcmp0(cmd, "change_pm_state") == 0) {
658                                         _change_pm_state_func(app_control);
659                                 }
660
661                                 g_free(cmd);
662                         }
663                 }
664                 g_free(operation);
665         }
666
667         pthread_mutex_lock(&mx);
668         if (!terminated)
669                 g_timeout_add_seconds(60, _check_app_terminate, NULL);
670         pthread_mutex_unlock(&mx);
671
672         return;
673 }
674
675 int main(int argc, char* argv[])
676 {
677         service_app_lifecycle_callback_s event_callback = {0,};
678
679         event_callback.create = service_app_create;
680         event_callback.terminate = service_app_terminate;
681         event_callback.app_control = service_app_control;
682
683         return service_app_main(argc, argv, &event_callback, NULL);
684 }