From 9d4b5bfa139d3643fc4744b04a46716ffeca18d7 Mon Sep 17 00:00:00 2001 From: Jerzy Pabich Date: Tue, 16 Dec 2014 14:52:47 +0100 Subject: [PATCH] [Messaging] sync() callback is being invoked Change-Id: I61ecac178d2b1b569cf3eef7b0611ecee8582718 Signed-off-by: Jerzy Pabich --- src/messaging/DBus/Connection.cpp | 6 ++-- src/messaging/DBus/EmailSignalProxy.cpp | 10 +++--- src/messaging/DBus/Proxy.cpp | 28 ++++++++-------- src/messaging/DBus/Proxy.h | 3 ++ src/messaging/DBus/SyncProxy.cpp | 44 ++++++++++++++----------- src/messaging/email_manager.cc | 26 +++++++-------- src/messaging/email_manager.h | 2 +- src/messaging/message_service_email.cc | 18 +++++----- src/messaging/messaging_instance.cc | 3 +- src/messaging/messaging_manager.cc | 1 - 10 files changed, 74 insertions(+), 67 deletions(-) diff --git a/src/messaging/DBus/Connection.cpp b/src/messaging/DBus/Connection.cpp index e1a49348..6eed4926 100644 --- a/src/messaging/DBus/Connection.cpp +++ b/src/messaging/DBus/Connection.cpp @@ -17,7 +17,7 @@ #include "Connection.h" #include "common/logger.h" -//#include +#include "common/platform_exception.h" #include #include #include "../message_service.h" @@ -45,9 +45,9 @@ Connection::Connection() m_dbus = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &m_error); if (!m_dbus || m_error) { - LOGE("Could not get connection"); + LoggerE("Could not get connection"); } - LOGD("Connection set"); + LoggerD("Connection set"); } Connection::~Connection() diff --git a/src/messaging/DBus/EmailSignalProxy.cpp b/src/messaging/DBus/EmailSignalProxy.cpp index 72149f17..b11254bb 100644 --- a/src/messaging/DBus/EmailSignalProxy.cpp +++ b/src/messaging/DBus/EmailSignalProxy.cpp @@ -22,7 +22,7 @@ #include "EmailSignalProxy.h" #include "common/logger.h" #include -//#include +#include "common/platform_exception.h" namespace extension { namespace messaging { @@ -70,11 +70,11 @@ void EmailSignalProxy::signalCallback(GDBusConnection* connection, handleEmailSignal(status, mail_id, source, op_handle, error_code); -// } catch(const Common::BasePlatformException& exception) { -// LOGE("Unhandled exception: %s (%s)!", (exception.getName()).c_str(), -// (exception.getMessage()).c_str()); + } catch(const common::PlatformException& exception) { + LoggerE("Unhandled exception: %s (%s)!", (exception.name()).c_str(), + (exception.message()).c_str()); } catch(...) { - LOGE("Unhandled exception!"); + LoggerE("Unhandled exception!"); } g_free(source); diff --git a/src/messaging/DBus/Proxy.cpp b/src/messaging/DBus/Proxy.cpp index a6692a0c..fc5c6c57 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 +#include "common/platform_exception.h" #include #include #include "../message_service.h" @@ -51,14 +51,14 @@ Proxy::Proxy(const std::string& proxy_path, m_error(NULL), m_dbus_signal_subscribed(false) { - LOGD("Proxy:\n" + LoggerD("Proxy:\n" " proxy_path: %s\n proxy_iface: %s" " signal_name: %s\n signal_path:%s\n signal_iface:%s", m_path.c_str(), m_iface.c_str(), m_signal_name.c_str(), m_signal_path.c_str(), m_signal_iface.c_str()); const gchar* unique_name = g_dbus_connection_get_unique_name(m_conn.getDBus()); - LOGD("Generated unique name: %d", unique_name); + LoggerD("Generated unique name: %d", unique_name); // path and interface are not obligatory to receive, but // they should be set to send the signals. @@ -66,8 +66,8 @@ Proxy::Proxy(const std::string& proxy_path, 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) { - LOGE("Could not get proxy"); - //TODO throw Common::UnknownException("Could not get proxy"); + LoggerE("Could not get proxy"); + throw common::UnknownException("Could not get proxy"); } } @@ -86,7 +86,7 @@ void Proxy::signalCallbackProxy(GDBusConnection *connection, { Proxy* this_ptr = static_cast(user_data); if (!this_ptr) { - LOGW("Proxy is null, nothing to do"); + LoggerW("Proxy is null, nothing to do"); return; } @@ -99,18 +99,18 @@ void Proxy::signalCallbackProxy(GDBusConnection *connection, this_ptr->signalCallback(connection, sender_name, object_path, interface_name, signal_name, parameters); -// } catch(const Common::BasePlatformException& exception) { -// LOGE("Unhandled exception: %s (%s)!", (exception.getName()).c_str(), -// (exception.getMessage()).c_str()); + } catch(const common::PlatformException& exception) { + LoggerE("Unhandled exception: %s (%s)!", (exception.name()).c_str(), + (exception.message()).c_str()); } catch(...) { - LOGE("Unhandled exception!"); + LoggerE("Unhandled exception!"); } } void Proxy::signalSubscribe() { if(m_dbus_signal_subscribed) { - LOGW("Proxy has already subscribed for listening DBus signal"); + LoggerW("Proxy has already subscribed for listening DBus signal"); return; } @@ -125,7 +125,7 @@ void Proxy::signalSubscribe() signalCallbackProxy, static_cast(this), NULL); - LOGD("g_dbus_connection_signal_subscribe returned id: %d", m_sub_id); + LoggerD("g_dbus_connection_signal_subscribe returned id: %d", m_sub_id); m_dbus_signal_subscribed = true; } @@ -133,12 +133,12 @@ void Proxy::signalSubscribe() void Proxy::signalUnsubscribe() { if (!m_dbus_signal_subscribed) { - LOGW("Proxy hasn't subscribed for listening DBus signal"); + LoggerW("Proxy hasn't subscribed for listening DBus signal"); return; } g_dbus_connection_signal_unsubscribe(m_conn.getDBus(), m_sub_id); - LOGD("g_dbus_connection_signal_unsubscribe finished"); + LoggerD("g_dbus_connection_signal_unsubscribe finished"); m_dbus_signal_subscribed = false; } diff --git a/src/messaging/DBus/Proxy.h b/src/messaging/DBus/Proxy.h index 75bab096..4db19c0e 100644 --- a/src/messaging/DBus/Proxy.h +++ b/src/messaging/DBus/Proxy.h @@ -28,6 +28,9 @@ #include #include #include "common/callback_user_data.h" +#include "common/picojson.h" +#include "common/platform_exception.h" +#include "../messaging_instance.h" namespace extension { namespace messaging { diff --git a/src/messaging/DBus/SyncProxy.cpp b/src/messaging/DBus/SyncProxy.cpp index 5c7f5fe4..32a91b52 100644 --- a/src/messaging/DBus/SyncProxy.cpp +++ b/src/messaging/DBus/SyncProxy.cpp @@ -21,7 +21,7 @@ #include "SyncProxy.h" #include "common/logger.h" -//#include +#include "common/platform_exception.h" #include #include #include "../message_service.h" @@ -55,8 +55,8 @@ common::CallbackUserData* SyncProxy::getCallback(long op_id) cb = it->second; return cb; } - LOGE("Could not find callback"); - //TODO throw Common::UnknownException("Could not find callback"); + LoggerE("Could not find callback"); + throw common::UnknownException("Could not find callback"); return cb; } @@ -69,8 +69,8 @@ void SyncProxy::removeCallback(long op_id){ m_callback_map.erase(it); } else { - LOGE("Could not find callback"); - //TODO throw Common::UnknownException("Could not find callback"); + LoggerE("Could not find callback"); + throw common::UnknownException("Could not find callback"); } } @@ -87,12 +87,12 @@ void SyncProxy::handleEmailSignal(const int status, return; } - LOGD("received email signal with:\n status: %d\n mail_id: %d\n " + LoggerD("received email signal with:\n status: %d\n mail_id: %d\n " "source: %s\n op_handle: %d\n error_code: %d", status, mail_id, source.c_str(), op_handle, error_code); if (NOTI_DOWNLOAD_START == status) { - LOGD("Sync started..."); + LoggerD("Sync started..."); // There is nothing more to do so we can return now. return; } @@ -105,34 +105,38 @@ void SyncProxy::handleEmailSignal(const int status, callback = callback_it->second; if (!callback) { LOGE("Callback is null"); - //TODO throw Common::UnknownException("Callback is null"); + throw common::UnknownException("Callback is null"); } + std::shared_ptr response = callback->getJson(); + picojson::object& obj = response->get(); switch (status) { case NOTI_DOWNLOAD_FINISH: LoggerD("Sync finished!"); - //TODO callback->callSuccessCallback(); + obj[JSON_ACTION] = picojson::value(JSON_CALLBACK_SUCCCESS); + MessagingInstance::getInstance().PostMessage(response->serialize().c_str()); break; case NOTI_DOWNLOAD_FAIL: LoggerD("Sync failed!"); - //TODO callback->callErrorCallback(); + obj[JSON_ACTION] = picojson::value(JSON_CALLBACK_ERROR); + MessagingInstance::getInstance().PostMessage(response->serialize().c_str()); break; default: break; } } -// catch (const Common::BasePlatformException& e) { -// // this situation may occur when there is no callback in the -// // map with specified opId (for example stopSync() has -// // removed it), but sync() was already started - only -// // warning here: -// LOGE("Exception in signal callback"); -// } + catch (const common::PlatformException& e) { + // this situation may occur when there is no callback in the + // map with specified opId (for example stopSync() has + // removed it), but sync() was already started - only + // warning here: + LoggerE("Exception in signal callback"); + } catch(...) { - LOGE("Exception in signal callback"); + LoggerE("Exception in signal callback"); } if(callback) { @@ -157,8 +161,8 @@ SyncProxy::CallbackMap::iterator SyncProxy::findSyncCallbackByOpHandle( // map with specified opId (for example stopSync() has // removed it), but sync() was already started - only // warning here: - LOGW("Could not find callback with op_handle: %d", op_handle); - //TODO throw Common::UnknownException("Could not find callback"); + LoggerW("Could not find callback with op_handle: %d", op_handle); + throw common::UnknownException("Could not find callback"); } } //namespace DBus diff --git a/src/messaging/email_manager.cc b/src/messaging/email_manager.cc index 148a13cf..c23912fa 100644 --- a/src/messaging/email_manager.cc +++ b/src/messaging/email_manager.cc @@ -24,7 +24,7 @@ //#include #include "common/logger.h" #include -//#include +#include "common/platform_exception.h" #include //#include @@ -87,12 +87,12 @@ EmailManager::EmailManager() const int non_err = EMAIL_ERROR_NONE; if(non_err != email_service_begin()){ - LOGE("Email service failed to begin"); - //TODO throw Common::UnknownException("Email service failed to begin"); + LoggerE("Email service failed to begin"); + throw common::UnknownException("Email service failed to begin"); } if(non_err != email_open_db()){ - LOGE("Email DB failed to open"); - //TODO throw Common::UnknownException("Email DB failed to open"); + LoggerE("Email DB failed to open"); + throw common::UnknownException("Email DB failed to open"); } int slot_size = -1; @@ -105,8 +105,8 @@ EmailManager::EmailManager() DBus::Proxy::DBUS_PATH_NETWORK_STATUS, DBus::Proxy::DBUS_IFACE_NETWORK_STATUS); if (!m_proxy_sync) { - LOGE("Sync proxy is null"); - //TODO throw Common::UnknownException("Sync proxy is null"); + LoggerE("Sync proxy is null"); + throw common::UnknownException("Sync proxy is null"); } m_proxy_sync->signalSubscribe(); @@ -649,11 +649,11 @@ void EmailManager::sync(void* data) LoggerD("Entered"); SyncCallbackData* callback = static_cast(data); if(!callback){ - LOGE("Callback is null"); + LoggerE("Callback is null"); return; } long op_id = callback->getOpId(); - //TODO m_proxy_sync->addCallback(op_id, callback); + m_proxy_sync->addCallback(op_id, callback); int err = EMAIL_ERROR_NONE; int limit = callback->getLimit(); @@ -669,16 +669,16 @@ void EmailManager::sync(void* data) err = email_set_mail_slot_size(0, 0, slot_size); if(EMAIL_ERROR_NONE != err){ - LOGE("Email set slot size failed, %d", err); - //TODO m_proxy_sync->removeCallback(op_id); + LoggerE("Email set slot size failed, %d", err); + m_proxy_sync->removeCallback(op_id); return; } int op_handle = -1; err = email_sync_header(account_id, 0, &op_handle); if(EMAIL_ERROR_NONE != err){ - LOGE("Email sync header failed, %d", err); - //TODO m_proxy_sync->removeCallback(op_id); + LoggerE("Email sync header failed, %d", err); + m_proxy_sync->removeCallback(op_id); } callback->setOperationHandle(op_handle); } diff --git a/src/messaging/email_manager.h b/src/messaging/email_manager.h index fd553a7c..cb7e4433 100644 --- a/src/messaging/email_manager.h +++ b/src/messaging/email_manager.h @@ -34,7 +34,7 @@ #include "email-api-mailbox.h" #include "common/callback_user_data.h" -//#include +#include "common/platform_exception.h" #include "messaging_util.h" #include "message_service.h" diff --git a/src/messaging/message_service_email.cc b/src/messaging/message_service_email.cc index 88a00611..e5601822 100644 --- a/src/messaging/message_service_email.cc +++ b/src/messaging/message_service_email.cc @@ -43,16 +43,16 @@ void MessageServiceEmail::loadMessageAttachment() static gboolean syncTask(void* data) { - LOGD("Entered"); + LoggerD("Entered"); try { EmailManager::getInstance().sync(data); -// } catch(const Common::BasePlatformException& exception) { -// LOGE("Unhandled exception: %s (%s)!", (exception.getName()).c_str(), -// (exception.getMessage()).c_str()); + } catch(const common::PlatformException& exception) { + LoggerE("Unhandled exception: %s (%s)!", (exception.name()).c_str(), + (exception.message()).c_str()); } catch(...) { - LOGE("Unhandled exception!"); + LoggerE("Unhandled exception!"); } return FALSE; @@ -62,8 +62,8 @@ long MessageServiceEmail::sync(SyncCallbackData *callback) { LoggerD("Entered"); if (!callback) { - LOGE("Callback is null"); - //TODO throw Common::UnknownException("Callback is null"); + LoggerE("Callback is null"); + throw common::UnknownException("Callback is null"); } long op_id = EmailManager::getInstance().getUniqueOpId(); @@ -72,9 +72,9 @@ long MessageServiceEmail::sync(SyncCallbackData *callback) guint id = g_idle_add(syncTask, static_cast(callback)); if (!id) { - LOGE("g_idle_add failed"); + LoggerE("g_idle_add failed"); delete callback; - //TODO throw Common::UnknownException("Could not add task"); + throw common::UnknownException("Could not add task"); } return op_id; } diff --git a/src/messaging/messaging_instance.cc b/src/messaging/messaging_instance.cc index f31a789d..2d02f629 100644 --- a/src/messaging/messaging_instance.cc +++ b/src/messaging/messaging_instance.cc @@ -32,6 +32,7 @@ const char* LOAD_MESSAGE_ATTACHMENT_ARGS_ATTACHMENT = "attachment"; const char* FUN_MESSAGE_SERVICE_SYNC = "MessageService_sync"; const char* SERVICE_SYNC_ARGS_ID = "id"; const char* SERVICE_SYNC_ARGS_LIMIT = "limit"; +const char* CMD_MESSAGE_SERVICE_SYNC = "sync"; const char* FUN_MESSAGE_SERVICE_SYNC_FOLDER = "MessageService_syncFolder"; const char* SYNC_FOLDER_ARGS_FOLDER = "folder"; @@ -180,7 +181,7 @@ void MessagingInstance::MessageServiceSync(const picojson::value& args, auto json = std::shared_ptr(new picojson::value(picojson::object())); picojson::object& obj = json->get(); obj[JSON_CALLBACK_ID] = picojson::value(callbackId); - //obj[JSON_DATA] = picojson::value( TODO ); + obj[JSON_CMD] = picojson::value(CMD_MESSAGE_SERVICE_SYNC); SyncCallbackData *callback = new SyncCallbackData(); callback->setJson(json); diff --git a/src/messaging/messaging_manager.cc b/src/messaging/messaging_manager.cc index eb5f3d14..6875feda 100755 --- a/src/messaging/messaging_manager.cc +++ b/src/messaging/messaging_manager.cc @@ -63,7 +63,6 @@ static gboolean callbackCompleted(const std::shared_ptr& { LoggerD("Entered"); std::shared_ptr response = user_data->json; - std::cout<serialize()<< std::endl; MessagingInstance::getInstance().PostMessage(response->serialize().c_str()); return false; } -- 2.34.1