2 * Copyright (c) 2011 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.
22 * @author Pawel Misiak (p.misiak@samsung.com)
27 #include <dpl/log/log.h>
28 #include <Commons/Exception.h>
29 #include <API/Messaging/ReqReceiverMessage.h>
30 #include "Messaging.h"
31 #include "CallbackMgr.h"
32 #include "MsgServiceHandleMgr.h"
35 #include <msg_storage.h>
39 using namespace TizenApis::Api::Messaging;
42 const char* EMPTY_ID = "0";
49 Sms::Sms(const string& id) :
54 LogDebug("m_id=" << getIdRef());
55 LogDebug("m_msgType=" << getMessageType());
57 if (getIdRef().empty()) {
60 readExistingMessage();
66 Sms::Sms(const std::string& id, const msg_struct_t msg_data) :
68 m_messageData(msg_data)
71 LogDebug("m_id=" << getIdRef());
72 LogDebug("m_msgType=" << getMessageType());
73 readRecipientList(m_messageData);
74 readBody(m_messageData);
75 readFolder(m_messageData);
76 readDateTime(m_messageData);
77 readReadStatus(m_messageData);
78 readSize(m_messageData);
79 setMessageStatus(Api::Messaging::MESSAGE_STATUS_LOADED);
89 // release platform message structure
90 msg_release_struct(&m_messageData);
94 void Sms::update(bool draftsOnly)
96 LogDebug("updating m_id=" << getIdRef());
99 //error if platform message not exists
100 LogError("message can not be updated");
101 Throw(WrtDeviceApis::Commons::PlatformException);
104 //update all sms data
105 if (!draftsOnly || getCurrentFolder() == Api::Messaging::DRAFTBOX) {
109 updateSourceAddress();
114 void Sms::readAllData()
116 readExistingMessage();
119 void Sms::moveToFolder(const FolderType newFolder)
126 const msg_folder_id_t platfromFolderId =
127 Messaging::convertFolderToPlatform(newFolder);
129 //call platform api to move message to other folder
130 if (msg_move_msg_to_folder(MsgGetCommonHandle(), convertId(getId()),
131 platfromFolderId) != MSG_SUCCESS) {
132 Throw(WrtDeviceApis::Commons::PlatformException);
136 Catch(WrtDeviceApis::Commons::PlatformException) {
137 LogError("remove message error");
143 void Sms::moveToFolder(const std::string& newFolder)
149 void Sms::copyToFolder(const FolderType newFolder)
154 msg_message_t msg = msg_new_message();
158 MSG_SENDINGOPT_S option = { false, false, false };
159 option.option.smsSendOpt.bReplyPath = true;
160 // trying to get message from platform
162 msg_get_message(MsgGetCommonHandle(), convertId(getIdRef()), msg,
164 const msg_folder_id_t platfromFolderId =
165 Messaging::convertFolderToPlatform(newFolder);
166 // new id will me set (initialize to 0)
167 msg_set_message_id(msg, 0);
168 msg_set_folder_id(msg, platfromFolderId);
170 // trying to add message
171 int error = msg_add_message(MsgGetCommonHandle(), msg, &option);
172 if (error != MSG_SUCCESS) {
173 LogError("msg_add_message failed, error code=" << error);
174 Throw(WrtDeviceApis::Commons::PlatformException);
177 //releasing platform message structure
178 msg_release_message(&msg);
182 Catch(WrtDeviceApis::Commons::PlatformException) {
183 LogError("remove message error");
185 //releasing platform message structure
186 msg_release_message(&msg);
193 void Sms::copyToFolder(const std::string& newFolder)
201 LogDebug("sending message, id=" << getIdRef());
203 if(m_messageData == NULL)
205 //prepare for sending sms
208 MsgGetCommonHandle();
210 Catch(WrtDeviceApis::Commons::PlatformException)
212 LogDebug("getHandle failed");
213 Throw(WrtDeviceApis::Commons::PlatformException);
219 msg_struct_list_s *addr_list = NULL;
220 msg_struct_list_s *new_addr_list = NULL;
221 char strNumber[MAX_ADDRESS_VAL_LEN] = {0,};
226 msg_get_list_handle(m_messageData, MSG_MESSAGE_ADDR_LIST_STRUCT, (void **)&addr_list);
227 msg_get_int_value(m_messageData, MSG_MESSAGE_ID_INT, &tempIdInt);
229 nToCnt = addr_list->nCount;
230 LogDebug("nToCnt : " << nToCnt);
232 for (int i = 0; i < nToCnt; ++i)
234 msg_struct_t new_msg = createNewCopyOfPLatformMsg(m_messageData);
235 msg_set_int_value(new_msg, MSG_MESSAGE_ID_INT, tempIdInt);
237 msg_get_list_handle(new_msg, MSG_MESSAGE_ADDR_LIST_STRUCT, (void **)&new_addr_list);
239 msg_get_int_value(addr_list->msg_struct_info[i], MSG_ADDRESS_INFO_RECIPIENT_TYPE_INT, &tempInt);
240 LogDebug("RECIPIENT_TYPE : " << tempInt);
241 if(MSG_RECIPIENTS_TYPE_TO != tempInt)
247 msg_get_str_value(addr_list->msg_struct_info[i], MSG_ADDRESS_INFO_ADDRESS_VALUE_STR, strNumber, MAX_ADDRESS_VAL_LEN);
248 msg_set_str_value(new_addr_list->msg_struct_info[0], MSG_ADDRESS_INFO_ADDRESS_VALUE_STR, strNumber, MAX_ADDRESS_VAL_LEN);
249 msg_set_int_value(new_addr_list->msg_struct_info[0], MSG_ADDRESS_INFO_RECIPIENT_TYPE_INT, MSG_RECIPIENTS_TYPE_TO);
250 new_addr_list->nCount = 1;
252 setMessageStatus(MESSAGE_STATUS_SENDING);
254 req.queue.push(new_msg);
258 DPL::Mutex::ScopedLock lock(&m_mutex);
259 m_sendRequests.push(req);
264 LogDebug("sending method finished");
266 return 0; //sms handle is -1;
269 void Sms::sendingCallback(msg_struct_t sent_status)
272 // "sendingCallback callback received. Req id = " <<
273 // sent_status->reqId << " Status = " << (int)sent_status->status <<
274 // ", Recipient=" << getRecipient());
275 int status = MSG_NETWORK_SEND_FAIL;
277 msg_get_int_value(sent_status, MSG_SENT_STATUS_NETWORK_STATUS_INT, &status);
279 DPL::Mutex::ScopedLock lock(&m_mutex);
281 if (status != MSG_NETWORK_SEND_SUCCESS) {
282 m_sendRequests.front().failed = true; // TODO mutex
283 //send callback, error for recipient
284 setSendingStatusFailed(getRecipient());
285 setMessageStatus(MESSAGE_STATUS_FAILED);
287 setSendingStatusOk(getRecipient());
288 setMessageStatus(MESSAGE_STATUS_SENT);
291 msg_release_struct(¤tQueue().front());
292 currentQueue().pop();
294 //schedule another sub message send
298 void Sms::OnEventReceived(const int&)
305 Api::Messaging::FolderType Sms::toFolder(const std::string &folder)
307 if (folder == "INBOX") {
309 } else if (folder == "OUTBOX") {
311 } else if (folder == "SENTBOX") {
313 } else if (folder == "DRAFTBOX") {
316 ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Invalid folder");
319 void Sms::sendSubMessage()
323 DPL::Mutex::ScopedLock lock(&m_mutex);
325 // if current request queue gets empty, try next one
326 while (!m_sendRequests.empty()) {
327 // send as long as the sending fails until there are no more messages
328 for (msg_error_t err = MSG_ERR_UNKNOWN;
329 err != MSG_SUCCESS && !currentQueue().empty(); )
331 err = CallbackMgrSingleton::Instance().registerAndSend(
332 msg_sms_send_message,
333 currentQueue().front(),
335 LogInfo("Sending Message (submit request) result:" << err);
336 if (err != MSG_SUCCESS) {
337 LogError("Sending Message (submit request) failed!!! err=" << err);
338 msg_release_struct(¤tQueue().front());
339 currentQueue().pop();
340 m_sendRequests.front().failed = true;
341 //send callback, error for recipient
342 setSendingStatusFailed(getRecipient());
346 // empty queue -> notify about results
347 if (currentQueue().empty()) {
349 if (m_sendRequests.front().failed) {
350 setSendingStatusFailed();
352 setSendingStatusOk();
355 // this request is finished, try next one
356 m_sendRequests.pop();
363 void Sms::setSendingStatusOk(const string &recipient)
365 LogDebug("enter, success number is : " << recipient);
366 //success callback should be executed here
367 ReqReceiverMessage *requestReceiver = getRequestReceiver();
368 if (requestReceiver) {
369 EventMessagingServicePtr event = getMessagingServiceEvent();
370 event->setExceptionCode(WrtDeviceApis::Commons::ExceptionCodes::None);
371 event->m_successRecipients.push_back(recipient);
373 msg_struct_list_s *addr_list = NULL;
374 msg_get_list_handle(m_messageData, MSG_MESSAGE_ADDR_LIST_STRUCT, (void **)&addr_list);
376 if ( event->m_successRecipients.size() + event->m_failRecipients.size() == (unsigned int)addr_list->nCount)
378 requestReceiver->WrtDeviceApis::Commons::EventRequestReceiver< EventMessagingService >::ManualAnswer(event);
382 EventSendMessagePtr event = getSendMessageEvent();
383 event->setExceptionCode(WrtDeviceApis::Commons::ExceptionCodes::None);
384 event->m_successRecipients.push_back(recipient);
385 //LogDebug("total address size : " << msg_get_address_count(m_messageData) << " Status size : " << event->m_successRecipients.size() + event->m_failRecipients.size());
386 if ( event->m_successRecipients.size() + event->m_failRecipients.size() == (unsigned int)msg_get_address_count(m_messageData))
388 requestReceiver->WrtDeviceApis::Commons::EventRequestReceiver< EventSendMessage >::ManualAnswer(event);
395 void Sms::setSendingStatusFailed(const string &recipient)
397 LogDebug("enter, fail number is : " << recipient);
398 //error callback should be executed here
399 EventOnSendingFailedEmitterPtr emitter = getEmitter();
401 EventOnSendingFailedPtr event(new EventOnSendingFailed);
402 event->setError(EventOnSendingFailed::UNKNOWN); // TODO error codes
403 emitter->emit(event);
405 ReqReceiverMessage *requestReceiver = getRequestReceiver();
406 if (requestReceiver) {
407 LogError("calling JS error callback");
408 EventMessagingServicePtr event = getMessagingServiceEvent();
409 event->setExceptionCode(WrtDeviceApis::Commons::ExceptionCodes::UnknownException);
410 event->m_successRecipients.push_back(recipient);
411 msg_struct_list_s *addr_list = NULL;
412 msg_get_list_handle(m_messageData, MSG_MESSAGE_ADDR_LIST_STRUCT, (void **)&addr_list);
414 if ( event->m_successRecipients.size() + event->m_failRecipients.size() == (unsigned int)addr_list->nCount)
416 requestReceiver->WrtDeviceApis::Commons::EventRequestReceiver< EventMessagingService >::ManualAnswer(event);
427 // delete message from platform
428 if (msg_delete_message(MsgGetCommonHandle(),
429 convertId(getId())) != MSG_SUCCESS) {
430 LogError("delete message failed");
431 Throw(WrtDeviceApis::Commons::PlatformException);
433 LogDebug("message deleted succesfully");
437 Catch(WrtDeviceApis::Commons::PlatformException) {
438 LogError("remove message error");
443 void Sms::createNewMessage()
447 // release platform message if it was created previously
448 msg_release_struct(&m_messageData);
449 m_messageData = NULL;
451 // create new platform message
452 LogDebug("create messeage instance");
453 m_messageData = msg_create_struct(MSG_STRUCT_MESSAGE_INFO);
454 LogDebug("created message : " << m_messageData);
458 //default message initialization
463 setMessageStatus(Api::Messaging::MESSAGE_STATUS_DRAFT);
465 tm dateT = getDateTime();
466 msg_set_int_value(m_messageData, MSG_MESSAGE_DISPLAY_TIME_INT, (int)mktime(&dateT));
468 setMessageStatus(Api::Messaging::MESSAGE_STATUS_CREATED);
469 LogDebug("Message created successfully, msgId=" << getId());
471 Catch(WrtDeviceApis::Commons::PlatformException) {
472 msg_release_struct(&m_messageData);
473 LogError("Problem with message creation, cleaning");
477 void Sms::readExistingMessage()
479 if (getIdRef().empty() || (EMPTY_ID == getIdRef())) {
480 ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Empty id.");
484 msg_release_struct(&m_messageData);
485 m_messageData = NULL;
486 msg_struct_t sendOpt = NULL;
489 // create new platform structure
490 m_messageData = msg_create_struct(MSG_STRUCT_MESSAGE_INFO);
491 sendOpt = msg_create_struct(MSG_STRUCT_SENDOPT);
493 msg_message_id_t l_id = convertId(getIdRef());
494 LogDebug("reading message id=" << l_id);
495 // trying to get message from platform
496 if (MSG_SUCCESS == msg_get_message(MsgGetCommonHandle(), l_id, m_messageData, sendOpt))
498 LogDebug("message found with msgId=" << getIdRef());
500 // read all mms dat to abstraction layer
501 readRecipientList(m_messageData);
502 readBody(m_messageData);
503 readFolder(m_messageData);
504 readDateTime(m_messageData);
505 readReadStatus(m_messageData);
506 readSize(m_messageData);
507 setMessageStatus(Api::Messaging::MESSAGE_STATUS_LOADED);
510 LogError("message not found with msgId=" << getIdRef());
512 Throw(WrtDeviceApis::Commons::PlatformException);
515 msg_release_struct(&sendOpt);
517 Catch(WrtDeviceApis::Commons::PlatformException) {
518 LogError("exception");
520 msg_release_struct(&sendOpt);
524 void Sms::updateBody()
526 // check if abstraction body value has been changed
530 LogInfo("updating platfoprm body");
532 // change body value in platform structure
533 if ( getBodyRef().length() > 0)
535 if (msg_set_str_value(m_messageData, MSG_MESSAGE_SMS_DATA_STR,
536 const_cast<char*>(getBodyRef().c_str()), getBodyRef().length()) != MSG_SUCCESS)
538 LogError("problem with update Body");
539 Throw(WrtDeviceApis::Commons::PlatformException);
541 // set flag as true - platform synchronized with abstraction
542 setBodyValidity(true);
544 // set flag as true - platform synchronized with abstraction
549 // check if abstraction recipient value has been changed
550 if (getToRecipients().isValid()) {
554 LogInfo("SMS updating platform recipients");
556 // reset addresses in platform structure
557 // msg_reset_address(m_messageData);
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, "", 0);
568 msg_set_str_value(addr_list->msg_struct_info[i], MSG_ADDRESS_INFO_DISPLAYNAME_STR, "", 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();
578 // update addresses in platform structure
581 LogInfo("updating to");
582 for (size_t i = 0; i < to.size(); i++)
584 string tmpAddr = to[i];
585 if(validatePhoneNumber(tmpAddr))
587 if (i >= MAX_TO_ADDRESS_CNT)
589 LogError("max number of recipient exceeded");
592 LogDebug("adding to[" << i << "]=" << to[i]);
594 if (msg_set_int_value(addr_list->msg_struct_info[i], MSG_ADDRESS_INFO_RECIPIENT_TYPE_INT,
595 MSG_RECIPIENTS_TYPE_TO) != MSG_SUCCESS)
597 LogError("problem with adding to address");
598 ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Problem with adding to address");
601 if(msg_set_str_value(addr_list->msg_struct_info[i], MSG_ADDRESS_INFO_ADDRESS_VALUE_STR,
602 const_cast<char*>(to[i].c_str()), to[i].size()) != MSG_SUCCESS)
604 LogError("problem with adding to address");
605 ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Problem with adding to address");
608 addr_list->nCount ++;
609 LogDebug("addr_list->nCount =" << addr_list->nCount);
613 LogError("wrong phone number format");
622 void Sms::updateFrom()
624 // check if abstraction from field value has been changed
625 if (getFromValidity()) {
626 // do not update if not changed
629 LogInfo("updating platform from");
633 // set flag as true - platform synchronized with abstraction
634 setFromValidity(true);
637 void Sms::updateSourceAddress()
639 // check if abstraction source address value has been changed
640 if (getSourceAddressValidity()) {
641 // do not update if not changed
644 LogInfo("updating platform source address");
648 // set flag as true - platform synchronized with abstraction
649 setSourceAddressValidity(true);
652 void Sms::updateReadStatus()
654 LogInfo("updating platform read status: " << isRead());
655 if (isReadStatusValid()) {
656 // do not update if not changed
659 if (MSG_SUCCESS != msg_set_bool_value(m_messageData, MSG_MESSAGE_READ_BOOL, isRead())) {
660 LogError("problem with setting subject");
661 ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Problem with setting subject");
663 setReadStatusValidity(true);
666 void Sms::updateIsRead()
668 LogDebug("updating m_id=" << getIdRef());
670 if (!m_messageData) {
671 //error if platform message not exists
672 LogError("message can not be updated");
673 Throw(WrtDeviceApis::Commons::PlatformException);
676 // check if abstraction from m_isReadChange value has been changed
677 if (isReadChangeStatusValid()) {
678 // do not update if not changed
684 if (this->getIdRef().empty()) {
685 LogError("existing msgId is zero, remove msg not done");
686 ThrowMsg(WrtDeviceApis::Commons::PlatformException,
687 "existing msgId is zero, remove msg not done");
691 msg_update_read_status(MsgGetCommonHandle(), convertId(getIdRef()), isReadChangeStatus()))
693 LogError("Failed to update isRead");
694 ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Failed to update isRead");
697 Catch(WrtDeviceApis::Commons::PlatformException) {
698 LogError("platform error occurs");
700 setisReadChangeStatusValidity(true);
704 void Sms::updateMessage()
706 LogDebug("updating m_id=" << getIdRef());
707 msg_error_t err = MSG_SUCCESS;
709 msg_struct_t msg = NULL;
710 msg_struct_t sendOpt = NULL;
712 if (!m_messageData) {
713 //error if platform message not exists
714 LogError("message can not be updated");
715 Throw(WrtDeviceApis::Commons::PlatformException);
721 msg = msg_create_struct(MSG_STRUCT_MESSAGE_INFO);
722 sendOpt = msg_create_struct(MSG_STRUCT_SENDOPT);
724 err = msg_get_message(MsgGetCommonHandle(), convertId(getIdRef()), msg, sendOpt);
726 if (err != MSG_SUCCESS)
728 LogError("Get Message Failed!");
729 ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Failed to update message");
732 if (this->getIdRef().empty()) {
733 LogError("existing msgId is zero, update msg not done");
734 ThrowMsg(WrtDeviceApis::Commons::PlatformException,
735 "existing msgId is zero, update msg not done");
740 if (MSG_SUCCESS != msg_update_message(MsgGetCommonHandle(), m_messageData, sendOpt))
742 LogError("Failed to update message");
743 ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Failed to update message");
745 msg_release_struct(&msg);
746 msg_release_struct(&sendOpt);
748 Catch(WrtDeviceApis::Commons::PlatformException) {
749 msg_release_struct(&msg);
750 msg_release_struct(&sendOpt);
751 LogError("platform error occurs");
755 void Sms::createSendMessage()
757 LogDebug("convert m_id= " << convertId(getIdRef()));
759 //prepare for add sms to draft folder
760 if (!m_messageData) {
761 //error if platform message not exists
762 LogError("message can not be updated");
763 Throw(WrtDeviceApis::Commons::PlatformException);
766 //update all sms data
767 if (getCurrentFolder() == Api::Messaging::DRAFTBOX) {
768 LogDebug("update all sms data");
772 updateSourceAddress();
778 // MSG_SENDINGOPT_S option = { false, false, false };
779 // option.option.smsSendOpt.bReplyPath = true;
780 // trying to get message from platform
782 // const msg_folder_id_t platfromFolderId = Messaging::convertFolderToPlatform(DRAFTBOX);
784 // msg_set_message_id(m_messageData, msgId);
785 // msg_set_folder_id(m_messageData, platfromFolderId);
786 // msg_set_network_status(m_messageData, MSG_NETWORK_NOT_SEND);
788 setId(convertId(msgId));
789 setFolderType(Api::Messaging::DRAFTBOX);
790 setMessageStatus(Api::Messaging::MESSAGE_STATUS_DRAFT);
792 Catch(WrtDeviceApis::Commons::PlatformException) {
793 LogError("remove message error");
795 //releasing platform message structure
796 msg_release_struct(&m_messageData);
805 void Sms::addMessageToDraft()
807 LogDebug("convert m_id= " << convertId(getIdRef()));
808 msg_struct_t sendOpt = NULL;
810 //prepare for add sms to draft folder
811 if (!m_messageData) {
812 //error if platform message not exists
813 LogError("message can not be updated");
814 Throw(WrtDeviceApis::Commons::PlatformException);
817 //update all sms data
818 if (getCurrentFolder() == Api::Messaging::DRAFTBOX) {
819 LogDebug("update all sms data");
823 updateSourceAddress();
828 sendOpt = msg_create_struct(MSG_STRUCT_SENDOPT);
829 msg_set_bool_value(sendOpt, MSG_SEND_OPT_SETTING_BOOL, false);
831 // MSG_SENDINGOPT_S option = { false, false, false };
832 // option.option.smsSendOpt.bReplyPath = true;
833 // trying to get message from platform
835 // const msg_folder_id_t platfromFolderId = Messaging::convertFolderToPlatform(DRAFTBOX);
837 // msg_set_message_id(m_messageData, 0);
838 // msg_set_folder_id(m_messageData, platfromFolderId);
839 // msg_set_network_status(m_messageData, MSG_NETWORK_NOT_SEND);
841 // trying to add message
842 int ret = msg_add_message(MsgGetCommonHandle(), m_messageData, sendOpt);
843 if (ret < MSG_SUCCESS) {
844 LogError("msg_add_message failed, error code=" << ret);
845 Throw(WrtDeviceApis::Commons::PlatformException);
852 LogDebug("Message ID : " << msgId);
855 LogDebug("Message ID is invailded ");
856 Throw(WrtDeviceApis::Commons::PlatformException);
859 msg_set_int_value(m_messageData, MSG_MESSAGE_ID_INT, msgId);
861 setId(convertId(msgId));
862 setFolderType(Api::Messaging::DRAFTBOX);
863 setMessageStatus(Api::Messaging::MESSAGE_STATUS_DRAFT);
864 LogDebug("Message Status " << getMessageStatus());
867 if ( folder_list_view.nCount )
868 msg_release_list_struct(&folder_list_view);
870 msg_release_struct(&sendOpt);
873 Catch(WrtDeviceApis::Commons::PlatformException) {
874 LogError("remove message error");
876 //releasing platform message structure
877 msg_release_struct(&m_messageData);
878 msg_release_struct(&sendOpt);
885 void Sms::readRecipientList(msg_struct_t& messageData)
887 std::string phoneNumber;
888 // int recipientCount = msg_get_address_count(messageData);
889 // LogDebug("Recipient count " << recipientCount);
891 msg_struct_list_s *addr_list;
892 msg_get_list_handle(messageData, MSG_MESSAGE_ADDR_LIST_STRUCT, (void **)&addr_list);
895 char strNumber[MAX_ADDRESS_VAL_LEN] = {0,};
897 int recipientCount = addr_list->nCount;
898 LogDebug("Recipient count " << recipientCount);
901 for (int i = 0; i < recipientCount; ++i)
903 msg_get_int_value(messageData, MSG_MESSAGE_DIRECTION_INT, &tempInt);
906 if (MSG_DIRECTION_TYPE_MT == type)
908 msg_struct_t addr_info = addr_list->msg_struct_info[i];
909 msg_get_str_value(addr_info, MSG_ADDRESS_INFO_ADDRESS_VALUE_STR, strNumber, MAX_ADDRESS_VAL_LEN);
910 phoneNumber = strNumber;
912 if (validatePhoneNumber(phoneNumber))
914 setSourceAddress(phoneNumber);
915 setFrom(phoneNumber);
917 LogDebug("MT number: " << phoneNumber);
919 else if (MSG_DIRECTION_TYPE_MO == type)
921 msg_struct_t addr_info = addr_list->msg_struct_info[i];
922 msg_get_str_value(addr_info, MSG_ADDRESS_INFO_ADDRESS_VALUE_STR, strNumber, MAX_ADDRESS_VAL_LEN);
923 LogDebug("MO number: " << strNumber);
924 appendToRecipients(strNumber);
928 LogError("Wrong type of recipient");
929 ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Wrong type of recipient");
934 void Sms::readBody(msg_struct_t& messageData)
936 //set abstraction body value
938 msg_get_int_value(messageData, MSG_MESSAGE_DATA_SIZE_INT, &tempInt);
939 LogError("body Size : " <<tempInt);
940 char msgText[tempInt+1];
941 memset(msgText, 0, tempInt+1);
942 msg_get_str_value(messageData, MSG_MESSAGE_SMS_DATA_STR, msgText, tempInt);
943 // setBody(msg_sms_get_message_body(messageData));
944 LogError("body : " <<msgText);
948 void Sms::readFolder(msg_struct_t& messageData)
951 msg_get_int_value(messageData, MSG_MESSAGE_FOLDER_ID_INT, &tempInt);
952 LogError("Folder : " <<tempInt);
956 setFolderType(Api::Messaging::INBOX);
959 setFolderType(Api::Messaging::OUTBOX);
962 setFolderType(Api::Messaging::SENTBOX);
965 setFolderType(Api::Messaging::DRAFTBOX);
968 LogError("Wrong folder id");
969 ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Unsupported folder id.");
973 void Sms::readDateTime(msg_struct_t& messageData)
975 // tm* time = localtime(msg_get_time(messageData));
976 // tm dateT = getDateTime();
978 msg_get_int_value(messageData, MSG_MESSAGE_DISPLAY_TIME_INT, &tempInt);
980 LogError("readDateTime : " <<tempInt);
982 tm* time = localtime((time_t*)&tempInt);
984 LogError("localtime failed");
985 Throw(WrtDeviceApis::Commons::PlatformException);
990 void Sms::readReadStatus(msg_struct_t& messageData)
994 msg_get_bool_value(messageData, MSG_MESSAGE_READ_BOOL, &tempBool);
995 LogError("readReadStatus : " <<tempBool);
996 setReadStatus(tempBool);
999 void Sms::readSize(msg_struct_t& messageData)
1002 msg_get_int_value(messageData, MSG_MESSAGE_DATA_SIZE_INT, &tempInt);
1003 // setSize(msg_get_message_body_size(messageData));
1004 LogError("readSize : " <<tempInt);
1008 msg_struct_t Sms::createNewCopyOfPLatformMsg(const msg_struct_t src) const
1013 msg_struct_t msg = msg_create_struct(MSG_STRUCT_MESSAGE_INFO);
1015 msg_get_int_value(src, MSG_MESSAGE_STORAGE_ID_INT, &tempInt);
1016 msg_set_int_value(msg, MSG_MESSAGE_STORAGE_ID_INT, tempInt);
1018 msg_get_int_value(src, MSG_MESSAGE_FOLDER_ID_INT, &tempInt);
1019 msg_set_int_value(msg, MSG_MESSAGE_FOLDER_ID_INT, tempInt);
1021 msg_get_int_value(src, MSG_MESSAGE_DATA_SIZE_INT, &tempInt);
1022 char tempStr[tempInt+1];
1023 memset(tempStr, 0, tempInt+1);
1025 msg_get_str_value(src, MSG_MESSAGE_SMS_DATA_STR, tempStr, tempInt);
1026 msg_set_str_value(msg, MSG_MESSAGE_SMS_DATA_STR, tempStr, strlen(tempStr));
1028 msg_get_int_value(src, MSG_MESSAGE_DISPLAY_TIME_INT, &tempInt);
1029 msg_set_int_value(msg, MSG_MESSAGE_DISPLAY_TIME_INT, tempInt);
1031 // msg_set_network_status(msg, msg_get_network_status(src));
1032 msg_get_int_value(src, MSG_MESSAGE_NETWORK_STATUS_INT, &tempInt);
1033 msg_set_int_value(msg, MSG_MESSAGE_NETWORK_STATUS_INT, tempInt);
1035 // msg_set_encode_type(msg, msg_get_encode_type(src));
1036 msg_get_int_value(src, MSG_MESSAGE_ENCODE_TYPE_INT, &tempInt);
1037 msg_set_int_value(msg, MSG_MESSAGE_ENCODE_TYPE_INT, tempInt);
1039 // msg_set_read_status(msg, msg_is_read(src));
1040 msg_get_bool_value(src, MSG_MESSAGE_READ_BOOL, &tempBool);
1041 msg_set_bool_value(msg, MSG_MESSAGE_READ_BOOL, tempBool);
1043 // msg_set_protect_status(msg, msg_is_protected(src));
1044 msg_get_bool_value(src, MSG_MESSAGE_PROTECTED_BOOL, &tempBool);
1045 msg_set_bool_value(msg, MSG_MESSAGE_PROTECTED_BOOL, tempBool);
1047 // msg_set_priority_info(msg, msg_get_priority_info(src));
1048 msg_get_int_value(src, MSG_MESSAGE_PRIORITY_INT, &tempInt);
1049 msg_set_int_value(msg, MSG_MESSAGE_PRIORITY_INT, tempInt);
1051 // msg_set_direction_info(msg, msg_get_direction_info(src));
1052 msg_get_int_value(src, MSG_MESSAGE_DIRECTION_INT, &tempInt);
1053 msg_set_int_value(msg, MSG_MESSAGE_DIRECTION_INT, tempInt);
1055 // msg_set_port(msg, msg_get_dest_port(src), msg_get_src_port(src));
1056 msg_get_int_value(src, MSG_MESSAGE_DEST_PORT_INT, &tempInt);
1057 msg_set_int_value(msg, MSG_MESSAGE_DEST_PORT_INT, tempInt);
1058 msg_get_int_value(src, MSG_MESSAGE_SRC_PORT_INT, &tempInt);
1059 msg_set_int_value(msg, MSG_MESSAGE_SRC_PORT_INT, tempInt);