[Messaging] sync() callback is being invoked
authorJerzy Pabich <j.pabich@samsung.com>
Tue, 16 Dec 2014 13:52:47 +0000 (14:52 +0100)
committerJerzy Pabich <j.pabich@samsung.com>
Tue, 16 Dec 2014 13:54:48 +0000 (14:54 +0100)
Change-Id: I61ecac178d2b1b569cf3eef7b0611ecee8582718
Signed-off-by: Jerzy Pabich <j.pabich@samsung.com>
src/messaging/DBus/Connection.cpp
src/messaging/DBus/EmailSignalProxy.cpp
src/messaging/DBus/Proxy.cpp
src/messaging/DBus/Proxy.h
src/messaging/DBus/SyncProxy.cpp
src/messaging/email_manager.cc
src/messaging/email_manager.h
src/messaging/message_service_email.cc
src/messaging/messaging_instance.cc
src/messaging/messaging_manager.cc

index e1a49348b99f19a069737282050c74bcb0f5ac38..6eed492685653678fcd48eacb3c2957c1b59e330 100644 (file)
@@ -17,7 +17,7 @@
 
 #include "Connection.h"
 #include "common/logger.h"
-//#include <PlatformException.h>
+#include "common/platform_exception.h"
 #include <cstring>
 #include <email-types.h>
 #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()
index 72149f17e92a08c467403305c4be63f0dd14850f..b11254bb3d5fab61856267571b593d7bf338dd4d 100644 (file)
@@ -22,7 +22,7 @@
 #include "EmailSignalProxy.h"
 #include "common/logger.h"
 #include <cstring>
-//#include <PlatformException.h>
+#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);
index a6692a0ce2147a8d204311d2af5ace9e4c910619..fc5c6c5785d26f54467ade7e39e04350eadfa149 100644 (file)
@@ -21,7 +21,7 @@
 
 #include "Proxy.h"
 #include "common/logger.h"
-//#include <PlatformException.h>
+#include "common/platform_exception.h"
 #include <cstring>
 #include <email-types.h>
 #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<Proxy*>(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<gpointer>(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;
 }
index 75bab0960a02bf3bd59ce5820e5bf5fb007b7ec5..4db19c0ec4e113a7c57aa6945af2499fe80852b0 100644 (file)
@@ -28,6 +28,9 @@
 #include <mutex>
 #include <map>
 #include "common/callback_user_data.h"
+#include "common/picojson.h"
+#include "common/platform_exception.h"
+#include "../messaging_instance.h"
 
 namespace extension {
 namespace messaging {
index 5c7f5fe4edc2bedb6ad02b6b1f77d09a561007f5..32a91b52b557e048cece6939dc667b33a613fd78 100644 (file)
@@ -21,7 +21,7 @@
 
 #include "SyncProxy.h"
 #include "common/logger.h"
-//#include <PlatformException.h>
+#include "common/platform_exception.h"
 #include <cstring>
 #include <email-types.h>
 #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<picojson::value> response = callback->getJson();
+        picojson::object& obj = response->get<picojson::object>();
         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
index 148a13cff109ac92d5f82d163a10007d04b14af0..c23912fa4064f474d72233c61b29ca3378218394 100644 (file)
@@ -24,7 +24,7 @@
 //#include <JSUtil.h>
 #include "common/logger.h"
 #include <memory>
-//#include <PlatformException.h>
+#include "common/platform_exception.h"
 #include <sstream>
 //#include <GlobalContextManager.h>
 
@@ -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<SyncCallbackData*>(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);
 }
index fd553a7c5b5e4ab71609eb12c8123f6a153bca14..cb7e4433672d59ecf989b43c675313f7b28ebf68 100644 (file)
@@ -34,7 +34,7 @@
 #include "email-api-mailbox.h"
 
 #include "common/callback_user_data.h"
-//#include <PlatformException.h>
+#include "common/platform_exception.h"
 
 #include "messaging_util.h"
 #include "message_service.h"
index 88a00611c175bac2061bb54571247c333efedf84..e560182274d9498419d8ac9863d25906d0184ae6 100644 (file)
@@ -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<void*>(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;
 }
index f31a789dd4f4c3a90294607c13d58bbf90742edb..2d02f6294d30d02a9b0240bc6e9f70ecb30edd23 100644 (file)
@@ -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<picojson::value>(new picojson::value(picojson::object()));
     picojson::object& obj = json->get<picojson::object>();
     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);
index eb5f3d1401f1a9d96c614c88c03a72ae2f931aca..6875fedaa06ad7abfda6bfa9b7259eef2e5bdd76 100755 (executable)
@@ -63,7 +63,6 @@ static gboolean callbackCompleted(const std::shared_ptr<MsgManagerCallbackData>&
 {
     LoggerD("Entered");
     std::shared_ptr<picojson::value> response = user_data->json;
-    std::cout<<response->serialize()<< std::endl;
     MessagingInstance::getInstance().PostMessage(response->serialize().c_str());
     return false;
 }