#include "Messaging.h"
#include "CallbackMgr.h"
#include "MsgServiceHandleMgr.h"
+#include "WidgetFilePathMgr.h"
#include <Logger.h>
+#include <vconf.h>
extern "C" {
#include <msg.h>
namespace {
const char* TEXT_AREA = "Text";
const char* TEXT_FILE_EXTENSION = ".txt";
-const char* TEXT_DIR_PREFIX = "/tmp/";
+const char* TEXT_DIR_SEPERATOR = "/";
const int WHITE_COLOR = 0xffffff;
const int BLACK_COLOR = 0x000000;
const int ROOT_LAYOUT_WIDTH = 100;
Mms::Mms(const string& id) :
IMessage(MMS, id),
-// m_bodyFilePath(string(tmpnam(NULL)) + TEXT_FILE_EXTENSION),
m_messageData(NULL)
{
LoggerD("m_id=" << getIdRef());
- LoggerD("m_msgType=" << getMessageType());
char buf[] = "XXXXXX";
mode_t mask = umask(S_IWGRP | S_IWOTH);
LoggerD("buf : " << buf << " i : " << i);
umask(mask);
m_bodyFilePath = buf;
- m_bodyFilePath = TEXT_DIR_PREFIX+m_bodyFilePath+TEXT_FILE_EXTENSION;
-
- LoggerD("m_bodyFilePath : " << m_bodyFilePath);
+ m_bodyFilePath = getWidgetPath()+TEXT_DIR_SEPERATOR+m_bodyFilePath+TEXT_FILE_EXTENSION;
if (getIdRef().empty()) {
- LoggerD("create new message");
createNewMessage();
} else {
- LoggerD("read existing message");
readExistingMessage();
}
}
Mms::Mms(const string& id, const msg_struct_t msg_data) :
IMessage(MMS, id),
-// m_bodyFilePath(string(tmpnam(NULL)) + TEXT_FILE_EXTENSION),
- m_messageData(msg_data)
+ m_messageData(NULL)
{
LoggerD("m_id=" << getIdRef());
- LoggerD("m_msgType=" << getMessageType());
+
+ m_messageData = createNewCopyOfPLatformMsgWithAddressList(msg_data);
char buf[] = "XXXXXX";
mode_t mask = umask(S_IWGRP | S_IWOTH);
LoggerD("buf : " << buf << " i : " << i);
umask(mask);
m_bodyFilePath = buf;
- m_bodyFilePath = TEXT_DIR_PREFIX+m_bodyFilePath+TEXT_FILE_EXTENSION;
-
- LoggerD("m_bodyFilePath : " << m_bodyFilePath);
-
+ m_bodyFilePath = getWidgetPath()+TEXT_DIR_SEPERATOR+m_bodyFilePath+TEXT_FILE_EXTENSION;
+
readConversationId(m_messageData);
readRecipientList(m_messageData);
readPriority(m_messageData);
readDateTime(m_messageData);
readReadStatus(m_messageData);
readMessageStatus(m_messageData);
-// setMessageStatus(MESSAGE_STATUS_LOADED);
}
void Mms::readBody(msg_struct_t& messageData)
{
- int pageLen, mediaLen, attachLen, tempInt, ret;
+ int pageLen, mediaLen, tempInt, ret;
msg_struct_t mms_struct = NULL;
msg_list_handle_t page_list = NULL;
msg_list_handle_t media_list = NULL;
- msg_list_handle_t attach_list = NULL;
msg_struct_t page = NULL;
msg_struct_t media = NULL;
}
}
}
-
+ msg_release_struct(&mms_struct);
}
{
LoggerD("updating m_id=" << getIdRef());
msg_error_t err = MSG_SUCCESS;
+ int tempInt = 0;
+
msg_struct_t msg = NULL;
msg_struct_t sendOpt = NULL;
if (err != MSG_SUCCESS)
{
- LoggerE("Get Message Failed!");
- ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Failed to update message");
+ LoggerE("msg_get_message() Failed!");
+ ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Failed to get message for update");
}
if (this->getIdRef().empty()) {
ThrowMsg(WrtDeviceApis::Commons::PlatformException,
"existing msgId is zero, update msg not done");
}
-
+
+ err = msg_get_int_value(msg, MSG_MESSAGE_NETWORK_STATUS_INT, &tempInt);
+ if(err == MSG_SUCCESS)
+ {
+ msg_set_int_value(m_messageData, MSG_MESSAGE_NETWORK_STATUS_INT, tempInt);
+ }
+
+ err = msg_get_int_value(msg, MSG_MESSAGE_FOLDER_ID_INT, &tempInt);
+ if(err == MSG_SUCCESS)
+ {
+ msg_set_int_value(m_messageData, MSG_MESSAGE_FOLDER_ID_INT, tempInt);
+ }
+
update(TRUE);
if (MSG_SUCCESS != msg_update_message(MsgGetCommonHandle(), m_messageData, sendOpt))
{
- LoggerE("Failed to update message");
+ LoggerE("msg_update_message() Failed!");
ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Failed to update message");
}
msg_release_struct(&msg);
msg_release_struct(&msg);
msg_release_struct(&sendOpt);
LoggerE("platform error occurs");
+ ReThrow(WrtDeviceApis::Commons::PlatformException);
}
}
{
LoggerD("convert m_id= " << convertId(getIdRef()));
+ msg_struct_t sendOpt = NULL;
+
//prepare for add sms to draft folder
if (!m_messageData) {
//error if platform message not exists
Throw(WrtDeviceApis::Commons::PlatformException);
}
- //update all sms data
+ //update all mms data
if (getCurrentFolder() == DRAFTBOX) {
LoggerD("update all mms data");
updateSubject();
Try
{
int msgId = 0;
-// MSG_SENDINGOPT_S option = { false, false, false };
-// option.option.smsSendOpt.bReplyPath = true;
- // trying to get message from platform
+ sendOpt = msg_create_struct(MSG_STRUCT_SENDOPT);
+ // trying to add message
-// msg_struct_t sendOpt = msg_create_struct(MSG_STRUCT_SENDOPT);
-// msg_set_bool_value(sendOpt, MSG_SEND_OPT_SETTING_BOOL, false);
+// msg_set_int_value(m_messageData, MSG_MESSAGE_NETWORK_STATUS_INT, MSG_NETWORK_NOT_SEND);
+ int ret = msg_add_message(MsgGetCommonHandle(), m_messageData, sendOpt);
+ if (ret < MSG_SUCCESS) {
+ LoggerE("msg_add_message failed, error code=" << ret);
+ Throw(WrtDeviceApis::Commons::PlatformException);
+ }
+ else
+ {
+ msgId = ret;
+ }
-// const msg_folder_id_t platfromFolderId = Messaging::convertFolderToPlatform(DRAFTBOX);
+ LoggerD("Message ID : " << msgId);
-// msg_set_int_value(m_messageData, MSG_MESSAGE_ID_INT, msgId);
-// msg_set_int_value(m_messageData, MSG_MESSAGE_FOLDER_ID_INT, 4);
-// msg_set_int_value(m_messageData, MSG_MESSAGE_NETWORK_STATUS_INT, MSG_NETWORK_NOT_SEND);
+ msg_set_int_value(m_messageData, MSG_MESSAGE_ID_INT, msgId);
setId(convertId(msgId));
- setFolderType(DRAFTBOX);
+ loadDraftMessage();
+
+ setFolderType(OUTBOX);
setMessageStatus(MESSAGE_STATUS_DRAFT);
+
+ msg_release_struct(&sendOpt);
}
Catch(WrtDeviceApis::Commons::PlatformException) {
LoggerE("remove message error");
- if (m_messageData) {
- //releasing platform message structure
-// msg_release_message(&m_messageData);
- msg_release_struct(&m_messageData);
- }
+ msg_release_struct(&sendOpt);
throw;
}
-
}
void Mms::addMessageToDraft()
int Mms::send()
{
LoggerD("sending message, id=" << getIdRef());
+ msg_error_t err = MSG_SUCCESS;
+
Try
{
//prepare for sending sms/mms
update();
- LoggerD("Start Sending Message...");
-
LoggerD("trying to send mms");
- msg_error_t err = CallbackMgrSingleton::Instance().registerAndSend(msg_mms_send_message, m_messageData, this);
+ if (!getCellularOn())
+ {
+ err = MSG_ERR_TRANSPORT_ERROR;
+ LoggerW("MMS send error. No transport possible over network");
+ }
+ else
+ {
+ err = CallbackMgrSingleton::Instance().registerAndSend(msg_mms_send_message, m_messageData, this);
+ }
if (err != MSG_SUCCESS)
{
LoggerE("Sending Message (submit request) failed!!! err=" << err);
setMessageStatus(MESSAGE_STATUS_FAILED);
- goto ERROR;
+ Throw(WrtDeviceApis::Commons::PlatformException);
}
setMessageStatus(MESSAGE_STATUS_SENDING);
}
Catch(WrtDeviceApis::Commons::PlatformException) {
LoggerE("message is not send, manually run callback");
- goto ERROR;
+ ReqReceiverMessage *requestReceiver = getRequestReceiver();
+ if (requestReceiver) {
+ LoggerE("send Error");
+ EventMessagingServicePtr event = getMessagingServiceEvent();
+ if(err == MSG_ERR_TRANSPORT_ERROR)
+ {
+ event->setExceptionCode(WrtDeviceApis::Commons::ExceptionCodes::PlatformWrongStateException);
+ }
+ else
+ {
+ event->setExceptionCode(WrtDeviceApis::Commons::ExceptionCodes::UnknownException);
+ }
+ requestReceiver->WrtDeviceApis::Commons::EventRequestReceiver< EventMessagingService>::ManualAnswer(event);
+ }
}
return 0;
-
- ERROR:
- ReqReceiverMessage *requestReceiver = getRequestReceiver();
- if (requestReceiver) {
- LoggerE("send Error");
- EventMessagingServicePtr event = getMessagingServiceEvent();
- event->setExceptionCode(WrtDeviceApis::Commons::ExceptionCodes::UnknownException);
- requestReceiver->WrtDeviceApis::Commons::EventRequestReceiver< EventMessagingService>::ManualAnswer(event);
- }
- return 0;
}
void Mms::sendingCallback(msg_struct_t sent_status)
{
-// LoggerI("sendingCallback callback received. Req id = " <<
-// sent_status->reqId << " Status = " << (int)sent_status->status);
-// msg_struct_t request_data = NULL;
-// msg_get_struct_handle(sent_status, MSG_STRUCT_REQUEST_INFO, (void **)request_data);
-// msg_get_int_value(request_data, MSG_REQUEST_REQUESTID_INT, &tempInt);
int status = MSG_NETWORK_SEND_FAIL;
msg_get_int_value(sent_status, MSG_SENT_STATUS_NETWORK_STATUS_INT, &status);
for ( int index=0; index < nToCnt; index++)
{
- msg_get_str_value(addr_list->msg_struct_info[0], MSG_ADDRESS_INFO_ADDRESS_VALUE_STR, strNumber, MAX_ADDRESS_VAL_LEN);
+ msg_get_str_value(addr_list->msg_struct_info[index], MSG_ADDRESS_INFO_ADDRESS_VALUE_STR, strNumber, MAX_ADDRESS_VAL_LEN);
event->m_successRecipients.push_back(strNumber);
}
ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Invalid folder");
}
+bool Mms::getCellularOn()
+{
+ auto cellularOn = true;
+ int tempInt;
+ int tempbool;
+
+ vconf_get_int(VCONFKEY_TELEPHONY_SVCTYPE, &tempInt);
+ vconf_get_bool(VCONFKEY_TELEPHONY_FLIGHT_MODE, &tempbool);
+ if(tempInt <= VCONFKEY_TELEPHONY_SVCTYPE_SEARCH || tempbool == TRUE)
+ {
+ LoggerE("VCONFKEY_TELEPHONY_SVCTYPE error " << tempInt);
+ LoggerE("VCONFKEY_TELEPHONY_FLIGHT_MODE error " << tempbool);
+ cellularOn = false;
+ return cellularOn;
+ }
+
+ vconf_get_bool(VCONFKEY_3G_ENABLE, &tempbool);
+ vconf_get_int(VCONFKEY_TELEPHONY_SVC_PS, &tempInt);
+ if(tempbool == FALSE || tempInt != VCONFKEY_TELEPHONY_SVC_PS_ON)
+ {
+ LoggerE("VCONFKEY_3G_ENABLE error " << tempbool);
+ LoggerE("VCONFKEY_TELEPHONY_SVC_PS_ON error " << tempInt);
+ cellularOn = false;
+ }
+ return cellularOn;
+}
+
+
MimeType Mms::mimeTypeStringToIndexInt(std::string inputString)
{
const char* szMimeStr = inputString.c_str();
LoggerD("szMimeStr " << szMimeStr);
- for(int idx =0; mimeTable[idx].szMIME != NULL ; idx++)
+ for(int idx =0; strcmp(mimeTable[idx].szMIME, "") != 0; idx++)
{
if (!strcmp(mimeTable[idx].szMIME, szMimeStr)) {
retInt = mimeTable[idx].mime;
return retString;
}
+msg_struct_t Mms::createNewCopyOfPLatformMsgWithAddressList(const msg_struct_t src) const
+{
+ int tempInt, nCount, ret;
+ bool tempBool;
+ msg_struct_list_s *addr_list;
+ msg_struct_list_s *new_addr_list;
+
+ msg_struct_t mms_struct = NULL;
+ msg_struct_t mms_struct_dummy = NULL;
+
+ msg_struct_t msg = msg_create_struct(MSG_STRUCT_MESSAGE_INFO);
+
+ msg_set_int_value(msg, MSG_MESSAGE_TYPE_INT, MSG_TYPE_MMS);
+
+ char strSubject[MAX_SUBJECT_LEN] = {0};
+ msg_get_str_value(src, MSG_MESSAGE_SUBJECT_STR, strSubject, MAX_SUBJECT_LEN);
+ msg_set_str_value(msg, MSG_MESSAGE_SUBJECT_STR, strSubject, MAX_SUBJECT_LEN);
+
+ msg_get_int_value(src, MSG_MESSAGE_STORAGE_ID_INT, &tempInt);
+ msg_set_int_value(msg, MSG_MESSAGE_STORAGE_ID_INT, tempInt);
+
+ msg_get_int_value(src, MSG_MESSAGE_THREAD_ID_INT, &tempInt);
+ msg_set_int_value(msg, MSG_MESSAGE_THREAD_ID_INT, tempInt);
+
+ msg_get_int_value(src, MSG_MESSAGE_FOLDER_ID_INT, &tempInt);
+ msg_set_int_value(msg, MSG_MESSAGE_FOLDER_ID_INT, tempInt);
+
+// msg_get_int_value(src, MSG_MESSAGE_DATA_SIZE_INT, &tempInt);
+// char tempStr[tempInt+1];
+// memset(tempStr, 0, tempInt+1);
+
+// msg_get_str_value(src, MSG_MESSAGE_SMS_DATA_STR, tempStr, tempInt);
+// msg_set_str_value(msg, MSG_MESSAGE_SMS_DATA_STR, tempStr, strlen(tempStr));
+// copy mms body and attachment
+ mms_struct = msg_create_struct(MSG_STRUCT_MMS);
+ mms_struct_dummy = msg_create_struct(MSG_STRUCT_MMS);
+ ret = msg_get_mms_struct(src, mms_struct);
+ if (ret != MSG_SUCCESS)
+ {
+ LoggerE("cannot get mms struct");
+ ThrowMsg(WrtDeviceApis::Commons::PlatformException, "cannot get mms struct");
+ }
+
+ msg_set_mms_struct(src, mms_struct_dummy);
+ msg_set_mms_struct(msg, mms_struct);
+
+ msg_get_int_value(src, MSG_MESSAGE_DISPLAY_TIME_INT, &tempInt);
+ msg_set_int_value(msg, MSG_MESSAGE_DISPLAY_TIME_INT, tempInt);
+
+// msg_set_network_status(msg, msg_get_network_status(src));
+ msg_get_int_value(src, MSG_MESSAGE_NETWORK_STATUS_INT, &tempInt);
+ msg_set_int_value(msg, MSG_MESSAGE_NETWORK_STATUS_INT, tempInt);
+
+// msg_set_encode_type(msg, msg_get_encode_type(src));
+ msg_get_int_value(src, MSG_MESSAGE_ENCODE_TYPE_INT, &tempInt);
+ msg_set_int_value(msg, MSG_MESSAGE_ENCODE_TYPE_INT, tempInt);
+
+// msg_set_read_status(msg, msg_is_read(src));
+ msg_get_bool_value(src, MSG_MESSAGE_READ_BOOL, &tempBool);
+ msg_set_bool_value(msg, MSG_MESSAGE_READ_BOOL, tempBool);
+
+// msg_set_protect_status(msg, msg_is_protected(src));
+ msg_get_bool_value(src, MSG_MESSAGE_PROTECTED_BOOL, &tempBool);
+ msg_set_bool_value(msg, MSG_MESSAGE_PROTECTED_BOOL, tempBool);
+
+// msg_set_priority_info(msg, msg_get_priority_info(src));
+ msg_get_int_value(src, MSG_MESSAGE_PRIORITY_INT, &tempInt);
+ msg_set_int_value(msg, MSG_MESSAGE_PRIORITY_INT, tempInt);
+
+// msg_set_direction_info(msg, msg_get_direction_info(src));
+ msg_get_int_value(src, MSG_MESSAGE_DIRECTION_INT, &tempInt);
+ msg_set_int_value(msg, MSG_MESSAGE_DIRECTION_INT, tempInt);
+
+// msg_set_port(msg, msg_get_dest_port(src), msg_get_src_port(src));
+ msg_get_int_value(src, MSG_MESSAGE_DEST_PORT_INT, &tempInt);
+ msg_set_int_value(msg, MSG_MESSAGE_DEST_PORT_INT, tempInt);
+ msg_get_int_value(src, MSG_MESSAGE_SRC_PORT_INT, &tempInt);
+ msg_set_int_value(msg, MSG_MESSAGE_SRC_PORT_INT, tempInt);
+
+// copy addr list
+ msg_get_list_handle(src, MSG_MESSAGE_ADDR_LIST_STRUCT, (void **)&addr_list);
+ msg_get_list_handle(msg, MSG_MESSAGE_ADDR_LIST_STRUCT, (void **)&new_addr_list);
+
+ new_addr_list->nCount = addr_list->nCount;
+
+ for(int i=0; i<addr_list->nCount; i++)
+ {
+ msg_struct_t addr_info = NULL;
+ msg_struct_t new_addr_info = NULL;
+ char addr_value[MAX_ADDRESS_VAL_LEN] = {0,};
+
+ //get original address
+ addr_info = addr_list->msg_struct_info[i];
+ msg_get_str_value(addr_info, MSG_ADDRESS_INFO_ADDRESS_VALUE_STR, addr_value, MAX_ADDRESS_VAL_LEN);
+ msg_get_int_value(addr_info, MSG_ADDRESS_INFO_RECIPIENT_TYPE_INT, &tempInt);
+
+ //copy original address
+ new_addr_info = new_addr_list->msg_struct_info[i];
+ msg_set_str_value(new_addr_info, MSG_ADDRESS_INFO_ADDRESS_VALUE_STR, addr_value, MAX_ADDRESS_VAL_LEN);
+ msg_set_int_value(new_addr_info, MSG_ADDRESS_INFO_RECIPIENT_TYPE_INT, tempInt);
+ }
+
+ msg_release_struct(&mms_struct_dummy);
+ msg_release_struct(&mms_struct);
+
+ return msg;
+}
+
}
}