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;
172 pCbsChannel = _CbsChannelImpl::GetCbsChannelN(from, to, name);
173 SysTryReturn(NID_MSG, pCbsChannel != null, r = E_SYSTEM, E_SYSTEM, "Failed to get the channel.");
177 _CbsChannelImpl::GetInstance(*pCbsChannel)->SetCbsChannelState(activate);
180 r =__pTempCbsChannelList->Add(*pCbsChannel);
182 err = SaveCbsSettings();
183 r = ConvertException(err);
189 _SmsMmsCallbackHandler::RemoveCbsChannel(int from, int to)
191 int err = MSG_SUCCESS;
192 result r = E_SUCCESS;
195 bool channelFound = false;
196 CbsChannel* pCbsChannel = NULL;
198 for (int index = 0; index < __pTempCbsChannelList->GetCount(); index++)
200 pCbsChannel = dynamic_cast< Tizen::Messaging::CbsChannel* >(__pTempCbsChannelList->GetAt(index));
201 SysTryReturn(NID_MSG, pCbsChannel != null, r = E_SYSTEM, E_SYSTEM, "Failed to get the channel.");
203 pCbsChannel->GetRange(fromId, toId);
204 if (from == fromId && to == toId)
206 channelFound = true; // found channel to be removed.
207 __pTempCbsChannelList->RemoveAt(index);
209 err = SaveCbsSettings();
210 r = ConvertException(err);
218 return E_OBJ_NOT_FOUND;
225 _SmsMmsCallbackHandler::SearchCbsChannel(int from, int to, int& index)
227 result r = E_SUCCESS;
230 bool channelFound = false;
231 CbsChannel* pCbsChannel = NULL;
233 for (int tempIndex = 0; tempIndex < __pTempCbsChannelList->GetCount(); tempIndex++)
235 pCbsChannel = dynamic_cast< Tizen::Messaging::CbsChannel* >(__pTempCbsChannelList->GetAt(tempIndex));
236 SysTryReturn(NID_MSG, pCbsChannel != null, r = E_SYSTEM, E_SYSTEM, "Failed to get the channel.");
238 pCbsChannel->GetRange(fromId, toId);
239 if (from == fromId && to == toId)
243 break; // found channel to be searched.
249 return E_OBJ_NOT_FOUND;
256 _SmsMmsCallbackHandler::UpdateCbsChannel(int from, int to, Tizen::Base::String name, bool activate)
258 int err = MSG_SUCCESS;
259 result r = E_SUCCESS;
262 bool channelFound = false;
263 CbsChannel* pCbsChannel = NULL;
265 for (int index = 0; index < __pTempCbsChannelList->GetCount(); index++)
267 pCbsChannel = dynamic_cast< Tizen::Messaging::CbsChannel* >(__pTempCbsChannelList->GetAt(index));
268 SysTryReturn(NID_MSG, pCbsChannel != null, r = E_SYSTEM, E_SYSTEM, "Failed to get the channel.");
270 pCbsChannel->GetRange(fromId, toId);
271 if (from == fromId && to == toId)
274 break; // found channel to be updated.
280 return E_OBJ_NOT_FOUND;
283 // set cbs channel name
284 _CbsChannelImpl::GetInstance(*pCbsChannel)->SetCbsChannelName(name);
288 _CbsChannelImpl::GetInstance(*pCbsChannel)->SetCbsChannelState(activate);
292 _CbsChannelImpl::GetInstance(*pCbsChannel)->SetCbsChannelState(false);
295 err = SaveCbsSettings();
296 r = ConvertException(err);
301 _SmsMmsCallbackHandler::GetCbsChannel(int index, int& from, int& to, Tizen::Base::String& name, bool& activate)
303 result r = E_SUCCESS;
304 CbsChannel* pCbsChannel = NULL;
306 pCbsChannel = dynamic_cast< Tizen::Messaging::CbsChannel* >(__pTempCbsChannelList->GetAt(index));
307 SysTryReturn(NID_MSG, pCbsChannel != null, r = E_SYSTEM, E_SYSTEM, "Failed to get the channel.");
309 pCbsChannel->GetRange(from, to);
310 name = pCbsChannel->GetName();
311 if (pCbsChannel->IsActivated())
323 _SmsMmsCallbackHandler::GetCbsChannelsCount(int& count)
325 result r = E_SUCCESS;
327 if (__pTempCbsChannelList)
329 count = __pTempCbsChannelList->GetCount();
336 _SmsMmsCallbackHandler::SaveCbsSettings()
338 int err = MSG_SUCCESS;
339 result r = E_SUCCESS;
342 bool isChannelActive = false;
344 char* pTempChannelName = null;
346 SysTryReturn(NID_MSG, __pTempCbsChannelList != null, r = E_SYSTEM, E_SYSTEM, "Failed to save the channel.");
347 err = msg_get_list_handle(__cbsSettingsHandle, MSG_CB_CHANNEL_LIST_STRUCT, (void **)&__pCbsChannelList);
350 for (int index = 0; index < __pTempCbsChannelList->GetCount(); index++)
352 Tizen::Messaging::CbsChannel* pCbsChannel = dynamic_cast< Tizen::Messaging::CbsChannel* >(__pTempCbsChannelList->GetAt(index));
353 SysTryReturn(NID_MSG, pCbsChannel != null, r = E_SYSTEM, E_SYSTEM, "Failed to get the channel.");
354 pCbsChannel->GetRange(fromId, toId);
355 channelName = pCbsChannel->GetName();
356 if (pCbsChannel->IsActivated())
358 isChannelActive = true;
361 pTempChannelName = _StringConverter::CopyToCharArrayN(channelName);
362 SysTryReturn(NID_MSG, pTempChannelName != null, r = E_OUT_OF_MEMORY, r, "Memory allocation failed.");
364 msg_set_bool_value(__pCbsChannelList->msg_struct_info[index], MSG_CB_CHANNEL_ACTIVATE_BOOL, isChannelActive);
365 msg_set_int_value(__pCbsChannelList->msg_struct_info[index], MSG_CB_CHANNEL_ID_FROM_INT, fromId);
366 msg_set_int_value(__pCbsChannelList->msg_struct_info[index], MSG_CB_CHANNEL_ID_TO_INT, toId);
367 msg_set_str_value(__pCbsChannelList->msg_struct_info[index], MSG_CB_CHANNEL_NAME_STR,
368 pTempChannelName,CB_CHANNEL_NAME_MAX);
370 if (pTempChannelName)
372 delete[] pTempChannelName;
373 pTempChannelName = null;
377 err = msg_set_cb_opt(__msgHandle, __cbsSettingsHandle);
378 r = ConvertException(err);
383 _SmsMmsCallbackHandler::LoadCbsSettings()
385 int err = MSG_SUCCESS;
386 result r = E_SUCCESS;
387 CbsChannel* pCbsChannel = NULL;
390 bool isChannelActive = false;
391 char channelName[CB_CHANNEL_NAME_MAX + 1] = {0,};
393 __pTempCbsChannelList = new (std::nothrow) ArrayList();
394 SysTryCatch(NID_MSG, __pTempCbsChannelList != null, r = E_OUT_OF_MEMORY, r, "memory allocation failed");
397 r = __pTempCbsChannelList->Construct();
398 SysTryCatch(NID_MSG, r == E_SUCCESS, , r, "Failed to construct an ArrayList");
400 if (__cbsSettingsHandle)
403 err = msg_get_list_handle(__cbsSettingsHandle, MSG_CB_CHANNEL_LIST_STRUCT, (void **)&__pCbsChannelList);
404 for (int index = 0; index < __pCbsChannelList->nCount; index++)
406 msg_get_bool_value(__pCbsChannelList->msg_struct_info[index], MSG_CB_CHANNEL_ACTIVATE_BOOL, &isChannelActive);
407 msg_get_int_value(__pCbsChannelList->msg_struct_info[index], MSG_CB_CHANNEL_ID_FROM_INT, &fromId);
408 msg_get_int_value(__pCbsChannelList->msg_struct_info[index], MSG_CB_CHANNEL_ID_TO_INT, &toId);
409 msg_get_str_value(__pCbsChannelList->msg_struct_info[index], MSG_CB_CHANNEL_NAME_STR,
410 channelName,CB_CHANNEL_NAME_MAX);
412 pCbsChannel = _CbsChannelImpl::GetCbsChannelN(fromId, toId, String(channelName));
413 SysTryCatch(NID_MSG, pCbsChannel != null, r = E_SYSTEM, r, "Failed to get the channel.");
416 _CbsChannelImpl::GetInstance(*pCbsChannel)->SetCbsChannelState(isChannelActive);
418 __pTempCbsChannelList->Add(*pCbsChannel);
422 r = ConvertException(err);
426 if (__pTempCbsChannelList)
428 if (__pTempCbsChannelList->GetCount() > 0)
430 __pTempCbsChannelList->RemoveAll(true);
432 delete __pTempCbsChannelList;
433 __pTempCbsChannelList = null;
440 _SmsMmsCallbackHandler::RegisterMessageCallback()
442 int err = MSG_SUCCESS;
444 if (__msgHandle && !__callbackRegistered)
446 err = msg_reg_sent_status_callback(__msgHandle, &_SmsMmsCallbackHandler::SentMessageStatusCallback, null);
447 __callbackRegistered = true;
454 _SmsMmsCallbackHandler::CloseMessageHandle()
456 int err = MSG_SUCCESS;
460 err = msg_close_msg_handle(&__msgHandle);
468 _SmsMmsCallbackHandler::CloseCbsSettingsHandle()
470 int err = MSG_SUCCESS;
472 if (__cbsSettingsHandle)
474 err = msg_release_struct(&__cbsSettingsHandle);
475 __cbsSettingsHandle = 0;
478 if (__pTempCbsChannelList)
480 if (__pTempCbsChannelList->GetCount() > 0)
482 __pTempCbsChannelList->RemoveAll(true);
484 delete __pTempCbsChannelList;
485 __pTempCbsChannelList = null;
492 _SmsMmsCallbackHandler::SetInComingSmsCallback(bool incomingSmsCallbackRegistered)
494 __incomingSmsCallbackRegistered = incomingSmsCallbackRegistered;
498 _SmsMmsCallbackHandler::SetCbsAndEtwsUserEvent(_MessageType msgType, Tizen::Base::Object* pEvent)
500 if (msgType == _MSG_CBS)
502 __pCbsUserEvent = pEvent;
506 __pEtwsUserEvent = pEvent;
511 _SmsMmsCallbackHandler::AddToMessageMap(int reqId, _MessageType msgType, Tizen::Base::Object* pEvent)
513 result r = E_SUCCESS;
515 Integer* pReqId = new (std::nothrow) Integer(reqId);
516 SysTryReturn(NID_MSG, pReqId != null, E_OUT_OF_MEMORY, r = E_OUT_OF_MEMORY, "memory allocation failed.");
517 Integer* pMsgType = new (std::nothrow) Integer(msgType);
518 SysTryReturn(NID_MSG, pMsgType != null, E_OUT_OF_MEMORY, r = E_OUT_OF_MEMORY, "memory allocation failed.");
520 __msgMutex.Acquire();
522 r = __messageMap.Add(*pReqId, *pMsgType);
523 r = __messageMap.Add(*pReqId, *pEvent);
525 __msgMutex.Release();
531 _SmsMmsCallbackHandler::GetAndRemoveFromMessageMap(int reqId, _MessageType& msgType, Tizen::Base::Object** pUserEvent)
533 result r = E_SUCCESS;
535 Integer* pReqId = new (std::nothrow) Integer(reqId);
536 SysTryReturn(NID_MSG, pReqId != null, E_OUT_OF_MEMORY, r = E_OUT_OF_MEMORY, "memory allocation failed.");
537 Integer* pKey = null;
538 Integer* pMsgType = null;
539 Tizen::Base::Object* pEvent = null;
540 IEnumerator* pValueEnum = null;
541 IMapEnumerator* pMapEnum = null;
543 __msgMutex.Acquire();
545 pValueEnum = __messageMap.GetValuesN(*pReqId);
549 if (pValueEnum->MoveNext() == E_SUCCESS)
551 pMsgType = static_cast <Integer*>(pValueEnum->GetCurrent());
553 if (pValueEnum->MoveNext() == E_SUCCESS)
555 pEvent = static_cast <Tizen::Base::Object*>(pValueEnum->GetCurrent());
560 *pUserEvent = pEvent;
564 if (pMsgType->ToInt() == _MSG_SMS)
574 //Manually getting and deleting the key value
575 pMapEnum = __messageMap.GetMapEnumeratorN();
579 while (pMapEnum->MoveNext() == E_SUCCESS)
581 pKey = static_cast <Integer*>(pMapEnum->GetKey());
584 if (!(pKey->CompareTo(*pReqId)))
592 r = __messageMap.Remove(*pReqId, false);
600 __msgMutex.Release();
606 _SmsMmsCallbackHandler::SentMessageStatusCallback(msg_handle_t hMsgHandle, msg_struct_t msgStatus, void* pUserParam)
608 result r = E_SUCCESS;
609 _MessageType msgType = (_MessageType) -1;
610 Tizen::Base::Object* pUserEvent = null;
611 int status = MSG_NETWORK_SEND_FAIL;
614 msg_get_int_value(msgStatus, MSG_SENT_STATUS_REQUESTID_INT, &reqId);
615 msg_get_int_value(msgStatus, MSG_SENT_STATUS_NETWORK_STATUS_INT, &status);
617 _SmsMmsCallbackHandler::GetInstance()->GetAndRemoveFromMessageMap(reqId, msgType, &pUserEvent);
619 SysLog(NID_MSG, "hMsgHandle[%d]", hMsgHandle);
620 SysLog(NID_MSG, "req[%d]", reqId);
621 SysLog(NID_MSG, "msgType[%d]", msgType);
622 SysLog(NID_MSG, "pUserEvent[%d]", pUserEvent);
624 if (status == MSG_NETWORK_SEND_SUCCESS)
627 SysLog(NID_MSG, "Message is sent successfully");
632 SysLog(NID_MSG, "Failed to send the message. error cause: Message is not sending");
635 if (msgType == _MSG_SMS)
637 _SmsEvent* pSmsEvent = dynamic_cast <_SmsEvent*>(pUserEvent);
638 _SmsEventArg* pSmsEventArg = null;
642 pSmsEventArg = new (std::nothrow) _SmsEventArg(r);
645 pSmsEvent->Fire(*pSmsEventArg);
651 if (msgType == _MSG_MMS)
653 _MmsEvent* pMmsEvent = dynamic_cast <_MmsEvent*>(pUserEvent);
654 _MmsEventArg* pMmsEventArg = null;
658 pMmsEventArg = new (std::nothrow) _MmsEventArg(r);
661 pMmsEvent->Fire(*pMmsEventArg);
670 _SmsMmsCallbackHandler::IncomingSmsMessageCallback(msg_handle_t hMsgHandle, msg_struct_t newMsg, void* pUserParam)
672 _SmsEvent* pSmsEvent = static_cast <_SmsEvent*>(pUserParam);
673 _SmsEventArg* pSmsEventArg = null;
676 msg_get_int_value(newMsg, MSG_MESSAGE_DATA_SIZE_INT, &msgSize);
677 char msgText[msgSize + 1];
678 memset(msgText, 0, msgSize + 1);
679 msg_get_str_value(newMsg, MSG_MESSAGE_SMS_DATA_STR, msgText, msgSize);
680 String message(msgText);
683 msg_get_int_value(newMsg, MSG_MESSAGE_DEST_PORT_INT, &port);
685 int displayTime = -1;
686 msg_get_int_value(newMsg, MSG_MESSAGE_DISPLAY_TIME_INT, &displayTime);
687 DateTime receivedTime = _MsgUtil::ConvertTime((time_t *) &displayTime);
689 char address[MAX_ADDRESS_VAL_LEN] = {0, };
690 msg_struct_list_s* pAddrList = NULL;
691 msg_struct_t addrInfo = NULL;
692 msg_get_list_handle(newMsg, MSG_MESSAGE_ADDR_LIST_STRUCT, (void **)&pAddrList);
693 addrInfo = pAddrList->msg_struct_info[0];
694 msg_get_str_value(addrInfo, MSG_ADDRESS_INFO_ADDRESS_VALUE_STR, address, MAX_ADDRESS_VAL_LEN);
695 String senderAddress(address);
697 SysLog(NID_MSG, "hMsgHandle: [%d]", hMsgHandle);
698 SysLog(NID_MSG, "msg_body: [%s]", msgText);
699 SysLog(NID_MSG, "port: [%d]", port);
700 //SysLog(NID_MSG, "received time: [%s]", ctime(pReceivedTime));
702 if (_SmsMmsCallbackHandler::GetInstance()->__incomingSmsCallbackRegistered)
706 if (port == 0) // normal incoming SMS message case
708 pSmsEventArg = new (std::nothrow) _SmsEventArg(message, senderAddress, receivedTime);
709 SysTryReturnVoidResult(NID_MSG, pSmsEventArg != null, E_OUT_OF_MEMORY, "memory allocation failed.");
711 else // SMS trigger message case
713 pSmsEventArg = new (std::nothrow) _SmsEventArg(port, receivedTime, message, senderAddress);
714 SysTryReturnVoidResult(NID_MSG, pSmsEventArg != null, E_OUT_OF_MEMORY, "memory allocation failed.");
716 pSmsEvent->Fire(*pSmsEventArg);
722 _SmsMmsCallbackHandler::IncomingCbsMessageCallback(msg_handle_t hMsgHandle, msg_struct_t newMsg, void* pUserParam)
724 _SmsEventArg* pSmsEventArg = null;
725 int tempReceivedTime = 0;
726 DateTime receivedTime;
727 bool etwsNotifiation = false;
729 int serialNumber = 0;
732 Tizen::Base::ByteBuffer msgSerialNumber;
734 msg_get_int_value(newMsg, MSG_CB_MSG_RECV_TIME_INT, &tempReceivedTime);
735 receivedTime = _MsgUtil::ConvertTime((time_t *) &tempReceivedTime);
737 msg_get_int_value(newMsg, MSG_CB_MSG_MSG_ID_INT, &messgeId);
738 msg_get_int_value(newMsg, MSG_CB_MSG_SERIAL_NUM_INT, &serialNumber);
739 msg_get_int_value(newMsg, MSG_CB_MSG_TYPE_INT, &cbsType);
741 Tizen::Base::Integer serialno(serialNumber);
742 length = serialno.ToString().GetLength();
744 msgSerialNumber.Construct(length);
745 msgSerialNumber.SetInt(0, serialNumber);
746 msgSerialNumber.SetPosition(0);
748 if (cbsType == MSG_TYPE_SMS_ETWS_PRIMARY || cbsType == MSG_TYPE_SMS_ETWS_SECONDARY)
751 char etwsWarningInfo[MESSAGES_ETWS_WARNING_INFO_LEN];
752 Tizen::Base::ByteBuffer msgSecurityInfo;
753 Tizen::Base::ByteBuffer etwsMsgWarningType;
754 msg_get_int_value(newMsg, MSG_CB_MSG_ETWS_WARNING_TYPE_INT, &etwsWarningType);
755 msg_get_str_value(newMsg, MSG_CB_MSG_ETWS_WARNING_SECU_INFO_STR, etwsWarningInfo, MESSAGES_ETWS_WARNING_INFO_LEN);
757 String etwsSecurityInfo(etwsWarningInfo);
758 length = etwsSecurityInfo.GetLength();
759 msgSecurityInfo.Construct(length);
760 msgSecurityInfo.SetArray((byte*) etwsWarningInfo, 0, length);
761 msgSecurityInfo.SetPosition(0);
763 Tizen::Base::Integer warningtype(etwsWarningType);
764 length = warningtype.ToString().GetLength();
766 etwsMsgWarningType.Construct(length);
767 etwsMsgWarningType.SetInt(0, etwsWarningType);
768 etwsMsgWarningType.SetPosition(0);
770 etwsNotifiation = true;
771 _SmsEvent* pSmsEvent = static_cast <_SmsEvent*>(_SmsMmsCallbackHandler::GetInstance()->__pEtwsUserEvent);
773 SysLog(NID_MSG, "cbs etwsWarningType: [%d]", etwsWarningType);
777 pSmsEventArg = new (std::nothrow) _SmsEventArg(receivedTime, msgSerialNumber, msgSecurityInfo, messgeId,
778 etwsMsgWarningType, _SMS_EVENT_TYPE_ETWS_RECEIVE_RESULT);
779 SysTryReturnVoidResult(NID_MSG, pSmsEventArg != null, E_OUT_OF_MEMORY, "memory allocation failed.");
780 pSmsEvent->Fire(*pSmsEventArg);
785 _SmsEvent* pSmsEvent = static_cast <_SmsEvent*>(_SmsMmsCallbackHandler::GetInstance()->__pCbsUserEvent);
786 int dataCodingScheme = 0;
789 msg_get_int_value(newMsg, MSG_CB_MSG_CB_TEXT_LEN_INT, &msgSize);
790 char msgBody[msgSize + 1];
791 memset(msgBody, 0, msgSize + 1);
792 msg_get_str_value(newMsg, MSG_CB_MSG_CB_TEXT_STR, msgBody, msgSize + 1);
793 String message(msgBody); // porting char* to String
795 msg_get_int_value(newMsg, MSG_CB_MSG_DCS_INT, &dataCodingScheme);
796 Tizen::Base::Integer dataCodingSchemeTemp(dataCodingScheme);
798 //language type of cbs message
799 String messageLanguage(L"");
800 byte higherNibble = dataCodingScheme & 0xf0;
801 byte lowerNibble = dataCodingScheme & 0x0f;
803 //check higher nibble
804 // if higher nibble 0000
805 if (higherNibble == 0x00)
807 messageLanguage = GetCbsLanguageType(lowerNibble);
809 else if (higherNibble == 0x01)
811 // if higher nibble is 0001, get language type from framework
814 memset(type, 0, len + 1);
815 msg_get_str_value(newMsg, MSG_CB_MSG_LANGUAGE_TYPE_STR, type, len);
816 messageLanguage = String(type);
818 else if (higherNibble == 0x20 && lowerNibble == 0x00)
821 messageLanguage = String(L"CS");
830 pSmsEventArg = new (std::nothrow) _SmsEventArg(message, msgSerialNumber, receivedTime, messgeId, etwsNotifiation,
831 ((byte) dataCodingSchemeTemp.ToChar()),messageLanguage, _SMS_EVENT_TYPE_CBS_RECEIVE_RESULT);
832 SysTryReturnVoidResult(NID_MSG, pSmsEventArg != null, E_OUT_OF_MEMORY, "memory allocation failed.");
833 pSmsEvent->Fire(*pSmsEventArg);
836 SysLog(NID_MSG, "cbs msg_body: [%s]", msgBody);
837 SysLog(NID_MSG, "cbs dataCodingScheme: [%d]", dataCodingScheme);
838 SysLog(NID_MSG, "cbs languageType: [%s]", messageLanguage.GetPointer());
841 SysLog(NID_MSG, "cbs msg_id: [%d]", messgeId);
842 SysLog(NID_MSG, "cbs serialNumber: [%d]", serialNumber);
843 SysLog(NID_MSG, "cbs etwsNotifiation: [%d]", etwsNotifiation);
847 _SmsMmsCallbackHandler::IncomingWapPushMessageCallback(msg_handle_t hMsgHandle, const char* pHeader, const char* pBody, int bodyLength, void* pUserParam)
849 _SmsEvent* pSmsEvent = static_cast <_SmsEvent*>(pUserParam);
850 _SmsEventArg* pSmsEventArg = null;
851 String msgHeader(pHeader);
852 Tizen::Base::ByteBuffer msgBody;
853 msgBody.Construct(bodyLength);
854 msgBody.SetArray((byte*) pBody, 0, bodyLength);
855 msgBody.SetPosition(0);
857 SysLog(NID_MSG, "push msg body: [%s]", pBody);
858 SysLog(NID_MSG, "push msg header: [%s]", pHeader);
859 SysLog(NID_MSG, "push body length: [%d]", bodyLength);
863 pSmsEventArg = new (std::nothrow) _SmsEventArg(msgHeader, msgBody, _SMS_EVENT_TYPE_WAP_PUSH_RECEIVE_RESULT);
864 SysTryReturnVoidResult(NID_MSG, pSmsEventArg != null, E_OUT_OF_MEMORY, "memory allocation failed.");
865 pSmsEvent->Fire(*pSmsEventArg);
870 _SmsMmsCallbackHandler::GetCbsLanguageType(byte codingScheme)
872 String languageType(L"");
877 languageType = String(L"DE");
880 languageType = String(L"EN");
883 languageType = String(L"IT");
886 languageType = String(L"FR");
889 languageType = String(L"ES");
892 languageType = String(L"NL");
895 languageType = String(L"SV");
898 languageType = String(L"DA");
901 languageType = String(L"PT");
904 languageType = String(L"FI");
907 languageType = String(L"NO");
910 languageType = String(L"EL");
913 languageType = String(L"TR");
916 languageType = String(L"HU");
919 languageType = String(L"PL");
922 languageType = String(L"");
923 SysLog(NID_MSG, "Language unspecified.");
933 _SmsMmsCallbackHandler::ConvertException(int err) const
935 result r = E_SUCCESS;
943 case MSG_ERR_INVALID_PARAMETER:
944 case MSG_ERR_INVALID_MESSAGE:
945 case MSG_ERR_NULL_POINTER:
946 case MSG_ERR_NULL_MESSAGE:
950 case MSG_ERR_MEMORY_ERROR:
954 case MSG_ERR_SERVER_NOT_READY:
955 case MSG_ERR_TRANSPORT_ERROR:
956 case MSG_ERR_COMMUNICATION_ERROR:
957 r = E_NETWORK_UNAVAILABLE;
961 r = E_DEVICE_UNAVAILABLE;
964 case MSG_ERR_PLUGIN_TAPI_FAILED:
976 } } // Tizen::Messaging