2 * Copyright 2012 Samsung Electronics Co., Ltd
4 * Licensed under the Flora License, Version 1.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.tizenopensource.org/license
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"
35 #include <dbus/dbus-glib.h>
39 static GMainLoop* mainloop = NULL;
42 /*==================================================================================================
44 ==================================================================================================*/
45 #define MSG_MOBILE_TRACKER_MSG "Mobile Tracker Alert"
48 /*==================================================================================================
49 FUNCTION IMPLEMENTATION
50 ==================================================================================================*/
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_DEBUG("The %s already exists", MSG_SMIL_FILE_PATH);
74 MSG_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);
107 // if IPC data path is already exist, clear all files in folder.
109 snprintf(exeStr, 1024, "rm %s*.DATA", MSG_IPC_DATA_PATH);
114 MSG_DEBUG("Error while mkdir %s", MSG_IPC_DATA_PATH);
115 return MSG_ERR_DB_MAKE_DIR;
119 chmod( MSG_IPC_DATA_PATH, S_IRWXU | S_IRWXG ); //public shared file: pass data by file
120 chown( MSG_IPC_DATA_PATH, 0, 6502 );
126 void* StartMsgServer(void*)
130 MsgTransactionManager::instance()->run();
132 catch (MsgException& e)
134 MSG_FATAL("%s", e.what());
138 MSG_FATAL("%s", e.what());
141 if (g_main_loop_is_running(mainloop))
142 g_main_loop_quit(mainloop);
148 void* InitMsgServer(void*)
150 MSG_ERROR_T err = MSG_SUCCESS;
152 MSG_MAIN_TYPE_T mainType = MSG_SMS_TYPE;
153 MsgPlugin* plg = MsgPluginManager::instance()->getPlugin(mainType);
155 // storage handler initialize
156 err = MsgStoInitDB(false);
158 if (err != MSG_SUCCESS) {
159 MSG_DEBUG("FAIL TO INITIALIZE STORAGE HANDLER [%d]", err);
163 MSG_DEBUG("No plugin for %d type", mainType);
167 // Set Msg FW Ready Flag
168 MsgSettingSetBool(VCONFKEY_MSG_SERVER_READY, true);
173 MSG_SIM_STATUS_T simStatus = MSG_SIM_STATUS_NORMAL;
176 if (plg->checkSimStatus(&simStatus) == MSG_SUCCESS) {
178 // Add the change of SIM to vconf
179 if (MsgSettingSetInt(MSG_SIM_CHANGED, (int)simStatus) != MSG_SUCCESS) {
180 MSG_DEBUG("Error to set config data [%s]", MSG_SIM_CHANGED);
183 if (simStatus != MSG_SIM_STATUS_NOT_FOUND) {
184 // Check Device Status
185 if (plg->checkDeviceStatus() != MSG_SUCCESS) {
186 MSG_DEBUG("checkDeviceStatus() error");
190 // Set Msg FW Ready Flag
191 MsgSettingSetBool(VCONFKEY_MSG_SERVER_READY, true);
198 if (MsgInitSimMessage(simStatus) != MSG_SUCCESS) {
199 MSG_DEBUG("Fail to Initialize SIM Message");
202 // Init SIM Configuration
203 if (MsgInitSimConfig(simStatus) != MSG_SUCCESS) {
204 MSG_DEBUG("Fail to Initialize SIM Configuration");
207 MSG_DEBUG("checkSimStatus() error");
212 // Try to connect contact server if it is not opened.
215 // Register Callback to get the change of contact
216 MsgInitContactSvc(&MsgContactChangedCallback);
218 // Set Msg FW Ready Flag
219 MsgSettingSetBool(VCONFKEY_MSG_SERVER_READY, true);
225 static gboolean InitThreadFunc(void* pData)
229 pthread_t initThreadId;
232 if (pthread_create(&initThreadId, NULL, InitMsgServer, NULL) != 0)
234 MSG_DEBUG("InitMsgFw not invoked: %s", strerror(errno));
238 pthread_detach(initThreadId);
249 dbus_g_thread_init();
251 ////////////////////////////////////
253 /// set to ignore child process terminated signal.
254 signal( SIGCHLD, SIG_IGN );
256 ////////////////////////////////////
259 MSG_DEBUG("===========START MESSAGING FRAMEWORK==========");
261 // Reset message server ready flag
262 MsgSettingSetBool(VCONFKEY_MSG_SERVER_READY, false);
265 // MsgStoConnectDB();
267 // Open Contact Service
275 // plugin manager initialize
276 MsgPluginManager::instance()->initialize();
278 catch (MsgException& e)
280 MSG_FATAL("%s", e.what());
284 MSG_FATAL("%s", e.what());
287 pthread_t startThreadId;
289 // start transaction manager
290 if (pthread_create(&startThreadId, NULL, StartMsgServer, NULL) != 0)
292 MSG_DEBUG("StartMsgServer not invoked: %s", strerror(errno));
296 MsgTransactionManager::instance()->getTMStatus();
298 mainloop = g_main_loop_new(NULL, FALSE);
302 g_idle_add(InitThreadFunc, NULL);
304 if (mainloop != NULL)
306 MSG_DEBUG("Start Messaging Framework!!!");
309 g_main_loop_run(mainloop);
313 MSG_DEBUG("Fail to start Messaging Framework!!!");
316 // Close Contact Sevice
317 MsgCloseContactSvc();
320 MsgStoDisconnectDB();