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 msg_struct_list_s *addr_list = NULL;
557 msg_get_list_handle(m_messageData, MSG_MESSAGE_ADDR_LIST_STRUCT, (void **)&addr_list);
558 int nToCnt = addr_list->nCount;
560 LogInfo("nToCnt size " << nToCnt);
564 for (int i = 0; i < nToCnt; i++) {
565 msg_set_str_value(addr_list->msg_struct_info[i], MSG_ADDRESS_INFO_ADDRESS_VALUE_STR, "", 0);
566 msg_set_str_value(addr_list->msg_struct_info[i], MSG_ADDRESS_INFO_DISPLAYNAME_STR, "", 0);
567 msg_set_int_value(addr_list->msg_struct_info[i], MSG_ADDRESS_INFO_ADDRESS_TYPE_INT, MSG_ADDRESS_TYPE_PLMN);
568 msg_set_int_value(addr_list->msg_struct_info[i], MSG_ADDRESS_INFO_RECIPIENT_TYPE_INT, MSG_RECIPIENTS_TYPE_UNKNOWN);
569 msg_set_int_value(addr_list->msg_struct_info[i], MSG_ADDRESS_INFO_CONTACT_ID_INT, 0);
572 addr_list->nCount = nToCnt;
575 vector<string> to = getToRecipients().getRecipients();
576 // update addresses in platform structure
579 LogInfo("updating to");
580 for (size_t i = 0; i < to.size(); i++)
582 string tmpAddr = to[i];
583 if(validatePhoneNumber(tmpAddr))
585 if (i >= MAX_TO_ADDRESS_CNT)
587 LogError("max number of recipient exceeded");
590 LogDebug("adding to[" << i << "]=" << to[i]);
592 msg_set_int_value(addr_list->msg_struct_info[i], MSG_ADDRESS_INFO_ADDRESS_TYPE_INT, MSG_ADDRESS_TYPE_PLMN);
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");
614 ThrowMsg(WrtDeviceApis::Commons::PlatformException, "wrong phone number format");
623 void Sms::updateFrom()
625 // check if abstraction from field value has been changed
626 if (getFromValidity()) {
627 // do not update if not changed
630 LogInfo("updating platform from");
634 // set flag as true - platform synchronized with abstraction
635 setFromValidity(true);
638 void Sms::updateSourceAddress()
640 // check if abstraction source address value has been changed
641 if (getSourceAddressValidity()) {
642 // do not update if not changed
645 LogInfo("updating platform source address");
649 // set flag as true - platform synchronized with abstraction
650 setSourceAddressValidity(true);
653 void Sms::updateReadStatus()
655 LogInfo("updating platform read status: " << isRead());
656 if (isReadStatusValid()) {
657 // do not update if not changed
660 if (MSG_SUCCESS != msg_set_bool_value(m_messageData, MSG_MESSAGE_READ_BOOL, isRead())) {
661 LogError("problem with setting subject");
662 ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Problem with setting subject");
664 setReadStatusValidity(true);
667 void Sms::updateIsRead()
669 LogDebug("updating m_id=" << getIdRef());
671 if (!m_messageData) {
672 //error if platform message not exists
673 LogError("message can not be updated");
674 Throw(WrtDeviceApis::Commons::PlatformException);
677 // check if abstraction from m_isReadChange value has been changed
678 if (isReadChangeStatusValid()) {
679 // do not update if not changed
685 if (this->getIdRef().empty()) {
686 LogError("existing msgId is zero, remove msg not done");
687 ThrowMsg(WrtDeviceApis::Commons::PlatformException,
688 "existing msgId is zero, remove msg not done");
692 msg_update_read_status(MsgGetCommonHandle(), convertId(getIdRef()), isReadChangeStatus()))
694 LogError("Failed to update isRead");
695 ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Failed to update isRead");
698 Catch(WrtDeviceApis::Commons::PlatformException) {
699 LogError("platform error occurs");
701 setisReadChangeStatusValidity(true);
705 void Sms::updateMessage()
707 LogDebug("updating m_id=" << getIdRef());
708 msg_error_t err = MSG_SUCCESS;
710 msg_struct_t msg = NULL;
711 msg_struct_t sendOpt = NULL;
713 if (!m_messageData) {
714 //error if platform message not exists
715 LogError("message can not be updated");
716 Throw(WrtDeviceApis::Commons::PlatformException);
722 msg = msg_create_struct(MSG_STRUCT_MESSAGE_INFO);
723 sendOpt = msg_create_struct(MSG_STRUCT_SENDOPT);
725 err = msg_get_message(MsgGetCommonHandle(), convertId(getIdRef()), msg, sendOpt);
727 if (err != MSG_SUCCESS)
729 LogError("Get Message Failed!");
730 ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Failed to update message");
733 if (this->getIdRef().empty()) {
734 LogError("existing msgId is zero, update msg not done");
735 ThrowMsg(WrtDeviceApis::Commons::PlatformException,
736 "existing msgId is zero, update msg not done");
741 if (MSG_SUCCESS != msg_update_message(MsgGetCommonHandle(), m_messageData, sendOpt))
743 LogError("Failed to update message");
744 ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Failed to update message");
746 msg_release_struct(&msg);
747 msg_release_struct(&sendOpt);
749 Catch(WrtDeviceApis::Commons::PlatformException) {
750 msg_release_struct(&msg);
751 msg_release_struct(&sendOpt);
752 LogError("platform error occurs");
756 void Sms::createSendMessage()
758 LogDebug("convert m_id= " << convertId(getIdRef()));
760 //prepare for add sms to draft folder
761 if (!m_messageData) {
762 //error if platform message not exists
763 LogError("message can not be updated");
764 Throw(WrtDeviceApis::Commons::PlatformException);
767 //update all sms data
768 if (getCurrentFolder() == Api::Messaging::DRAFTBOX) {
769 LogDebug("update all sms data");
773 updateSourceAddress();
779 // MSG_SENDINGOPT_S option = { false, false, false };
780 // option.option.smsSendOpt.bReplyPath = true;
781 // trying to get message from platform
783 // const msg_folder_id_t platfromFolderId = Messaging::convertFolderToPlatform(DRAFTBOX);
785 // msg_set_message_id(m_messageData, msgId);
786 // msg_set_folder_id(m_messageData, platfromFolderId);
787 // msg_set_network_status(m_messageData, MSG_NETWORK_NOT_SEND);
789 setId(convertId(msgId));
790 setFolderType(Api::Messaging::DRAFTBOX);
791 setMessageStatus(Api::Messaging::MESSAGE_STATUS_DRAFT);
793 Catch(WrtDeviceApis::Commons::PlatformException) {
794 LogError("remove message error");
796 //releasing platform message structure
797 msg_release_struct(&m_messageData);
806 void Sms::addMessageToDraft()
808 LogDebug("convert m_id= " << convertId(getIdRef()));
809 msg_struct_t sendOpt = NULL;
811 //prepare for add sms to draft folder
812 if (!m_messageData) {
813 //error if platform message not exists
814 LogError("message can not be updated");
815 Throw(WrtDeviceApis::Commons::PlatformException);
818 //update all sms data
819 if (getCurrentFolder() == Api::Messaging::DRAFTBOX) {
820 LogDebug("update all sms data");
824 updateSourceAddress();
829 sendOpt = msg_create_struct(MSG_STRUCT_SENDOPT);
830 msg_set_bool_value(sendOpt, MSG_SEND_OPT_SETTING_BOOL, false);
832 // MSG_SENDINGOPT_S option = { false, false, false };
833 // option.option.smsSendOpt.bReplyPath = true;
834 // trying to get message from platform
836 // const msg_folder_id_t platfromFolderId = Messaging::convertFolderToPlatform(DRAFTBOX);
838 // msg_set_message_id(m_messageData, 0);
839 // msg_set_folder_id(m_messageData, platfromFolderId);
840 // msg_set_network_status(m_messageData, MSG_NETWORK_NOT_SEND);
842 // trying to add message
843 int ret = msg_add_message(MsgGetCommonHandle(), m_messageData, sendOpt);
844 if (ret < MSG_SUCCESS) {
845 LogError("msg_add_message failed, error code=" << ret);
846 Throw(WrtDeviceApis::Commons::PlatformException);
853 LogDebug("Message ID : " << msgId);
856 LogDebug("Message ID is invailded ");
857 Throw(WrtDeviceApis::Commons::PlatformException);
860 msg_set_int_value(m_messageData, MSG_MESSAGE_ID_INT, msgId);
862 setId(convertId(msgId));
863 setFolderType(Api::Messaging::DRAFTBOX);
864 setMessageStatus(Api::Messaging::MESSAGE_STATUS_DRAFT);
865 LogDebug("Message Status " << getMessageStatus());
868 if ( folder_list_view.nCount )
869 msg_release_list_struct(&folder_list_view);
871 msg_release_struct(&sendOpt);
874 Catch(WrtDeviceApis::Commons::PlatformException) {
875 LogError("remove message error");
877 //releasing platform message structure
878 msg_release_struct(&m_messageData);
879 msg_release_struct(&sendOpt);
886 void Sms::readRecipientList(msg_struct_t& messageData)
888 std::string phoneNumber;
889 // int recipientCount = msg_get_address_count(messageData);
890 // LogDebug("Recipient count " << recipientCount);
892 msg_struct_list_s *addr_list;
893 msg_get_list_handle(messageData, MSG_MESSAGE_ADDR_LIST_STRUCT, (void **)&addr_list);
896 char strNumber[MAX_ADDRESS_VAL_LEN] = {0,};
898 int recipientCount = addr_list->nCount;
899 LogDebug("Recipient count " << recipientCount);
902 for (int i = 0; i < recipientCount; ++i)
904 msg_get_int_value(messageData, MSG_MESSAGE_DIRECTION_INT, &tempInt);
907 if (MSG_DIRECTION_TYPE_MT == type)
909 msg_struct_t addr_info = addr_list->msg_struct_info[i];
910 msg_get_str_value(addr_info, MSG_ADDRESS_INFO_ADDRESS_VALUE_STR, strNumber, MAX_ADDRESS_VAL_LEN);
911 phoneNumber = strNumber;
913 if (validatePhoneNumber(phoneNumber))
915 setSourceAddress(phoneNumber);
916 setFrom(phoneNumber);
918 LogDebug("MT number: " << phoneNumber);
920 else if (MSG_DIRECTION_TYPE_MO == 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 LogDebug("MO number: " << strNumber);
925 appendToRecipients(strNumber);
929 LogError("Wrong type of recipient");
930 ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Wrong type of recipient");
935 void Sms::readBody(msg_struct_t& messageData)
937 //set abstraction body value
939 msg_get_int_value(messageData, MSG_MESSAGE_DATA_SIZE_INT, &tempInt);
940 LogError("body Size : " <<tempInt);
941 char msgText[tempInt+1];
942 memset(msgText, 0, tempInt+1);
943 msg_get_str_value(messageData, MSG_MESSAGE_SMS_DATA_STR, msgText, tempInt);
944 // setBody(msg_sms_get_message_body(messageData));
945 LogError("body : " <<msgText);
949 void Sms::readFolder(msg_struct_t& messageData)
952 msg_get_int_value(messageData, MSG_MESSAGE_FOLDER_ID_INT, &tempInt);
953 LogError("Folder : " <<tempInt);
957 setFolderType(Api::Messaging::INBOX);
960 setFolderType(Api::Messaging::OUTBOX);
963 setFolderType(Api::Messaging::SENTBOX);
966 setFolderType(Api::Messaging::DRAFTBOX);
969 LogError("Wrong folder id");
970 ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Unsupported folder id.");
974 void Sms::readDateTime(msg_struct_t& messageData)
976 // tm* time = localtime(msg_get_time(messageData));
977 // tm dateT = getDateTime();
979 msg_get_int_value(messageData, MSG_MESSAGE_DISPLAY_TIME_INT, &tempInt);
981 LogError("readDateTime : " <<tempInt);
983 tm* time = localtime((time_t*)&tempInt);
985 LogError("localtime failed");
986 Throw(WrtDeviceApis::Commons::PlatformException);
991 void Sms::readReadStatus(msg_struct_t& messageData)
995 msg_get_bool_value(messageData, MSG_MESSAGE_READ_BOOL, &tempBool);
996 LogError("readReadStatus : " <<tempBool);
997 setReadStatus(tempBool);
1000 void Sms::readSize(msg_struct_t& messageData)
1003 msg_get_int_value(messageData, MSG_MESSAGE_DATA_SIZE_INT, &tempInt);
1004 // setSize(msg_get_message_body_size(messageData));
1005 LogError("readSize : " <<tempInt);
1009 msg_struct_t Sms::createNewCopyOfPLatformMsg(const msg_struct_t src) const
1014 msg_struct_t msg = msg_create_struct(MSG_STRUCT_MESSAGE_INFO);
1016 msg_get_int_value(src, MSG_MESSAGE_STORAGE_ID_INT, &tempInt);
1017 msg_set_int_value(msg, MSG_MESSAGE_STORAGE_ID_INT, tempInt);
1019 msg_get_int_value(src, MSG_MESSAGE_FOLDER_ID_INT, &tempInt);
1020 msg_set_int_value(msg, MSG_MESSAGE_FOLDER_ID_INT, tempInt);
1022 msg_get_int_value(src, MSG_MESSAGE_DATA_SIZE_INT, &tempInt);
1023 char tempStr[tempInt+1];
1024 memset(tempStr, 0, tempInt+1);
1026 msg_get_str_value(src, MSG_MESSAGE_SMS_DATA_STR, tempStr, tempInt);
1027 msg_set_str_value(msg, MSG_MESSAGE_SMS_DATA_STR, tempStr, strlen(tempStr));
1029 msg_get_int_value(src, MSG_MESSAGE_DISPLAY_TIME_INT, &tempInt);
1030 msg_set_int_value(msg, MSG_MESSAGE_DISPLAY_TIME_INT, tempInt);
1032 // msg_set_network_status(msg, msg_get_network_status(src));
1033 msg_get_int_value(src, MSG_MESSAGE_NETWORK_STATUS_INT, &tempInt);
1034 msg_set_int_value(msg, MSG_MESSAGE_NETWORK_STATUS_INT, tempInt);
1036 // msg_set_encode_type(msg, msg_get_encode_type(src));
1037 msg_get_int_value(src, MSG_MESSAGE_ENCODE_TYPE_INT, &tempInt);
1038 msg_set_int_value(msg, MSG_MESSAGE_ENCODE_TYPE_INT, tempInt);
1040 // msg_set_read_status(msg, msg_is_read(src));
1041 msg_get_bool_value(src, MSG_MESSAGE_READ_BOOL, &tempBool);
1042 msg_set_bool_value(msg, MSG_MESSAGE_READ_BOOL, tempBool);
1044 // msg_set_protect_status(msg, msg_is_protected(src));
1045 msg_get_bool_value(src, MSG_MESSAGE_PROTECTED_BOOL, &tempBool);
1046 msg_set_bool_value(msg, MSG_MESSAGE_PROTECTED_BOOL, tempBool);
1048 // msg_set_priority_info(msg, msg_get_priority_info(src));
1049 msg_get_int_value(src, MSG_MESSAGE_PRIORITY_INT, &tempInt);
1050 msg_set_int_value(msg, MSG_MESSAGE_PRIORITY_INT, tempInt);
1052 // msg_set_direction_info(msg, msg_get_direction_info(src));
1053 msg_get_int_value(src, MSG_MESSAGE_DIRECTION_INT, &tempInt);
1054 msg_set_int_value(msg, MSG_MESSAGE_DIRECTION_INT, tempInt);
1056 // msg_set_port(msg, msg_get_dest_port(src), msg_get_src_port(src));
1057 msg_get_int_value(src, MSG_MESSAGE_DEST_PORT_INT, &tempInt);
1058 msg_set_int_value(msg, MSG_MESSAGE_DEST_PORT_INT, tempInt);
1059 msg_get_int_value(src, MSG_MESSAGE_SRC_PORT_INT, &tempInt);
1060 msg_set_int_value(msg, MSG_MESSAGE_SRC_PORT_INT, tempInt);