2 * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
19 * @file JSPluginTemplete.cpp
20 * @author Jaehyun Park (jaehyun77.park@samsung.com)
22 * @brief Implementation of the JSPluginTemplete class
25 #include "JSMessagingStorage.h"
26 #include "JSMessagingService.h"
27 #include "MessagingListener.h"
28 #include "ConverterMessage.h"
29 #include "MessagingStorageMultiCallback.h"
30 #include <API/Messaging/ReqReceiverMessage.h>
31 #include <API/Filter/SortMode.h>
33 #include <Tizen/Tizen/FilterConverter.h>
35 #include <CommonsJavaScript/Converter.h>
36 #include <CommonsJavaScript/Validator.h>
37 #include <CommonsJavaScript/JSUtils.h>
38 #include <CommonsJavaScript/JSCallbackManager.h>
39 #include <CommonsJavaScript/Utils.h>
40 #include <CommonsJavaScript/JSDOMExceptionFactory.h>
41 #include <CommonsJavaScript/SecurityExceptions.h>
43 #include <Tizen/Common/JSTizenExceptionFactory.h>
44 #include <Tizen/Common/JSTizenException.h>
45 #include <Tizen/Common/SecurityExceptions.h>
47 #include "MessagingErrorMsg.h"
48 #include "plugin_config.h"
53 using namespace WrtDeviceApis::Commons;
54 using namespace WrtDeviceApis::CommonsJavaScript;
55 using namespace TizenApis::Tizen1_0::Tizen;
56 using namespace TizenApis::Commons;
62 JSClassRef JSMessagingStorage::m_jsClassRef = NULL;
64 JSClassDefinition JSMessagingStorage::m_classInfo =
67 kJSClassAttributeNone,
77 NULL, //deleteProperty,Geolocation
78 NULL, //getPropertyNames,
85 JSStaticFunction JSMessagingStorage::m_function[] =
87 { "addDraftMessage", JSMessagingStorage::addDraftMessage, kJSPropertyAttributeNone },
88 { "findMessages", JSMessagingStorage::findMessages, kJSPropertyAttributeNone },
89 { "removeMessages", JSMessagingStorage::removeMessages, kJSPropertyAttributeNone },
90 { "updateMessages", JSMessagingStorage::updateMessages, kJSPropertyAttributeNone },
91 { "findConversations", JSMessagingStorage::findConversations, kJSPropertyAttributeNone },
92 { "removeConversations", JSMessagingStorage::removeConversations, kJSPropertyAttributeNone },
93 { "findFolders", JSMessagingStorage::findFolders, kJSPropertyAttributeNone },
94 { "addMessagesChangeListener", JSMessagingStorage::addMessagesChangeListener, kJSPropertyAttributeNone },
95 { "addConversationsChangeListener", JSMessagingStorage::addConversationsChangeListener, kJSPropertyAttributeNone },
96 { "addFoldersChangeListener", JSMessagingStorage::addFoldersChangeListener, kJSPropertyAttributeNone },
97 { "removeChangeListener", JSMessagingStorage::removeChangeListener, kJSPropertyAttributeNone },
101 const JSClassRef JSMessagingStorage::getClassRef()
105 m_jsClassRef = JSClassCreate(&m_classInfo);
110 void JSMessagingStorage::initialize(JSContextRef context, JSObjectRef object)
112 LogDebug("creation messaging instance");
115 void JSMessagingStorage::finalize(JSObjectRef object)
119 MessagingStoragePriv* priv = static_cast<MessagingStoragePriv*>(JSObjectGetPrivate(object));
122 LogDebug("deleting private object (messaging)");
123 // for messaging object, private object is shared pointer, so will be deleted automatically
125 // object will be deleted, but used to show that private object is deleted
126 JSObjectSetPrivate(object, NULL);
130 bool JSMessagingStorage::hasInstance(JSContextRef context, JSObjectRef constructor, JSValueRef possibleInstance, JSValueRef* exception)
132 return JSValueIsObjectOfClass(context, possibleInstance, getClassRef());
135 JSValueRef JSMessagingStorage::getProperty(JSContextRef context, JSObjectRef object, JSStringRef propertyName, JSValueRef* exception)
138 JSValueRef retVal = NULL;
142 Converter convert(context);
143 if (JSStringIsEqualToUTF8CString(propertyName, "FOLDER_INBOX"))
145 LogDebug("FOLDER_INBOX" << ":" << "1");
146 retVal = convert.toJSValueRef(Api::Messaging::INBOX);
148 else if (JSStringIsEqualToUTF8CString(propertyName, "FOLDER_OUTBOX"))
150 LogDebug("FOLDER_OUTBOX" << ":" << "2");
151 retVal = convert.toJSValueRef(Api::Messaging::OUTBOX);
153 else if (JSStringIsEqualToUTF8CString(propertyName, "FOLDER_DRAFTS"))
155 LogDebug("FOLDER_DRAFTS" << ":" << "3");
156 retVal = convert.toJSValueRef(Api::Messaging::DRAFTBOX);
158 else if (JSStringIsEqualToUTF8CString(propertyName, "FOLDER_SENTBOX"))
160 LogDebug("FOLDER_SENTBOX" << ":" << "4");
161 retVal = convert.toJSValueRef(Api::Messaging::SENTBOX);
165 retVal = JSValueMakeUndefined(context);
168 Catch (WrtDeviceApis::Commons::Exception)
170 LogError("Exception: " << _rethrown_exception.GetMessage());
171 return JSTizenExceptionFactory::postException(context, exception,
172 JSTizenException::UNKNOWN_ERROR, JSMESSAGING_EXCEPTION_MSG_UNKNOWN);
179 JSValueRef JSMessagingStorage::addDraftMessage(JSContextRef context, JSObjectRef object, JSObjectRef thisObject, size_t argumentCount,
180 const JSValueRef arguments[], JSValueRef* exception)
185 MessagingStoragePriv* priv = static_cast<MessagingStoragePriv*>(JSObjectGetPrivate(thisObject));
189 LogDebug("priv is NULL.");
190 return JSTizenExceptionFactory::postException(
191 context, exception, JSTizenException::TYPE_MISMATCH_ERROR, JSMESSAGING_EXCEPTION_MSG_TYPE_MISMATCH);
194 MessagingStoragePrivObjPtr objectPriv = priv->getObject();
198 LogDebug("objectPriv is NULL.");
199 return JSTizenExceptionFactory::postException(
200 context, exception, JSTizenException::TYPE_MISMATCH_ERROR, JSMESSAGING_EXCEPTION_MSG_TYPE_MISMATCH);
204 AceSecurityStatus status = MESSAGING_CHECK_ACCESS(
205 MessagingExportedNames[MESSAGING_FUNCTION_API_ADD_DRAFT_MESSAGE]);
206 TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
208 WrtDeviceApis::CommonsJavaScript::JSCallbackManagerPtr callbackManager(NULL);
209 callbackManager = JSCallbackManager::createObject(priv->getContext());
211 ConverterMessageFactory::ConverterType converter = ConverterMessageFactory::getConverter(context);
215 Api::Messaging::EventAddDraftMessagePtr event(new Api::Messaging::EventAddDraftMessage());
217 FilterConverterFactory::ConverterType filterConverter = FilterConverterFactory::getConverter(context);
219 JSValueRef onSuccessForCbm = NULL, onErrorForCbm = NULL;
221 if((objectPriv->getType() < Api::Messaging::SMS) || (objectPriv->getType() > Api::Messaging::EMAIL))
223 ThrowMsg(InvalidArgumentException, "Message type is not SMS or MMS or EMAIL.");
227 if(objectPriv->getType() == Api::Messaging::EMAIL)
229 if(objectPriv->getIndex() < 1)
231 ThrowMsg(InvalidArgumentException, "serviceId is not defined.");
236 if(argumentCount >= 1) // Message object
238 if(JSValueIsObject(context, arguments[0]))
240 event->msg = converter->toIMessage(arguments[0]);
244 LogDebug("Invalid argument exception");
245 Throw(ConversionException);
248 if(argumentCount >= 2) // successCallback
250 if(Validator(context).isCallback(arguments[1]))
252 onSuccessForCbm = arguments[1];
254 else if(!Validator(context).isNullOrUndefined(arguments[1])) //nullable
256 LogDebug("SuccessCallback type is mismatched.");
257 Throw(ConversionException);
260 if(argumentCount >= 3) //optional ErrorCallback? errorCallback
262 if(Validator(context).isCallback(arguments[2]))
264 onErrorForCbm = arguments[2];
266 else if(!Validator(context).isNullOrUndefined(arguments[2])) //nullable
268 LogDebug("ErrorCallback type is mismatched.");
269 Throw(ConversionException);
274 callbackManager->setOnSuccess(onSuccessForCbm);
275 callbackManager->setOnError(onErrorForCbm);
278 event->setIndex(objectPriv->getIndex());
279 event->setType(objectPriv->getType());
280 event->setPrivateData(DPL::StaticPointerCast<WrtDeviceApis::Commons::IEventPrivateData >(callbackManager));
281 event->setForAsynchronousCall(&MessagingListener::getInstance());
283 Api::Messaging::ReqReceiverMessageSingleton::Instance().addDraftMessage(event);
285 return makePendingOperation(context, event);
287 Catch(WrtDeviceApis::Commons::ConversionException)
289 LogError(">>> TypeMismatchException");
290 return JSTizenExceptionFactory::postException(context, exception,
291 JSTizenException::TYPE_MISMATCH_ERROR, JSMESSAGING_EXCEPTION_MSG_TYPE_MISMATCH);
293 Catch(WrtDeviceApis::Commons::NullPointerException)
295 LogError(">>> TypeMismatchException");
296 return JSTizenExceptionFactory::postException(context, exception,
297 JSTizenException::TYPE_MISMATCH_ERROR, JSMESSAGING_EXCEPTION_MSG_TYPE_MISMATCH);
299 Catch(WrtDeviceApis::Commons::InvalidArgumentException)
301 LogError(">>> InvalidValuesException");
302 return JSTizenExceptionFactory::postException(context, exception,
303 JSTizenException::INVALID_VALUES_ERROR, JSMESSAGING_EXCEPTION_MSG_INVALID_ARGUMENT);
305 Catch(WrtDeviceApis::Commons::PlatformException)
307 LogError(">>> UnknownException");
308 return JSTizenExceptionFactory::postException(context, exception,
309 JSTizenException::UNKNOWN_ERROR, JSMESSAGING_EXCEPTION_MSG_UNKNOWN);
312 LogError(">>> JSValueMakeNull");
313 return JSValueMakeNull(context);
319 JSValueRef JSMessagingStorage::findMessages(JSContextRef context, JSObjectRef object, JSObjectRef thisObject, size_t argumentCount,
320 const JSValueRef arguments[], JSValueRef* exception)
325 MessagingStoragePriv* priv = static_cast<MessagingStoragePriv*>(JSObjectGetPrivate(thisObject));
329 LogDebug("priv is NULL.");
330 return JSTizenExceptionFactory::postException(
331 context, exception, JSTizenException::TYPE_MISMATCH_ERROR, JSMESSAGING_EXCEPTION_MSG_TYPE_MISMATCH);
334 MessagingStoragePrivObjPtr objectPriv = priv->getObject();
338 LogDebug("objectPriv is NULL.");
339 return JSTizenExceptionFactory::postException(
340 context, exception, JSTizenException::TYPE_MISMATCH_ERROR, JSMESSAGING_EXCEPTION_MSG_TYPE_MISMATCH);
344 AceSecurityStatus status = MESSAGING_CHECK_ACCESS(
345 MessagingExportedNames[MESSAGING_FUNCTION_API_FIND_MESSAGES]);
346 TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
348 WrtDeviceApis::CommonsJavaScript::JSCallbackManagerPtr callbackManager(NULL);
349 callbackManager = JSCallbackManager::createObject(priv->getContext());
351 ConverterMessageFactory::ConverterType converter = ConverterMessageFactory::getConverter(context);
355 Api::Messaging::EventQueryMessagesPtr event(new Api::Messaging::EventQueryMessages());
357 FilterConverterFactory::ConverterType filterConverter = FilterConverterFactory::getConverter(context);
359 JSValueRef onSuccessForCbm = NULL, onErrorForCbm = NULL;
361 if((objectPriv->getType() < Api::Messaging::SMS) || (objectPriv->getType() > Api::Messaging::EMAIL))
363 ThrowMsg(InvalidArgumentException, "Message type is not SMS or MMS or EMAIL.");
367 if(objectPriv->getType() == Api::Messaging::EMAIL)
369 if(objectPriv->getIndex() < 1)
371 ThrowMsg(InvalidArgumentException, "serviceId is not defined.");
376 if(argumentCount >= 1) //optional AbstractFilter? filter
378 if(JSValueIsObject(context, arguments[0]))
380 Api::Tizen::FilterPtr filter = filterConverter->toFilter(arguments[0]);
381 event->setFilter(filter);
385 LogDebug("Filter type is mismatched.");
386 Throw(ConversionException);
389 if(argumentCount >= 2) // successCallback
391 if(Validator(context).isCallback(arguments[1]))
393 onSuccessForCbm = arguments[1];
397 LogDebug("SuccessCallback type is mismatched.");
398 Throw(ConversionException);
401 if(argumentCount >= 3) //optional ErrorCallback? errorCallback
403 if(Validator(context).isCallback(arguments[2]))
405 onErrorForCbm = arguments[2];
407 else if(!Validator(context).isNullOrUndefined(arguments[2])) //nullable
409 LogDebug("ErrorCallback type is mismatched.");
410 Throw(ConversionException);
413 if(argumentCount >= 4) //optional SortMode? sortMode
415 if(JSValueIsObject(context, arguments[3]))
417 Api::Tizen::SortModePtr sortMode = filterConverter->toSortMode(arguments[3]);
418 event->setSortMode(sortMode);
420 else if(!Validator(context).isNullOrUndefined(arguments[3])) //nullable
422 LogDebug("SortMode type is mismatched.");
423 Throw(ConversionException);
426 if(argumentCount >= 5) //optional unsigned long? limit JSValueIsUndefined(context, arguments[0]), JSValueIsNull(context, arguments[0])
428 if (!Validator(context).isNullOrUndefined(arguments[4]))
430 if (!JSValueIsNumber(context, arguments[4]))
432 Throw(ConversionException);
434 long limit = filterConverter->toULong(arguments[4]);
435 event->setLimit(limit);
438 if(argumentCount >= 6) //optional unsigned long? offset JSValueIsUndefined(context, arguments[0]), JSValueIsNull(context, arguments[0])
440 if (!Validator(context).isNullOrUndefined(arguments[5]))
442 if (!JSValueIsNumber(context, arguments[5]))
444 Throw(ConversionException);
446 long offset = filterConverter->toULong(arguments[5]);
447 event->setOffset(offset);
453 callbackManager->setOnSuccess(onSuccessForCbm);
454 callbackManager->setOnError(onErrorForCbm);
457 event->setPrivateData(DPL::StaticPointerCast<WrtDeviceApis::Commons::IEventPrivateData >(callbackManager));
458 event->setForAsynchronousCall(&MessagingListener::getInstance());
459 event->setIndex(objectPriv->getIndex());
460 event->setType(objectPriv->getType());
462 Api::Messaging::ReqReceiverMessageSingleton::Instance().queryMessages(event);
465 return makePendingOperation(context, event);
467 Catch(WrtDeviceApis::Commons::ConversionException)
469 LogError(">>> TypeMismatchException");
470 return JSTizenExceptionFactory::postException(context, exception,
471 JSTizenException::TYPE_MISMATCH_ERROR, JSMESSAGING_EXCEPTION_MSG_TYPE_MISMATCH);
473 Catch(WrtDeviceApis::Commons::NullPointerException)
475 LogError(">>> TypeMismatchException");
476 return JSTizenExceptionFactory::postException(context, exception,
477 JSTizenException::TYPE_MISMATCH_ERROR, JSMESSAGING_EXCEPTION_MSG_TYPE_MISMATCH);
479 Catch(WrtDeviceApis::Commons::InvalidArgumentException)
481 LogError(">>> InvalidValuesException");
482 return JSTizenExceptionFactory::postException(context, exception,
483 JSTizenException::INVALID_VALUES_ERROR, JSMESSAGING_EXCEPTION_MSG_INVALID_ARGUMENT);
485 Catch(WrtDeviceApis::Commons::PlatformException)
487 LogError(">>> UnknownException");
488 return JSTizenExceptionFactory::postException(context, exception,
489 JSTizenException::UNKNOWN_ERROR, JSMESSAGING_EXCEPTION_MSG_UNKNOWN);
492 LogError(">>> JSValueMakeNull");
493 return JSValueMakeNull(context);
496 JSValueRef JSMessagingStorage::removeMessages(JSContextRef context, JSObjectRef object, JSObjectRef thisObject, size_t argumentCount,
497 const JSValueRef arguments[], JSValueRef* exception)
502 MessagingStoragePriv* priv = static_cast<MessagingStoragePriv*>(JSObjectGetPrivate(thisObject));
506 LogDebug("priv is NULL.");
507 return JSTizenExceptionFactory::postException(
508 context, exception, JSTizenException::TYPE_MISMATCH_ERROR, JSMESSAGING_EXCEPTION_MSG_TYPE_MISMATCH);
511 MessagingStoragePrivObjPtr objectPriv = priv->getObject();
515 LogDebug("objectPriv is NULL.");
516 return JSTizenExceptionFactory::postException(
517 context, exception, JSTizenException::TYPE_MISMATCH_ERROR, JSMESSAGING_EXCEPTION_MSG_TYPE_MISMATCH);
521 AceSecurityStatus status = MESSAGING_CHECK_ACCESS(
522 MessagingExportedNames[MESSAGING_FUNCTION_API_REMOVE_MESSAGES]);
523 TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
525 WrtDeviceApis::CommonsJavaScript::JSCallbackManagerPtr callbackManager(NULL);
526 callbackManager = JSCallbackManager::createObject(priv->getContext());
528 ConverterMessageFactory::ConverterType converter = ConverterMessageFactory::getConverter(context);
533 Api::Messaging::EventDeleteMessagesPtr event(new Api::Messaging::EventDeleteMessages());
535 FilterConverterFactory::ConverterType filterConverter = FilterConverterFactory::getConverter(context);
537 JSValueRef onSuccessForCbm = NULL, onErrorForCbm = NULL;
539 JSObjectRef objArg = NULL;
541 if((objectPriv->getType() < Api::Messaging::SMS) || (objectPriv->getType() > Api::Messaging::EMAIL))
543 ThrowMsg(InvalidArgumentException, "Message type is not SMS or MMS or EMAIL.");
547 if(objectPriv->getType() == Api::Messaging::EMAIL)
549 if(objectPriv->getIndex() < 1)
551 ThrowMsg(InvalidArgumentException, "serviceId is not defined.");
556 if(argumentCount >= 1) // Message object
558 if(JSValueIsObject(context, arguments[0]))
560 objArg = converter->toJSObjectRef(arguments[0]);
564 LogDebug("Invalid argument exception");
565 Throw(ConversionException);
568 if(argumentCount >= 2) // successCallback
570 if(Validator(context).isCallback(arguments[1]))
572 onSuccessForCbm = arguments[1];
574 else if(!Validator(context).isNullOrUndefined(arguments[1])) //nullable
576 LogDebug("SuccessCallback type is mismatched.");
577 Throw(ConversionException);
580 if(argumentCount >= 3) //optional ErrorCallback? errorCallback
582 if(Validator(context).isCallback(arguments[2]))
584 onErrorForCbm = arguments[2];
586 else if(!Validator(context).isNullOrUndefined(arguments[2])) //nullable
588 LogDebug("ErrorCallback type is mismatched.");
589 Throw(ConversionException);
594 callbackManager->setOnSuccess(onSuccessForCbm);
595 callbackManager->setOnError(onErrorForCbm);
598 std::vector<Api::Messaging::IMessagePtr> msgs;
600 LogDebug("array length "<<JSGetArrayLength(context, objArg));
601 for (std::size_t i = 0; i < JSGetArrayLength(context, objArg); i++)
603 JSValueRef element = JSGetArrayElement(context, objArg, i);
604 JSObjectRef arg = JSValueToObject(context, element, NULL);
605 Api::Messaging::IMessagePtr msg = converter->toIMessage(arg);
609 event->msgArray = msgs;
611 event->setPrivateData(DPL::StaticPointerCast<WrtDeviceApis::Commons::IEventPrivateData >(callbackManager));
612 event->setForAsynchronousCall(&MessagingListener::getInstance());
613 event->setIndex(objectPriv->getIndex());
614 event->setType(objectPriv->getType());
616 Api::Messaging::ReqReceiverMessageSingleton::Instance().deleteMessages(event);
618 return makePendingOperation(context, event);
620 Catch(WrtDeviceApis::Commons::ConversionException)
622 LogError(">>> TypeMismatchException");
623 return JSTizenExceptionFactory::postException(context, exception,
624 JSTizenException::TYPE_MISMATCH_ERROR, JSMESSAGING_EXCEPTION_MSG_TYPE_MISMATCH);
626 Catch(WrtDeviceApis::Commons::NullPointerException)
628 LogError(">>> TypeMismatchException");
629 return JSTizenExceptionFactory::postException(context, exception,
630 JSTizenException::TYPE_MISMATCH_ERROR, JSMESSAGING_EXCEPTION_MSG_TYPE_MISMATCH);
632 Catch(WrtDeviceApis::Commons::InvalidArgumentException)
634 LogError(">>> InvalidValuesException");
635 return JSTizenExceptionFactory::postException(context, exception,
636 JSTizenException::INVALID_VALUES_ERROR, JSMESSAGING_EXCEPTION_MSG_INVALID_ARGUMENT);
638 Catch(WrtDeviceApis::Commons::PlatformException)
640 LogError(">>> UnknownException");
641 return JSTizenExceptionFactory::postException(context, exception,
642 JSTizenException::UNKNOWN_ERROR, JSMESSAGING_EXCEPTION_MSG_UNKNOWN);
645 return JSValueMakeNull(context);
648 JSValueRef JSMessagingStorage::updateMessages(JSContextRef context, JSObjectRef object, JSObjectRef thisObject, size_t argumentCount,
649 const JSValueRef arguments[], JSValueRef* exception)
654 MessagingStoragePriv* priv = static_cast<MessagingStoragePriv*>(JSObjectGetPrivate(thisObject));
658 LogDebug("priv is NULL.");
659 return JSTizenExceptionFactory::postException(
660 context, exception, JSTizenException::TYPE_MISMATCH_ERROR, JSMESSAGING_EXCEPTION_MSG_TYPE_MISMATCH);
663 MessagingStoragePrivObjPtr objectPriv = priv->getObject();
667 LogDebug("objectPriv is NULL.");
668 return JSTizenExceptionFactory::postException(
669 context, exception, JSTizenException::TYPE_MISMATCH_ERROR, JSMESSAGING_EXCEPTION_MSG_TYPE_MISMATCH);
673 AceSecurityStatus status = MESSAGING_CHECK_ACCESS(
674 MessagingExportedNames[MESSAGING_FUNCTION_API_UPDATE_MESSAGES]);
675 TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
677 WrtDeviceApis::CommonsJavaScript::JSCallbackManagerPtr callbackManager(NULL);
678 callbackManager = JSCallbackManager::createObject(priv->getContext());
680 ConverterMessageFactory::ConverterType converter = ConverterMessageFactory::getConverter(context);
685 Api::Messaging::EventUpdateMessagesPtr event(new Api::Messaging::EventUpdateMessages());
687 FilterConverterFactory::ConverterType filterConverter = FilterConverterFactory::getConverter(context);
689 JSValueRef onSuccessForCbm = NULL, onErrorForCbm = NULL;
691 JSObjectRef objArg = NULL;
693 if((objectPriv->getType() < Api::Messaging::SMS) || (objectPriv->getType() > Api::Messaging::EMAIL))
695 ThrowMsg(InvalidArgumentException, "Message type is not SMS or MMS or EMAIL.");
699 if(objectPriv->getType() == Api::Messaging::EMAIL)
701 if(objectPriv->getIndex() < 1)
703 ThrowMsg(InvalidArgumentException, "serviceId is not defined.");
708 if(argumentCount >= 1) // Message object
710 if(JSValueIsObject(context, arguments[0]))
712 objArg = converter->toJSObjectRef(arguments[0]);
716 LogDebug("Invalid argument exception");
717 Throw(ConversionException);
720 if(argumentCount >= 2) // successCallback
722 if(Validator(context).isCallback(arguments[1]))
724 onSuccessForCbm = arguments[1];
726 else if(!Validator(context).isNullOrUndefined(arguments[1])) //nullable
728 LogDebug("SuccessCallback type is mismatched.");
729 Throw(ConversionException);
732 if(argumentCount >= 3) //optional ErrorCallback? errorCallback
734 if(Validator(context).isCallback(arguments[2]))
736 onErrorForCbm = arguments[2];
738 else if(!Validator(context).isNullOrUndefined(arguments[2])) //nullable
740 LogDebug("ErrorCallback type is mismatched.");
741 Throw(ConversionException);
746 callbackManager->setOnSuccess(onSuccessForCbm);
747 callbackManager->setOnError(onErrorForCbm);
750 std::vector<Api::Messaging::IMessagePtr> msgs;
751 LogDebug("array length "<<JSGetArrayLength(context, objArg));
752 for (std::size_t i = 0; i < JSGetArrayLength(context, objArg); i++)
754 JSValueRef element = JSGetArrayElement(context, objArg, i);
755 JSObjectRef arg = JSValueToObject(context, element, NULL);
756 Api::Messaging::IMessagePtr msg = converter->toIMessage(arg);
760 event->msgArray = msgs;
761 event->setPrivateData(DPL::StaticPointerCast<WrtDeviceApis::Commons::IEventPrivateData >(callbackManager));
762 event->setForAsynchronousCall(&MessagingListener::getInstance());
764 event->setIndex(objectPriv->getIndex());
765 event->setType(objectPriv->getType());
767 Api::Messaging::ReqReceiverMessageSingleton::Instance().updateMessages(event);
769 return makePendingOperation(context, event);
771 Catch(WrtDeviceApis::Commons::ConversionException)
773 LogError(">>> TypeMismatchException");
774 return JSTizenExceptionFactory::postException(context, exception,
775 JSTizenException::TYPE_MISMATCH_ERROR, JSMESSAGING_EXCEPTION_MSG_TYPE_MISMATCH);
777 Catch(WrtDeviceApis::Commons::NullPointerException)
779 LogError(">>> TypeMismatchException");
780 return JSTizenExceptionFactory::postException(context, exception,
781 JSTizenException::TYPE_MISMATCH_ERROR, JSMESSAGING_EXCEPTION_MSG_TYPE_MISMATCH);
783 Catch(WrtDeviceApis::Commons::InvalidArgumentException)
785 LogError(">>> InvalidValuesException");
786 return JSTizenExceptionFactory::postException(context, exception,
787 JSTizenException::INVALID_VALUES_ERROR, JSMESSAGING_EXCEPTION_MSG_INVALID_ARGUMENT);
789 Catch(WrtDeviceApis::Commons::PlatformException)
791 LogError(">>> UnknownException");
792 return JSTizenExceptionFactory::postException(context, exception,
793 JSTizenException::UNKNOWN_ERROR, JSMESSAGING_EXCEPTION_MSG_UNKNOWN);
795 return JSValueMakeNull(context);
798 JSValueRef JSMessagingStorage::findConversations(JSContextRef context, JSObjectRef object, JSObjectRef thisObject, size_t argumentCount,
799 const JSValueRef arguments[], JSValueRef* exception)
804 MessagingStoragePriv* priv = static_cast<MessagingStoragePriv*>(JSObjectGetPrivate(thisObject));
808 LogDebug("priv is NULL.");
809 return JSTizenExceptionFactory::postException(
810 context, exception, JSTizenException::TYPE_MISMATCH_ERROR, JSMESSAGING_EXCEPTION_MSG_TYPE_MISMATCH);
813 MessagingStoragePrivObjPtr objectPriv = priv->getObject();
817 LogDebug("objectPriv is NULL.");
818 return JSTizenExceptionFactory::postException(
819 context, exception, JSTizenException::TYPE_MISMATCH_ERROR, JSMESSAGING_EXCEPTION_MSG_TYPE_MISMATCH);
823 AceSecurityStatus status = MESSAGING_CHECK_ACCESS(
824 MessagingExportedNames[MESSAGING_FUNCTION_API_FIND_CONVERSATIONS]);
825 TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
827 WrtDeviceApis::CommonsJavaScript::JSCallbackManagerPtr callbackManager(NULL);
828 callbackManager = JSCallbackManager::createObject(priv->getContext());
830 ConverterMessageFactory::ConverterType converter = ConverterMessageFactory::getConverter(context);
834 Api::Messaging::EventQueryConversationsPtr event(new Api::Messaging::EventQueryConversations());
836 FilterConverterFactory::ConverterType filterConverter = FilterConverterFactory::getConverter(context);
838 JSValueRef onSuccessForCbm = NULL, onErrorForCbm = NULL;
840 if((objectPriv->getType() < Api::Messaging::SMS) || (objectPriv->getType() > Api::Messaging::EMAIL))
842 ThrowMsg(InvalidArgumentException, "Message type is not SMS or MMS or EMAIL.");
846 if(objectPriv->getType() == Api::Messaging::EMAIL)
848 if(objectPriv->getIndex() < 1)
850 ThrowMsg(InvalidArgumentException, "serviceId is not defined.");
855 if(argumentCount >= 1) //optional AbstractFilter? filter
857 if(JSValueIsObject(context, arguments[0]))
859 Api::Tizen::FilterPtr filter = filterConverter->toFilter(arguments[0]);
860 event->setFilter(filter);
864 LogDebug("Filter type is mismatched.");
865 Throw(ConversionException);
868 if(argumentCount >= 2) // successCallback
870 if(Validator(context).isCallback(arguments[1]))
872 onSuccessForCbm = arguments[1];
876 LogDebug("SuccessCallback type is mismatched.");
877 Throw(ConversionException);
880 if(argumentCount >= 3) //optional ErrorCallback? errorCallback
882 if(Validator(context).isCallback(arguments[2]))
884 onErrorForCbm = arguments[2];
886 else if(!Validator(context).isNullOrUndefined(arguments[2])) //nullable
888 LogDebug("ErrorCallback type is mismatched.");
889 Throw(ConversionException);
892 if(argumentCount >= 4) //optional SortMode? sortMode
894 if(JSValueIsObject(context, arguments[3]))
896 Api::Tizen::SortModePtr sortMode = filterConverter->toSortMode(arguments[3]);
897 event->setSortMode(sortMode);
899 else if(!Validator(context).isNullOrUndefined(arguments[3])) //nullable
901 LogDebug("SortMode type is mismatched.");
902 Throw(ConversionException);
905 if(argumentCount >= 5) //optional unsigned long? limit JSValueIsUndefined(context, arguments[0]), JSValueIsNull(context, arguments[0])
907 if (!Validator(context).isNullOrUndefined(arguments[4]))
909 if (!JSValueIsNumber(context, arguments[4]))
911 Throw(ConversionException);
913 long limit = filterConverter->toULong(arguments[4]);
914 event->setLimit(limit);
917 if(argumentCount >= 6) //optional unsigned long? offset JSValueIsUndefined(context, arguments[0]), JSValueIsNull(context, arguments[0])
919 if (!Validator(context).isNullOrUndefined(arguments[5]))
921 if (!JSValueIsNumber(context, arguments[5]))
923 Throw(ConversionException);
925 long offset = filterConverter->toULong(arguments[5]);
926 event->setOffset(offset);
931 callbackManager->setOnSuccess(onSuccessForCbm);
932 callbackManager->setOnError(onErrorForCbm);
935 event->setPrivateData(DPL::StaticPointerCast<WrtDeviceApis::Commons::IEventPrivateData >(callbackManager));
936 event->setForAsynchronousCall(&MessagingListener::getInstance());
937 event->setIndex(objectPriv->getIndex());
938 event->setType(objectPriv->getType());
940 Api::Messaging::ReqReceiverMessageSingleton::Instance().queryConversations(event);
942 return makePendingOperation(context, event);
944 Catch(WrtDeviceApis::Commons::ConversionException)
946 LogError(">>> TypeMismatchException");
947 return JSTizenExceptionFactory::postException(context, exception,
948 JSTizenException::TYPE_MISMATCH_ERROR, JSMESSAGING_EXCEPTION_MSG_TYPE_MISMATCH);
950 Catch(WrtDeviceApis::Commons::NullPointerException)
952 LogError(">>> TypeMismatchException");
953 return JSTizenExceptionFactory::postException(context, exception,
954 JSTizenException::TYPE_MISMATCH_ERROR, JSMESSAGING_EXCEPTION_MSG_TYPE_MISMATCH);
956 Catch(WrtDeviceApis::Commons::InvalidArgumentException)
958 LogError(">>> InvalidValuesException");
959 return JSTizenExceptionFactory::postException(context, exception,
960 JSTizenException::INVALID_VALUES_ERROR, JSMESSAGING_EXCEPTION_MSG_INVALID_ARGUMENT);
962 Catch(WrtDeviceApis::Commons::PlatformException)
964 LogError(">>> UnknownException");
965 return JSTizenExceptionFactory::postException(context, exception,
966 JSTizenException::UNKNOWN_ERROR, JSMESSAGING_EXCEPTION_MSG_UNKNOWN);
969 LogError(">>> JSValueMakeNull");
970 return JSValueMakeNull(context);
973 JSValueRef JSMessagingStorage::removeConversations(JSContextRef context, JSObjectRef object, JSObjectRef thisObject, size_t argumentCount,
974 const JSValueRef arguments[], JSValueRef* exception)
978 MessagingStoragePriv* priv = static_cast<MessagingStoragePriv*>(JSObjectGetPrivate(thisObject));
982 LogDebug("priv is NULL.");
983 return JSTizenExceptionFactory::postException(
984 context, exception, JSTizenException::TYPE_MISMATCH_ERROR, JSMESSAGING_EXCEPTION_MSG_TYPE_MISMATCH);
987 MessagingStoragePrivObjPtr objectPriv = priv->getObject();
991 LogDebug("objectPriv is NULL.");
992 return JSTizenExceptionFactory::postException(
993 context, exception, JSTizenException::TYPE_MISMATCH_ERROR, JSMESSAGING_EXCEPTION_MSG_TYPE_MISMATCH);
997 AceSecurityStatus status = MESSAGING_CHECK_ACCESS(
998 MessagingExportedNames[MESSAGING_FUNCTION_API_REMOVE_CONVERSATIONS]);
999 TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
1001 WrtDeviceApis::CommonsJavaScript::JSCallbackManagerPtr callbackManager(NULL);
1002 callbackManager = JSCallbackManager::createObject(priv->getContext());
1004 ConverterMessageFactory::ConverterType converter = ConverterMessageFactory::getConverter(context);
1009 Api::Messaging::EventDeleteConversationsPtr event(new Api::Messaging::EventDeleteConversations());
1011 FilterConverterFactory::ConverterType filterConverter = FilterConverterFactory::getConverter(context);
1013 JSValueRef onSuccessForCbm = NULL, onErrorForCbm = NULL;
1015 std::vector<Api::Messaging::IConversationPtr> deleteConversationArray;
1017 if((objectPriv->getType() < Api::Messaging::SMS) || (objectPriv->getType() > Api::Messaging::EMAIL))
1019 ThrowMsg(InvalidArgumentException, "Message type is not SMS or MMS or EMAIL.");
1023 if(objectPriv->getType() == Api::Messaging::EMAIL)
1025 if(objectPriv->getIndex() < 1)
1027 ThrowMsg(InvalidArgumentException, "serviceId is not defined.");
1032 if(argumentCount >= 1) // Message object
1034 if(JSValueIsObject(context, arguments[0]))
1036 deleteConversationArray = converter->toVectorOfConversation(arguments[0]);
1040 LogDebug("Invalid argument exception");
1041 Throw(ConversionException);
1044 if(argumentCount >= 2) // successCallback
1046 if(Validator(context).isCallback(arguments[1]))
1048 onSuccessForCbm = arguments[1];
1050 else if(!Validator(context).isNullOrUndefined(arguments[1])) //nullable
1052 LogDebug("SuccessCallback type is mismatched.");
1053 Throw(ConversionException);
1056 if(argumentCount >= 3) //optional ErrorCallback? errorCallback
1058 if(Validator(context).isCallback(arguments[2]))
1060 onErrorForCbm = arguments[2];
1062 else if(!Validator(context).isNullOrUndefined(arguments[2])) //nullable
1064 LogDebug("ErrorCallback type is mismatched.");
1065 Throw(ConversionException);
1070 callbackManager->setOnSuccess(onSuccessForCbm);
1071 callbackManager->setOnError(onErrorForCbm);
1074 event->setConversations(deleteConversationArray);
1075 event->setFilterUsing(false);
1077 event->setPrivateData(DPL::StaticPointerCast<WrtDeviceApis::Commons::IEventPrivateData >(callbackManager));
1078 event->setForAsynchronousCall(&MessagingListener::getInstance());
1079 event->setIndex(objectPriv->getIndex());
1080 event->setType(objectPriv->getType());
1082 Api::Messaging::ReqReceiverMessageSingleton::Instance().deleteConversations(event);
1084 return makePendingOperation(context, event);
1086 Catch(WrtDeviceApis::Commons::ConversionException)
1088 LogError(">>> TypeMismatchException");
1089 return JSTizenExceptionFactory::postException(context, exception,
1090 JSTizenException::TYPE_MISMATCH_ERROR, JSMESSAGING_EXCEPTION_MSG_TYPE_MISMATCH);
1092 Catch(WrtDeviceApis::Commons::NullPointerException)
1094 LogError(">>> TypeMismatchException");
1095 return JSTizenExceptionFactory::postException(context, exception,
1096 JSTizenException::TYPE_MISMATCH_ERROR, JSMESSAGING_EXCEPTION_MSG_TYPE_MISMATCH);
1098 Catch(WrtDeviceApis::Commons::InvalidArgumentException)
1100 LogError(">>> InvalidValuesException");
1101 return JSTizenExceptionFactory::postException(context, exception,
1102 JSTizenException::INVALID_VALUES_ERROR, JSMESSAGING_EXCEPTION_MSG_INVALID_ARGUMENT);
1104 Catch(WrtDeviceApis::Commons::PlatformException)
1106 LogError(">>> UnknownException");
1107 return JSTizenExceptionFactory::postException(context, exception,
1108 JSTizenException::UNKNOWN_ERROR, JSMESSAGING_EXCEPTION_MSG_UNKNOWN);
1110 return JSValueMakeNull(context);
1113 JSValueRef JSMessagingStorage::findFolders(JSContextRef context, JSObjectRef object, JSObjectRef thisObject, size_t argumentCount,
1114 const JSValueRef arguments[], JSValueRef* exception)
1118 MessagingStoragePriv* priv = static_cast<MessagingStoragePriv*>(JSObjectGetPrivate(thisObject));
1122 LogDebug("priv is NULL.");
1123 return JSTizenExceptionFactory::postException(
1124 context, exception, JSTizenException::TYPE_MISMATCH_ERROR, JSMESSAGING_EXCEPTION_MSG_TYPE_MISMATCH);
1127 MessagingStoragePrivObjPtr objectPriv = priv->getObject();
1131 LogDebug("objectPriv is NULL.");
1132 return JSTizenExceptionFactory::postException(
1133 context, exception, JSTizenException::TYPE_MISMATCH_ERROR, JSMESSAGING_EXCEPTION_MSG_TYPE_MISMATCH);
1137 AceSecurityStatus status = MESSAGING_CHECK_ACCESS(
1138 MessagingExportedNames[MESSAGING_FUNCTION_API_FIND_FOLDERS]);
1139 TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
1141 WrtDeviceApis::CommonsJavaScript::JSCallbackManagerPtr callbackManager(NULL);
1142 callbackManager = JSCallbackManager::createObject(priv->getContext());
1144 ConverterMessageFactory::ConverterType converter = ConverterMessageFactory::getConverter(context);
1148 Api::Messaging::EventQueryFoldersPtr event(new Api::Messaging::EventQueryFolders());
1150 FilterConverterFactory::ConverterType filterConverter = FilterConverterFactory::getConverter(context);
1152 JSValueRef onSuccessForCbm = NULL, onErrorForCbm = NULL;
1154 if((objectPriv->getType() < Api::Messaging::SMS) || (objectPriv->getType() > Api::Messaging::EMAIL))
1156 ThrowMsg(InvalidArgumentException, "Message type is not SMS or MMS or EMAIL.");
1160 if(objectPriv->getType() == Api::Messaging::EMAIL)
1162 if(objectPriv->getIndex() < 1)
1164 ThrowMsg(InvalidArgumentException, "serviceId is not defined.");
1169 if(argumentCount >= 1) //optional AbstractFilter? filter
1171 if(JSValueIsObject(context, arguments[0]))
1173 Api::Tizen::FilterPtr filter = filterConverter->toFilter(arguments[0]);
1174 event->setFilter(filter);
1176 else // NOT nullable
1178 LogDebug("Filter type is mismatched.");
1179 Throw(ConversionException);
1182 if(argumentCount >= 2) // successCallback
1184 if(Validator(context).isCallback(arguments[1]))
1186 onSuccessForCbm = arguments[1];
1188 else // NOT nullable
1190 LogDebug("SuccessCallback type is mismatched.");
1191 Throw(ConversionException);
1194 if(argumentCount >= 3) //optional ErrorCallback? errorCallback
1196 if(Validator(context).isCallback(arguments[2]))
1198 onErrorForCbm = arguments[2];
1200 else if(!Validator(context).isNullOrUndefined(arguments[2])) //nullable
1202 LogDebug("ErrorCallback type is mismatched.");
1203 Throw(ConversionException);
1208 callbackManager->setOnSuccess(onSuccessForCbm);
1209 callbackManager->setOnError(onErrorForCbm);
1212 event->setPrivateData(DPL::StaticPointerCast<WrtDeviceApis::Commons::IEventPrivateData >(callbackManager));
1213 event->setForAsynchronousCall(&MessagingListener::getInstance());
1214 event->setIndex(objectPriv->getIndex());
1215 event->setType(objectPriv->getType());
1217 Api::Messaging::ReqReceiverMessageSingleton::Instance().queryFolders(event);
1219 return makePendingOperation(context, event);
1222 Catch(WrtDeviceApis::Commons::ConversionException)
1224 LogError(">>> TypeMismatchException");
1225 return JSTizenExceptionFactory::postException(context, exception,
1226 JSTizenException::TYPE_MISMATCH_ERROR, JSMESSAGING_EXCEPTION_MSG_TYPE_MISMATCH);
1228 Catch(WrtDeviceApis::Commons::NullPointerException)
1230 LogError(">>> TypeMismatchException");
1231 return JSTizenExceptionFactory::postException(context, exception,
1232 JSTizenException::TYPE_MISMATCH_ERROR, JSMESSAGING_EXCEPTION_MSG_TYPE_MISMATCH);
1234 Catch(WrtDeviceApis::Commons::InvalidArgumentException)
1236 LogError(">>> InvalidValuesException");
1237 return JSTizenExceptionFactory::postException(context, exception,
1238 JSTizenException::INVALID_VALUES_ERROR, JSMESSAGING_EXCEPTION_MSG_INVALID_ARGUMENT);
1240 Catch(WrtDeviceApis::Commons::PlatformException)
1242 LogError(">>> UnknownException");
1243 return JSTizenExceptionFactory::postException(context, exception,
1244 JSTizenException::UNKNOWN_ERROR, JSMESSAGING_EXCEPTION_MSG_UNKNOWN);
1247 return JSValueMakeNull(context);
1250 JSValueRef JSMessagingStorage::addMessagesChangeListener(JSContextRef context, JSObjectRef object, JSObjectRef thisObject, size_t argumentCount,
1251 const JSValueRef arguments[], JSValueRef* exception)
1256 MessagingStoragePriv* priv = static_cast<MessagingStoragePriv*>(JSObjectGetPrivate(thisObject));
1260 LogDebug("priv is NULL.");
1261 return JSTizenExceptionFactory::postException(
1262 context, exception, JSTizenException::TYPE_MISMATCH_ERROR, JSMESSAGING_EXCEPTION_MSG_TYPE_MISMATCH);
1265 MessagingStoragePrivObjPtr objectPriv = priv->getObject();
1269 LogDebug("objectPriv is NULL.");
1270 return JSTizenExceptionFactory::postException(
1271 context, exception, JSTizenException::TYPE_MISMATCH_ERROR, JSMESSAGING_EXCEPTION_MSG_TYPE_MISMATCH);
1275 AceSecurityStatus status = MESSAGING_CHECK_ACCESS(
1276 MessagingExportedNames[MESSAGING_FUNCTION_API_ADD_MESSAGES_CHANGE_LISTNER]);
1277 TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
1279 WrtDeviceApis::CommonsJavaScript::JSCallbackManagerPtr callbackManager(NULL);
1281 WrtDeviceApis::CommonsJavaScript::JSCallbackManagerPtr messagesUpdatedCbm(NULL);
1282 WrtDeviceApis::CommonsJavaScript::JSCallbackManagerPtr messagesRemovedCbm(NULL);
1284 callbackManager = JSCallbackManager::createObject(priv->getContext());
1286 ConverterMessageFactory::ConverterType converter = ConverterMessageFactory::getConverter(context);
1290 FilterConverterFactory::ConverterType filterConverter = FilterConverterFactory::getConverter(context);
1292 JSValueRef onSuccessForCbm = NULL;
1294 OnMessagesChanged functionResult;
1295 int funtionIndex = -1;
1297 if((objectPriv->getType() < Api::Messaging::SMS) || (objectPriv->getType() > Api::Messaging::EMAIL))
1299 ThrowMsg(InvalidArgumentException, "Message type is not SMS or MMS or EMAIL.");
1303 if(objectPriv->getType() == Api::Messaging::EMAIL)
1305 if(objectPriv->getIndex() < 1)
1307 ThrowMsg(InvalidArgumentException, "serviceId is not defined.");
1312 if(argumentCount >= 1) // successCallback
1314 if(!Validator(context).isNullOrUndefined(arguments[0]))
1316 functionResult = converter->toMessageMultifunctions(arguments[0]);
1317 funtionIndex = functionResult.functionIndex;
1319 onSuccessForCbm = functionResult.messagesAdded;
1320 messagesUpdatedCbm = JSCallbackManager::createObject(priv->getContext(), functionResult.messagesUpdated, NULL);
1321 messagesRemovedCbm = JSCallbackManager::createObject(priv->getContext(), functionResult.messagesRemoved, NULL);
1323 else // NOT nullable
1325 LogDebug("SuccessCallback type is mismatched.");
1326 Throw(ConversionException);
1330 if(funtionIndex < 0)
1332 LogError("funtionIndex is not valid");
1333 Throw(ConversionException);
1336 EventOnMessagingStorageChangesPrivateDataPtr privData(
1337 new EventOnMessagingStorageChangesPrivateData(callbackManager, messagesUpdatedCbm, messagesRemovedCbm, funtionIndex));
1339 if(argumentCount >= 2) //optional AbstractFilter? filter
1341 if(JSValueIsObject(context, arguments[1]))
1343 Api::Tizen::FilterPtr filter = filterConverter->toFilter(arguments[1]);
1344 privData->setFilter(filter);
1346 else // NOT nullable
1348 LogDebug("Filter type is mismatched.");
1349 Throw(ConversionException);
1354 callbackManager->setOnSuccess(onSuccessForCbm);
1357 privData->setIndex(objectPriv->getIndex());
1358 privData->setType(objectPriv->getType());
1360 MessagingListener::getInstance().registerMessageReceivedEmitter(privData);
1362 // add to map and return index
1363 return JSValueMakeNumber(context,
1364 MessagingListener::getInstance().addIncomingMsgCallback(callbackManager, funtionIndex));
1367 Catch(WrtDeviceApis::Commons::ConversionException)
1369 LogError("Error on conversion");
1370 return JSTizenExceptionFactory::postException(context, exception,
1371 JSTizenException::TYPE_MISMATCH_ERROR, JSMESSAGING_EXCEPTION_MSG_TYPE_MISMATCH);
1373 Catch(WrtDeviceApis::Commons::InvalidArgumentException) {
1374 LogError("Invalid argument exception");
1375 return JSTizenExceptionFactory::postException(context, exception,
1376 JSTizenException::INVALID_VALUES_ERROR, JSMESSAGING_EXCEPTION_MSG_INVALID_ARGUMENT);
1378 Catch(WrtDeviceApis::Commons::UnsupportedException)
1380 LogError("Unsupported exception");
1381 return JSTizenExceptionFactory::postException(context, exception,
1382 JSTizenException::NOT_SUPPORTED_ERROR, JSMESSAGING_EXCEPTION_MSG_NOT_SUPPORTED); // unsupported type
1384 Catch(WrtDeviceApis::Commons::AlreadyInUseException)
1386 LogError("Already in use exception");
1388 Catch(WrtDeviceApis::Commons::PlatformException)
1390 LogError("not registered for incoming message notifications");
1393 return JSValueMakeUndefined(context);
1396 JSValueRef JSMessagingStorage::addConversationsChangeListener(JSContextRef context, JSObjectRef object, JSObjectRef thisObject, size_t argumentCount,
1397 const JSValueRef arguments[], JSValueRef* exception)
1401 MessagingStoragePriv* priv = static_cast<MessagingStoragePriv*>(JSObjectGetPrivate(thisObject));
1405 LogDebug("priv is NULL.");
1406 return JSTizenExceptionFactory::postException(
1407 context, exception, JSTizenException::TYPE_MISMATCH_ERROR, JSMESSAGING_EXCEPTION_MSG_TYPE_MISMATCH);
1410 MessagingStoragePrivObjPtr objectPriv = priv->getObject();
1414 LogDebug("objectPriv is NULL.");
1415 return JSTizenExceptionFactory::postException(
1416 context, exception, JSTizenException::TYPE_MISMATCH_ERROR, JSMESSAGING_EXCEPTION_MSG_TYPE_MISMATCH);
1420 AceSecurityStatus status = MESSAGING_CHECK_ACCESS(
1421 MessagingExportedNames[MESSAGING_FUNCTION_API_ADD_CONVERSATIONS_CHANGE_LISTNER]);
1422 TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
1424 WrtDeviceApis::CommonsJavaScript::JSCallbackManagerPtr callbackManager(NULL);
1426 WrtDeviceApis::CommonsJavaScript::JSCallbackManagerPtr messagesUpdatedCbm(NULL);
1427 WrtDeviceApis::CommonsJavaScript::JSCallbackManagerPtr messagesRemovedCbm(NULL);
1429 callbackManager = JSCallbackManager::createObject(priv->getContext());
1431 ConverterMessageFactory::ConverterType converter = ConverterMessageFactory::getConverter(context);
1435 FilterConverterFactory::ConverterType filterConverter = FilterConverterFactory::getConverter(context);
1437 JSValueRef onSuccessForCbm = NULL;
1439 OnMessagesChanged functionResult;
1440 int funtionIndex = -1;
1442 if((objectPriv->getType() < Api::Messaging::SMS) || (objectPriv->getType() > Api::Messaging::EMAIL))
1444 ThrowMsg(InvalidArgumentException, "Message type is not SMS or MMS or EMAIL.");
1448 if(objectPriv->getType() == Api::Messaging::EMAIL)
1450 if(objectPriv->getIndex() < 1)
1452 ThrowMsg(InvalidArgumentException, "serviceId is not defined.");
1457 if(argumentCount >= 1) // successCallback
1459 if(!Validator(context).isNullOrUndefined(arguments[0]))
1461 functionResult = converter->toMessageMultifunctions(arguments[0]);
1462 funtionIndex = functionResult.functionIndex;
1464 onSuccessForCbm = functionResult.messagesAdded;
1465 messagesUpdatedCbm = JSCallbackManager::createObject(priv->getContext(), functionResult.messagesUpdated, NULL);
1466 messagesRemovedCbm = JSCallbackManager::createObject(priv->getContext(), functionResult.messagesRemoved, NULL);
1468 else // NOT nullable
1470 LogDebug("SuccessCallback type is mismatched.");
1471 Throw(ConversionException);
1475 if(funtionIndex < 0)
1477 LogError("funtionIndex is not valid");
1478 Throw(ConversionException);
1481 EventOnMessagingStorageChangesPrivateDataPtr privData(
1482 new EventOnMessagingStorageChangesPrivateData(callbackManager, messagesUpdatedCbm, messagesRemovedCbm, funtionIndex));
1484 if(argumentCount >= 2) //optional AbstractFilter? filter
1486 if(JSValueIsObject(context, arguments[1]))
1488 Api::Tizen::FilterPtr filter = filterConverter->toFilter(arguments[1]);
1489 privData->setFilter(filter);
1491 else // NOT nullable
1493 LogDebug("Filter type is mismatched.");
1494 Throw(ConversionException);
1499 callbackManager->setOnSuccess(onSuccessForCbm);
1502 privData->setIndex(objectPriv->getIndex());
1503 privData->setType(objectPriv->getType());
1505 MessagingListener::getInstance().registerMessageReceivedEmitter(privData);
1507 // add to map and return index
1508 return JSValueMakeNumber(context,
1509 MessagingListener::getInstance().addIncomingMsgCallback(callbackManager, funtionIndex));
1511 Catch(WrtDeviceApis::Commons::ConversionException)
1513 LogError("Error on conversion");
1514 return JSTizenExceptionFactory::postException(context, exception,
1515 JSTizenException::TYPE_MISMATCH_ERROR, JSMESSAGING_EXCEPTION_MSG_TYPE_MISMATCH);
1517 Catch(WrtDeviceApis::Commons::InvalidArgumentException)
1519 LogError("Invalid argument exception");
1520 return JSTizenExceptionFactory::postException(context, exception,
1521 JSTizenException::INVALID_VALUES_ERROR, JSMESSAGING_EXCEPTION_MSG_INVALID_ARGUMENT);
1523 Catch(WrtDeviceApis::Commons::UnsupportedException)
1525 LogError("Unsupported exception");
1526 return JSTizenExceptionFactory::postException(context, exception,
1527 JSTizenException::NOT_SUPPORTED_ERROR, JSMESSAGING_EXCEPTION_MSG_NOT_SUPPORTED); // unsupported type
1529 Catch(WrtDeviceApis::Commons::AlreadyInUseException)
1531 LogError("Already in use exception");
1533 Catch(WrtDeviceApis::Commons::PlatformException)
1535 LogError("not registered for incoming message notifications");
1538 return JSValueMakeUndefined(context);
1542 JSValueRef JSMessagingStorage::addFoldersChangeListener(JSContextRef context, JSObjectRef object, JSObjectRef thisObject, size_t argumentCount,
1543 const JSValueRef arguments[], JSValueRef* exception)
1548 MessagingStoragePriv* priv = static_cast<MessagingStoragePriv*>(JSObjectGetPrivate(thisObject));
1552 LogDebug("priv is NULL.");
1553 return JSTizenExceptionFactory::postException(
1554 context, exception, JSTizenException::TYPE_MISMATCH_ERROR, JSMESSAGING_EXCEPTION_MSG_TYPE_MISMATCH);
1557 MessagingStoragePrivObjPtr objectPriv = priv->getObject();
1561 LogDebug("objectPriv is NULL.");
1562 return JSTizenExceptionFactory::postException(
1563 context, exception, JSTizenException::TYPE_MISMATCH_ERROR, JSMESSAGING_EXCEPTION_MSG_TYPE_MISMATCH);
1567 AceSecurityStatus status = MESSAGING_CHECK_ACCESS(
1568 MessagingExportedNames[MESSAGING_FUNCTION_API_ADD_FOLDERS_CHANGE_LISTNER]);
1569 TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
1571 WrtDeviceApis::CommonsJavaScript::JSCallbackManagerPtr callbackManager(NULL);
1573 WrtDeviceApis::CommonsJavaScript::JSCallbackManagerPtr messagesUpdatedCbm(NULL);
1574 WrtDeviceApis::CommonsJavaScript::JSCallbackManagerPtr messagesRemovedCbm(NULL);
1576 callbackManager = JSCallbackManager::createObject(priv->getContext());
1578 ConverterMessageFactory::ConverterType converter = ConverterMessageFactory::getConverter(context);
1583 FilterConverterFactory::ConverterType filterConverter = FilterConverterFactory::getConverter(context);
1585 JSValueRef onSuccessForCbm = NULL;
1587 OnMessagesChanged functionResult;
1588 int funtionIndex = -1;
1590 if((objectPriv->getType() < Api::Messaging::SMS) || (objectPriv->getType() > Api::Messaging::EMAIL))
1592 ThrowMsg(InvalidArgumentException, "Message type is not SMS or MMS or EMAIL.");
1596 if(objectPriv->getType() == Api::Messaging::EMAIL)
1598 if(objectPriv->getIndex() < 1)
1600 ThrowMsg(InvalidArgumentException, "serviceId is not defined.");
1605 if(argumentCount >= 1) // successCallback
1607 if(!Validator(context).isNullOrUndefined(arguments[0]))
1609 functionResult = converter->toMessageMultifunctions(arguments[0]);
1610 funtionIndex = functionResult.functionIndex;
1612 onSuccessForCbm = functionResult.messagesAdded;
1613 messagesUpdatedCbm = JSCallbackManager::createObject(priv->getContext(), functionResult.messagesUpdated, NULL);
1614 messagesRemovedCbm = JSCallbackManager::createObject(priv->getContext(), functionResult.messagesRemoved, NULL);
1616 else // NOT nullable
1618 LogDebug("SuccessCallback type is mismatched.");
1619 Throw(ConversionException);
1623 if(funtionIndex < 0)
1625 LogError("funtionIndex is not valid");
1626 Throw(ConversionException);
1629 EventOnMessagingStorageChangesPrivateDataPtr privData(
1630 new EventOnMessagingStorageChangesPrivateData(callbackManager, messagesUpdatedCbm, messagesRemovedCbm, funtionIndex));
1632 if(argumentCount >= 2) //optional AbstractFilter? filter
1634 if(JSValueIsObject(context, arguments[1]))
1636 Api::Tizen::FilterPtr filter = filterConverter->toFilter(arguments[1]);
1637 privData->setFilter(filter);
1639 else // NOT nullable
1641 LogDebug("Filter type is mismatched.");
1642 Throw(ConversionException);
1647 callbackManager->setOnSuccess(onSuccessForCbm);
1650 privData->setIndex(objectPriv->getIndex());
1651 privData->setType(objectPriv->getType());
1653 MessagingListener::getInstance().registerMessageReceivedEmitter(privData);
1655 // add to map and return index
1656 return JSValueMakeNumber(context,
1657 MessagingListener::getInstance().addIncomingMsgCallback(callbackManager, funtionIndex));
1660 Catch(WrtDeviceApis::Commons::ConversionException)
1662 LogError("Error on conversion");
1663 return JSTizenExceptionFactory::postException(context, exception,
1664 JSTizenException::TYPE_MISMATCH_ERROR, JSMESSAGING_EXCEPTION_MSG_TYPE_MISMATCH);
1666 Catch(WrtDeviceApis::Commons::InvalidArgumentException)
1668 LogError("Invalid argument exception");
1669 return JSTizenExceptionFactory::postException(context, exception,
1670 JSTizenException::INVALID_VALUES_ERROR, JSMESSAGING_EXCEPTION_MSG_INVALID_ARGUMENT);
1672 Catch(WrtDeviceApis::Commons::UnsupportedException)
1674 LogError("Unsupported exception");
1675 return JSTizenExceptionFactory::postException(context, exception,
1676 JSTizenException::NOT_SUPPORTED_ERROR, JSMESSAGING_EXCEPTION_MSG_NOT_SUPPORTED); // unsupported type
1678 Catch(WrtDeviceApis::Commons::AlreadyInUseException)
1680 LogError("Already in use exception");
1682 Catch(WrtDeviceApis::Commons::PlatformException)
1684 LogError("not registered for incoming message notifications");
1687 return JSValueMakeUndefined(context);
1690 JSValueRef JSMessagingStorage::removeChangeListener(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount,
1691 const JSValueRef arguments[], JSValueRef* exception)
1695 MessagingStoragePriv* priv = static_cast<MessagingStoragePriv*>(JSObjectGetPrivate(thisObject));
1701 LogDebug("priv is NULL.");
1702 return JSTizenExceptionFactory::postException(
1703 context, exception, JSTizenException::TYPE_MISMATCH_ERROR, JSMESSAGING_EXCEPTION_MSG_TYPE_MISMATCH);
1706 MessagingStoragePrivObjPtr objectPriv = priv->getObject();
1710 LogDebug("objectPriv is NULL.");
1711 return JSTizenExceptionFactory::postException(
1712 context, exception, JSTizenException::TYPE_MISMATCH_ERROR, JSMESSAGING_EXCEPTION_MSG_TYPE_MISMATCH);
1716 AceSecurityStatus status = MESSAGING_CHECK_ACCESS(
1717 MessagingExportedNames[MESSAGING_FUNCTION_API_REMOVE_CHANGE_LISTENER]);
1718 TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
1720 WrtDeviceApis::CommonsJavaScript::JSCallbackManagerPtr callbackManager(NULL);
1721 callbackManager = JSCallbackManager::createObject(priv->getContext());
1723 ConverterMessageFactory::ConverterType converter = ConverterMessageFactory::getConverter(context);
1727 FilterConverterFactory::ConverterType filterConverter = FilterConverterFactory::getConverter(context);
1729 if(argumentCount >= 1) //optional unsigned long? limit JSValueIsUndefined(context, arguments[0]), JSValueIsNull(context, arguments[0])
1731 if (!Validator(context).isNullOrUndefined(arguments[0]))
1733 if (!JSValueIsNumber(context, arguments[0]))
1735 Throw(ConversionException);
1737 handler = filterConverter->toLong(arguments[0]);
1741 Throw(ConversionException);
1746 LogError("handler is not valid");
1747 Throw(ConversionException);
1749 MessagingListener::getInstance().removeIncomingMsgCallback(handler, objectPriv->getType(), objectPriv->getIndex());
1751 Catch(WrtDeviceApis::Commons::ConversionException)
1753 LogError("conversion error");
1754 return JSTizenExceptionFactory::postException(context, exception,
1755 JSTizenException::TYPE_MISMATCH_ERROR, JSMESSAGING_EXCEPTION_MSG_TYPE_MISMATCH);
1757 Catch(WrtDeviceApis::Commons::InvalidArgumentException)
1759 LogError(">>> InvalidValuesException");
1760 return JSTizenExceptionFactory::postException(context, exception,
1761 JSTizenException::INVALID_VALUES_ERROR, JSMESSAGING_EXCEPTION_MSG_INVALID_ARGUMENT);
1763 return JSValueMakeUndefined(context);