Improve typing of constants data
[platform/core/messaging/msg-service.git] / framework / main.cpp
index 943a7e6..4383d9b 100755 (executable)
@@ -1,17 +1,20 @@
 /*
-* Copyright 2012  Samsung Electronics Co., Ltd
-*
-* Licensed under the Flora License, Version 1.0 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-*    http://www.tizenopensource.org/license
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
+ * msg-service
+ *
+ * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd. All rights reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
 */
 
 /*==================================================================================================
@@ -22,7 +25,6 @@
 #include "MsgContact.h"
 #include "MsgMemory.h"
 #include "MsgGconfWrapper.h"
-#include "MsgSpamFilter.h"
 #include "MsgPluginManager.h"
 #include "MsgSettingHandler.h"
 #include "MsgStorageHandler.h"
@@ -31,6 +33,9 @@
 #include "MsgTransManager.h"
 #include "MsgStorageTypes.h"
 #include "MsgSoundPlayer.h"
+#include "MsgCmdHandler.h"
+#include "MsgUtilStorage.h"
+#include "MsgNotificationWrapper.h"
 
 #include <errno.h>
 #include <glib.h>
@@ -108,7 +113,7 @@ msg_error_t InitMmsDir()
 
                        // if IPC data path is already exist, clear all files in folder.
                        char exeStr[1024];
-                       snprintf(exeStr, 1024, "rm %s*.DATA", MSG_IPC_DATA_PATH);
+                       snprintf(exeStr, 1024, "rm %s/*.DATA", MSG_IPC_DATA_PATH);
                        system(exeStr);
                }
                else
@@ -118,7 +123,9 @@ msg_error_t InitMmsDir()
                }
        }
 
-       chmod( MSG_IPC_DATA_PATH, S_IRWXU | S_IRWXG ); //public shared file: pass data by file
+       if(chmod( MSG_IPC_DATA_PATH, S_IRWXU | S_IRWXG ) !=0) { //public shared file: pass data by file
+               MSG_DEBUG("Fail to chmod [%s].", MSG_IPC_DATA_PATH);
+       }
        chown( MSG_IPC_DATA_PATH, 0, 6502 );
 
        return MSG_SUCCESS;
@@ -180,6 +187,10 @@ void SendMobileTrackerMsg()
        {
                MSG_DEBUG("Assign Default Msg");
                msgText = strdup(MSG_MOBILE_TRACKER_MSG);
+               if (msgText == NULL) {
+                       MSG_DEBUG("msgText is NULL.");
+                       return;
+               }
        }
 
        MSG_DEBUG("mobile tracker msg : [%s]", msgText);
@@ -195,6 +206,8 @@ void SendMobileTrackerMsg()
        if (orgRecipientList == NULL)
        {
                MSG_DEBUG("recipient list is NULL");
+               free(msgText);
+               msgText = NULL;
                return;
        }
 
@@ -262,6 +275,9 @@ void SendMobileTrackerMsg()
 
 void* StartMsgServer(void*)
 {
+
+       MsgOpenContactSvc();
+
        try
        {
                MsgTransactionManager::instance()->run();
@@ -278,6 +294,8 @@ void* StartMsgServer(void*)
        if (g_main_loop_is_running(mainloop))
                g_main_loop_quit(mainloop);
 
+       MsgCloseContactSvc();
+
        return (void*)0;
 }
 
@@ -286,6 +304,22 @@ void* InitMsgServer(void*)
 {
        msg_error_t err = MSG_SUCCESS;
 
+       MsgOpenContactSvc();
+
+       try
+       {
+               // plugin manager initialize
+               MsgPluginManager::instance()->initialize();
+       }
+       catch (MsgException& e)
+       {
+               MSG_FATAL("%s", e.what());
+       }
+       catch (exception& e)
+       {
+               MSG_FATAL("%s", e.what());
+       }
+
        MSG_MAIN_TYPE_T mainType = MSG_SMS_TYPE;
        MsgPlugin* plg = MsgPluginManager::instance()->getPlugin(mainType);
 
@@ -297,7 +331,8 @@ void* InitMsgServer(void*)
        }
 
        // Set Msg FW Ready Flag
-       MsgSettingSetBool(VCONFKEY_MSG_SERVER_READY, true);
+       if(MsgSettingSetBool(VCONFKEY_MSG_SERVER_READY, true) != MSG_SUCCESS)
+               MSG_DEBUG("MsgSettingSetBool FAIL : VCONFKEY_MSG_SERVER_READY");
        MSG_DEBUG("### VCONFKEY_MSG_SERVER_READY ###");
 
        if (plg == NULL) {
@@ -307,6 +342,9 @@ void* InitMsgServer(void*)
                return (void*)0;
        }
 
+       // Clear and reset notification
+       MsgCleanAndResetNoti();
+
        MSG_SIM_STATUS_T simStatus = MSG_SIM_STATUS_NORMAL;
 
        // Check Sim Status
@@ -350,13 +388,11 @@ void* InitMsgServer(void*)
 
        MsgReleaseMemory();
 
-       // Try to connect contact server  if it is not opened.
-       MsgOpenContactSvc();
-
        // Register Callback to get the change of contact
        MsgInitContactSvc(&MsgContactChangedCallback);
 
-       MsgSoundPlayStart();
+       MsgSoundInitRepeatAlarm();
+
        return (void*)0;
 }
 
@@ -400,7 +436,8 @@ signal( SIGCHLD, SIG_IGN );
        MSG_DEBUG("===========START MESSAGING FRAMEWORK==========");
 
        // Reset message server ready flag
-       MsgSettingSetBool(VCONFKEY_MSG_SERVER_READY, false);
+       if(MsgSettingSetBool(VCONFKEY_MSG_SERVER_READY, false) != MSG_SUCCESS)
+               MSG_DEBUG("MsgSettingSetBool FAIL: VCONFKEY_MSG_SERVER_READY");
 
        // Connect to DB
        //      MsgStoConnectDB();
@@ -414,20 +451,6 @@ signal( SIGCHLD, SIG_IGN );
        // Regist vconf CB.
        MsgSettingRegVconfCB();
 
-       try
-       {
-               // plugin manager initialize
-               MsgPluginManager::instance()->initialize();
-       }
-       catch (MsgException& e)
-       {
-               MSG_FATAL("%s", e.what());
-       }
-       catch (exception& e)
-       {
-               MSG_FATAL("%s", e.what());
-       }
-
        pthread_t startThreadId;
 
        // start transaction manager
@@ -441,7 +464,9 @@ signal( SIGCHLD, SIG_IGN );
 
        mainloop = g_main_loop_new(NULL, FALSE);
 
-       g_type_init();
+#if !GLIB_CHECK_VERSION(2,35,0)
+       g_type_init ();
+#endif
 
        g_idle_add(InitThreadFunc, NULL);