2 * Copyright (c) 2015 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.
20 #include "MsgException.h"
21 #include "MsgGconfWrapper.h"
24 #include "SmsCdmaPluginTransport.h"
25 #include "SmsCdmaPluginStorage.h"
26 #include "SmsCdmaPluginCallback.h"
27 #include "SmsCdmaPluginEventHandler.h"
28 #include "SmsCdmaPluginUAManager.h"
29 #include "SmsCdmaPluginSetting.h"
30 #include "SmsCdmaPluginMain.h"
35 #include <tapi_common.h>
37 #include <TapiUtility.h>
39 #include <ITapiNetText.h>
42 #define BUS_NAME "org.tizen.system.deviced"
43 #define PATH_NAME "/Org/Tizen/System/DeviceD/Lowmem"
44 #define INTERFACE_NAME BUS_NAME".lowmem"
45 #define MEMBER_NAME "Full"
47 struct tapi_handle *pTapiHandle = NULL;
48 bool isMemAvailable = true;
50 GDBusConnection *gdbus_conn = NULL;
51 GDBusProxy *gdbus_proxy = NULL;
58 void MsgResourceMonitorInit(void);
59 void MsgResourceMonitorDeinit(void);
61 /*==================================================================================================
62 FUNCTION IMPLEMENTATION
63 ==================================================================================================*/
65 static void MsgTapiInitCB(keynode_t *key, void* data)
67 MSG_DEBUG("MsgTapiInitCB is called.");
74 msg_error_t MsgPlgCreateHandle(MSG_PLUGIN_HANDLER_S *pPluginHandle)
76 if (pPluginHandle == NULL) {
77 MSG_DEBUG("SMS plugin: create handler error ");
78 return MSG_ERR_NULL_POINTER;
80 pPluginHandle->pfInitialize = SmsPlgInitialize;
81 pPluginHandle->pfFinalize = SmsPlgFinalize;
82 pPluginHandle->pfRegisterListener = SmsPlgRegisterListener;
83 pPluginHandle->pfSubmitRequest = SmsPlgSubmitRequest;
84 pPluginHandle->pfSaveSimMessage = SmsPlgSaveSimMessage;
85 pPluginHandle->pfDeleteSimMessage = SmsPlgDeleteSimMessage;
86 pPluginHandle->pfSetReadStatus = SmsPlgSetReadStatus;
87 pPluginHandle->pfSetMemoryStatus = SmsPlgSetMemoryStatus;
88 pPluginHandle->pfSetConfigData = SmsPlgSetConfigData;
89 pPluginHandle->pfGetConfigData = SmsPlgGetConfigData;
90 pPluginHandle->pfAddMessage = SmsPlgAddMessage;
92 MSG_DEBUG("SMS plugin: create handler OK");
93 MSG_DEBUG("SMS plugin %p", pPluginHandle);
100 msg_error_t MsgPlgDestroyHandle(MSG_PLUGIN_HANDLER_S *pPluginHandle)
102 if (pPluginHandle != NULL) {
104 pPluginHandle = NULL;
107 MSG_DEBUG("SMS plugin: destory handler OK");
113 msg_error_t SmsPlgInitialize()
119 for (int i = 0; i < 100; i++) {
120 if (MsgSettingGetBool(VCONFKEY_TELEPHONY_READY, &bReady) != MSG_SUCCESS)
121 MSG_INFO("MsgSettingGetBool() is failed");
123 MSG_DEBUG("Get VCONFKEY_TELEPHONY_READY [%d].", bReady ? 1 : 0);
132 MSG_DEBUG("Fail to wait telephony init complete.");
133 return MSG_ERR_PLUGIN_TAPIINIT;
136 pTapiHandle = tel_init(NULL);
139 /* register event. */
140 SmsPluginCallback::instance()->registerEvent();
142 /* set sim change status. */
143 MSG_DEBUG("Try to initialize SIM on init");
144 SmsPluginSetting::instance()->setSimChangeStatus();
146 /* set resource monitor */
147 MsgResourceMonitorInit();
156 msg_error_t SmsPlgFinalize()
160 MsgResourceMonitorDeinit();
163 return MSG_ERR_PLUGIN_TAPIINIT;
165 SmsPluginCallback::instance()->deRegisterEvent();
167 tel_deinit(pTapiHandle);
175 msg_error_t SmsPlgRegisterListener(MSG_PLUGIN_LISTENER_S *pListener)
179 SmsPluginEventHandler::instance()->registerListener(pListener);
187 msg_error_t SmsPlgSubmitRequest(MSG_REQUEST_INFO_S *pReqInfo)
189 msg_error_t err = MSG_SUCCESS;
191 /* Add Submit SMS into DB */
192 if (pReqInfo->msgInfo.msgId == 0) {
193 if (pReqInfo->msgInfo.msgPort.valid == false) {
194 err = SmsPluginStorage::instance()->checkMessage(&(pReqInfo->msgInfo));
196 if (err != MSG_SUCCESS) {
197 MSG_DEBUG("######## checkMessage Fail !! [err=%d]", err);
198 return MSG_ERR_PLUGIN_STORAGE;
201 err = SmsPluginStorage::instance()->addSmsMessage(&(pReqInfo->msgInfo));
202 if (err != MSG_SUCCESS) {
203 MSG_DEBUG("######## addSmsMessage Fail !! [err=%d]", err);
204 return MSG_ERR_PLUGIN_STORAGE;
207 if (SmsPluginStorage::instance()->addSmsSendOption(&(pReqInfo->msgInfo), &(pReqInfo->sendOptInfo)) != MSG_SUCCESS) {
208 MSG_DEBUG("######## addSmsSendOption Fail !!");
209 return MSG_ERR_PLUGIN_STORAGE;
214 sms_request_info_s *request = NULL;
216 request = (sms_request_info_s *)calloc(1, sizeof(sms_request_info_s));
218 if (request != NULL) {
219 request->reqId = pReqInfo->reqId;
221 memcpy(&(request->msgInfo), &(pReqInfo->msgInfo), sizeof(MSG_MESSAGE_INFO_S));
222 memcpy(&(request->sendOptInfo), &(pReqInfo->sendOptInfo), sizeof(MSG_SENDINGOPT_INFO_S));
224 /* Add Request into Queue and Start UA Manger */
225 SmsPluginUAManager::instance()->addReqEntity(request);
235 msg_error_t SmsPlgSaveSimMessage(const MSG_MESSAGE_INFO_S *pMsgInfo, SMS_SIM_ID_LIST_S *pSimIdList)
237 MSG_DEBUG("CDMA does not support sim card operations.");
242 msg_error_t SmsPlgDeleteSimMessage(msg_sim_id_t SimMsgId)
244 MSG_DEBUG("CDMA does not support sim card operations.");
249 msg_error_t SmsPlgSetReadStatus(msg_sim_id_t SimMsgId)
251 MSG_DEBUG("CDMA does not support sim card operations.");
256 msg_error_t SmsPlgSetMemoryStatus(msg_error_t Error)
258 int tapiRet = TAPI_API_SUCCESS;
259 int status = TAPI_NETTEXT_PDA_MEMORY_STATUS_AVAILABLE;
261 if (Error == MSG_ERR_SIM_STORAGE_FULL || Error == MSG_ERR_MESSAGE_COUNT_FULL) {
262 status = TAPI_NETTEXT_PDA_MEMORY_STATUS_FULL;
265 MSG_DEBUG("Set Status : [%d]", status);
267 tapiRet = tel_set_sms_memory_status(pTapiHandle, status, TapiEventMemoryStatus, NULL);
269 if (tapiRet == TAPI_API_SUCCESS) {
270 MSG_DEBUG("######## tel_set_sms_memory_status() Success !!! #######");
272 MSG_DEBUG("######## tel_set_sms_memory_status() Success !!! return : [%d] #######", tapiRet);
279 msg_error_t SmsPlgSetConfigData(const MSG_SETTING_S *pSetting)
282 SmsPluginSetting::instance()->setConfigData(pSetting);
283 } catch (MsgException& e) {
284 MSG_FATAL("%s", e.what());
285 return MSG_ERR_PLUGIN_SETTING;
286 } catch (exception& e) {
287 MSG_FATAL("%s", e.what());
288 return MSG_ERR_PLUGIN_SETTING;
295 msg_error_t SmsPlgGetConfigData(MSG_SETTING_S *pSetting)
298 SmsPluginSetting::instance()->getConfigData(pSetting);
299 } catch (MsgException& e) {
300 MSG_FATAL("%s", e.what());
301 return MSG_ERR_PLUGIN_SETTING;
302 } catch (exception& e) {
303 MSG_FATAL("%s", e.what());
304 return MSG_ERR_PLUGIN_SETTING;
311 msg_error_t SmsPlgAddMessage(MSG_MESSAGE_INFO_S *pMsgInfo, MSG_SENDINGOPT_INFO_S* pSendOptInfo, char* pFileData)
313 MSG_DEBUG("CDMA does not support sim card operations.");
318 static void on_change_received(GDBusConnection *connection, const gchar *sender_name,
319 const gchar *object_path, const gchar *interface_name, const gchar *signal_name,
320 GVariant *parameters, gpointer user_data)
322 MSG_DEBUG("signal_name = [%s]", signal_name);
324 if (g_strcmp0(signal_name, MEMBER_NAME) == 0) {
326 g_variant_get(parameters, "(i)", &memStatus);
327 MSG_DEBUG("memStatus = [%d]", memStatus);
328 if (memStatus == 0) {
329 SmsPlgSetMemoryStatus(MSG_SUCCESS);
335 void MsgResourceMonitorInit(void)
339 GError *error = NULL;
342 g_object_unref(gdbus_conn);
346 gdbus_conn = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &error);
348 MSG_FATAL("g_bus_get_sync() failed : %s", error->message);
355 g_object_unref(gdbus_proxy);
359 gdbus_proxy = g_dbus_proxy_new_sync(gdbus_conn, G_DBUS_PROXY_FLAGS_NONE,
360 NULL, BUS_NAME, PATH_NAME, INTERFACE_NAME, NULL, &error);
362 MSG_FATAL("g_dbus_proxy_new_sync() failed : %s", error->message);
368 subs_id = g_dbus_connection_signal_subscribe(gdbus_conn, NULL,
369 INTERFACE_NAME, MEMBER_NAME, PATH_NAME,
370 NULL, G_DBUS_SIGNAL_FLAGS_NONE,
378 g_object_unref(gdbus_conn);
383 g_object_unref(gdbus_proxy);
392 void MsgResourceMonitorDeinit(void)
397 g_dbus_connection_signal_unsubscribe(gdbus_conn, subs_id);
402 g_object_unref(gdbus_conn);
407 g_object_unref(gdbus_proxy);