DEFINE_EXCEPTION(NotSupported)
DEFINE_EXCEPTION(NotFound)
DEFINE_EXCEPTION(InvalidAccess)
+DEFINE_EXCEPTION(Abort)
DEFINE_EXCEPTION(QuotaExceeded)
#undef DEFINE_EXCEPTION
} // namespace common
-#endif // COMMON_PLATFORM_EXCEPTION_H_
\ No newline at end of file
+#endif // COMMON_PLATFORM_EXCEPTION_H_
//}
//
////#################################### ^syncFolder #############################
-//
-////################################## stopSync: #################################
-//
-//void EmailManager::stopSync(long op_id)
-//{
-// LoggerD("Entered");
-// SyncCallbackData* callback = NULL;
-// try {
-// callback = dynamic_cast<SyncCallbackData*>(
-// m_proxy_sync->getCallback(op_id));
-// }
-// catch (const BasePlatformException& e) {
-// LoggerE("Could not get callback");
-// }
-// if(!callback){
-// LoggerE("Callback is null");
-// return;
-// }
-//
-// int err = EMAIL_ERROR_NONE;
-// err = email_cancel_job(callback->getAccountId(), callback->getOperationHandle(),
-// EMAIL_CANCELED_BY_USER);
-// if(EMAIL_ERROR_NONE != err){
-// LoggerE("Email cancel job failed, %d", err);
-// }
-// JSObjectRef err_obj =
-// JSWebAPIErrorFactory::makeErrorObject(callback->getContext(),
-// JSWebAPIErrorFactory::ABORT_ERROR,
-// "Sync aborted by user");
-// callback->callErrorCallback(err_obj);
-// m_proxy_sync->removeCallback(op_id);
-//}
-//
-////################################## ^stopSync #################################
-//
+
+//################################## stopSync: #################################
+
+void EmailManager::stopSync(long op_id)
+{
+ LoggerD("Entered");
+ SyncCallbackData* callback = NULL;
+ try {
+ callback = dynamic_cast<SyncCallbackData*>(
+ m_proxy_sync->getCallback(op_id));
+ }
+ catch (const common::PlatformException& e) {
+ LoggerE("Could not get callback");
+ }
+ if(!callback){
+ LoggerE("Callback is null");
+ return;
+ }
+
+ int err = EMAIL_ERROR_NONE;
+ err = email_cancel_job(callback->getAccountId(), callback->getOperationHandle(),
+ EMAIL_CANCELED_BY_USER);
+ if(EMAIL_ERROR_NONE != err){
+ LoggerE("Email cancel job failed, %d", err);
+ }
+
+ std::shared_ptr<picojson::value> response = callback->getJson();
+ picojson::object& obj = response->get<picojson::object>();
+ common::AbortException error("Sync aborted by user");
+ callback->setError(error.name(), error.message());
+ MessagingInstance::getInstance().PostMessage(response->serialize().c_str());
+ m_proxy_sync->removeCallback(op_id);
+}
+
+//################################## ^stopSync #################################
+
//void removeEmailCompleteCB(MessagesCallbackUserData* callback)
//{
// LoggerD("Entered");
void sync(void* data);
// void syncFolder(SyncFolderCallbackData* callback);
-// void stopSync(long op_id);
-//
+ void stopSync(long op_id);
+
// void registerStatusCallback(msg_handle_t msg_handle);
/**
throw common::NotSupportedException("Cannot sync folder with external server");
}
-void MessageService::stopSync()
+void MessageService::stopSync(long op_id)
{
// this method should be overwritten by email service
// for MMS and SMS this function is not supported
virtual void loadMessageAttachment();
virtual long sync(SyncCallbackData *callback);
virtual long syncFolder();
- virtual void stopSync();
+ virtual void stopSync(long op_id);
picojson::object toPicoJS() const;
return 0;
}
-void MessageServiceEmail::stopSync()
+static gboolean stopSyncTask(void* data)
{
LoggerD("Entered");
- //TODO add implementation
+
+ try {
+ if (!data) {
+ LoggerE("opId is null");
+ return FALSE;
+ }
+
+ const long op_id = *(static_cast<long*>(data));
+ delete static_cast<long*>(data);
+ data = NULL;
+ EmailManager::getInstance().stopSync(op_id);
+
+ } catch(const common::PlatformException& exception) {
+ LoggerE("Unhandled exception: %s (%s)!", (exception.name()).c_str(),
+ (exception.message()).c_str());
+ } catch(...) {
+ LoggerE("Unhandled exception!");
+ }
+
+ return FALSE;
+}
+
+void MessageServiceEmail::stopSync(long op_id)
+{
+ LoggerD("Entered");
+ long* data = new long(op_id);
+ guint id = g_idle_add(stopSyncTask, static_cast<void*>(data));
+ if (!id) {
+ LOGE("g_idle_add failed");
+ delete data;
+ data = NULL;
+ throw common::UnknownException("Could not add task");
+ }
}
} // messaging
virtual void loadMessageAttachment();
virtual long sync(SyncCallbackData *callback);
virtual long syncFolder();
- virtual void stopSync();
+ virtual void stopSync(long op_id);
};
} // messaging
if (args.errorCallback) {
args.errorCallback.call(
null,
- new tizen.WebAPIException(e.code, e.name, e.message)
+ new tizen.WebAPIException(e.code, e.message, e.name)
)
}
}
if (args.errorCallback) {
args.errorCallback.call(
null,
- new tizen.WebAPIException(e.code, e.name, e.message)
+ new tizen.WebAPIException(e.code, e.message, e.name)
)
}
}
if (args.errorCallback) {
args.errorCallback.call(
null,
- new tizen.WebAPIException(e.code, e.name, e.message)
+ new tizen.WebAPIException(e.code, e.message, e.name)
)
}
}
if (args.errorCallback) {
args.errorCallback.call(
null,
- new tizen.WebAPIException(e.code, e.name, e.message)
+ new tizen.WebAPIException(e.code, e.message, e.name)
)
}
}
if (args.errorCallback) {
args.errorCallback.call(
null,
- new tizen.WebAPIException(e.code, e.name, e.message)
+ new tizen.WebAPIException(e.code, e.message, e.name)
)
}
}
if (args.errorCallback) {
args.errorCallback.call(
null,
- new tizen.WebAPIException(e.code, e.name, e.message)
+ new tizen.WebAPIException(e.code, e.message, e.name)
)
}
}
{name: 'opId', type: types_.LONG}
]);
+ var self = this;
bridge.sync({
cmd: 'MessageService_stopSync',
args: {
+ id: self.id,
opId: args.opId
}
});
if (args.errorCallback) {
args.errorCallback.call(
null,
- new tizen.WebAPIException(e.code, e.name, e.message)
+ new tizen.WebAPIException(e.code, e.message, e.name)
)
}
}
if (args.errorCallback) {
args.errorCallback.call(
null,
- new tizen.WebAPIException(e.code, e.name, e.message)
+ new tizen.WebAPIException(e.code, e.message, e.name)
)
}
}
if (args.errorCallback) {
args.errorCallback.call(
null,
- new tizen.WebAPIException(e.code, e.name, e.message)
+ new tizen.WebAPIException(e.code, e.message, e.name)
)
}
}
if (args.errorCallback) {
args.errorCallback.call(
null,
- new tizen.WebAPIException(e.code, e.name, e.message)
+ new tizen.WebAPIException(e.code, e.message, e.name)
)
}
}
if (args.errorCallback) {
args.errorCallback.call(
null,
- new tizen.WebAPIException(e.code, e.name, e.message)
+ new tizen.WebAPIException(e.code, e.message, e.name)
)
}
}
if (args.errorCallback) {
args.errorCallback.call(
null,
- new tizen.WebAPIException(e.code, e.name, e.message)
+ new tizen.WebAPIException(e.code, e.message, e.name)
)
}
}
if (args.errorCallback) {
args.errorCallback.call(
null,
- new tizen.WebAPIException(e.code, e.name, e.message)
+ new tizen.WebAPIException(e.code, e.message, e.name)
)
}
}
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* SYNC_ARGS_ID = "id";
+const char* SYNC_ARGS_LIMIT = "limit";
const char* FUN_MESSAGE_SERVICE_SYNC_FOLDER = "MessageService_syncFolder";
const char* SYNC_FOLDER_ARGS_FOLDER = "folder";
const char* SYNC_FOLDER_ARGS_LIMIT = "limit";
const char* FUN_MESSAGE_SERVICE_STOP_SYNC = "MessageService_stopSync";
+const char* STOP_SYNC_ARGS_ID = "id";
const char* STOP_SYNC_ARGS_OPID = "opId";
const char* FUN_MESSAGE_STORAGE_ADD_DRAFT_MESSAGE = "MessageStorage_addDraftMessage";
LoggerD("Entered");
picojson::object data = args.get(JSON_DATA).get<picojson::object>();
- picojson::value v_id = data.at(SERVICE_SYNC_ARGS_ID);
- picojson::value v_limit = data.at(SERVICE_SYNC_ARGS_LIMIT);
+ picojson::value v_id = data.at(SYNC_ARGS_ID);
+ picojson::value v_limit = data.at(SYNC_ARGS_LIMIT);
const double callbackId = args.get(JSON_CALLBACK_ID).get<double>();
int id = static_cast<int>(v_id.get<double>());
picojson::object& out)
{
LoggerD("Entered");
+
+ picojson::object data = args.get(JSON_DATA).get<picojson::object>();
+ picojson::value v_id = data.at(STOP_SYNC_ARGS_ID);
+ picojson::value v_op_id = data.at(STOP_SYNC_ARGS_OPID);
+
+ int id = static_cast<int>(v_id.get<double>());
+ long op_id = 0;
+ if (v_op_id.is<double>()) {
+ op_id = static_cast<long>(v_op_id.get<double>());
+ }
+
+ MessagingManager::getInstance().getMessageServiceEmail(id)->stopSync(op_id);
+
+ ReportSuccess(out);
}
/* Code used to testing in node.js console
extern const char* MESSAGE_BODY_ATTRIBUTE_PLAIN_BODY;
extern const char* MESSAGE_BODY_ATTRIBUTE_HTML_BODY;
-extern const char* JSON_RET_DATA;
-extern const char* JSON_RET_ERR_MESSAGE;
-extern const char* JSON_RET_ERR_NAME;
-
enum MessageType {
UNDEFINED = 0,
SMS,