#include <CommonsJavaScript/JSCallbackManager.h>
#include <CommonsJavaScript/Utils.h>
#include <CommonsJavaScript/ScopedJSStringRef.h>
+#include <CommonsJavaScript/JSPendingOperation.h>
+#include <CommonsJavaScript/JSDOMExceptionFactory.h>
#include <Commons/StringUtils.h>
#include <API/Messaging/ReqReceiverMessage.h>
{"id", getProperty, NULL, kJSPropertyAttributeReadOnly},
{"type", getProperty, NULL, kJSPropertyAttributeReadOnly},
{"name", getProperty, NULL, kJSPropertyAttributeReadOnly},
- {"messagingStorage", getProperty, NULL, kJSPropertyAttributeReadOnly},
+ {"messageStorage", getProperty, NULL, kJSPropertyAttributeReadOnly},
{ 0, 0, 0, 0 }
};
JSStaticFunction JSMessagingService::m_function[] = {
- { "createMessage", JSMessagingService::createMessage, kJSPropertyAttributeNone },
+ //{ "createMessage", JSMessagingService::createMessage, kJSPropertyAttributeNone },
{ "sendMessage", JSMessagingService::sendMessage, kJSPropertyAttributeNone },
{ "loadMessageBody", JSMessagingService::loadMessageBody, kJSPropertyAttributeNone },
{ "loadMessageAttachment", JSMessagingService::loadMessageAttachment, kJSPropertyAttributeNone },
{ "sync", JSMessagingService::sync, kJSPropertyAttributeNone },
{ "syncFolder", JSMessagingService::syncFolder, kJSPropertyAttributeNone },
- { "cancelOperation", JSMessagingService::cancelOperation, kJSPropertyAttributeNone },
+ //{ "cancelOperation", JSMessagingService::cancelOperation, kJSPropertyAttributeNone },
+ { "stopSync", JSMessagingService::stopSync, kJSPropertyAttributeNone },
{ 0, 0, 0 }
};
}
retVal = converter->toJSValueRef(stream.str());
- } else if (JSStringIsEqualToUTF8CString(propertyName, "messagingStorage")) {
- LogDebug("messagingStorage" << ":" << imessagingService->getAccountID());
+ } else if (JSStringIsEqualToUTF8CString(propertyName, "messageStorage")) {
JSContextRef l_globalContext = converter->toJSGlobalContext(object);
- retVal = JSUtils::makeObject(l_globalContext, JSMessagingStorage::getClassRef(), NULL);
+ MessagingStoragePrivObjPtr storagePriv(new MessagingStoragePrivObj());
+// MessagingListenerPtr listener_priv = MessagingListener::getInstance(l_globalContext) ;
+ storagePriv->m_index = imessagingService->getAccountID();
+ storagePriv->m_type = imessagingService->getType();
+ LogDebug("type" << ":" << imessagingService->getType());
+ LogDebug("accountId" << ":" << imessagingService->getAccountID());
+
+ MessagingStoragePriv *priv = new MessagingStoragePriv(l_globalContext, storagePriv);
+ //MessagingStoragePrivObjPtr storagePriv = priv->getObject();
+
+// retVal = JSUtils::makeObject(l_globalContext, JSMessagingStorage::getClassRef(), priv);
+ retVal = JSObjectMake(l_globalContext, JSMessagingStorage::getClassRef(), priv);
+
} else{
retVal = JSValueMakeUndefined(context);
}
if (priv)
{
AceSecurityStatus status = MESSAGING_CHECK_ACCESS(
- priv->getContext(),
MessagingExportedNames[MESSAGING_FUNCTION_API_CREATE_MESSAGE]);
TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
const ScopedJSStringRef bccStr(JSStringCreateWithUTF8CString("bcc"));
const ScopedJSStringRef plainBodyStr(JSStringCreateWithUTF8CString("plainBody"));
const ScopedJSStringRef htmlBodyStr(JSStringCreateWithUTF8CString("htmlBody"));
- const ScopedJSStringRef priorityStr(JSStringCreateWithUTF8CString("priority"));
+ const ScopedJSStringRef priorityStr(JSStringCreateWithUTF8CString("isHighPriority"));
JSObjectRef arg = converter->toJSObjectRef(arguments[0]);
JSValueRef subjectData = JSObjectGetProperty(l_globalContext, arg, subjectStr.get(), NULL);
}
JSContextRef globalContext = priv->getContext();
-
LogInfo(">>> argument count : " << argumentCount);
- if (argumentCount < 2) {
+ if (argumentCount < 1) {
return JSTizenExceptionFactory::postException(context, exception,
- JSTizenException::TYPE_MISMATCH_ERROR, JSMESSAGING_EXCEPTION_MSG_INVALID_ARGUMENT);
+ JSTizenException::TYPE_MISMATCH_ERROR, JSMESSAGING_EXCEPTION_MSG_TYPE_MISMATCH);
}
WrtDeviceApis::CommonsJavaScript::JSCallbackManagerPtr callbackManager = JSCallbackManager::createObject(globalContext);
WrtDeviceApis::CommonsJavaScript::JSCallbackManagerPtr recipientCallbackManager;
ConverterMessageFactory::ConverterType converter = ConverterMessageFactory::getConverter(context);
- Try {
+ //check permission.
+ AceSecurityStatus status = MESSAGING_CHECK_ACCESS(
+ MessagingExportedNames[MESSAGING_FUNCTION_API_SEND_MESSAGE]);
+ TIZEN_ASYNC_CBM_ACCESS_HANDLER(status, context, callbackManager);
- if ( argumentCount > 1 && argumentCount < 4)
+
+Try {
+ //argu 1. Message ( mandatory )
+ if (!JSValueIsObject(context, arguments[0]))
{
- if ( argumentCount > 1)
- {
- if (JSValueIsObject(context, arguments[1]) && !Validator(context).isCallback(arguments[1])) //check
- {
- MessageSendCallback callbacks = converter->toMessageSendCallback(arguments[1]);
+ LogDebug("arguments is invaild");
+ ThrowMsg(WrtDeviceApis::Commons::InvalidArgumentException,"invalid argument exception");
+ }
+
+ IMessagePtr msg = converter->toIMessage(arguments[0]);
+
+ //argu 2. Success callback (optional)
+ if ( argumentCount > 1)
+ {
+ if ( JSValueIsObject(context, arguments[1]) || Validator(context).isCallback(arguments[1]))
+ {
+ MessageSendCallback callbacks = converter->toMessageSendCallback(arguments[1]);
+
+ if (!(JSValueIsUndefined(context, callbacks.onSuccess) || JSValueIsNull(context, callbacks.onSuccess)) )
+ {
callbackManager->setOnSuccess( converter->toFunctionOrNull(callbacks.onSuccess) );
}
else
{
- callbackManager->setOnSuccess(converter->toFunction(arguments[1]));
- }
-
- if ( argumentCount == 3)
- {
- callbackManager->setOnError(converter->toFunctionOrNull(arguments[2]));
+ callbackManager->setOnSuccess(converter->toFunctionOrNull(arguments[1]));
}
}
+ else
+ {
+ ThrowMsg(WrtDeviceApis::Commons::InvalidArgumentException,"invalid argument exception");
+ }
}
- else
+ //argu 3. error callback (optional & nullable)
+ if ( argumentCount > 2)
{
- ThrowMsg(WrtDeviceApis::Commons::InvalidArgumentException,"invalid argument exception");
+ if ( Validator(context).isCallback(arguments[2]))
+ callbackManager->setOnError(arguments[2]);
+ else if(Validator(context).isNullOrUndefined(arguments[2]))
+ callbackManager->setOnError(NULL);
+ else
+ Throw(WrtDeviceApis::Commons::InvalidArgumentException);
}
-
- //check permission.
- AceSecurityStatus status = MESSAGING_CHECK_ACCESS(
- priv->getContext(),
- MessagingExportedNames[MESSAGING_FUNCTION_API_SEND_MESSAGE]);
- TIZEN_ASYNC_CBM_ACCESS_HANDLER(status, context, callbackManager);
-
//create PrivateData
- EventSendMessagePrivateDataPtr privateData( new EventSendMessagePrivateData(callbackManager, recipientCallbackManager) );
-
- Api::Messaging::EventSendMessagePtr event(new Api::Messaging::EventSendMessage());
+ EventMessagingServicePrivateDataPtr privateData( new EventMessagingServicePrivateData(callbackManager, recipientCallbackManager) );
- LogDebug("Event size");
+ //Api::Messaging::EventSendMessagePtr event(new Api::Messaging::EventSendMessage());
+ Api::Messaging::EventMessagingServicePtr event(new Api::Messaging::EventMessagingService());
IMessagingServicePtr imessagingService = priv->getObject();
event->opId = imessagingService->createOpId(MESSAGING_SERVICE_OP_SEND_MESSAGE);
- event->msg = converter->toIMessage(arguments[0]);
- imessagingService->setMessageToOpId( event->opId, event->msg);
+ event->setEventType(MESSAGING_SERVICE_EVENT_TYPE_SEND_MESSAGE);
+ event->m_message = msg;
+ imessagingService->setMessageToOpId( event->opId, event->m_message);
event->store = true; //always store message in sendbox after send , email Type.
event->m_messagingService = imessagingService;
event->setPrivateData(DPL::StaticPointerCast<WrtDeviceApis::Commons::IEventPrivateData>(privateData));
-
- //event->setForAsynchronousCall(&JSMessagingListener::getInstance());
- //event->setForAsynchronousCall(&MessagingControllerSingleton::Instance());
event->setForAsynchronousCall(&MessagingController::getInstance());
Api::Messaging::ReqReceiverMessageSingleton::Instance().sendMessage(event); //send message
+#if 0 //Pending Operation.
+ DPL::SharedPtr<IExternEventCanceler<EventMessagingService> > eventCanceller =
+ DPL::StaticPointerCast<IExternEventCanceler<EventMessagingService> >(imessagingService);
- return converter->toJSValueRef(event->opId);
+ IJSExtCancelPendingOperationPrivateObject<EventMessagingService> *gcPendingOperation =
+ new IJSExtCancelPendingOperationPrivateObject<EventMessagingService>(event, eventCanceller);
+
+ return JSObjectMake(globalContext, JSPendingOperation::getClassRef(), gcPendingOperation);
+#endif
+ //return converter->toJSValueRef(event->opId);
+
+ return JSValueMakeUndefined(context);
}
Catch(WrtDeviceApis::Commons::ConversionException) {
return JSTizenExceptionFactory::postException(context, exception,
JSTizenException::TYPE_MISMATCH_ERROR, JSMESSAGING_EXCEPTION_MSG_TYPE_MISMATCH);
}
Catch(WrtDeviceApis::Commons::InvalidArgumentException) {
- callbackManager->callOnError(JSTizenExceptionFactory::makeErrorObject(context,
- JSTizenException::INVALID_VALUES_ERROR, JSMESSAGING_EXCEPTION_MSG_INVALID_ARGUMENT));
+ return JSTizenExceptionFactory::postException(context, exception,
+ JSTizenException::TYPE_MISMATCH_ERROR, JSMESSAGING_EXCEPTION_MSG_TYPE_MISMATCH);
}
return JSValueMakeNull(context);
JSContextRef globalContext = priv->getContext(); //create global Context
LogInfo(">>> argument count : " << argumentCount);
- if (argumentCount < 2) {
+ if (argumentCount < 3) {
return JSTizenExceptionFactory::postException(context, exception,
- JSTizenException::TYPE_MISMATCH_ERROR, JSMESSAGING_EXCEPTION_MSG_INVALID_ARGUMENT);
+ JSTizenException::TYPE_MISMATCH_ERROR, JSMESSAGING_EXCEPTION_MSG_TYPE_MISMATCH);
}
Validator check(context, exception); //create check
WrtDeviceApis::CommonsJavaScript::JSCallbackManagerPtr callbackManager = JSCallbackManager::createObject(globalContext);
ConverterMessageFactory::ConverterType converter = ConverterMessageFactory::getConverter(globalContext); //create converter
- Try {
- //create event
- EventMessagingServicePrivateDataPtr privateData( new EventMessagingServicePrivateData(callbackManager) );
-
- //check permission.
- AceSecurityStatus status = MESSAGING_CHECK_ACCESS(
- priv->getContext(),
+ //check permission.
+ AceSecurityStatus status = MESSAGING_CHECK_ACCESS(
MessagingExportedNames[MESSAGING_FUNCTION_API_LOAD_MESSAGE_BODY]);
- TIZEN_ASYNC_CBM_ACCESS_HANDLER(status, context, callbackManager);
-
- if ( JSValueIsObject(context, arguments[0]) )
- {
- switch(argumentCount){
- case 3:
- {
- if ( Validator(context).isCallback(arguments[2]))
- {
- callbackManager->setOnError(converter->toFunctionOrNull(arguments[2]));
- }
- else
- {
- return JSTizenExceptionFactory::postException(context, exception,
- JSTizenException::INVALID_VALUES_ERROR, JSMESSAGING_EXCEPTION_MSG_INVALID_ARGUMENT);
- }
- }
- case 2:
- {
- if ( Validator(context).isCallback(arguments[1]))
- {
- callbackManager->setOnSuccess(converter->toFunctionOrNull(arguments[1]));
- }
- else
- {
- return JSTizenExceptionFactory::postException(context, exception,
- JSTizenException::INVALID_VALUES_ERROR, JSMESSAGING_EXCEPTION_MSG_INVALID_ARGUMENT);
- }
- }
+ TIZEN_ASYNC_CBM_ACCESS_HANDLER(status, context, callbackManager);
+
+ Try {
+ //argu 1. message (mandatory)
+ if (!JSValueIsObject(context, arguments[0]) )
+ {
+ ThrowMsg(WrtDeviceApis::Commons::InvalidArgumentException,"invalid argument exception");
+ }
+ //argu 2. success callback
+ if ( Validator(context).isCallback(arguments[1]))
+ {
+ callbackManager->setOnSuccess(converter->toFunctionOrNull(arguments[1]));
}
+ else
+ {
+ ThrowMsg(WrtDeviceApis::Commons::InvalidArgumentException,"invalid argument exception");
+ }
+
+ //argu 3. error callback (optional & nullable)
+ if ( argumentCount > 2)
+ {
+ if ( check.isCallback(arguments[2]))
+ callbackManager->setOnError(arguments[2]);
+ else if(check.isNullOrUndefined(arguments[2]))
+ callbackManager->setOnError(NULL);
+ else
+ Throw(WrtDeviceApis::Commons::InvalidArgumentException);
+ }
+ }
+ Catch(WrtDeviceApis::Commons::ConversionException) {
+ return JSTizenExceptionFactory::postException(context, exception,
+ JSTizenException::TYPE_MISMATCH_ERROR, JSMESSAGING_EXCEPTION_MSG_TYPE_MISMATCH);
+ }
+ Catch(WrtDeviceApis::Commons::InvalidArgumentException) {
+ return JSTizenExceptionFactory::postException(context, exception,
+ JSTizenException::TYPE_MISMATCH_ERROR, JSMESSAGING_EXCEPTION_MSG_TYPE_MISMATCH);
+ }
+ Catch(WrtDeviceApis::Commons::PlatformException) {
+ return JSTizenExceptionFactory::postException(context, exception,
+ JSTizenException::UNKNOWN_ERROR, JSMESSAGING_EXCEPTION_MSG_UNKNOWN);
+ }
+
+ Try {
+ IMessagePtr msg = converter->toIMessage(arguments[0]);
+ LogInfo(" checked toIMessages " );
+ //create event
+ EventMessagingServicePrivateDataPtr privateData( new EventMessagingServicePrivateData(callbackManager) );
+ Api::Messaging::EventMessagingServicePtr event(new Api::Messaging::EventMessagingService());
+ event->m_message = msg;
- Api::Messaging::EventMessagingServicePtr event(new Api::Messaging::EventMessagingService()); //create even
- event->m_message = converter->toIMessage(arguments[0]) ;
if ( event->m_message )
{
int msgType = event->m_message->getMessageType();
- LogDebug("Message Type =" << event->m_message->getMessageType());
+
if (msgType == Api::Messaging::EMAIL)
{
Api::Messaging::IEmailPtr email = Api::Messaging::MessageFactory::convertToEmail(event->m_message);
if (email && email->isBodyDownloaded() > 0)
{
- callbackManager->callOnSuccess(arguments[0]);
- return JSValueMakeNull(context);
+ callbackManager->callOnSuccess(arguments[1]);
}
}
- else
+ else
{
- callbackManager->callOnSuccess(arguments[0]);
+ callbackManager->callOnError(JSTizenExceptionFactory::makeErrorObject(context,
+ JSTizenException::INVALID_VALUES_ERROR, JSMESSAGING_EXCEPTION_MSG_INVALID_ARGUMENT));
return JSValueMakeNull(context);
}
privateData->setMessageJSValueRef(arguments[0]); //set Message JSValueRef.
}
-
+ LogInfo(" Checked Message Type " );
+
IMessagingServicePtr imessagingService = priv->getObject();
int opId = imessagingService->createOpId(MESSAGING_SERVICE_OP_DOWNLOAD_BODY);
LogDebug("Operation ID is = " << opId);
event->opId = opId;
imessagingService->setMessageToOpId(opId, event->m_message);
- event->setEventType(EventMessagingService::MESSAGING_SERVICE_EVENT_TYPE_LOAD_MESSAGE_BODY);
+ event->setEventType(MESSAGING_SERVICE_EVENT_TYPE_LOAD_MESSAGE_BODY);
event->setPrivateData(DPL::StaticPointerCast<WrtDeviceApis::Commons::IEventPrivateData>(privateData));
event->setForAsynchronousCall(&MessagingController::getInstance());
Api::Messaging::ReqReceiverMessageSingleton::Instance().loadMessageBody(event); //load message Body
+#if 0
+ DPL::SharedPtr<IExternEventCanceler<EventMessagingService> > eventCanceller =
+ DPL::StaticPointerCast<IExternEventCanceler<EventMessagingService> >(imessagingService);
- return converter->toJSValueRef(event->opId);
- }
- else
- {
- return JSTizenExceptionFactory::postException(context, exception,
- JSTizenException::TYPE_MISMATCH_ERROR, JSMESSAGING_EXCEPTION_MSG_TYPE_MISMATCH);
- }
+ IJSExtCancelPendingOperationPrivateObject<EventMessagingService> *gcPendingOperation =
+ new IJSExtCancelPendingOperationPrivateObject<EventMessagingService>(event, eventCanceller);
- }
- Catch(WrtDeviceApis::Commons::ConversionException) {
- return JSTizenExceptionFactory::postException(context, exception,
- JSTizenException::TYPE_MISMATCH_ERROR, JSMESSAGING_EXCEPTION_MSG_TYPE_MISMATCH);
+ return JSObjectMake(globalContext, JSPendingOperation::getClassRef(), gcPendingOperation);
+#endif
+ //return converter->toJSValueRef(event->opId);
+ return JSValueMakeUndefined(context);
}
Catch(WrtDeviceApis::Commons::NullPointerException) {
- return JSTizenExceptionFactory::postException(context, exception,
- JSTizenException::TYPE_MISMATCH_ERROR, JSMESSAGING_EXCEPTION_MSG_TYPE_MISMATCH);
- }
- Catch(WrtDeviceApis::Commons::InvalidArgumentException) {
callbackManager->callOnError(JSTizenExceptionFactory::makeErrorObject(context,
- JSTizenException::INVALID_VALUES_ERROR, JSMESSAGING_EXCEPTION_MSG_INVALID_ARGUMENT));
+ JSTizenException::INVALID_VALUES_ERROR, JSMESSAGING_EXCEPTION_MSG_INVALID_ARGUMENT));
+ return JSValueMakeNull(context);
}
- Catch(WrtDeviceApis::Commons::PlatformException) {
+ Catch(WrtDeviceApis::Commons::Exception) {
callbackManager->callOnError(JSTizenExceptionFactory::makeErrorObject(context,
- JSTizenException::UNKNOWN_ERROR, JSMESSAGING_EXCEPTION_MSG_UNKNOWN));
+ JSTizenException::UNKNOWN_ERROR, JSMESSAGING_EXCEPTION_MSG_UNKNOWN));
+ return JSValueMakeNull(context);
}
return JSValueMakeNull(context);
JSContextRef globalContext = priv->getContext(); //create global Context
LogInfo(">>> argument count : " << argumentCount);
- if (argumentCount < 2) {
+ if (argumentCount < 3) {
return JSTizenExceptionFactory::postException(context, exception,
- JSTizenException::TYPE_MISMATCH_ERROR, JSMESSAGING_EXCEPTION_MSG_INVALID_ARGUMENT);
+ JSTizenException::TYPE_MISMATCH_ERROR, JSMESSAGING_EXCEPTION_MSG_TYPE_MISMATCH);
}
Validator check(context, exception); //create check
//check permission.
AceSecurityStatus status = MESSAGING_CHECK_ACCESS(
- priv->getContext(),
MessagingExportedNames[MESSAGING_FUNCTION_API_LOAD_MESSAGE_ATTACHMENT]);
TIZEN_ASYNC_CBM_ACCESS_HANDLER(status, context, callbackManager);
+
+ //argu 1. Attachment (mandatory)
+ if (!JSValueIsObject(context, arguments[0]))
+ {
+ ThrowMsg(WrtDeviceApis::Commons::InvalidArgumentException,"invalid argument exception");
+ }
+
+ //argu 2. success callback
+ if ( check.isCallback(arguments[1]))
+ callbackManager->setOnSuccess(converter->toFunctionOrNull(arguments[1]));
+ else
+ ThrowMsg(WrtDeviceApis::Commons::InvalidArgumentException,"invalid argument exception");
- if (JSValueIsObject(context, arguments[0]) && !JSValueIsNull(context, arguments[0]))
+ //argu 3. error callback (optional & nullable)
+ if ( argumentCount > 2)
{
- EventMessagingServicePrivateDataPtr privateData( new EventMessagingServicePrivateData(callbackManager) );
- if (!privateData)
- return JSTizenExceptionFactory::postException(context, exception,
- JSTizenException::UNKNOWN_ERROR, JSMESSAGING_EXCEPTION_MSG_UNKNOWN);
-
- switch(argumentCount){
- case 3:
- {
- if ( Validator(context).isCallback(arguments[2]))
- {
- callbackManager->setOnError(converter->toFunctionOrNull(arguments[2]));
- }
- else
- {
- return JSTizenExceptionFactory::postException(context, exception,
- JSTizenException::INVALID_VALUES_ERROR, JSMESSAGING_EXCEPTION_MSG_INVALID_ARGUMENT);
- }
- }
- case 2:
- {
- if ( Validator(context).isCallback(arguments[1]))
- {
- callbackManager->setOnSuccess(converter->toFunctionOrNull(arguments[1]));
- }
- else
- {
- return JSTizenExceptionFactory::postException(context, exception,
- JSTizenException::INVALID_VALUES_ERROR, JSMESSAGING_EXCEPTION_MSG_INVALID_ARGUMENT);
- }
- }
- }
+ if ( check.isCallback(arguments[2]))
+ callbackManager->setOnError(arguments[2]);
+ else if(check.isNullOrUndefined(arguments[2]))
+ callbackManager->setOnError(NULL);
+ else
+ Throw(WrtDeviceApis::Commons::InvalidArgumentException);
+ }
- Api::Messaging::EventMessagingServicePtr event(new Api::Messaging::EventMessagingService()); //create event
- event->setEventType(EventMessagingService::MESSAGING_SERVICE_EVENT_TYPE_LOAD_MESSAGE_ATTACHMENT);
- event->setPrivateData(DPL::StaticPointerCast<WrtDeviceApis::Commons::IEventPrivateData>(privateData));
- event->setForAsynchronousCall(&MessagingController::getInstance());
-
- Api::Messaging::IAttachmentPtr iAttchmentPtr = converter->toIAttachment(arguments[0]);
- if (iAttchmentPtr)
- {
- event->m_attachment = iAttchmentPtr;
- event->m_message = event->m_attachment->getMessage();
-
- if (!event->m_message)
- return JSTizenExceptionFactory::postException(context, exception,
+ }
+ Catch(WrtDeviceApis::Commons::ConversionException) {
+ return JSTizenExceptionFactory::postException(context, exception,
+ JSTizenException::TYPE_MISMATCH_ERROR, JSMESSAGING_EXCEPTION_MSG_TYPE_MISMATCH);
+ }
+ Catch(WrtDeviceApis::Commons::InvalidArgumentException) {
+ return JSTizenExceptionFactory::postException(context, exception,
+ JSTizenException::TYPE_MISMATCH_ERROR, JSMESSAGING_EXCEPTION_MSG_TYPE_MISMATCH);
+ }
+ Catch(WrtDeviceApis::Commons::Exception) {
+ return JSTizenExceptionFactory::postException(context, exception,
JSTizenException::UNKNOWN_ERROR, JSMESSAGING_EXCEPTION_MSG_UNKNOWN);
+ }
- privateData->setMessageJSValueRef(arguments[0]); //set attachment JSValueRef.
- }
- else
- {
+
+ EventMessagingServicePrivateDataPtr privateData( new EventMessagingServicePrivateData(callbackManager) );
+ if (!privateData)
return JSTizenExceptionFactory::postException(context, exception,
- JSTizenException::NOT_FOUND_ERROR, JSMESSAGING_EXCEPTION_MSG_NOT_FOUND);
- }
+ JSTizenException::UNKNOWN_ERROR, JSMESSAGING_EXCEPTION_MSG_UNKNOWN);
+
+ Try {
+ Api::Messaging::EventMessagingServicePtr event(new Api::Messaging::EventMessagingService()); //create event
+ event->setEventType(MESSAGING_SERVICE_EVENT_TYPE_LOAD_MESSAGE_ATTACHMENT);
+ event->setPrivateData(DPL::StaticPointerCast<WrtDeviceApis::Commons::IEventPrivateData>(privateData));
+ event->setForAsynchronousCall(&MessagingController::getInstance());
+
+ Api::Messaging::IAttachmentPtr iAttchmentPtr = converter->toIAttachment(arguments[0]);
+
+ event->m_attachment = iAttchmentPtr;
+ event->m_message = event->m_attachment->getMessage();
+
+ privateData->setMessageJSValueRef(arguments[0]); //set attachment JSValueRef.
IMessagingServicePtr imessagingService = priv->getObject();
if (imessagingService)
//JSValueRef pendingOperation = WrtDeviceApis::CommonsJavaScript::makePendingOperation(globalContext, event); //create pendingOperation.
Api::Messaging::ReqReceiverMessageSingleton::Instance().loadMessageAttachment(event); //load message Body
+#if 0
+ DPL::SharedPtr<IExternEventCanceler<EventMessagingService> > eventCanceller =
+ DPL::StaticPointerCast<IExternEventCanceler<EventMessagingService> >(imessagingService);
- return converter->toJSValueRef(event->opId);
+ IJSExtCancelPendingOperationPrivateObject<EventMessagingService> *gcPendingOperation =
+ new IJSExtCancelPendingOperationPrivateObject<EventMessagingService>(event, eventCanceller);
+
+ return JSObjectMake(globalContext, JSPendingOperation::getClassRef(), gcPendingOperation);
+#endif
+ //return converter->toJSValueRef(event->opId);
+ return JSValueMakeUndefined(context);
+
}
else
{
return JSTizenExceptionFactory::postException(context, exception,
JSTizenException::NOT_FOUND_ERROR, JSMESSAGING_EXCEPTION_MSG_NOT_FOUND);
}
-
-
- }
- else
- {
- return JSTizenExceptionFactory::postException(context, exception,
- JSTizenException::TYPE_MISMATCH_ERROR, JSMESSAGING_EXCEPTION_MSG_INVALID_ARGUMENT);
- }
- }
- Catch(WrtDeviceApis::Commons::ConversionException) {
- return JSTizenExceptionFactory::postException(context, exception,
- JSTizenException::TYPE_MISMATCH_ERROR, JSMESSAGING_EXCEPTION_MSG_TYPE_MISMATCH);
- }
- Catch(WrtDeviceApis::Commons::NullPointerException) {
- return JSTizenExceptionFactory::postException(context, exception,
- JSTizenException::TYPE_MISMATCH_ERROR, JSMESSAGING_EXCEPTION_MSG_TYPE_MISMATCH);
- }
- Catch(WrtDeviceApis::Commons::InvalidArgumentException) {
+ }
+ Catch(WrtDeviceApis::Commons::NullPointerException) {
callbackManager->callOnError(JSTizenExceptionFactory::makeErrorObject(context,
- JSTizenException::INVALID_VALUES_ERROR, JSMESSAGING_EXCEPTION_MSG_INVALID_ARGUMENT));
- }
- Catch(WrtDeviceApis::Commons::PlatformException) {
+ JSTizenException::INVALID_VALUES_ERROR, JSMESSAGING_EXCEPTION_MSG_INVALID_ARGUMENT));
+ return JSValueMakeNull(context);
+ }
+ Catch(WrtDeviceApis::Commons::Exception) {
callbackManager->callOnError(JSTizenExceptionFactory::makeErrorObject(context,
JSTizenException::UNKNOWN_ERROR, JSMESSAGING_EXCEPTION_MSG_UNKNOWN));
- }
+ return JSValueMakeNull(context);
+ }
- return JSValueMakeNull(context);
+
+ return JSValueMakeUndefined(context);
}
JSValueRef JSMessagingService::sync(JSContextRef context, JSObjectRef function, JSObjectRef thisObject,
LogInfo(">>> argument count : " << argumentCount);
- if (argumentCount > 4 || argumentCount < 2 ) {
+ if (argumentCount < 2 ) {
return JSTizenExceptionFactory::postException(context, exception,
- JSTizenException::TYPE_MISMATCH_ERROR, JSMESSAGING_EXCEPTION_MSG_INVALID_ARGUMENT);
+ JSTizenException::TYPE_MISMATCH_ERROR, JSMESSAGING_EXCEPTION_MSG_TYPE_MISMATCH);
}
Validator check(context, exception); //check context
Api::Messaging::MessageType msgType = (Api::Messaging::MessageType)imessagingService->getType();
LogInfo("msgType :" << msgType);
+
+ //check permission.
+ AceSecurityStatus status = MESSAGING_CHECK_ACCESS(
+ MessagingExportedNames[MESSAGING_FUNCTION_API_SYNC]);
+ TIZEN_ASYNC_CBM_ACCESS_HANDLER(status, context, callbackManager);
+
Try {
int limit = -1; //sync limit
-
+ //argu 1. success callback.
if (JSValueIsObject(context, arguments[0]) && Validator(context).isCallback(arguments[0])) //check
{
callbackManager->setOnSuccess(converter->toFunctionOrNull(arguments[0]));
- if (converter->toFunctionOrNull(arguments[1]) && Validator(context).isCallback(arguments[1]) )
- {
- callbackManager->setOnError(converter->toFunctionOrNull(arguments[1]));
- }
-
- //check permission.
- AceSecurityStatus status = MESSAGING_CHECK_ACCESS(
- priv->getContext(),
- MessagingExportedNames[MESSAGING_FUNCTION_API_SYNC]);
- TIZEN_ASYNC_CBM_ACCESS_HANDLER(status, context, callbackManager);
-
- EventMessagingServicePrivateDataPtr privateData( new EventMessagingServicePrivateData(callbackManager) );
+ }
+ //argu 2. error callback ( nullable )
+ if ( check.isCallback(arguments[1]))
+ callbackManager->setOnError(arguments[1]);
+ else if(check.isNullOrUndefined(arguments[1]))
+ callbackManager->setOnError(NULL);
+ else
+ Throw(WrtDeviceApis::Commons::InvalidArgumentException);
- Api::Messaging::EventMessagingServicePtr event(new Api::Messaging::EventMessagingService()); //create event
+ //argu 3. limit ( optional )
+ if (argumentCount > 2)
+ {
+ limit = converter->toInt(arguments[2]);
+ if ( limit < 0 )
+ {
+ callbackManager->callOnError(JSTizenExceptionFactory::makeErrorObject(context,
+ JSTizenException::INVALID_VALUES_ERROR, JSMESSAGING_EXCEPTION_MSG_INVALID_ARGUMENT));
+ return JSValueMakeNull(context);
+ }
+ }
- if (argumentCount == 3 && !JSValueIsNull(context, arguments[2]))
- limit = converter->toInt(arguments[2]);
+ EventMessagingServicePrivateDataPtr privateData( new EventMessagingServicePrivateData(callbackManager) );
+ Api::Messaging::EventMessagingServicePtr event(new Api::Messaging::EventMessagingService()); //create event
LogDebug("limit : " << limit);
event->m_sync_account_id = imessagingService->getAccountID() ;
event->m_sync_limit = limit;
event->m_messagingService = imessagingService;
+ imessagingService->setEventToOpId(event->opId, event);
- event->setEventType(EventMessagingService::MESSAGING_SERVICE_EVENT_TYPE_SYNC);
+ event->setEventType(MESSAGING_SERVICE_EVENT_TYPE_SYNC);
event->setPrivateData(DPL::StaticPointerCast<WrtDeviceApis::Commons::IEventPrivateData>(privateData));
event->setForAsynchronousCall(&MessagingController::getInstance());
Api::Messaging::ReqReceiverMessageSingleton::Instance().sync(event); //load message Body
-
+#if 0
+ DPL::SharedPtr<IExternEventCanceler<EventMessagingService> > eventCanceller =
+ DPL::StaticPointerCast<IExternEventCanceler<EventMessagingService> >(imessagingService);
+
+ IJSExtCancelPendingOperationPrivateObject<EventMessagingService> *gcPendingOperation =
+ new IJSExtCancelPendingOperationPrivateObject<EventMessagingService>(event, eventCanceller);
+
+ return JSObjectMake(globalContext, JSPendingOperation::getClassRef(), gcPendingOperation);
+#endif
return converter->toJSValueRef(event->opId);
-
- }
- else
- {
- return JSTizenExceptionFactory::postException(context, exception,
- JSTizenException::TYPE_MISMATCH_ERROR, JSMESSAGING_EXCEPTION_MSG_TYPE_MISMATCH);
- }
+
}
Catch(WrtDeviceApis::Commons::ConversionException) {
return JSTizenExceptionFactory::postException(context, exception,
if (priv) {
JSContextRef globalContext = priv->getContext(); //get global Context
-#if 0
- AceSecurityStatus status = MESSAGING_CHECK_ACCESS(
- globalContext,
- MESSAGING_FUNCTION_API_SYNC);
-#endif
LogInfo(">>> argument count : " << argumentCount);
- if (argumentCount > 4 || argumentCount < 1) {
+ if (argumentCount < 3) {
return JSTizenExceptionFactory::postException(context, exception,
- JSTizenException::TYPE_MISMATCH_ERROR, JSMESSAGING_EXCEPTION_MSG_INVALID_ARGUMENT);
+ JSTizenException::TYPE_MISMATCH_ERROR, JSMESSAGING_EXCEPTION_MSG_TYPE_MISMATCH);
}
Validator check(context, exception); //check context
Api::Messaging::MessageType msgType = (Api::Messaging::MessageType)imessagingService->getType();
LogInfo("msgType :" << msgType);
+ //check permission
+ AceSecurityStatus status = MESSAGING_CHECK_ACCESS(
+ MessagingExportedNames[MESSAGING_FUNCTION_API_SYNC_FOLDER]);
+ TIZEN_ASYNC_CBM_ACCESS_HANDLER(status, context, callbackManager);
+
Try {
int limit = -1;
-
- if (JSValueIsObject(context, arguments[0]) && !Validator(context).isCallback(arguments[0])) //check
- {
- AceSecurityStatus status = MESSAGING_CHECK_ACCESS(
- priv->getContext(),
- MessagingExportedNames[MESSAGING_FUNCTION_API_SYNC_FOLDER]);
- TIZEN_ASYNC_CBM_ACCESS_HANDLER(status, context, callbackManager);
-
- EventMessagingServicePrivateDataPtr privateData( new EventMessagingServicePrivateData(callbackManager) );
- //private->setSyncAccountID( imessagingService->getAccountID()); //set account ID
-
- Api::Messaging::EventMessagingServicePtr event(new Api::Messaging::EventMessagingService()); //create event
-
+ //argu 1. Folder (mandatory)
+ if (!JSValueIsObject(context, arguments[0]))
+ {
+ return JSTizenExceptionFactory::postException(context, exception,
+ JSTizenException::INVALID_VALUES_ERROR, JSMESSAGING_EXCEPTION_MSG_INVALID_ARGUMENT);
+ }
+ IMessageFolderPtr folder = converter->toIMessageFolder(arguments[0]);
- IMessageFolderPtr folder = converter->toIMessageFolder(arguments[0]);
- if ( folder )
+ //argu 2. success callback.
+ if (Validator(context).isCallback(arguments[1]))
+ callbackManager->setOnSuccess(converter->toFunctionOrNull(arguments[1]));
+ else
+ ThrowMsg(WrtDeviceApis::Commons::InvalidArgumentException,"invalid argument exception");
+
+ //argu 3. error callback (optional & nullable)
+ if ( argumentCount > 2)
+ {
+ if ( check.isCallback(arguments[2]))
+ callbackManager->setOnError(arguments[2]);
+ else if(check.isNullOrUndefined(arguments[2]))
+ callbackManager->setOnError(NULL);
+ else
+ Throw(WrtDeviceApis::Commons::InvalidArgumentException);
+ }
+ //argu 4. limit ( optional )
+ if ( argumentCount > 3 )
+ {
+ limit = converter->toInt(arguments[3]);
+ if ( limit < 0 )
{
- //event->m_folder_name = folder->getName(); //it will be changed to the folder ptr
- event->m_folder_name = folder->getPath(); //it will be changed to the folder ptr
+ callbackManager->callOnError(JSTizenExceptionFactory::makeErrorObject(context,
+ JSTizenException::INVALID_VALUES_ERROR, JSMESSAGING_EXCEPTION_MSG_INVALID_ARGUMENT));
+ return JSValueMakeNull(context);
}
-
- if ( argumentCount > 1 )
+ }
+
+ Api::Messaging::EventMessagingServicePtr event(new Api::Messaging::EventMessagingService()); //create event
+ EventMessagingServicePrivateDataPtr privateData( new EventMessagingServicePrivateData(callbackManager) );
+
+ if ( folder )
{
- if (JSValueIsObject(context, arguments[1]) && Validator(context).isCallback(arguments[1])) //check
- {
- callbackManager->setOnSuccess(converter->toFunctionOrNull(arguments[1]));
- }
-
- if ( argumentCount > 2 )
- {
- if (JSValueIsObject(context, arguments[2]) && Validator(context).isCallback(arguments[2])) //check
- {
- callbackManager->setOnError(converter->toFunctionOrNull(arguments[2]));
- }
- }
-
- if (argumentCount == 4 && !JSValueIsNull(context, arguments[3]))
- limit = converter->toInt(arguments[3]);
-
+ event->m_folder_name = folder->getPath(); //it will be changed to the folder ptr
}
LogDebug("limit : " << limit);
event ->m_sync_account_id = imessagingService->getAccountID() ;
event ->m_sync_limit = limit;
event->m_messagingService = imessagingService;
+ imessagingService->setEventToOpId(event->opId, event);
- event->setEventType(EventMessagingService::MESSAGING_SERVICE_EVENT_TYPE_SYNC_FOLDER);
+ event->setEventType(MESSAGING_SERVICE_EVENT_TYPE_SYNC_FOLDER);
event->setPrivateData(DPL::StaticPointerCast<WrtDeviceApis::Commons::IEventPrivateData>(privateData));
event->setForAsynchronousCall(&MessagingController::getInstance());
Api::Messaging::ReqReceiverMessageSingleton::Instance().syncFolder(event); //load message Body
+#if 0
+ DPL::SharedPtr<IExternEventCanceler<EventMessagingService> > eventCanceller =
+ DPL::StaticPointerCast<IExternEventCanceler<EventMessagingService> >(imessagingService);
+
+ IJSExtCancelPendingOperationPrivateObject<EventMessagingService> *gcPendingOperation =
+ new IJSExtCancelPendingOperationPrivateObject<EventMessagingService>(event, eventCanceller);
+
+ return JSObjectMake(globalContext, JSPendingOperation::getClassRef(), gcPendingOperation);
+#endif
return converter->toJSValueRef(event->opId);
-
- }
- else
- {
- return JSTizenExceptionFactory::postException(context, exception,
- JSTizenException::TYPE_MISMATCH_ERROR, JSMESSAGING_EXCEPTION_MSG_TYPE_MISMATCH);
- }
}
Catch(WrtDeviceApis::Commons::UnsupportedException) {
return JSTizenExceptionFactory::postException(context, exception,
JSTizenException::TYPE_MISMATCH_ERROR, JSMESSAGING_EXCEPTION_MSG_TYPE_MISMATCH);
}
Catch(WrtDeviceApis::Commons::NullPointerException) {
- return JSTizenExceptionFactory::postException(context, exception,
- JSTizenException::TYPE_MISMATCH_ERROR, JSMESSAGING_EXCEPTION_MSG_TYPE_MISMATCH);
+ callbackManager->callOnError(JSTizenExceptionFactory::makeErrorObject(context,
+ JSTizenException::INVALID_VALUES_ERROR, JSMESSAGING_EXCEPTION_MSG_INVALID_ARGUMENT));
+ return JSValueMakeNull(context);
}
Catch(WrtDeviceApis::Commons::InvalidArgumentException) {
callbackManager->callOnError(JSTizenExceptionFactory::makeErrorObject(context,
JSTizenException::INVALID_VALUES_ERROR, JSMESSAGING_EXCEPTION_MSG_INVALID_ARGUMENT));
+ return JSValueMakeNull(context);
}
Catch(WrtDeviceApis::Commons::PlatformException) {
callbackManager->callOnError(JSTizenExceptionFactory::makeErrorObject(context,
{ //for email.
if (msgType == Api::Messaging::EMAIL)
{
+ IMessagePtr msg = imessagingService->getMessageFromOpId(opId);
+ Api::Messaging::IEmailPtr email = Api::Messaging::MessageFactory::convertToEmail(msg);
+
if ( opType == Api::Messaging::MESSAGING_SERVICE_OP_DOWNLOAD_BODY )
{
- IMessagePtr msg = imessagingService->getMessageFromOpId(opId);
- Api::Messaging::IEmailPtr email = Api::Messaging::MessageFactory::convertToEmail(msg);
LogDebug("Cancel Download Body , handle = " << handle);
email->downloadBodyCancel(handle);
}
+ else if ( opType == Api::Messaging::MESSAGING_SERVICE_OP_DOWNLOAD_ATTACHMENT)
+ {
+ LogDebug("Cancel Download Attachment , handle = " << handle);
+ email->downloadAttachmentCancel(handle);
+ }
else if ( opType == Api::Messaging::MESSAGING_SERVICE_OP_SYNC )
{
LogDebug("Cancel Sync , handle = " << handle);
}
LogDebug(">>>");
- return JSValueMakeNull(context);
+ return JSValueMakeUndefined(context);
+}
+
+JSValueRef JSMessagingService::stopSync(JSContextRef context, JSObjectRef function, JSObjectRef thisObject,
+ size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
+{
+ LogDebug("entered");
+
+ JSMessagingServicePriv* priv = static_cast<JSMessagingServicePriv*>(JSObjectGetPrivate(thisObject)); //get private object
+
+ if (priv)
+ {
+ IMessagingServicePtr imessagingService = priv->getObject();
+ Try
+ {
+ LogInfo(">>> argument count : " << argumentCount);
+
+ if ( argumentCount > 0 && !Validator(context).isCallback(arguments[0]))
+ {
+ ConverterMessageFactory::ConverterType converter = ConverterMessageFactory::getConverter(context);
+ Api::Messaging::MessageType msgType = (Api::Messaging::MessageType)imessagingService->getType();
+ LogInfo("msgType :" << msgType);
+
+ int opId = converter->toLong( arguments[0]); //Fetch operation ID
+ int handle = imessagingService->getHandleFromOpId(opId);
+ if ( handle < 0 )
+ {
+ ThrowMsg(WrtDeviceApis::Commons::NotFoundException,"Operation ID Not found");
+ }
+
+ int opType = imessagingService->getOpTypeFromOpId(opId);
+ LogInfo("operation ID :" << opId << " operation Type : " << opType);
+
+ if (msgType == Api::Messaging::EMAIL)
+ {
+ if ( opType == Api::Messaging::MESSAGING_SERVICE_OP_SYNC )
+ {
+ LogDebug("Cancel Sync , handle = " << handle);
+ imessagingService->syncCancel(handle);
+ }
+ else if ( opType == Api::Messaging::MESSAGING_SERVICE_OP_SYNC_FOLDER )
+ {
+ LogDebug("Cancel Sync Folder, handle = " << handle);
+ imessagingService->syncFolderCancel(handle);
+ }
+
+ //call error callback.
+ EventMessagingServicePtr event = imessagingService->getEventFromOpId(opId);
+ if (event)
+ {
+ LogDebug("get callback Manager");
+ EventMessagingServicePrivateDataPtr privateData =
+ DPL::StaticPointerCast<EventMessagingServicePrivateData>(event->getPrivateData());
+
+ WrtDeviceApis::CommonsJavaScript::JSCallbackManagerPtr callbackManager = privateData->getCallbackManager(); //get callback manager
+ JSContextRef globalContext = callbackManager->getContext();
+ if (callbackManager)
+ {
+ LogDebug("call error callback.");
+ callbackManager->callOnError(JSDOMExceptionFactory::AbortException.make(globalContext, exception));
+ }
+ }
+
+ imessagingService->deleteOpId(opId);
+
+ }
+ else
+ {
+ ThrowMsg(WrtDeviceApis::Commons::UnsupportedException, "Operation Type is mismatched");
+ }
+
+ }
+ else
+ {
+ ThrowMsg(WrtDeviceApis::Commons::InvalidArgumentException,"invalid argument exception");
+ }
+
+ }
+ Catch (WrtDeviceApis::Commons::InvalidArgumentException){
+ LogError("Exception: " << _rethrown_exception.GetMessage());
+ return JSTizenExceptionFactory::postException(context, exception,
+ JSTizenException::INVALID_VALUES_ERROR, JSMESSAGING_EXCEPTION_MSG_INVALID_ARGUMENT);
+ }
+ Catch (WrtDeviceApis::Commons::NotFoundException){
+ LogError("Exception: " << _rethrown_exception.GetMessage());
+ return JSTizenExceptionFactory::postException(context, exception,
+ JSTizenException::INVALID_VALUES_ERROR, JSMESSAGING_EXCEPTION_MSG_INVALID_ARGUMENT);
+ //JSTizenException::NOT_FOUND_ERROR, JSMESSAGING_EXCEPTION_MSG_NOT_FOUND);
+ }
+ Catch (WrtDeviceApis::Commons::UnsupportedException){
+ LogError("Exception: " << _rethrown_exception.GetMessage());
+ return JSTizenExceptionFactory::postException(context, exception,
+ JSTizenException::NOT_SUPPORTED_ERROR, JSMESSAGING_EXCEPTION_MSG_NOT_SUPPORTED);
+ }
+ Catch (WrtDeviceApis::Commons::Exception){
+ LogError("Exception: " << _rethrown_exception.GetMessage());
+ return JSTizenExceptionFactory::postException(context, exception,
+ JSTizenException::UNKNOWN_ERROR, JSMESSAGING_EXCEPTION_MSG_UNKNOWN);
+ }
+
+ }
+ else
+ {
+ LogDebug(" Private Object is NULL ");
+ return JSTizenExceptionFactory::postException(context, exception,
+ JSTizenException::NOT_FOUND_ERROR, JSMESSAGING_EXCEPTION_MSG_NOT_FOUND);
+ }
+
+ LogDebug(">>>");
+ return JSValueMakeUndefined(context);
}
+
}
}