Fix uncheck return of vconf_get_bool
[platform/core/messaging/msg-service.git] / manager / src / msg-manager.cpp
index 4f4ffc3..6deb06a 100644 (file)
@@ -50,7 +50,7 @@ extern "C"
 msg_handle_t msg_handle = NULL;
 cm_client_h cm_handle = NULL;
 
-pthread_mutex_t mx;
+pthread_mutex_t mx = PTHREAD_MUTEX_INITIALIZER;
 static int job_cnt = 0;
 static bool terminated = false;
 
@@ -87,18 +87,20 @@ bool service_app_create(void *data)
 
        int msg_server_ready = 0;
        for (int i = 0; i < 100; i++) {
-               vconf_get_bool(VCONFKEY_MSG_SERVER_READY, &msg_server_ready);
-               if (msg_server_ready == 1) {
-                       int msg_err = msg_open_msg_handle(&msg_handle);
-                       if (msg_err != MSG_SUCCESS)
-                               MSG_MGR_ERR("msg_open_msg_handle() failed [%d]", msg_err);
-                       else
-                               MSG_MGR_DEBUG("msg_open_msg_handle() success");
-
-                       break;
-               } else {
-                       MSG_MGR_DEBUG("msg-server is not ready.");
-                       sleep(1);
+               if (vconf_get_bool(VCONFKEY_MSG_SERVER_READY, &msg_server_ready) == 0) {
+                       if (msg_server_ready == 1) {
+                               int msg_err = msg_open_msg_handle(&msg_handle);
+                               if (msg_err != MSG_SUCCESS)
+                                       MSG_MGR_ERR("msg_open_msg_handle() failed [%d]", msg_err);
+                               else
+                                       MSG_MGR_INFO("msg_open_msg_handle() success");
+
+                               break;
+                       }
+                       else {
+                               MSG_MGR_INFO("msg-server is not ready.");
+                               sleep(1);
+                       }
                }
        }
 
@@ -123,126 +125,6 @@ void service_app_terminate(void *data)
        return;
 }
 
