2 // Open Service Platform
3 // Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
5 // Licensed under the Apache License, Version 2.0 (the License);
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
9 // http://www.apache.org/licenses/LICENSE-2.0
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
18 * @file FMsg_SmsMmsCallbackHandler.cpp
19 * @brief This is the implementation file for the %_SmsMmsCallbackHandler class.
21 * This file contains the implementation of the %_SmsMmsCallbackHandler class.
25 #include <msg_transport.h>
26 #include <msg_storage.h>
27 #include <dbus/dbus.h>
28 #include <email-api.h>
29 #include <FMsgSmsManager.h>
30 #include <FBaseInteger.h>
31 #include <FBaseSysLog.h>
32 #include <FMsgEtwsPrimaryNotification.h>
33 #include <FBase_StringConverter.h>
34 #include "FMsg_SmsEvent.h"
35 #include "FMsg_SmsEventArg.h"
36 #include "FMsg_MmsEvent.h"
37 #include "FMsg_MmsEventArg.h"
38 #include "FMsg_MsgUtil.h"
39 #include "FMsg_SmsMmsCallbackHandler.h"
40 #include "FMsg_CbsChannelImpl.h"
42 using namespace Tizen::Base;
43 using namespace Tizen::Base::Collection;
44 using namespace Tizen::Base::Runtime;
46 namespace Tizen { namespace Messaging
49 _SmsMmsCallbackHandler* _SmsMmsCallbackHandler::__pMessageCallbackHandler = 0;
51 _SmsMmsCallbackHandler::_SmsMmsCallbackHandler(void)
53 , __cbsSettingsHandle(0)
54 , __pCbsChannelList(0)
55 , __pTempCbsChannelList(0)
56 , __callbackRegistered(false)
57 , __incomingSmsCallbackRegistered(true)
58 , __pCbsUserEvent(null)
59 , __pEtwsUserEvent(null)
64 _SmsMmsCallbackHandler::Construct()
68 r = __messageMap.Construct();
72 r = __msgMutex.Create();
78 _SmsMmsCallbackHandler::~_SmsMmsCallbackHandler(void)
82 msg_close_msg_handle(&__msgHandle);
86 if (__messageMap.GetCount())
88 __messageMap.RemoveAll(true);
91 if (__cbsSettingsHandle)
93 msg_release_struct(&__cbsSettingsHandle);
94 __cbsSettingsHandle = 0;
97 if (__pTempCbsChannelList)
99 if (__pTempCbsChannelList->GetCount() > 0)
101 __pTempCbsChannelList->RemoveAll(true);
103 delete __pTempCbsChannelList;
104 __pTempCbsChannelList = null;
108 _SmsMmsCallbackHandler*
109 _SmsMmsCallbackHandler::GetInstance(void)
111 result r = E_SUCCESS;
113 if (!__pMessageCallbackHandler)
115 __pMessageCallbackHandler = new (std::nothrow) _SmsMmsCallbackHandler();
116 SysTryReturn(NID_MSG, __pMessageCallbackHandler != NULL, null, E_SYSTEM, "failed to create instance");
118 if (__pMessageCallbackHandler)
120 r = __pMessageCallbackHandler->Construct();
124 delete __pMessageCallbackHandler;
125 __pMessageCallbackHandler = 0;
130 return __pMessageCallbackHandler;
134 _SmsMmsCallbackHandler::OpenMessageHandle(msg_handle_t& messageHandle)
136 int err = MSG_SUCCESS;
140 err = msg_open_msg_handle(&__msgHandle);
143 messageHandle = __msgHandle;
148 _SmsMmsCallbackHandler::OpenCbsSettingsHandle(msg_struct_t& cbsSettingsHandle)
150 int err = MSG_SUCCESS;
152 if (!__cbsSettingsHandle)
154 __cbsSettingsHandle = msg_create_struct(MSG_STRUCT_SETTING_CB_OPT);
155 if (__cbsSettingsHandle && __msgHandle)
157 err = msg_get_cb_opt(__msgHandle, __cbsSettingsHandle);
161 cbsSettingsHandle = __cbsSettingsHandle;
166 _SmsMmsCallbackHandler::AddCbsChannel(int from, int to, Tizen::Base::String& name, bool activate)
168 int err = MSG_SUCCESS;
169 result r = E_SUCCESS;
170 CbsChannel* pCbsChannel = null;
173 bool channelFound = false;
174 SysLog(NID_MSG, "AddCbsChannel from %d to %d name %s activate %d ",from, to, name.GetPointer(), activate);
176 for (int index = 0; index < __pTempCbsChannelList->GetCount(); index++)
178 CbsChannel* pCbsChannel = null;
179 pCbsChannel = dynamic_cast< Tizen::Messaging::CbsChannel* >(__pTempCbsChannelList->GetAt(index));
180 SysTryReturn(NID_MSG, pCbsChannel != null, r = E_SYSTEM, E_SYSTEM, "Failed to get the channel.");
182 pCbsChannel->GetRange(fromId, toId);
183 if (from == fromId && to == toId && pCbsChannel->GetName() == name)
186 _CbsChannelImpl::GetInstance(*pCbsChannel)->SetCbsChannelState(activate);
187 break; // found channel to be updated.
196 CbsChannel* pCbsChannel = null;
197 pCbsChannel = _CbsChannelImpl::GetCbsChannelN(from, to, name);
198 SysTryReturn(NID_MSG, pCbsChannel != null, r = E_SYSTEM, E_SYSTEM, "Failed to get the channel.");
202 _CbsChannelImpl::GetInstance(*pCbsChannel)->SetCbsChannelState(activate);
204 r =__pTempCbsChannelList->Add(*pCbsChannel);
205 SysTryReturn(NID_MSG,r == E_SUCCESS, r = E_SYSTEM, E_SYSTEM, "Failed to set the channel.");
212 r = SaveCbsSettings();
217 _SmsMmsCallbackHandler::RemoveCbsChannel(int from, int to)
219 int err = MSG_SUCCESS;
220 result r = E_SUCCESS;
223 bool channelFound = false;
224 CbsChannel* pCbsChannel = NULL;
225 SysLog(NID_MSG, "RemoveCbsChannel from %d %d ",from, to);
227 for (int index = 0; index < __pTempCbsChannelList->GetCount(); index++)
229 pCbsChannel = dynamic_cast< Tizen::Messaging::CbsChannel* >(__pTempCbsChannelList->GetAt(index));
230 SysTryReturn(NID_MSG, pCbsChannel != null, r = E_SYSTEM, E_SYSTEM, "Failed to get the channel.");
232 pCbsChannel->GetRange(fromId, toId);
233 if (from == fromId && to == toId)
235 channelFound = true; // found channel to be removed.
236 __pTempCbsChannelList->RemoveAt(index);
246 return E_OBJ_NOT_FOUND;
248 r = SaveCbsSettings();
249 SysTryReturn(NID_MSG, r == E_SUCCESS, r = E_SYSTEM, E_SYSTEM, "Failed to remove the channel.");
255 _SmsMmsCallbackHandler::SearchCbsChannel(int from, int to, int& index)
257 result r = E_SUCCESS;
260 bool channelFound = false;
261 CbsChannel* pCbsChannel = NULL;
262 SysLog(NID_MSG, "SearchCbsChannel from %d %d ",from, to);
264 for (int tempIndex = 0; tempIndex < __pTempCbsChannelList->GetCount(); tempIndex++)
266 pCbsChannel = dynamic_cast< Tizen::Messaging::CbsChannel* >(__pTempCbsChannelList->GetAt(tempIndex));
267 SysTryReturn(NID_MSG, pCbsChannel != null, r = E_SYSTEM, E_SYSTEM, "Failed to get the channel.");
269 pCbsChannel->GetRange(fromId, toId);
270 if (from == fromId && to == toId)
274 break; // found channel to be searched.
280 return E_OBJ_NOT_FOUND;
287 _SmsMmsCallbackHandler::UpdateCbsChannel(int from, int to, Tizen::Base::String name, bool activate)
289 int err = MSG_SUCCESS;
290 result r = E_SUCCESS;
293 bool channelFound = false;
295 CbsChannel* pCbsChannel = NULL;
296 SysLog(NID_MSG, "UpdateCbsChannel from %d to %d name %s activate %d ",from, to, name.GetPointer(), activate);
298 for (int i = 0; i < __pTempCbsChannelList->GetCount(); i++)
300 pCbsChannel = dynamic_cast< Tizen::Messaging::CbsChannel* >(__pTempCbsChannelList->GetAt(i));
301 SysTryReturn(NID_MSG, pCbsChannel != null, r = E_SYSTEM, E_SYSTEM, "Failed to get the channel.");
303 pCbsChannel->GetRange(fromId, toId);
304 if (from == fromId && to == toId)
308 break; // found channel to be updated.
314 return E_OBJ_NOT_FOUND;
317 // set cbs channel name
318 _CbsChannelImpl::GetInstance(*pCbsChannel)->SetCbsChannelName(name);
322 _CbsChannelImpl::GetInstance(*pCbsChannel)->SetCbsChannelState(activate);
326 _CbsChannelImpl::GetInstance(*pCbsChannel)->SetCbsChannelState(false);
328 //For changing to latest
329 __pTempCbsChannelList->RemoveAt(index);
330 __pTempCbsChannelList->Add(*pCbsChannel);
332 r = SaveCbsSettings();
333 SysTryReturn(NID_MSG, r == E_SUCCESS, r = E_SYSTEM, E_SYSTEM, "Failed to save the channel.");
339 _SmsMmsCallbackHandler::GetCbsChannel(int index, int& from, int& to, Tizen::Base::String& name, bool& activate)
341 result r = E_SUCCESS;
342 CbsChannel* pCbsChannel = NULL;
344 pCbsChannel = dynamic_cast< Tizen::Messaging::CbsChannel* >(__pTempCbsChannelList->GetAt(index));
345 SysTryReturn(NID_MSG, pCbsChannel != null, r = E_SYSTEM, E_SYSTEM, "Failed to get the channel.");
347 pCbsChannel->GetRange(from, to);
348 name = pCbsChannel->GetName();
349 if (pCbsChannel->IsActivated())
361 _SmsMmsCallbackHandler::GetCbsChannelsCount(int& count)
363 result r = E_SUCCESS;
365 if (__pTempCbsChannelList)
367 count = __pTempCbsChannelList->GetCount();
374 _SmsMmsCallbackHandler::SaveCbsSettings()
376 int err = MSG_SUCCESS;
377 result r = E_SUCCESS;
380 bool isChannelActive = false;
382 char* pTempChannelName = null;
384 SysTryReturn(NID_MSG, __pTempCbsChannelList != null, r = E_SYSTEM, E_SYSTEM, "Failed to save the channel.");
385 err = msg_get_list_handle(__cbsSettingsHandle, MSG_CB_CHANNEL_LIST_STRUCT, (void **)&__pCbsChannelList);
386 SysTryReturn(NID_MSG, err == MSG_SUCCESS, r = E_SYSTEM, E_SYSTEM, "Failed to get the channel handle.");
387 __pCbsChannelList->nCount = __pTempCbsChannelList->GetCount();
390 for (int index = 0; index < __pTempCbsChannelList->GetCount(); index++)
392 Tizen::Messaging::CbsChannel* pCbsChannel = dynamic_cast< Tizen::Messaging::CbsChannel* >(__pTempCbsChannelList->GetAt(index));
393 SysTryReturn(NID_MSG, pCbsChannel != null, r = E_SYSTEM, E_SYSTEM, "Failed to get the channel.");
394 pCbsChannel->GetRange(fromId, toId);
395 channelName = pCbsChannel->GetName();
396 if (pCbsChannel->IsActivated())
398 isChannelActive = true;
401 pTempChannelName = _StringConverter::CopyToCharArrayN(channelName);
402 SysTryReturn(NID_MSG, pTempChannelName != null, r = E_OUT_OF_MEMORY, r, "Memory allocation failed.");
404 msg_set_bool_value(__pCbsChannelList->msg_struct_info[index], MSG_CB_CHANNEL_ACTIVATE_BOOL, isChannelActive);
405 msg_set_int_value(__pCbsChannelList->msg_struct_info[index], MSG_CB_CHANNEL_ID_FROM_INT, fromId);
406 msg_set_int_value(__pCbsChannelList->msg_struct_info[index], MSG_CB_CHANNEL_ID_TO_INT, toId);
407 msg_set_str_value(__pCbsChannelList->msg_struct_info[index], MSG_CB_CHANNEL_NAME_STR,
408 pTempChannelName,CB_CHANNEL_NAME_MAX);
410 if (pTempChannelName)
412 delete[] pTempChannelName;
413 pTempChannelName = null;
417 err = msg_set_cb_opt(__msgHandle, __cbsSettingsHandle);
418 r = ConvertException(err);
423 _SmsMmsCallbackHandler::LoadCbsSettings()
425 int err = MSG_SUCCESS;
426 result r = E_SUCCESS;
427 CbsChannel* pCbsChannel = NULL;
430 bool isChannelActive = false;
431 char channelName[CB_CHANNEL_NAME_MAX + 1] = {0,};
433 __pTempCbsChannelList = new (std::nothrow) ArrayList();
434 SysTryCatch(NID_MSG, __pTempCbsChannelList != null, r = E_OUT_OF_MEMORY, r, "memory allocation failed");
437 r = __pTempCbsChannelList->Construct();
438 SysTryCatch(NID_MSG, r == E_SUCCESS, , r, "Failed to construct an ArrayList");
440 if (__cbsSettingsHandle)
443 err = msg_get_list_handle(__cbsSettingsHandle, MSG_CB_CHANNEL_LIST_STRUCT, (void **)&__pCbsChannelList);
444 for (int index = 0; index < __pCbsChannelList->nCount; index++)
446 msg_get_bool_value(__pCbsChannelList->msg_struct_info[index], MSG_CB_CHANNEL_ACTIVATE_BOOL, &isChannelActive);
447 msg_get_int_value(__pCbsChannelList->msg_struct_info[index], MSG_CB_CHANNEL_ID_FROM_INT, &fromId);
448 msg_get_int_value(__pCbsChannelList->msg_struct_info[index], MSG_CB_CHANNEL_ID_TO_INT, &toId);
449 msg_get_str_value(__pCbsChannelList->msg_struct_info[index], MSG_CB_CHANNEL_NAME_STR,
450 channelName,CB_CHANNEL_NAME_MAX);
452 pCbsChannel = _CbsChannelImpl::GetCbsChannelN(fromId, toId, String(channelName));
453 SysTryCatch(NID_MSG, pCbsChannel != null, r = E_SYSTEM, r, "Failed to get the channel.");
456 _CbsChannelImpl::GetInstance(*pCbsChannel)->SetCbsChannelState(isChannelActive);
458 __pTempCbsChannelList->Add(*pCbsChannel);
462 r = ConvertException(err);
466 if (__pTempCbsChannelList)
468 if (__pTempCbsChannelList->GetCount() > 0)
470 __pTempCbsChannelList->RemoveAll(true);
472 delete __pTempCbsChannelList;
473 __pTempCbsChannelList = null;
480 _SmsMmsCallbackHandler::RegisterMessageCallback()
482 int err = MSG_SUCCESS;
484 if (__msgHandle && !__callbackRegistered)
486 err = msg_reg_sent_status_callback(__msgHandle, &_SmsMmsCallbackHandler::SentMessageStatusCallback, null);
487 __callbackRegistered = true;
494 _SmsMmsCallbackHandler::CloseMessageHandle()
496 int err = MSG_SUCCESS;
500 err = msg_close_msg_handle(&__msgHandle);
502 __callbackRegistered = false;
509 _SmsMmsCallbackHandler::CloseCbsSettingsHandle()
511 int err = MSG_SUCCESS;
513 if (__cbsSettingsHandle)
515 err = msg_release_struct(&__cbsSettingsHandle);
516 __cbsSettingsHandle = 0;
519 if (__pTempCbsChannelList)
521 if (__pTempCbsChannelList->GetCount() > 0)
523 __pTempCbsChannelList->RemoveAll(true);
525 delete __pTempCbsChannelList;
526 __pTempCbsChannelList = null;
533 _SmsMmsCallbackHandler::SetInComingSmsCallback(bool incomingSmsCallbackRegistered)
535 __incomingSmsCallbackRegistered = incomingSmsCallbackRegistered;
539 _SmsMmsCallbackHandler::SetCbsAndEtwsUserEvent(_MessageType msgType, Tizen::Base::Object* pEvent)
541 if (msgType == _MSG_CBS)
543 __pCbsUserEvent = pEvent;
547 __pEtwsUserEvent = pEvent;
552 _SmsMmsCallbackHandler::AddToMessageMap(int reqId, _MessageType msgType, Tizen::Base::Object* pEvent)
554 result r = E_SUCCESS;
556 Integer* pReqId = new (std::nothrow) Integer(reqId);
557 SysTryReturn(NID_MSG, pReqId != null, E_OUT_OF_MEMORY, r = E_OUT_OF_MEMORY, "memory allocation failed.");
558 Integer* pMsgType = new (std::nothrow) Integer(msgType);
559 SysTryReturn(NID_MSG, pMsgType != null, E_OUT_OF_MEMORY, r = E_OUT_OF_MEMORY, "memory allocation failed.");
561 __msgMutex.Acquire();
563 r = __messageMap.Add(*pReqId, *pMsgType);
564 r = __messageMap.Add(*pReqId, *pEvent);
566 __msgMutex.Release();
572 _SmsMmsCallbackHandler::GetAndRemoveFromMessageMap(int reqId, _MessageType& msgType, Tizen::Base::Object** pUserEvent)
574 result r = E_SUCCESS;
576 Integer* pReqId = new (std::nothrow) Integer(reqId);
577 SysTryReturn(NID_MSG, pReqId != null, E_OUT_OF_MEMORY, r = E_OUT_OF_MEMORY, "memory allocation failed.");
578 Integer* pKey = null;
579 Integer* pMsgType = null;
580 Tizen::Base::Object* pEvent = null;
581 IEnumerator* pValueEnum = null;
582 IMapEnumerator* pMapEnum = null;
584 __msgMutex.Acquire();
586 pValueEnum = __messageMap.GetValuesN(*pReqId);
590 if (pValueEnum->MoveNext() == E_SUCCESS)
592 pMsgType = static_cast <Integer*>(pValueEnum->GetCurrent());
594 if (pValueEnum->MoveNext() == E_SUCCESS)
596 pEvent = static_cast <Tizen::Base::Object*>(pValueEnum->GetCurrent());
601 *pUserEvent = pEvent;
605 if (pMsgType->ToInt() == _MSG_SMS)
615 //Manually getting and deleting the key value
616 pMapEnum = __messageMap.GetMapEnumeratorN();
620 while (pMapEnum->MoveNext() == E_SUCCESS)
622 pKey = static_cast <Integer*>(pMapEnum->GetKey());
625 if (!(pKey->CompareTo(*pReqId)))
633 r = __messageMap.Remove(*pReqId, false);
641 __msgMutex.Release();
647 _SmsMmsCallbackHandler::SentMessageStatusCallback(msg_handle_t hMsgHandle, msg_struct_t msgStatus, void* pUserParam)
649 result r = E_SUCCESS;
650 _MessageType msgType = (_MessageType) -1;
651 Tizen::Base::Object* pUserEvent = null;
652 int status = MSG_NETWORK_SEND_FAIL;
655 msg_get_int_value(msgStatus, MSG_SENT_STATUS_REQUESTID_INT, &reqId);
656 msg_get_int_value(msgStatus, MSG_SENT_STATUS_NETWORK_STATUS_INT, &status);
658 _SmsMmsCallbackHandler::GetInstance()->GetAndRemoveFromMessageMap(reqId, msgType, &pUserEvent);
660 SysLog(NID_MSG, "hMsgHandle[%d]", hMsgHandle);
661 SysLog(NID_MSG, "req[%d]", reqId);
662 SysLog(NID_MSG, "msgType[%d]", msgType);
663 SysLog(NID_MSG, "pUserEvent[%d]", pUserEvent);
665 if (status == MSG_NETWORK_SEND_SUCCESS)
668 SysLog(NID_MSG, "Message is sent successfully");
673 SysLog(NID_MSG, "Failed to send the message. error cause: Message is not sending");
676 if (msgType == _MSG_SMS)
678 _SmsEvent* pSmsEvent = dynamic_cast <_SmsEvent*>(pUserEvent);
679 _SmsEventArg* pSmsEventArg = null;
683 pSmsEventArg = new (std::nothrow) _SmsEventArg(r);
686 pSmsEvent->Fire(*pSmsEventArg);
692 if (msgType == _MSG_MMS)
694 _MmsEvent* pMmsEvent = dynamic_cast <_MmsEvent*>(pUserEvent);
695 _MmsEventArg* pMmsEventArg = null;
699 pMmsEventArg = new (std::nothrow) _MmsEventArg(r);
702 pMmsEvent->Fire(*pMmsEventArg);
711 _SmsMmsCallbackHandler::IncomingSmsMessageCallback(msg_handle_t hMsgHandle, msg_struct_t newMsg, void* pUserParam)
713 _SmsEvent* pSmsEvent = static_cast <_SmsEvent*>(pUserParam);
714 _SmsEventArg* pSmsEventArg = null;
717 msg_get_int_value(newMsg, MSG_MESSAGE_DATA_SIZE_INT, &msgSize);
718 char msgText[msgSize + 1];
719 memset(msgText, 0, msgSize + 1);
720 msg_get_str_value(newMsg, MSG_MESSAGE_SMS_DATA_STR, msgText, msgSize);
721 String message(msgText);
724 msg_get_int_value(newMsg, MSG_MESSAGE_DEST_PORT_INT, &port);
726 int displayTime = -1;
727 msg_get_int_value(newMsg, MSG_MESSAGE_DISPLAY_TIME_INT, &displayTime);
728 DateTime receivedTime = _MsgUtil::ConvertTime((time_t *) &displayTime);
730 char address[MAX_ADDRESS_VAL_LEN] = {0, };
731 msg_struct_list_s* pAddrList = NULL;
732 msg_struct_t addrInfo = NULL;
733 msg_get_list_handle(newMsg, MSG_MESSAGE_ADDR_LIST_STRUCT, (void **)&pAddrList);
734 addrInfo = pAddrList->msg_struct_info[0];
735 msg_get_str_value(addrInfo, MSG_ADDRESS_INFO_ADDRESS_VALUE_STR, address, MAX_ADDRESS_VAL_LEN);
736 String senderAddress(address);
738 SysLog(NID_MSG, "hMsgHandle: [%d]", hMsgHandle);
739 SysLog(NID_MSG, "msg_body: [%s]", msgText);
740 SysLog(NID_MSG, "port: [%d]", port);
741 //SysLog(NID_MSG, "received time: [%s]", ctime(pReceivedTime));
743 if (_SmsMmsCallbackHandler::GetInstance()->__incomingSmsCallbackRegistered)
747 if (port == 0) // normal incoming SMS message case
749 pSmsEventArg = new (std::nothrow) _SmsEventArg(message, senderAddress, receivedTime);
750 SysTryReturnVoidResult(NID_MSG, pSmsEventArg != null, E_OUT_OF_MEMORY, "memory allocation failed.");
752 else // SMS trigger message case
754 pSmsEventArg = new (std::nothrow) _SmsEventArg(port, receivedTime, message, senderAddress);
755 SysTryReturnVoidResult(NID_MSG, pSmsEventArg != null, E_OUT_OF_MEMORY, "memory allocation failed.");
757 pSmsEvent->Fire(*pSmsEventArg);
763 _SmsMmsCallbackHandler::IncomingCbsMessageCallback(msg_handle_t hMsgHandle, msg_struct_t newMsg, void* pUserParam)
765 _SmsEventArg* pSmsEventArg = null;
766 int tempReceivedTime = 0;
767 DateTime receivedTime;
768 bool etwsNotifiation = false;
770 int serialNumber = 0;
773 Tizen::Base::ByteBuffer msgSerialNumber;
775 msg_get_int_value(newMsg, MSG_CB_MSG_RECV_TIME_INT, &tempReceivedTime);
776 receivedTime = _MsgUtil::ConvertTime((time_t *) &tempReceivedTime);
778 msg_get_int_value(newMsg, MSG_CB_MSG_MSG_ID_INT, &messgeId);
779 msg_get_int_value(newMsg, MSG_CB_MSG_SERIAL_NUM_INT, &serialNumber);
780 msg_get_int_value(newMsg, MSG_CB_MSG_TYPE_INT, &cbsType);
782 Tizen::Base::Integer serialno(serialNumber);
783 length = serialno.ToString().GetLength();
785 msgSerialNumber.Construct(length);
786 msgSerialNumber.SetInt(0, serialNumber);
787 msgSerialNumber.SetPosition(0);
789 if (cbsType == MSG_TYPE_SMS_ETWS_PRIMARY || cbsType == MSG_TYPE_SMS_ETWS_SECONDARY)
792 char etwsWarningInfo[MESSAGES_ETWS_WARNING_INFO_LEN];
793 Tizen::Base::ByteBuffer msgSecurityInfo;
794 Tizen::Base::ByteBuffer etwsMsgWarningType;
795 msg_get_int_value(newMsg, MSG_CB_MSG_ETWS_WARNING_TYPE_INT, &etwsWarningType);
796 msg_get_str_value(newMsg, MSG_CB_MSG_ETWS_WARNING_SECU_INFO_STR, etwsWarningInfo, MESSAGES_ETWS_WARNING_INFO_LEN);
798 String etwsSecurityInfo(etwsWarningInfo);
799 length = etwsSecurityInfo.GetLength();
800 msgSecurityInfo.Construct(length);
801 msgSecurityInfo.SetArray((byte*) etwsWarningInfo, 0, length);
802 msgSecurityInfo.SetPosition(0);
804 Tizen::Base::Integer warningtype(etwsWarningType);
805 length = warningtype.ToString().GetLength();
807 etwsMsgWarningType.Construct(length);
808 etwsMsgWarningType.SetInt(0, etwsWarningType);
809 etwsMsgWarningType.SetPosition(0);
811 etwsNotifiation = true;
812 _SmsEvent* pSmsEvent = static_cast <_SmsEvent*>(_SmsMmsCallbackHandler::GetInstance()->__pEtwsUserEvent);
814 SysLog(NID_MSG, "cbs etwsWarningType: [%d]", etwsWarningType);
818 pSmsEventArg = new (std::nothrow) _SmsEventArg(receivedTime, msgSerialNumber, msgSecurityInfo, messgeId,
819 etwsMsgWarningType, _SMS_EVENT_TYPE_ETWS_RECEIVE_RESULT);
820 SysTryReturnVoidResult(NID_MSG, pSmsEventArg != null, E_OUT_OF_MEMORY, "memory allocation failed.");
821 pSmsEvent->Fire(*pSmsEventArg);
826 _SmsEvent* pSmsEvent = static_cast <_SmsEvent*>(_SmsMmsCallbackHandler::GetInstance()->__pCbsUserEvent);
827 int dataCodingScheme = 0;
830 msg_get_int_value(newMsg, MSG_CB_MSG_CB_TEXT_LEN_INT, &msgSize);
831 char msgBody[msgSize + 1];
832 memset(msgBody, 0, msgSize + 1);
833 msg_get_str_value(newMsg, MSG_CB_MSG_CB_TEXT_STR, msgBody, msgSize + 1);
834 String message(msgBody); // porting char* to String
836 msg_get_int_value(newMsg, MSG_CB_MSG_DCS_INT, &dataCodingScheme);
837 Tizen::Base::Integer dataCodingSchemeTemp(dataCodingScheme);
839 //language type of cbs message
840 String messageLanguage(L"");
841 byte higherNibble = dataCodingScheme & 0xf0;
842 byte lowerNibble = dataCodingScheme & 0x0f;
844 //check higher nibble
845 // if higher nibble 0000
846 if (higherNibble == 0x00)
848 messageLanguage = GetCbsLanguageType(lowerNibble);
850 else if (higherNibble == 0x01)
852 // if higher nibble is 0001, get language type from framework
855 memset(type, 0, len + 1);
856 msg_get_str_value(newMsg, MSG_CB_MSG_LANGUAGE_TYPE_STR, type, len);
857 messageLanguage = String(type);
859 else if (higherNibble == 0x20 && lowerNibble == 0x00)
862 messageLanguage = String(L"CS");
871 pSmsEventArg = new (std::nothrow) _SmsEventArg(message, msgSerialNumber, receivedTime, messgeId, etwsNotifiation,
872 ((byte) dataCodingSchemeTemp.ToChar()),messageLanguage, _SMS_EVENT_TYPE_CBS_RECEIVE_RESULT);
873 SysTryReturnVoidResult(NID_MSG, pSmsEventArg != null, E_OUT_OF_MEMORY, "memory allocation failed.");
874 pSmsEvent->Fire(*pSmsEventArg);
877 SysLog(NID_MSG, "cbs msg_body: [%s]", msgBody);
878 SysLog(NID_MSG, "cbs dataCodingScheme: [%d]", dataCodingScheme);
879 SysLog(NID_MSG, "cbs languageType: [%s]", messageLanguage.GetPointer());
882 SysLog(NID_MSG, "cbs msg_id: [%d]", messgeId);
883 SysLog(NID_MSG, "cbs serialNumber: [%d]", serialNumber);
884 SysLog(NID_MSG, "cbs etwsNotifiation: [%d]", etwsNotifiation);
888 _SmsMmsCallbackHandler::IncomingWapPushMessageCallback(msg_handle_t hMsgHandle, const char* pHeader, const char* pBody, int bodyLength, void* pUserParam)
890 _SmsEvent* pSmsEvent = static_cast <_SmsEvent*>(pUserParam);
891 _SmsEventArg* pSmsEventArg = null;
892 String msgHeader(pHeader);
893 Tizen::Base::ByteBuffer msgBody;
894 msgBody.Construct(bodyLength);
895 msgBody.SetArray((byte*) pBody, 0, bodyLength);
896 msgBody.SetPosition(0);
898 SysLog(NID_MSG, "push msg body: [%s]", pBody);
899 SysLog(NID_MSG, "push msg header: [%s]", pHeader);
900 SysLog(NID_MSG, "push body length: [%d]", bodyLength);
904 pSmsEventArg = new (std::nothrow) _SmsEventArg(msgHeader, msgBody, _SMS_EVENT_TYPE_WAP_PUSH_RECEIVE_RESULT);
905 SysTryReturnVoidResult(NID_MSG, pSmsEventArg != null, E_OUT_OF_MEMORY, "memory allocation failed.");
906 pSmsEvent->Fire(*pSmsEventArg);
911 _SmsMmsCallbackHandler::GetCbsLanguageType(byte codingScheme)
913 String languageType(L"");
918 languageType = String(L"DE");
921 languageType = String(L"EN");
924 languageType = String(L"IT");
927 languageType = String(L"FR");
930 languageType = String(L"ES");
933 languageType = String(L"NL");
936 languageType = String(L"SV");
939 languageType = String(L"DA");
942 languageType = String(L"PT");
945 languageType = String(L"FI");
948 languageType = String(L"NO");
951 languageType = String(L"EL");
954 languageType = String(L"TR");
957 languageType = String(L"HU");
960 languageType = String(L"PL");
963 languageType = String(L"");
964 SysLog(NID_MSG, "Language unspecified.");
974 _SmsMmsCallbackHandler::ConvertException(int err) const
976 result r = E_SUCCESS;
984 case MSG_ERR_INVALID_PARAMETER:
985 case MSG_ERR_INVALID_MESSAGE:
986 case MSG_ERR_NULL_POINTER:
987 case MSG_ERR_NULL_MESSAGE:
991 case MSG_ERR_MEMORY_ERROR:
995 case MSG_ERR_SERVER_NOT_READY:
996 case MSG_ERR_TRANSPORT_ERROR:
997 case MSG_ERR_COMMUNICATION_ERROR:
998 r = E_NETWORK_UNAVAILABLE;
1001 case MSG_ERR_NO_SIM:
1002 r = E_DEVICE_UNAVAILABLE;
1005 case MSG_ERR_PLUGIN_TAPI_FAILED:
1017 } } // Tizen::Messaging