From: Pawel Andruszkiewicz
Date: Mon, 9 Feb 2015 14:58:25 +0000 (+0100)
Subject: [Messaging] Removed throw/try/catch.
X-Git-Tag: submit/tizen_tv/20150603.064601~1^2~271
X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=d0bd874eb5af27f94445d4a8972b3a6ed5524175;p=platform%2Fcore%2Fapi%2Fwebapi-plugins.git
[Messaging] Removed throw/try/catch.
This commit consists of:
31e6edf [Messaging] Remove throw/try/catch from sendMessage().
1305c3d [Messaging] Remove throw/try/catch from loadMessageBody().
7a5c041 [Messaging] Remove throw/try/catch from getMessageServices().
b2e6686 [Messaging] Removed try/catch from addDraft method
fcda037 [Messaging] Remove throw/try/catch from loadMessageAttachment().
e50e5ec [Messaging] Remove throw/try/catch from sync().
409d9ab [Messaging] Remove throw/try/catch from syncFolder().
e222f4d [Messaging] Remove throw/try/catch from stopSync().
bfe0dd4 [Messaging] updateMessages and removeMessages refactored
10ad44d [Messaging] findMessages() refactored for Emails.
97fe5f7 [Messaging] try/catch removed from findConversations()
0cdd325 [Messaging] removeConversations and findFolders refactored
6e9f3d1 [Messaging] Filters refactored to not use throw
4f0aacb [Messaging] - Removing try and catch in MessageStorage
a90d5a9 [Messaging] remove try/catch next part
1723e3d [Messaging] refactored throws and error-related TODOs
0800313 [Messaging] Refactored callback cleaning and removed checking type in C++
01d4818 [Messaging] picojson .at() calls wrapped with if
9dc5931 [Messaging] Removing throws from ithe email manager constructor
7264508 [Messaging] - Checking service type in JS
ee97991 [Messaging] - Removing try and catch from DBus ditectory
64c13f7 [Messaging] Removed throws from filters.
MessagingEmail pass rate: 100%
MessagingMMS pass rate: 100%
MessagingSMS pass rate: 100%
Change-Id: I4422236b59725ed6704a02b57f0ecda721f5809e
(cherry picked from commit 101612406b8beed50fa8b878b11631920478184c)
---
diff --git a/src/messaging/DBus/Connection.cpp b/src/messaging/DBus/Connection.cpp
index c39d01bd..d912671d 100644
--- a/src/messaging/DBus/Connection.cpp
+++ b/src/messaging/DBus/Connection.cpp
@@ -17,7 +17,6 @@
#include "Connection.h"
#include "common/logger.h"
-#include "common/platform_exception.h"
#include
#include
#include "../message_service.h"
diff --git a/src/messaging/DBus/EmailSignalProxy.cpp b/src/messaging/DBus/EmailSignalProxy.cpp
index 8f8739d5..ab80f51b 100644
--- a/src/messaging/DBus/EmailSignalProxy.cpp
+++ b/src/messaging/DBus/EmailSignalProxy.cpp
@@ -22,7 +22,6 @@
#include "EmailSignalProxy.h"
#include "common/logger.h"
#include
-#include "common/platform_exception.h"
namespace extension {
namespace messaging {
@@ -53,29 +52,21 @@ void EmailSignalProxy::signalCallback(GDBusConnection* connection,
int status, mail_id, op_handle, error_code;
char* source = NULL;
- try {
- g_variant_get(parameters, "(iisii)",
- &status,
- &mail_id,
- &source,
- &op_handle,
- &error_code);
+ g_variant_get(parameters, "(iisii)",
+ &status,
+ &mail_id,
+ &source,
+ &op_handle,
+ &error_code);
- //It is better to log this only when subclass is responsible of handling
- //passed signal (usually determined by status value).
- //
- //LoggerD("email:\n status: %d\n mail_id: %d\n "
- // "source: %s\n op_handle: %d\n error_code: %d",
- // status, mail_id, source, op_handle, error_code);
+ //It is better to log this only when subclass is responsible of handling
+ //passed signal (usually determined by status value).
+ //
+ //LoggerD("email:\n status: %d\n mail_id: %d\n "
+ // "source: %s\n op_handle: %d\n error_code: %d",
+ // status, mail_id, source, op_handle, error_code);
- handleEmailSignal(status, mail_id, source, op_handle, error_code);
-
- } catch(const common::PlatformException& exception) {
- LoggerE("Unhandled exception: %s (%s)!", (exception.name()).c_str(),
- (exception.message()).c_str());
- } catch(...) {
- LoggerE("Unhandled exception!");
- }
+ handleEmailSignal(status, mail_id, source, op_handle, error_code);
g_free(source);
}
diff --git a/src/messaging/DBus/EmailSignalProxy.h b/src/messaging/DBus/EmailSignalProxy.h
index 74789815..9791f4b3 100644
--- a/src/messaging/DBus/EmailSignalProxy.h
+++ b/src/messaging/DBus/EmailSignalProxy.h
@@ -33,11 +33,12 @@ typedef std::shared_ptr EmailSignalProxyPtr;
class EmailSignalProxy : public Proxy {
public:
- EmailSignalProxy(const std::string& proxy_path,
- const std::string& proxy_iface);
virtual ~EmailSignalProxy();
protected:
+ EmailSignalProxy(const std::string& proxy_path,
+ const std::string& proxy_iface);
+
/**
* Override this method in subclass to handle email signal
*/
diff --git a/src/messaging/DBus/LoadAttachmentProxy.cpp b/src/messaging/DBus/LoadAttachmentProxy.cpp
index f875898b..31624797 100644
--- a/src/messaging/DBus/LoadAttachmentProxy.cpp
+++ b/src/messaging/DBus/LoadAttachmentProxy.cpp
@@ -22,7 +22,7 @@
#include "LoadAttachmentProxy.h"
#include "common/logger.h"
-#include "common/platform_exception.h"
+#include "common/platform_result.h"
#include
#include
@@ -37,11 +37,13 @@ namespace extension {
namespace messaging {
namespace DBus {
+using namespace common;
+
/**
* This method perform very specified task (see warning comment) so it should not be
* visible outside LoadAttachmentProxy class.
*/
-void updateAttachmentDataWithEmailGetAttachmentData(
+PlatformResult updateAttachmentDataWithEmailGetAttachmentData(
std::shared_ptr attachment)
{
struct ScopedEmailAttachmentData {
@@ -72,7 +74,7 @@ void updateAttachmentDataWithEmailGetAttachmentData(
if (EMAIL_ERROR_NONE != err ||
NULL == attachment_data_holder.data) {
LoggerE("Couldn't get attachment data for attachmentId:%d", attachment->getId());
- throw common::UnknownException("Couldn't get attachment.");
+ return PlatformResult(ErrorCode::UNKNOWN_ERR, "Couldn't get attachment.");
}
LoggerD("attachment name : %s", attachment_data_holder->attachment_name);
@@ -91,6 +93,7 @@ void updateAttachmentDataWithEmailGetAttachmentData(
}
isSaved = attachment_data_holder->save_status;
attachment->setIsSaved(isSaved);
+ return PlatformResult(ErrorCode::NO_ERROR);
}
LoadAttachmentProxy::LoadAttachmentProxy(const std::string& path,
@@ -103,6 +106,19 @@ LoadAttachmentProxy::~LoadAttachmentProxy()
{
}
+PlatformResult LoadAttachmentProxy::create(const std::string& path,
+ const std::string& iface,
+ LoadAttachmentProxyPtr* load_attachment_proxy) {
+ load_attachment_proxy->reset(new LoadAttachmentProxy(path, iface));
+ if ((*load_attachment_proxy)->isNotProxyGot()) {
+ LoggerE("Could not get load attachment proxy");
+ load_attachment_proxy->reset();
+ return PlatformResult(ErrorCode::UNKNOWN_ERR, "Could not get load attachment proxy");
+ } else {
+ return PlatformResult(ErrorCode::NO_ERROR);
+ }
+}
+
void LoadAttachmentProxy::addCallback(MessageAttachmentCallbackData* callbackOwned)
{
if(callbackOwned->getMessageAttachment()) {
@@ -167,68 +183,50 @@ void LoadAttachmentProxy::handleEmailSignal(const int status,
// and not handle returned from above call!!
const int nth = op_handle;
- try {
- // From old implementation it looks that op_handle(nth) is is equal to
- // index (1 based) of attachment inside email thus it is not globally unique!
- // Therfore we need to test if mail_id match.
- // For details see old implementation MailSync.cp line 461
-
- callback = findCallback(nth, mail_id);
- if(!callback) {
- //We should not log not found pair since it could be requested by
- //different application.
- return;
- }
+ // From old implementation it looks that op_handle(nth) is is equal to
+ // index (1 based) of attachment inside email thus it is not globally unique!
+ // Therfore we need to test if mail_id match.
+ // For details see old implementation MailSync.cp line 461
+
+ callback = findCallback(nth, mail_id);
+ if(!callback) {
+ //We should not log not found pair since it could be requested by
+ //different application.
+ return;
+ }
- LoggerD("Found callback for pair mailId:%d nth:%d", mail_id, nth);
+ LoggerD("Found callback for pair mailId:%d nth:%d", mail_id, nth);
- if(NOTI_DOWNLOAD_ATTACH_FINISH == status) {
- LoggerD("Message attachment downloaded!");
+ PlatformResult ret = PlatformResult(ErrorCode::NO_ERROR);
+ if(NOTI_DOWNLOAD_ATTACH_FINISH == status) {
+ LoggerD("Message attachment downloaded!");
- std::shared_ptr att = callback->getMessageAttachment();
- updateAttachmentDataWithEmailGetAttachmentData(att);
+ std::shared_ptr att = callback->getMessageAttachment();
+ ret = updateAttachmentDataWithEmailGetAttachmentData(att);
+ if (!ret.IsError()) {
LoggerD("Updated Message attachment object");
- try {
- auto json = callback->getJson();
- picojson::object& obj = json->get();
- obj[JSON_ACTION] = picojson::value(JSON_CALLBACK_SUCCCESS);
-
- picojson::object args;
- args[JSON_DATA_MESSAGE_ATTACHMENT] = MessagingUtil::messageAttachmentToJson(
- callback->getMessageAttachment());
- obj[JSON_DATA] = picojson::value(args);
-
- PostQueue::getInstance().resolve(
- obj.at(JSON_CALLBACK_ID).get(),
- json->serialize()
- );
- } catch (...) {
- LoggerW("Couldn't create JSMessageAttachment object!");
- throw common::UnknownException(
- "Couldn't create JSMessageAttachment object!");
- }
+ auto json = callback->getJson();
+ picojson::object& obj = json->get();
+ obj[JSON_ACTION] = picojson::value(JSON_CALLBACK_SUCCCESS);
+
+ picojson::object args;
+ args[JSON_DATA_MESSAGE_ATTACHMENT] = MessagingUtil::messageAttachmentToJson(
+ callback->getMessageAttachment());
+ obj[JSON_DATA] = picojson::value(args);
- } else if(NOTI_DOWNLOAD_ATTACH_FAIL) {
- LoggerD("Load message attachment failed!");
- common::UnknownException e("Load message attachment failed!");
- callback->setError(e.name(), e.message());
PostQueue::getInstance().resolve(
- callback->getJson()->get().at(JSON_CALLBACK_ID).get(),
- callback->getJson()->serialize()
+ obj.at(JSON_CALLBACK_ID).get(),
+ json->serialize()
);
}
- } catch (const common::PlatformException& e) {
- LoggerE("Exception in signal callback");
- callback->setError(e.name(), e.message());
- PostQueue::getInstance().resolve(
- callback->getJson()->get().at(JSON_CALLBACK_ID).get(),
- callback->getJson()->serialize()
- );
- } catch (...) {
+ } else if(NOTI_DOWNLOAD_ATTACH_FAIL) {
+ LoggerD("Load message attachment failed!");
+ ret = PlatformResult(ErrorCode::UNKNOWN_ERR, "Load message attachment failed!");
+ }
+ if (ret.IsError()) {
LoggerE("Exception in signal callback");
- common::UnknownException e("Exception in signal callback");
- callback->setError(e.name(), e.message());
+ callback->setError(ret);
PostQueue::getInstance().resolve(
callback->getJson()->get().at(JSON_CALLBACK_ID).get(),
callback->getJson()->serialize()
diff --git a/src/messaging/DBus/LoadAttachmentProxy.h b/src/messaging/DBus/LoadAttachmentProxy.h
index 8e3f2f38..9a163c18 100644
--- a/src/messaging/DBus/LoadAttachmentProxy.h
+++ b/src/messaging/DBus/LoadAttachmentProxy.h
@@ -22,6 +22,7 @@
#ifndef __TIZEN_DBUS_LOAD_ATTACHMENT_PROXY_H__
#define __TIZEN_DBUS_LOAD_ATTACHMENT_PROXY_H__
+#include "common/platform_result.h"
#include "EmailSignalProxy.h"
#include
@@ -41,15 +42,18 @@ public:
// Callback is owned by this set
typedef std::set CallbackSet;
- LoadAttachmentProxy(const std::string& path,
- const std::string& iface);
virtual ~LoadAttachmentProxy();
+ static common::PlatformResult create(const std::string& path,
+ const std::string& iface,
+ LoadAttachmentProxyPtr* load_attachment_proxy);
//Passed callback will be owned by this proxy
void addCallback(MessageAttachmentCallbackData* callbackOwned);
void removeCallback(MessageAttachmentCallbackData* callback);
protected:
+ LoadAttachmentProxy(const std::string& path,
+ const std::string& iface);
virtual void handleEmailSignal(const int status,
const int mail_id,
const std::string& source,
diff --git a/src/messaging/DBus/LoadBodyProxy.cpp b/src/messaging/DBus/LoadBodyProxy.cpp
index 68cb03b6..5c0d8cb9 100644
--- a/src/messaging/DBus/LoadBodyProxy.cpp
+++ b/src/messaging/DBus/LoadBodyProxy.cpp
@@ -35,7 +35,7 @@
#include "common/logger.h"
#include
-#include "common/platform_exception.h"
+#include "common/platform_result.h"
#include "../message.h"
#include "../message_body.h"
@@ -45,16 +45,29 @@ namespace extension {
namespace messaging {
namespace DBus {
+using namespace common;
+
LoadBodyProxy::LoadBodyProxy(const std::string& path,
const std::string& iface) :
EmailSignalProxy(path, iface)
{
-
}
LoadBodyProxy::~LoadBodyProxy()
{
+}
+PlatformResult LoadBodyProxy::create(const std::string& path,
+ const std::string& iface,
+ LoadBodyProxyPtr* load_body_proxy) {
+ load_body_proxy->reset(new LoadBodyProxy(path, iface));
+ if ((*load_body_proxy)->isNotProxyGot()) {
+ LoggerE("Could not get load body proxy");
+ load_body_proxy->reset();
+ return PlatformResult(ErrorCode::UNKNOWN_ERR, "Could not get load body proxy");
+ } else {
+ return PlatformResult(ErrorCode::NO_ERROR);
+ }
}
void LoadBodyProxy::addCallback(MessageBodyCallbackData* callbackOwned)
@@ -125,105 +138,82 @@ void LoadBodyProxy::handleEmailSignal(const int status,
}
MessageBodyCallbackData* callback = NULL;
- try {
- callback = findCallbackByOpHandle(op_handle);
- if (!callback) {
- LoggerE("Callback is null");
- } else {
- if( (NOTI_DOWNLOAD_BODY_FINISH == status) ||
- (NOTI_DOWNLOAD_BODY_FAIL == status &&
- EMAIL_ERROR_MAIL_IS_ALREADY_DOWNLOADED == error_code)) {
-
- // Old implementation is not verifying whether message update failed,
- // it just calls success callback.
- if(callback->getMessage()) {
- email_mail_data_t* mail_data = EmailManager::loadMessage(
- callback->getMessage()->getId());
- if (mail_data) {
- callback->getMessage()->updateEmailMessage(*mail_data);
+
+ callback = findCallbackByOpHandle(op_handle);
+ if (!callback) {
+ LoggerE("Callback is null");
+ } else {
+ PlatformResult ret = PlatformResult(ErrorCode::NO_ERROR);
+ if( (NOTI_DOWNLOAD_BODY_FINISH == status) ||
+ (NOTI_DOWNLOAD_BODY_FAIL == status &&
+ EMAIL_ERROR_MAIL_IS_ALREADY_DOWNLOADED == error_code)) {
+
+ // Old implementation is not verifying whether message update failed,
+ // it just calls success callback.
+ if(callback->getMessage()) {
+ email_mail_data_t* mail_data = EmailManager::loadMessage(
+ callback->getMessage()->getId());
+ if (mail_data) {
+ ret = callback->getMessage()->updateEmailMessage(*mail_data);
+ if (!ret.IsError()) {
EmailManager::freeMessage(mail_data);
mail_data = NULL;
}
-
- //TODO: this should be reviewed when attachments and
- // loadAttachments have been completed.
- //TODO: see old implementation lines 608-635 in MailSync.cpp
- /*
- * This is original Messaging implementation:
- *
- * std::vector attachments = mail->getAttachments();
- * std::vector inlineAttachments = mail->getInlineAttachments();
- *
- * for (unsigned int idx = 0; idx < attachments.size() ; idx++ )
- * {
- * LoggerD("set Attachment ID = " << attachments[idx]->getAttachmentID());
- * attachments[idx]->setMessage(event->m_message);
- *
- * }
- * for (unsigned int idx = 0; idx < inlineAttachments.size() ; idx++ )
- * {
- * LoggerD("set inline Attachment ID = " << inlineAttachments[idx]->getAttachmentID());
- * inlineAttachments[idx]->setMessage(event->m_message);
- * }
- */
}
- LoggerD("Message body downloaded!");
- try {
- LoggerD("Calling success callback");
-
- auto json = callback->getJson();
- picojson::object& obj = json->get();
- obj[JSON_ACTION] = picojson::value(JSON_CALLBACK_SUCCCESS);
-
- picojson::object args;
- args[JSON_DATA_MESSAGE_BODY] = MessagingUtil::messageBodyToJson(
- callback->getMessage()->getBody());
- obj[JSON_DATA] = picojson::value(args);
-
- PostQueue::getInstance().resolve(
- obj.at(JSON_CALLBACK_ID).get(),
- json->serialize()
- );
- } catch (...) {
- LoggerW("Couldn't create JSMessage object!");
- throw common::UnknownException(
- "Couldn't create JSMessage object!");
- }
+ //TODO: this should be reviewed when attachments and
+ // loadAttachments have been completed.
+ //TODO: see old implementation lines 608-635 in MailSync.cpp
+ //
+ // This is original Messaging implementation:
+ //
+ // std::vector attachments = mail->getAttachments();
+ // std::vector inlineAttachments = mail->getInlineAttachments();
+ //
+ // for (unsigned int idx = 0; idx < attachments.size() ; idx++ )
+ // {
+ // LoggerD("set Attachment ID = " << attachments[idx]->getAttachmentID());
+ // attachments[idx]->setMessage(event->m_message);
+ //
+ // }
+ // for (unsigned int idx = 0; idx < inlineAttachments.size() ; idx++ )
+ // {
+ // LoggerD("set inline Attachment ID = " << inlineAttachments[idx]->getAttachmentID());
+ // inlineAttachments[idx]->setMessage(event->m_message);
+ // }
+ //
+ }
- } else if(NOTI_DOWNLOAD_BODY_FAIL == status) {
- LoggerD("Load message body failed!");
+ if (!ret.IsError()) {
+ LoggerD("Calling success callback");
+
+ auto json = callback->getJson();
+ picojson::object& obj = json->get();
+ obj[JSON_ACTION] = picojson::value(JSON_CALLBACK_SUCCCESS);
+
+ picojson::object args;
+ args[JSON_DATA_MESSAGE_BODY] = MessagingUtil::messageBodyToJson(
+ callback->getMessage()->getBody());
+ obj[JSON_DATA] = picojson::value(args);
- common::UnknownException e("Load message body failed!");
- callback->setError(e.name(), e.message());
PostQueue::getInstance().resolve(
- callback->getJson()->get().at(JSON_CALLBACK_ID).get(),
- callback->getJson()->serialize()
+ obj.at(JSON_CALLBACK_ID).get(),
+ json->serialize()
);
}
+ } else if(NOTI_DOWNLOAD_BODY_FAIL == status) {
+ LoggerD("Load message body failed!");
+ ret = PlatformResult(ErrorCode::UNKNOWN_ERR, "Load message body failed!");
+ }
+
+ if (ret.IsError()) {
+ callback->setError(ret);
+ PostQueue::getInstance().resolve(
+ callback->getJson()->get().at(JSON_CALLBACK_ID).get(),
+ callback->getJson()->serialize()
+ );
}
- }
- catch (const common::PlatformException& e) {
- LoggerE("Exception in signal callback");
-
- callback->setError(e.name(), e.message());
- PostQueue::getInstance().resolve(
- callback->getJson()->get().at(JSON_CALLBACK_ID).get(),
- callback->getJson()->serialize()
- );
- }
- catch (...) {
- LoggerE("Exception in signal callback");
-
- common::UnknownException e("Load message body failed!");
- callback->setError(e.name(), e.message());
- PostQueue::getInstance().resolve(
- callback->getJson()->get().at(JSON_CALLBACK_ID).get(),
- callback->getJson()->serialize()
- );
- }
- if(callback) {
removeCallback(callback);
delete callback;
}
diff --git a/src/messaging/DBus/LoadBodyProxy.h b/src/messaging/DBus/LoadBodyProxy.h
index 0ed55090..69f29c30 100644
--- a/src/messaging/DBus/LoadBodyProxy.h
+++ b/src/messaging/DBus/LoadBodyProxy.h
@@ -22,6 +22,7 @@
#ifndef __TIZEN_DBUS_LOAD_BODY_PROXY_H__
#define __TIZEN_DBUS_LOAD_BODY_PROXY_H__
+#include "common/platform_result.h"
#include "EmailSignalProxy.h"
#include
@@ -41,15 +42,18 @@ public:
// Callback is owned by this set
typedef std::set CallbackSet;
- LoadBodyProxy(const std::string& path,
- const std::string& iface);
virtual ~LoadBodyProxy();
+ static common::PlatformResult create(const std::string& path,
+ const std::string& iface,
+ LoadBodyProxyPtr* load_body_proxy);
//Passed callback will be owned by this proxy
void addCallback(MessageBodyCallbackData* callbackOwned);
void removeCallback(MessageBodyCallbackData* callback);
protected:
+ LoadBodyProxy(const std::string& path,
+ const std::string& iface);
virtual void handleEmailSignal(const int status,
const int mail_id,
const std::string& source,
diff --git a/src/messaging/DBus/MessageProxy.cpp b/src/messaging/DBus/MessageProxy.cpp
index 2c1dd059..b986adef 100644
--- a/src/messaging/DBus/MessageProxy.cpp
+++ b/src/messaging/DBus/MessageProxy.cpp
@@ -17,24 +17,20 @@
#include "MessageProxy.h"
#include "Connection.h"
-
#include "common/logger.h"
-#include "common/platform_exception.h"
-
#include "../message.h"
#include "../message_email.h"
-
#include "../message_conversation.h"
//#include
-
#include "../change_listener_container.h"
-
#include "../email_manager.h"
namespace extension {
namespace messaging {
namespace DBus {
+using namespace common;
+
MessageProxy::MessageProxy():
Proxy(Proxy::DBUS_PATH_EMAIL_STORAGE_CHANGE,
Proxy::DBUS_IFACE_EMAIL_STORAGE_CHANGE,
@@ -48,6 +44,17 @@ MessageProxy::~MessageProxy()
{
}
+PlatformResult MessageProxy::create(MessageProxyPtr* message_proxy) {
+ message_proxy->reset(new MessageProxy());
+ if ((*message_proxy)->isNotProxyGot()) {
+ LoggerE("Could not get proxy");
+ message_proxy->reset();
+ return PlatformResult(ErrorCode::UNKNOWN_ERR, "Could not get proxy");
+ } else {
+ return PlatformResult(ErrorCode::NO_ERROR);
+ }
+}
+
void MessageProxy::signalCallback(GDBusConnection *connection,
const gchar *sender_name,
const gchar *object_path,
@@ -70,44 +77,42 @@ void MessageProxy::signalCallback(GDBusConnection *connection,
LoggerD("name: %s", name);
LoggerD("thread_id: %d", thread_id);
- try {
- switch (status) {
- case NOTI_MAIL_ADD:
- case NOTI_MAIL_UPDATE:
- handleEmailEvent(account_id, object_id, thread_id, status);
- break;
- case NOTI_MAIL_DELETE:
- //ids of removing messages are sent with name in format:
- //id1,id2,id3,
- handleEmailRemoveEvent(account_id, name);
- break;
- case NOTI_MAIL_DELETE_FINISH:
- case NOTI_MAIL_DELETE_FAIL:
- //notify EmailManager, maybe it tries to delete mail
- notifyEmailManager(name, static_cast(status));
- break;
- case NOTI_THREAD_DELETE:
- handleThreadRemoveEvent(account_id, object_id);
- break;
- case NOTI_MAILBOX_ADD:
- case NOTI_MAILBOX_UPDATE:
- case NOTI_MAILBOX_FIELD_UPDATE:
- case NOTI_MAILBOX_RENAME:
- case NOTI_MAILBOX_DELETE:
- handleMailboxEvent(account_id, object_id, status);
- break;
- default:
- LoggerD("Unrecognized status: %d", status);
- }
- } catch (const common::PlatformException& err) {
- LoggerE("%s (%s)", (err.name()).c_str(), (err.message()).c_str());
- } catch (...) {
- LoggerE("Failed to call callback");
+ PlatformResult ret(ErrorCode::NO_ERROR);
+ switch (status) {
+ case NOTI_MAIL_ADD:
+ case NOTI_MAIL_UPDATE:
+ ret = handleEmailEvent(account_id, object_id, thread_id, status);
+ break;
+ case NOTI_MAIL_DELETE:
+ //ids of removing messages are sent with name in format:
+ //id1,id2,id3,
+ handleEmailRemoveEvent(account_id, name);
+ break;
+ case NOTI_MAIL_DELETE_FINISH:
+ case NOTI_MAIL_DELETE_FAIL:
+ //notify EmailManager, maybe it tries to delete mail
+ notifyEmailManager(name, static_cast(status));
+ break;
+ case NOTI_THREAD_DELETE:
+ handleThreadRemoveEvent(account_id, object_id);
+ break;
+ case NOTI_MAILBOX_ADD:
+ case NOTI_MAILBOX_UPDATE:
+ case NOTI_MAILBOX_FIELD_UPDATE:
+ case NOTI_MAILBOX_RENAME:
+ case NOTI_MAILBOX_DELETE:
+ ret = handleMailboxEvent(account_id, object_id, status);
+ break;
+ default:
+ LoggerD("Unrecognized status: %d", status);
+ }
+ if (ret.IsError()){
+ LoggerE("%d (%s)", ret.error_code(), (ret.message()).c_str());
}
g_free(name);
}
-void MessageProxy::handleEmailEvent(int account_id, int mail_id, int thread_id, int event)
+PlatformResult MessageProxy::handleEmailEvent(int account_id, int mail_id, int thread_id, int event)
{
LoggerD("Enter");
@@ -119,7 +124,10 @@ void MessageProxy::handleEmailEvent(int account_id, int mail_id, int thread_id,
if (mail_data) email_free_mail_data(&mail_data, 1);
LoggerE("Failed to get mail data during setting conversation id in MessageProxy.");
- return;
+ //TODO maybe error should be ignored
+ return PlatformResult(ErrorCode::UNKNOWN_ERR,
+ "Failed to get mail data during setting"
+ " conversation id in MessageProxy.");
}
thread_id = mail_data->thread_id;
@@ -131,11 +139,15 @@ void MessageProxy::handleEmailEvent(int account_id, int mail_id, int thread_id,
email_mail_data_t* mail_data = EmailManager::getInstance().loadMessage(mail_id);
if (mail_data == NULL) {
- throw common::UnknownException("Failed to load email");
+ return PlatformResult(ErrorCode::UNKNOWN_ERR, "Failed to load email");
}
- std::shared_ptr msg = Message::convertPlatformEmailToObject(*mail_data);
- ConversationPtr conv = MessageConversation::convertEmailConversationToObject(
- thread_id);
+ std::shared_ptr msg;
+ PlatformResult ret = Message::convertPlatformEmailToObject(*mail_data, &msg);
+ if (ret.IsError()) return ret;
+ ConversationPtr conv;
+ ret = MessageConversation::convertEmailConversationToObject(
+ thread_id, &conv);
+ if (ret.IsError()) return ret;
EventMessages* eventMsg = new EventMessages();
eventMsg->service_type = MessageType::EMAIL;
@@ -169,6 +181,7 @@ void MessageProxy::handleEmailEvent(int account_id, int mail_id, int thread_id,
delete eventConv;
EmailManager::getInstance().freeMessage(mail_data);
+ return PlatformResult(ErrorCode::NO_ERROR);
}
std::vector getMailIds(const std::string& idsString)
@@ -242,7 +255,7 @@ void MessageProxy::handleThreadRemoveEvent(int account_id, int thread_id)
eventConv = NULL;
}
-void MessageProxy::handleMailboxEvent(int account_id, int mailbox_id, int event)
+PlatformResult MessageProxy::handleMailboxEvent(int account_id, int mailbox_id, int event)
{
LoggerD("Enter");
EventFolders* eventFolder = new EventFolders();
@@ -265,7 +278,7 @@ void MessageProxy::handleMailboxEvent(int account_id, int mailbox_id, int event)
if (EMAIL_ERROR_NONE != email_get_mailbox_by_mailbox_id(mailbox_id, &mail_box)) {
LoggerE("Mailbox not retrieved");
delete eventFolder;
- throw common::UnknownException("Failed to load mailbox");
+ return PlatformResult(ErrorCode::UNKNOWN_ERR, "Failed to load mailbox");
}
folder.reset(new MessageFolder(*mail_box));
if (EMAIL_ERROR_NONE != email_free_mailbox(&mail_box, 1)) {
@@ -288,6 +301,7 @@ void MessageProxy::handleMailboxEvent(int account_id, int mailbox_id, int event)
LoggerW("Unknown event type: %d", event);
}
delete eventFolder;
+ return PlatformResult(ErrorCode::NO_ERROR);
}
} //namespace DBus
diff --git a/src/messaging/DBus/MessageProxy.h b/src/messaging/DBus/MessageProxy.h
index 1b8f040f..81e8a3bc 100644
--- a/src/messaging/DBus/MessageProxy.h
+++ b/src/messaging/DBus/MessageProxy.h
@@ -26,16 +26,21 @@
#include
#include
#include "Proxy.h"
+#include "common/platform_result.h"
namespace extension {
namespace messaging {
namespace DBus {
+class MessageProxy;
+typedef std::shared_ptr MessageProxyPtr;
+
class MessageProxy: public Proxy {
public:
- MessageProxy();
virtual ~MessageProxy();
+ static common::PlatformResult create(MessageProxyPtr* message_proxy);
protected:
+ MessageProxy();
virtual void signalCallback(GDBusConnection *connection,
const gchar *sender_name,
const gchar *object_path,
@@ -49,15 +54,13 @@ protected:
* @param thread_id
* @param event
*/
- void handleEmailEvent(int account_id, int mail_id, int thread_id, int event);
+ common::PlatformResult handleEmailEvent(int account_id, int mail_id, int thread_id, int event);
void handleEmailRemoveEvent(int account_id, const std::string& idsString);
void notifyEmailManager(const std::string& idsString, email_noti_on_storage_event status);
void handleThreadRemoveEvent(int account_id, int thread_id);
- void handleMailboxEvent(int account_id, int mailbox_id, int event);
+ common::PlatformResult handleMailboxEvent(int account_id, int mailbox_id, int event);
};
-typedef std::shared_ptr MessageProxyPtr;
-
} //namespace DBus
} //namespace messaging
} //namespace extension
diff --git a/src/messaging/DBus/Proxy.cpp b/src/messaging/DBus/Proxy.cpp
index c7c817e2..2dddfb1b 100644
--- a/src/messaging/DBus/Proxy.cpp
+++ b/src/messaging/DBus/Proxy.cpp
@@ -21,7 +21,7 @@
#include "Proxy.h"
#include "common/logger.h"
-#include "common/platform_exception.h"
+#include "common/platform_result.h"
#include
#include
#include "../message_service.h"
@@ -30,6 +30,8 @@ namespace extension {
namespace messaging {
namespace DBus {
+using namespace common;
+
const char* Proxy::DBUS_PATH_NETWORK_STATUS = "/User/Email/NetworkStatus";
const char* Proxy::DBUS_IFACE_NETWORK_STATUS = "User.Email.NetworkStatus";
const char* Proxy::DBUS_PATH_EMAIL_STORAGE_CHANGE = "/User/Email/StorageChange";
@@ -65,10 +67,6 @@ Proxy::Proxy(const std::string& proxy_path,
m_proxy = g_dbus_proxy_new_sync(m_conn.getDBus(),
G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES,
NULL, unique_name, m_path.c_str(), m_iface.c_str(), NULL, &m_error);
- if (!m_proxy || m_error) {
- LoggerE("Could not get proxy");
- throw common::UnknownException("Could not get proxy");
- }
}
Proxy::~Proxy()
@@ -90,21 +88,12 @@ void Proxy::signalCallbackProxy(GDBusConnection *connection,
return;
}
- try {
- //It is better to log this only when subclass is responsible of handling
- //passed signal. If you need it put it into your signalCallback(...) method
- //LoggerD("signal: %s from: %s path: %s interface: %s",
- // signal_name, sender_name, object_path, interface_name);
-
- this_ptr->signalCallback(connection, sender_name, object_path, interface_name,
- signal_name, parameters);
-
- } catch(const common::PlatformException& exception) {
- LoggerE("Unhandled exception: %s (%s)!", (exception.name()).c_str(),
- (exception.message()).c_str());
- } catch(...) {
- LoggerE("Unhandled exception!");
- }
+ //It is better to log this only when subclass is responsible of handling
+ //passed signal. If you need it put it into your signalCallback(...) method
+ //LoggerD("signal: %s from: %s path: %s interface: %s",
+ // signal_name, sender_name, object_path, interface_name);
+ this_ptr->signalCallback(connection, sender_name, object_path, interface_name,
+ signal_name, parameters);
}
void Proxy::signalSubscribe()
diff --git a/src/messaging/DBus/Proxy.h b/src/messaging/DBus/Proxy.h
index 4db19c0e..81622511 100644
--- a/src/messaging/DBus/Proxy.h
+++ b/src/messaging/DBus/Proxy.h
@@ -29,7 +29,7 @@
#include