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