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.
18 #include "MsgException.h"
19 #include "MsgGconfWrapper.h"
21 #include "SmsPluginTransport.h"
22 #include "SmsPluginSimMsg.h"
23 #include "SmsPluginStorage.h"
24 #include "SmsPluginSetting.h"
25 #include "SmsPluginCallback.h"
26 #include "SmsPluginEventHandler.h"
27 #include "SmsPluginUAManager.h"
28 #include "SmsPluginMain.h"
33 #include <ITapiNetText.h>
37 /*==================================================================================================
38 FUNCTION IMPLEMENTATION
39 ==================================================================================================*/
40 MSG_ERROR_T MsgPlgCreateHandle(MSG_PLUGIN_HANDLER_S *pPluginHandle)
42 if (pPluginHandle == NULL)
44 MSG_DEBUG("SMS plugin: create handler error ");
45 return MSG_ERR_NULL_POINTER;
49 pPluginHandle->pfInitialize = SmsPlgInitialize;
50 pPluginHandle->pfFinalize = SmsPlgFinalize;
51 pPluginHandle->pfRegisterListener = SmsPlgRegisterListener;
52 pPluginHandle->pfCheckSimStatus = SmsPlgCheckSimStatus;
53 pPluginHandle->pfCheckDeviceStatus = SmsPlgCheckDeviceStatus;
54 pPluginHandle->pfSubmitRequest = SmsPlgSubmitRequest;
55 pPluginHandle->pfInitSimMessage = SmsPlgInitSimMessage;
56 pPluginHandle->pfSaveSimMessage = SmsPlgSaveSimMessage;
57 pPluginHandle->pfDeleteSimMessage = SmsPlgDeleteSimMessage;
58 pPluginHandle->pfSetReadStatus = SmsPlgSetReadStatus;
59 pPluginHandle->pfSetMemoryStatus = SmsPlgSetMemoryStatus;
60 pPluginHandle->pfInitConfigData = SmsPlgInitConfigData;
61 pPluginHandle->pfSetConfigData = SmsPlgSetConfigData;
62 pPluginHandle->pfGetConfigData = SmsPlgGetConfigData;
64 pPluginHandle->pfRestoreMsg = NULL;
66 MSG_DEBUG("SMS plugin: create handler OK");
67 MSG_DEBUG ("SMS plugin %p", pPluginHandle);
74 MSG_ERROR_T MsgPlgDestroyHandle(MSG_PLUGIN_HANDLER_S *pPluginHandle)
76 if (pPluginHandle != NULL)
82 MSG_DEBUG("SMS plugin: destory handler OK");
88 MSG_ERROR_T SmsPlgInitialize()
92 int tapiRet = TAPI_API_SUCCESS;
96 if (tapiRet != TAPI_API_SUCCESS)
97 return MSG_ERR_PLUGIN_TAPIINIT;
101 SmsPluginCallback::instance()->registerEvent();
103 catch (MsgException& e)
105 MSG_FATAL("%s", e.what());
106 return MSG_ERR_PLUGIN_REGEVENT;
110 MSG_FATAL("%s", e.what());
111 return MSG_ERR_PLUGIN_REGEVENT;
120 MSG_ERROR_T SmsPlgFinalize()
124 SmsPluginCallback::instance()->deRegisterEvent();
134 MSG_ERROR_T SmsPlgRegisterListener(MSG_PLUGIN_LISTENER_S *pListener)
138 SmsPluginEventHandler::instance()->registerListener(pListener);
146 MSG_ERROR_T SmsPlgCheckSimStatus(MSG_SIM_STATUS_T *pStatus)
150 int tryNum = 0, tapiRet = TAPI_API_SUCCESS;
152 TelSimCardStatus_t status = TAPI_SIM_STATUS_CARD_ERROR;
158 if (tryNum > 30) return MSG_ERR_PLUGIN_TAPIINIT;
160 tapiRet = tel_get_sim_init_info(&status, &cardChanged);
162 if (tapiRet == TAPI_API_SUCCESS)
164 if (status == TAPI_SIM_STATUS_SIM_PIN_REQUIRED || status == TAPI_SIM_STATUS_SIM_PUK_REQUIRED)
166 MSG_DEBUG("PIN or PUK is required [%d]", status);
173 if (status == TAPI_SIM_STATUS_SIM_INIT_COMPLETED)
175 MSG_DEBUG("SIM status is OK [%d]", status);
177 MSG_DEBUG("SIM Changed [%d]", cardChanged);
179 if (cardChanged == 1)
180 *pStatus = MSG_SIM_STATUS_CHANGED;
182 *pStatus = MSG_SIM_STATUS_NORMAL;
186 else if (status == TAPI_SIM_STATUS_CARD_NOT_PRESENT)
188 MSG_DEBUG("SIM is not present [%d]", status);
190 *pStatus = MSG_SIM_STATUS_NOT_FOUND;
196 MSG_DEBUG("SIM status is not OK [%d]", status);
203 else if (tapiRet == TAPI_API_SIM_NOT_FOUND)
205 MSG_DEBUG("tel_get_sim_init_info() result is TAPI_API_SIM_NOT_FOUND");
207 *pStatus = MSG_SIM_STATUS_NOT_FOUND;
213 MSG_DEBUG("tel_get_sim_init_info() result is unknown!!!!!!!!!! [%d]", tapiRet);
227 MSG_ERROR_T SmsPlgCheckDeviceStatus()
231 int status = 0, tapiRet = TAPI_API_SUCCESS;
233 tapiRet = tel_check_sms_device_status(&status);
235 if (tapiRet != TAPI_API_SUCCESS)
237 MSG_DEBUG("tel_check_sms_device_status() Error! [%d], Status [%d]", tapiRet, status);
239 return MSG_ERR_PLUGIN_TAPI_FAILED;
242 if (status == TAPI_NETTEXT_DEVICE_READY)
244 MSG_DEBUG("Device Is Ready");
247 else if (status == TAPI_NETTEXT_DEVICE_NOT_READY)
249 MSG_DEBUG("Device Is Not Ready.. Waiting For Ready Callback");
251 if (SmsPluginEventHandler::instance()->getDeviceStatus() == true)
253 MSG_DEBUG("Device Is Ready");
262 MSG_ERROR_T SmsPlgSubmitRequest(MSG_REQUEST_INFO_S *pReqInfo, bool bReqCb)
264 // Add Submit SMS into DB
265 if ((pReqInfo->msgInfo.msgId == 0) && pReqInfo->msgInfo.msgPort.valid == false) {
266 if (SmsPluginStorage::instance()->addMessage(&(pReqInfo->msgInfo)) != MSG_SUCCESS) {
267 MSG_DEBUG("######## addMessage Fail !!");
268 return MSG_ERR_PLUGIN_STORAGE;
272 // Check SIM is present or not
273 MSG_SIM_STATUS_T simStatus = (MSG_SIM_STATUS_T)MsgSettingGetInt(MSG_SIM_CHANGED);
275 if (simStatus == MSG_SIM_STATUS_NOT_FOUND)
277 MSG_DEBUG("SIM is not present..");
280 if (pReqInfo->msgInfo.msgPort.valid == false)
281 SmsPluginStorage::instance()->updateSentMsg(&(pReqInfo->msgInfo), MSG_NETWORK_SEND_FAIL);
283 return MSG_ERR_NO_SIM;
286 SMS_REQUEST_INFO_S request = {};
288 request.reqId = pReqInfo->reqId;
290 memcpy(&(request.msgInfo), &(pReqInfo->msgInfo), sizeof(MSG_MESSAGE_INFO_S));
291 memcpy(&(request.sendOptInfo), &(pReqInfo->sendOptInfo), sizeof(MSG_SENDINGOPT_INFO_S));
293 request.bReqCb = bReqCb;
295 // Add Request into Queue and Start UA Manger
296 SmsPluginUAManager::instance()->addReqEntity(request);
302 MSG_ERROR_T SmsPlgInitSimMessage()
306 SmsPluginSimMsg::instance()->initSimMessage();
308 catch (MsgException& e)
310 MSG_FATAL("%s", e.what());
311 return MSG_ERR_PLUGIN_STORAGE;
315 MSG_FATAL("%s", e.what());
316 return MSG_ERR_PLUGIN_STORAGE;
323 MSG_ERROR_T SmsPlgSaveSimMessage(const MSG_MESSAGE_INFO_S *pMsgInfo, SMS_SIM_ID_LIST_S *pSimIdList)
325 MSG_ERROR_T err = MSG_SUCCESS;
327 err = SmsPluginSimMsg::instance()->saveSimMessage(pMsgInfo, pSimIdList);
333 MSG_ERROR_T SmsPlgDeleteSimMessage(MSG_SIM_ID_T SimMsgId)
337 SmsPluginSimMsg::instance()->deleteSimMessage(SimMsgId);
339 catch (MsgException& e)
341 MSG_FATAL("%s", e.what());
342 return MSG_ERR_PLUGIN_STORAGE;
346 MSG_FATAL("%s", e.what());
347 return MSG_ERR_PLUGIN_STORAGE;
354 MSG_ERROR_T SmsPlgSetReadStatus(MSG_SIM_ID_T SimMsgId)
358 SmsPluginSimMsg::instance()->setReadStatus(SimMsgId);
360 catch (MsgException& e)
362 MSG_FATAL("%s", e.what());
363 return MSG_ERR_PLUGIN_STORAGE;
367 MSG_FATAL("%s", e.what());
368 return MSG_ERR_PLUGIN_STORAGE;
375 MSG_ERROR_T SmsPlgSetMemoryStatus(MSG_ERROR_T Error)
377 int tapiRet = TAPI_API_SUCCESS, reqId = 0;
378 int status = TAPI_NETTEXT_PDA_MEMORY_STATUS_AVAILABLE;
380 if (Error == MSG_ERR_SIM_STORAGE_FULL || Error == MSG_ERR_MESSAGE_COUNT_FULL)
382 status = TAPI_NETTEXT_PDA_MEMORY_STATUS_FULL;
385 MSG_DEBUG("Set Status : [%d]", status);
387 tapiRet = tel_set_sms_memory_status(status, &reqId);
389 if (tapiRet == TAPI_API_SUCCESS)
391 MSG_DEBUG("######## tel_set_sms_memory_status() Success !!! req Id : [%d] #######", reqId);
395 MSG_DEBUG("######## tel_set_sms_memory_status() Success !!! req Id : [%d] return : [%d] #######", reqId, tapiRet);
402 MSG_ERROR_T SmsPlgInitConfigData(MSG_SIM_STATUS_T SimStatus)
406 SmsPluginSetting::instance()->initConfigData(SimStatus);
408 catch (MsgException& e)
410 MSG_FATAL("%s", e.what());
411 return MSG_ERR_PLUGIN_SETTING;
415 MSG_FATAL("%s", e.what());
416 return MSG_ERR_PLUGIN_SETTING;
423 MSG_ERROR_T SmsPlgSetConfigData(const MSG_SETTING_S *pSetting)
427 SmsPluginSetting::instance()->setConfigData(pSetting);
429 catch (MsgException& e)
431 MSG_FATAL("%s", e.what());
432 return MSG_ERR_PLUGIN_SETTING;
436 MSG_FATAL("%s", e.what());
437 return MSG_ERR_PLUGIN_SETTING;
444 MSG_ERROR_T SmsPlgGetConfigData(MSG_SETTING_S *pSetting)
448 SmsPluginSetting::instance()->getConfigData(pSetting);
450 catch (MsgException& e)
452 MSG_FATAL("%s", e.what());
453 return MSG_ERR_PLUGIN_SETTING;
457 MSG_FATAL("%s", e.what());
458 return MSG_ERR_PLUGIN_SETTING;