-void _incoming_msg_func(app_control_h app_control)
-{
-       MSG_MGR_BEGIN();
-
-       int ret = 0;
-       char *rcv_msg_type = NULL;
-       char *rcv_msg_id = NULL;
-
-       ret = app_control_get_extra_data(app_control, EVENT_KEY_MSG_ID, &rcv_msg_id);
-       if (ret != APP_CONTROL_ERROR_NONE || rcv_msg_id == NULL) {
-               MSG_MGR_ERR("app_control_get_extra_data failed");
-               return;
-       }
-
-       ret = app_control_get_extra_data(app_control, EVENT_KEY_MSG_TYPE, &rcv_msg_type);
-       if (ret != APP_CONTROL_ERROR_NONE || rcv_msg_type == NULL) {
-               MSG_MGR_ERR("app_control_get_extra_data failed");
-               g_free(rcv_msg_id);
-               return;
-       }
-
-       MSG_MGR_INFO("rcv_msg_type(%s), rcv_msg_id(%s)", rcv_msg_type, rcv_msg_id);
-
-       int msg_err = MSG_SUCCESS;
-       msg_message_id_t msg_id = atoi(rcv_msg_id);
-       msg_struct_t msg = NULL;
-       msg_struct_t opt = NULL;
-       contactInfo contact_info = {0, };
-       contact_info.msgId = msg_id;
-
-       msg = msg_create_struct(MSG_STRUCT_MESSAGE_INFO);
-       opt = msg_create_struct(MSG_STRUCT_SENDOPT);
-       msg_err = msg_get_message(msg_handle, msg_id, msg, opt);
-       if (msg_err != MSG_SUCCESS) {
-               MSG_MGR_ERR("msg_get_message() failed [%d]", msg_err);
-               return;
-       }
-
-       msg_get_int_value(msg, MSG_MESSAGE_TYPE_INT, &contact_info.msgType);
-       msg_get_int_value(msg, MSG_MESSAGE_FOLDER_ID_INT, &contact_info.folderId);
-       msg_get_int_value(msg, MSG_MESSAGE_SIM_INDEX_INT, &contact_info.simIndex);
-       msg_get_list_handle(msg, MSG_MESSAGE_ADDR_LIST_HND, (void **)&contact_info.addrList);
-       msg_get_str_value(msg, MSG_MESSAGE_SUBJECT_STR, contact_info.subject, MAX_CONTACT_TEXT_LEN);
-       int msgSize = 0;
-       msg_get_int_value(msg, MSG_MESSAGE_DATA_SIZE_INT, &msgSize);
-       if (msgSize > 0)
-               msg_get_str_value(msg, MSG_MESSAGE_SMS_DATA_STR, contact_info.msgText, MAX_CONTACT_TEXT_LEN);
-
-       if ((contact_info.folderId == MSG_INBOX_ID || contact_info.folderId == MSG_SPAMBOX_ID)) {
-               MsgMgrAddPhoneLog(&contact_info);
-       }
-
-       msg_release_struct(&msg);
-       msg_release_struct(&opt);
-
-       g_free(rcv_msg_id);
-       g_free(rcv_msg_type);
-
-       MSG_MGR_END();
-}
-
-void _outgoing_msg_func(app_control_h app_control)
-{
-       MSG_MGR_BEGIN();
-
-       int ret = 0;
-       char *sent_msg_type = NULL;
-       char *sent_msg_id = NULL;
-
-       ret = app_control_get_extra_data(app_control, EVENT_KEY_OUT_MSG_ID, &sent_msg_id);
-       if (ret != APP_CONTROL_ERROR_NONE || sent_msg_id == NULL) {
-               MSG_MGR_ERR("app_control_get_extra_data failed");
-               return;
-       }
-
-       ret = app_control_get_extra_data(app_control, EVENT_KEY_OUT_MSG_TYPE, &sent_msg_type);
-       if (ret != APP_CONTROL_ERROR_NONE || sent_msg_type == NULL) {
-               MSG_MGR_ERR("app_control_get_extra_data failed");
-               g_free(sent_msg_id);
-               return;
-       }
-
-       MSG_MGR_INFO("sent_msg_type(%s) sent_msg_id(%s)", sent_msg_type, sent_msg_id);
-
-       int msg_err = MSG_SUCCESS;
-       msg_message_id_t msg_id = atoi(sent_msg_id);
-       msg_struct_t msg = NULL;
-       msg_struct_t opt = NULL;
-       contactInfo contact_info = {0, };
-       contact_info.msgId = msg_id;
-
-       msg = msg_create_struct(MSG_STRUCT_MESSAGE_INFO);
-       opt = msg_create_struct(MSG_STRUCT_SENDOPT);
-       msg_err = msg_get_message(msg_handle, msg_id, msg, opt);
-       if (msg_err != MSG_SUCCESS) {
-               MSG_MGR_ERR("msg_get_message() failed [%d]", msg_err);
-               return;
-       }
-
-       msg_get_int_value(msg, MSG_MESSAGE_TYPE_INT, &contact_info.msgType);
-       msg_get_int_value(msg, MSG_MESSAGE_FOLDER_ID_INT, &contact_info.folderId);
-       msg_get_int_value(msg, MSG_MESSAGE_SIM_INDEX_INT, &contact_info.simIndex);
-       msg_get_list_handle(msg, MSG_MESSAGE_ADDR_LIST_HND, (void **)&contact_info.addrList);
-       msg_get_str_value(msg, MSG_MESSAGE_SUBJECT_STR, contact_info.subject, 100);
-       int msgSize = 0;
-       msg_get_int_value(msg, MSG_MESSAGE_DATA_SIZE_INT, &msgSize);
-       if (msgSize > 0)
-               msg_get_str_value(msg, MSG_MESSAGE_SMS_DATA_STR, contact_info.msgText, 100);
-
-       MsgMgrAddPhoneLog(&contact_info);
-
-       msg_release_struct(&msg);
-       msg_release_struct(&opt);
-
-       g_free(sent_msg_id);
-       g_free(sent_msg_type);
-
-       MSG_MGR_END();
-}
-
 void _refresh_noti_func(app_control_h app_control)
 {
        char *type = NULL;
@@ -333,11 +215,15 @@ void _add_noti_func(app_control_h app_control)
        MSG_MGR_MESSAGE_INFO_S msg_info = {0, };
        msg_info.msgId = msg_id;
 
+       g_free(msgId);
+
        msg = msg_create_struct(MSG_STRUCT_MESSAGE_INFO);
        opt = msg_create_struct(MSG_STRUCT_SENDOPT);
        msg_err = msg_get_message(msg_handle, msg_id, msg, opt);
        if (msg_err != MSG_SUCCESS) {
                MSG_MGR_ERR("msg_get_message() failed [%d]", msg_err);
+               msg_release_struct(&msg);
+               msg_release_struct(&opt);
                return;
        }
 
@@ -360,8 +246,6 @@ void _add_noti_func(app_control_h app_control)
        msg_release_struct(&msg);
        msg_release_struct(&opt);
 
-       g_free(msgId);
-
        MsgMgrAddNotification(noti_type, &msg_info);
 }
 
