-OnMessagesChanged ConverterMessage::toMessageMultifunctions(JSValueRef argument)
-{
- OnMessagesChanged result;
- Validator validator(m_context);
- JSObjectRef objectCallbacks = toJSObjectRef(argument);
- std::string callbackName = toString(argument);
- int index = 0;
-
- LogDebug("Enter\n");
-
- for (index = 0; index < MESSAGING_MULTI_FUNTION_MAX; index++)
- {
- ScopedJSStringRef propName(toJSStringRef(m_callbackNames[index].addedFunction));
-
- if (JSObjectHasProperty(m_context, objectCallbacks, propName.get()))
- {
- LogDebug("Callback name :" << m_callbackNames[index].addedFunction << " "
- << m_callbackNames[index].updatedFunction << " " << m_callbackNames[index].removedFunction);
-
- result.messagesAdded = JSUtils::getJSPropertyOrUndefined(m_context, objectCallbacks, m_callbackNames[index].addedFunction);
- result.messagesUpdated = JSUtils::getJSPropertyOrUndefined(m_context, objectCallbacks, m_callbackNames[index].updatedFunction);
- result.messagesRemoved = JSUtils::getJSPropertyOrUndefined(m_context, objectCallbacks, m_callbackNames[index].removedFunction);
- break;
- }
-
- }
-
- if(result.messagesAdded == NULL || result.messagesUpdated == NULL || result.messagesRemoved == NULL)
- {
- LogError("OnMessagesChanged is not set");
- Throw(WrtDeviceApis::Commons::ConversionException);
- }
-
- result.functionIndex = index;
-
- if ((!validator.isNullOrUndefined(result.messagesAdded) && !validator.isCallback(result.messagesAdded)) ||
- (!validator.isNullOrUndefined(result.messagesUpdated) && !validator.isCallback(result.messagesUpdated)) ||
- (!validator.isNullOrUndefined(result.messagesRemoved) && !validator.isCallback(result.messagesRemoved)))
- {
- LogError("java script call back set error");
- Throw(WrtDeviceApis::Commons::InvalidArgumentException);
- }
+OnMessagesChanged ConverterMessage::toMessageMultifunctions(JSValueRef argument, int multiFuntionType)
+{
+ LoggerD("Enter");
+
+ LoggerD("multiFuntionType : " << multiFuntionType);
+
+ OnMessagesChanged result;
+ Validator validator(m_context);
+ JSObjectRef objectCallbacks = toJSObjectRef(argument);
+
+ ScopedJSStringRef propNameAdded(toJSStringRef(m_callbackNames[multiFuntionType].addedFunction));
+ ScopedJSStringRef propNameUpdated(toJSStringRef(m_callbackNames[multiFuntionType].updatedFunction));
+ ScopedJSStringRef propNameRemoved(toJSStringRef(m_callbackNames[multiFuntionType].removedFunction));
+
+ if(JSObjectHasProperty(m_context, objectCallbacks, propNameAdded.get()))
+ {
+ LoggerD("added exist");
+ result.messagesAdded = JSUtils::getJSPropertyOrUndefined(m_context, objectCallbacks, m_callbackNames[multiFuntionType].addedFunction);
+ if (validator.isNullOrUndefined(result.messagesAdded))
+ result.messagesAdded = NULL;
+ else if (!validator.isCallback(result.messagesAdded)) {
+ LoggerD("is not Callback");
+ ThrowMsg(ConversionException, "1nd argument's onsuccess attribute is not a 'function'");
+ }
+ }
+ if(JSObjectHasProperty(m_context, objectCallbacks, propNameUpdated.get()))
+ {
+ LoggerD("updated exist");
+ result.messagesUpdated = JSUtils::getJSPropertyOrUndefined(m_context, objectCallbacks, m_callbackNames[multiFuntionType].updatedFunction);
+ if (validator.isNullOrUndefined(result.messagesUpdated))
+ result.messagesUpdated = NULL;
+ else if (!validator.isCallback(result.messagesUpdated)) {
+ LoggerD("is not Callback");
+ ThrowMsg(ConversionException, "2nd argument's onsuccess attribute is not a 'function'");
+ }
+ }
+ if(JSObjectHasProperty(m_context, objectCallbacks, propNameRemoved.get()))
+ {
+ LoggerD("removed exist");
+ result.messagesRemoved = JSUtils::getJSPropertyOrUndefined(m_context, objectCallbacks, m_callbackNames[multiFuntionType].removedFunction);
+ if (validator.isNullOrUndefined(result.messagesRemoved))
+ result.messagesRemoved = NULL;
+ else if (!validator.isCallback(result.messagesRemoved)) {
+ LoggerD("is not Callback");
+ ThrowMsg(ConversionException, "3nd argument's onsuccess attribute is not a 'function'");
+ }
+ }
+
+ if(result.messagesAdded != NULL || result.messagesUpdated != NULL || result.messagesRemoved != NULL)
+ {
+ result.functionIndex = multiFuntionType;
+ }