2 // Tizen Web Device API
3 // Copyright (c) 2012 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.
19 #include <Commons/Exception.h>
20 #include "ReqReceiverMessage.h"
21 #include "Messaging.h"
22 #include "CallbackMgr.h"
23 #include "MsgServiceHandleMgr.h"
27 #include <msg_storage.h>
33 const char* EMPTY_ID = "0";
39 Sms::Sms(const string& id) :
44 LoggerD("m_id=" << getIdRef());
45 LoggerD("m_msgType=" << getMessageType());
47 if (getIdRef().empty()) {
50 readExistingMessage();
56 Sms::Sms(const std::string& id, const msg_struct_t msg_data) :
61 LoggerD("m_id=" << getIdRef());
62 LoggerD("m_msgType=" << getMessageType());
64 LoggerD("created msg_data : " << msg_data);
65 m_messageData = createNewCopyOfPLatformMsgWithAddressList(msg_data);
66 LoggerD("created m_messageData : " << m_messageData);
68 readConversationId(m_messageData);
69 readRecipientList(m_messageData);
70 readBody(m_messageData);
71 readFolder(m_messageData);
72 readDateTime(m_messageData);
73 readReadStatus(m_messageData);
74 readSize(m_messageData);
75 readMessageStatus(m_messageData);
76 // setMessageStatus(MESSAGE_STATUS_LOADED);
85 // release platform message structure
86 LoggerD("release m_messageData : " << m_messageData);
87 msg_release_struct(&m_messageData);
91 void Sms::update(bool draftsOnly)
93 LoggerD("updating m_id=" << getIdRef());
96 //error if platform message not exists
97 LoggerE("message can not be updated");
98 Throw(WrtDeviceApis::Commons::PlatformException);
101 //update all sms data
102 if (!draftsOnly || getCurrentFolder() == DRAFTBOX) {
106 updateSourceAddress();
111 void Sms::readAllData()
113 readExistingMessage();
116 void Sms::moveToFolder(const FolderType newFolder)
123 const msg_folder_id_t platfromFolderId =
124 Messaging::convertFolderToPlatform(newFolder);
126 //call platform api to move message to other folder
127 if (msg_move_msg_to_folder(MsgGetCommonHandle(), convertId(getId()),
128 platfromFolderId) != MSG_SUCCESS) {
129 Throw(WrtDeviceApis::Commons::PlatformException);
133 Catch(WrtDeviceApis::Commons::PlatformException) {
134 LoggerE("remove message error");
140 void Sms::moveToFolder(const std::string& newFolder)
146 void Sms::copyToFolder(const FolderType newFolder)
151 msg_message_t msg = msg_new_message();
155 MSG_SENDINGOPT_S option = { false, false, false };
156 option.option.smsSendOpt.bReplyPath = true;
157 // trying to get message from platform
159 msg_get_message(MsgGetCommonHandle(), convertId(getIdRef()), msg,
161 const msg_folder_id_t platfromFolderId =
162 Messaging::convertFolderToPlatform(newFolder);
163 // new id will me set (initialize to 0)
164 msg_set_message_id(msg, 0);
165 msg_set_folder_id(msg, platfromFolderId);
167 // trying to add message
168 int error = msg_add_message(MsgGetCommonHandle(), msg, &option);
169 if (error != MSG_SUCCESS) {
170 LoggerE("msg_add_message failed, error code=" << error);
171 Throw(WrtDeviceApis::Commons::PlatformException);
174 //releasing platform message structure
175 msg_release_message(&msg);
179 Catch(WrtDeviceApis::Commons::PlatformException) {
180 LoggerE("remove message error");
182 //releasing platform message structure
183 msg_release_message(&msg);
190 void Sms::copyToFolder(const std::string& newFolder)
198 LoggerD("sending message, id=" << getIdRef());
200 if(m_messageData == NULL)
202 //prepare for sending sms
205 MsgGetCommonHandle();
207 Catch(WrtDeviceApis::Commons::PlatformException)
209 LoggerD("getHandle failed");
210 Throw(WrtDeviceApis::Commons::PlatformException);
216 msg_struct_list_s *addr_list = NULL;
217 msg_struct_list_s *new_addr_list = NULL;
218 char strNumber[MAX_ADDRESS_VAL_LEN] = {0,};
223 msg_get_list_handle(m_messageData, MSG_MESSAGE_ADDR_LIST_STRUCT, (void **)&addr_list);
224 msg_get_int_value(m_messageData, MSG_MESSAGE_ID_INT, &tempIdInt);
226 nToCnt = addr_list->nCount;
227 LoggerD("nToCnt : " << nToCnt);
229 for (int i = 0; i < nToCnt; ++i)
231 msg_struct_t new_msg = createNewCopyOfPLatformMsg(m_messageData);
232 msg_set_int_value(new_msg, MSG_MESSAGE_ID_INT, tempIdInt);
234 msg_get_list_handle(new_msg, MSG_MESSAGE_ADDR_LIST_STRUCT, (void **)&new_addr_list);
236 msg_get_int_value(addr_list->msg_struct_info[i], MSG_ADDRESS_INFO_RECIPIENT_TYPE_INT, &tempInt);
237 LoggerD("RECIPIENT_TYPE : " << tempInt);
238 if(MSG_RECIPIENTS_TYPE_TO != tempInt)
244 msg_get_str_value(addr_list->msg_struct_info[i], MSG_ADDRESS_INFO_ADDRESS_VALUE_STR, strNumber, MAX_ADDRESS_VAL_LEN);
245 msg_set_str_value(new_addr_list->msg_struct_info[0], MSG_ADDRESS_INFO_ADDRESS_VALUE_STR, strNumber, MAX_ADDRESS_VAL_LEN);
246 msg_set_int_value(new_addr_list->msg_struct_info[0], MSG_ADDRESS_INFO_RECIPIENT_TYPE_INT, MSG_RECIPIENTS_TYPE_TO);
247 new_addr_list->nCount = 1;
249 setMessageStatus(MESSAGE_STATUS_SENDING);
251 req.queue.push(new_msg);
255 DPL::Mutex::ScopedLock lock(&m_mutex);
256 m_sendRequests.push(req);
261 LoggerD("sending method finished");
263 return 0; //sms handle is -1;
266 void Sms::sendingCallback(msg_struct_t sent_status)
269 // "sendingCallback callback received. Req id = " <<
270 // sent_status->reqId << " Status = " << (int)sent_status->status <<
271 // ", Recipient=" << getRecipient());
272 int status = MSG_NETWORK_SEND_FAIL;
274 msg_get_int_value(sent_status, MSG_SENT_STATUS_NETWORK_STATUS_INT, &status);
276 DPL::Mutex::ScopedLock lock(&m_mutex);
278 if (status != MSG_NETWORK_SEND_SUCCESS) {
279 m_sendRequests.front().failed = true; // TODO mutex
280 //send callback, error for recipient
281 setSendingStatusFailed(getRecipient());
282 setMessageStatus(MESSAGE_STATUS_FAILED);
284 setSendingStatusOk(getRecipient());
285 setMessageStatus(MESSAGE_STATUS_SENT);
288 msg_release_struct(¤tQueue().front());
289 currentQueue().pop();
291 //schedule another sub message send
295 void Sms::OnEventReceived(const int&)
302 FolderType Sms::toFolder(const std::string &folder)
304 if (folder == "INBOX") {
306 } else if (folder == "OUTBOX") {
308 } else if (folder == "SENTBOX") {
310 } else if (folder == "DRAFTBOX") {
313 ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Invalid folder");
316 void Sms::sendSubMessage()
320 DPL::Mutex::ScopedLock lock(&m_mutex);
322 // if current request queue gets empty, try next one
323 while (!m_sendRequests.empty()) {
324 // send as long as the sending fails until there are no more messages
325 for (msg_error_t err = MSG_ERR_UNKNOWN;
326 err != MSG_SUCCESS && !currentQueue().empty(); )
328 err = CallbackMgrSingleton::Instance().registerAndSend(
329 msg_sms_send_message,
330 currentQueue().front(),
332 LoggerI("Sending Message (submit request) result:" << err);
333 if (err != MSG_SUCCESS) {
334 LoggerE("Sending Message (submit request) failed!!! err=" << err);
335 msg_release_struct(¤tQueue().front());
336 currentQueue().pop();
337 m_sendRequests.front().failed = true;
338 //send callback, error for recipient
339 setSendingStatusFailed(getRecipient());
343 // empty queue -> notify about results
344 if (currentQueue().empty()) {
346 if (m_sendRequests.front().failed) {
347 setSendingStatusFailed();
349 setSendingStatusOk();
352 // this request is finished, try next one
353 m_sendRequests.pop();
360 void Sms::setSendingStatusOk(const string &recipient)
362 LoggerD("enter, success number is : " << recipient);
363 //success callback should be executed here
364 ReqReceiverMessage *requestReceiver = getRequestReceiver();
365 if (requestReceiver) {
366 EventMessagingServicePtr event = getMessagingServiceEvent();
367 event->setExceptionCode(WrtDeviceApis::Commons::ExceptionCodes::None);
368 event->m_successRecipients.push_back(recipient);
370 msg_struct_list_s *addr_list = NULL;
371 msg_get_list_handle(m_messageData, MSG_MESSAGE_ADDR_LIST_STRUCT, (void **)&addr_list);
373 if ( event->m_successRecipients.size() + event->m_failRecipients.size() == (unsigned int)addr_list->nCount)
375 requestReceiver->WrtDeviceApis::Commons::EventRequestReceiver< EventMessagingService >::ManualAnswer(event);
379 EventSendMessagePtr event = getSendMessageEvent();
380 event->setExceptionCode(WrtDeviceApis::Commons::ExceptionCodes::None);
381 event->m_successRecipients.push_back(recipient);
382 //LoggerD("total address size : " << msg_get_address_count(m_messageData) << " Status size : " << event->m_successRecipients.size() + event->m_failRecipients.size());
383 if ( event->m_successRecipients.size() + event->m_failRecipients.size() == (unsigned int)msg_get_address_count(m_messageData))
385 requestReceiver->WrtDeviceApis::Commons::EventRequestReceiver< EventSendMessage >::ManualAnswer(event);
392 void Sms::setSendingStatusFailed(const string &recipient)
394 LoggerD("enter, fail number is : " << recipient);
395 //error callback should be executed here
396 EventOnSendingFailedEmitterPtr emitter = getEmitter();
398 EventOnSendingFailedPtr event(new EventOnSendingFailed);
399 event->setError(EventOnSendingFailed::UNKNOWN); // TODO error codes
400 emitter->emit(event);
402 ReqReceiverMessage *requestReceiver = getRequestReceiver();
403 if (requestReceiver) {
404 LoggerE("calling JS error callback");
405 EventMessagingServicePtr event = getMessagingServiceEvent();
406 event->setExceptionCode(WrtDeviceApis::Commons::ExceptionCodes::UnknownException);
407 event->m_successRecipients.push_back(recipient);
408 msg_struct_list_s *addr_list = NULL;
409 msg_get_list_handle(m_messageData, MSG_MESSAGE_ADDR_LIST_STRUCT, (void **)&addr_list);
411 if ( event->m_successRecipients.size() + event->m_failRecipients.size() == (unsigned int)addr_list->nCount)
413 requestReceiver->WrtDeviceApis::Commons::EventRequestReceiver< EventMessagingService >::ManualAnswer(event);
424 // delete message from platform
425 if (msg_delete_message(MsgGetCommonHandle(),
426 convertId(getId())) != MSG_SUCCESS) {
427 LoggerE("delete message failed");
428 Throw(WrtDeviceApis::Commons::PlatformException);
430 LoggerD("message deleted succesfully");
434 Catch(WrtDeviceApis::Commons::PlatformException) {
435 LoggerE("remove message error");
440 void Sms::createNewMessage()
444 // release platform message if it was created previously
445 msg_release_struct(&m_messageData);
446 m_messageData = NULL;
448 // create new platform message
449 LoggerD("create messeage instance");
450 m_messageData = msg_create_struct(MSG_STRUCT_MESSAGE_INFO);
451 LoggerD("created message : " << m_messageData);
455 //default message initialization
460 setMessageStatus(MESSAGE_STATUS_DRAFT);
462 tm dateT = getDateTime();
463 msg_set_int_value(m_messageData, MSG_MESSAGE_DISPLAY_TIME_INT, (int)mktime(&dateT));
465 setMessageStatus(MESSAGE_STATUS_CREATED);
466 LoggerD("Message created successfully, msgId=" << getId());
468 Catch(WrtDeviceApis::Commons::PlatformException) {
469 msg_release_struct(&m_messageData);
470 m_messageData = NULL;
471 LoggerE("Problem with message creation, cleaning");
475 void Sms::readExistingMessage()
477 if (getIdRef().empty() || (EMPTY_ID == getIdRef())) {
478 ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Empty id.");
483 // release platform message if it was created previously
484 msg_release_struct(&m_messageData);
485 m_messageData = NULL;
487 msg_struct_t sendOpt = NULL;
490 // create new platform structure
491 m_messageData = msg_create_struct(MSG_STRUCT_MESSAGE_INFO);
492 sendOpt = msg_create_struct(MSG_STRUCT_SENDOPT);
494 msg_message_id_t l_id = convertId(getIdRef());
495 LoggerD("reading message id=" << l_id);
496 // trying to get message from platform
497 if (MSG_SUCCESS == msg_get_message(MsgGetCommonHandle(), l_id, m_messageData, sendOpt))
499 LoggerD("message found with msgId=" << getIdRef());
501 // read all mms dat to abstraction layer
502 readConversationId(m_messageData);
503 readRecipientList(m_messageData);
504 readBody(m_messageData);
505 readFolder(m_messageData);
506 readDateTime(m_messageData);
507 readReadStatus(m_messageData);
508 readSize(m_messageData);
509 readMessageStatus(m_messageData);
512 LoggerE("message not found with msgId=" << getIdRef());
514 Throw(WrtDeviceApis::Commons::PlatformException);
517 msg_release_struct(&sendOpt);
519 Catch(WrtDeviceApis::Commons::PlatformException) {
520 LoggerE("exception");
522 msg_release_struct(&sendOpt);
526 void Sms::updateBody()
528 // check if abstraction body value has been changed
532 LoggerI("updating platfoprm body");
534 // change body value in platform structure
535 if ( getBodyRef().length() > 0)
537 if (msg_set_str_value(m_messageData, MSG_MESSAGE_SMS_DATA_STR,
538 const_cast<char*>(getBodyRef().c_str()), getBodyRef().length()) != MSG_SUCCESS)
540 LoggerE("problem with update Body");
541 Throw(WrtDeviceApis::Commons::PlatformException);
543 // set flag as true - platform synchronized with abstraction
544 setBodyValidity(true);
546 // set flag as true - platform synchronized with abstraction
551 // check if abstraction recipient value has been changed
552 if (getToRecipients().isValid()) {
556 LoggerI("SMS updating platform recipients");
558 msg_struct_list_s *addr_list = NULL;
559 msg_get_list_handle(m_messageData, MSG_MESSAGE_ADDR_LIST_STRUCT, (void **)&addr_list);
560 int nToCnt = addr_list->nCount;
562 LogInfo("nToCnt size " << nToCnt);
566 for (int i = 0; i < nToCnt; i++) {
567 msg_set_str_value(addr_list->msg_struct_info[i], MSG_ADDRESS_INFO_ADDRESS_VALUE_STR, (char *)"", 0);
568 msg_set_str_value(addr_list->msg_struct_info[i], MSG_ADDRESS_INFO_DISPLAYNAME_STR, (char *)"", 0);
569 msg_set_int_value(addr_list->msg_struct_info[i], MSG_ADDRESS_INFO_ADDRESS_TYPE_INT, MSG_ADDRESS_TYPE_PLMN);
570 msg_set_int_value(addr_list->msg_struct_info[i], MSG_ADDRESS_INFO_RECIPIENT_TYPE_INT, MSG_RECIPIENTS_TYPE_UNKNOWN);
571 msg_set_int_value(addr_list->msg_struct_info[i], MSG_ADDRESS_INFO_CONTACT_ID_INT, 0);
574 addr_list->nCount = nToCnt;
577 vector<string> to = getToRecipients().getRecipients();
579 // update addresses in platform structure
582 LoggerI("updating to");
583 for (size_t i = 0; i < to.size(); i++)
585 string tmpAddr = to[i];
586 if(validatePhoneNumber(tmpAddr))
588 if (i >= MAX_TO_ADDRESS_CNT)
590 LoggerE("max number of recipient exceeded");
593 LoggerD("adding to[" << i << "]=" << to[i]);
595 msg_set_int_value(addr_list->msg_struct_info[i], MSG_ADDRESS_INFO_ADDRESS_TYPE_INT, MSG_ADDRESS_TYPE_PLMN);
597 if (msg_set_int_value(addr_list->msg_struct_info[i], MSG_ADDRESS_INFO_RECIPIENT_TYPE_INT,
598 MSG_RECIPIENTS_TYPE_TO) != MSG_SUCCESS)
600 LoggerE("problem with adding to address");
601 ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Problem with adding to address");
604 if(msg_set_str_value(addr_list->msg_struct_info[i], MSG_ADDRESS_INFO_ADDRESS_VALUE_STR,
605 const_cast<char*>(to[i].c_str()), to[i].size()) != MSG_SUCCESS)
607 LoggerE("problem with adding to address");
608 ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Problem with adding to address");
611 addr_list->nCount ++;
612 LoggerD("addr_list->nCount =" << addr_list->nCount);
616 LoggerE("wrong phone number format");
617 ThrowMsg(WrtDeviceApis::Commons::PlatformException, "wrong phone number format");
626 void Sms::updateFrom()
628 // check if abstraction from field value has been changed
629 if (getFromValidity()) {
630 // do not update if not changed
633 LoggerI("updating platform from");
637 // set flag as true - platform synchronized with abstraction
638 setFromValidity(true);
641 void Sms::updateSourceAddress()
643 // check if abstraction source address value has been changed
644 if (getSourceAddressValidity()) {
645 // do not update if not changed
648 LoggerI("updating platform source address");
652 // set flag as true - platform synchronized with abstraction
653 setSourceAddressValidity(true);
656 void Sms::updateReadStatus()
658 LoggerI("updating platform read status: " << isRead());
659 if (isReadStatusValid()) {
660 // do not update if not changed
663 if (MSG_SUCCESS != msg_set_bool_value(m_messageData, MSG_MESSAGE_READ_BOOL, isRead())) {
664 LoggerE("problem with setting subject");
665 ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Problem with setting subject");
667 setReadStatusValidity(true);
670 void Sms::updateIsRead()
672 LoggerD("updating m_id=" << getIdRef());
674 if (!m_messageData) {
675 //error if platform message not exists
676 LoggerE("message can not be updated");
677 Throw(WrtDeviceApis::Commons::PlatformException);
680 // check if abstraction from m_isReadChange value has been changed
681 if (isReadChangeStatusValid()) {
682 // do not update if not changed
688 if (this->getIdRef().empty()) {
689 LoggerE("existing msgId is zero, remove msg not done");
690 ThrowMsg(WrtDeviceApis::Commons::PlatformException,
691 "existing msgId is zero, remove msg not done");
695 msg_update_read_status(MsgGetCommonHandle(), convertId(getIdRef()), isReadChangeStatus()))
697 LoggerE("Failed to update isRead");
698 ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Failed to update isRead");
701 Catch(WrtDeviceApis::Commons::PlatformException) {
702 LoggerE("platform error occurs");
704 setisReadChangeStatusValidity(true);
708 void Sms::updateMessage()
710 LoggerD("updating m_id=" << getIdRef());
711 msg_error_t err = MSG_SUCCESS;
713 msg_struct_t msg = NULL;
714 msg_struct_t sendOpt = NULL;
716 if (!m_messageData) {
717 //error if platform message not exists
718 LoggerE("message can not be updated");
719 Throw(WrtDeviceApis::Commons::PlatformException);
725 msg = msg_create_struct(MSG_STRUCT_MESSAGE_INFO);
726 sendOpt = msg_create_struct(MSG_STRUCT_SENDOPT);
728 err = msg_get_message(MsgGetCommonHandle(), convertId(getIdRef()), msg, sendOpt);
730 if (err != MSG_SUCCESS)
732 LoggerE("Get Message Failed!");
733 ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Failed to update message");
736 if (this->getIdRef().empty()) {
737 LoggerE("existing msgId is zero, update msg not done");
738 ThrowMsg(WrtDeviceApis::Commons::PlatformException,
739 "existing msgId is zero, update msg not done");
744 if (MSG_SUCCESS != msg_update_message(MsgGetCommonHandle(), m_messageData, sendOpt))
746 LoggerE("Failed to update message");
747 ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Failed to update message");
749 msg_release_struct(&msg);
750 msg_release_struct(&sendOpt);
752 Catch(WrtDeviceApis::Commons::PlatformException) {
753 msg_release_struct(&msg);
754 msg_release_struct(&sendOpt);
755 LoggerE("platform error occurs");
759 void Sms::createSendMessage()
761 LoggerD("convert m_id= " << convertId(getIdRef()));
763 //prepare for add sms to draft folder
764 if (!m_messageData) {
765 //error if platform message not exists
766 LoggerE("message can not be updated");
767 Throw(WrtDeviceApis::Commons::PlatformException);
770 //update all sms data
771 if (getCurrentFolder() == DRAFTBOX) {
772 LoggerD("update all sms data");
776 updateSourceAddress();
782 // MSG_SENDINGOPT_S option = { false, false, false };
783 // option.option.smsSendOpt.bReplyPath = true;
784 // trying to get message from platform
786 // const msg_folder_id_t platfromFolderId = Messaging::convertFolderToPlatform(DRAFTBOX);
788 // msg_set_message_id(m_messageData, msgId);
789 // msg_set_folder_id(m_messageData, platfromFolderId);
790 // msg_set_network_status(m_messageData, MSG_NETWORK_NOT_SEND);
792 setId(convertId(msgId));
793 setFolderType(DRAFTBOX);
794 setMessageStatus(MESSAGE_STATUS_DRAFT);
796 Catch(WrtDeviceApis::Commons::PlatformException) {
797 LoggerE("remove message error");
799 //releasing platform message structure
800 msg_release_struct(&m_messageData);
801 m_messageData = NULL;
810 void Sms::addMessageToDraft()
812 LoggerD("convert m_id= " << convertId(getIdRef()));
813 msg_struct_t sendOpt = NULL;
815 //prepare for add sms to draft folder
816 if (!m_messageData) {
817 //error if platform message not exists
818 LoggerE("message can not be updated");
819 Throw(WrtDeviceApis::Commons::PlatformException);
822 //update all sms data
823 if (getCurrentFolder() == DRAFTBOX) {
824 LoggerD("update all sms data");
828 updateSourceAddress();
833 sendOpt = msg_create_struct(MSG_STRUCT_SENDOPT);
834 msg_set_bool_value(sendOpt, MSG_SEND_OPT_SETTING_BOOL, false);
836 // MSG_SENDINGOPT_S option = { false, false, false };
837 // option.option.smsSendOpt.bReplyPath = true;
838 // trying to get message from platform
840 // const msg_folder_id_t platfromFolderId = Messaging::convertFolderToPlatform(DRAFTBOX);
842 // msg_set_message_id(m_messageData, 0);
843 // msg_set_folder_id(m_messageData, platfromFolderId);
844 // msg_set_network_status(m_messageData, MSG_NETWORK_NOT_SEND);
846 // trying to add message
847 int ret = msg_add_message(MsgGetCommonHandle(), m_messageData, sendOpt);
848 if (ret < MSG_SUCCESS) {
849 LoggerE("msg_add_message failed, error code=" << ret);
850 Throw(WrtDeviceApis::Commons::PlatformException);
857 LoggerD("Message ID : " << msgId);
860 LoggerD("Message ID is invailded ");
861 Throw(WrtDeviceApis::Commons::PlatformException);
864 msg_set_int_value(m_messageData, MSG_MESSAGE_ID_INT, msgId);
866 setId(convertId(msgId));
867 setFolderType(DRAFTBOX);
868 setMessageStatus(MESSAGE_STATUS_DRAFT);
869 LoggerD("Message Status " << getMessageStatus());
872 if ( folder_list_view.nCount )
873 msg_release_list_struct(&folder_list_view);
875 msg_release_struct(&sendOpt);
878 Catch(WrtDeviceApis::Commons::PlatformException) {
879 LoggerE("remove message error");
881 //releasing platform message structure
882 msg_release_struct(&m_messageData);
883 m_messageData = NULL;
884 msg_release_struct(&sendOpt);
891 void Sms::readConversationId(msg_struct_t& messageData)
894 msg_get_int_value(messageData, MSG_MESSAGE_THREAD_ID_INT, &tempInt);
895 LoggerD("conversationID : " <<tempInt);
899 void Sms::readRecipientList(msg_struct_t& messageData)
901 std::string phoneNumber;
902 // int recipientCount = msg_get_address_count(messageData);
903 // LoggerD("Recipient count " << recipientCount);
905 msg_struct_list_s *addr_list;
906 msg_get_list_handle(messageData, MSG_MESSAGE_ADDR_LIST_STRUCT, (void **)&addr_list);
909 char strNumber[MAX_ADDRESS_VAL_LEN] = {0,};
911 int recipientCount = addr_list->nCount;
912 LoggerD("Recipient count " << recipientCount);
915 for (int i = 0; i < recipientCount; ++i)
917 msg_get_int_value(messageData, MSG_MESSAGE_DIRECTION_INT, &tempInt);
920 if (MSG_DIRECTION_TYPE_MT == type)
922 msg_struct_t addr_info = addr_list->msg_struct_info[i];
923 msg_get_str_value(addr_info, MSG_ADDRESS_INFO_ADDRESS_VALUE_STR, strNumber, MAX_ADDRESS_VAL_LEN);
924 phoneNumber = strNumber;
926 if (validatePhoneNumber(phoneNumber))
928 setSourceAddress(phoneNumber);
929 setFrom(phoneNumber);
931 LoggerD("MT number: " << phoneNumber);
933 else if (MSG_DIRECTION_TYPE_MO == type)
935 msg_struct_t addr_info = addr_list->msg_struct_info[i];
936 msg_get_str_value(addr_info, MSG_ADDRESS_INFO_ADDRESS_VALUE_STR, strNumber, MAX_ADDRESS_VAL_LEN);
937 LoggerD("MO number: " << strNumber);
938 appendToRecipients(strNumber);
942 LoggerE("Wrong type of recipient");
943 ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Wrong type of recipient");
948 void Sms::readBody(msg_struct_t& messageData)
950 //set abstraction body value
952 msg_get_int_value(messageData, MSG_MESSAGE_DATA_SIZE_INT, &tempInt);
953 LoggerE("body Size : " <<tempInt);
954 char msgText[tempInt+1];
955 memset(msgText, 0, tempInt+1);
956 msg_get_str_value(messageData, MSG_MESSAGE_SMS_DATA_STR, msgText, tempInt);
957 // setBody(msg_sms_get_message_body(messageData));
958 LoggerE("body : " <<msgText);
962 void Sms::readFolder(msg_struct_t& messageData)
965 msg_get_int_value(messageData, MSG_MESSAGE_FOLDER_ID_INT, &tempInt);
966 LoggerE("Folder : " <<tempInt);
970 setFolderType(INBOX);
973 setFolderType(OUTBOX);
976 setFolderType(SENTBOX);
979 setFolderType(DRAFTBOX);
982 LoggerE("Wrong folder id");
983 ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Unsupported folder id.");
987 void Sms::readMessageStatus(msg_struct_t& messageData)
990 msg_get_int_value(messageData, MSG_MESSAGE_FOLDER_ID_INT, &tempValue);
991 LoggerD("readMessageStatus folder : " << tempValue);
995 setMessageStatus(MESSAGE_STATUS_LOADED);
998 setMessageStatus(MESSAGE_STATUS_SENDING);
1000 case MSG_SENTBOX_ID:
1001 setMessageStatus(MESSAGE_STATUS_SENT);
1004 setMessageStatus(MESSAGE_STATUS_DRAFT);
1007 setMessageStatus(MESSAGE_STATUS_LOADED);
1013 void Sms::readDateTime(msg_struct_t& messageData)
1015 // tm* time = localtime(msg_get_time(messageData));
1016 // tm dateT = getDateTime();
1018 msg_get_int_value(messageData, MSG_MESSAGE_DISPLAY_TIME_INT, &tempInt);
1020 LoggerE("readDateTime : " <<tempInt);
1022 tm* time = localtime((time_t*)&tempInt);
1024 LoggerE("localtime failed");
1025 Throw(WrtDeviceApis::Commons::PlatformException);
1030 void Sms::readReadStatus(msg_struct_t& messageData)
1034 msg_get_bool_value(messageData, MSG_MESSAGE_READ_BOOL, &tempBool);
1035 LoggerE("readReadStatus : " <<tempBool);
1036 setReadStatus(tempBool);
1039 void Sms::readSize(msg_struct_t& messageData)
1042 msg_get_int_value(messageData, MSG_MESSAGE_DATA_SIZE_INT, &tempInt);
1043 // setSize(msg_get_message_body_size(messageData));
1044 LoggerE("readSize : " <<tempInt);
1048 msg_struct_t Sms::createNewCopyOfPLatformMsg(const msg_struct_t src) const
1053 msg_struct_t msg = msg_create_struct(MSG_STRUCT_MESSAGE_INFO);
1055 msg_get_int_value(src, MSG_MESSAGE_STORAGE_ID_INT, &tempInt);
1056 msg_set_int_value(msg, MSG_MESSAGE_STORAGE_ID_INT, tempInt);
1058 msg_get_int_value(src, MSG_MESSAGE_FOLDER_ID_INT, &tempInt);
1059 msg_set_int_value(msg, MSG_MESSAGE_FOLDER_ID_INT, tempInt);
1061 msg_get_int_value(src, MSG_MESSAGE_DATA_SIZE_INT, &tempInt);
1062 char tempStr[tempInt+1];
1063 memset(tempStr, 0, tempInt+1);
1065 msg_get_str_value(src, MSG_MESSAGE_SMS_DATA_STR, tempStr, tempInt);
1066 msg_set_str_value(msg, MSG_MESSAGE_SMS_DATA_STR, tempStr, strlen(tempStr));
1068 msg_get_int_value(src, MSG_MESSAGE_DISPLAY_TIME_INT, &tempInt);
1069 msg_set_int_value(msg, MSG_MESSAGE_DISPLAY_TIME_INT, tempInt);
1071 // msg_set_network_status(msg, msg_get_network_status(src));
1072 msg_get_int_value(src, MSG_MESSAGE_NETWORK_STATUS_INT, &tempInt);
1073 msg_set_int_value(msg, MSG_MESSAGE_NETWORK_STATUS_INT, tempInt);
1075 // msg_set_encode_type(msg, msg_get_encode_type(src));
1076 msg_get_int_value(src, MSG_MESSAGE_ENCODE_TYPE_INT, &tempInt);
1077 msg_set_int_value(msg, MSG_MESSAGE_ENCODE_TYPE_INT, tempInt);
1079 // msg_set_read_status(msg, msg_is_read(src));
1080 msg_get_bool_value(src, MSG_MESSAGE_READ_BOOL, &tempBool);
1081 msg_set_bool_value(msg, MSG_MESSAGE_READ_BOOL, tempBool);
1083 // msg_set_protect_status(msg, msg_is_protected(src));
1084 msg_get_bool_value(src, MSG_MESSAGE_PROTECTED_BOOL, &tempBool);
1085 msg_set_bool_value(msg, MSG_MESSAGE_PROTECTED_BOOL, tempBool);
1087 // msg_set_priority_info(msg, msg_get_priority_info(src));
1088 msg_get_int_value(src, MSG_MESSAGE_PRIORITY_INT, &tempInt);
1089 msg_set_int_value(msg, MSG_MESSAGE_PRIORITY_INT, tempInt);
1091 // msg_set_direction_info(msg, msg_get_direction_info(src));
1092 msg_get_int_value(src, MSG_MESSAGE_DIRECTION_INT, &tempInt);
1093 msg_set_int_value(msg, MSG_MESSAGE_DIRECTION_INT, tempInt);
1095 // msg_set_port(msg, msg_get_dest_port(src), msg_get_src_port(src));
1096 msg_get_int_value(src, MSG_MESSAGE_DEST_PORT_INT, &tempInt);
1097 msg_set_int_value(msg, MSG_MESSAGE_DEST_PORT_INT, tempInt);
1098 msg_get_int_value(src, MSG_MESSAGE_SRC_PORT_INT, &tempInt);
1099 msg_set_int_value(msg, MSG_MESSAGE_SRC_PORT_INT, tempInt);
1104 msg_struct_t Sms::createNewCopyOfPLatformMsgWithAddressList(const msg_struct_t src) const
1108 msg_struct_list_s *addr_list;
1109 msg_struct_list_s *new_addr_list;
1111 msg_struct_t msg = msg_create_struct(MSG_STRUCT_MESSAGE_INFO);
1113 msg_get_int_value(src, MSG_MESSAGE_STORAGE_ID_INT, &tempInt);
1114 msg_set_int_value(msg, MSG_MESSAGE_STORAGE_ID_INT, tempInt);
1116 msg_get_int_value(src, MSG_MESSAGE_FOLDER_ID_INT, &tempInt);
1117 msg_set_int_value(msg, MSG_MESSAGE_FOLDER_ID_INT, tempInt);
1119 msg_get_int_value(src, MSG_MESSAGE_DATA_SIZE_INT, &tempInt);
1120 char tempStr[tempInt+1];
1121 memset(tempStr, 0, tempInt+1);
1123 msg_get_str_value(src, MSG_MESSAGE_SMS_DATA_STR, tempStr, tempInt);
1124 msg_set_str_value(msg, MSG_MESSAGE_SMS_DATA_STR, tempStr, strlen(tempStr));
1126 msg_get_int_value(src, MSG_MESSAGE_DISPLAY_TIME_INT, &tempInt);
1127 msg_set_int_value(msg, MSG_MESSAGE_DISPLAY_TIME_INT, tempInt);
1129 // msg_set_network_status(msg, msg_get_network_status(src));
1130 msg_get_int_value(src, MSG_MESSAGE_NETWORK_STATUS_INT, &tempInt);
1131 msg_set_int_value(msg, MSG_MESSAGE_NETWORK_STATUS_INT, tempInt);
1133 // msg_set_encode_type(msg, msg_get_encode_type(src));
1134 msg_get_int_value(src, MSG_MESSAGE_ENCODE_TYPE_INT, &tempInt);
1135 msg_set_int_value(msg, MSG_MESSAGE_ENCODE_TYPE_INT, tempInt);
1137 // msg_set_read_status(msg, msg_is_read(src));
1138 msg_get_bool_value(src, MSG_MESSAGE_READ_BOOL, &tempBool);
1139 msg_set_bool_value(msg, MSG_MESSAGE_READ_BOOL, tempBool);
1141 // msg_set_protect_status(msg, msg_is_protected(src));
1142 msg_get_bool_value(src, MSG_MESSAGE_PROTECTED_BOOL, &tempBool);
1143 msg_set_bool_value(msg, MSG_MESSAGE_PROTECTED_BOOL, tempBool);
1145 // msg_set_priority_info(msg, msg_get_priority_info(src));
1146 msg_get_int_value(src, MSG_MESSAGE_PRIORITY_INT, &tempInt);
1147 msg_set_int_value(msg, MSG_MESSAGE_PRIORITY_INT, tempInt);
1149 // msg_set_direction_info(msg, msg_get_direction_info(src));
1150 msg_get_int_value(src, MSG_MESSAGE_DIRECTION_INT, &tempInt);
1151 msg_set_int_value(msg, MSG_MESSAGE_DIRECTION_INT, tempInt);
1153 // msg_set_port(msg, msg_get_dest_port(src), msg_get_src_port(src));
1154 msg_get_int_value(src, MSG_MESSAGE_DEST_PORT_INT, &tempInt);
1155 msg_set_int_value(msg, MSG_MESSAGE_DEST_PORT_INT, tempInt);
1156 msg_get_int_value(src, MSG_MESSAGE_SRC_PORT_INT, &tempInt);
1157 msg_set_int_value(msg, MSG_MESSAGE_SRC_PORT_INT, tempInt);
1160 msg_get_list_handle(src, MSG_MESSAGE_ADDR_LIST_STRUCT, (void **)&addr_list);
1161 msg_get_list_handle(msg, MSG_MESSAGE_ADDR_LIST_STRUCT, (void **)&new_addr_list);
1163 new_addr_list->nCount = addr_list->nCount;
1165 for(int i=0; i<addr_list->nCount; i++)
1167 msg_struct_t addr_info = NULL;
1168 msg_struct_t new_addr_info = NULL;
1169 char addr_value[MAX_ADDRESS_VAL_LEN] = {0,};
1171 //get original address
1172 addr_info = addr_list->msg_struct_info[i];
1173 msg_get_str_value(addr_info, MSG_ADDRESS_INFO_ADDRESS_VALUE_STR, addr_value, MAX_ADDRESS_VAL_LEN);
1174 msg_get_int_value(addr_info, MSG_ADDRESS_INFO_RECIPIENT_TYPE_INT, &tempInt);
1176 //copy original address
1177 new_addr_info = new_addr_list->msg_struct_info[i];
1178 msg_set_str_value(new_addr_info, MSG_ADDRESS_INFO_ADDRESS_VALUE_STR, addr_value, MAX_ADDRESS_VAL_LEN);
1179 msg_set_int_value(new_addr_info, MSG_ADDRESS_INFO_RECIPIENT_TYPE_INT, tempInt);