*/
#include "JSMessagingStorage.h"
+#include "JSMessagingService.h"
#include "MessagingListener.h"
#include "ConverterMessage.h"
#include "MessagingStorageMultiCallback.h"
JSClassRef JSMessagingStorage::m_jsClassRef = NULL;
- JSClassDefinition JSMessagingStorage::m_classInfo = {
+ JSClassDefinition JSMessagingStorage::m_classInfo =
+ {
0,
kJSClassAttributeNone,
- "messagingStorage",
+ "messageStorage",
NULL,
NULL,
m_function,
NULL
};
- JSStaticFunction JSMessagingStorage::m_function[] = {
+ JSStaticFunction JSMessagingStorage::m_function[] =
+ {
{ "addDraftMessage", JSMessagingStorage::addDraftMessage, kJSPropertyAttributeNone },
{ "findMessages", JSMessagingStorage::findMessages, kJSPropertyAttributeNone },
{ "removeMessages", JSMessagingStorage::removeMessages, kJSPropertyAttributeNone },
{ 0, 0, 0 }
};
- const JSClassRef JSMessagingStorage::getClassRef() {
- if (!m_jsClassRef) {
+ const JSClassRef JSMessagingStorage::getClassRef()
+ {
+ if (!m_jsClassRef)
+ {
m_jsClassRef = JSClassCreate(&m_classInfo);
}
return m_jsClassRef;
}
- void JSMessagingStorage::initialize(JSContextRef context, JSObjectRef object) {
+ void JSMessagingStorage::initialize(JSContextRef context, JSObjectRef object)
+ {
LogDebug("creation messaging instance");
-
- MessagingListener* priv = new MessagingListener(context);
- JSObjectSetPrivate(object, static_cast<void*>(priv));
- LogDebug("global context=" << priv->getContext());
-
}
- void JSMessagingStorage::finalize(JSObjectRef object) {
+ void JSMessagingStorage::finalize(JSObjectRef object)
+ {
LogDebug("enter");
- MessagingListener* priv =
- static_cast<MessagingListener*>(JSObjectGetPrivate(object));
- if (priv) {
- // deregister from incoming message notifications
- priv->deregisterMessageReceivedEmitter();
+ MessagingStoragePriv* priv = static_cast<MessagingStoragePriv*>(JSObjectGetPrivate(object));
+ if (priv)
+ {
LogDebug("deleting private object (messaging)");
// for messaging object, private object is shared pointer, so will be deleted automatically
delete priv;
// object will be deleted, but used to show that private object is deleted
JSObjectSetPrivate(object, NULL);
}
-
}
- bool JSMessagingStorage::hasInstance(JSContextRef context, JSObjectRef constructor, JSValueRef possibleInstance, JSValueRef* exception) {
+ bool JSMessagingStorage::hasInstance(JSContextRef context, JSObjectRef constructor, JSValueRef possibleInstance, JSValueRef* exception)
+ {
return JSValueIsObjectOfClass(context, possibleInstance, getClassRef());
}
JSValueRef JSMessagingStorage::getProperty(JSContextRef context, JSObjectRef object, JSStringRef propertyName, JSValueRef* exception)
- {
+ {
LogDebug("<<< ");
JSValueRef retVal = NULL;
- Try{
+ Try
+ {
Converter convert(context);
- if (JSStringIsEqualToUTF8CString(propertyName, "FOLDER_INBOX")) {
+ if (JSStringIsEqualToUTF8CString(propertyName, "FOLDER_INBOX"))
+ {
LogDebug("FOLDER_INBOX" << ":" << "1");
retVal = convert.toJSValueRef(Api::Messaging::INBOX);
- } else if (JSStringIsEqualToUTF8CString(propertyName, "FOLDER_OUTBOX")) {
+ }
+ else if (JSStringIsEqualToUTF8CString(propertyName, "FOLDER_OUTBOX"))
+ {
LogDebug("FOLDER_OUTBOX" << ":" << "2");
retVal = convert.toJSValueRef(Api::Messaging::OUTBOX);
- } else if (JSStringIsEqualToUTF8CString(propertyName, "FOLDER_DRAFTS")) {
+ }
+ else if (JSStringIsEqualToUTF8CString(propertyName, "FOLDER_DRAFTS"))
+ {
LogDebug("FOLDER_DRAFTS" << ":" << "3");
retVal = convert.toJSValueRef(Api::Messaging::DRAFTBOX);
- } else if (JSStringIsEqualToUTF8CString(propertyName, "FOLDER_SENTBOX")) {
+ }
+ else if (JSStringIsEqualToUTF8CString(propertyName, "FOLDER_SENTBOX"))
+ {
LogDebug("FOLDER_SENTBOX" << ":" << "4");
retVal = convert.toJSValueRef(Api::Messaging::SENTBOX);
- } else{
+ }
+ else
+ {
retVal = JSValueMakeUndefined(context);
+ }
}
- }Catch (WrtDeviceApis::Commons::Exception){
+ Catch (WrtDeviceApis::Commons::Exception)
+ {
LogError("Exception: " << _rethrown_exception.GetMessage());
return JSTizenExceptionFactory::postException(context, exception,
JSTizenException::UNKNOWN_ERROR, JSMESSAGING_EXCEPTION_MSG_UNKNOWN);
-
- }
+ }
LogDebug(">>>");
return retVal;
}
JSValueRef JSMessagingStorage::addDraftMessage(JSContextRef context, JSObjectRef object, JSObjectRef thisObject, size_t argumentCount,
- const JSValueRef arguments[], JSValueRef* exception) {
-
- LogDebug("<<<");
-
- MessagingListener* priv = static_cast<MessagingListener*>
- (JSObjectGetPrivate(thisObject));
-
- if (!priv) {
- LogError(">>> Null pointer");
- return JSTizenExceptionFactory::postException(context, exception,
- JSTizenException::UNKNOWN_ERROR, JSMESSAGING_EXCEPTION_MSG_UNKNOWN);
-
- }
+ const JSValueRef arguments[], JSValueRef* exception)
+ {
- JSContextRef globalContext = priv->getContext();
+ LogDebug("<<<");
- if (argumentCount < 1) {
- LogError(">>> TypeMismatchException");
- return JSTizenExceptionFactory::postException(context, exception,
- JSTizenException::INVALID_VALUES_ERROR, JSMESSAGING_EXCEPTION_MSG_INVALID_ARGUMENT);
+ MessagingStoragePriv* priv = static_cast<MessagingStoragePriv*>(JSObjectGetPrivate(thisObject));
- }
+ if (!priv)
+ {
+ LogDebug("priv is NULL.");
+ return JSTizenExceptionFactory::postException(
+ context, exception, JSTizenException::TYPE_MISMATCH_ERROR, JSMESSAGING_EXCEPTION_MSG_TYPE_MISMATCH);
+ }
- WrtDeviceApis::CommonsJavaScript::JSCallbackManagerPtr callbackManager = JSCallbackManager::createObject(globalContext);
+ MessagingStoragePrivObjPtr objectPriv = priv->getObject();
- ConverterMessageFactory::ConverterType converter = ConverterMessageFactory::getConverter(context);
- Try {
+ if (!objectPriv)
+ {
+ LogDebug("objectPriv is NULL.");
+ return JSTizenExceptionFactory::postException(
+ context, exception, JSTizenException::TYPE_MISMATCH_ERROR, JSMESSAGING_EXCEPTION_MSG_TYPE_MISMATCH);
+ }
//check permission.
AceSecurityStatus status = MESSAGING_CHECK_ACCESS(
- priv->getContext(),
MessagingExportedNames[MESSAGING_FUNCTION_API_ADD_DRAFT_MESSAGE]);
- TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
+ TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
+
+ WrtDeviceApis::CommonsJavaScript::JSCallbackManagerPtr callbackManager(NULL);
+ callbackManager = JSCallbackManager::createObject(priv->getContext());
- Api::Messaging::EventAddDraftMessagePtr event(new Api::Messaging::EventAddDraftMessage());
+ ConverterMessageFactory::ConverterType converter = ConverterMessageFactory::getConverter(context);
+
+ Try
+ {
+ Api::Messaging::EventAddDraftMessagePtr event(new Api::Messaging::EventAddDraftMessage());
FilterConverterFactory::ConverterType filterConverter = FilterConverterFactory::getConverter(context);
- if (argumentCount > 1) {
- callbackManager->setOnSuccess(converter->toFunctionOrNull(arguments[1]));
- }
-
- if (argumentCount > 2) {
- callbackManager->setOnError(converter->toFunctionOrNull(arguments[2]));
- }
-
- event->msg = converter->toIMessage(arguments[0]);
+ JSValueRef onSuccessForCbm = NULL, onErrorForCbm = NULL;
+
+ if((objectPriv->getType() < Api::Messaging::SMS) || (objectPriv->getType() > Api::Messaging::EMAIL))
+ {
+ ThrowMsg(InvalidArgumentException, "Message type is not SMS or MMS or EMAIL.");
+ }
+ else
+ {
+ if(objectPriv->getType() == Api::Messaging::EMAIL)
+ {
+ if(objectPriv->getIndex() < 1)
+ {
+ ThrowMsg(InvalidArgumentException, "serviceId is not defined.");
+ }
+ }
+ }
- event->setPrivateData(DPL::StaticPointerCast<WrtDeviceApis::Commons::IEventPrivateData >(
- callbackManager));
- event->setForAsynchronousCall(priv);
+ if(argumentCount >= 1) // Message object
+ {
+ if(JSValueIsObject(context, arguments[0]))
+ {
+ event->msg = converter->toIMessage(arguments[0]);
+ }
+ else // NOT nullable
+ {
+ LogDebug("Invalid argument exception");
+ Throw(ConversionException);
+ }
+ }
+ if(argumentCount >= 2) // successCallback
+ {
+ if(Validator(context).isCallback(arguments[1]))
+ {
+ onSuccessForCbm = arguments[1];
+ }
+ else if(!Validator(context).isNullOrUndefined(arguments[1])) //nullable
+ {
+ LogDebug("SuccessCallback type is mismatched.");
+ Throw(ConversionException);
+ }
+ }
+ if(argumentCount >= 3) //optional ErrorCallback? errorCallback
+ {
+ if(Validator(context).isCallback(arguments[2]))
+ {
+ onErrorForCbm = arguments[2];
+ }
+ else if(!Validator(context).isNullOrUndefined(arguments[2])) //nullable
+ {
+ LogDebug("ErrorCallback type is mismatched.");
+ Throw(ConversionException);
+ }
+ }
+ if(callbackManager)
+ {
+ callbackManager->setOnSuccess(onSuccessForCbm);
+ callbackManager->setOnError(onErrorForCbm);
+ }
+
+ event->setIndex(objectPriv->getIndex());
+ event->setType(objectPriv->getType());
+ event->setPrivateData(DPL::StaticPointerCast<WrtDeviceApis::Commons::IEventPrivateData >(callbackManager));
+ event->setForAsynchronousCall(&MessagingListener::getInstance());
- Api::Messaging::ReqReceiverMessageSingleton::Instance().addDraftMessage(event);
+ Api::Messaging::ReqReceiverMessageSingleton::Instance().addDraftMessage(event);
- return JSValueMakeNull(context);
- }Catch(WrtDeviceApis::Commons::ConversionException) {
- LogError(">>> TypeMismatchException");
- return JSTizenExceptionFactory::postException(context, exception,
- JSTizenException::TYPE_MISMATCH_ERROR, JSMESSAGING_EXCEPTION_MSG_TYPE_MISMATCH);
- }Catch(WrtDeviceApis::Commons::NullPointerException) {
- LogError(">>> TypeMismatchException");
- return JSTizenExceptionFactory::postException(context, exception,
- JSTizenException::TYPE_MISMATCH_ERROR, JSMESSAGING_EXCEPTION_MSG_TYPE_MISMATCH);
- }Catch(WrtDeviceApis::Commons::InvalidArgumentException) {
- LogError(">>> InvalidValuesException");
- if(argumentCount < 3)
+ return makePendingOperation(context, event);
+ }
+ Catch(WrtDeviceApis::Commons::ConversionException)
{
+ LogError(">>> TypeMismatchException");
return JSTizenExceptionFactory::postException(context, exception,
- JSTizenException::INVALID_VALUES_ERROR, JSMESSAGING_EXCEPTION_MSG_INVALID_ARGUMENT);
- }
- callbackManager->callOnError(JSTizenExceptionFactory::makeErrorObject(context,
- JSTizenException::INVALID_VALUES_ERROR, JSMESSAGING_EXCEPTION_MSG_INVALID_ARGUMENT));
- }Catch(WrtDeviceApis::Commons::PlatformException) {
- LogError(">>> UnknownException");
- return JSTizenExceptionFactory::postException(context, exception,
- JSTizenException::UNKNOWN_ERROR, JSMESSAGING_EXCEPTION_MSG_UNKNOWN);
- }
-
- LogError(">>> JSValueMakeNull");
- return JSValueMakeNull(context);
+ JSTizenException::TYPE_MISMATCH_ERROR, JSMESSAGING_EXCEPTION_MSG_TYPE_MISMATCH);
+ }
+ Catch(WrtDeviceApis::Commons::NullPointerException)
+ {
+ LogError(">>> TypeMismatchException");
+ return JSTizenExceptionFactory::postException(context, exception,
+ JSTizenException::TYPE_MISMATCH_ERROR, JSMESSAGING_EXCEPTION_MSG_TYPE_MISMATCH);
+ }
+ Catch(WrtDeviceApis::Commons::InvalidArgumentException)
+ {
+ LogError(">>> InvalidValuesException");
+ return JSTizenExceptionFactory::postException(context, exception,
+ JSTizenException::INVALID_VALUES_ERROR, JSMESSAGING_EXCEPTION_MSG_INVALID_ARGUMENT);
+ }
+ Catch(WrtDeviceApis::Commons::PlatformException)
+ {
+ LogError(">>> UnknownException");
+ return JSTizenExceptionFactory::postException(context, exception,
+ JSTizenException::UNKNOWN_ERROR, JSMESSAGING_EXCEPTION_MSG_UNKNOWN);
+ }
+
+ LogError(">>> JSValueMakeNull");
+ return JSValueMakeNull(context);
+
}
- JSValueRef JSMessagingStorage::findMessages(JSContextRef context, JSObjectRef object, JSObjectRef thisObject, size_t argumentCount,
- const JSValueRef arguments[], JSValueRef* exception) {
+ JSValueRef JSMessagingStorage::findMessages(JSContextRef context, JSObjectRef object, JSObjectRef thisObject, size_t argumentCount,
+ const JSValueRef arguments[], JSValueRef* exception)
+ {
LogDebug("<<<");
- MessagingListener* priv = static_cast<MessagingListener*>
- (JSObjectGetPrivate(thisObject));
-
- if (!priv) {
- LogError(">>> Null pointer");
- return JSTizenExceptionFactory::postException(context, exception,
- JSTizenException::UNKNOWN_ERROR, JSMESSAGING_EXCEPTION_MSG_UNKNOWN);
+ MessagingStoragePriv* priv = static_cast<MessagingStoragePriv*>(JSObjectGetPrivate(thisObject));
+ if (!priv)
+ {
+ LogDebug("priv is NULL.");
+ return JSTizenExceptionFactory::postException(
+ context, exception, JSTizenException::TYPE_MISMATCH_ERROR, JSMESSAGING_EXCEPTION_MSG_TYPE_MISMATCH);
}
- JSContextRef globalContext = priv->getContext();
-
- if (argumentCount < 2) {
- LogError(">>> TypeMismatchException");
- return JSTizenExceptionFactory::postException(context, exception,
- JSTizenException::TYPE_MISMATCH_ERROR, JSMESSAGING_EXCEPTION_MSG_INVALID_ARGUMENT);
+ MessagingStoragePrivObjPtr objectPriv = priv->getObject();
+ if (!objectPriv)
+ {
+ LogDebug("objectPriv is NULL.");
+ return JSTizenExceptionFactory::postException(
+ context, exception, JSTizenException::TYPE_MISMATCH_ERROR, JSMESSAGING_EXCEPTION_MSG_TYPE_MISMATCH);
}
- WrtDeviceApis::CommonsJavaScript::JSCallbackManagerPtr callbackManager = JSCallbackManager::createObject(globalContext);
-
- ConverterMessageFactory::ConverterType converter = ConverterMessageFactory::getConverter(context);
- Try {
+ //check permission.
+ AceSecurityStatus status = MESSAGING_CHECK_ACCESS(
+ MessagingExportedNames[MESSAGING_FUNCTION_API_FIND_MESSAGES]);
+ TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
- //check permission.
- AceSecurityStatus status = MESSAGING_CHECK_ACCESS(
- priv->getContext(),
- MessagingExportedNames[MESSAGING_FUNCTION_API_FIND_MESSAGES]);
- TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
+ WrtDeviceApis::CommonsJavaScript::JSCallbackManagerPtr callbackManager(NULL);
+ callbackManager = JSCallbackManager::createObject(priv->getContext());
+ ConverterMessageFactory::ConverterType converter = ConverterMessageFactory::getConverter(context);
+
+ Try
+ {
Api::Messaging::EventQueryMessagesPtr event(new Api::Messaging::EventQueryMessages());
- FilterConverterFactory::ConverterType filterConverter = FilterConverterFactory::getConverter(context);
- LogDebug("start filter");
- Api::Tizen::FilterPtr filter = filterConverter->toFilter(arguments[0]);
- event->setFilter(filter);
- LogDebug("end filter");
- callbackManager->setOnSuccess(converter->toFunction(arguments[1]));
- if(argumentCount > 2)
+ FilterConverterFactory::ConverterType filterConverter = FilterConverterFactory::getConverter(context);
+
+ JSValueRef onSuccessForCbm = NULL, onErrorForCbm = NULL;
+
+ if((objectPriv->getType() < Api::Messaging::SMS) || (objectPriv->getType() > Api::Messaging::EMAIL))
{
- callbackManager->setOnError(converter->toFunctionOrNull(arguments[2]));
+ ThrowMsg(InvalidArgumentException, "Message type is not SMS or MMS or EMAIL.");
}
-
- if ((argumentCount >= 3) && !JSValueIsNull(context, arguments[0]) && !JSValueIsUndefined(context, arguments[0])) {
- switch(argumentCount){
- case 6:{
- long offset = filterConverter->toLong(arguments[5]);
- LogDebug("offset:" << offset);
- event->setOffset(offset);
+ else
+ {
+ if(objectPriv->getType() == Api::Messaging::EMAIL)
+ {
+ if(objectPriv->getIndex() < 1)
+ {
+ ThrowMsg(InvalidArgumentException, "serviceId is not defined.");
}
- case 5:{
- long limit = filterConverter->toLong(arguments[4]);
- LogDebug("limit:" << limit);
- event->setLimit(limit);
+ }
+ }
+
+ if(argumentCount >= 1) //optional AbstractFilter? filter
+ {
+ if(JSValueIsObject(context, arguments[0]))
+ {
+ Api::Tizen::FilterPtr filter = filterConverter->toFilter(arguments[0]);
+ event->setFilter(filter);
+ }
+ else // NOT nullable
+ {
+ LogDebug("Filter type is mismatched.");
+ Throw(ConversionException);
+ }
+ }
+ if(argumentCount >= 2) // successCallback
+ {
+ if(Validator(context).isCallback(arguments[1]))
+ {
+ onSuccessForCbm = arguments[1];
+ }
+ else // NOT nullable
+ {
+ LogDebug("SuccessCallback type is mismatched.");
+ Throw(ConversionException);
+ }
+ }
+ if(argumentCount >= 3) //optional ErrorCallback? errorCallback
+ {
+ if(Validator(context).isCallback(arguments[2]))
+ {
+ onErrorForCbm = arguments[2];
+ }
+ else if(!Validator(context).isNullOrUndefined(arguments[2])) //nullable
+ {
+ LogDebug("ErrorCallback type is mismatched.");
+ Throw(ConversionException);
+ }
+ }
+ if(argumentCount >= 4) //optional SortMode? sortMode
+ {
+ if(JSValueIsObject(context, arguments[3]))
+ {
+ Api::Tizen::SortModePtr sortMode = filterConverter->toSortMode(arguments[3]);
+ event->setSortMode(sortMode);
+ }
+ else if(!Validator(context).isNullOrUndefined(arguments[3])) //nullable
+ {
+ LogDebug("SortMode type is mismatched.");
+ Throw(ConversionException);
+ }
+ }
+ if(argumentCount >= 5) //optional unsigned long? limit JSValueIsUndefined(context, arguments[0]), JSValueIsNull(context, arguments[0])
+ {
+ if (!Validator(context).isNullOrUndefined(arguments[4]))
+ {
+ if (!JSValueIsNumber(context, arguments[4]))
+ {
+ Throw(ConversionException);
}
- case 4:{
- Api::Tizen::SortModePtr sortMode = filterConverter->toSortMode(arguments[3]);
- event->setSortMode(sortMode);
- break;
+ long limit = filterConverter->toULong(arguments[4]);
+ event->setLimit(limit);
+ }
+ }
+ if(argumentCount >= 6) //optional unsigned long? offset JSValueIsUndefined(context, arguments[0]), JSValueIsNull(context, arguments[0])
+ {
+ if (!Validator(context).isNullOrUndefined(arguments[5]))
+ {
+ if (!JSValueIsNumber(context, arguments[5]))
+ {
+ Throw(ConversionException);
}
+ long offset = filterConverter->toULong(arguments[5]);
+ event->setOffset(offset);
}
+ }
+
+ if(callbackManager)
+ {
+ callbackManager->setOnSuccess(onSuccessForCbm);
+ callbackManager->setOnError(onErrorForCbm);
}
event->setPrivateData(DPL::StaticPointerCast<WrtDeviceApis::Commons::IEventPrivateData >(callbackManager));
- event->setForAsynchronousCall(priv);
+ event->setForAsynchronousCall(&MessagingListener::getInstance());
+ event->setIndex(objectPriv->getIndex());
+ event->setType(objectPriv->getType());
Api::Messaging::ReqReceiverMessageSingleton::Instance().queryMessages(event);
LogError(">>>");
- return JSValueMakeNull(context);
- }Catch(WrtDeviceApis::Commons::ConversionException) {
+ return makePendingOperation(context, event);
+ }
+ Catch(WrtDeviceApis::Commons::ConversionException)
+ {
LogError(">>> TypeMismatchException");
return JSTizenExceptionFactory::postException(context, exception,
JSTizenException::TYPE_MISMATCH_ERROR, JSMESSAGING_EXCEPTION_MSG_TYPE_MISMATCH);
- }Catch(WrtDeviceApis::Commons::NullPointerException) {
+ }
+ Catch(WrtDeviceApis::Commons::NullPointerException)
+ {
LogError(">>> TypeMismatchException");
return JSTizenExceptionFactory::postException(context, exception,
JSTizenException::TYPE_MISMATCH_ERROR, JSMESSAGING_EXCEPTION_MSG_TYPE_MISMATCH);
- }Catch(WrtDeviceApis::Commons::InvalidArgumentException) {
+ }
+ Catch(WrtDeviceApis::Commons::InvalidArgumentException)
+ {
LogError(">>> InvalidValuesException");
- if(argumentCount < 3)
- {
- return JSTizenExceptionFactory::postException(context, exception,
- JSTizenException::INVALID_VALUES_ERROR, JSMESSAGING_EXCEPTION_MSG_INVALID_ARGUMENT);
- }
- callbackManager->callOnError(JSTizenExceptionFactory::makeErrorObject(context,
- JSTizenException::INVALID_VALUES_ERROR, JSMESSAGING_EXCEPTION_MSG_INVALID_ARGUMENT));
- }Catch(WrtDeviceApis::Commons::PlatformException) {
+ return JSTizenExceptionFactory::postException(context, exception,
+ JSTizenException::INVALID_VALUES_ERROR, JSMESSAGING_EXCEPTION_MSG_INVALID_ARGUMENT);
+ }
+ Catch(WrtDeviceApis::Commons::PlatformException)
+ {
LogError(">>> UnknownException");
return JSTizenExceptionFactory::postException(context, exception,
JSTizenException::UNKNOWN_ERROR, JSMESSAGING_EXCEPTION_MSG_UNKNOWN);
- }
+ }
LogError(">>> JSValueMakeNull");
return JSValueMakeNull(context);
}
JSValueRef JSMessagingStorage::removeMessages(JSContextRef context, JSObjectRef object, JSObjectRef thisObject, size_t argumentCount,
- const JSValueRef arguments[], JSValueRef* exception) {
-
- LogDebug("enter");
+ const JSValueRef arguments[], JSValueRef* exception)
+ {
- MessagingListener* priv = static_cast<MessagingListener*>
- (JSObjectGetPrivate(thisObject));
+ LogDebug("<<<");
- if (!priv) {
- LogError("Null pointer");
- return JSTizenExceptionFactory::postException(context, exception,
- JSTizenException::UNKNOWN_ERROR, JSMESSAGING_EXCEPTION_MSG_UNKNOWN);
+ MessagingStoragePriv* priv = static_cast<MessagingStoragePriv*>(JSObjectGetPrivate(thisObject));
+ if (!priv)
+ {
+ LogDebug("priv is NULL.");
+ return JSTizenExceptionFactory::postException(
+ context, exception, JSTizenException::TYPE_MISMATCH_ERROR, JSMESSAGING_EXCEPTION_MSG_TYPE_MISMATCH);
}
- JSContextRef globalContext = priv->getContext();
+ MessagingStoragePrivObjPtr objectPriv = priv->getObject();
- if (argumentCount < 1) {
- return JSTizenExceptionFactory::postException(context, exception,
- JSTizenException::INVALID_VALUES_ERROR, JSMESSAGING_EXCEPTION_MSG_INVALID_ARGUMENT);
+ if (!objectPriv)
+ {
+ LogDebug("objectPriv is NULL.");
+ return JSTizenExceptionFactory::postException(
+ context, exception, JSTizenException::TYPE_MISMATCH_ERROR, JSMESSAGING_EXCEPTION_MSG_TYPE_MISMATCH);
}
- WrtDeviceApis::CommonsJavaScript::JSCallbackManagerPtr callbackManager = JSCallbackManager::createObject(globalContext);
+ //check permission.
+ AceSecurityStatus status = MESSAGING_CHECK_ACCESS(
+ MessagingExportedNames[MESSAGING_FUNCTION_API_REMOVE_MESSAGES]);
+ TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
- ConverterMessageFactory::ConverterType converter = ConverterMessageFactory::getConverter(context);
- Try {
+ WrtDeviceApis::CommonsJavaScript::JSCallbackManagerPtr callbackManager(NULL);
+ callbackManager = JSCallbackManager::createObject(priv->getContext());
- //check permission.
- AceSecurityStatus status = MESSAGING_CHECK_ACCESS(
- priv->getContext(),
- MessagingExportedNames[MESSAGING_FUNCTION_API_REMOVE_MESSAGES]);
- TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
+ ConverterMessageFactory::ConverterType converter = ConverterMessageFactory::getConverter(context);
+
+ Try
+ {
Api::Messaging::EventDeleteMessagesPtr event(new Api::Messaging::EventDeleteMessages());
+
+ FilterConverterFactory::ConverterType filterConverter = FilterConverterFactory::getConverter(context);
+
+ JSValueRef onSuccessForCbm = NULL, onErrorForCbm = NULL;
+ JSObjectRef objArg = NULL;
- if (argumentCount > 1) {
- callbackManager->setOnSuccess(converter->toFunctionOrNull(arguments[1]));
+ if((objectPriv->getType() < Api::Messaging::SMS) || (objectPriv->getType() > Api::Messaging::EMAIL))
+ {
+ ThrowMsg(InvalidArgumentException, "Message type is not SMS or MMS or EMAIL.");
+ }
+ else
+ {
+ if(objectPriv->getType() == Api::Messaging::EMAIL)
+ {
+ if(objectPriv->getIndex() < 1)
+ {
+ ThrowMsg(InvalidArgumentException, "serviceId is not defined.");
+ }
+ }
}
- if (argumentCount > 2) {
- callbackManager->setOnError(converter->toFunctionOrNull(arguments[2]));
+ if(argumentCount >= 1) // Message object
+ {
+ if(JSValueIsObject(context, arguments[0]))
+ {
+ objArg = converter->toJSObjectRef(arguments[0]);
+ }
+ else
+ {
+ LogDebug("Invalid argument exception");
+ Throw(ConversionException);
+ }
+ }
+ if(argumentCount >= 2) // successCallback
+ {
+ if(Validator(context).isCallback(arguments[1]))
+ {
+ onSuccessForCbm = arguments[1];
+ }
+ else if(!Validator(context).isNullOrUndefined(arguments[1])) //nullable
+ {
+ LogDebug("SuccessCallback type is mismatched.");
+ Throw(ConversionException);
+ }
+ }
+ if(argumentCount >= 3) //optional ErrorCallback? errorCallback
+ {
+ if(Validator(context).isCallback(arguments[2]))
+ {
+ onErrorForCbm = arguments[2];
+ }
+ else if(!Validator(context).isNullOrUndefined(arguments[2])) //nullable
+ {
+ LogDebug("ErrorCallback type is mismatched.");
+ Throw(ConversionException);
+ }
+ }
+ if(callbackManager)
+ {
+ callbackManager->setOnSuccess(onSuccessForCbm);
+ callbackManager->setOnError(onErrorForCbm);
}
std::vector<Api::Messaging::IMessagePtr> msgs;
-
- JSObjectRef objArg = converter->toJSObjectRef(arguments[0]);
+
LogDebug("array length "<<JSGetArrayLength(context, objArg));
- for (std::size_t i = 0; i < JSGetArrayLength(context, objArg); i++){
+ for (std::size_t i = 0; i < JSGetArrayLength(context, objArg); i++)
+ {
JSValueRef element = JSGetArrayElement(context, objArg, i);
JSObjectRef arg = JSValueToObject(context, element, NULL);
Api::Messaging::IMessagePtr msg = converter->toIMessage(arg);
msgs.push_back(msg);
}
- event->msgArray = msgs;
+
+ event->msgArray = msgs;
event->setPrivateData(DPL::StaticPointerCast<WrtDeviceApis::Commons::IEventPrivateData >(callbackManager));
- event->setForAsynchronousCall(priv);
+ event->setForAsynchronousCall(&MessagingListener::getInstance());
+ event->setIndex(objectPriv->getIndex());
+ event->setType(objectPriv->getType());
Api::Messaging::ReqReceiverMessageSingleton::Instance().deleteMessages(event);
- return JSValueMakeNull(context);
- }Catch(WrtDeviceApis::Commons::ConversionException) {
+ return makePendingOperation(context, event);
+ }
+ Catch(WrtDeviceApis::Commons::ConversionException)
+ {
LogError(">>> TypeMismatchException");
return JSTizenExceptionFactory::postException(context, exception,
JSTizenException::TYPE_MISMATCH_ERROR, JSMESSAGING_EXCEPTION_MSG_TYPE_MISMATCH);
- }Catch(WrtDeviceApis::Commons::NullPointerException) {
+ }
+ Catch(WrtDeviceApis::Commons::NullPointerException)
+ {
LogError(">>> TypeMismatchException");
return JSTizenExceptionFactory::postException(context, exception,
JSTizenException::TYPE_MISMATCH_ERROR, JSMESSAGING_EXCEPTION_MSG_TYPE_MISMATCH);
- }Catch(WrtDeviceApis::Commons::InvalidArgumentException) {
+ }
+ Catch(WrtDeviceApis::Commons::InvalidArgumentException)
+ {
LogError(">>> InvalidValuesException");
- if(argumentCount < 3)
- {
- return JSTizenExceptionFactory::postException(context, exception,
- JSTizenException::INVALID_VALUES_ERROR, JSMESSAGING_EXCEPTION_MSG_INVALID_ARGUMENT);
- }
- callbackManager->callOnError(JSTizenExceptionFactory::makeErrorObject(context,
- JSTizenException::INVALID_VALUES_ERROR, JSMESSAGING_EXCEPTION_MSG_INVALID_ARGUMENT));
- }Catch(WrtDeviceApis::Commons::PlatformException) {
+ return JSTizenExceptionFactory::postException(context, exception,
+ JSTizenException::INVALID_VALUES_ERROR, JSMESSAGING_EXCEPTION_MSG_INVALID_ARGUMENT);
+ }
+ Catch(WrtDeviceApis::Commons::PlatformException)
+ {
LogError(">>> UnknownException");
return JSTizenExceptionFactory::postException(context, exception,
JSTizenException::UNKNOWN_ERROR, JSMESSAGING_EXCEPTION_MSG_UNKNOWN);
return JSValueMakeNull(context);
}
- JSValueRef JSMessagingStorage::updateMessages(JSContextRef context, JSObjectRef object, JSObjectRef thisObject, size_t argumentCount,
- const JSValueRef arguments[], JSValueRef* exception) {
-
- LogDebug("enter");
-
- MessagingListener* priv = static_cast<MessagingListener*>
- (JSObjectGetPrivate(thisObject));
-
- if (!priv) {
- LogError("Null pointer");
- return JSTizenExceptionFactory::postException(context, exception,
- JSTizenException::UNKNOWN_ERROR, JSMESSAGING_EXCEPTION_MSG_UNKNOWN);
+ JSValueRef JSMessagingStorage::updateMessages(JSContextRef context, JSObjectRef object, JSObjectRef thisObject, size_t argumentCount,
+ const JSValueRef arguments[], JSValueRef* exception)
+ {
- }
+ LogDebug("<<<");
- JSContextRef globalContext = priv->getContext();
+ MessagingStoragePriv* priv = static_cast<MessagingStoragePriv*>(JSObjectGetPrivate(thisObject));
- if (argumentCount < 1) {
- return JSTizenExceptionFactory::postException(context, exception,
- JSTizenException::INVALID_VALUES_ERROR, JSMESSAGING_EXCEPTION_MSG_INVALID_ARGUMENT);
- }
+ if (!priv)
+ {
+ LogDebug("priv is NULL.");
+ return JSTizenExceptionFactory::postException(
+ context, exception, JSTizenException::TYPE_MISMATCH_ERROR, JSMESSAGING_EXCEPTION_MSG_TYPE_MISMATCH);
+ }
- WrtDeviceApis::CommonsJavaScript::JSCallbackManagerPtr callbackManager = JSCallbackManager::createObject(
- globalContext);
+ MessagingStoragePrivObjPtr objectPriv = priv->getObject();
- ConverterMessageFactory::ConverterType converter = ConverterMessageFactory::getConverter(context);
-
- Try {
+ if (!objectPriv)
+ {
+ LogDebug("objectPriv is NULL.");
+ return JSTizenExceptionFactory::postException(
+ context, exception, JSTizenException::TYPE_MISMATCH_ERROR, JSMESSAGING_EXCEPTION_MSG_TYPE_MISMATCH);
+ }
//check permission.
AceSecurityStatus status = MESSAGING_CHECK_ACCESS(
- priv->getContext(),
MessagingExportedNames[MESSAGING_FUNCTION_API_UPDATE_MESSAGES]);
TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
- Api::Messaging::EventUpdateMessagesPtr event(new Api::Messaging::EventUpdateMessages());
+ WrtDeviceApis::CommonsJavaScript::JSCallbackManagerPtr callbackManager(NULL);
+ callbackManager = JSCallbackManager::createObject(priv->getContext());
- if (argumentCount > 1) {
- callbackManager->setOnSuccess(converter->toFunctionOrNull(arguments[1]));
- }
-
- if (argumentCount > 2) {
- callbackManager->setOnError(converter->toFunctionOrNull(arguments[2]));
- }
+ ConverterMessageFactory::ConverterType converter = ConverterMessageFactory::getConverter(context);
+
+ Try
+ {
+ Api::Messaging::EventUpdateMessagesPtr event(new Api::Messaging::EventUpdateMessages());
- std::vector<Api::Messaging::IMessagePtr> msgs;
-
- JSObjectRef objArg = converter->toJSObjectRef(arguments[0]);
- LogDebug("array length "<<JSGetArrayLength(context, objArg));
- for (std::size_t i = 0; i < JSGetArrayLength(context, objArg); i++)
- {
- JSValueRef element = JSGetArrayElement(context, objArg, i);
- JSObjectRef arg = JSValueToObject(context, element, NULL);
- Api::Messaging::IMessagePtr msg = converter->toIMessage(arg);
- msgs.push_back(msg);
- }
- event->msgArray = msgs;
+ FilterConverterFactory::ConverterType filterConverter = FilterConverterFactory::getConverter(context);
- event->setPrivateData(DPL::StaticPointerCast<WrtDeviceApis::Commons::IEventPrivateData >(
- callbackManager));
- event->setForAsynchronousCall(priv);
+ JSValueRef onSuccessForCbm = NULL, onErrorForCbm = NULL;
- Api::Messaging::ReqReceiverMessageSingleton::Instance().updateMessages(event);
+ JSObjectRef objArg = NULL;
- return JSValueMakeNull(context);
- }
- Catch(WrtDeviceApis::Commons::ConversionException) {
- LogError(">>> TypeMismatchException");
- return JSTizenExceptionFactory::postException(context, exception,
- JSTizenException::TYPE_MISMATCH_ERROR, JSMESSAGING_EXCEPTION_MSG_TYPE_MISMATCH);
- }Catch(WrtDeviceApis::Commons::NullPointerException) {
- LogError(">>> TypeMismatchException");
- return JSTizenExceptionFactory::postException(context, exception,
- JSTizenException::TYPE_MISMATCH_ERROR, JSMESSAGING_EXCEPTION_MSG_TYPE_MISMATCH);
- }Catch(WrtDeviceApis::Commons::InvalidArgumentException) {
- LogError(">>> InvalidValuesException");
- if(argumentCount < 3)
+ if((objectPriv->getType() < Api::Messaging::SMS) || (objectPriv->getType() > Api::Messaging::EMAIL))
+ {
+ ThrowMsg(InvalidArgumentException, "Message type is not SMS or MMS or EMAIL.");
+ }
+ else
+ {
+ if(objectPriv->getType() == Api::Messaging::EMAIL)
+ {
+ if(objectPriv->getIndex() < 1)
+ {
+ ThrowMsg(InvalidArgumentException, "serviceId is not defined.");
+ }
+ }
+ }
+
+ if(argumentCount >= 1) // Message object
+ {
+ if(JSValueIsObject(context, arguments[0]))
+ {
+ objArg = converter->toJSObjectRef(arguments[0]);
+ }
+ else
+ {
+ LogDebug("Invalid argument exception");
+ Throw(ConversionException);
+ }
+ }
+ if(argumentCount >= 2) // successCallback
+ {
+ if(Validator(context).isCallback(arguments[1]))
+ {
+ onSuccessForCbm = arguments[1];
+ }
+ else if(!Validator(context).isNullOrUndefined(arguments[1])) //nullable
+ {
+ LogDebug("SuccessCallback type is mismatched.");
+ Throw(ConversionException);
+ }
+ }
+ if(argumentCount >= 3) //optional ErrorCallback? errorCallback
+ {
+ if(Validator(context).isCallback(arguments[2]))
+ {
+ onErrorForCbm = arguments[2];
+ }
+ else if(!Validator(context).isNullOrUndefined(arguments[2])) //nullable
+ {
+ LogDebug("ErrorCallback type is mismatched.");
+ Throw(ConversionException);
+ }
+ }
+ if(callbackManager)
+ {
+ callbackManager->setOnSuccess(onSuccessForCbm);
+ callbackManager->setOnError(onErrorForCbm);
+ }
+
+ std::vector<Api::Messaging::IMessagePtr> msgs;
+ LogDebug("array length "<<JSGetArrayLength(context, objArg));
+ for (std::size_t i = 0; i < JSGetArrayLength(context, objArg); i++)
+ {
+ JSValueRef element = JSGetArrayElement(context, objArg, i);
+ JSObjectRef arg = JSValueToObject(context, element, NULL);
+ Api::Messaging::IMessagePtr msg = converter->toIMessage(arg);
+ msgs.push_back(msg);
+ }
+
+ event->msgArray = msgs;
+ event->setPrivateData(DPL::StaticPointerCast<WrtDeviceApis::Commons::IEventPrivateData >(callbackManager));
+ event->setForAsynchronousCall(&MessagingListener::getInstance());
+
+ event->setIndex(objectPriv->getIndex());
+ event->setType(objectPriv->getType());
+
+ Api::Messaging::ReqReceiverMessageSingleton::Instance().updateMessages(event);
+
+ return makePendingOperation(context, event);
+ }
+ Catch(WrtDeviceApis::Commons::ConversionException)
+ {
+ LogError(">>> TypeMismatchException");
+ return JSTizenExceptionFactory::postException(context, exception,
+ JSTizenException::TYPE_MISMATCH_ERROR, JSMESSAGING_EXCEPTION_MSG_TYPE_MISMATCH);
+ }
+ Catch(WrtDeviceApis::Commons::NullPointerException)
{
+ LogError(">>> TypeMismatchException");
return JSTizenExceptionFactory::postException(context, exception,
- JSTizenException::INVALID_VALUES_ERROR, JSMESSAGING_EXCEPTION_MSG_INVALID_ARGUMENT);
- }
- callbackManager->callOnError(JSTizenExceptionFactory::makeErrorObject(context,
- JSTizenException::INVALID_VALUES_ERROR, JSMESSAGING_EXCEPTION_MSG_INVALID_ARGUMENT));
- }Catch(WrtDeviceApis::Commons::PlatformException) {
- LogError(">>> UnknownException");
- return JSTizenExceptionFactory::postException(context, exception,
- JSTizenException::UNKNOWN_ERROR, JSMESSAGING_EXCEPTION_MSG_UNKNOWN);
+ JSTizenException::TYPE_MISMATCH_ERROR, JSMESSAGING_EXCEPTION_MSG_TYPE_MISMATCH);
+ }
+ Catch(WrtDeviceApis::Commons::InvalidArgumentException)
+ {
+ LogError(">>> InvalidValuesException");
+ return JSTizenExceptionFactory::postException(context, exception,
+ JSTizenException::INVALID_VALUES_ERROR, JSMESSAGING_EXCEPTION_MSG_INVALID_ARGUMENT);
+ }
+ Catch(WrtDeviceApis::Commons::PlatformException)
+ {
+ LogError(">>> UnknownException");
+ return JSTizenExceptionFactory::postException(context, exception,
+ JSTizenException::UNKNOWN_ERROR, JSMESSAGING_EXCEPTION_MSG_UNKNOWN);
+ }
+ return JSValueMakeNull(context);
}
- return JSValueMakeNull(context);
- }
-
JSValueRef JSMessagingStorage::findConversations(JSContextRef context, JSObjectRef object, JSObjectRef thisObject, size_t argumentCount,
- const JSValueRef arguments[], JSValueRef* exception)
+ const JSValueRef arguments[], JSValueRef* exception)
{
LogDebug("<<<");
- MessagingListener* priv = static_cast<MessagingListener*>
- (JSObjectGetPrivate(thisObject));
+ MessagingStoragePriv* priv = static_cast<MessagingStoragePriv*>(JSObjectGetPrivate(thisObject));
- if (!priv) {
- LogError(">>> Null pointer");
- return JSTizenExceptionFactory::postException(context, exception,
- JSTizenException::UNKNOWN_ERROR, JSMESSAGING_EXCEPTION_MSG_UNKNOWN);
+ if (!priv)
+ {
+ LogDebug("priv is NULL.");
+ return JSTizenExceptionFactory::postException(
+ context, exception, JSTizenException::TYPE_MISMATCH_ERROR, JSMESSAGING_EXCEPTION_MSG_TYPE_MISMATCH);
}
- JSContextRef globalContext = priv->getContext();
-
- if (argumentCount < 2) {
- LogError(">>> TypeMismatchException");
- return JSTizenExceptionFactory::postException(context, exception,
- JSTizenException::INVALID_VALUES_ERROR, JSMESSAGING_EXCEPTION_MSG_INVALID_ARGUMENT);
+ MessagingStoragePrivObjPtr objectPriv = priv->getObject();
+ if (!objectPriv)
+ {
+ LogDebug("objectPriv is NULL.");
+ return JSTizenExceptionFactory::postException(
+ context, exception, JSTizenException::TYPE_MISMATCH_ERROR, JSMESSAGING_EXCEPTION_MSG_TYPE_MISMATCH);
}
- JSCallbackManagerPtr callbackManager = JSCallbackManager::createObject(globalContext);
+ //check permission.
+ AceSecurityStatus status = MESSAGING_CHECK_ACCESS(
+ MessagingExportedNames[MESSAGING_FUNCTION_API_FIND_CONVERSATIONS]);
+ TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
- ConverterMessageFactory::ConverterType converter = ConverterMessageFactory::getConverter(context);
- Try {
+ WrtDeviceApis::CommonsJavaScript::JSCallbackManagerPtr callbackManager(NULL);
+ callbackManager = JSCallbackManager::createObject(priv->getContext());
- //check permission.
- AceSecurityStatus status = MESSAGING_CHECK_ACCESS(
- priv->getContext(),
- MessagingExportedNames[MESSAGING_FUNCTION_API_FIND_CONVERSATIONS]);
- TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
-
+ ConverterMessageFactory::ConverterType converter = ConverterMessageFactory::getConverter(context);
+
+ Try
+ {
Api::Messaging::EventQueryConversationsPtr event(new Api::Messaging::EventQueryConversations());
-
+
FilterConverterFactory::ConverterType filterConverter = FilterConverterFactory::getConverter(context);
- Api::Tizen::FilterPtr filter = filterConverter->toFilter(arguments[0]);
- event->setFilter(filter);
+ JSValueRef onSuccessForCbm = NULL, onErrorForCbm = NULL;
- callbackManager->setOnSuccess(converter->toFunction(arguments[1]));
-
- if (argumentCount > 2)
+ if((objectPriv->getType() < Api::Messaging::SMS) || (objectPriv->getType() > Api::Messaging::EMAIL))
{
- callbackManager->setOnError(converter->toFunctionOrNull(arguments[2]));
+ ThrowMsg(InvalidArgumentException, "Message type is not SMS or MMS or EMAIL.");
}
-
- // setup message filter
- if ((argumentCount >= 3) && !JSValueIsNull(context, arguments[0]) && !JSValueIsUndefined(context, arguments[0]))
+ else
{
- switch(argumentCount)
+ if(objectPriv->getType() == Api::Messaging::EMAIL)
{
- case 6:
+ if(objectPriv->getIndex() < 1)
{
- long offset = filterConverter->toLong(arguments[5]);
- LogDebug("offset:" << offset);
- event->setOffset(offset);
+ ThrowMsg(InvalidArgumentException, "serviceId is not defined.");
}
- case 5:
+ }
+ }
+
+ if(argumentCount >= 1) //optional AbstractFilter? filter
+ {
+ if(JSValueIsObject(context, arguments[0]))
+ {
+ Api::Tizen::FilterPtr filter = filterConverter->toFilter(arguments[0]);
+ event->setFilter(filter);
+ }
+ else // NOT nullable
+ {
+ LogDebug("Filter type is mismatched.");
+ Throw(ConversionException);
+ }
+ }
+ if(argumentCount >= 2) // successCallback
+ {
+ if(Validator(context).isCallback(arguments[1]))
+ {
+ onSuccessForCbm = arguments[1];
+ }
+ else // NOT nullable
+ {
+ LogDebug("SuccessCallback type is mismatched.");
+ Throw(ConversionException);
+ }
+ }
+ if(argumentCount >= 3) //optional ErrorCallback? errorCallback
+ {
+ if(Validator(context).isCallback(arguments[2]))
+ {
+ onErrorForCbm = arguments[2];
+ }
+ else if(!Validator(context).isNullOrUndefined(arguments[2])) //nullable
+ {
+ LogDebug("ErrorCallback type is mismatched.");
+ Throw(ConversionException);
+ }
+ }
+ if(argumentCount >= 4) //optional SortMode? sortMode
+ {
+ if(JSValueIsObject(context, arguments[3]))
+ {
+ Api::Tizen::SortModePtr sortMode = filterConverter->toSortMode(arguments[3]);
+ event->setSortMode(sortMode);
+ }
+ else if(!Validator(context).isNullOrUndefined(arguments[3])) //nullable
+ {
+ LogDebug("SortMode type is mismatched.");
+ Throw(ConversionException);
+ }
+ }
+ if(argumentCount >= 5) //optional unsigned long? limit JSValueIsUndefined(context, arguments[0]), JSValueIsNull(context, arguments[0])
+ {
+ if (!Validator(context).isNullOrUndefined(arguments[4]))
+ {
+ if (!JSValueIsNumber(context, arguments[4]))
{
- long limit = filterConverter->toLong(arguments[4]);
- LogDebug("limit:" << limit);
- event->setLimit(limit);
+ Throw(ConversionException);
}
- case 4:
+ long limit = filterConverter->toULong(arguments[4]);
+ event->setLimit(limit);
+ }
+ }
+ if(argumentCount >= 6) //optional unsigned long? offset JSValueIsUndefined(context, arguments[0]), JSValueIsNull(context, arguments[0])
+ {
+ if (!Validator(context).isNullOrUndefined(arguments[5]))
+ {
+ if (!JSValueIsNumber(context, arguments[5]))
{
- Api::Tizen::SortModePtr sortMode = filterConverter->toSortMode(arguments[3]);
- event->setSortMode(sortMode);
- break;
+ Throw(ConversionException);
}
+ long offset = filterConverter->toULong(arguments[5]);
+ event->setOffset(offset);
}
}
-
+ if(callbackManager)
+ {
+ callbackManager->setOnSuccess(onSuccessForCbm);
+ callbackManager->setOnError(onErrorForCbm);
+ }
+
event->setPrivateData(DPL::StaticPointerCast<WrtDeviceApis::Commons::IEventPrivateData >(callbackManager));
- event->setForAsynchronousCall(priv);
+ event->setForAsynchronousCall(&MessagingListener::getInstance());
+ event->setIndex(objectPriv->getIndex());
+ event->setType(objectPriv->getType());
Api::Messaging::ReqReceiverMessageSingleton::Instance().queryConversations(event);
- return JSValueMakeNull(context);
+ return makePendingOperation(context, event);
}
- Catch(WrtDeviceApis::Commons::ConversionException) {
+ Catch(WrtDeviceApis::Commons::ConversionException)
+ {
LogError(">>> TypeMismatchException");
return JSTizenExceptionFactory::postException(context, exception,
JSTizenException::TYPE_MISMATCH_ERROR, JSMESSAGING_EXCEPTION_MSG_TYPE_MISMATCH);
- }Catch(WrtDeviceApis::Commons::NullPointerException) {
+ }
+ Catch(WrtDeviceApis::Commons::NullPointerException)
+ {
LogError(">>> TypeMismatchException");
return JSTizenExceptionFactory::postException(context, exception,
JSTizenException::TYPE_MISMATCH_ERROR, JSMESSAGING_EXCEPTION_MSG_TYPE_MISMATCH);
- }Catch(WrtDeviceApis::Commons::InvalidArgumentException) {
+ }
+ Catch(WrtDeviceApis::Commons::InvalidArgumentException)
+ {
LogError(">>> InvalidValuesException");
- if(argumentCount < 3)
- {
- return JSTizenExceptionFactory::postException(context, exception,
- JSTizenException::INVALID_VALUES_ERROR, JSMESSAGING_EXCEPTION_MSG_INVALID_ARGUMENT);
- }
- callbackManager->callOnError(JSTizenExceptionFactory::makeErrorObject(context,
- JSTizenException::INVALID_VALUES_ERROR, JSMESSAGING_EXCEPTION_MSG_INVALID_ARGUMENT));
- }Catch(WrtDeviceApis::Commons::PlatformException) {
+ return JSTizenExceptionFactory::postException(context, exception,
+ JSTizenException::INVALID_VALUES_ERROR, JSMESSAGING_EXCEPTION_MSG_INVALID_ARGUMENT);
+ }
+ Catch(WrtDeviceApis::Commons::PlatformException)
+ {
LogError(">>> UnknownException");
return JSTizenExceptionFactory::postException(context, exception,
JSTizenException::UNKNOWN_ERROR, JSMESSAGING_EXCEPTION_MSG_UNKNOWN);
LogError(">>> JSValueMakeNull");
return JSValueMakeNull(context);
-
-
}
JSValueRef JSMessagingStorage::removeConversations(JSContextRef context, JSObjectRef object, JSObjectRef thisObject, size_t argumentCount,
- const JSValueRef arguments[], JSValueRef* exception)
+ const JSValueRef arguments[], JSValueRef* exception)
{
- LogDebug("enter");
+ LogDebug("<<<");
- MessagingListener* priv = static_cast<MessagingListener*>(JSObjectGetPrivate(thisObject));
+ MessagingStoragePriv* priv = static_cast<MessagingStoragePriv*>(JSObjectGetPrivate(thisObject));
- if (!priv) {
- LogError("Null pointer");
- return JSTizenExceptionFactory::postException(context, exception,
- JSTizenException::UNKNOWN_ERROR, JSMESSAGING_EXCEPTION_MSG_UNKNOWN);
+ if (!priv)
+ {
+ LogDebug("priv is NULL.");
+ return JSTizenExceptionFactory::postException(
+ context, exception, JSTizenException::TYPE_MISMATCH_ERROR, JSMESSAGING_EXCEPTION_MSG_TYPE_MISMATCH);
}
- JSContextRef globalContext = priv->getContext();
+ MessagingStoragePrivObjPtr objectPriv = priv->getObject();
- if (argumentCount < 1) {
- return JSTizenExceptionFactory::postException(context, exception,
- JSTizenException::INVALID_VALUES_ERROR, JSMESSAGING_EXCEPTION_MSG_INVALID_ARGUMENT);
+ if (!objectPriv)
+ {
+ LogDebug("objectPriv is NULL.");
+ return JSTizenExceptionFactory::postException(
+ context, exception, JSTizenException::TYPE_MISMATCH_ERROR, JSMESSAGING_EXCEPTION_MSG_TYPE_MISMATCH);
}
- WrtDeviceApis::CommonsJavaScript::JSCallbackManagerPtr callbackManager = JSCallbackManager::createObject(
- globalContext);
+ //check permission.
+ AceSecurityStatus status = MESSAGING_CHECK_ACCESS(
+ MessagingExportedNames[MESSAGING_FUNCTION_API_REMOVE_CONVERSATIONS]);
+ TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
+
+ WrtDeviceApis::CommonsJavaScript::JSCallbackManagerPtr callbackManager(NULL);
+ callbackManager = JSCallbackManager::createObject(priv->getContext());
ConverterMessageFactory::ConverterType converter = ConverterMessageFactory::getConverter(context);
+
+ Try
+ {
- Try {
+ Api::Messaging::EventDeleteConversationsPtr event(new Api::Messaging::EventDeleteConversations());
+
+ FilterConverterFactory::ConverterType filterConverter = FilterConverterFactory::getConverter(context);
- AceSecurityStatus status = MESSAGING_CHECK_ACCESS(
- priv->getContext(),
- MessagingExportedNames[MESSAGING_FUNCTION_API_REMOVE_CONVERSATIONS]);
- TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
+ JSValueRef onSuccessForCbm = NULL, onErrorForCbm = NULL;
- Api::Messaging::EventDeleteConversationsPtr event(new Api::Messaging::EventDeleteConversations());
+ std::vector<Api::Messaging::IConversationPtr> deleteConversationArray;
- if (argumentCount > 1) {
- callbackManager->setOnSuccess(converter->toFunctionOrNull(arguments[1]));
+ if((objectPriv->getType() < Api::Messaging::SMS) || (objectPriv->getType() > Api::Messaging::EMAIL))
+ {
+ ThrowMsg(InvalidArgumentException, "Message type is not SMS or MMS or EMAIL.");
+ }
+ else
+ {
+ if(objectPriv->getType() == Api::Messaging::EMAIL)
+ {
+ if(objectPriv->getIndex() < 1)
+ {
+ ThrowMsg(InvalidArgumentException, "serviceId is not defined.");
+ }
+ }
}
- if (argumentCount > 2) {
- callbackManager->setOnError(converter->toFunctionOrNull(arguments[2]));
+ if(argumentCount >= 1) // Message object
+ {
+ if(JSValueIsObject(context, arguments[0]))
+ {
+ deleteConversationArray = converter->toVectorOfConversation(arguments[0]);
+ }
+ else
+ {
+ LogDebug("Invalid argument exception");
+ Throw(ConversionException);
+ }
+ }
+ if(argumentCount >= 2) // successCallback
+ {
+ if(Validator(context).isCallback(arguments[1]))
+ {
+ onSuccessForCbm = arguments[1];
+ }
+ else if(!Validator(context).isNullOrUndefined(arguments[1])) //nullable
+ {
+ LogDebug("SuccessCallback type is mismatched.");
+ Throw(ConversionException);
+ }
+ }
+ if(argumentCount >= 3) //optional ErrorCallback? errorCallback
+ {
+ if(Validator(context).isCallback(arguments[2]))
+ {
+ onErrorForCbm = arguments[2];
+ }
+ else if(!Validator(context).isNullOrUndefined(arguments[2])) //nullable
+ {
+ LogDebug("ErrorCallback type is mismatched.");
+ Throw(ConversionException);
+ }
+ }
+ if(callbackManager)
+ {
+ callbackManager->setOnSuccess(onSuccessForCbm);
+ callbackManager->setOnError(onErrorForCbm);
}
- //check permission.
- std::vector<Api::Messaging::IConversationPtr> deleteConversationArray = converter->toVectorOfConversation(arguments[0]);
event->setConversations(deleteConversationArray);
event->setFilterUsing(false);
event->setPrivateData(DPL::StaticPointerCast<WrtDeviceApis::Commons::IEventPrivateData >(callbackManager));
- event->setForAsynchronousCall(priv);
+ event->setForAsynchronousCall(&MessagingListener::getInstance());
+ event->setIndex(objectPriv->getIndex());
+ event->setType(objectPriv->getType());
Api::Messaging::ReqReceiverMessageSingleton::Instance().deleteConversations(event);
+ return makePendingOperation(context, event);
}
- Catch(WrtDeviceApis::Commons::ConversionException) {
+ Catch(WrtDeviceApis::Commons::ConversionException)
+ {
LogError(">>> TypeMismatchException");
return JSTizenExceptionFactory::postException(context, exception,
JSTizenException::TYPE_MISMATCH_ERROR, JSMESSAGING_EXCEPTION_MSG_TYPE_MISMATCH);
- }Catch(WrtDeviceApis::Commons::NullPointerException) {
+ }
+ Catch(WrtDeviceApis::Commons::NullPointerException)
+ {
LogError(">>> TypeMismatchException");
return JSTizenExceptionFactory::postException(context, exception,
JSTizenException::TYPE_MISMATCH_ERROR, JSMESSAGING_EXCEPTION_MSG_TYPE_MISMATCH);
- }Catch(WrtDeviceApis::Commons::InvalidArgumentException) {
+ }
+ Catch(WrtDeviceApis::Commons::InvalidArgumentException)
+ {
LogError(">>> InvalidValuesException");
- if(argumentCount < 3)
- {
- return JSTizenExceptionFactory::postException(context, exception,
- JSTizenException::INVALID_VALUES_ERROR, JSMESSAGING_EXCEPTION_MSG_INVALID_ARGUMENT);
- }
- callbackManager->callOnError(JSTizenExceptionFactory::makeErrorObject(context,
- JSTizenException::INVALID_VALUES_ERROR, JSMESSAGING_EXCEPTION_MSG_INVALID_ARGUMENT));
- }Catch(WrtDeviceApis::Commons::PlatformException) {
+ return JSTizenExceptionFactory::postException(context, exception,
+ JSTizenException::INVALID_VALUES_ERROR, JSMESSAGING_EXCEPTION_MSG_INVALID_ARGUMENT);
+ }
+ Catch(WrtDeviceApis::Commons::PlatformException)
+ {
LogError(">>> UnknownException");
return JSTizenExceptionFactory::postException(context, exception,
JSTizenException::UNKNOWN_ERROR, JSMESSAGING_EXCEPTION_MSG_UNKNOWN);
}
JSValueRef JSMessagingStorage::findFolders(JSContextRef context, JSObjectRef object, JSObjectRef thisObject, size_t argumentCount,
- const JSValueRef arguments[], JSValueRef* exception)
+ const JSValueRef arguments[], JSValueRef* exception)
{
+ LogDebug("<<<");
- LogDebug("enter");
-
- MessagingListener* priv = static_cast<MessagingListener*>(JSObjectGetPrivate(thisObject));
+ MessagingStoragePriv* priv = static_cast<MessagingStoragePriv*>(JSObjectGetPrivate(thisObject));
- if (!priv) {
- LogError("Null pointer");
- return JSTizenExceptionFactory::postException(context, exception,
- JSTizenException::UNKNOWN_ERROR, JSMESSAGING_EXCEPTION_MSG_UNKNOWN);
+ if (!priv)
+ {
+ LogDebug("priv is NULL.");
+ return JSTizenExceptionFactory::postException(
+ context, exception, JSTizenException::TYPE_MISMATCH_ERROR, JSMESSAGING_EXCEPTION_MSG_TYPE_MISMATCH);
}
- JSContextRef globalContext = priv->getContext();
+ MessagingStoragePrivObjPtr objectPriv = priv->getObject();
- if (argumentCount < 2) {
- return JSTizenExceptionFactory::postException(context, exception,
- JSTizenException::INVALID_VALUES_ERROR, JSMESSAGING_EXCEPTION_MSG_INVALID_ARGUMENT);
+ if (!objectPriv)
+ {
+ LogDebug("objectPriv is NULL.");
+ return JSTizenExceptionFactory::postException(
+ context, exception, JSTizenException::TYPE_MISMATCH_ERROR, JSMESSAGING_EXCEPTION_MSG_TYPE_MISMATCH);
}
- WrtDeviceApis::CommonsJavaScript::JSCallbackManagerPtr callbackManager = JSCallbackManager::createObject(globalContext);
- ConverterMessageFactory::ConverterType converter = ConverterMessageFactory::getConverter(context);
+ //check permission.
+ AceSecurityStatus status = MESSAGING_CHECK_ACCESS(
+ MessagingExportedNames[MESSAGING_FUNCTION_API_FIND_FOLDERS]);
+ TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
+
+ WrtDeviceApis::CommonsJavaScript::JSCallbackManagerPtr callbackManager(NULL);
+ callbackManager = JSCallbackManager::createObject(priv->getContext());
- // TODO : need to re-implement for supporting filter
- Try {
- //check permission.
- AceSecurityStatus status = MESSAGING_CHECK_ACCESS(
- priv->getContext(),
- MessagingExportedNames[MESSAGING_FUNCTION_API_FIND_FOLDERS]);
- TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
-
+ ConverterMessageFactory::ConverterType converter = ConverterMessageFactory::getConverter(context);
+
+ Try
+ {
Api::Messaging::EventQueryFoldersPtr event(new Api::Messaging::EventQueryFolders());
-
- // setup message filter
+
FilterConverterFactory::ConverterType filterConverter = FilterConverterFactory::getConverter(context);
- Api::Tizen::FilterPtr filter = filterConverter->toFilter(arguments[0]);
- event->setFilter(filter);
+ JSValueRef onSuccessForCbm = NULL, onErrorForCbm = NULL;
- callbackManager->setOnSuccess(converter->toFunction(arguments[1]));
-
- if(argumentCount > 2)
+ if((objectPriv->getType() < Api::Messaging::SMS) || (objectPriv->getType() > Api::Messaging::EMAIL))
{
- callbackManager->setOnError(converter->toFunctionOrNull(arguments[2]));
+ ThrowMsg(InvalidArgumentException, "Message type is not SMS or MMS or EMAIL.");
+ }
+ else
+ {
+ if(objectPriv->getType() == Api::Messaging::EMAIL)
+ {
+ if(objectPriv->getIndex() < 1)
+ {
+ ThrowMsg(InvalidArgumentException, "serviceId is not defined.");
+ }
+ }
+ }
+
+ if(argumentCount >= 1) //optional AbstractFilter? filter
+ {
+ if(JSValueIsObject(context, arguments[0]))
+ {
+ Api::Tizen::FilterPtr filter = filterConverter->toFilter(arguments[0]);
+ event->setFilter(filter);
+ }
+ else // NOT nullable
+ {
+ LogDebug("Filter type is mismatched.");
+ Throw(ConversionException);
+ }
+ }
+ if(argumentCount >= 2) // successCallback
+ {
+ if(Validator(context).isCallback(arguments[1]))
+ {
+ onSuccessForCbm = arguments[1];
+ }
+ else // NOT nullable
+ {
+ LogDebug("SuccessCallback type is mismatched.");
+ Throw(ConversionException);
+ }
+ }
+ if(argumentCount >= 3) //optional ErrorCallback? errorCallback
+ {
+ if(Validator(context).isCallback(arguments[2]))
+ {
+ onErrorForCbm = arguments[2];
+ }
+ else if(!Validator(context).isNullOrUndefined(arguments[2])) //nullable
+ {
+ LogDebug("ErrorCallback type is mismatched.");
+ Throw(ConversionException);
+ }
+ }
+ if(callbackManager)
+ {
+ callbackManager->setOnSuccess(onSuccessForCbm);
+ callbackManager->setOnError(onErrorForCbm);
}
event->setPrivateData(DPL::StaticPointerCast<WrtDeviceApis::Commons::IEventPrivateData >(callbackManager));
- event->setForAsynchronousCall(priv);
+ event->setForAsynchronousCall(&MessagingListener::getInstance());
+ event->setIndex(objectPriv->getIndex());
+ event->setType(objectPriv->getType());
Api::Messaging::ReqReceiverMessageSingleton::Instance().queryFolders(event);
- return JSValueMakeNull(context);
+ return makePendingOperation(context, event);
- }
- Catch(WrtDeviceApis::Commons::ConversionException) {
- LogError(">>> TypeMismatchException");
- return JSTizenExceptionFactory::postException(context, exception,
- JSTizenException::TYPE_MISMATCH_ERROR, JSMESSAGING_EXCEPTION_MSG_TYPE_MISMATCH);
- }Catch(WrtDeviceApis::Commons::NullPointerException) {
- LogError(">>> TypeMismatchException");
- return JSTizenExceptionFactory::postException(context, exception,
- JSTizenException::TYPE_MISMATCH_ERROR, JSMESSAGING_EXCEPTION_MSG_TYPE_MISMATCH);
- }Catch(WrtDeviceApis::Commons::InvalidArgumentException) {
- LogError(">>> InvalidValuesException");
- if(argumentCount < 3)
+ }
+ Catch(WrtDeviceApis::Commons::ConversionException)
{
+ LogError(">>> TypeMismatchException");
return JSTizenExceptionFactory::postException(context, exception,
- JSTizenException::INVALID_VALUES_ERROR, JSMESSAGING_EXCEPTION_MSG_INVALID_ARGUMENT);
- }
- callbackManager->callOnError(JSTizenExceptionFactory::makeErrorObject(context,
- JSTizenException::INVALID_VALUES_ERROR, JSMESSAGING_EXCEPTION_MSG_INVALID_ARGUMENT));
- }Catch(WrtDeviceApis::Commons::PlatformException) {
- LogError(">>> UnknownException");
- return JSTizenExceptionFactory::postException(context, exception,
- JSTizenException::UNKNOWN_ERROR, JSMESSAGING_EXCEPTION_MSG_UNKNOWN);
- }
+ JSTizenException::TYPE_MISMATCH_ERROR, JSMESSAGING_EXCEPTION_MSG_TYPE_MISMATCH);
+ }
+ Catch(WrtDeviceApis::Commons::NullPointerException)
+ {
+ LogError(">>> TypeMismatchException");
+ return JSTizenExceptionFactory::postException(context, exception,
+ JSTizenException::TYPE_MISMATCH_ERROR, JSMESSAGING_EXCEPTION_MSG_TYPE_MISMATCH);
+ }
+ Catch(WrtDeviceApis::Commons::InvalidArgumentException)
+ {
+ LogError(">>> InvalidValuesException");
+ return JSTizenExceptionFactory::postException(context, exception,
+ JSTizenException::INVALID_VALUES_ERROR, JSMESSAGING_EXCEPTION_MSG_INVALID_ARGUMENT);
+ }
+ Catch(WrtDeviceApis::Commons::PlatformException)
+ {
+ LogError(">>> UnknownException");
+ return JSTizenExceptionFactory::postException(context, exception,
+ JSTizenException::UNKNOWN_ERROR, JSMESSAGING_EXCEPTION_MSG_UNKNOWN);
+ }
- return JSValueMakeNull(context);
- }
+ return JSValueMakeNull(context);
+ }
JSValueRef JSMessagingStorage::addMessagesChangeListener(JSContextRef context, JSObjectRef object, JSObjectRef thisObject, size_t argumentCount,
- const JSValueRef arguments[], JSValueRef* exception) {
+ const JSValueRef arguments[], JSValueRef* exception)
+ {
- LogInfo("<<<");
- LogDebug("arumentConunt:" << argumentCount);
+ LogDebug("<<<");
- MessagingListener* priv = static_cast<MessagingListener*>
- (JSObjectGetPrivate(thisObject));
-
- if (!priv) {
- LogError("Null pointer");
- return JSTizenExceptionFactory::postException(context, exception,
- JSTizenException::UNKNOWN_ERROR, JSMESSAGING_EXCEPTION_MSG_UNKNOWN);
- }
+ MessagingStoragePriv* priv = static_cast<MessagingStoragePriv*>(JSObjectGetPrivate(thisObject));
- if (argumentCount < 1 ||
- JSValueIsUndefined(context, arguments[0]) ||
- JSValueIsNull(context, arguments[0]))
+ if (!priv)
{
- LogError("bad argument");
- return JSTizenExceptionFactory::postException(context, exception,
- JSTizenException::INVALID_VALUES_ERROR, JSMESSAGING_EXCEPTION_MSG_INVALID_ARGUMENT);
+ LogDebug("priv is NULL.");
+ return JSTizenExceptionFactory::postException(
+ context, exception, JSTizenException::TYPE_MISMATCH_ERROR, JSMESSAGING_EXCEPTION_MSG_TYPE_MISMATCH);
}
- MessagingListener* listener =
- static_cast<MessagingListener*>(JSObjectGetPrivate(thisObject));
- if (!listener) {
- LogError("no private object");
- return JSValueMakeUndefined(context);
- }
+ MessagingStoragePrivObjPtr objectPriv = priv->getObject();
- Try
- {
+ if (!objectPriv)
+ {
+ LogDebug("objectPriv is NULL.");
+ return JSTizenExceptionFactory::postException(
+ context, exception, JSTizenException::TYPE_MISMATCH_ERROR, JSMESSAGING_EXCEPTION_MSG_TYPE_MISMATCH);
+ }
//check permission.
AceSecurityStatus status = MESSAGING_CHECK_ACCESS(
- priv->getContext(),
- MessagingExportedNames[MESSAGING_FUNCTION_API_ADD_MESSAGES_CHANGE_LISTNER]);
-
+ MessagingExportedNames[MESSAGING_FUNCTION_API_ADD_MESSAGES_CHANGE_LISTNER]);
TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
- ConverterMessageFactory::ConverterType converter =
- ConverterMessageFactory::getConverter(context);
- JSContextRef l_globalContext = converter->toJSGlobalContext(thisObject);
-
- WrtDeviceApis::CommonsJavaScript::JSCallbackManagerPtr callbackManager =
- WrtDeviceApis::CommonsJavaScript::JSCallbackManager::createObject(l_globalContext,
- NULL,
- NULL);
+ WrtDeviceApis::CommonsJavaScript::JSCallbackManagerPtr callbackManager(NULL);
+
+ WrtDeviceApis::CommonsJavaScript::JSCallbackManagerPtr messagesUpdatedCbm(NULL);
+ WrtDeviceApis::CommonsJavaScript::JSCallbackManagerPtr messagesRemovedCbm(NULL);
+
+ callbackManager = JSCallbackManager::createObject(priv->getContext());
- OnMessagesChanged result = converter->toMessageMultifunctions(arguments[0]);
- int funtionIndex = result.functionIndex;
+ ConverterMessageFactory::ConverterType converter = ConverterMessageFactory::getConverter(context);
- callbackManager->setOnSuccess(result.messagesAdded);
- WrtDeviceApis::CommonsJavaScript::JSCallbackManagerPtr messagesUpdatedCbm = JSCallbackManager::createObject(listener->getContext(), result.messagesUpdated, NULL);
- WrtDeviceApis::CommonsJavaScript::JSCallbackManagerPtr messagesRemovedCbm = JSCallbackManager::createObject(listener->getContext(), result.messagesRemoved, NULL);
+ Try
+ {
+ FilterConverterFactory::ConverterType filterConverter = FilterConverterFactory::getConverter(context);
+ JSValueRef onSuccessForCbm = NULL;
- EventOnMessagingStorageChangesPrivateDataPtr privData(
- new EventOnMessagingStorageChangesPrivateData(callbackManager, messagesUpdatedCbm, messagesRemovedCbm, funtionIndex));
+ OnMessagesChanged functionResult;
+ int funtionIndex = -1;
+
+ if((objectPriv->getType() < Api::Messaging::SMS) || (objectPriv->getType() > Api::Messaging::EMAIL))
+ {
+ ThrowMsg(InvalidArgumentException, "Message type is not SMS or MMS or EMAIL.");
+ }
+ else
+ {
+ if(objectPriv->getType() == Api::Messaging::EMAIL)
+ {
+ if(objectPriv->getIndex() < 1)
+ {
+ ThrowMsg(InvalidArgumentException, "serviceId is not defined.");
+ }
+ }
+ }
- //filter
- if ((argumentCount == 2) && !JSValueIsNull(context, arguments[1]) && !JSValueIsUndefined(context, arguments[1]))
- {
- FilterConverterFactory::ConverterType filterConverter = FilterConverterFactory::getConverter(context);
- privData->setFilter(filterConverter->toFilter(arguments[1]));
- }
+ if(argumentCount >= 1) // successCallback
+ {
+ if(!Validator(context).isNullOrUndefined(arguments[0]))
+ {
+ functionResult = converter->toMessageMultifunctions(arguments[0]);
+ funtionIndex = functionResult.functionIndex;
+
+ onSuccessForCbm = functionResult.messagesAdded;
+ messagesUpdatedCbm = JSCallbackManager::createObject(priv->getContext(), functionResult.messagesUpdated, NULL);
+ messagesRemovedCbm = JSCallbackManager::createObject(priv->getContext(), functionResult.messagesRemoved, NULL);
+ }
+ else // NOT nullable
+ {
+ LogDebug("SuccessCallback type is mismatched.");
+ Throw(ConversionException);
+ }
+ }
- listener->registerMessageReceivedEmitter(privData);
+ if(funtionIndex < 0)
+ {
+ LogError("funtionIndex is not valid");
+ Throw(ConversionException);
+ }
- // add to map and return index
- return JSValueMakeNumber(context,
- listener->addIncomingMsgCallback(callbackManager, funtionIndex));
+ EventOnMessagingStorageChangesPrivateDataPtr privData(
+ new EventOnMessagingStorageChangesPrivateData(callbackManager, messagesUpdatedCbm, messagesRemovedCbm, funtionIndex));
+
+ if(argumentCount >= 2) //optional AbstractFilter? filter
+ {
+ if(JSValueIsObject(context, arguments[1]))
+ {
+ Api::Tizen::FilterPtr filter = filterConverter->toFilter(arguments[1]);
+ privData->setFilter(filter);
+ }
+ else // NOT nullable
+ {
+ LogDebug("Filter type is mismatched.");
+ Throw(ConversionException);
+ }
+ }
+ if(callbackManager)
+ {
+ callbackManager->setOnSuccess(onSuccessForCbm);
+ }
- }
- Catch(WrtDeviceApis::Commons::ConversionException) {
- LogError("Error on conversion");
- return JSTizenExceptionFactory::postException(context, exception,
- JSTizenException::TYPE_MISMATCH_ERROR, JSMESSAGING_EXCEPTION_MSG_TYPE_MISMATCH);
- }
- Catch(WrtDeviceApis::Commons::InvalidArgumentException) {
- LogError("Invalid argument exception");
- return JSTizenExceptionFactory::postException(context, exception,
- JSTizenException::INVALID_VALUES_ERROR, JSMESSAGING_EXCEPTION_MSG_INVALID_ARGUMENT);
- }
- Catch(WrtDeviceApis::Commons::UnsupportedException) {
- LogError("Unsupported exception");
- return JSTizenExceptionFactory::postException(context, exception,
- JSTizenException::NOT_SUPPORTED_ERROR, JSMESSAGING_EXCEPTION_MSG_NOT_SUPPORTED); // unsupported type
- }
- Catch(WrtDeviceApis::Commons::AlreadyInUseException) {
- LogError("Already in use exception");
- }
- Catch(WrtDeviceApis::Commons::PlatformException) {
- LogError("not registered for incoming message notifications");
- }
-
- return JSValueMakeUndefined(context);
- }
+ privData->setIndex(objectPriv->getIndex());
+ privData->setType(objectPriv->getType());
- JSValueRef JSMessagingStorage::addConversationsChangeListener(JSContextRef context, JSObjectRef object, JSObjectRef thisObject, size_t argumentCount,
- const JSValueRef arguments[], JSValueRef* exception) {
+ MessagingListener::getInstance().registerMessageReceivedEmitter(privData);
- LogInfo("<<<");
- LogDebug("arumentConunt:" << argumentCount);
+ // add to map and return index
+ return JSValueMakeNumber(context,
+ MessagingListener::getInstance().addIncomingMsgCallback(callbackManager, funtionIndex));
- MessagingListener* priv = static_cast<MessagingListener*>
- (JSObjectGetPrivate(thisObject));
-
- if (!priv) {
- LogError("Null pointer");
+ }
+ Catch(WrtDeviceApis::Commons::ConversionException)
+ {
+ LogError("Error on conversion");
+ return JSTizenExceptionFactory::postException(context, exception,
+ JSTizenException::TYPE_MISMATCH_ERROR, JSMESSAGING_EXCEPTION_MSG_TYPE_MISMATCH);
+ }
+ Catch(WrtDeviceApis::Commons::InvalidArgumentException) {
+ LogError("Invalid argument exception");
return JSTizenExceptionFactory::postException(context, exception,
- JSTizenException::UNKNOWN_ERROR, JSMESSAGING_EXCEPTION_MSG_UNKNOWN);
+ JSTizenException::INVALID_VALUES_ERROR, JSMESSAGING_EXCEPTION_MSG_INVALID_ARGUMENT);
}
-
- if (argumentCount < 1 ||
- JSValueIsUndefined(context, arguments[0]) ||
- JSValueIsNull(context, arguments[0]))
+ Catch(WrtDeviceApis::Commons::UnsupportedException)
{
- LogError("bad argument");
+ LogError("Unsupported exception");
return JSTizenExceptionFactory::postException(context, exception,
- JSTizenException::INVALID_VALUES_ERROR, JSMESSAGING_EXCEPTION_MSG_INVALID_ARGUMENT);
+ JSTizenException::NOT_SUPPORTED_ERROR, JSMESSAGING_EXCEPTION_MSG_NOT_SUPPORTED); // unsupported type
}
+ Catch(WrtDeviceApis::Commons::AlreadyInUseException)
+ {
+ LogError("Already in use exception");
+ }
+ Catch(WrtDeviceApis::Commons::PlatformException)
+ {
+ LogError("not registered for incoming message notifications");
+ }
+
+ return JSValueMakeUndefined(context);
+ }
+
+ JSValueRef JSMessagingStorage::addConversationsChangeListener(JSContextRef context, JSObjectRef object, JSObjectRef thisObject, size_t argumentCount,
+ const JSValueRef arguments[], JSValueRef* exception)
+ {
+ LogDebug("<<<");
+
+ MessagingStoragePriv* priv = static_cast<MessagingStoragePriv*>(JSObjectGetPrivate(thisObject));
- MessagingListener* listener =
- static_cast<MessagingListener*>(JSObjectGetPrivate(thisObject));
- if (!listener) {
- LogError("no private object");
- return JSValueMakeUndefined(context);
+ if (!priv)
+ {
+ LogDebug("priv is NULL.");
+ return JSTizenExceptionFactory::postException(
+ context, exception, JSTizenException::TYPE_MISMATCH_ERROR, JSMESSAGING_EXCEPTION_MSG_TYPE_MISMATCH);
}
- Try
- {
+ MessagingStoragePrivObjPtr objectPriv = priv->getObject();
+
+ if (!objectPriv)
+ {
+ LogDebug("objectPriv is NULL.");
+ return JSTizenExceptionFactory::postException(
+ context, exception, JSTizenException::TYPE_MISMATCH_ERROR, JSMESSAGING_EXCEPTION_MSG_TYPE_MISMATCH);
+ }
//check permission.
AceSecurityStatus status = MESSAGING_CHECK_ACCESS(
- priv->getContext(),
- MessagingExportedNames[MESSAGING_FUNCTION_API_ADD_CONVERSATIONS_CHANGE_LISTNER]);
-
+ MessagingExportedNames[MESSAGING_FUNCTION_API_ADD_CONVERSATIONS_CHANGE_LISTNER]);
TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
- ConverterMessageFactory::ConverterType converter =
- ConverterMessageFactory::getConverter(context);
- JSContextRef l_globalContext = converter->toJSGlobalContext(thisObject);
+ WrtDeviceApis::CommonsJavaScript::JSCallbackManagerPtr callbackManager(NULL);
+
+ WrtDeviceApis::CommonsJavaScript::JSCallbackManagerPtr messagesUpdatedCbm(NULL);
+ WrtDeviceApis::CommonsJavaScript::JSCallbackManagerPtr messagesRemovedCbm(NULL);
+
+ callbackManager = JSCallbackManager::createObject(priv->getContext());
- WrtDeviceApis::CommonsJavaScript::JSCallbackManagerPtr callbackManager =
- WrtDeviceApis::CommonsJavaScript::JSCallbackManager::createObject(l_globalContext,
- NULL,
- NULL);
+ ConverterMessageFactory::ConverterType converter = ConverterMessageFactory::getConverter(context);
- OnMessagesChanged result = converter->toMessageMultifunctions(arguments[0]);
- int funtionIndex = result.functionIndex;
+ Try
+ {
+ FilterConverterFactory::ConverterType filterConverter = FilterConverterFactory::getConverter(context);
- callbackManager->setOnSuccess(result.messagesAdded);
- WrtDeviceApis::CommonsJavaScript::JSCallbackManagerPtr messagesUpdatedCbm = JSCallbackManager::createObject(listener->getContext(), result.messagesUpdated, NULL);
- WrtDeviceApis::CommonsJavaScript::JSCallbackManagerPtr messagesRemovedCbm = JSCallbackManager::createObject(listener->getContext(), result.messagesRemoved, NULL);
+ JSValueRef onSuccessForCbm = NULL;
+ OnMessagesChanged functionResult;
+ int funtionIndex = -1;
+
+ if((objectPriv->getType() < Api::Messaging::SMS) || (objectPriv->getType() > Api::Messaging::EMAIL))
+ {
+ ThrowMsg(InvalidArgumentException, "Message type is not SMS or MMS or EMAIL.");
+ }
+ else
+ {
+ if(objectPriv->getType() == Api::Messaging::EMAIL)
+ {
+ if(objectPriv->getIndex() < 1)
+ {
+ ThrowMsg(InvalidArgumentException, "serviceId is not defined.");
+ }
+ }
+ }
- EventOnMessagingStorageChangesPrivateDataPtr privData(
- new EventOnMessagingStorageChangesPrivateData(callbackManager, messagesUpdatedCbm, messagesRemovedCbm, funtionIndex));
+ if(argumentCount >= 1) // successCallback
+ {
+ if(!Validator(context).isNullOrUndefined(arguments[0]))
+ {
+ functionResult = converter->toMessageMultifunctions(arguments[0]);
+ funtionIndex = functionResult.functionIndex;
+
+ onSuccessForCbm = functionResult.messagesAdded;
+ messagesUpdatedCbm = JSCallbackManager::createObject(priv->getContext(), functionResult.messagesUpdated, NULL);
+ messagesRemovedCbm = JSCallbackManager::createObject(priv->getContext(), functionResult.messagesRemoved, NULL);
+ }
+ else // NOT nullable
+ {
+ LogDebug("SuccessCallback type is mismatched.");
+ Throw(ConversionException);
+ }
+ }
- //filter
- if ((argumentCount == 2) && !JSValueIsNull(context, arguments[1]) && !JSValueIsUndefined(context, arguments[1]))
- {
- FilterConverterFactory::ConverterType filterConverter = FilterConverterFactory::getConverter(context);
- privData->setFilter(filterConverter->toFilter(arguments[1]));
- }
+ if(funtionIndex < 0)
+ {
+ LogError("funtionIndex is not valid");
+ Throw(ConversionException);
+ }
- listener->registerMessageReceivedEmitter(privData);
+ EventOnMessagingStorageChangesPrivateDataPtr privData(
+ new EventOnMessagingStorageChangesPrivateData(callbackManager, messagesUpdatedCbm, messagesRemovedCbm, funtionIndex));
+
+ if(argumentCount >= 2) //optional AbstractFilter? filter
+ {
+ if(JSValueIsObject(context, arguments[1]))
+ {
+ Api::Tizen::FilterPtr filter = filterConverter->toFilter(arguments[1]);
+ privData->setFilter(filter);
+ }
+ else // NOT nullable
+ {
+ LogDebug("Filter type is mismatched.");
+ Throw(ConversionException);
+ }
+ }
+ if(callbackManager)
+ {
+ callbackManager->setOnSuccess(onSuccessForCbm);
+ }
- // add to map and return index
- return JSValueMakeNumber(context,
- listener->addIncomingMsgCallback(callbackManager, funtionIndex));
+ privData->setIndex(objectPriv->getIndex());
+ privData->setType(objectPriv->getType());
+
+ MessagingListener::getInstance().registerMessageReceivedEmitter(privData);
- }
- Catch(WrtDeviceApis::Commons::ConversionException) {
- LogError("Error on conversion");
- return JSTizenExceptionFactory::postException(context, exception,
- JSTizenException::TYPE_MISMATCH_ERROR, JSMESSAGING_EXCEPTION_MSG_TYPE_MISMATCH);
- }
- Catch(WrtDeviceApis::Commons::InvalidArgumentException) {
- LogError("Invalid argument exception");
- return JSTizenExceptionFactory::postException(context, exception,
+ // add to map and return index
+ return JSValueMakeNumber(context,
+ MessagingListener::getInstance().addIncomingMsgCallback(callbackManager, funtionIndex));
+ }
+ Catch(WrtDeviceApis::Commons::ConversionException)
+ {
+ LogError("Error on conversion");
+ return JSTizenExceptionFactory::postException(context, exception,
+ JSTizenException::TYPE_MISMATCH_ERROR, JSMESSAGING_EXCEPTION_MSG_TYPE_MISMATCH);
+ }
+ Catch(WrtDeviceApis::Commons::InvalidArgumentException)
+ {
+ LogError("Invalid argument exception");
+ return JSTizenExceptionFactory::postException(context, exception,
JSTizenException::INVALID_VALUES_ERROR, JSMESSAGING_EXCEPTION_MSG_INVALID_ARGUMENT);
- }
- Catch(WrtDeviceApis::Commons::UnsupportedException) {
- LogError("Unsupported exception");
- return JSTizenExceptionFactory::postException(context, exception,
- JSTizenException::NOT_SUPPORTED_ERROR, JSMESSAGING_EXCEPTION_MSG_NOT_SUPPORTED); // unsupported type
- }
- Catch(WrtDeviceApis::Commons::AlreadyInUseException) {
- LogError("Already in use exception");
- }
- Catch(WrtDeviceApis::Commons::PlatformException) {
- LogError("not registered for incoming message notifications");
- }
-
- return JSValueMakeUndefined(context);
- }
+ }
+ Catch(WrtDeviceApis::Commons::UnsupportedException)
+ {
+ LogError("Unsupported exception");
+ return JSTizenExceptionFactory::postException(context, exception,
+ JSTizenException::NOT_SUPPORTED_ERROR, JSMESSAGING_EXCEPTION_MSG_NOT_SUPPORTED); // unsupported type
+ }
+ Catch(WrtDeviceApis::Commons::AlreadyInUseException)
+ {
+ LogError("Already in use exception");
+ }
+ Catch(WrtDeviceApis::Commons::PlatformException)
+ {
+ LogError("not registered for incoming message notifications");
+ }
+
+ return JSValueMakeUndefined(context);
+ }
JSValueRef JSMessagingStorage::addFoldersChangeListener(JSContextRef context, JSObjectRef object, JSObjectRef thisObject, size_t argumentCount,
- const JSValueRef arguments[], JSValueRef* exception) {
+ const JSValueRef arguments[], JSValueRef* exception)
+ {
- LogInfo("<<<");
- LogDebug("arumentConunt:" << argumentCount);
+ LogDebug("<<<");
- MessagingListener* priv = static_cast<MessagingListener*>
- (JSObjectGetPrivate(thisObject));
-
- if (!priv) {
- LogError("Null pointer");
- return JSTizenExceptionFactory::postException(context, exception,
- JSTizenException::UNKNOWN_ERROR, JSMESSAGING_EXCEPTION_MSG_UNKNOWN);
- }
+ MessagingStoragePriv* priv = static_cast<MessagingStoragePriv*>(JSObjectGetPrivate(thisObject));
- if (argumentCount < 1 ||
- JSValueIsUndefined(context, arguments[0]) ||
- JSValueIsNull(context, arguments[0]))
+ if (!priv)
{
- LogError("bad argument");
- return JSTizenExceptionFactory::postException(context, exception,
- JSTizenException::INVALID_VALUES_ERROR, JSMESSAGING_EXCEPTION_MSG_INVALID_ARGUMENT);
+ LogDebug("priv is NULL.");
+ return JSTizenExceptionFactory::postException(
+ context, exception, JSTizenException::TYPE_MISMATCH_ERROR, JSMESSAGING_EXCEPTION_MSG_TYPE_MISMATCH);
}
- MessagingListener* listener =
- static_cast<MessagingListener*>(JSObjectGetPrivate(thisObject));
- if (!listener) {
- LogError("no private object");
- return JSValueMakeUndefined(context);
- }
+ MessagingStoragePrivObjPtr objectPriv = priv->getObject();
- Try
- {
+ if (!objectPriv)
+ {
+ LogDebug("objectPriv is NULL.");
+ return JSTizenExceptionFactory::postException(
+ context, exception, JSTizenException::TYPE_MISMATCH_ERROR, JSMESSAGING_EXCEPTION_MSG_TYPE_MISMATCH);
+ }
//check permission.
AceSecurityStatus status = MESSAGING_CHECK_ACCESS(
- priv->getContext(),
- MessagingExportedNames[MESSAGING_FUNCTION_API_ADD_FOLDERS_CHANGE_LISTNER]);
-
+ MessagingExportedNames[MESSAGING_FUNCTION_API_ADD_FOLDERS_CHANGE_LISTNER]);
TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
- ConverterMessageFactory::ConverterType converter =
- ConverterMessageFactory::getConverter(context);
- JSContextRef l_globalContext = converter->toJSGlobalContext(thisObject);
+ WrtDeviceApis::CommonsJavaScript::JSCallbackManagerPtr callbackManager(NULL);
+
+ WrtDeviceApis::CommonsJavaScript::JSCallbackManagerPtr messagesUpdatedCbm(NULL);
+ WrtDeviceApis::CommonsJavaScript::JSCallbackManagerPtr messagesRemovedCbm(NULL);
+
+ callbackManager = JSCallbackManager::createObject(priv->getContext());
+
+ ConverterMessageFactory::ConverterType converter = ConverterMessageFactory::getConverter(context);
+
+ Try
+ {
- WrtDeviceApis::CommonsJavaScript::JSCallbackManagerPtr callbackManager =
- WrtDeviceApis::CommonsJavaScript::JSCallbackManager::createObject(l_globalContext,
- NULL,
- NULL);
+ FilterConverterFactory::ConverterType filterConverter = FilterConverterFactory::getConverter(context);
- OnMessagesChanged result = converter->toMessageMultifunctions(arguments[0]);
- int funtionIndex = result.functionIndex;
+ JSValueRef onSuccessForCbm = NULL;
- callbackManager->setOnSuccess(result.messagesAdded);
- WrtDeviceApis::CommonsJavaScript::JSCallbackManagerPtr messagesUpdatedCbm = JSCallbackManager::createObject(listener->getContext(), result.messagesUpdated, NULL);
- WrtDeviceApis::CommonsJavaScript::JSCallbackManagerPtr messagesRemovedCbm = JSCallbackManager::createObject(listener->getContext(), result.messagesRemoved, NULL);
+ OnMessagesChanged functionResult;
+ int funtionIndex = -1;
+
+ if((objectPriv->getType() < Api::Messaging::SMS) || (objectPriv->getType() > Api::Messaging::EMAIL))
+ {
+ ThrowMsg(InvalidArgumentException, "Message type is not SMS or MMS or EMAIL.");
+ }
+ else
+ {
+ if(objectPriv->getType() == Api::Messaging::EMAIL)
+ {
+ if(objectPriv->getIndex() < 1)
+ {
+ ThrowMsg(InvalidArgumentException, "serviceId is not defined.");
+ }
+ }
+ }
+
+ if(argumentCount >= 1) // successCallback
+ {
+ if(!Validator(context).isNullOrUndefined(arguments[0]))
+ {
+ functionResult = converter->toMessageMultifunctions(arguments[0]);
+ funtionIndex = functionResult.functionIndex;
+
+ onSuccessForCbm = functionResult.messagesAdded;
+ messagesUpdatedCbm = JSCallbackManager::createObject(priv->getContext(), functionResult.messagesUpdated, NULL);
+ messagesRemovedCbm = JSCallbackManager::createObject(priv->getContext(), functionResult.messagesRemoved, NULL);
+ }
+ else // NOT nullable
+ {
+ LogDebug("SuccessCallback type is mismatched.");
+ Throw(ConversionException);
+ }
+ }
+ if(funtionIndex < 0)
+ {
+ LogError("funtionIndex is not valid");
+ Throw(ConversionException);
+ }
- EventOnMessagingStorageChangesPrivateDataPtr privData(
- new EventOnMessagingStorageChangesPrivateData(callbackManager, messagesUpdatedCbm, messagesRemovedCbm, funtionIndex));
+ EventOnMessagingStorageChangesPrivateDataPtr privData(
+ new EventOnMessagingStorageChangesPrivateData(callbackManager, messagesUpdatedCbm, messagesRemovedCbm, funtionIndex));
+
+ if(argumentCount >= 2) //optional AbstractFilter? filter
+ {
+ if(JSValueIsObject(context, arguments[1]))
+ {
+ Api::Tizen::FilterPtr filter = filterConverter->toFilter(arguments[1]);
+ privData->setFilter(filter);
+ }
+ else // NOT nullable
+ {
+ LogDebug("Filter type is mismatched.");
+ Throw(ConversionException);
+ }
+ }
+ if(callbackManager)
+ {
+ callbackManager->setOnSuccess(onSuccessForCbm);
+ }
- //filter
- if ((argumentCount == 2) && !JSValueIsNull(context, arguments[1]) && !JSValueIsUndefined(context, arguments[1]))
- {
- FilterConverterFactory::ConverterType filterConverter = FilterConverterFactory::getConverter(context);
- privData->setFilter(filterConverter->toFilter(arguments[1]));
- }
+ privData->setIndex(objectPriv->getIndex());
+ privData->setType(objectPriv->getType());
- listener->registerMessageReceivedEmitter(privData);
+ MessagingListener::getInstance().registerMessageReceivedEmitter(privData);
- // add to map and return index
- return JSValueMakeNumber(context,
- listener->addIncomingMsgCallback(callbackManager, funtionIndex));
+ // add to map and return index
+ return JSValueMakeNumber(context,
+ MessagingListener::getInstance().addIncomingMsgCallback(callbackManager, funtionIndex));
- }
- Catch(WrtDeviceApis::Commons::ConversionException) {
- LogError("Error on conversion");
- return JSTizenExceptionFactory::postException(context, exception,
- JSTizenException::TYPE_MISMATCH_ERROR, JSMESSAGING_EXCEPTION_MSG_TYPE_MISMATCH);
- }
- Catch(WrtDeviceApis::Commons::InvalidArgumentException) {
- LogError("Invalid argument exception");
- return JSTizenExceptionFactory::postException(context, exception,
+ }
+ Catch(WrtDeviceApis::Commons::ConversionException)
+ {
+ LogError("Error on conversion");
+ return JSTizenExceptionFactory::postException(context, exception,
+ JSTizenException::TYPE_MISMATCH_ERROR, JSMESSAGING_EXCEPTION_MSG_TYPE_MISMATCH);
+ }
+ Catch(WrtDeviceApis::Commons::InvalidArgumentException)
+ {
+ LogError("Invalid argument exception");
+ return JSTizenExceptionFactory::postException(context, exception,
JSTizenException::INVALID_VALUES_ERROR, JSMESSAGING_EXCEPTION_MSG_INVALID_ARGUMENT);
- }
- Catch(WrtDeviceApis::Commons::UnsupportedException) {
- LogError("Unsupported exception");
- return JSTizenExceptionFactory::postException(context, exception,
- JSTizenException::NOT_SUPPORTED_ERROR, JSMESSAGING_EXCEPTION_MSG_NOT_SUPPORTED); // unsupported type
- }
- Catch(WrtDeviceApis::Commons::AlreadyInUseException) {
- LogError("Already in use exception");
- }
- Catch(WrtDeviceApis::Commons::PlatformException) {
- LogError("not registered for incoming message notifications");
- }
-
- return JSValueMakeUndefined(context);
- }
-
- JSValueRef JSMessagingStorage::removeChangeListener(JSContextRef context,
- JSObjectRef function,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef* exception)
- {
- LogInfo("entered");
-
- MessagingListener* priv = static_cast<MessagingListener*>
- (JSObjectGetPrivate(thisObject));
-
- if (!priv) {
- LogError("Null pointer");
- return JSTizenExceptionFactory::postException(context, exception,
- JSTizenException::UNKNOWN_ERROR, JSMESSAGING_EXCEPTION_MSG_UNKNOWN);
- }
-
- if (argumentCount < 1) {
- LogError("wrong argument count");
- return JSTizenExceptionFactory::postException(context, exception,
- JSTizenException::INVALID_VALUES_ERROR, JSMESSAGING_EXCEPTION_MSG_INVALID_ARGUMENT);
- }
-
- //check permission.
- AceSecurityStatus status = MESSAGING_CHECK_ACCESS(
- priv->getContext(),
- MessagingExportedNames[MESSAGING_FUNCTION_API_REMOVE_CHANGE_LISTENER]);
-
- TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
-
-
- MessagingListener* listener =
- static_cast<MessagingListener*>(JSObjectGetPrivate(thisObject));
- if (!listener) {
- LogError("no private object");
- return JSValueMakeUndefined(context);
- }
-
- WrtDeviceApis::CommonsJavaScript::Converter converter(context);
- Try {
- double handler = converter.toDouble(arguments[0]);
- listener->removeIncomingMsgCallback(handler);
- }
- Catch(WrtDeviceApis::Commons::ConversionException) {
- LogError("conversion error");
- return JSTizenExceptionFactory::postException(context, exception,
- JSTizenException::TYPE_MISMATCH_ERROR, JSMESSAGING_EXCEPTION_MSG_TYPE_MISMATCH);
- }
-
- return JSValueMakeUndefined(context);
- }
+ }
+ Catch(WrtDeviceApis::Commons::UnsupportedException)
+ {
+ LogError("Unsupported exception");
+ return JSTizenExceptionFactory::postException(context, exception,
+ JSTizenException::NOT_SUPPORTED_ERROR, JSMESSAGING_EXCEPTION_MSG_NOT_SUPPORTED); // unsupported type
+ }
+ Catch(WrtDeviceApis::Commons::AlreadyInUseException)
+ {
+ LogError("Already in use exception");
+ }
+ Catch(WrtDeviceApis::Commons::PlatformException)
+ {
+ LogError("not registered for incoming message notifications");
+ }
+ return JSValueMakeUndefined(context);
+ }
+
+ JSValueRef JSMessagingStorage::removeChangeListener(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount,
+ const JSValueRef arguments[], JSValueRef* exception)
+ {
+ LogDebug("<<<");
+
+ MessagingStoragePriv* priv = static_cast<MessagingStoragePriv*>(JSObjectGetPrivate(thisObject));
+
+ long handler = -1;
+
+ if (!priv)
+ {
+ LogDebug("priv is NULL.");
+ return JSTizenExceptionFactory::postException(
+ context, exception, JSTizenException::TYPE_MISMATCH_ERROR, JSMESSAGING_EXCEPTION_MSG_TYPE_MISMATCH);
+ }
+
+ MessagingStoragePrivObjPtr objectPriv = priv->getObject();
+
+ if (!objectPriv)
+ {
+ LogDebug("objectPriv is NULL.");
+ return JSTizenExceptionFactory::postException(
+ context, exception, JSTizenException::TYPE_MISMATCH_ERROR, JSMESSAGING_EXCEPTION_MSG_TYPE_MISMATCH);
+ }
+
+ //check permission.
+ AceSecurityStatus status = MESSAGING_CHECK_ACCESS(
+ MessagingExportedNames[MESSAGING_FUNCTION_API_REMOVE_CHANGE_LISTENER]);
+ TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
+
+ WrtDeviceApis::CommonsJavaScript::JSCallbackManagerPtr callbackManager(NULL);
+ callbackManager = JSCallbackManager::createObject(priv->getContext());
+
+ ConverterMessageFactory::ConverterType converter = ConverterMessageFactory::getConverter(context);
+
+ Try
+ {
+ FilterConverterFactory::ConverterType filterConverter = FilterConverterFactory::getConverter(context);
+
+ if(argumentCount >= 1) //optional unsigned long? limit JSValueIsUndefined(context, arguments[0]), JSValueIsNull(context, arguments[0])
+ {
+ if (!Validator(context).isNullOrUndefined(arguments[0]))
+ {
+ if (!JSValueIsNumber(context, arguments[0]))
+ {
+ Throw(ConversionException);
+ }
+ handler = filterConverter->toLong(arguments[0]);
+ }
+ else
+ {
+ Throw(ConversionException);
+ }
+ }
+ if(handler < 0)
+ {
+ LogError("handler is not valid");
+ Throw(ConversionException);
+ }
+ MessagingListener::getInstance().removeIncomingMsgCallback(handler, objectPriv->getType(), objectPriv->getIndex());
+ }
+ Catch(WrtDeviceApis::Commons::ConversionException)
+ {
+ LogError("conversion error");
+ return JSTizenExceptionFactory::postException(context, exception,
+ JSTizenException::TYPE_MISMATCH_ERROR, JSMESSAGING_EXCEPTION_MSG_TYPE_MISMATCH);
+ }
+ Catch(WrtDeviceApis::Commons::InvalidArgumentException)
+ {
+ LogError(">>> InvalidValuesException");
+ return JSTizenExceptionFactory::postException(context, exception,
+ JSTizenException::INVALID_VALUES_ERROR, JSMESSAGING_EXCEPTION_MSG_INVALID_ARGUMENT);
+ }
+ return JSValueMakeUndefined(context);
+ }
}
}