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)
29 #include <dpl/log/log.h>
30 #include <Commons/Exception.h>
31 #include <API/Messaging/ReqReceiverMessage.h>
32 #include "Messaging.h"
33 #include "CallbackMgr.h"
34 #include "MsgServiceHandleMgr.h"
38 #include <msg_storage.h>
43 const char* TEXT_AREA = "Text";
44 const char* TEXT_FILE_EXTENSION = ".txt";
45 const int WHITE_COLOR = 0xffffff;
46 const int BLACK_COLOR = 0x000000;
47 const int ROOT_LAYOUT_WIDTH = 100;
48 const int ROOT_LAYOUT_HEIGHT = 100;
49 const char* EMPTY_ID = "0";
53 using namespace TizenApis::Api::Messaging;
59 Mms::Mms(const string& id) :
61 m_bodyFilePath(string(tmpnam(NULL)) + TEXT_FILE_EXTENSION),
65 LogDebug("m_id=" << getIdRef());
66 LogDebug("m_msgType=" << getMessageType());
67 if (getIdRef().empty()) {
70 readExistingMessage();
74 Mms::Mms(const string& id, const msg_struct_t msg_data) :
76 m_bodyFilePath(string(tmpnam(NULL)) + TEXT_FILE_EXTENSION),
77 m_messageData(msg_data)
80 LogDebug("m_id=" << getIdRef());
81 LogDebug("m_msgType=" << getMessageType());
82 readRecipientList(m_messageData);
83 readPriority(m_messageData);
84 readSubject(m_messageData);
85 readBodyAndAttachments(m_messageData);
86 readFolder(m_messageData);
87 readDateTime(m_messageData);
88 readReadStatus(m_messageData);
89 setMessageStatus(Api::Messaging::MESSAGE_STATUS_LOADED);
98 // release platform message structure
99 // msg_release_message(&m_messageData);
100 msg_release_struct(&m_messageData);
104 //trying to remove file, return value is skipped
105 if (!m_bodyFilePath.empty()) {
106 LogDebug("remove tmp file=" << m_bodyFilePath);
107 (void) ::remove(m_bodyFilePath.c_str());
111 void Mms::createNewMessage()
114 msg_release_struct(&m_messageData);
115 m_messageData = NULL;
118 char strSubject[MAX_SUBJECT_LEN] = {0,};
120 m_messageData = msg_create_struct(MSG_STRUCT_MESSAGE_INFO);
121 msg_struct_t sendOpt = msg_create_struct(MSG_STRUCT_SENDOPT);
122 msg_struct_t option = NULL;
124 // initialize platform message structure
125 msg_set_int_value(m_messageData, MSG_MESSAGE_TYPE_INT, MSG_TYPE_MMS);
126 msg_set_bool_value(sendOpt, MSG_SEND_OPT_SETTING_BOOL, false);
127 msg_set_str_value(m_messageData, MSG_MESSAGE_SUBJECT_STR, strSubject, MAX_SUBJECT_LEN);
129 setMmsType(MULTIPART_MIXED);
130 setReadStatus(false);
131 setMessageStatus(Api::Messaging::MESSAGE_STATUS_CREATED);
133 LogDebug("Message created successfully, Id: " << getIdRef());
136 void Mms::readExistingMessage()
140 if (getIdRef().empty() || (EMPTY_ID == getIdRef()))
142 ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Empty id.");
145 msg_release_struct(&m_messageData);
146 m_messageData = NULL;
147 msg_struct_t sendOpt = NULL;
151 m_messageData = msg_create_struct(MSG_STRUCT_MESSAGE_INFO);
152 sendOpt = msg_create_struct(MSG_STRUCT_SENDOPT);
154 // trying to get message from platform
155 if (MSG_SUCCESS != msg_get_message(MsgGetCommonHandle(), convertId(getIdRef()), m_messageData, sendOpt))
157 LogError("get message error");
158 Throw(WrtDeviceApis::Commons::PlatformException);
160 LogDebug("message found with msgId=" << getIdRef());
162 // read all mms dat to abstraction layer
163 readRecipientList(m_messageData);
164 readPriority(m_messageData);
165 readSubject(m_messageData);
166 readBodyAndAttachments(m_messageData);
167 readFolder(m_messageData);
168 readDateTime(m_messageData);
169 readReadStatus(m_messageData);
170 setMessageStatus(Api::Messaging::MESSAGE_STATUS_LOADED);
172 msg_release_struct(&sendOpt);
174 Catch(WrtDeviceApis::Commons::PlatformException) {
175 LogError("exception");
177 msg_release_struct(&sendOpt);
181 void Mms::readDateTime(msg_struct_t& messageData)
183 // tm* time = localtime(msg_get_time(messageData));
184 // tm dateT = getDateTime();
186 msg_get_int_value(messageData, MSG_MESSAGE_DISPLAY_TIME_INT, &tempInt);
188 LogError("readDateTime : " <<tempInt);
190 tm* time = localtime((time_t*)&tempInt);
192 LogError("localtime failed");
193 Throw(WrtDeviceApis::Commons::PlatformException);
198 void Mms::readReadStatus(msg_struct_t& messageData)
201 msg_get_bool_value(messageData, MSG_MESSAGE_READ_BOOL, &tempBool);
202 setReadStatus(tempBool);
205 void Mms::readFolder(msg_struct_t& messageData)
208 msg_get_int_value(messageData, MSG_MESSAGE_FOLDER_ID_INT, &tempValue);
212 setFolderType(Api::Messaging::INBOX);
215 setFolderType(Api::Messaging::OUTBOX);
218 setFolderType(Api::Messaging::SENTBOX);
221 setFolderType(Api::Messaging::DRAFTBOX);
224 ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Unsupported folder id.");
228 void Mms::readPriority(msg_struct_t& messageData)
230 // switch (msg_get_priority_info(messageData)) {
232 msg_get_int_value(messageData, MSG_MESSAGE_PRIORITY_INT, &tempInt);
234 case MSG_MESSAGE_PRIORITY_LOW:
235 setPriority(MessagePriority::LOW);
237 case MSG_MESSAGE_PRIORITY_NORMAL:
238 setPriority(MessagePriority::NORMAL);
240 case MSG_MESSAGE_PRIORITY_HIGH:
241 setPriority(MessagePriority::HIGH);
244 LogError("Wrong priority type");
245 ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Wrong priority type");
249 void Mms::readRecipientList(msg_struct_t& messageData)
251 std::string phoneNumber;
252 // int recipientCount = msg_get_address_count(messageData);
253 // LogDebug("Recipient count " << recipientCount);
255 msg_struct_list_s *addr_list;
256 msg_get_list_handle(messageData, MSG_MESSAGE_ADDR_LIST_STRUCT, (void **)&addr_list);
259 char strNumber[MAX_ADDRESS_VAL_LEN] = {0,};
261 int recipientCount = addr_list->nCount;
262 LogDebug("Recipient count " << recipientCount);
264 for (int i = 0; i < recipientCount; ++i)
266 // int type = msg_get_direction_info(messageData);
267 msg_get_int_value(messageData, MSG_MESSAGE_DIRECTION_INT, &tempInt);
269 LogDebug("Direction: " << type);
271 if (MSG_DIRECTION_TYPE_MT == type)
273 msg_struct_t addr_info = addr_list->msg_struct_info[i];
274 memset(strNumber, 0x00, sizeof(MAX_ADDRESS_VAL_LEN));
275 msg_get_str_value(addr_info, MSG_ADDRESS_INFO_ADDRESS_VALUE_STR, strNumber, MAX_ADDRESS_VAL_LEN);
276 phoneNumber = strNumber;
278 if (validatePhoneNumber(phoneNumber))
280 setSourceAddress(phoneNumber);
281 setFrom(phoneNumber);
283 LogDebug("MT number: " << phoneNumber);
285 else if (MSG_DIRECTION_TYPE_MO == type)
287 msg_struct_t addr_info = addr_list->msg_struct_info[i];
288 memset(strNumber, 0x00, sizeof(MAX_ADDRESS_VAL_LEN));
289 msg_get_str_value(addr_info, MSG_ADDRESS_INFO_ADDRESS_VALUE_STR, strNumber, MAX_ADDRESS_VAL_LEN);
290 msg_get_int_value(addr_info, MSG_ADDRESS_INFO_RECIPIENT_TYPE_INT, &tempInt);
291 LogDebug("MO number: " << strNumber);
292 LogDebug("Type : " << tempInt);
295 case MSG_RECIPIENTS_TYPE_TO:
296 appendToRecipients(strNumber);
298 case MSG_RECIPIENTS_TYPE_CC:
299 appendCcRecipients(strNumber);
301 case MSG_RECIPIENTS_TYPE_BCC:
302 appendBccRecipients(strNumber);
305 LogError("Wrong type of recipient");
310 LogError("Wrong type of recipient");
311 ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Wrong type of recipient");
316 void Mms::readSubject(msg_struct_t& messageData)
318 char strTemp[MAX_SUBJECT_LEN] = {0};
319 msg_get_str_value(messageData, MSG_MESSAGE_SUBJECT_STR, strTemp, MAX_SUBJECT_LEN);
320 // setSubject(msg_get_subject(messageData));
321 LogError("readSubject : " << strTemp);
325 void Mms::readBodyAndAttachments(msg_struct_t& messageData)
328 int pageLen, mediaLen, attachLen, tempInt;
330 msg_struct_t mms_struct = NULL;
332 msg_list_handle_t page_list = NULL;
333 msg_list_handle_t media_list = NULL;
334 msg_list_handle_t attach_list = NULL;
336 msg_struct_t page = NULL;
337 msg_struct_t media = NULL;
338 msg_struct_t attach = NULL;
340 mms_struct = msg_create_struct(MSG_STRUCT_MMS);
341 msg_get_mms_struct(messageData, mms_struct );
343 char szFilePath[MSG_FILEPATH_LEN_MAX] = {0,};
344 char szFileName[MSG_FILENAME_LEN_MAX] = {0,};
346 msg_get_list_handle(mms_struct, MSG_MMS_PAGE_LIST_HND, (void **)&page_list);
347 pageLen = msg_list_length(page_list);
350 setMmsType(MULTIPART_RELATED);
352 setMmsType(MULTIPART_MIXED);
355 LogDebug("page count: " << pageLen);
357 for (int p = 0; p < pageLen; ++p)
359 LogDebug("page " << p);
360 page = (msg_struct_t)msg_list_nth_data(page_list, p);
363 LogError("returned page is null, continue");
367 msg_get_list_handle(page, MSG_MMS_PAGE_MEDIA_LIST_HND, (void **)&media_list);
368 mediaLen = msg_list_length(media_list);
370 for (int m = 0; m < mediaLen; ++m)
372 LogDebug("media file " << m);
373 media = (msg_struct_t)msg_list_nth_data(media_list, m);
376 LogError("returned media is null, continue");
380 msg_get_int_value(media, MSG_MMS_MEDIA_TYPE_INT, &tempInt);
382 memset(szFilePath, 0, sizeof(szFilePath));
383 msg_get_str_value(media, MSG_MMS_MEDIA_FILEPATH_STR, szFilePath, sizeof(szFilePath));
385 if ((0 == p) && (MMS_SMIL_MEDIA_TEXT == tempInt))
387 //text value on first page goes to body attribute
388 LogDebug("setting body from " << szFilePath);
391 f = fopen(szFilePath, "r");
394 LogError("cannot read file with body" << szFilePath);
395 ThrowMsg(WrtDeviceApis::Commons::PlatformException,
396 "Cannot read file with body");
398 fseek(f, 0, SEEK_END);
399 long int size = ftell(f);
400 fseek(f, 0, SEEK_SET);
401 char* data = new (nothrow) char[size + 1];
403 memset(data, 0, size + 1);
404 fread(data, 1, size, f);
408 LogError("body is not set");
410 LogDebug("message body: '" << getBody() << "'");
415 LogDebug("adding attachment " << szFilePath);
417 IAttachmentPtr attachment = appendAttachment(szFilePath, false);
418 //attachment->setMessage(this); //set IMessagePtr
420 memset(szFileName, 0, sizeof(szFileName));
421 msg_get_str_value(media, MSG_MMS_MEDIA_FILENAME_STR, szFileName, sizeof(szFileName));
423 if (NULL != szFileName && strnlen(szFileName, MSG_FILENAME_LEN_MAX) > 0)
425 LogDebug("renaming to " << szFileName);
426 attachment->rename(szFileName);
428 else if (MMS_SMIL_MEDIA_TEXT == tempInt)
430 std::stringstream newName;
431 newName << "body_page_" << p + 1 << ".txt";
432 LogDebug("renaming to " << newName.str());
433 attachment->rename(newName.str());
439 msg_get_list_handle(mms_struct, MSG_MMS_ATTACH_LIST_HND, (void **)&attach_list);
440 attachLen= msg_list_length(attach_list);
442 LogDebug("attachment count: " << attachLen);
443 for (int a = 0; a < attachLen; ++a)
445 attach = (msg_struct_t)msg_list_nth_data(attach_list, a);
448 LogError("attachment is null, continue");
452 memset(szFilePath, 0, sizeof(szFilePath));
453 memset(szFileName, 0, sizeof(szFileName));
455 msg_get_str_value(attach, MSG_MMS_ATTACH_FILEPATH_STR, szFilePath, sizeof(szFilePath));
456 msg_get_str_value(attach, MSG_MMS_ATTACH_FILENAME_STR, szFileName, sizeof(szFileName));
458 IAttachmentPtr att = appendAttachment(szFilePath, false);
459 if (NULL != szFileName &&
460 strnlen(szFileName, MSG_FILENAME_LEN_MAX) > 0) {
461 LogDebug("renaming to " << szFileName);
462 att->rename(szFileName);
467 bool Mms::hasAttachment()
469 std::size_t attachmentSize = getAttachmentsCount();
470 if ( attachmentSize > 0)
476 void Mms::update(bool draftsOnly)
478 LogDebug("updating m_id=" << getIdRef());
480 if (!m_messageData) {
481 //error if platform message not exists
482 LogError("message can not be updated");
483 Throw(WrtDeviceApis::Commons::PlatformException);
486 //update mms data from abstraction
487 if (!draftsOnly || getCurrentFolder() == Api::Messaging::DRAFTBOX) {
489 updateBodyAndAttachments();
490 updateRecipientList();
496 void Mms::updatePriority()
498 if (isPriorityValid()) {
502 LogInfo("MMS updating priority");
504 //set priority in platform
505 switch (getPriority()) {
506 case MessagePriority::LOW:
507 priority = MSG_MESSAGE_PRIORITY_LOW;
509 case MessagePriority::NORMAL:
510 priority = MSG_MESSAGE_PRIORITY_NORMAL;
512 case MessagePriority::HIGH:
513 priority = MSG_MESSAGE_PRIORITY_HIGH;
516 LogError("Wrong priority");
517 Throw(WrtDeviceApis::Commons::PlatformException);
520 // msg_set_priority_info(m_messageData, MSG_MESSAGE_PRIORITY_LOW)) {
521 msg_set_int_value(m_messageData, MSG_MESSAGE_PRIORITY_INT, priority)){
523 LogError("Error during setting priority");
524 Throw(WrtDeviceApis::Commons::PlatformException);
528 void Mms::updateRecipientList()
530 // check if abstraction recipient value has been changed
531 if (getToRecipients().isValid() &&
532 getBccRecipients().isValid() &&
533 getCcRecipients().isValid()) {
537 LogInfo("MMS updating platform recipients");
539 // reset addresses in platform structure
540 // msg_reset_address(m_messageData);
541 msg_struct_list_s *addr_list = NULL;
542 msg_get_list_handle(m_messageData, MSG_MESSAGE_ADDR_LIST_STRUCT, (void **)&addr_list);
544 nToCnt = addr_list->nCount;
546 LogInfo("addr_list->nCount" << addr_list->nCount);
550 for (int i = 0; i < nToCnt; i++) {
551 msg_set_str_value(addr_list->msg_struct_info[i], MSG_ADDRESS_INFO_ADDRESS_VALUE_STR, "", 0);
552 msg_set_str_value(addr_list->msg_struct_info[i], MSG_ADDRESS_INFO_DISPLAYNAME_STR, "", 0);
553 msg_set_int_value(addr_list->msg_struct_info[i], MSG_ADDRESS_INFO_ADDRESS_TYPE_INT, MSG_ADDRESS_TYPE_PLMN);
554 msg_set_int_value(addr_list->msg_struct_info[i], MSG_ADDRESS_INFO_RECIPIENT_TYPE_INT, MSG_RECIPIENTS_TYPE_UNKNOWN);
555 msg_set_int_value(addr_list->msg_struct_info[i], MSG_ADDRESS_INFO_CONTACT_ID_INT, 0);
558 addr_list->nCount = nToCnt;
561 LogInfo("addr_list->nCount" << addr_list->nCount);
563 vector<string> to = getToRecipients().getRecipients();
564 vector<string> cc = getCcRecipients().getRecipients();
565 vector<string> bcc = getBccRecipients().getRecipients();
567 // update addresses in platform structure
570 LogInfo("updating to");
571 for (size_t i = 0; i < to.size(); i++)
573 if (i >= MAX_TO_ADDRESS_CNT)
575 LogError("max number of recipient exceeded");
578 LogDebug("adding to[" << i << "]=" << to[i]);
580 if (msg_set_int_value(addr_list->msg_struct_info[i], MSG_ADDRESS_INFO_RECIPIENT_TYPE_INT,
581 MSG_RECIPIENTS_TYPE_TO) != MSG_SUCCESS)
583 LogError("problem with adding to address");
584 ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Problem with adding to address");
587 if(msg_set_str_value(addr_list->msg_struct_info[i], MSG_ADDRESS_INFO_ADDRESS_VALUE_STR,
588 const_cast<char*>(to[i].c_str()), to[i].size()) != MSG_SUCCESS)
590 LogError("problem with adding to address");
591 ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Problem with adding to address");
595 addr_list->nCount = nToCnt;
596 LogError("nToCnt : " << nToCnt);
597 LogError("addr_list->nCount: " <<addr_list->nCount);
601 LogInfo("addr_list->nCount" << addr_list->nCount);
605 LogInfo("updating cc");
606 for (size_t i = 0; i < cc.size(); i++)
608 if (nToCnt >= MAX_TO_ADDRESS_CNT)
610 LogError("max number of recipient exceeded");
613 LogDebug("adding cc[" << i << "]=" << cc[i]);
615 if (msg_set_int_value(addr_list->msg_struct_info[i], MSG_ADDRESS_INFO_RECIPIENT_TYPE_INT,
616 MSG_RECIPIENTS_TYPE_CC) != MSG_SUCCESS)
618 LogError("problem with adding cc address");
619 ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Problem with adding cc address");
622 if(msg_set_str_value(addr_list->msg_struct_info[i], MSG_ADDRESS_INFO_ADDRESS_VALUE_STR,
623 const_cast<char*>(cc[i].c_str()), cc[i].size()) != MSG_SUCCESS)
625 LogError("problem with adding cc address");
626 ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Problem with adding cc address");
630 addr_list->nCount = nToCnt;
631 LogError("nToCnt : " << nToCnt);
632 LogError("addr_list->nCount: " <<addr_list->nCount);
635 LogInfo("addr_list->nCount" << addr_list->nCount);
639 LogInfo("updating bcc");
640 for (size_t i = 0; i < bcc.size(); i++)
642 if (nToCnt >= MAX_TO_ADDRESS_CNT)
644 LogError("max number of recipient exceeded");
647 LogDebug("adding bcc[" << i << "]=" << bcc[i]);
649 if (msg_set_int_value(addr_list->msg_struct_info[i], MSG_ADDRESS_INFO_RECIPIENT_TYPE_INT,
650 MSG_RECIPIENTS_TYPE_BCC) != MSG_SUCCESS)
652 LogError("problem with adding bcc address");
653 ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Problem with adding bcc address");
656 if(msg_set_str_value(addr_list->msg_struct_info[i], MSG_ADDRESS_INFO_ADDRESS_VALUE_STR,
657 const_cast<char*>(bcc[i].c_str()), bcc[i].size()) != MSG_SUCCESS)
659 LogError("problem with adding bcc address");
660 ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Problem with adding bcc address");
664 addr_list->nCount = nToCnt;
665 LogError("nToCnt : " << nToCnt);
666 LogError("addr_list->nCount: " <<addr_list->nCount);
669 LogInfo("addr_list->nCount" << addr_list->nCount);
672 setBccValidity(true);
675 void Mms::updateSubject()
677 // check if abstraction subject value has been changed
678 if (isSubjectValid()) {
681 LogInfo("updating platform subject: " << getSubjectRef());
683 // msg_set_subject(m_messageData, getSubjectRef().c_str())) {
684 msg_set_str_value(m_messageData, MSG_MESSAGE_SUBJECT_STR, const_cast<char*>(getSubjectRef().c_str()), MAX_SUBJECT_LEN)) {
686 LogError("problem with setting subject");
687 ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Problem with setting subject");
689 setSubjectValidity(true);
692 void Mms::updateBodyAndAttachments()
694 // check if attachment or body source address value has been changed
695 if (isAttachmentsValid() && isBodyValid()) {
699 // MMS_MESSAGE_DATA_S *mmsData = NULL;
700 msg_struct_t mms_struct = NULL;
701 // msg_struct_t old_mms_struct = NULL;// THIS
704 LogInfo("updating platform body and attachment");
708 msg_struct_t region[1];
709 msg_struct_t page[1];
710 msg_struct_t media[1];
711 msg_struct_t smil_text[1];
713 if (getMessageType() != MMS) {
714 LogError("Wrong msg type");
715 ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Wrong msg type");
717 // mmsData = msg_mms_create_message();
718 mms_struct = msg_create_struct(MSG_STRUCT_MMS);
719 // old_mms_struct = msg_create_struct(MSG_STRUCT_MMS);// THIS
721 // ret = msg_get_mms_struct(m_messageData, old_mms_struct);// THIS
722 // LogError("ret " << ret);// THIS
723 // ret = msg_release_struct(&old_mms_struct);// THIS
724 // LogError("ret " << ret);// THIS
727 LogError("create message body failed");
728 ThrowMsg(WrtDeviceApis::Commons::PlatformException, "create message body failed");
732 if (!getBodyRef().empty()) {
734 f = fopen(m_bodyFilePath.c_str(), "w");
736 LogError("cannot create file with body" << m_bodyFilePath);
737 ThrowMsg(WrtDeviceApis::Commons::PlatformException,
738 "cannot create file with body");
740 LogDebug("body file: " << m_bodyFilePath);
741 fwrite(getBodyRef().c_str(), strlen(getBodyRef().c_str()), 1, f);
745 LogDebug("getBodyRef(): " << getBodyRef());
747 msg_set_int_value(mms_struct, MSG_MMS_ROOTLAYOUT_WIDTH_INT, ROOT_LAYOUT_WIDTH);
748 msg_set_int_value(mms_struct, MSG_MMS_ROOTLAYOUT_HEIGHT_INT, ROOT_LAYOUT_HEIGHT);
749 msg_set_int_value(mms_struct, MSG_MMS_ROOTLAYOUT_BGCOLOR_INT, WHITE_COLOR);
750 msg_set_bool_value(mms_struct, MSG_MMS_ROOTLAYOUT_WIDTH_PERCENT_BOOL, true);
751 msg_set_bool_value(mms_struct, MSG_MMS_ROOTLAYOUT_HEIGHT_PERCENT_BOOL, true);
753 msg_mms_add_item(mms_struct, MSG_STRUCT_MMS_REGION, ®ion[0]);
754 msg_set_str_value(region[0], MSG_MMS_REGION_ID_STR, const_cast<char*>(TEXT_AREA), 4);
755 msg_set_int_value(region[0], MSG_MMS_REGION_LENGTH_LEFT_INT, 0);
756 msg_set_int_value(region[0], MSG_MMS_REGION_LENGTH_TOP_INT, 0);
757 msg_set_int_value(region[0], MSG_MMS_REGION_LENGTH_WIDTH_INT, ROOT_LAYOUT_WIDTH);
758 msg_set_int_value(region[0], MSG_MMS_REGION_LENGTH_HEIGHT_INT, ROOT_LAYOUT_HEIGHT);
759 msg_set_int_value(region[0], MSG_MMS_REGION_BGCOLOR_INT, WHITE_COLOR);
761 msg_set_bool_value(region[0], MSG_MMS_REGION_LENGTH_LEFT_PERCENT_BOOL, true);
762 msg_set_bool_value(region[0], MSG_MMS_REGION_LENGTH_TOP_PERCENT_BOOL, true);
763 msg_set_bool_value(region[0], MSG_MMS_REGION_LENGTH_WIDTH_PERCENT_BOOL, true);
764 msg_set_bool_value(region[0], MSG_MMS_REGION_LENGTH_HEIGHT_PERCENT_BOOL, true);
766 msg_mms_add_item(mms_struct, MSG_STRUCT_MMS_PAGE, &page[0]);
767 msg_set_int_value(page[0], MSG_MMS_PAGE_PAGE_DURATION_INT, 0);
769 msg_mms_add_item(page[0], MSG_STRUCT_MMS_MEDIA, &media[0]);
770 msg_set_int_value(media[0], MSG_MMS_MEDIA_TYPE_INT, MMS_SMIL_MEDIA_TEXT);
771 msg_set_str_value(media[0], MSG_MMS_MEDIA_REGION_ID_STR, const_cast<char*>(TEXT_AREA), 4);
773 error = msg_set_str_value(media[0], MSG_MMS_MEDIA_FILEPATH_STR, const_cast<char*>(m_bodyFilePath.c_str()),MSG_FILEPATH_LEN_MAX);
774 LogDebug("bodyFile Path= " << m_bodyFilePath);
775 LogDebug("error= " << error);
776 char szFilePath[MSG_FILEPATH_LEN_MAX] = {0,};
777 memset(szFilePath, 0, sizeof(szFilePath));
778 msg_get_str_value(media[0], MSG_MMS_MEDIA_FILEPATH_STR, szFilePath, sizeof(szFilePath));
779 LogDebug("bodyFile Path= " << m_bodyFilePath);
781 msg_get_struct_handle(media[0], MSG_MMS_MEDIA_SMIL_TEXT_HND, &smil_text[0]);
782 msg_set_int_value(smil_text[0], MSG_MMS_SMIL_TEXT_COLOR_INT, BLACK_COLOR);
783 msg_set_int_value(smil_text[0], MSG_MMS_SMIL_TEXT_SIZE_INT, MMS_SMIL_FONT_SIZE_NORMAL);
784 msg_set_bool_value(smil_text[0], MSG_MMS_SMIL_TEXT_BOLD_BOOL, true);
792 msg_struct_t attachment[20];
794 for (size_t i = 0; i < getAttachmentsRef().size(); ++i) {
795 Api::Messaging::IAttachmentPtr att = getAttachment(i);
800 LogDebug("Add attachment=" << att->getFullPath());
802 errnum = stat(att->getFullPath().c_str(), &buffer);
804 LogError("Opening file: " <<
805 att->getFullPath().c_str() <<
806 " " << strerror(errnum));
807 ThrowMsg(WrtDeviceApis::Commons::PlatformException,
808 "cannot open attachment file");
811 //this function should return valid pointer
813 msg_mms_add_item(mms_struct, MSG_STRUCT_MMS_ATTACH, &attachment[i]);
814 msg_set_str_value(attachment[i], MSG_MMS_ATTACH_FILEPATH_STR, const_cast<char*>(att->getFullPath().c_str()), MSG_FILEPATH_LEN_MAX);
816 LogDebug("Attachment added");
822 if (MSG_SUCCESS !=msg_set_mms_struct(m_messageData, mms_struct))
824 LogError("set message body error");
825 ThrowMsg(WrtDeviceApis::Commons::PlatformException, "set message body error");
828 msg_release_struct(&mms_struct);
830 setAttachmentsValidity(true);
831 setBodyValidity(true);
834 Catch(WrtDeviceApis::Commons::PlatformException) {
835 LogError("Platform error");
836 msg_release_struct(&mms_struct);
842 void Mms::updateReadStatus()
844 if (isReadStatusValid()) {
848 LogInfo("updating platform read status: " << isRead());
849 // if (MSG_SUCCESS != msg_set_read_status(m_messageData, isRead())) {
850 if (MSG_SUCCESS != msg_set_bool_value(m_messageData, MSG_MESSAGE_READ_BOOL, isRead())) {
851 LogError("problem with setting subject");
852 ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Problem with setting subject");
855 setReadStatusValidity(true);
858 void Mms::updateIsRead()
860 LogDebug("updating m_id=" << getIdRef());
862 if (!m_messageData) {
863 //error if platform message not exists
864 LogError("message can not be updated");
865 Throw(WrtDeviceApis::Commons::PlatformException);
868 // check if abstraction from m_isReadChange value has been changed
869 if (isReadChangeStatusValid()) {
870 // do not update if not changed
876 if (this->getIdRef().empty()) {
877 LogError("existing msgId is zero, remove msg not done");
878 ThrowMsg(WrtDeviceApis::Commons::PlatformException,
879 "existing msgId is zero, remove msg not done");
883 msg_update_read_status(MsgGetCommonHandle(), convertId(getIdRef()), isReadChangeStatus()))
885 LogError("Failed to update isRead");
886 ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Failed to update isRead");
889 Catch(WrtDeviceApis::Commons::PlatformException) {
890 LogError("platform error occurs");
892 setisReadChangeStatusValidity(true);
896 void Mms::updateMessage()
898 LogDebug("updating m_id=" << getIdRef());
899 msg_error_t err = MSG_SUCCESS;
900 msg_struct_t msg = NULL;
901 msg_struct_t sendOpt = NULL;
903 if (!m_messageData) {
904 //error if platform message not exists
905 LogError("message can not be updated");
906 Throw(WrtDeviceApis::Commons::PlatformException);
912 msg = msg_create_struct(MSG_STRUCT_MESSAGE_INFO);
913 sendOpt = msg_create_struct(MSG_STRUCT_SENDOPT);
915 err = msg_get_message(MsgGetCommonHandle(), convertId(getIdRef()), msg, sendOpt);
917 if (err != MSG_SUCCESS)
919 LogError("Get Message Failed!");
920 ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Failed to update message");
923 if (this->getIdRef().empty()) {
924 LogError("existing msgId is zero, update msg not done");
925 ThrowMsg(WrtDeviceApis::Commons::PlatformException,
926 "existing msgId is zero, update msg not done");
931 if (MSG_SUCCESS != msg_update_message(MsgGetCommonHandle(), m_messageData, sendOpt))
933 LogError("Failed to update message");
934 ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Failed to update message");
936 msg_release_struct(&msg);
937 msg_release_struct(&sendOpt);
939 Catch(WrtDeviceApis::Commons::PlatformException) {
940 msg_release_struct(&msg);
941 msg_release_struct(&sendOpt);
942 LogError("platform error occurs");
947 void Mms::createSendMessage()
949 LogDebug("convert m_id= " << convertId(getIdRef()));
951 //prepare for add sms to draft folder
952 if (!m_messageData) {
953 //error if platform message not exists
954 LogError("message can not be updated");
955 Throw(WrtDeviceApis::Commons::PlatformException);
958 //update all sms data
959 if (getCurrentFolder() == Api::Messaging::DRAFTBOX) {
960 LogDebug("update all mms data");
962 updateBodyAndAttachments();
963 updateRecipientList();
970 // MSG_SENDINGOPT_S option = { false, false, false };
971 // option.option.smsSendOpt.bReplyPath = true;
972 // trying to get message from platform
974 // msg_struct_t sendOpt = msg_create_struct(MSG_STRUCT_SENDOPT);
975 // msg_set_bool_value(sendOpt, MSG_SEND_OPT_SETTING_BOOL, false);
978 // const msg_folder_id_t platfromFolderId = Messaging::convertFolderToPlatform(DRAFTBOX);
980 // msg_set_int_value(m_messageData, MSG_MESSAGE_ID_INT, msgId);
981 // msg_set_int_value(m_messageData, MSG_MESSAGE_FOLDER_ID_INT, 4);
982 // msg_set_int_value(m_messageData, MSG_MESSAGE_NETWORK_STATUS_INT, MSG_NETWORK_NOT_SEND);
984 setId(convertId(msgId));
985 setFolderType(Api::Messaging::DRAFTBOX);
986 setMessageStatus(Api::Messaging::MESSAGE_STATUS_DRAFT);
988 Catch(WrtDeviceApis::Commons::PlatformException) {
989 LogError("remove message error");
991 //releasing platform message structure
992 // msg_release_message(&m_messageData);
993 msg_release_struct(&m_messageData);
1000 void Mms::addMessageToDraft()
1002 LogDebug("convert m_id= " << convertId(getIdRef()));
1004 msg_struct_t sendOpt = NULL;
1006 //prepare for add sms to draft folder
1007 if (!m_messageData) {
1008 //error if platform message not exists
1009 LogError("message can not be updated");
1010 Throw(WrtDeviceApis::Commons::PlatformException);
1013 //update all sms data
1014 if (getCurrentFolder() == Api::Messaging::DRAFTBOX) {
1016 updateBodyAndAttachments();
1017 updateRecipientList();
1024 sendOpt = msg_create_struct(MSG_STRUCT_SENDOPT);
1026 // trying to get message from platform
1028 // const msg_folder_id_t platfromFolderId =
1029 // Messaging::convertFolderToPlatform(DRAFTBOX);
1031 // trying to add message
1032 int ret = msg_add_message(MsgGetCommonHandle(), m_messageData, sendOpt);
1033 if (ret < MSG_SUCCESS) {
1034 LogError("msg_add_message failed, error code=" << ret);
1035 Throw(WrtDeviceApis::Commons::PlatformException);
1042 LogDebug("Message ID : " << msgId);
1045 LogDebug("Message ID is invailded ");
1046 Throw(WrtDeviceApis::Commons::PlatformException);
1049 msg_set_int_value(m_messageData, MSG_MESSAGE_ID_INT, msgId);
1051 setId(convertId(msgId));
1052 setFolderType(Api::Messaging::DRAFTBOX);
1053 setMessageStatus(Api::Messaging::MESSAGE_STATUS_DRAFT);
1055 msg_release_struct(&sendOpt);
1058 Catch(WrtDeviceApis::Commons::PlatformException) {
1059 LogError("remove message error");
1060 // msg_release_struct(&m_messageData);
1061 msg_release_struct(&sendOpt);
1067 void Mms::readAllData()
1069 readExistingMessage();
1072 void Mms::moveToFolder(const FolderType newFolder)
1079 msg_folder_id_t platfromFolderId = Messaging::convertFolderToPlatform(
1082 if (msg_move_msg_to_folder(MsgGetCommonHandle(), convertId(getId()),
1083 platfromFolderId) != MSG_SUCCESS) {
1084 ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Error during movinf message");
1088 Catch(WrtDeviceApis::Commons::PlatformException) {
1089 LogError("remove message error");
1095 void Mms::moveToFolder(const string& newFolder)
1102 msg_folder_id_t platfromFolderId = Messaging::convertFolderToPlatform(
1105 if (msg_move_msg_to_folder(MsgGetCommonHandle(), convertId(getId()),
1106 platfromFolderId) != MSG_SUCCESS) {
1107 LogError("msg_move_msg_to_folder error");
1108 ThrowMsg(WrtDeviceApis::Commons::PlatformException, "msg_move_msg_to_folder error");
1112 Catch(WrtDeviceApis::Commons::PlatformException) {
1113 LogError("remove message error");
1119 void Mms::copyToFolder(const FolderType newFolder)
1124 msg_message_t msg = msg_new_message();
1128 MSG_SENDINGOPT_S option = { false, false, false };
1129 option.option.smsSendOpt.bReplyPath = true;
1131 msg_get_message(MsgGetCommonHandle(), convertId(getIdRef()), msg,
1133 const msg_folder_id_t platfromFolderId =
1134 Messaging::convertFolderToPlatform(newFolder);
1135 msg_set_message_id(msg, 0);
1136 msg_set_folder_id(msg, platfromFolderId);
1138 int error = msg_add_message(MsgGetCommonHandle(), msg, &option);
1139 if (error != MSG_SUCCESS) {
1140 LogError("msg_add_message failed, error code=" << error);
1141 ThrowMsg(WrtDeviceApis::Commons::PlatformException, "msg_add_message failed");
1145 msg_release_message(&msg);
1149 Catch(WrtDeviceApis::Commons::PlatformException) {
1150 LogError("remove message error");
1152 msg_release_message(&msg);
1159 void Mms::copyToFolder(const string& newFolder)
1164 msg_message_t msg = msg_new_message();
1168 MSG_SENDINGOPT_S option = { false, false, false };
1169 option.option.smsSendOpt.bReplyPath = true;
1171 msg_get_message(MsgGetCommonHandle(), convertId(getIdRef()), msg,
1173 const msg_folder_id_t platfromFolderId =
1174 Messaging::convertFolderToPlatform(newFolder);
1175 msg_set_message_id(msg, 0);
1176 msg_set_folder_id(msg, platfromFolderId);
1178 int error = msg_add_message(MsgGetCommonHandle(), msg, &option);
1179 if (error != MSG_SUCCESS) {
1180 LogError("msg_add_message failed, error code=" << error);
1181 ThrowMsg(WrtDeviceApis::Commons::PlatformException, "msg_add_message failed");
1185 msg_release_message(&msg);
1189 Catch(WrtDeviceApis::Commons::PlatformException) {
1190 LogError("remove message error");
1192 msg_release_message(&msg);
1201 LogDebug("delete m_id=" << getIdRef());
1205 if (this->getIdRef().empty()) {
1206 LogError("existing msgId is zero, remove msg not done");
1207 ThrowMsg(WrtDeviceApis::Commons::PlatformException,
1208 "existing msgId is zero, remove msg not done");
1212 msg_delete_message(MsgGetCommonHandle(),
1213 convertId(getIdRef()))) {
1214 LogError("Failed to delete Message");
1215 ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Failed to delete Message");
1219 Catch(WrtDeviceApis::Commons::PlatformException) {
1220 LogError("platform error occurs");
1226 LogDebug("sending message, id=" << getIdRef());
1229 //prepare for sending sms/mms
1232 LogDebug("Start Sending Message...");
1234 LogDebug("trying to send mms");
1235 msg_error_t err = CallbackMgrSingleton::Instance().registerAndSend(msg_mms_send_message, m_messageData, this);
1237 if (err != MSG_SUCCESS)
1239 LogError("Sending Message (submit request) failed!!! err=" << err);
1240 setMessageStatus(MESSAGE_STATUS_FAILED);
1244 setMessageStatus(MESSAGE_STATUS_SENDING);
1246 LogDebug("Sending Message request is submitted!");
1248 Catch(WrtDeviceApis::Commons::PlatformException) {
1249 LogError("message is not send, manually run callback");
1256 ReqReceiverMessage *requestReceiver = getRequestReceiver();
1257 if (requestReceiver) {
1258 LogError("send Error");
1259 EventMessagingServicePtr event = getMessagingServiceEvent();
1260 event->setExceptionCode(WrtDeviceApis::Commons::ExceptionCodes::UnknownException);
1261 requestReceiver->WrtDeviceApis::Commons::EventRequestReceiver< EventMessagingService>::ManualAnswer(event);
1266 void Mms::sendingCallback(msg_struct_t sent_status)
1268 // LogInfo("sendingCallback callback received. Req id = " <<
1269 // sent_status->reqId << " Status = " << (int)sent_status->status);
1270 // msg_struct_t request_data = NULL;
1271 // msg_get_struct_handle(sent_status, MSG_STRUCT_REQUEST_INFO, (void **)request_data);
1272 // msg_get_int_value(request_data, MSG_REQUEST_REQUESTID_INT, &tempInt);
1273 int status = MSG_NETWORK_SEND_FAIL;
1274 msg_get_int_value(sent_status, MSG_SENT_STATUS_NETWORK_STATUS_INT, &status);
1275 if (MSG_NETWORK_SEND_SUCCESS == status) {
1276 LogDebug("sending ok");
1277 setSendingStatusOk();
1278 setMessageStatus(MESSAGE_STATUS_SENT);
1280 LogError("sending failed: " <<
1281 static_cast<unsigned int>(status));
1282 setSendingStatusFailed();
1283 setMessageStatus(MESSAGE_STATUS_FAILED);
1287 void Mms::sendCancel(int handle)
1289 LogDebug("sending message, id=" << getIdRef());
1291 LogDebug("handle =" << handle);
1294 void Mms::setSendingStatusOk()
1296 //success callback should be executed here
1297 ReqReceiverMessage *requestReceiver = getRequestReceiver();
1298 msg_struct_list_s *addr_list = NULL;
1299 char strNumber[MAX_ADDRESS_VAL_LEN] = {0,};
1302 if (requestReceiver) {
1303 LogInfo("calling JS success callback");
1304 EventMessagingServicePtr event = getMessagingServiceEvent();
1305 event->setExceptionCode(WrtDeviceApis::Commons::ExceptionCodes::None);
1307 msg_get_list_handle(m_messageData, MSG_MESSAGE_ADDR_LIST_STRUCT, (void **)&addr_list);
1309 nToCnt = addr_list->nCount;
1311 for ( int index=0; index < nToCnt; index++)
1313 msg_get_str_value(addr_list->msg_struct_info[0], MSG_ADDRESS_INFO_ADDRESS_VALUE_STR, strNumber, MAX_ADDRESS_VAL_LEN);
1314 event->m_successRecipients.push_back(strNumber);
1317 requestReceiver->WrtDeviceApis::Commons::EventRequestReceiver< EventMessagingService >::ManualAnswer(event);
1321 void Mms::setSendingStatusFailed()
1323 //error callback should be executed here
1324 EventOnSendingFailedEmitterPtr emitter = getEmitter();
1325 msg_struct_list_s *addr_list = NULL;
1326 char strNumber[MAX_ADDRESS_VAL_LEN] = {0,};
1331 EventOnSendingFailedPtr event(new EventOnSendingFailed);
1332 event->setError(EventOnSendingFailed::UNKNOWN); // TODO error codes
1333 emitter->emit(event);
1337 ReqReceiverMessage *requestReceiver = getRequestReceiver();
1338 if (requestReceiver)
1340 LogError("calling JS error callback");
1341 EventSendMessagePtr event = getSendMessageEvent();
1342 event->setExceptionCode(WrtDeviceApis::Commons::ExceptionCodes::UnknownException);
1344 msg_get_list_handle(m_messageData, MSG_MESSAGE_ADDR_LIST_STRUCT, (void **)&addr_list);
1346 nToCnt = addr_list->nCount;
1348 for ( int index=0; index < nToCnt; index++)
1350 msg_get_str_value(addr_list->msg_struct_info[index], MSG_ADDRESS_INFO_ADDRESS_VALUE_STR, strNumber, MAX_ADDRESS_VAL_LEN);
1351 event->m_failRecipients.push_back(strNumber);
1357 Api::Messaging::FolderType Mms::toFolder(const std::string &folder)
1359 if (folder == "INBOX") {
1361 } else if (folder == "OUTBOX") {
1363 } else if (folder == "SENTBOX") {
1365 } else if (folder == "DRAFTBOX") {
1368 ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Invalid folder");