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 ==================================================================================================*/
20 #include "MsgCallStatusManager.h"
22 #include "MsgException.h"
23 #include "MsgContact.h"
24 #include "MsgMemory.h"
25 #include "MsgGconfWrapper.h"
26 #include "MsgSensorWrapper.h"
27 #include "MsgPluginManager.h"
28 #include "MsgSettingHandler.h"
29 #include "MsgStorageHandler.h"
30 #include "MsgSubmitHandler.h"
31 #include "MsgDeliverHandler.h"
32 #include "MsgTransManager.h"
33 #include "MsgStorageTypes.h"
34 #include "MsgCmdHandler.h"
35 #include "MsgUtilFile.h"
36 #include "MsgUtilFunction.h"
37 #include "MsgUtilStorage.h"
38 #include "MsgNotificationWrapper.h"
45 static GMainLoop* mainloop = NULL;
47 /*==================================================================================================
48 FUNCTION IMPLEMENTATION
49 ==================================================================================================*/
52 void* InitMsgServer(void*)
54 msg_error_t err = MSG_SUCCESS;
55 MSG_DEBUG("Start InitMsgServer.");
57 MsgInitCallStatusManager();
59 msg_init_dpm_policy();
62 /* storage handler initialize */
63 err = MsgStoInitDB(false);
64 if (err != MSG_SUCCESS) {
65 MSG_ERR("FAIL TO INITIALIZE STORAGE HANDLER [%d]", err);
71 /* plugin manager initialize */
72 MsgPluginManager::instance()->initialize();
73 } catch (MsgException& e) {
74 MSG_FATAL("%s", e.what());
75 } catch (exception& e) {
76 MSG_FATAL("%s", e.what());
82 MSG_DEBUG("End InitMsgServer.");
88 void* StartMsgServer(void*)
91 if (MsgTransactionManager::instance()->initCynara() == false) {
92 MSG_ERR("Cynara initialize failed. It will try again when API is called.");
95 MsgTransactionManager::instance()->run();
96 } catch (MsgException& e) {
97 MSG_FATAL("%s", e.what());
98 } catch (exception& e) {
99 MSG_FATAL("%s", e.what());
102 MsgTransactionManager::instance()->finishCynara();
104 if (g_main_loop_is_running(mainloop))
105 g_main_loop_quit(mainloop);
113 #if !GLIB_CHECK_VERSION(2, 31, 0)
116 /* set to ignore child process terminated signal */
117 signal(SIGCHLD, SIG_IGN);
119 MSG_INFO("===========START MESSAGING FRAMEWORK==========");
121 #if !GLIB_CHECK_VERSION(2, 36, 0)
124 /* Reset message server ready flag */
125 if(MsgSettingSetBool(VCONFKEY_MSG_SERVER_READY, false) != MSG_SUCCESS)
126 MSG_DEBUG("MsgSettingSetBool FAIL: VCONFKEY_MSG_SERVER_READY");
131 pthread_t startThreadId;
133 /* start transaction manager */
134 if (pthread_create(&startThreadId, NULL, StartMsgServer, NULL) != 0) {
135 MSG_DEBUG("StartMsgServer not invoked: %s", g_strerror(errno));
140 mainloop = g_main_loop_new(NULL, FALSE);
142 if (mainloop != NULL) {
143 MSG_DEBUG("Start Messaging Framework!!!");
146 g_main_loop_run(mainloop);
148 MSG_DEBUG("Fail to start Messaging Framework!!!");
151 /* Disconnect to DB */
152 MsgStoDisconnectDB();
154 MsgDeInitCallStatusManager();
156 msg_deinit_dpm_policy();