2 * Copyright (c) 2014 Samsung Electronics Co., Ltd. All rights reserved
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 /*==================================================================================================
19 ==================================================================================================*/
21 #include "MsgException.h"
22 #include "MsgContact.h"
23 #include "MsgMemory.h"
24 #include "MsgGconfWrapper.h"
25 #include "MsgPluginManager.h"
26 #include "MsgSettingHandler.h"
27 #include "MsgStorageHandler.h"
28 #include "MsgSubmitHandler.h"
29 #include "MsgDeliverHandler.h"
30 #include "MsgTransManager.h"
31 #include "MsgStorageTypes.h"
32 #include "MsgSoundPlayer.h"
33 #include "MsgCmdHandler.h"
34 #include "MsgUtilFile.h"
35 #include "MsgUtilStorage.h"
36 #include "MsgNotificationWrapper.h"
37 #include "MsgZoneManager.h"
41 #include <dbus/dbus-glib.h>
45 static GMainLoop* mainloop = NULL;
47 /*==================================================================================================
48 FUNCTION IMPLEMENTATION
49 ==================================================================================================*/
51 msg_error_t InitMmsDir()
53 if (mkdir(MSG_DATA_ROOT_PATH, S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH) < 0)
57 MSG_DEBUG("The %s already exists", MSG_DATA_ROOT_PATH);
61 MSG_DEBUG("Error while mkdir %s", MSG_DATA_ROOT_PATH);
62 return MSG_ERR_DB_MAKE_DIR;
66 if (mkdir(MSG_SMIL_FILE_PATH, S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH) < 0)
70 MSG_SEC_DEBUG("The %s already exists", MSG_SMIL_FILE_PATH);
74 MSG_SEC_DEBUG("Error while mkdir %s", MSG_SMIL_FILE_PATH);
75 return MSG_ERR_DB_MAKE_DIR;
79 if (mkdir(MSG_DATA_PATH, S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH) < 0)
83 MSG_DEBUG("The %s already exists", MSG_DATA_PATH);
87 MSG_DEBUG("Error while mkdir %s", MSG_DATA_PATH);
88 return MSG_ERR_DB_MAKE_DIR;
92 if (mkdir(MSG_THUMBNAIL_PATH, S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH) < 0) {
93 if (errno == EEXIST) {
94 MSG_DEBUG("The %s already exists.", MSG_THUMBNAIL_PATH);
96 MSG_DEBUG(" Error while mkdir %s", MSG_THUMBNAIL_PATH);
97 return MSG_ERR_DB_MAKE_DIR;
101 if (mkdir(MSG_IPC_DATA_PATH, S_IRWXU ) < 0)
105 MSG_DEBUG("The %s already exists", MSG_IPC_DATA_PATH);
106 // if IPC data path is already exist, clear all files in folder.
107 MsgRmRf((char *)MSG_IPC_DATA_PATH);
111 MSG_DEBUG("Error while mkdir %s", MSG_IPC_DATA_PATH);
112 return MSG_ERR_DB_MAKE_DIR;
116 if (MsgChmod( MSG_IPC_DATA_PATH, S_IRWXU | S_IRWXG) == 0) { //public shared file: pass data by file
117 MSG_DEBUG("Fail to chmod [%s].", MSG_IPC_DATA_PATH);
119 if (MsgChown(MSG_DATA_ROOT_PATH, 200, 5000) == 0) {
120 MSG_DEBUG("Fail to chown [%s].", MSG_DATA_ROOT_PATH);
122 if (MsgChown(MSG_DATA_PATH, 200, 5000) == 0) {
123 MSG_DEBUG("Fail to chown [%s].", MSG_DATA_PATH);
125 if (MsgChown(MSG_SMIL_FILE_PATH, 200, 5000) == 0) {
126 MSG_DEBUG("Fail to chown [%s].", MSG_SMIL_FILE_PATH);
128 if (MsgChown(MSG_IPC_DATA_PATH, 200, 5000) == 0) {
129 MSG_DEBUG("Fail to chown [%s].", MSG_IPC_DATA_PATH);
131 if (MsgChown(MSG_THUMBNAIL_PATH, 200, 5000) == 0) {
132 MSG_DEBUG("Fail to chown [%s].", MSG_THUMBNAIL_PATH);
139 void* InitMsgServer(void*)
141 msg_error_t err = MSG_SUCCESS;
142 MSG_DEBUG("Start InitMsgServer.");
144 //CID 356902: Moving try block up to include MsgStoInitDB which also throws MsgException
147 // storage handler initialize
148 err = MsgStoInitDB(false);
149 if (err != MSG_SUCCESS) {
150 MSG_ERR("FAIL TO INITIALIZE STORAGE HANDLER [%d]", err);
155 // plugin manager initialize
156 MsgPluginManager::instance()->initialize();
158 catch (MsgException& e)
160 MSG_FATAL("%s", e.what());
164 MSG_FATAL("%s", e.what());
168 // MsgSoundPlayer::instance()->MsgSoundInitRepeatAlarm();
170 MsgStoDisconnectDB();
173 MSG_DEBUG("End InitMsgServer.");
179 void* StartMsgServer(void*)
183 MsgTransactionManager::instance()->run();
185 catch (MsgException& e)
187 MSG_FATAL("%s", e.what());
191 MSG_FATAL("%s", e.what());
194 if (g_main_loop_is_running(mainloop))
195 g_main_loop_quit(mainloop);
203 #if !GLIB_CHECK_VERSION(2, 31, 0)
206 /* set to ignore child process terminated signal */
207 signal(SIGCHLD, SIG_IGN);
209 MSG_INFO("===========START MESSAGING FRAMEWORK==========");
211 #if !GLIB_CHECK_VERSION(2, 36, 0)
214 // Reset message server ready flag
215 if(MsgSettingSetBool(VCONFKEY_MSG_SERVER_READY, false) != MSG_SUCCESS)
216 MSG_DEBUG("MsgSettingSetBool FAIL: VCONFKEY_MSG_SERVER_READY");
219 // MsgStoConnectDB();
227 pthread_t startThreadId;
229 // start transaction manager
230 if (pthread_create(&startThreadId, NULL, StartMsgServer, NULL) != 0)
232 MSG_DEBUG("StartMsgServer not invoked: %s", strerror(errno));
237 MsgSettingRegVconfCB();
239 mainloop = g_main_loop_new(NULL, FALSE);
241 if (mainloop != NULL)
243 MSG_DEBUG("Start Messaging Framework!!!");
246 g_main_loop_run(mainloop);
250 MSG_DEBUG("Fail to start Messaging Framework!!!");
254 MsgSettingRemoveVconfCB();
255 //contacts-service is not used for gear
256 #ifndef MSG_CONTACTS_SERVICE_NOT_SUPPORTED
257 // Close Contact Sevice
258 MsgCloseContactSvc();
259 #endif //MSG_CONTACTS_SERVICE_NOT_SUPPORTED
262 MsgStoDisconnectDB();