From: Maciek Blim Date: Thu, 8 Jan 2015 12:14:38 +0000 (+0100) Subject: [Messaging] SMS getMessageServices X-Git-Tag: submit/tizen_tv/20150603.064601~1^2~657^2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=5aeec3cfaeac60a2168757cbb0570f0bb94d8fa9;p=platform%2Fcore%2Fapi%2Fwebapi-plugins.git [Messaging] SMS getMessageServices Change-Id: I12bb11565c19741cd6dc8204aeccb634f11b690f Signed-off-by: Maciek Blim --- diff --git a/src/messaging/message_service_short_msg.cc b/src/messaging/message_service_short_msg.cc new file mode 100644 index 00000000..dc648bab --- /dev/null +++ b/src/messaging/message_service_short_msg.cc @@ -0,0 +1,160 @@ +// Copyright 2014 Samsung Electronics Co, Ltd. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. +// + +#include "message_service_short_msg.h" +#include "common/logger.h" +#include "common/platform_exception.h" + +#include +#include +#include + +//#include +//#include +//#include +//#include "ShortMsgManager.h" +//#include "JSMessage.h" + +//using namespace DeviceAPI::Common; + +namespace extension { +namespace messaging { + +MessageServiceShortMsg::MessageServiceShortMsg(int id, MessageType msgType) + : MessageService(id, + msgType, + MessagingUtil::messageTypeToString(msgType)) +{ + LoggerD("Entered"); +} + +MessageServiceShortMsg::~MessageServiceShortMsg() +{ + LoggerD("Entered"); +} + +static gboolean sendMessageThread(void* data) +{ + LoggerD("Entered"); + + auto callback = static_cast(data); + if (!callback) { + LoggerE("Callback is null"); + throw common::UnknownException("Callback is null"); + } + + // TODO + //ShortMsgManager::getInstance().sendMessage(callback); + return FALSE; +} + +void MessageServiceShortMsg::sendMessage(MessageRecipientsCallbackData *callback) +{ + if (!callback) { + LoggerE("Callback is null"); + throw common::UnknownException("Callback is null"); + } + + if (m_msg_type != callback->getMessage()->getType()) { + LoggerE("Incorrect message type"); + throw common::TypeMismatchException("Incorrect message type"); + } + + /* + * Set sim index. + * If user has set sim index manually, check sim index is valid. + * Otherwise, use default sim which is already set. + */ + TelNetworkDefaultDataSubs_t default_sim = + TAPI_NETWORK_DEFAULT_DATA_SUBS_UNKNOWN; + TapiHandle *handle = tel_init(NULL); + + int ret = tel_get_network_default_data_subscription(handle, &default_sim); + if (ret != TAPI_API_SUCCESS) { + LoggerE("Failed to find default sim index %d", ret); + } + + LoggerD("Default sim index: %d", default_sim); + callback->setDefaultSimIndex(default_sim); + tel_deinit(handle); + + // simIndex parameter is only available for sms message. + // In case of mms, the parameter is silently ignored. + if (callback->isSetSimIndex() && + callback->getMessage()->getType() == MessageType::SMS) { + char **cp_list = tel_get_cp_name_list(); + TelNetworkDefaultDataSubs_t sim_index = callback->getSimIndex(); + int sim_count = 0; + + if (cp_list) { + while (cp_list[sim_count]) { + sim_count++; + } + g_strfreev(cp_list); + } else { + LoggerD("Empty cp name list"); + } + + if (sim_index >= sim_count) { + LoggerE("Sim index out of count %d : %d", sim_index, sim_count); + throw common::InvalidValuesException("The index of sim is out of bound"); + } + + callback->getMessage()->setSimIndex(sim_index); + } else { + callback->getMessage()->setSimIndex(default_sim); + } + + if(!g_idle_add(sendMessageThread, static_cast(callback))) { + LoggerE("g_idle_add fails"); + throw common::UnknownException("Could not add task"); + } +} + +static gboolean loadMessageBodyTask(void* data) +{ + LoggerD("Entered"); + MessageBodyCallbackData* callback = static_cast(data); + if(!callback) { + LoggerE("callback is NULL"); + return FALSE; + } + + try { + // TODO call success callback + //JSContextRef context = callback->getContext(); + //JSObjectRef jsMessage = JSMessage::makeJSObject(context, callback->getMessage()); + //callback->callSuccessCallback(jsMessage); + } catch (...) { + LoggerE("Couldn't create JSMessage object!"); + // TODO call error callback + //callback->callErrorCallback(); + } + + return FALSE; +} + +void MessageServiceShortMsg::loadMessageBody(MessageBodyCallbackData *callback) +{ + if (!callback) { + LoggerE("Callback is null"); + throw common::UnknownException("Callback is null"); + } + + if (m_msg_type != callback->getMessage()->getType()) { + LoggerE("Incorrect message type"); + throw common::TypeMismatchException("Incorrect message type"); + } + + guint id = g_idle_add(loadMessageBodyTask, static_cast(callback)); + if (!id) { + LoggerE("g_idle_add fails"); + throw common::UnknownException("Could not add task"); + } +} + +} // namespace messaging +} // namespace extension + diff --git a/src/messaging/message_service_short_msg.h b/src/messaging/message_service_short_msg.h new file mode 100644 index 00000000..27489935 --- /dev/null +++ b/src/messaging/message_service_short_msg.h @@ -0,0 +1,26 @@ +// Copyright 2014 Samsung Electronics Co, Ltd. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef __MESSAGING_MESSAGE_SERVICE_SHORT_MSG_H__ +#define __MESSAGING_MESSAGE_SERVICE_SHORT_MSG_H__ + +#include "message_service.h" +#include "messaging_util.h" + +namespace extension { +namespace messaging { + +class MessageServiceShortMsg : public MessageService { +public: + MessageServiceShortMsg(int id, MessageType msgType); + virtual ~MessageServiceShortMsg(); + + void sendMessage(MessageRecipientsCallbackData *callback); + + virtual void loadMessageBody(MessageBodyCallbackData *callback); +}; + +} // namespace messaging +} // namespace extension +#endif // __MESSAGING_MESSAGE_SERVICE_SHORT_MSG_H__ diff --git a/src/messaging/messaging.gyp b/src/messaging/messaging.gyp index a5d32c44..de135e51 100644 --- a/src/messaging/messaging.gyp +++ b/src/messaging/messaging.gyp @@ -103,7 +103,9 @@ 'conversations_change_callback.cc', 'conversations_change_callback.h', 'folders_change_callback.cc', - 'folders_change_callback.h' + 'folders_change_callback.h', + 'message_service_short_msg.cc', + 'message_service_short_msg.h' ], 'includes': [ '../common/pkg-config.gypi', diff --git a/src/messaging/messaging_manager.cc b/src/messaging/messaging_manager.cc index 5b7498a2..5111a1b8 100755 --- a/src/messaging/messaging_manager.cc +++ b/src/messaging/messaging_manager.cc @@ -80,14 +80,32 @@ static void* getMsgServicesThread(const std::shared_ptr& bool isSupported = false; switch (type) { case MessageType::SMS: - LoggerD("Currently unsupported"); - // TODO add class which will extended message_service and call message_service_short_msg + LoggerD("MessageService for SMS"); + { + MessageService* service = new(std::nothrow) MessageServiceShortMsg( + MessageServiceAccountId::SMS_ACCOUNT_ID, + MessageType::SMS); + if (!service) { + LoggerE("MessageService for SMS creation failed"); + throw common::UnknownException("MessageService for email creation failed"); + } + + // TODO FIXME + picojson::array array; + array.push_back(picojson::value(service->toPicoJS())); + obj[JSON_DATA] = picojson::value(array); + obj[JSON_ACTION] = picojson::value(JSON_CALLBACK_SUCCCESS); + + delete service; + service = NULL; + } break; case MessageType::MMS: LoggerD("Currently unsupported"); // TODO add class which will extended message_service and call message_service_short_msg break; case MessageType::EMAIL: + // TODO FIXME need to work on readability of that case if (email_get_account_list(&email_accounts, &count) != EMAIL_ERROR_NONE) { LoggerE("Method failed: email_get_account_list()"); throw common::UnknownException("Error during getting account list"); diff --git a/src/messaging/messaging_manager.h b/src/messaging/messaging_manager.h index b584b446..a9de957e 100755 --- a/src/messaging/messaging_manager.h +++ b/src/messaging/messaging_manager.h @@ -10,6 +10,7 @@ #include #include "message_service_email.h" +#include "message_service_short_msg.h" namespace extension { namespace messaging {