// limitations under the License.
//
-#include <CommonsJavaScript/Converter.h>
-#include <CommonsJavaScript/Validator.h>
-#include <CommonsJavaScript/JSUtils.h>
-#include <CommonsJavaScript/JSCallbackManager.h>
-#include <CommonsJavaScript/Utils.h>
#include <SecurityExceptions.h>
-#include <JSTizenExceptionFactory.h>
-#include <JSTizenException.h>
-#include "NotificationFactory.h"
-#include "JSStatusNotification.h"
-#include "NotificationConverter.h"
-//#include "plugin_config.h"
+#include <JSUtil.h>
+#include <JSWebAPIError.h>
+#include <ArgumentValidator.h>
+#include <GlobalContextManager.h>
+#include <MultiCallbackUserData.h>
+#include <PlatformException.h>
+#include <JSWebAPIError.h>
+#include <FilesystemUtils.h>
+#include "plugin_config.h"
+
+#include "JSStatusNotification.h"
+#include "JSNotificationDetailInfo.h"
+using namespace WrtDeviceApis::Commons;
using namespace DeviceAPI::Common;
namespace DeviceAPI {
namespace Notification {
-
-JSClassDefinition JSStatusNotification::m_classInfo =
-{
- 0,
- kJSClassAttributeNone,
- "StatusNotification",
- NULL,
- m_properties,
- NULL,
- initialize,
- finalize,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- constructor,
- hasInstance,
- NULL
+#define NOTIFICATION_TYPE_VALUE "STATUS"
+
+JSClassDefinition JSStatusNotification::m_classInfo = {
+ 0,
+ kJSClassAttributeNone,
+ "StatusNotification",
+ NULL, //ParentClass
+ m_property, //StaticValues
+ NULL, //StaticFunctions
+ initialize, //Initialize
+ finalize, //Finalize
+ NULL, //HasProperty,
+ NULL, //GetProperty,
+ NULL, //SetProperty,
+ NULL, //DeleteProperty,
+ NULL, //GetPropertyNames,
+ NULL, //CallAsFunction,
+ NULL, //CallAsConstructor,
+ NULL, //HasInstance,
+ NULL //ConvertToType
};
-JSStaticValue JSStatusNotification::m_properties[] =
+JSStaticValue JSStatusNotification::m_property[] =
{
- {NOTIFICATION_ID, JSStatusNotification::getProperty, NULL, kJSPropertyAttributeReadOnly },
- {NOTIFICATION_TYPE, JSStatusNotification::getProperty, NULL, kJSPropertyAttributeReadOnly },
- {NOTIFICATION_POSTED_TIME, JSStatusNotification::getProperty, NULL, kJSPropertyAttributeReadOnly },
- {NOTIFICATION_TITLE, JSStatusNotification::getProperty, JSStatusNotification::setProperty, kJSPropertyAttributeNone },
- {NOTIFICATION_CONTENT, JSStatusNotification::getProperty, JSStatusNotification::setProperty, kJSPropertyAttributeNone },
-
- {NOTIFICATION_STATUS_TYPE, JSStatusNotification::getProperty, NULL, kJSPropertyAttributeReadOnly },
- {NOTIFICATION_ICON_PATH, JSStatusNotification::getProperty, JSStatusNotification::setProperty, kJSPropertyAttributeNone },
- {NOTIFICATION_SOUND_PATH, JSStatusNotification::getProperty, JSStatusNotification::setProperty, kJSPropertyAttributeNone },
- {NOTIFICATION_VIBRATION, JSStatusNotification::getProperty, JSStatusNotification::setProperty, kJSPropertyAttributeNone },
-#ifdef APPLICATION_API_BACKWARD_COMPATIBILITY
- {NOTIFICATION_SEVICE, JSStatusNotification::getProperty, JSStatusNotification::setProperty, kJSPropertyAttributeNone },
-#endif
- {NOTIFICATION_APP_CONTROL, JSStatusNotification::getProperty, JSStatusNotification::setProperty, kJSPropertyAttributeNone },
- {NOTIFICATION_APP_ID, JSStatusNotification::getProperty, JSStatusNotification::setProperty, kJSPropertyAttributeNone },
- {NOTIFICATION_PROGRESS_VALUE, JSStatusNotification::getProperty, JSStatusNotification::setProperty, kJSPropertyAttributeNone },
- {NOTIFICATION_LINES, JSStatusNotification::getProperty, JSStatusNotification::setProperty, kJSPropertyAttributeNone },
- {NOTIFICATION_BACKGROUND_IMAGE_PATH, JSStatusNotification::getProperty, JSStatusNotification::setProperty, kJSPropertyAttributeNone },
- {NOTIFICATION_NUMBER, JSStatusNotification::getProperty, JSStatusNotification::setProperty, kJSPropertyAttributeNone },
- {NOTIFICATION_THUMBNAILS, JSStatusNotification::getProperty, JSStatusNotification::setProperty, kJSPropertyAttributeNone },
- {NOTIFICATION_SUB_ICON_PATH, JSStatusNotification::getProperty, JSStatusNotification::setProperty, kJSPropertyAttributeNone },
+ {STATUS_NOTIFICATION_PROGRESS_TYPE, JSStatusNotification::getProperty, JSStatusNotification::setProperty, kJSPropertyAttributeNone },
+ {STATUS_NOTIFICATION_PROGRESS_VALUE, JSStatusNotification::getProperty, JSStatusNotification::setProperty, kJSPropertyAttributeNone },
{0, 0, 0, 0}
};
-const JSClassRef JSStatusNotification::getClassRef()
-{
- if (!m_jsClassRef) {
- m_jsClassRef = JSClassCreate(&m_classInfo);
- }
- return m_jsClassRef;
-}
-
-const JSClassDefinition* JSStatusNotification::getClassInfo()
-{
- return &m_classInfo;
-}
-
-JSClassRef JSStatusNotification::m_jsClassRef = JSClassCreate(JSStatusNotification::getClassInfo());
-
-void JSStatusNotification::initialize(JSContextRef context, JSObjectRef object)
-{
- LogDebug("JSStatusNotification::initialize, nothing ");
-}
-
-void JSStatusNotification::finalize(JSObjectRef object)
-{
- JSStatusNotificationPriv* priv = static_cast<JSStatusNotificationPriv*>(JSObjectGetPrivate(object));
-
- LogDebug("JSStatusNotification::Finalize");
-
- if (priv != NULL)
- {
- JSObjectSetPrivate(object, NULL);
- delete priv;
- }
-}
-
-bool JSStatusNotification::hasInstance(JSContextRef context, JSObjectRef constructor,
- JSValueRef possibleInstance, JSValueRef* exception)
-{
- return JSValueIsObjectOfClass(context, possibleInstance, getClassRef());
-}
-
bool JSStatusNotification::setProperty(JSContextRef context,
JSObjectRef object,
JSStringRef propertyName,
JSValueRef value,
JSValueRef* exception)
{
- LogDebug("OK");
-
- JSStatusNotificationPriv* priv = static_cast<JSStatusNotificationPriv*>(JSObjectGetPrivate(object));
- //NotificationConverter converter(context);
- NotificationConverterFactory::ConverterType converter =
- NotificationConverterFactory::getConverter(context);
- std::string property = converter->toString(propertyName);
- LogDebug("Property = " << property);
- try {
-
- if (priv == NULL)
- {
- ThrowMsg(WrtDeviceApis::Commons::ConversionException,"Private Object is null");
- }
-
- INotificationPtr notification(priv->getObject());
+ StatusNotification *priv = static_cast<StatusNotification*>(JSObjectGetPrivate(object));
+ LogDebug("statusNotification :" << priv);
+ if (!priv) {
+ throw TypeMismatchException("StatusNotification's private object is NULL.");
+ }
- if (notification == NULL)
- {
- ThrowMsg(WrtDeviceApis::Commons::ConversionException,"Private Object is null");
- }
-
- if (property == NOTIFICATION_TITLE)
- {
- std::string title = converter->toString(value);
- notification->setTitle(title);
- return true;
- }
- else if (property == NOTIFICATION_CONTENT)
- {
- std::string content = converter->toString(value);
- notification->setContent(content);
- return true;
- }
+ try {
+ std::string property;
+ size_t jsSize = JSStringGetMaximumUTF8CStringSize(propertyName);
+ if (jsSize > 0) {
+ jsSize = jsSize + 1;
+ char* buffer = new char[jsSize];
+ size_t written = JSStringGetUTF8CString(propertyName, buffer, jsSize);
+ if (written > jsSize) {
+ throw InvalidValuesException("Conversion could not be fully performed.");
+ }
+ property = buffer;
+ delete[] buffer;
+ }
+
+ LogInfo("property =" << property);
+
+ if ( property == STATUS_NOTIFICATION_PROGRESS_TYPE)
+ {
+ std::string strProgressType = JSUtil::JSValueToString(context, value);
+ LogInfo("Progress Type : " << strProgressType);
+
+ NotificationProgressType progType = NOTI_PROGRESS_TYPE_NONE;
+ if( strProgressType.compare(TIZEN_NOTIFICATION_PROGRESS_TYPE_PERCENTAGE) == 0)
+ progType = NOTI_PROGRESS_TYPE_PERCENTAGE;
+ else if( strProgressType.compare(TIZEN_NOTIFICATION_PROGRESS_TYPE_BYTE) == 0)
+ progType = NOTI_PROGRESS_TYPE_SIZE;
+ else
+ throw InvalidValuesException("Invalid Progress Type.");
+
+ priv->setProgressType(progType); //set progress Type
- else if (property == NOTIFICATION_ICON_PATH)
- {
- if (JSValueIsUndefined(context, value) || JSValueIsNull(context, value))
- {
- return true;
- }
-
- std::string iconPath = converter->toString(value);
- DeviceAPI::Filesystem::IPathPtr path = DeviceAPI::Filesystem::Utils::fromVirtualPath(context, iconPath);
- iconPath = path->getFullPath();
-
- notification->setIconPath(iconPath);
return true;
- }
- else if (property == NOTIFICATION_SOUND_PATH)
- {
- if (JSValueIsUndefined(context, value) || JSValueIsNull(context, value))
- {
- return true;
- }
-
- std::string soundPath = converter->toString(value);
- DeviceAPI::Filesystem::IPathPtr path = DeviceAPI::Filesystem::Utils::fromVirtualPath(context, soundPath);
- soundPath = path->getFullPath();
-
- notification->setSoundPath(soundPath);
- return true;
- }
- else if (property == NOTIFICATION_VIBRATION)
- {
- bool virbration = converter->toBool(value);
- notification->setDefaultVibration(virbration);
- return true;
- }
- else if (property == NOTIFICATION_APP_CONTROL
-#ifdef APPLICATION_API_BACKWARD_COMPATIBILITY
- || property == NOTIFICATION_SEVICE
-#endif
- )
- {
- DeviceAPI::Application::ApplicationControlPtr appControl = converter->toIApplicationPtr(value);
- notification->setApplicationControl(appControl);
- return true;
- }
- else if (property == NOTIFICATION_APP_ID)
- {
- std::string appId = converter->toString(value);
- notification->setApplicationId(appId);
- }
- else if (property == NOTIFICATION_PROGRESS_VALUE)
- {
- unsigned short progressValue = (unsigned short)converter->toULong(value);
- NotificationProgressType progressType = notification->getProgressType();
-
- LogDebug(" progress type = " << progressType << "progressValue = " << progressValue);
-
- if ( NOTI_PROGRESS_TYPE_SIZE == progressType)
- {
- notification->setProgressValue(progressValue);
- }
- else if ( NOTI_PROGRESS_TYPE_PERCENTAGE == progressType)
- {
- //check arrang.
- if ( progressValue > 100 )
- {
- ThrowMsg(WrtDeviceApis::Commons::InvalidArgumentException, "progress value error");
- }
-
- double percentage = (double)progressValue/(double)100;
- LogDebug(" Percentage Value = " << percentage);
- notification->setProgressValue(percentage);
- }
-
- return true;
- }
-
- else if (property == NOTIFICATION_LINES)
- {
- NotificationLineArrayPtr lines = converter->toNotificationLineArray(value);
- notification->setLines(lines);
- }
- else if (property == NOTIFICATION_BACKGROUND_IMAGE_PATH )
- {
- if (JSValueIsUndefined(context, value) || JSValueIsNull(context, value))
- {
- return true;
- }
-
- std::string backgroundImagePath = converter->toString(value);
- DeviceAPI::Filesystem::IPathPtr path = DeviceAPI::Filesystem::Utils::fromVirtualPath(context, backgroundImagePath);
- backgroundImagePath = path->getFullPath();
- notification->setBackground(backgroundImagePath);
- return true;
- }
- else if (property == NOTIFICATION_NUMBER)
- {
- unsigned int number = converter->toULong(value);
- LogDebug("Number is = " << number);
- notification->setNumber(number);
- }
- else if (property == NOTIFICATION_THUMBNAILS)
- {
-
- StringArrayPtr thumbnailsPtr = converter->toStringArray(value);
- notification->setThumbnails(thumbnailsPtr);
-
- std::vector<std::string>::iterator it;
-
- int idx = 0;
- for (it = thumbnailsPtr->begin(); it < thumbnailsPtr->end(); ++it)
- {
- std::string str = *it;
- LogDebug(" thumbs : " << str);
- DeviceAPI::Filesystem::IPathPtr path = DeviceAPI::Filesystem::Utils::fromVirtualPath(context, str);
- str = path->getFullPath();
-
- LogDebug(" thumbs : " << str);
- notification->setThumbnail(str, idx);
- idx ++;
- }
-
- }
- else if (property == NOTIFICATION_SUB_ICON_PATH )
- {
- if (JSValueIsUndefined(context, value) || JSValueIsNull(context, value))
- {
- return true;
- }
-
- std::string subIconPath = converter->toString(value);
- DeviceAPI::Filesystem::IPathPtr path = DeviceAPI::Filesystem::Utils::fromVirtualPath(context, subIconPath);
- subIconPath = path->getFullPath();
- notification->setSubIconPath(subIconPath);
- return true;
- }
- else
- {
- ThrowMsg(WrtDeviceApis::Commons::ConversionException,"No attribute");
- }
-
- }
- Catch (WrtDeviceApis::Commons::ConversionException)
- {
- LogWarning("Exception: "<<_rethrown_exception.GetMessage());
- return JSTizenExceptionFactory::postException(context, exception,
- JSTizenException::TYPE_MISMATCH_ERROR, _rethrown_exception.GetMessage());
-
- }
- Catch (WrtDeviceApis::Commons::InvalidArgumentException)
- {
- LogWarning("Exception: "<<_rethrown_exception.GetMessage());
- return JSTizenExceptionFactory::postException(context, exception,
- JSTizenException::INVALID_VALUES_ERROR, _rethrown_exception.GetMessage());
- }
- Catch(WrtDeviceApis::Commons::UnsupportedException)
- {
- LogWarning("Exception: "<<_rethrown_exception.GetMessage());
- return JSTizenExceptionFactory::postException(context, exception,
- JSTizenException::NOT_SUPPORTED_ERROR, _rethrown_exception.GetMessage());
- }
- Catch (WrtDeviceApis::Commons::Exception)
- {
- LogWarning("Exception: "<<_rethrown_exception.GetMessage());
- return JSTizenExceptionFactory::postException(context, exception,
- JSTizenException::UNKNOWN_ERROR, _rethrown_exception.GetMessage());
- }
+ }
+ else if ( property == STATUS_NOTIFICATION_PROGRESS_VALUE)
+ {
+ // progressValue
+ unsigned long progressVal = JSUtil::JSValueToULong(context, value);
+ LogInfo("Progress Value : " << progressVal);
+
+ if ( priv->getProgressType() == NOTI_PROGRESS_TYPE_PERCENTAGE)
+ {
+ if ( 100 < progressVal )
+ throw InvalidValuesException("The percentage progress value must be between 0 and 100");
+ priv->setProgressValue((double)progressVal/(double)100);
+ }
+ else
+ {
+ priv->setProgressValue((double)progressVal);
+ }
+
+ return true;
+ }
+
+ }
+ catch ( const BasePlatformException& err)
+ {
+ LogWarning(" notification convertion is failed. " << err.getName().c_str() << ":" << err.getMessage().c_str());
+ }
+
- return false;
+ return false;
}
JSValueRef JSStatusNotification::getProperty(JSContextRef context,
JSStringRef propertyName,
JSValueRef* exception)
{
- LogDebug("OK");
-
- JSStatusNotificationPriv* priv = static_cast<JSStatusNotificationPriv*>(JSObjectGetPrivate(object));
- //NotificationConverter converter(context);
- NotificationConverterFactory::ConverterType converter =
- NotificationConverterFactory::getConverter(context);
- std::string property = converter->toString(propertyName);
- LogDebug("property = " << property);
+ StatusNotification *priv = static_cast<StatusNotification*>(JSObjectGetPrivate(object));
+ LogDebug("statusNotification :" << priv);
+ if (!priv) {
+ throw TypeMismatchException("StatusNotification's private object is NULL.");
+ }
try {
-
- if (priv == NULL)
- {
- ThrowMsg(WrtDeviceApis::Commons::ConversionException,"Private Object is null");
- }
-
- INotificationPtr notification(priv->getObject());
-
- if (notification == NULL)
- {
- ThrowMsg(WrtDeviceApis::Commons::ConversionException,"Private Object is null");
- }
-
- if (property == NOTIFICATION_ID)
- {
- LogDebug(" ID : " << notification->getID());
- int id = notification->getID();
- if (id >= 0)
+
+ std::string property;
+ size_t jsSize = JSStringGetMaximumUTF8CStringSize(propertyName);
+ if (jsSize > 0) {
+ jsSize = jsSize + 1;
+ char* buffer = new char[jsSize];
+ size_t written = JSStringGetUTF8CString(propertyName, buffer, jsSize);
+ if (written > jsSize) {
+ throw InvalidValuesException("Conversion could not be fully performed.");
+ }
+ property = buffer;
+ delete[] buffer;
+ }
+
+ LogInfo("property =" << property);
+ if ( property == STATUS_NOTIFICATION_PROGRESS_TYPE)
+ {
+ std::string type;
+ if ( NOTI_PROGRESS_TYPE_PERCENTAGE == priv->getProgressType())
{
- std::stringstream stream;
- stream << id;
-
- return converter->toJSValueRef(stream.str());
+ type = TIZEN_NOTIFICATION_PROGRESS_TYPE_PERCENTAGE;
}
- else
+ else if ( NOTI_PROGRESS_TYPE_SIZE== priv->getProgressType())
{
- return JSValueMakeNull(context);
+ type = TIZEN_NOTIFICATION_PROGRESS_TYPE_BYTE;
}
-
- return converter->toJSValueRef(notification->getID());
- }
- else if (property == NOTIFICATION_TYPE)
- {
- LogDebug(" TYPE : " << notification->getNotiType());
- return converter->toJSValueRef(notification->getNotiType());
- }
- else if (property == NOTIFICATION_POSTED_TIME)
- {
- LogDebug("notification =" << notification) ;
- time_t postedTime = notification->getPostedTime();
-
- LogDebug("postedtime = " << postedTime);
-
- if (postedTime)
- return converter->toJSValueRef(postedTime);
- else
- return JSValueMakeNull(context);
- }
- else if (property == NOTIFICATION_TITLE)
- {
- std::string title = notification->getTitle();
- LogDebug(" Title : " << title);
- return converter->toJSValueRef(title);
- }
- else if (property == NOTIFICATION_CONTENT)
- {
- std::string content = notification->getContent();
-
- if (content.size() == 0)
- return JSValueMakeNull(context);
+
+ return JSUtil::toJSValueRef(context, type);
+
+ }
+ else if ( property == STATUS_NOTIFICATION_PROGRESS_VALUE)
+ {
+ // progressValue
+
+ LogInfo("Progress Type=" << priv->getProgressType());
- LogDebug(" Content : " << content);
-
- return converter->toJSValueRef(content);
- }
- else if (property == NOTIFICATION_STATUS_TYPE)
- {
- //std::string statusType = notification->getStatusType();
- LogDebug(" NOTIFICATION_STATUS_TYPE : " << notification->getNotiType());
- return converter->toJSValueRef(notification->getNotiType());
- }
- else if (property == NOTIFICATION_ICON_PATH)
- {
- std::string iconPath = notification->getIconPath();
- LogDebug(" IconPath : " << iconPath);
- if (iconPath.empty())
- return JSValueMakeNull(context);
-
- iconPath = DeviceAPI::Filesystem::Utils::toVirtualPath(context, iconPath);
-
- return converter->toJSValueRef(iconPath);
- }
- else if (property == NOTIFICATION_SOUND_PATH)
- {
- std::string soundPath = notification->getSoundPath();
- LogDebug(" NOTIFICATION_SOUND_PATH : " << soundPath);
- if (soundPath.empty())
- return JSValueMakeNull(context);
-
- soundPath = DeviceAPI::Filesystem::Utils::toVirtualPath(context, soundPath);
-
- return converter->toJSValueRef(soundPath);
- }
- else if (property == NOTIFICATION_VIBRATION)
- {
- bool virbration = notification->getDefaultVibration();
- LogDebug(" NOTIFICATION_VIBRATION : " << virbration);
- return converter->toJSValueRef(virbration);
- }
- else if (property == NOTIFICATION_APP_ID)
- {
- std::string appid = notification->getApplicationId();
- LogDebug(" NOTIFICATION_APP_ID : " << appid);
- return converter->toJSValueRef(appid);
- }
- else if (property == NOTIFICATION_APP_CONTROL
-#ifdef APPLICATION_API_BACKWARD_COMPATIBILITY
- || property == NOTIFICATION_SEVICE
-#endif
- )
- {
- DeviceAPI::Application::ApplicationControlPtr appControl = notification->getApplicationControl();
- return converter->toJSValueRef(appControl);
- }
- else if (property == NOTIFICATION_PROGRESS_VALUE)
- {
- double progress = notification->getProgressValue();
- NotificationProgressType progressType = notification->getProgressType();
- LogDebug(" progress type = " << progressType << " progress = " << progress);
-
- int progressValue = 0;
+ // progressValue
+ unsigned long progressVal = 0;
+ if ( NOTI_PROGRESS_TYPE_PERCENTAGE == priv->getProgressType())
+ {
+ progressVal = (unsigned long)( (priv->getProgressValue()*100) );
+ }
+ else if ( NOTI_PROGRESS_TYPE_SIZE== priv->getProgressType())
+ {
+ progressVal = (unsigned long)priv->getProgressValue();
+ }
- if ( NOTI_PROGRESS_TYPE_SIZE == progressType)
- {
- progressValue = int(progress);
- }
- else if ( NOTI_PROGRESS_TYPE_PERCENTAGE == progressType)
- {
- progressValue = int(progress*100 + 0.01);
- }
- LogDebug("ProgressValue = " << progressValue);
-
- //int progressValue = int (progress);
- //LogDebug("progress = " << progress << " value = " << progressValue);
-
- return converter->toJSValueRef(progressValue);
- }
- else if (property == NOTIFICATION_LINES)
- {
- if (notification->getLines())
- return converter->toJSValueRef(notification->getLines());
- else
- return JSValueMakeNull(context);
- }
- else if (property == NOTIFICATION_BACKGROUND_IMAGE_PATH )
- {
- std::string strBackground = notification->getBackground();
- LogDebug(" NOTIFICATION_BACKGROUND_PATH : " << strBackground);
- if (strBackground.empty())
- return JSValueMakeNull(context);
-
- strBackground = DeviceAPI::Filesystem::Utils::toVirtualPath(context, strBackground);
- return converter->toJSValueRef(strBackground);
- }
- else if (property == NOTIFICATION_NUMBER)
- {
- unsigned int number = notification->getNumber();
- LogDebug(" NUMBER : " << notification->getNumber());
- return converter->toJSValueRef(number);
- }
- else if (property == NOTIFICATION_THUMBNAILS)
- {
- return converter->toJSValueRef(notification->getThumbnails());
- }
- else if (property == NOTIFICATION_SUB_ICON_PATH )
- {
- std::string strSubIcon = notification->getSubIconPath();
- LogDebug(" NOTIFICATION_SUB_ICON_PATH : " << strSubIcon);
- if (strSubIcon.empty())
- return JSValueMakeNull(context);
-
- strSubIcon = DeviceAPI::Filesystem::Utils::toVirtualPath(context, strSubIcon);
- return converter->toJSValueRef(strSubIcon);
- }
- else
- {
- ThrowMsg(WrtDeviceApis::Commons::ConversionException,"No attribute");
- }
-
- }
- Catch (WrtDeviceApis::Commons::NullPointerException)
- {
- if (property == NOTIFICATION_POSTED_TIME || property == NOTIFICATION_APP_CONTROL
- #ifdef APPLICATION_API_BACKWARD_COMPATIBILITY
- || property == NOTIFICATION_SEVICE
- #endif
- )
- {
- return JSValueMakeNull(context);
- }
- else
- {
- LogWarning("Exception: "<<_rethrown_exception.GetMessage());
- return JSTizenExceptionFactory::postException(context, exception,
- JSTizenException::TYPE_MISMATCH_ERROR, _rethrown_exception.GetMessage());
- }
- }
- Catch (WrtDeviceApis::Commons::ConversionException)
- {
- LogWarning("Exception: "<<_rethrown_exception.GetMessage());
- return JSTizenExceptionFactory::postException(context, exception,
- JSTizenException::TYPE_MISMATCH_ERROR, _rethrown_exception.GetMessage());
+ LogInfo("Progress Value=" << progressVal);
+
+ return JSUtil::toJSValueRef(context, progressVal);
+ }
+
+ }
+ catch ( const BasePlatformException& err)
+ {
+ LogWarning(" notification convertion is failed. " << err.getName().c_str() << ":" << err.getMessage().c_str());
+ return NULL;
+ }
+
+}
- }
- Catch (WrtDeviceApis::Commons::InvalidArgumentException)
- {
- LogWarning("Exception: "<<_rethrown_exception.GetMessage());
- return JSTizenExceptionFactory::postException(context, exception,
- JSTizenException::INVALID_VALUES_ERROR, _rethrown_exception.GetMessage());
- }
- Catch(WrtDeviceApis::Commons::UnsupportedException)
- {
- LogWarning("Exception: "<<_rethrown_exception.GetMessage());
- return JSTizenExceptionFactory::postException(context, exception,
- JSTizenException::NOT_SUPPORTED_ERROR, _rethrown_exception.GetMessage());
- }
- Catch (WrtDeviceApis::Commons::Exception)
- {
- LogWarning("Exception: "<<_rethrown_exception.GetMessage());
- return JSTizenExceptionFactory::postException(context, exception,
- JSTizenException::UNKNOWN_ERROR, _rethrown_exception.GetMessage());
- }
+JSClassRef JSStatusNotification::m_jsClassRef = JSClassCreate(JSStatusNotification::getClassInfo());
+
+const JSClassRef JSStatusNotification::getClassRef()
+{
+ if (!m_jsClassRef) {
+ m_jsClassRef = JSClassCreate(&m_classInfo);
+ }
+ return m_jsClassRef;
}
+const JSClassDefinition* JSStatusNotification::getClassInfo()
+{
+ return &m_classInfo;
+}
-JSObjectRef JSStatusNotification::createJSObject(JSContextRef context, INotificationPtr notification)
+void JSStatusNotification::initialize(JSContextRef context, JSObjectRef object)
{
- JSStatusNotificationPriv* priv = new JSStatusNotificationPriv( context, notification);
- return JSObjectMake(context, getClassRef(), priv);
+ LogDebug("JSStatusNotification::initialize, nothing ");
}
+void JSStatusNotification::finalize(JSObjectRef object)
+{
+ StatusNotification *priv = static_cast<StatusNotification*>(JSObjectGetPrivate(object));
+ if (priv) {
+ JSObjectSetPrivate(object, NULL);
+ delete priv;
+ }
+}
JSObjectRef JSStatusNotification::constructor(JSContextRef context,
JSObjectRef constructor,
const JSValueRef arguments[],
JSValueRef* exception)
{
- LogDebug("OK");
- //NotificationConverter converter(context);
- NotificationConverterFactory::ConverterType converter =
- NotificationConverterFactory::getConverter(context);
- JSValueRef reserveArguments[3];
- size_t index = 0;
- JSStatusNotificationPriv* priv = NULL;
-
- Try
- {
- for (index = 0; index < 3; index++)
- {
- if (index < argumentCount)
- reserveArguments[index] = arguments[index];
- else
- reserveArguments[index] = JSValueMakeUndefined(context);
- }
-
- std::string statusType = converter->toString(reserveArguments[0]);
+ ArgumentValidator validator(context, argumentCount, arguments);
+
+ //get StatusType
+ JSObjectRef obj = JSObjectMake(context, getClassRef(), NULL);
+
+ JSStringRef ctorName = JSStringCreateWithUTF8CString("constructor");
+ JSObjectSetProperty(context, obj, ctorName, constructor,
+ kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete | kJSPropertyAttributeDontEnum, NULL);
+ JSStringRelease(ctorName);
+
+ try {
+ NotificationType notiType = NOTI_TYPE_NONE;
+ std::string strStatusType = validator.toString(0, false, "");
+ LogInfo("Notification Type : " << strStatusType);
+
+ if( strStatusType.compare(TIZEN_STATUS_NOTIFICATION_TYPE_SIMPLE) == 0)
+ notiType = NOTI_TYPE_SIMPLE;
+ else if( strStatusType.compare(TIZEN_STATUS_NOTIFICATION_TYPE_THUMBNAIL) == 0)
+ notiType = NOTI_TYPE_THUMBNAIL;
+ else if( strStatusType.compare(TIZEN_STATUS_NOTIFICATION_TYPE_ONGOING) == 0)
+ notiType = NOTI_TYPE_ONGOING;
+ else if( strStatusType.compare(TIZEN_STATUS_NOTIFICATION_TYPE_PROGRESS) == 0)
+ notiType = NOTI_TYPE_PROGRESS;
+ else
+ throw TypeMismatchException("status type mismatch.");
+
+ StatusNotification *priv = new StatusNotification(notiType);
+
+ priv->setTitle(validator.toString(1, false, "")); //title
+
+ JSObjectRef notiInitDict = validator.toObject(2, true);
- //create notification private object.
- INotificationPtr notification = NotificationFactory::getInstance().getNotification(converter->toNotificationType(reserveArguments[0]));
- priv = new JSStatusNotificationPriv(context, notification);
-
- LogDebug("notification=" << notification);
-
-#if 0
- if (statusType == "ONGOING" || statusType == "PROGRESS")
- {
- notification.Reset();
- INotificationPtr newNotification(
- NotificationFactory::getInstance().getNotification(TRUE));
- notification = newNotification;
-
- if (priv)
- {
- delete priv;
- priv = new JSStatusNotificationPriv(context, notification);
- }
- }
-#endif
- //notification->setStatusType(converter.toString(reserveArguments[0]));
- //notification->setNotiType(converter.toNotificationType(reserveArguments[0]));
-
- notification->setTitle(converter->toString(reserveArguments[1]));
-
- if (!JSValueIsUndefined(context, reserveArguments[2]))
- {
- converter->toNotificationFromDict(notification, reserveArguments[2]);
- }
+ if (notiInitDict)
+ {
+ //content
+ try {
+ JSValueRef contentValue = JSUtil::getProperty(context, notiInitDict, NOTIFICATION_CONTENT);
+ if (!JSValueIsUndefined(context, contentValue))
+ priv->setContent(JSUtil::JSValueToString(context, contentValue));
+ }
+ catch ( const BasePlatformException& err)
+ {
+ LogWarning("notification's content convertion is failed." << err.getMessage().c_str());
+ }
+
+ //icon
+ try {
+ JSValueRef iconValue = JSUtil::getProperty(context, notiInitDict, STATUS_NOTIFICATION_ICON_PATH);
+ if (!JSValueIsUndefined(context, iconValue))
+ {
+ DeviceAPI::Filesystem::IPathPtr path = DeviceAPI::Filesystem::Utils::fromVirtualPath(context, JSUtil::JSValueToString(context, iconValue));
+ priv->setIconPath(path->getFullPath());
+ }
+ }
+ catch ( const BasePlatformException& err)
+ {
+ LogWarning("notification's icon path convertion is failed." << err.getMessage().c_str());
+ }
+
+ //sound
+ try {
+ JSValueRef soundValue = JSUtil::getProperty(context, notiInitDict, STATUS_NOTIFICATION_SOUND_PATH);
+ if (!JSValueIsUndefined(context, soundValue))
+ {
+ DeviceAPI::Filesystem::IPathPtr path = DeviceAPI::Filesystem::Utils::fromVirtualPath(context, JSUtil::JSValueToString(context, soundValue));
+ priv->setSoundPath(path->getFullPath());
+ }
+ }
+ catch ( const BasePlatformException& err)
+ {
+ LogWarning("notification's sound path convertion is failed." << err.getMessage().c_str());
+ }
+
+ //vibration
+ try {
+ JSValueRef vibrationValue = JSUtil::getProperty(context, notiInitDict, STATUS_NOTIFICATION_VIBRATION);
+ if (!JSValueIsUndefined(context, vibrationValue))
+ {
+ priv->setDefaultVibration(JSUtil::JSValueToBoolean(context, vibrationValue));
+ }
+ }
+ catch ( const BasePlatformException& err)
+ {
+ LogWarning("notification's vibration value convertion is failed." << err.getMessage().c_str());
+ }
+
+ //appControl
+ try {
+ JSValueRef appControlValue = JSUtil::getProperty(context, notiInitDict, STATUS_NOTIFICATION_APP_CONTROL);
+ if (!JSValueIsUndefined(context, appControlValue))
+ {
+ priv->setApplicationControl(DeviceAPI::Application::JSApplicationControl::getApplicationControl(context, JSUtil::JSValueToObject(context, appControlValue) ));
+ }
+ }
+ catch ( const BasePlatformException& err)
+ {
+ LogWarning("notification's App Control convertion is failed." << err.getMessage().c_str());
+ }
+
+ //appID
+ try {
+ JSValueRef appIdValue = JSUtil::getProperty(context, notiInitDict, STATUS_NOTIFICATION_APP_ID);
+ if (!JSValueIsUndefined(context, appIdValue))
+ {
+ priv->setApplicationId(JSUtil::JSValueToString(context, appIdValue));
+ }
+ }
+ catch ( const BasePlatformException& err)
+ {
+ LogWarning("notification's icon path convertion is failed." << err.getMessage().c_str());
+ }
+
+
+ //progressType
+ NotificationProgressType progressType = NOTI_PROGRESS_TYPE_PERCENTAGE;
+ try {
+ JSValueRef progressTypeValue = JSUtil::getProperty(context, notiInitDict, STATUS_NOTIFICATION_PROGRESS_TYPE);
+ if (!JSValueIsUndefined(context, progressTypeValue))
+ {
+ std::string strProgressType = JSUtil::JSValueToString(context, progressTypeValue);
+ LogInfo("Progress Type : " << strProgressType);
+
+
+ if( strProgressType.compare(TIZEN_NOTIFICATION_PROGRESS_TYPE_PERCENTAGE) == 0)
+ progressType = NOTI_PROGRESS_TYPE_PERCENTAGE;
+ else if( strProgressType.compare(TIZEN_NOTIFICATION_PROGRESS_TYPE_BYTE) == 0)
+ progressType = NOTI_PROGRESS_TYPE_SIZE;
+ else
+ throw InvalidValuesException("Invalid Progress Type.");
+
+ priv->setProgressType(progressType);
+ }
+ }
+ catch ( const BasePlatformException& err)
+ {
+ LogWarning("notification's icon path convertion is failed." << err.getMessage().c_str());
+ }
+
+ //ProgressValue
+ try {
+ JSValueRef progressValue = JSUtil::getProperty(context, notiInitDict, STATUS_NOTIFICATION_PROGRESS_VALUE);
+ if (!JSValueIsUndefined(context, progressValue))
+ {
+ if ( progressType == NOTI_PROGRESS_TYPE_PERCENTAGE)
+ {
+ if ( 100 < JSUtil::JSValueToULong(context, progressValue) )
+ throw InvalidValuesException("The percentage progress value must be between 0 and 100");
+ priv->setProgressValue((double)JSUtil::JSValueToULong(context, progressValue)/(double)100);
+ }
+ else
+ {
+ priv->setProgressValue((double)JSUtil::JSValueToULong(context, progressValue));
+ }
+
+ }
+ }
+ catch ( const BasePlatformException& err)
+ {
+ LogWarning("notification's icon path convertion is failed." << err.getMessage().c_str());
+ }
+
+ //DetailInfo
+ try {
+ JSValueRef detailInfoValue = JSUtil::getProperty(context, notiInitDict, STATUS_NOTIFICATION_DETAIL_INFO);
+
+ std::vector<NotificationDetailInfo*> detailInfos;
+ if (JSIsArrayValue(context, detailInfoValue))
+ {
+ JSObjectRef arrayobj = JSUtil::JSValueToObject(context, detailInfoValue);
+ for(std::size_t i = 0; i < JSGetArrayLength(context, arrayobj); ++i)
+ {
+ JSValueRef element = JSGetArrayElement(context, arrayobj, i);
+ JSObjectRef object = JSUtil::JSValueToObject(context, element);
+ if (object)
+ {
+ NotificationDetailInfo* item = static_cast<NotificationDetailInfo*>(JSObjectGetPrivate(object));
+ std::string main = item->getMainText();
+ std::string sub = item->getSubText();
+ LogInfo("Main : " << main << " Sub : " << sub);
- return JSObjectMake(context, getClassRef(), priv);
- }
- Catch (WrtDeviceApis::Commons::Exception)
- {
- if (priv != NULL)
- {
- delete priv;
- }
- LogWarning("Exception: "<<_rethrown_exception.GetMessage());
- *exception = JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::TYPE_MISMATCH_ERROR, _rethrown_exception.GetMessage());
- }
-
+ NotificationDetailInfo *detailinfo = new NotificationDetailInfo(NULL, (int)i, main, sub);
+ detailInfos.push_back(detailinfo);
+ }
+ }
+ }
+ priv->setDetailInfos(detailInfos);
+ }
+ catch ( const BasePlatformException& err)
+ {
+ LogWarning("notification's icon path convertion is failed." << err.getMessage().c_str());
+ }
+
+ //backgroundimage
+ try {
+ JSValueRef backgroundImageValue = JSUtil::getProperty(context, notiInitDict, STATUS_NOTIFICATION_BACKGROUND_IMAGE_PATH);
+ if (!JSValueIsUndefined(context, backgroundImageValue))
+ {
+ DeviceAPI::Filesystem::IPathPtr path = DeviceAPI::Filesystem::Utils::fromVirtualPath(context, JSUtil::JSValueToString(context, backgroundImageValue));
+ priv->setBackground(path->getFullPath());
+ }
+ }
+ catch ( const BasePlatformException& err)
+ {
+ LogWarning("notification's icon path convertion is failed." << err.getMessage().c_str());
+ }
+
+ //number
+ try {
+ JSValueRef numberValue = JSUtil::getProperty(context, notiInitDict, STATUS_NOTIFICATION_NUMBER);
+ if (!JSValueIsUndefined(context, numberValue))
+ {
+ priv->setNumber(JSUtil::JSValueToLong(context, numberValue));
+ }
+ }
+ catch ( const BasePlatformException& err)
+ {
+ LogWarning("notification's icon path convertion is failed." << err.getMessage().c_str());
+ }
+
+ //thumbnail
+ try {
+ JSValueRef thumbnailsValue = JSUtil::getProperty(context, notiInitDict, STATUS_NOTIFICATION_THUMBNAILS);
+ if (!JSValueIsUndefined(context, thumbnailsValue))
+ {
+ priv->setThumbnails(JSUtil::JSArrayToStringVector(context, thumbnailsValue));
+ }
+ }
+ catch ( const BasePlatformException& err)
+ {
+ LogWarning("notification's icon path convertion is failed." << err.getMessage().c_str());
+ }
+
+ //subIconPath
+ try {
+ JSValueRef subIconPathValue = JSUtil::getProperty(context, notiInitDict, STATUS_NOTIFICATION_SUB_ICON_PATH);
+ if (!JSValueIsUndefined(context, subIconPathValue))
+ {
+ DeviceAPI::Filesystem::IPathPtr path = DeviceAPI::Filesystem::Utils::fromVirtualPath(context, JSUtil::JSValueToString(context, subIconPathValue));
+ priv->setSubIconPath( path->getFullPath());
+ }
+ }
+ catch ( const BasePlatformException& err)
+ {
+ LogWarning("notification's icon path convertion is failed." << err.getMessage().c_str());
+ }
+
+ }
+
+ setPrivateObject(context, obj, priv);
+
+ }
+ catch ( const BasePlatformException& err)
+ {
+ LogWarning(" notification convertion is failed. " << err.getName().c_str() << ":" << err.getMessage().c_str());
+ JSObjectRef error = JSWebAPIError::makeJSWebAPIError(context, err);
+ *exception = error;
return NULL;
+ }
+
+ return obj;
+
}
-INotificationPtr JSStatusNotification::getNotification(JSContextRef context, JSValueRef value)
+StatusNotification* JSStatusNotification::getPrivateObject(JSContextRef context, JSObjectRef object)
{
- JSObjectRef object = JSValueToObject(context, value, NULL);
- if (!object)
- {
- Throw(WrtDeviceApis::Commons::InvalidArgumentException);
- }
- JSStatusNotificationPriv *priv = static_cast<JSStatusNotificationPriv*>(JSObjectGetPrivate(object));
-
- if (!priv)
- {
- Throw(WrtDeviceApis::Commons::NullPointerException);
- }
- return priv->getObject();
+ LogDebug("get object :" << object);
+
+ StatusNotification *priv = static_cast<StatusNotification*>(JSObjectGetPrivate(object));
+ LogDebug("statusNotification :" << priv);
+ if (!priv) {
+ throw TypeMismatchException("StatusNotification's private object is NULL.");
+ }
+
+ //type
+ JSValueRef type = JSUtil::getProperty(context, object, NOTIFICATION_TYPE);
+ if ((JSUtil::JSValueToString(context, type)).compare(NOTIFICATION_TYPE_VALUE) )
+ {
+ throw TypeMismatchException("StatusNotification's type is mismatched");
+ }
+
+ //Title
+ JSValueRef title = JSUtil::getProperty(context, object, NOTIFICATION_TITLE);
+ priv->setTitle( JSUtil::JSValueToString(context, title));
+
+ //Content
+ JSValueRef contents = JSUtil::getProperty(context, object, NOTIFICATION_CONTENT);
+ priv->setContent( JSUtil::JSValueToString(context, contents));
+
+ // iconPath
+ JSValueRef iconPath = JSUtil::getProperty(context, object, STATUS_NOTIFICATION_ICON_PATH);
+ if (!JSUtil::JSValueToString(context, iconPath).empty())
+ {
+ DeviceAPI::Filesystem::IPathPtr icon = DeviceAPI::Filesystem::Utils::fromVirtualPath(context, JSUtil::JSValueToString(context, iconPath));
+ priv->setIconPath(icon->getFullPath());
+ }
+ else
+ {
+ priv->setIconPath("");
+ }
+
+ // subIconPath
+ JSValueRef subIconPath = JSUtil::getProperty(context, object, STATUS_NOTIFICATION_SUB_ICON_PATH);
+ if (!JSUtil::JSValueToString(context, subIconPath).empty())
+ {
+ DeviceAPI::Filesystem::IPathPtr subIcon = DeviceAPI::Filesystem::Utils::fromVirtualPath(context, JSUtil::JSValueToString(context, subIconPath));
+ priv->setSubIconPath(subIcon->getFullPath());
+ }
+ else
+ {
+ priv->setSubIconPath("");
+ }
+
+ // number
+ JSValueRef number = JSUtil::getProperty(context, object, STATUS_NOTIFICATION_NUMBER);
+ priv->setNumber(JSUtil::JSValueToLong(context, number));
+
+ // detailInfo
+ JSValueRef detailInfo = JSUtil::getProperty(context, object, STATUS_NOTIFICATION_DETAIL_INFO);
+ std::vector<NotificationDetailInfo*> detailInfos;
+ if (JSIsArrayValue(context, detailInfo))
+ {
+ JSObjectRef arrayobj = JSUtil::JSValueToObject(context, detailInfo);
+ for(std::size_t i = 0; i < JSGetArrayLength(context, arrayobj); ++i)
+ {
+ JSValueRef element = JSGetArrayElement(context, arrayobj, i);
+ JSObjectRef object = JSUtil::JSValueToObject(context, element);
+ if (object)
+ {
+ NotificationDetailInfo* detailinfo = static_cast<NotificationDetailInfo*>(JSObjectGetPrivate(object));
+ detailInfos.push_back(detailinfo);
+ }
+ }
+ }
+ priv->setDetailInfos(detailInfos);
+
+ // backgroundImagePath
+ JSValueRef backgroundImagePath = JSUtil::getProperty(context, object, STATUS_NOTIFICATION_BACKGROUND_IMAGE_PATH);
+ if (!JSUtil::JSValueToString(context, backgroundImagePath).empty())
+ {
+ DeviceAPI::Filesystem::IPathPtr backgroundImage = DeviceAPI::Filesystem::Utils::fromVirtualPath(context, JSUtil::JSValueToString(context, backgroundImagePath));
+ priv->setBackground(backgroundImage->getFullPath());
+ }
+ else
+ {
+ priv->setBackground("");
+ }
+
+ // thumbnails
+ JSValueRef thumbnails = JSUtil::getProperty(context, object, STATUS_NOTIFICATION_THUMBNAILS);
+
+ std::vector<std::string> thumbnailPaths;
+ if( JSIsArrayValue(context, thumbnails)){
+ JSObjectRef arrayobj = JSUtil::JSValueToObject(context, thumbnails);
+ for (std::size_t i = 0; i < JSGetArrayLength(context, arrayobj); ++i) {
+ JSValueRef element = JSGetArrayElement(context, arrayobj, i);
+ DeviceAPI::Filesystem::IPathPtr thumbnailPath =
+ DeviceAPI::Filesystem::Utils::fromVirtualPath(context, JSUtil::JSValueToString(context, element));
+ LogInfo("thumbnail Path = " << thumbnailPath->getFullPath());
+ thumbnailPaths.push_back(thumbnailPath->getFullPath());
+ }
+ }
+ priv->setThumbnails(thumbnailPaths);
+
+ // soundPath
+ JSValueRef soundPath = JSUtil::getProperty(context, object, STATUS_NOTIFICATION_SOUND_PATH);
+ if (!JSUtil::JSValueToString(context, soundPath).empty())
+ {
+ DeviceAPI::Filesystem::IPathPtr sound = DeviceAPI::Filesystem::Utils::fromVirtualPath(context, JSUtil::JSValueToString(context, soundPath));
+ priv->setSoundPath(sound->getFullPath());
+ }
+ else
+ {
+ priv->setSoundPath("");
+ }
+
+ // vibration
+ JSValueRef vibration = JSUtil::getProperty(context, object, STATUS_NOTIFICATION_VIBRATION);
+ priv->setDefaultVibration(JSUtil::JSValueToBoolean(context, vibration));
+
+ // appControl
+ JSValueRef appControl = JSUtil::getProperty(context, object, STATUS_NOTIFICATION_APP_CONTROL);
+ priv->setApplicationControl(DeviceAPI::Application::JSApplicationControl::getApplicationControl(context, JSUtil::JSValueToObject(context,appControl)));
+
+ // appId
+ JSValueRef appId = JSUtil::getProperty(context, object, STATUS_NOTIFICATION_APP_ID);
+ priv->setApplicationId(JSUtil::JSValueToString(context, appId));
+
+#if 0
+ // progressType
+ JSValueRef progressType = JSUtil::getProperty(context, object, STATUS_NOTIFICATION_PROGRESS_TYPE);
+ std::string strProgressType = JSUtil::JSValueToString(context, progressType);
+ LogInfo("Progress Type : " << strProgressType);
+
+ NotificationProgressType progType = NOTI_PROGRESS_TYPE_NONE;
+ if( strProgressType.compare(TIZEN_NOTIFICATION_PROGRESS_TYPE_PERCENTAGE) == 0)
+ progType = NOTI_PROGRESS_TYPE_PERCENTAGE;
+ else if( strProgressType.compare(TIZEN_NOTIFICATION_PROGRESS_TYPE_BYTE) == 0)
+ progType = NOTI_PROGRESS_TYPE_SIZE;
+ else
+ throw InvalidValuesException("Invalid Progress Type.");
+ priv->setProgressType(progType);
+
+ // progressValue
+ JSValueRef progressValue = JSUtil::getProperty(context, object, STATUS_NOTIFICATION_PROGRESS_VALUE);
+ LogInfo(" Progress Value in Private Object = " << JSUtil::JSValueToULong(context, progressValue));
+ if ( progType == NOTI_PROGRESS_TYPE_PERCENTAGE)
+ {
+ if ( 100 < JSUtil::JSValueToULong(context, progressValue) )
+ throw InvalidValuesException("The percentage progress value must be between 0 and 100");
+ priv->setProgressValue((double)JSUtil::JSValueToULong(context, progressValue)/(double)100);
+ }
+ else
+ {
+ priv->setProgressValue((double)JSUtil::JSValueToULong(context, progressValue));
+ }
+ #endif
+ return priv;
}
+void JSStatusNotification::setPrivateObject(JSContextRef context, JSObjectRef object, StatusNotification *priv)
+{
+ if (priv) {
+ JSObjectSetPrivate(object, static_cast<void*>(priv));
+ }
+
+ //type
+ std::string typeVal(NOTIFICATION_TYPE_VALUE);
+ JSUtil::setProperty(context, object, NOTIFICATION_TYPE,
+ JSUtil::toJSValueRef(context, typeVal), kJSPropertyAttributeReadOnly);
+
+ std::string type;
+
+ //statusType
+ if ( NOTI_TYPE_SIMPLE == priv->getNotiType())
+ type = TIZEN_STATUS_NOTIFICATION_TYPE_SIMPLE;
+ else if ( NOTI_TYPE_ONGOING == priv->getNotiType())
+ type = TIZEN_STATUS_NOTIFICATION_TYPE_ONGOING;
+ else if ( NOTI_TYPE_PROGRESS == priv->getNotiType())
+ type = TIZEN_STATUS_NOTIFICATION_TYPE_PROGRESS;
+ else if ( NOTI_TYPE_THUMBNAIL == priv->getNotiType())
+ type = TIZEN_STATUS_NOTIFICATION_TYPE_THUMBNAIL;
+ else
+ throw TypeMismatchException("status type mismatch.");
+
+ JSUtil::setProperty(context, object, STATUS_NOTIFICATION_STATUS_TYPE,
+ JSUtil::toJSValueRef(context, type), kJSPropertyAttributeReadOnly);
+
+ //id
+ if (priv->getID() >= 0)
+ {
+ std::stringstream stream;
+ stream << priv->getID();
+
+ if(stream.fail())
+ throw TypeMismatchException("Notification's ID conversion is failed.");
+
+ JSUtil::setProperty(context, object, NOTIFICATION_ID,
+ JSUtil::toJSValueRef(context, stream.str()), kJSPropertyAttributeReadOnly);
+ }
+ else
+ {
+ JSUtil::setProperty(context, object, NOTIFICATION_ID,
+ JSValueMakeNull(context), kJSPropertyAttributeReadOnly);
+ }
+
+ //postedTime
+ if (priv->getPostedTime() > 0)
+ {
+ JSUtil::setProperty(context, object, NOTIFICATION_POSTED_TIME,
+ JSUtil::makeDateObject(context,priv->getPostedTime()), kJSPropertyAttributeReadOnly);
+ }
+ else
+ {
+ JSUtil::setProperty(context, object, NOTIFICATION_POSTED_TIME,
+ JSValueMakeNull(context), kJSPropertyAttributeReadOnly);
+ }
+
+ //title
+ JSUtil::setProperty(context, object, NOTIFICATION_TITLE,
+ JSUtil::toJSValueRef(context, priv->getTitle()), kJSPropertyAttributeNone);
+
+ //content
+ JSUtil::setProperty(context, object, NOTIFICATION_CONTENT,
+ JSUtil::toJSValueRef(context, priv->getContent()), kJSPropertyAttributeNone);
+
+ //iconPath
+ JSUtil::setProperty(context, object, STATUS_NOTIFICATION_ICON_PATH,
+ JSUtil::toJSValueRef(context, DeviceAPI::Filesystem::Utils::toVirtualPath(context, priv->getIconPath())), kJSPropertyAttributeNone);
+
+ //subIconPath
+ JSUtil::setProperty(context, object, STATUS_NOTIFICATION_SUB_ICON_PATH,
+ JSUtil::toJSValueRef(context, DeviceAPI::Filesystem::Utils::toVirtualPath(context, priv->getSubIconPath())), kJSPropertyAttributeNone);
+
+ //number
+ JSUtil::setProperty(context, object, STATUS_NOTIFICATION_NUMBER,
+ JSUtil::toJSValueRef(context, (unsigned long)priv->getNumber()), kJSPropertyAttributeNone);
+
+ // backgroundImagePath
+ JSUtil::setProperty(context, object, STATUS_NOTIFICATION_BACKGROUND_IMAGE_PATH,
+ JSUtil::toJSValueRef(context, DeviceAPI::Filesystem::Utils::toVirtualPath(context, priv->getBackground())), kJSPropertyAttributeNone);
+
+ // thumbnails
+
+ std::vector<std::string> thumbnails = priv->getThumbnails();
+ LogInfo("Thumbnail Size : " << thumbnails.size());
+ JSValueRef tumbnailvalueArray[thumbnails.size()];
+ for( unsigned int i = 0 ; i < thumbnails.size(); i++) {
+ if (!thumbnails[i].empty())
+ {
+ LogInfo("Thumbnail :" << thumbnails[i]);
+ tumbnailvalueArray[i] = JSUtil::toJSValueRef(context, DeviceAPI::Filesystem::Utils::toVirtualPath(context, thumbnails[i]));
+ }
+ }
+
+ JSValueRef exception = NULL;
+ JSObjectRef jsThumbnails = JSObjectMakeArray(context, thumbnails.size(), tumbnailvalueArray, &exception);
+ if (exception != NULL) {
+ throw DeviceAPI::Common::UnknownException("Make Object Array failed.");
+ }
+
+ JSUtil::setProperty(context, object, STATUS_NOTIFICATION_THUMBNAILS,
+ jsThumbnails, kJSPropertyAttributeNone);
+
+ // soundPath
+ JSUtil::setProperty(context, object, STATUS_NOTIFICATION_SOUND_PATH,
+ JSUtil::toJSValueRef(context, DeviceAPI::Filesystem::Utils::toVirtualPath(context, priv->getSoundPath())), kJSPropertyAttributeNone);
+
+ // vibration
+ JSUtil::setProperty(context, object, STATUS_NOTIFICATION_VIBRATION,
+ JSUtil::toJSValueRef(context, priv->getDefaultVibration()), kJSPropertyAttributeNone);
+
+ // appId
+ JSUtil::setProperty(context, object, STATUS_NOTIFICATION_APP_ID,
+ JSUtil::toJSValueRef(context, priv->getApplicationId()), kJSPropertyAttributeNone);
+#if 0
+ // progressType & Value
+ LogInfo("Progress Type=" << priv->getProgressType());
+
+ // progressValue
+ unsigned long progressVal = 0;
+ if ( NOTI_PROGRESS_TYPE_PERCENTAGE == priv->getProgressType())
+ {
+ type = TIZEN_NOTIFICATION_PROGRESS_TYPE_PERCENTAGE;
+ progressVal = (unsigned long)( (priv->getProgressValue()*100) );
+ }
+ else if ( NOTI_PROGRESS_TYPE_SIZE== priv->getProgressType())
+ {
+ type = TIZEN_NOTIFICATION_PROGRESS_TYPE_BYTE;
+ progressVal = (unsigned long)priv->getProgressValue();
+ }
+
+ LogInfo("Progress Type=" << type);
+ JSUtil::setProperty(context, object, STATUS_NOTIFICATION_PROGRESS_TYPE,
+ JSUtil::toJSValueRef(context, type), kJSPropertyAttributeNone);
+
+ LogInfo("Progress Value =" << progressVal);
+ JSUtil::setProperty(context, object, STATUS_NOTIFICATION_PROGRESS_VALUE,
+ JSUtil::toJSValueRef(context, progressVal), kJSPropertyAttributeNone);
+#endif
+ // detailInfo
+ std::vector<NotificationDetailInfo*> detailInfo = priv->getDetailInfos();
+ LogInfo("detail Info Size : " << detailInfo.size());
+ JSObjectRef valueArray[detailInfo.size()];
+ for( unsigned int i = 0 ; i < detailInfo.size(); i++) {
+ if (detailInfo[i])
+ {
+ LogInfo("Main = " << detailInfo[i]->getMainText() << " Sub = " << detailInfo[i]->getSubText());
+ valueArray[i] = JSObjectMake(GlobalContextManager::getInstance()->getGlobalContext(context), JSNotificationDetailInfo::getClassRef(), static_cast<void*>(detailInfo[i]));
+ JSNotificationDetailInfo::setPrivateObject(context, valueArray[i], detailInfo[i]);
+ LogInfo("make Object : " << valueArray[i]);
+ }
+ }
+
+ exception = NULL;
+ JSObjectRef jsResult = JSObjectMakeArray(GlobalContextManager::getInstance()->getGlobalContext(context), detailInfo.size(), valueArray, &exception);
+ if (exception != NULL) {
+ throw DeviceAPI::Common::UnknownException("Make Object Array failed.");
+ }
+
+ // detailInfo
+ JSUtil::setProperty(context, object, STATUS_NOTIFICATION_DETAIL_INFO,
+ jsResult, kJSPropertyAttributeNone);
+
+ // appControl
+ DeviceAPI::Application::JSApplicationControlPriv *appCtrlPriv = new DeviceAPI::Application::JSApplicationControlPriv(context, priv->getApplicationControl());
+ if (appCtrlPriv)
+ {
+ JSObjectRef jsAppCtrl = JSObjectMake(context, DeviceAPI::Application::JSApplicationControl::getClassRef(), appCtrlPriv);
+ JSUtil::setProperty(context, object, STATUS_NOTIFICATION_APP_CONTROL, jsAppCtrl, kJSPropertyAttributeNone);
+ }
+
}
-}
+
+} // Notification
+} // DeviceAPI