@@ -440,11 +324,15 @@ void _add_report_noti_func(app_control_h app_control)
        MSG_MGR_MESSAGE_INFO_S msg_info = {0, };
        msg_info.msgId = msg_id;
 
+       g_free(msgId);
+
        msg = msg_create_struct(MSG_STRUCT_MESSAGE_INFO);
        opt = msg_create_struct(MSG_STRUCT_SENDOPT);
        msg_err = msg_get_message(msg_handle, msg_id, msg, opt);
        if (msg_err != MSG_SUCCESS) {
                MSG_MGR_ERR("msg_get_message() failed [%d]", msg_err);
+               msg_release_struct(&msg);
+               msg_release_struct(&opt);
                return;
        }
 
@@ -460,8 +348,6 @@ void _add_report_noti_func(app_control_h app_control)
        msg_release_struct(&msg);
        msg_release_struct(&opt);
 
-       g_free(msgId);
-
        MsgMgrAddReportNotification(noti_type, &msg_info);
 }
 
@@ -518,11 +404,15 @@ void _insert_only_active_noti_func(app_control_h app_control)
        MSG_MGR_MESSAGE_INFO_S msg_info = {0, };
        msg_info.msgId = msg_id;
 
+       g_free(msgId);
+
        msg = msg_create_struct(MSG_STRUCT_MESSAGE_INFO);
        opt = msg_create_struct(MSG_STRUCT_SENDOPT);
        msg_err = msg_get_message(msg_handle, msg_id, msg, opt);
        if (msg_err != MSG_SUCCESS) {
                MSG_MGR_ERR("msg_get_message() failed [%d]", msg_err);
+               msg_release_struct(&msg);
+               msg_release_struct(&opt);
                return;
        }
 
@@ -544,8 +434,6 @@ void _insert_only_active_noti_func(app_control_h app_control)
        msg_release_struct(&msg);
        msg_release_struct(&opt);
 
-       g_free(msgId);
-
        MsgMgrInsertOnlyActiveNotification(noti_type, &msg_info);
 }
 
@@ -650,7 +538,7 @@ void _change_pm_state_func(app_control_h app_control)
        MsgMgrChangePmState();
 }
 
-void _on_boot_func(app_control_h app_control)
+void _on_boot_func()
 {
        MsgMgrOnBoot();
 }
@@ -745,13 +633,9 @@ void service_app_control(app_control_h app_control, void *data)
                if (g_strcmp0(operation, APP_CONTROL_OPERATION_DEFAULT) == 0) {
                        ret = app_control_get_extra_data(app_control, "cmd", &cmd);
                        if (ret == APP_CONTROL_ERROR_NONE && cmd) {
-                               MSG_MGR_DEBUG("cmd [%s]", cmd);
+                               MSG_MGR_INFO("cmd [%s]", cmd);
 
-                               if (g_strcmp0(cmd, "incoming_msg") == 0) {
-                                       _incoming_msg_func(app_control);
-                               } else if (g_strcmp0(cmd, "outgoing_msg") == 0) {
-                                       _outgoing_msg_func(app_control);
-                               } else if (g_strcmp0(cmd, "refresh_noti") == 0) {
+                               if (g_strcmp0(cmd, "refresh_noti") == 0) {
                                        _refresh_noti_func(app_control);
                                } else if (g_strcmp0(cmd, "add_noti") == 0) {
                                        _add_noti_func(app_control);
@@ -771,13 +655,14 @@ void service_app_control(app_control_h app_control, void *data)
                                        _sound_play_start_func(app_control);
                                } else if (g_strcmp0(cmd, "change_pm_state") == 0) {
                                        _change_pm_state_func(app_control);
-                               } else if (g_strcmp0(cmd, "on_boot") == 0) {
-                                       _on_boot_func(app_control);
                                } else if (g_strcmp0(cmd, "reply_msg") == 0) {
                                        _reply_msg_func(app_control);
                                }
 
                                g_free(cmd);
+                       } else if (ret == APP_CONTROL_ERROR_KEY_NOT_FOUND) {
+                               MSG_MGR_INFO("on boot");
+                               _on_boot_func();
                        }
                }
                g_free(operation);