2 // Tizen Web Device API
3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
5 // Licensed under the Apache License, Version 2.0 (the License);
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
9 // http://www.apache.org/licenses/LICENSE-2.0
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
18 #include "JSMessagingService.h"
19 #include "MessagingController.h"
20 #include <CommonsJavaScript/Converter.h>
21 #include <CommonsJavaScript/Validator.h>
22 #include <CommonsJavaScript/JSUtils.h>
23 #include <CommonsJavaScript/JSCallbackManager.h>
24 #include <CommonsJavaScript/Utils.h>
25 #include <CommonsJavaScript/ScopedJSStringRef.h>
26 #include <CommonsJavaScript/JSPendingOperation.h>
27 #include <CommonsJavaScript/JSDOMExceptionFactory.h>
28 #include <Commons/StringUtils.h>
30 #include "ReqReceiverMessage.h"
31 #include <JSTizenExceptionFactory.h>
32 #include <JSTizenException.h>
33 #include <SecurityExceptions.h>
35 #include "MessagingErrorMsg.h"
36 #include "ConverterMessage.h"
37 #include "MessagingListener.h"
38 #include "JSMessagingStorage.h"
39 #include "JSMessage.h"
40 #include "EventSendMessagePrivateData.h" //for send message
41 #include "EventMessagingServicePrivateData.h"
42 #include "MessageAsyncCallbackManager.h"
43 #include "plugin_config.h"
47 using namespace WrtDeviceApis;
48 using namespace WrtDeviceApis::Commons;
49 using namespace WrtDeviceApis::CommonsJavaScript;
50 using namespace DeviceAPI::Messaging;
51 using namespace DeviceAPI::Common;
56 JSClassRef JSMessagingService::m_jsClassRef = NULL;
57 JSClassDefinition JSMessagingService::m_classInfo = {
59 kJSClassAttributeNone,
69 NULL, //deleteProperty,Geolocation
70 NULL, //getPropertyNames,
77 JSStaticValue JSMessagingService::m_property[] =
79 {"id", getProperty, NULL, kJSPropertyAttributeReadOnly},
80 {"type", getProperty, NULL, kJSPropertyAttributeReadOnly},
81 {"name", getProperty, NULL, kJSPropertyAttributeReadOnly},
82 {"messageStorage", getProperty, NULL, kJSPropertyAttributeReadOnly},
86 JSStaticFunction JSMessagingService::m_function[] = {
87 //{ "createMessage", JSMessagingService::createMessage, kJSPropertyAttributeNone },
88 { "sendMessage", JSMessagingService::sendMessage, kJSPropertyAttributeNone },
89 { "loadMessageBody", JSMessagingService::loadMessageBody, kJSPropertyAttributeNone },
90 { "loadMessageAttachment", JSMessagingService::loadMessageAttachment, kJSPropertyAttributeNone },
91 { "sync", JSMessagingService::sync, kJSPropertyAttributeNone },
92 { "syncFolder", JSMessagingService::syncFolder, kJSPropertyAttributeNone },
93 //{ "cancelOperation", JSMessagingService::cancelOperation, kJSPropertyAttributeNone },
94 { "stopSync", JSMessagingService::stopSync, kJSPropertyAttributeNone },
98 const JSClassRef JSMessagingService::getClassRef() {
100 m_jsClassRef = JSClassCreate(&m_classInfo);
105 void JSMessagingService::initialize(JSContextRef context, JSObjectRef object) {
106 LogDebug("creation messaging Service instance");
109 void JSMessagingService::finalize(JSObjectRef object) {
110 LogDebug("finalize messaging instance");
111 //JSMessagingServicePriv *priv = static_cast<JSMessagingServicePriv*>(JSObjectGetPrivate(object));
112 JSMessagingServicePriv *priv = static_cast<JSMessagingServicePriv*>(JSObjectGetPrivate(object));
116 bool JSMessagingService::hasInstance(JSContextRef context, JSObjectRef constructor, JSValueRef possibleInstance, JSValueRef* exception) {
117 return JSValueIsObjectOfClass(context, possibleInstance, getClassRef());
120 JSObjectRef JSMessagingService::createJSObject(JSContextRef context, const IMessagingServicePtr &messagingService)
122 JSMessagingServicePriv* priv = new JSMessagingServicePriv( context, messagingService); //make private class.
123 return JSObjectMake(context, getClassRef(), priv);
126 JSValueRef JSMessagingService::getProperty(JSContextRef context, JSObjectRef object, JSStringRef propertyName, JSValueRef* exception)
129 JSValueRef retVal = NULL;
131 JSMessagingServicePriv* priv = static_cast<JSMessagingServicePriv*>(JSObjectGetPrivate(object)); //get private object
134 IMessagingServicePtr imessagingService = priv->getObject();
136 ConverterMessageFactory::ConverterType converter = ConverterMessageFactory::getConverter(context);
138 if (JSStringIsEqualToUTF8CString(propertyName, "type")) {
139 LogDebug("type" << ":" << imessagingService->getType());
140 retVal = converter->toJSValueRef(converter->toMessageType(imessagingService->getType()));
141 } else if (JSStringIsEqualToUTF8CString(propertyName, "name")) {
142 LogDebug("name" << ":" << imessagingService->getName());
143 retVal = converter->toJSValueRef(imessagingService->getName());
144 } else if (JSStringIsEqualToUTF8CString(propertyName, "id")) {
145 LogDebug("accountId" << ":" << imessagingService->getAccountID());
147 std::stringstream stream;
148 stream << imessagingService->getAccountID();
150 ThrowMsg(WrtDeviceApis::Commons::UnknownException,"Couldn't convert e-mail account id");
153 retVal = converter->toJSValueRef(stream.str());
154 } else if (JSStringIsEqualToUTF8CString(propertyName, "messageStorage")) {
155 JSContextRef l_globalContext = converter->toJSGlobalContext(object);
156 MessagingStoragePrivObjPtr storagePriv(new MessagingStoragePrivObj());
157 // MessagingListenerPtr listener_priv = MessagingListener::getInstance(l_globalContext) ;
158 storagePriv->m_index = imessagingService->getAccountID();
159 storagePriv->m_type = imessagingService->getType();
160 LogDebug("type" << ":" << imessagingService->getType());
161 LogDebug("accountId" << ":" << imessagingService->getAccountID());
163 MessagingStoragePriv *priv = new MessagingStoragePriv(l_globalContext, storagePriv);
164 //MessagingStoragePrivObjPtr storagePriv = priv->getObject();
166 // retVal = JSUtils::makeObject(l_globalContext, JSMessagingStorage::getClassRef(), priv);
167 retVal = JSObjectMake(l_globalContext, JSMessagingStorage::getClassRef(), priv);
170 retVal = JSValueMakeUndefined(context);
173 } Catch (WrtDeviceApis::Commons::Exception){
174 LogError("Exception: " << _rethrown_exception.GetMessage());
175 return JSTizenExceptionFactory::postException(context, exception,
176 JSTizenException::UNKNOWN_ERROR, JSMESSAGING_EXCEPTION_MSG_UNKNOWN);
185 LogDebug(" Private Object is NULL ");
186 return JSTizenExceptionFactory::postException(context, exception,
187 JSTizenException::NOT_FOUND_ERROR, JSMESSAGING_EXCEPTION_MSG_NOT_FOUND);
192 JSValueRef JSMessagingService::createMessage(JSContextRef context, JSObjectRef object, JSObjectRef thisObject, size_t argumentCount,
193 const JSValueRef arguments[], JSValueRef* exception)
197 LogDebug("arumentConunt:" << argumentCount);
199 JSMessagingServicePriv* priv = static_cast<JSMessagingServicePriv*>(JSObjectGetPrivate(thisObject));
202 AceSecurityStatus status = MESSAGING_CHECK_ACCESS(
203 MessagingExportedNames[MESSAGING_FUNCTION_API_CREATE_MESSAGE]);
204 TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
207 ConverterMessageFactory::ConverterType converter = ConverterMessageFactory::getConverter(context);
208 JSContextRef l_globalContext = converter->toJSGlobalContext(thisObject);
209 Validator check(context, exception);
211 IMessagingServicePtr imessagingService = priv->getObject(); //get MessagingService.
212 JSValueRef objMsg = NULL;
214 MessageType msgType = (MessageType)imessagingService->getType();
215 LogInfo("msgType :" << msgType);
217 if (msgType == EMAIL)
219 EmailAccountInfo account = imessagingService->getCurrentEmailAccount();
220 LogDebug("Account Address:" << &account);
221 objMsg = JSMessage::createJSObject(l_globalContext, account, msgType); //make message JSValueRef.
225 objMsg = JSMessage::createJSObject(l_globalContext, msgType); //make message JSValueRef.
229 if ( argumentCount == 1)
231 IMessagePtr msg = converter->toIMessage(objMsg) ;
234 ThrowMsg(WrtDeviceApis::Commons::PlatformException,"platform exception");
236 LogDebug ("##### msg type is " << msg->getId());
238 const ScopedJSStringRef subjectStr(JSStringCreateWithUTF8CString("subject"));
239 const ScopedJSStringRef toStr(JSStringCreateWithUTF8CString("to"));
240 const ScopedJSStringRef ccStr(JSStringCreateWithUTF8CString("cc"));
241 const ScopedJSStringRef bccStr(JSStringCreateWithUTF8CString("bcc"));
242 const ScopedJSStringRef plainBodyStr(JSStringCreateWithUTF8CString("plainBody"));
243 const ScopedJSStringRef htmlBodyStr(JSStringCreateWithUTF8CString("htmlBody"));
244 const ScopedJSStringRef priorityStr(JSStringCreateWithUTF8CString("isHighPriority"));
246 JSObjectRef arg = converter->toJSObjectRef(arguments[0]);
247 JSValueRef subjectData = JSObjectGetProperty(l_globalContext, arg, subjectStr.get(), NULL);
248 JSValueRef toData = JSObjectGetProperty(l_globalContext, arg, toStr.get(), NULL);
249 JSValueRef ccData = JSObjectGetProperty(l_globalContext, arg, ccStr.get(), NULL);
250 JSValueRef bccData = JSObjectGetProperty(l_globalContext, arg, bccStr.get(), NULL);
251 JSValueRef plainBodyData = JSObjectGetProperty(l_globalContext, arg, plainBodyStr.get(), NULL);
252 JSValueRef htmlBodyData = JSObjectGetProperty(l_globalContext, arg, htmlBodyStr.get(), NULL);
253 JSValueRef priorityData = JSObjectGetProperty(l_globalContext, arg, priorityStr.get(), NULL);
256 if (!JSValueIsUndefined(l_globalContext, subjectData) )
258 LogDebug ( " Subject : " << converter->toString(subjectData) );
259 std::string subject = converter->toString(subjectData);
264 IMmsPtr mms = MessageFactory::convertToMms(msg);
265 mms->setSubject(subject);
270 IEmailPtr email = MessageFactory::convertToEmail(msg);
271 email->setSubject(subject);
276 LogError("message not supported");
277 //Throw(WrtDeviceApis::Commons::UnsupportedException);
283 if (!JSValueIsUndefined(l_globalContext, toData) )
285 Recipients to = converter->toRecipients(toData);
286 LogDebug("setting to field, size=" << to.getRecipientSize());
287 msg->setToRecipients(to);
290 if (msgType == EMAIL )
292 IEmailPtr email = MessageFactory::convertToEmail(msg);
293 if (!JSValueIsUndefined(l_globalContext, ccData))
295 Recipients cc = converter->toRecipients(ccData);
296 email->setCcRecipients(cc);
299 if (!JSValueIsUndefined(l_globalContext, bccData))
301 Recipients bcc = converter->toRecipients(bccData);
302 email->setBccRecipients(bcc);
305 if (!JSValueIsUndefined(l_globalContext, htmlBodyData))
307 std::string body = converter->toString(htmlBodyData);
308 LogDebug("html body : " << body);
309 email->setHtmlBody(body);
312 if (!JSValueIsUndefined(l_globalContext, priorityData))
314 email->setPriority(converter->toMessagePriority(priorityData));
319 if (!JSValueIsUndefined(l_globalContext, plainBodyData) )
321 std::string body = converter->toString(plainBodyData);
322 LogDebug("plain body : " << body);
330 Catch(WrtDeviceApis::Commons::InvalidArgumentException) {
331 return JSTizenExceptionFactory::postException(context, exception,
332 JSTizenException::INVALID_VALUES_ERROR, JSMESSAGING_EXCEPTION_MSG_INVALID_ARGUMENT);
334 Catch(WrtDeviceApis::Commons::ConversionException) {
335 return JSTizenExceptionFactory::postException(context, exception,
336 JSTizenException::TYPE_MISMATCH_ERROR, JSMESSAGING_EXCEPTION_MSG_TYPE_MISMATCH);
340 // return JSValueMakeUndefined(context);
344 LogDebug(" Private Object is NULL ");
345 return JSTizenExceptionFactory::postException(context, exception,
346 JSTizenException::NOT_FOUND_ERROR, JSMESSAGING_EXCEPTION_MSG_NOT_FOUND);
351 JSValueRef JSMessagingService::sendMessage(JSContextRef context,
352 JSObjectRef function,
353 JSObjectRef thisObject,
354 size_t argumentCount,
355 const JSValueRef arguments[],
356 JSValueRef* exception)
361 AceSecurityStatus status = MESSAGING_CHECK_ACCESS(
362 MessagingExportedNames[MESSAGING_FUNCTION_API_SEND_MESSAGE]);
363 TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
365 JSMessagingServicePriv* priv = static_cast<JSMessagingServicePriv*>(JSObjectGetPrivate(thisObject));
368 LogError("Null pointer");
369 return JSTizenExceptionFactory::postException(context, exception,
370 JSTizenException::INVALID_VALUES_ERROR, JSMESSAGING_EXCEPTION_MSG_INVALID_ARGUMENT);
373 JSContextRef globalContext = priv->getContext();
374 LogInfo(">>> argument count : " << argumentCount);
376 if (argumentCount < 1) {
377 return JSTizenExceptionFactory::postException(context, exception,
378 JSTizenException::TYPE_MISMATCH_ERROR, JSMESSAGING_EXCEPTION_MSG_TYPE_MISMATCH);
381 WrtDeviceApis::CommonsJavaScript::JSCallbackManagerPtr callbackManager = JSCallbackManager::createObject(globalContext);
382 WrtDeviceApis::CommonsJavaScript::JSCallbackManagerPtr recipientCallbackManager;
384 callbackManager->setObject(thisObject);
386 ConverterMessageFactory::ConverterType converter = ConverterMessageFactory::getConverter(context);
389 //argu 1. Message ( mandatory )
390 if (!JSValueIsObject(context, arguments[0]) || JSIsArrayValue(context, arguments[0]))
392 LogDebug("arguments is invaild");
393 ThrowMsg(WrtDeviceApis::Commons::InvalidArgumentException,"invalid argument exception");
396 IMessagePtr msg = converter->toIMessage(arguments[0]);
398 //argu 2. Success callback (optional)
399 if ( argumentCount > 1)
401 if ( JSValueIsObject(context, arguments[1]) || Validator(context).isCallback(arguments[1]))
403 MessageSendCallback callbacks = converter->toMessageSendCallback(arguments[1]);
405 if (!(JSValueIsUndefined(context, callbacks.onSuccess) || JSValueIsNull(context, callbacks.onSuccess)) )
407 callbackManager->setOnSuccess( converter->toFunctionOrNull(callbacks.onSuccess) );
411 callbackManager->setOnSuccess(converter->toFunctionOrNull(arguments[1]));
416 ThrowMsg(WrtDeviceApis::Commons::InvalidArgumentException,"invalid argument exception");
419 //argu 3. error callback (optional & nullable)
420 if ( argumentCount > 2)
422 if ( Validator(context).isCallback(arguments[2]))
423 callbackManager->setOnError(arguments[2]);
424 else if(Validator(context).isNullOrUndefined(arguments[2]))
425 callbackManager->setOnError(NULL);
427 Throw(WrtDeviceApis::Commons::InvalidArgumentException);
430 EventMessagingServicePrivateDataPtr privateData( new EventMessagingServicePrivateData(callbackManager, recipientCallbackManager) );
432 //EventSendMessagePtr event(new EventSendMessage());
433 EventMessagingServicePtr event(new EventMessagingService());
435 IMessagingServicePtr imessagingService = priv->getObject();
437 event->opId = imessagingService->createOpId(MESSAGING_SERVICE_OP_SEND_MESSAGE);
438 event->setEventType(MESSAGING_SERVICE_EVENT_TYPE_SEND_MESSAGE);
439 event->m_message = msg;
440 imessagingService->setMessageToOpId( event->opId, event->m_message);
441 event->store = true; //always store message in sendbox after send , email Type.
442 event->m_messagingService = imessagingService;
443 event->setPrivateData(DPL::StaticPointerCast<WrtDeviceApis::Commons::IEventPrivateData>(privateData));
444 event->setForAsynchronousCall(&MessagingController::getInstance());
446 ReqReceiverMessageSingleton::Instance().sendMessage(event); //send message
447 MessageAsyncCallbackManagerSingleton::Instance().registerCallbackManager(callbackManager, globalContext);
448 #if 0 //Pending Operation.
449 DPL::SharedPtr<IExternEventCanceler<EventMessagingService> > eventCanceller =
450 DPL::StaticPointerCast<IExternEventCanceler<EventMessagingService> >(imessagingService);
452 IJSExtCancelPendingOperationPrivateObject<EventMessagingService> *gcPendingOperation =
453 new IJSExtCancelPendingOperationPrivateObject<EventMessagingService>(event, eventCanceller);
455 return JSObjectMake(globalContext, JSPendingOperation::getClassRef(), gcPendingOperation);
457 //return converter->toJSValueRef(event->opId);
459 return JSValueMakeUndefined(context);
461 Catch(WrtDeviceApis::Commons::ConversionException) {
462 return JSTizenExceptionFactory::postException(context, exception,
463 JSTizenException::TYPE_MISMATCH_ERROR, JSMESSAGING_EXCEPTION_MSG_TYPE_MISMATCH);
465 Catch(WrtDeviceApis::Commons::NullPointerException) {
466 return JSTizenExceptionFactory::postException(context, exception,
467 JSTizenException::TYPE_MISMATCH_ERROR, JSMESSAGING_EXCEPTION_MSG_TYPE_MISMATCH);
469 Catch(WrtDeviceApis::Commons::InvalidArgumentException) {
470 return JSTizenExceptionFactory::postException(context, exception,
471 JSTizenException::TYPE_MISMATCH_ERROR, JSMESSAGING_EXCEPTION_MSG_TYPE_MISMATCH);
474 // return JSValueMakeNull(context);
477 JSValueRef JSMessagingService::loadMessageBody(JSContextRef context,
478 JSObjectRef function,
479 JSObjectRef thisObject,
480 size_t argumentCount,
481 const JSValueRef arguments[],
482 JSValueRef* exception)
487 AceSecurityStatus status = MESSAGING_CHECK_ACCESS(
488 MessagingExportedNames[MESSAGING_FUNCTION_API_LOAD_MESSAGE_BODY]);
489 TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
491 JSMessagingServicePriv* priv = static_cast<JSMessagingServicePriv*>(JSObjectGetPrivate(thisObject));
494 LogError("Null pointer");
495 return JSTizenExceptionFactory::postException(context, exception,
496 JSTizenException::INVALID_VALUES_ERROR, JSMESSAGING_EXCEPTION_MSG_INVALID_ARGUMENT);
499 JSContextRef globalContext = priv->getContext(); //create global Context
500 LogInfo(">>> argument count : " << argumentCount);
502 if (argumentCount < 2) {
503 return JSTizenExceptionFactory::postException(context, exception,
504 JSTizenException::TYPE_MISMATCH_ERROR, JSMESSAGING_EXCEPTION_MSG_TYPE_MISMATCH);
507 Validator check(context, exception); //create check
509 WrtDeviceApis::CommonsJavaScript::JSCallbackManagerPtr callbackManager = JSCallbackManager::createObject(globalContext);
510 callbackManager->setObject(thisObject);
512 ConverterMessageFactory::ConverterType converter = ConverterMessageFactory::getConverter(globalContext); //create converter
515 //argu 1. message (mandatory)
516 if (!JSValueIsObject(context, arguments[0]) || JSIsArrayValue(context, arguments[0]))
518 ThrowMsg(WrtDeviceApis::Commons::InvalidArgumentException,"invalid argument exception");
520 //argu 2. success callback
521 if ( Validator(context).isCallback(arguments[1]))
523 callbackManager->setOnSuccess(converter->toFunctionOrNull(arguments[1]));
527 ThrowMsg(WrtDeviceApis::Commons::InvalidArgumentException,"invalid argument exception");
530 //argu 3. error callback (optional & nullable)
531 if ( argumentCount > 2)
533 if ( check.isCallback(arguments[2]))
534 callbackManager->setOnError(arguments[2]);
535 else if(check.isNullOrUndefined(arguments[2]))
536 callbackManager->setOnError(NULL);
538 Throw(WrtDeviceApis::Commons::InvalidArgumentException);
542 callbackManager->setOnError(NULL);
545 Catch(WrtDeviceApis::Commons::ConversionException) {
546 return JSTizenExceptionFactory::postException(context, exception,
547 JSTizenException::TYPE_MISMATCH_ERROR, JSMESSAGING_EXCEPTION_MSG_TYPE_MISMATCH);
549 Catch(WrtDeviceApis::Commons::InvalidArgumentException) {
550 return JSTizenExceptionFactory::postException(context, exception,
551 JSTizenException::TYPE_MISMATCH_ERROR, JSMESSAGING_EXCEPTION_MSG_TYPE_MISMATCH);
553 Catch(WrtDeviceApis::Commons::PlatformException) {
554 return JSTizenExceptionFactory::postException(context, exception,
555 JSTizenException::UNKNOWN_ERROR, JSMESSAGING_EXCEPTION_MSG_UNKNOWN);
559 IMessagePtr msg = converter->toIMessage(arguments[0]);
560 LogInfo(" checked toIMessages " );
562 EventMessagingServicePrivateDataPtr privateData( new EventMessagingServicePrivateData(callbackManager) );
563 EventMessagingServicePtr event(new EventMessagingService());
564 event->m_message = msg;
566 if ( event->m_message )
568 int msgType = event->m_message->getMessageType();
570 if (msgType == EMAIL)
572 IEmailPtr email = MessageFactory::convertToEmail(event->m_message);
573 if (email && email->isBodyDownloaded() > 0)
575 callbackManager->callOnSuccess(converter->toJSValueRef(msg));
576 return JSValueMakeNull(context);
581 callbackManager->callOnSuccess(converter->toJSValueRef(msg));
582 return JSValueMakeNull(context);
585 privateData->setMessageJSValueRef(arguments[0]); //set Message JSValueRef.
587 LogInfo(" Checked Message Type " );
589 IMessagingServicePtr imessagingService = priv->getObject();
590 int opId = imessagingService->createOpId(MESSAGING_SERVICE_OP_DOWNLOAD_BODY);
591 LogDebug("Operation ID is = " << opId);
594 imessagingService->setMessageToOpId(opId, event->m_message);
595 event->setEventType(MESSAGING_SERVICE_EVENT_TYPE_LOAD_MESSAGE_BODY);
596 event->setPrivateData(DPL::StaticPointerCast<WrtDeviceApis::Commons::IEventPrivateData>(privateData));
597 event->setForAsynchronousCall(&MessagingController::getInstance());
599 ReqReceiverMessageSingleton::Instance().loadMessageBody(event); //load message Body
600 MessageAsyncCallbackManagerSingleton::Instance().registerCallbackManager(callbackManager, globalContext);
602 DPL::SharedPtr<IExternEventCanceler<EventMessagingService> > eventCanceller =
603 DPL::StaticPointerCast<IExternEventCanceler<EventMessagingService> >(imessagingService);
605 IJSExtCancelPendingOperationPrivateObject<EventMessagingService> *gcPendingOperation =
606 new IJSExtCancelPendingOperationPrivateObject<EventMessagingService>(event, eventCanceller);
608 return JSObjectMake(globalContext, JSPendingOperation::getClassRef(), gcPendingOperation);
610 //return converter->toJSValueRef(event->opId);
611 return JSValueMakeUndefined(context);
613 Catch(WrtDeviceApis::Commons::NullPointerException) {
614 callbackManager->callOnError(JSTizenExceptionFactory::makeErrorObject(context,
615 JSTizenException::INVALID_VALUES_ERROR, JSMESSAGING_EXCEPTION_MSG_INVALID_ARGUMENT));
616 return JSValueMakeNull(context);
618 Catch(WrtDeviceApis::Commons::ConversionException) {
619 callbackManager->callOnError(JSTizenExceptionFactory::makeErrorObject(context,
620 JSTizenException::INVALID_VALUES_ERROR, JSMESSAGING_EXCEPTION_MSG_INVALID_ARGUMENT));
621 return JSValueMakeNull(context);
623 Catch(WrtDeviceApis::Commons::Exception) {
624 callbackManager->callOnError(JSTizenExceptionFactory::makeErrorObject(context,
625 JSTizenException::UNKNOWN_ERROR, JSMESSAGING_EXCEPTION_MSG_UNKNOWN));
626 return JSValueMakeNull(context);
629 // return JSValueMakeNull(context);
633 JSValueRef JSMessagingService::loadMessageAttachment(JSContextRef context,
634 JSObjectRef function,
635 JSObjectRef thisObject,
636 size_t argumentCount,
637 const JSValueRef arguments[],
638 JSValueRef* exception)
643 AceSecurityStatus status = MESSAGING_CHECK_ACCESS(
644 MessagingExportedNames[MESSAGING_FUNCTION_API_LOAD_MESSAGE_ATTACHMENT]);
645 TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
647 JSMessagingServicePriv* priv = static_cast<JSMessagingServicePriv*>(JSObjectGetPrivate(thisObject));
650 LogError("Private Object is Null pointer");
651 return JSTizenExceptionFactory::postException(context, exception,
652 JSTizenException::INVALID_VALUES_ERROR, JSMESSAGING_EXCEPTION_MSG_INVALID_ARGUMENT);
655 JSContextRef globalContext = priv->getContext(); //create global Context
656 LogInfo(">>> argument count : " << argumentCount);
658 if (argumentCount < 2) {
659 return JSTizenExceptionFactory::postException(context, exception,
660 JSTizenException::TYPE_MISMATCH_ERROR, JSMESSAGING_EXCEPTION_MSG_TYPE_MISMATCH);
663 Validator check(context, exception); //create check
665 WrtDeviceApis::CommonsJavaScript::JSCallbackManagerPtr callbackManager = JSCallbackManager::createObject(globalContext);
666 callbackManager->setObject(thisObject);
667 ConverterMessageFactory::ConverterType converter = ConverterMessageFactory::getConverter(globalContext); //create converter
671 //argu 1. Attachment (mandatory)
672 if (!JSValueIsObject(context, arguments[0]) || JSIsArrayValue(context, arguments[0]))
674 ThrowMsg(WrtDeviceApis::Commons::InvalidArgumentException,"invalid argument exception");
677 //argu 2. success callback
678 if ( check.isCallback(arguments[1]))
679 callbackManager->setOnSuccess(converter->toFunctionOrNull(arguments[1]));
681 ThrowMsg(WrtDeviceApis::Commons::InvalidArgumentException,"invalid argument exception");
683 //argu 3. error callback (optional & nullable)
684 if ( argumentCount > 2)
686 if ( check.isCallback(arguments[2]))
687 callbackManager->setOnError(arguments[2]);
688 else if(check.isNullOrUndefined(arguments[2]))
689 callbackManager->setOnError(NULL);
691 Throw(WrtDeviceApis::Commons::InvalidArgumentException);
694 callbackManager->setOnError(NULL);
698 Catch(WrtDeviceApis::Commons::ConversionException) {
699 return JSTizenExceptionFactory::postException(context, exception,
700 JSTizenException::TYPE_MISMATCH_ERROR, JSMESSAGING_EXCEPTION_MSG_TYPE_MISMATCH);
702 Catch(WrtDeviceApis::Commons::InvalidArgumentException) {
703 return JSTizenExceptionFactory::postException(context, exception,
704 JSTizenException::TYPE_MISMATCH_ERROR, JSMESSAGING_EXCEPTION_MSG_TYPE_MISMATCH);
706 Catch(WrtDeviceApis::Commons::Exception) {
707 return JSTizenExceptionFactory::postException(context, exception,
708 JSTizenException::UNKNOWN_ERROR, JSMESSAGING_EXCEPTION_MSG_UNKNOWN);
712 EventMessagingServicePrivateDataPtr privateData( new EventMessagingServicePrivateData(callbackManager) );
715 return JSTizenExceptionFactory::postException(context, exception,
716 JSTizenException::UNKNOWN_ERROR, JSMESSAGING_EXCEPTION_MSG_UNKNOWN);
719 IAttachmentPtr iAttchmentPtr = converter->toIAttachment(arguments[0]);
720 LogInfo("iAttchmentPtr->getDownloaded() : " << iAttchmentPtr->getDownloaded());
721 if(iAttchmentPtr->getDownloaded() > 0)
723 callbackManager->callOnSuccess(converter->toJSValueRef(iAttchmentPtr));
724 return JSValueMakeNull(context);
727 EventMessagingServicePtr event(new EventMessagingService()); //create event
728 event->setEventType(MESSAGING_SERVICE_EVENT_TYPE_LOAD_MESSAGE_ATTACHMENT);
729 event->setPrivateData(DPL::StaticPointerCast<WrtDeviceApis::Commons::IEventPrivateData>(privateData));
730 event->setForAsynchronousCall(&MessagingController::getInstance());
732 event->m_attachment = iAttchmentPtr;
733 event->m_message = event->m_attachment->getMessage();
735 privateData->setMessageJSValueRef(arguments[0]); //set attachment JSValueRef.
737 IMessagingServicePtr imessagingService = priv->getObject();
738 if (imessagingService)
740 int opId = imessagingService->createOpId(MESSAGING_SERVICE_OP_DOWNLOAD_ATTACHMENT);
741 LogDebug("Operation ID is = " << opId);
744 imessagingService->setMessageToOpId(opId, event->m_message);
746 //JSValueRef pendingOperation = WrtDeviceApis::CommonsJavaScript::makePendingOperation(globalContext, event); //create pendingOperation.
747 ReqReceiverMessageSingleton::Instance().loadMessageAttachment(event); //load message Body
748 MessageAsyncCallbackManagerSingleton::Instance().registerCallbackManager(callbackManager, globalContext);
750 DPL::SharedPtr<IExternEventCanceler<EventMessagingService> > eventCanceller =
751 DPL::StaticPointerCast<IExternEventCanceler<EventMessagingService> >(imessagingService);
753 IJSExtCancelPendingOperationPrivateObject<EventMessagingService> *gcPendingOperation =
754 new IJSExtCancelPendingOperationPrivateObject<EventMessagingService>(event, eventCanceller);
756 return JSObjectMake(globalContext, JSPendingOperation::getClassRef(), gcPendingOperation);
758 //return converter->toJSValueRef(event->opId);
759 return JSValueMakeUndefined(context);
764 return JSTizenExceptionFactory::postException(context, exception,
765 JSTizenException::NOT_FOUND_ERROR, JSMESSAGING_EXCEPTION_MSG_NOT_FOUND);
769 Catch(WrtDeviceApis::Commons::NullPointerException) {
770 callbackManager->callOnError(JSTizenExceptionFactory::makeErrorObject(context,
771 JSTizenException::INVALID_VALUES_ERROR, JSMESSAGING_EXCEPTION_MSG_INVALID_ARGUMENT));
772 return JSValueMakeNull(context);
774 Catch(WrtDeviceApis::Commons::Exception) {
775 callbackManager->callOnError(JSTizenExceptionFactory::makeErrorObject(context,
776 JSTizenException::UNKNOWN_ERROR, JSMESSAGING_EXCEPTION_MSG_UNKNOWN));
777 return JSValueMakeNull(context);
779 // return JSValueMakeUndefined(context);
782 JSValueRef JSMessagingService::sync(JSContextRef context, JSObjectRef function, JSObjectRef thisObject,
783 size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
789 AceSecurityStatus status = MESSAGING_CHECK_ACCESS(
790 MessagingExportedNames[MESSAGING_FUNCTION_API_SYNC]);
791 TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
793 JSMessagingServicePriv* priv = static_cast<JSMessagingServicePriv*>(JSObjectGetPrivate(thisObject));
797 JSContextRef globalContext = priv->getContext(); //get global Context
799 LogInfo(">>> argument count : " << argumentCount);
801 // if (argumentCount < 2 ) {
802 // return JSTizenExceptionFactory::postException(context, exception,
803 // JSTizenException::TYPE_MISMATCH_ERROR, JSMESSAGING_EXCEPTION_MSG_TYPE_MISMATCH);
806 Validator check(context, exception); //check context
808 WrtDeviceApis::CommonsJavaScript::JSCallbackManagerPtr callbackManager = JSCallbackManager::createObject(globalContext);
809 callbackManager->setObject(thisObject);
810 ConverterMessageFactory::ConverterType converter = ConverterMessageFactory::getConverter(globalContext); //create converter
812 IMessagingServicePtr imessagingService = priv->getObject(); //get MessagingService.
814 MessageType msgType = (MessageType)imessagingService->getType();
815 LogInfo("msgType :" << msgType);
821 int limit = -1; //sync limit
822 //argu 1. success callback ( nullable )
823 if (argumentCount > 0)
825 if ( check.isCallback(arguments[0]))
827 callbackManager->setOnSuccess(arguments[0]);
829 else if(check.isNullOrUndefined(arguments[0]))
831 callbackManager->setOnSuccess(NULL);
835 Throw(WrtDeviceApis::Commons::ConversionException);
839 callbackManager->setOnSuccess(NULL);
841 //argu 2. error callback ( nullable )
842 if (argumentCount > 1)
845 if ( check.isCallback(arguments[1]))
846 callbackManager->setOnError(arguments[1]);
847 else if(check.isNullOrUndefined(arguments[1]))
848 callbackManager->setOnError(NULL);
850 Throw(WrtDeviceApis::Commons::ConversionException);
853 callbackManager->setOnError(NULL);
855 //argu 3. limit ( optional )
856 if(argumentCount > 2)
858 if (!Validator(context).isNullOrUndefined(arguments[2]))
860 limit = converter->toInt(arguments[2]);
864 EventMessagingServicePrivateDataPtr privateData( new EventMessagingServicePrivateData(callbackManager) );
865 EventMessagingServicePtr event(new EventMessagingService()); //create event
867 LogDebug("limit : " << limit);
869 event->opId = imessagingService->createOpId(MESSAGING_SERVICE_OP_SYNC);
870 event->m_sync_account_id = imessagingService->getAccountID() ;
871 event->m_sync_limit = limit;
872 event->m_messagingService = imessagingService;
873 imessagingService->setEventToOpId(event->opId, event);
875 event->setEventType(MESSAGING_SERVICE_EVENT_TYPE_SYNC);
876 event->setPrivateData(DPL::StaticPointerCast<WrtDeviceApis::Commons::IEventPrivateData>(privateData));
877 event->setForAsynchronousCall(&MessagingController::getInstance());
879 ReqReceiverMessageSingleton::Instance().sync(event); //load message Body
880 MessageAsyncCallbackManagerSingleton::Instance().registerCallbackManager(callbackManager, globalContext);
882 DPL::SharedPtr<IExternEventCanceler<EventMessagingService> > eventCanceller =
883 DPL::StaticPointerCast<IExternEventCanceler<EventMessagingService> >(imessagingService);
885 IJSExtCancelPendingOperationPrivateObject<EventMessagingService> *gcPendingOperation =
886 new IJSExtCancelPendingOperationPrivateObject<EventMessagingService>(event, eventCanceller);
888 return JSObjectMake(globalContext, JSPendingOperation::getClassRef(), gcPendingOperation);
890 return converter->toJSValueRef(event->opId);
893 Catch(WrtDeviceApis::Commons::ConversionException) {
894 LogError(">>> TypeMismatchException");
895 return JSTizenExceptionFactory::postException(context, exception,
896 JSTizenException::TYPE_MISMATCH_ERROR, JSMESSAGING_EXCEPTION_MSG_TYPE_MISMATCH);
898 Catch(WrtDeviceApis::Commons::NullPointerException) {
899 LogError(">>> TypeMismatchException");
900 return JSTizenExceptionFactory::postException(context, exception,
901 JSTizenException::TYPE_MISMATCH_ERROR, JSMESSAGING_EXCEPTION_MSG_TYPE_MISMATCH);
903 Catch(WrtDeviceApis::Commons::InvalidArgumentException) {
904 callbackManager->callOnError(JSTizenExceptionFactory::makeErrorObject(context,
905 JSTizenException::INVALID_VALUES_ERROR, JSMESSAGING_EXCEPTION_MSG_INVALID_ARGUMENT));
907 Catch(WrtDeviceApis::Commons::PlatformException) {
908 callbackManager->callOnError(JSTizenExceptionFactory::makeErrorObject(context,
909 JSTizenException::UNKNOWN_ERROR, JSMESSAGING_EXCEPTION_MSG_UNKNOWN));
915 LogError("Null pointer");
916 return JSTizenExceptionFactory::postException(context, exception,
917 JSTizenException::INVALID_VALUES_ERROR, JSMESSAGING_EXCEPTION_MSG_INVALID_ARGUMENT);
920 return JSValueMakeNull(context);
925 JSValueRef JSMessagingService::syncFolder(JSContextRef context, JSObjectRef function, JSObjectRef thisObject,
926 size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
931 AceSecurityStatus status = MESSAGING_CHECK_ACCESS(
932 MessagingExportedNames[MESSAGING_FUNCTION_API_SYNC_FOLDER]);
933 TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
935 JSMessagingServicePriv* priv = static_cast<JSMessagingServicePriv*>(JSObjectGetPrivate(thisObject));
938 JSContextRef globalContext = priv->getContext(); //get global Context
940 LogInfo(">>> argument count : " << argumentCount);
942 if (argumentCount < 1) {
943 return JSTizenExceptionFactory::postException(context, exception,
944 JSTizenException::TYPE_MISMATCH_ERROR, JSMESSAGING_EXCEPTION_MSG_TYPE_MISMATCH);
947 Validator check(context, exception); //check context
949 WrtDeviceApis::CommonsJavaScript::JSCallbackManagerPtr callbackManager = JSCallbackManager::createObject(globalContext);
950 callbackManager->setObject(thisObject);
951 ConverterMessageFactory::ConverterType converter = ConverterMessageFactory::getConverter(globalContext); //create converter
953 IMessagingServicePtr imessagingService = priv->getObject(); //get MessagingService.
955 MessageType msgType = (MessageType)imessagingService->getType();
956 LogInfo("msgType :" << msgType);
961 //argu 1. Folder (mandatory)
962 if (!JSValueIsObject(context, arguments[0]) || JSIsArrayValue(context, arguments[0]))
964 Throw(WrtDeviceApis::Commons::ConversionException);
966 IMessageFolderPtr folder = converter->toIMessageFolder(arguments[0]);
968 //argu 2. success callback.
969 if ( argumentCount > 1)
971 if (Validator(context).isCallback(arguments[1]))
972 callbackManager->setOnSuccess(converter->toFunctionOrNull(arguments[1]));
973 else if(check.isNullOrUndefined(arguments[1]))
974 callbackManager->setOnSuccess(NULL);
976 Throw(WrtDeviceApis::Commons::ConversionException);
979 callbackManager->setOnSuccess(NULL);
981 //argu 3. error callback (optional & nullable)
982 if ( argumentCount > 2)
984 if ( check.isCallback(arguments[2]))
985 callbackManager->setOnError(arguments[2]);
986 else if(check.isNullOrUndefined(arguments[2]))
987 callbackManager->setOnError(NULL);
989 Throw(WrtDeviceApis::Commons::ConversionException);
992 callbackManager->setOnError(NULL);
994 //argu 4. limit ( optional )
995 if(argumentCount > 3)
997 if (!Validator(context).isNullOrUndefined(arguments[3]))
999 limit = converter->toInt(arguments[3]);
1003 EventMessagingServicePtr event(new EventMessagingService()); //create event
1004 EventMessagingServicePrivateDataPtr privateData( new EventMessagingServicePrivateData(callbackManager) );
1008 event->m_folder_name = folder->getPath(); //it will be changed to the folder ptr
1009 event->m_sync_folder_id = folder->getId(); //it will be changed to the folder ptr
1012 LogDebug("limit : " << limit);
1013 LogDebug("folderName : " << event->m_folder_name);
1014 event->opId = imessagingService->createOpId(MESSAGING_SERVICE_OP_SYNC_FOLDER);
1015 event ->m_sync_account_id = imessagingService->getAccountID() ;
1016 event ->m_sync_limit = limit;
1017 event->m_messagingService = imessagingService;
1018 imessagingService->setEventToOpId(event->opId, event);
1020 event->setEventType(MESSAGING_SERVICE_EVENT_TYPE_SYNC_FOLDER);
1021 event->setPrivateData(DPL::StaticPointerCast<WrtDeviceApis::Commons::IEventPrivateData>(privateData));
1022 event->setForAsynchronousCall(&MessagingController::getInstance());
1024 ReqReceiverMessageSingleton::Instance().syncFolder(event); //load message Body
1025 MessageAsyncCallbackManagerSingleton::Instance().registerCallbackManager(callbackManager, globalContext);
1028 DPL::SharedPtr<IExternEventCanceler<EventMessagingService> > eventCanceller =
1029 DPL::StaticPointerCast<IExternEventCanceler<EventMessagingService> >(imessagingService);
1031 IJSExtCancelPendingOperationPrivateObject<EventMessagingService> *gcPendingOperation =
1032 new IJSExtCancelPendingOperationPrivateObject<EventMessagingService>(event, eventCanceller);
1034 return JSObjectMake(globalContext, JSPendingOperation::getClassRef(), gcPendingOperation);
1036 return converter->toJSValueRef(event->opId);
1038 Catch(WrtDeviceApis::Commons::UnsupportedException) {
1039 return JSTizenExceptionFactory::postException(context, exception,
1040 JSTizenException::NOT_SUPPORTED_ERROR, JSMESSAGING_EXCEPTION_MSG_NOT_SUPPORTED);
1042 Catch(WrtDeviceApis::Commons::ConversionException) {
1043 return JSTizenExceptionFactory::postException(context, exception,
1044 JSTizenException::TYPE_MISMATCH_ERROR, JSMESSAGING_EXCEPTION_MSG_TYPE_MISMATCH);
1046 Catch(WrtDeviceApis::Commons::NullPointerException) {
1047 callbackManager->callOnError(JSTizenExceptionFactory::makeErrorObject(context,
1048 JSTizenException::INVALID_VALUES_ERROR, JSMESSAGING_EXCEPTION_MSG_INVALID_ARGUMENT));
1049 return JSValueMakeNull(context);
1051 Catch(WrtDeviceApis::Commons::InvalidArgumentException) {
1052 callbackManager->callOnError(JSTizenExceptionFactory::makeErrorObject(context,
1053 JSTizenException::INVALID_VALUES_ERROR, JSMESSAGING_EXCEPTION_MSG_INVALID_ARGUMENT));
1054 return JSValueMakeNull(context);
1056 Catch(WrtDeviceApis::Commons::PlatformException) {
1057 callbackManager->callOnError(JSTizenExceptionFactory::makeErrorObject(context,
1058 JSTizenException::UNKNOWN_ERROR, JSMESSAGING_EXCEPTION_MSG_UNKNOWN));
1064 LogError("Null pointer");
1065 return JSTizenExceptionFactory::postException(context, exception,
1066 JSTizenException::INVALID_VALUES_ERROR, JSMESSAGING_EXCEPTION_MSG_INVALID_ARGUMENT);
1069 return JSValueMakeNull(context);
1074 JSValueRef JSMessagingService::cancelOperation(JSContextRef context, JSObjectRef function, JSObjectRef thisObject,
1075 size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
1077 LogDebug("entered");
1079 JSMessagingServicePriv* priv = static_cast<JSMessagingServicePriv*>(JSObjectGetPrivate(thisObject)); //get private object
1083 IMessagingServicePtr imessagingService = priv->getObject();
1086 LogInfo(">>> argument count : " << argumentCount);
1088 if ( argumentCount == 1 && !Validator(context).isCallback(arguments[0]))
1090 ConverterMessageFactory::ConverterType converter = ConverterMessageFactory::getConverter(context);
1091 MessageType msgType = (MessageType)imessagingService->getType();
1092 LogInfo("msgType :" << msgType);
1094 int opId = converter->toLong( arguments[0] ); //Fetch operation ID
1095 int handle = imessagingService->getHandleFromOpId(opId);
1098 ThrowMsg(WrtDeviceApis::Commons::NotFoundException,"Operation ID Not found");
1101 int opType = imessagingService->getOpTypeFromOpId(opId);
1102 LogInfo("operation ID :" << opId << " operation Type : " << opType);
1104 if ( opType == MESSAGING_SERVICE_OP_SEND_MESSAGE)
1106 IMessagePtr msg = imessagingService->getMessageFromOpId(opId);
1109 LogDebug("Call Cancel Function");
1110 msg->sendCancel(handle);
1111 imessagingService->deleteOpId(opId);
1116 if (msgType == EMAIL)
1118 IMessagePtr msg = imessagingService->getMessageFromOpId(opId);
1119 IEmailPtr email = MessageFactory::convertToEmail(msg);
1121 if ( opType == MESSAGING_SERVICE_OP_DOWNLOAD_BODY )
1123 LogDebug("Cancel Download Body , handle = " << handle);
1124 email->downloadBodyCancel(handle);
1126 else if ( opType == MESSAGING_SERVICE_OP_DOWNLOAD_ATTACHMENT)
1128 LogDebug("Cancel Download Attachment , handle = " << handle);
1129 email->downloadAttachmentCancel(handle);
1131 else if ( opType == MESSAGING_SERVICE_OP_SYNC )
1133 LogDebug("Cancel Sync , handle = " << handle);
1134 imessagingService->syncCancel(handle);
1136 else if ( opType == MESSAGING_SERVICE_OP_SYNC_FOLDER )
1138 LogDebug("Cancel Sync Folder, handle = " << handle);
1139 imessagingService->syncFolderCancel(handle);
1141 imessagingService->deleteOpId(opId);
1145 ThrowMsg(WrtDeviceApis::Commons::UnsupportedException, "Operation Type is mismatched");
1152 ThrowMsg(WrtDeviceApis::Commons::InvalidArgumentException,"invalid argument exception");
1156 Catch (WrtDeviceApis::Commons::InvalidArgumentException){
1157 LogError("Exception: " << _rethrown_exception.GetMessage());
1158 return JSTizenExceptionFactory::postException(context, exception,
1159 JSTizenException::INVALID_VALUES_ERROR, JSMESSAGING_EXCEPTION_MSG_INVALID_ARGUMENT);
1161 Catch (WrtDeviceApis::Commons::NotFoundException){
1162 LogError("Exception: " << _rethrown_exception.GetMessage());
1163 return JSTizenExceptionFactory::postException(context, exception,
1164 JSTizenException::NOT_FOUND_ERROR, JSMESSAGING_EXCEPTION_MSG_NOT_FOUND);
1166 Catch (WrtDeviceApis::Commons::UnsupportedException){
1167 LogError("Exception: " << _rethrown_exception.GetMessage());
1168 return JSTizenExceptionFactory::postException(context, exception,
1169 JSTizenException::NOT_SUPPORTED_ERROR, JSMESSAGING_EXCEPTION_MSG_NOT_SUPPORTED);
1171 Catch (WrtDeviceApis::Commons::Exception){
1172 LogError("Exception: " << _rethrown_exception.GetMessage());
1173 return JSTizenExceptionFactory::postException(context, exception,
1174 JSTizenException::UNKNOWN_ERROR, JSMESSAGING_EXCEPTION_MSG_UNKNOWN);
1180 LogDebug(" Private Object is NULL ");
1181 return JSTizenExceptionFactory::postException(context, exception,
1182 JSTizenException::NOT_FOUND_ERROR, JSMESSAGING_EXCEPTION_MSG_NOT_FOUND);
1186 return JSValueMakeUndefined(context);
1189 JSValueRef JSMessagingService::stopSync(JSContextRef context, JSObjectRef function, JSObjectRef thisObject,
1190 size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
1192 LogDebug("entered");
1194 JSMessagingServicePriv* priv = static_cast<JSMessagingServicePriv*>(JSObjectGetPrivate(thisObject)); //get private object
1198 IMessagingServicePtr imessagingService = priv->getObject();
1201 LogInfo(">>> argument count : " << argumentCount);
1203 if ( argumentCount < 1 )
1205 return JSTizenExceptionFactory::postException(context, exception,
1206 JSTizenException::TYPE_MISMATCH_ERROR, JSMESSAGING_EXCEPTION_MSG_TYPE_MISMATCH);
1209 ConverterMessageFactory::ConverterType converter = ConverterMessageFactory::getConverter(context);
1210 MessageType msgType = (MessageType)imessagingService->getType();
1211 LogInfo("msgType :" << msgType);
1213 int opId = converter->toLong( arguments[0]); //Fetch operation ID
1214 int handle = imessagingService->getHandleFromOpId(opId);
1217 ThrowMsg(WrtDeviceApis::Commons::NotFoundException,"Operation ID Not found");
1220 int opType = imessagingService->getOpTypeFromOpId(opId);
1221 LogInfo("operation ID :" << opId << " operation Type : " << opType);
1223 if (msgType == EMAIL)
1225 if ( opType == MESSAGING_SERVICE_OP_SYNC )
1227 LogDebug("Cancel Sync , handle = " << handle);
1228 imessagingService->syncCancel(handle);
1230 else if ( opType == MESSAGING_SERVICE_OP_SYNC_FOLDER )
1232 LogDebug("Cancel Sync Folder, handle = " << handle);
1233 imessagingService->syncFolderCancel(handle);
1236 //call error callback.
1237 EventMessagingServicePtr event = imessagingService->getEventFromOpId(opId);
1240 LogDebug("get callback Manager");
1241 EventMessagingServicePrivateDataPtr privateData =
1242 DPL::StaticPointerCast<EventMessagingServicePrivateData>(event->getPrivateData());
1244 WrtDeviceApis::CommonsJavaScript::JSCallbackManagerPtr callbackManager = privateData->getCallbackManager(); //get callback manager
1245 JSContextRef globalContext = callbackManager->getContext();
1246 if (callbackManager)
1248 LogDebug("call error callback.");
1249 callbackManager->callOnError(JSDOMExceptionFactory::AbortException.make(globalContext, JSMESSAGING_EXCEPTION_MSG_ABORT_ERROR));
1253 imessagingService->deleteOpId(opId);
1258 ThrowMsg(WrtDeviceApis::Commons::UnsupportedException, "Operation Type is mismatched");
1263 Catch (WrtDeviceApis::Commons::InvalidArgumentException){
1264 LogError("Exception: " << _rethrown_exception.GetMessage());
1265 return JSTizenExceptionFactory::postException(context, exception,
1266 JSTizenException::INVALID_VALUES_ERROR, JSMESSAGING_EXCEPTION_MSG_INVALID_ARGUMENT);
1268 Catch (WrtDeviceApis::Commons::NotFoundException){
1269 LogError("Exception: " << _rethrown_exception.GetMessage());
1270 return JSTizenExceptionFactory::postException(context, exception,
1271 JSTizenException::INVALID_VALUES_ERROR, JSMESSAGING_EXCEPTION_MSG_INVALID_ARGUMENT);
1273 Catch (WrtDeviceApis::Commons::UnsupportedException){
1274 LogError("Exception: " << _rethrown_exception.GetMessage());
1275 return JSTizenExceptionFactory::postException(context, exception,
1276 JSTizenException::NOT_SUPPORTED_ERROR, JSMESSAGING_EXCEPTION_MSG_NOT_SUPPORTED);
1278 Catch (WrtDeviceApis::Commons::Exception){
1279 LogError("Exception: " << _rethrown_exception.GetMessage());
1280 return JSTizenExceptionFactory::postException(context, exception,
1281 JSTizenException::UNKNOWN_ERROR, JSMESSAGING_EXCEPTION_MSG_UNKNOWN);
1287 LogDebug(" Private Object is NULL ");
1288 return JSTizenExceptionFactory::postException(context, exception,
1289 JSTizenException::NOT_FOUND_ERROR, JSMESSAGING_EXCEPTION_MSG_NOT_FOUND);
1293 return JSValueMakeUndefined(context);