#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"
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()
#include "EmailSignalProxy.h"
#include "common/logger.h"
#include <cstring>
-//#include <PlatformException.h>
+#include "common/platform_exception.h"
namespace extension {
namespace messaging {
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);
#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"
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.
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");
}
}
{
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;
}
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;
}
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;
}
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;
}
#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 {
#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"
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;
}
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");
}
}
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;
}
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) {
// 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
//#include <JSUtil.h>
#include "common/logger.h"
#include <memory>
-//#include <PlatformException.h>
+#include "common/platform_exception.h"
#include <sstream>
//#include <GlobalContextManager.h>
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;
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();
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();
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);
}
#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"
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;
{
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();
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;
}
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";
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);
{
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;
}